diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-12-10 11:48:01 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska@appnovation.com> | 2023-12-10 11:48:01 +0000 |
| commit | b8d0f83e6cea9640a7ee4402c163ad812237355d (patch) | |
| tree | 57a64ac8aa0e98c40db8c36e96e7379490e44dbf /src/common | |
| download | shibari-b8d0f83e6cea9640a7ee4402c163ad812237355d.tar.gz | |
Initial commit
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/deps-lib/shibari-common | 10 | ||||
| -rw-r--r-- | src/common/shibari_log_answer.c | 36 | ||||
| -rw-r--r-- | src/common/shibari_log_exit.c | 14 | ||||
| -rw-r--r-- | src/common/shibari_log_query.c | 18 | ||||
| -rw-r--r-- | src/common/shibari_log_queryplus.c | 24 | ||||
| -rw-r--r-- | src/common/shibari_log_start.c | 17 | ||||
| -rw-r--r-- | src/common/shibari_util_get_prefixlen.c | 14 | ||||
| -rw-r--r-- | src/common/shibari_util_qtype_num.c | 121 | ||||
| -rw-r--r-- | src/common/shibari_util_qtype_str.c | 285 | ||||
| -rw-r--r-- | src/common/shibari_util_rcode_str.c | 41 |
10 files changed, 580 insertions, 0 deletions
diff --git a/src/common/deps-lib/shibari-common b/src/common/deps-lib/shibari-common new file mode 100644 index 0000000..a5c44a4 --- /dev/null +++ b/src/common/deps-lib/shibari-common @@ -0,0 +1,10 @@ +shibari_log_answer.o +shibari_log_exit.o +shibari_log_query.o +shibari_log_queryplus.o +shibari_log_start.o +shibari_util_qtype_num.o +shibari_util_qtype_str.o +shibari_util_rcode_str.o +shibari_util_get_prefixlen.o +-lskarnet diff --git a/src/common/shibari_log_answer.c b/src/common/shibari_log_answer.c new file mode 100644 index 0000000..f34cee5 --- /dev/null +++ b/src/common/shibari_log_answer.c @@ -0,0 +1,36 @@ +/* ISC license. */ + +#include <skalibs/uint16.h> +#include <skalibs/strerr.h> + +#include <s6-dns/s6dns-message.h> + +#include <shibari/util.h> +#include <shibari/log.h> + +void shibari_log_answer (uint32_t v, s6dns_message_header_t const *hdr, uint16_t len) +{ + if (v < 2) return ; + if (hdr->rcode) + { + char fmtr[UINT16_FMT] ; + fmtr[uint16_fmt(fmtr, hdr->rcode)] = 0 ; + strerr_warni4x("answer ", fmtr, " ", shibari_util_rcode_str(hdr->rcode)) ; + } + else + { + size_t pos = 0 ; + char fmt[UINT16_FMT << 2] ; + char fmtl[UINT16_FMT] ; + pos += uint16_fmt(fmt + pos, hdr->counts.qd) ; + fmt[pos++] = '+' ; + pos += uint16_fmt(fmt + pos, hdr->counts.an) ; + fmt[pos++] = '+' ; + pos += uint16_fmt(fmt + pos, hdr->counts.ns) ; + fmt[pos++] = '+' ; + pos += uint16_fmt(fmt + pos, hdr->counts.qd) ; + fmt[pos] = 0 ; + fmtl[uint16_fmt(fmtl, len)] = 0 ; + strerr_warni5x("answer 0 noerror ", fmt, " len ", fmtl, hdr->tc ? " tc" : "") ; + } +} diff --git a/src/common/shibari_log_exit.c b/src/common/shibari_log_exit.c new file mode 100644 index 0000000..8e383c6 --- /dev/null +++ b/src/common/shibari_log_exit.c @@ -0,0 +1,14 @@ +/* ISC license. */ + +#include <skalibs/types.h> +#include <skalibs/strerr.h> + +#include <shibari/log.h> + +void shibari_log_exit (uint32_t v, int e) +{ + char fmt[UINT_FMT] ; + if (v < 2) return ; + fmt[uint_fmt(fmt, (unsigned int)e)] = 0 ; + strerr_warni2x("exit ", fmt) ; +} diff --git a/src/common/shibari_log_query.c b/src/common/shibari_log_query.c new file mode 100644 index 0000000..b04ee27 --- /dev/null +++ b/src/common/shibari_log_query.c @@ -0,0 +1,18 @@ +/* ISC license. */ + +#include <skalibs/strerr.h> + +#include <s6-dns/s6dns-domain.h> + +#include <shibari/util.h> +#include <shibari/log.h> + +void shibari_log_query (uint32_t v, s6dns_domain_t const *q, uint16_t qtype) +{ + char qs[256] ; + s6dns_domain_t qe ; + if (v < 2) return ; + qe = *q ; + if (!s6dns_domain_encode(&qe) || !s6dns_domain_tostring(qs, 256, &qe)) return ; + strerr_warni4x("query ", shibari_util_qtype_str(qtype), " ", qs) ; +} diff --git a/src/common/shibari_log_queryplus.c b/src/common/shibari_log_queryplus.c new file mode 100644 index 0000000..7e7fecc --- /dev/null +++ b/src/common/shibari_log_queryplus.c @@ -0,0 +1,24 @@ +/* ISC license. */ + +#include <skalibs/uint16.h> +#include <skalibs/ip46.h> +#include <skalibs/strerr.h> + +#include <s6-dns/s6dns-domain.h> + +#include <shibari/util.h> +#include <shibari/log.h> + +void shibari_log_queryplus (uint32_t v, s6dns_domain_t const *q, uint16_t qtype, ip46 const *ip, uint16_t port) +{ + char qs[256] ; + char fmti[IP46_FMT] ; + char fmtp[UINT16_FMT] ; + s6dns_domain_t qe ; + if (v < 2) return ; + qe = *q ; + if (!s6dns_domain_encode(&qe) || !s6dns_domain_tostring(qs, 256, &qe)) return ; + fmti[ip46_fmt(fmti, ip)] = 0 ; + fmtp[uint16_fmt(fmtp, port)] = 0 ; + strerr_warni8x("query ", shibari_util_qtype_str(qtype), " ", qs, " ip ", fmti, " port ", fmtp) ; +} diff --git a/src/common/shibari_log_start.c b/src/common/shibari_log_start.c new file mode 100644 index 0000000..214dc60 --- /dev/null +++ b/src/common/shibari_log_start.c @@ -0,0 +1,17 @@ +/* ISC license. */ + +#include <skalibs/uint16.h> +#include <skalibs/ip46.h> +#include <skalibs/strerr.h> + +#include <shibari/log.h> + +void shibari_log_start (uint32_t v, ip46 const *ip, uint16_t port) +{ + char fmti[IP46_FMT] ; + char fmtp[UINT16_FMT] ; + if (v < 2) return ; + fmti[ip46_fmt(fmti, ip)] = 0 ; + fmtp[uint16_fmt(fmtp, port)] = 0 ; + strerr_warni4x("start ip ", fmti, " port ", fmtp) ; +} diff --git a/src/common/shibari_util_get_prefixlen.c b/src/common/shibari_util_get_prefixlen.c new file mode 100644 index 0000000..784a3ee --- /dev/null +++ b/src/common/shibari_util_get_prefixlen.c @@ -0,0 +1,14 @@ +/* ISC license. */ + +#include <stdint.h> +#include <string.h> + +#include <shibari/util.h> + +int shibari_util_get_prefixlen (char const *name, uint16_t namelen, char const *zone, uint16_t zonelen) +{ + return + namelen < zonelen ? -1 : + memcmp(name + namelen - zonelen, zone, zonelen) ? -1 : + namelen - zonelen ; +} diff --git a/src/common/shibari_util_qtype_num.c b/src/common/shibari_util_qtype_num.c new file mode 100644 index 0000000..350e268 --- /dev/null +++ b/src/common/shibari_util_qtype_num.c @@ -0,0 +1,121 @@ +/* ISC license. */ + +#include <stdint.h> +#include <strings.h> +#include <stdlib.h> + +#include <shibari/util.h> + +struct map_s +{ + char const *s ; + uint16_t num ; +} ; + +static int map_cmp (void const *a, void const *b) +{ + return strcasecmp((char const *)a, ((struct map_s const *)b)->s) ; +} + +#define BSEARCH(key, array) bsearch(key, (array), sizeof(array)/sizeof(struct map_s), sizeof(struct map_s), &map_cmp) + +static struct map_s const qtype_table[] = +{ + { "*", 255 }, + { "A", 1 }, + { "A6", 38 }, + { "AAAA", 28 }, + { "AFSDB", 18 }, + { "AMTRELAY", 260 }, + { "ANY", 255 }, + { "APL", 42 }, + { "ATMA", 34 }, + { "AVC", 258 }, + { "AXFR", 252 }, + { "CAA", 257 }, + { "CDNSKEY", 60 }, + { "CDS", 59 }, + { "CERT", 37 }, + { "CNAME", 5 }, + { "CSYNC", 62 }, + { "DHCID", 49 }, + { "DLV", 32769 }, + { "DNAME", 39 }, + { "DNSKEY", 48 }, + { "DOA", 259 }, + { "DS", 43 }, + { "EID", 31 }, + { "EUI48", 108 }, + { "EUI64", 109 }, + { "GID", 102 }, + { "GPOS", 27 }, + { "HINFO", 13 }, + { "HIP", 55 }, + { "HTTPS", 65 }, + { "IPSECKEY", 45 }, + { "ISDN", 20 }, + { "IXFR", 251 }, + { "KEY", 25 }, + { "KX", 36 }, + { "L32", 105 }, + { "L64", 106 }, + { "LOC", 29 }, + { "LP", 107 }, + { "MAILA", 254 }, + { "MAILB", 253 }, + { "MB", 7 }, + { "MD", 3 }, + { "MF", 4 }, + { "MG", 8 }, + { "MINFO", 14 }, + { "MR", 9 }, + { "MX", 15 }, + { "NAPTR", 35 }, + { "NID", 104 }, + { "NIMLOC", 32 }, + { "NINFO", 56 }, + { "NS", 2 }, + { "NSAP", 22 }, + { "NSAP-PTR", 23 }, + { "NSEC", 47 }, + { "NSEC3", 50 }, + { "NSEC3PARAM", 51 }, + { "NULL", 10 }, + { "NXT", 30 }, + { "OPENPGPKEY", 61 }, + { "OPT", 41 }, + { "PTR", 12 }, + { "PX", 26 }, + { "RESINFO", 261 }, + { "RKEY", 57 }, + { "RP", 17 }, + { "RRSIG", 46 }, + { "RT", 21 }, + { "SIG", 24 }, + { "SINK", 40 }, + { "SMIMEA", 53 }, + { "SOA", 6 }, + { "SPF", 99 }, + { "SRV", 33 }, + { "SSHFP", 44 }, + { "SVCB", 64 }, + { "TA", 32768 }, + { "TALINK", 58 }, + { "TKEY", 249 }, + { "TLSA", 52 }, + { "TSIG", 250 }, + { "TXT", 16 }, + { "UID", 101 }, + { "UINFO", 100 }, + { "UNSPEC", 103 }, + { "URI", 256 }, + { "WKS", 11 }, + { "X25", 19 }, + { "ZONEMD", 63 } +} ; + +uint16_t shibari_util_qtype_num (char const *s) +{ + struct map_s const *p = BSEARCH(s, qtype_table) ; + return p ? p->num : 0 ; +} diff --git a/src/common/shibari_util_qtype_str.c b/src/common/shibari_util_qtype_str.c new file mode 100644 index 0000000..97b701d --- /dev/null +++ b/src/common/shibari_util_qtype_str.c @@ -0,0 +1,285 @@ +/* ISC license. */ + +#include <stdint.h> + +#include <shibari/util.h> + +static char const *const qtype_table[262] = +{ + "error", + "A", + "NS", + "MD", + "MF", + "CNAME", + "SOA", + "MB" + "MG", + "MR", + "NULL", + "WKS", + "PTR", + "HINFO", + "MINFO", + "MX", + "TXT", + "RP", + "AFSDB", + "X25", + "ISDN", + "RT", + "NSAP", + "NSAP-PTR", + "SIG", + "KEY", + "PX", + "GPOS", + "AAAA", + "LOC", + "NXT", + "EID", + "NIMLOC", + "SRV", + "ATMA", + "NAPTR", + "KX", + "CERT", + "A6", + "DNAME", + "SINK", + "OPT", + "APL", + "DS", + "SSHFP", + "IPSECKEY", + "RRSIG", + "NSEC", + "DNSKEY", + "DHCID", + "NSEC3", + "NSEC3PARAM", + "TLSA", + "SMIMEA", + "unassigned", + "HIP", + "NINFO", + "RKEY", + "TALINK", + "CDS", + "CDNSKEY", + "OPENPGPKEY", + "CSYNC", + "ZONEMD", + "SVCB", + "HTTPS", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "SPF", + "UINFO", + "UID", + "GID", + "UNSPEC", + "NID", + "L32", + "L64", + "LP", + "EUI48", + "EUI64", + + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + + "TKEY", + "TSIG", + "IXFR", + "AXFR", + "MAILB", + "MAILA", + "*", + "URI", + "CAA", + "AVC", + "DOA", + "AMTRELAY", + "RESINFO" +} ; + + +char const *shibari_util_qtype_str (uint16_t qtype) +{ + if (qtype < 262) return qtype_table[qtype] ; + if (qtype < 32768) return "unassigned" ; + if (qtype == 32768) return "TA" ; + if (qtype == 32769) return "DLV" ; + if (qtype < 65279) return "unassigned" ; + if (qtype < 65535) return "private" ; + return "reserved" ; +} diff --git a/src/common/shibari_util_rcode_str.c b/src/common/shibari_util_rcode_str.c new file mode 100644 index 0000000..142cc0e --- /dev/null +++ b/src/common/shibari_util_rcode_str.c @@ -0,0 +1,41 @@ +/* ISC license. */ + +#include <stdint.h> + +#include <shibari/util.h> + +char const *shibari_util_rcode_str (uint16_t rcode) +{ + static char const *const rcode_table[24] = + { + "noerror", + "formerr", + "servfail", + "nxdomain", + "notimp", + "refused", + "yxdomain", + "yxrrset", + "nxrrset", + "notauth", + "notzone", + "dsotypeni", + "unassigned", + "unassigned", + "unassigned", + "unassigned", + "badsig", + "badkey", + "badtime", + "badmode", + "badname", + "badalg", + "badtrunc", + "badcookie" + } ; + if (rcode < 24) return rcode_table[rcode] ; + if (rcode < 3841) return "unassigned" ; + if (rcode < 4096) return "private" ; + if (rcode < 65535) return "unassigned" ; + return "reserved" ; +} |
