From 2d78c35314f0310561cabefea8564123ccbb2622 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 2 Dec 2023 10:23:03 +0000 Subject: Add nodecode functions for get_domain and parse_question Also make sure get_domain always returns lowercase. Signed-off-by: Laurent Bercot --- src/libs6dns/deps-lib/s6dns | 1 + src/libs6dns/s6dns_message_get_domain_nodecode.c | 2 ++ src/libs6dns/s6dns_message_parse_question.c | 21 ++-------------- .../s6dns_message_parse_question_nodecode.c | 28 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 src/libs6dns/s6dns_message_parse_question_nodecode.c (limited to 'src/libs6dns') diff --git a/src/libs6dns/deps-lib/s6dns b/src/libs6dns/deps-lib/s6dns index 266b574..818e913 100644 --- a/src/libs6dns/deps-lib/s6dns +++ b/src/libs6dns/deps-lib/s6dns @@ -84,6 +84,7 @@ s6dns_message_parse_getrr.o s6dns_message_parse_init.o s6dns_message_parse_next.o s6dns_message_parse_question.o +s6dns_message_parse_question_nodecode.o s6dns_message_parse_skipqd.o s6dns_rci_free.o s6dns_rci_here.o diff --git a/src/libs6dns/s6dns_message_get_domain_nodecode.c b/src/libs6dns/s6dns_message_get_domain_nodecode.c index 9774527..d3678db 100644 --- a/src/libs6dns/s6dns_message_get_domain_nodecode.c +++ b/src/libs6dns/s6dns_message_get_domain_nodecode.c @@ -4,6 +4,7 @@ #include #include +#include #include @@ -45,5 +46,6 @@ size_t s6dns_message_get_domain_nodecode (char *out, size_t outmax, char const * } else return (errno = EPROTONOSUPPORT, 0) ; /* unsupported extension */ } + case_lowerb(out, w) ; return w ; } diff --git a/src/libs6dns/s6dns_message_parse_question.c b/src/libs6dns/s6dns_message_parse_question.c index 780ec22..484774c 100644 --- a/src/libs6dns/s6dns_message_parse_question.c +++ b/src/libs6dns/s6dns_message_parse_question.c @@ -1,26 +1,9 @@ /* ISC license. */ -#include - -#include -#include - -#include +#include #include int s6dns_message_parse_question (s6dns_message_counts_t *counts, s6dns_domain_t *name, uint16_t *qtypep, char const *packet, unsigned int packetlen, unsigned int *pos) { - s6dns_domain_t d ; - uint16_t qtype ; - uint16_t qclass ; - if (!counts->qd) return (errno = EINVAL, 0) ; - if (!s6dns_message_get_domain(&d, packet, packetlen, pos)) return 0 ; - if (*pos + 4 > packetlen) return (errno = EPROTO, 0) ; - uint16_unpack_big(packet + *pos, &qtype) ; *pos += 2 ; - uint16_unpack_big(packet + *pos, &qclass) ; *pos += 2 ; - if (qclass != S6DNS_C_IN) return (errno = ENOTSUP, 0) ; - counts->qd-- ; - *name = d ; - *qtypep = qtype ; - return 1 ; + return s6dns_message_parse_question_nodecode(counts, name, qtypep, packet, packetlen, pos) && s6dns_domain_decode(name) ; } diff --git a/src/libs6dns/s6dns_message_parse_question_nodecode.c b/src/libs6dns/s6dns_message_parse_question_nodecode.c new file mode 100644 index 0000000..f6cc4a7 --- /dev/null +++ b/src/libs6dns/s6dns_message_parse_question_nodecode.c @@ -0,0 +1,28 @@ +/* ISC license. */ + +#include +#include + +#include +#include + +#include +#include +#include + +int s6dns_message_parse_question_nodecode (s6dns_message_counts_t *counts, s6dns_domain_t *name, uint16_t *qtypep, char const *packet, unsigned int packetlen, unsigned int *pos) +{ + s6dns_domain_t d ; + uint16_t qtype ; + uint16_t qclass ; + if (!counts->qd) return (errno = EINVAL, 0) ; + if (!s6dns_message_get_domain_nodecode(&d, packet, packetlen, pos)) return 0 ; + if (*pos + 4 > packetlen) return (errno = EPROTO, 0) ; + uint16_unpack_big(packet + *pos, &qtype) ; *pos += 2 ; + uint16_unpack_big(packet + *pos, &qclass) ; *pos += 2 ; + if (qclass != S6DNS_C_IN) return (errno = ENOTSUP, 0) ; + counts->qd-- ; + *name = d ; + *qtypep = qtype ; + return 1 ; +} -- cgit v1.2.3