diff options
| author | Cy Schubert <cy@FreeBSD.org> | 2022-06-08 14:43:13 +0000 |
|---|---|---|
| committer | Cy Schubert <cy@FreeBSD.org> | 2022-06-08 14:43:13 +0000 |
| commit | 5f9f82264b91e041df7cba2406625146e7268ce4 (patch) | |
| tree | ba7309ee547bf22115420277f45a3478aafb6397 /util/data | |
| parent | 3574dc0bd83e731bba79edc130c0569bf05f7af5 (diff) | |
Diffstat (limited to 'util/data')
| -rw-r--r-- | util/data/msgparse.c | 3 | ||||
| -rw-r--r-- | util/data/msgparse.h | 9 | ||||
| -rw-r--r-- | util/data/msgreply.c | 31 | ||||
| -rw-r--r-- | util/data/msgreply.h | 39 |
4 files changed, 80 insertions, 2 deletions
diff --git a/util/data/msgparse.c b/util/data/msgparse.c index a600a8c60151..5bb69d6ed06f 100644 --- a/util/data/msgparse.c +++ b/util/data/msgparse.c @@ -1157,7 +1157,7 @@ skip_pkt_rr(sldns_buffer* pkt) } /** skip RRs from packet */ -static int +int skip_pkt_rrs(sldns_buffer* pkt, int num) { int i; @@ -1235,3 +1235,4 @@ log_edns_opt_list(enum verbosity_value level, const char* info_str, } } } + diff --git a/util/data/msgparse.h b/util/data/msgparse.h index 4c0559a739a4..0c458e6e8e25 100644 --- a/util/data/msgparse.h +++ b/util/data/msgparse.h @@ -294,6 +294,15 @@ int parse_extract_edns_from_response_msg(struct msg_parse* msg, struct edns_data* edns, struct regional* region); /** + * Skip RRs from packet + * @param pkt: the packet. position at start must be right after the query + * section. At end, right after EDNS data or no movement if failed. + * @param num: Limit of the number of records we want to parse. + * @return: 0 on success, 1 on failure. + */ +int skip_pkt_rrs(struct sldns_buffer* pkt, int num); + +/** * If EDNS data follows a query section, extract it and initialize edns struct. * @param pkt: the packet. position at start must be right after the query * section. At end, right after EDNS data or no movement if failed. diff --git a/util/data/msgreply.c b/util/data/msgreply.c index ec46e4724780..e3ee607b1540 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -117,6 +117,7 @@ construct_reply_info_base(struct regional* region, uint16_t flags, size_t qd, rep->ar_numrrsets = ar; rep->rrset_count = total; rep->security = sec; + rep->reason_bogus = LDNS_EDE_NONE; rep->authoritative = 0; /* array starts after the refs */ if(region) @@ -989,6 +990,36 @@ parse_reply_in_temp_region(sldns_buffer* pkt, struct regional* region, return rep; } +int edns_opt_list_append_ede(struct edns_option** list, struct regional* region, + sldns_ede_code code, const char *txt) +{ + struct edns_option** prevp; + struct edns_option* opt; + size_t txt_len = txt ? strlen(txt) : 0; + + /* allocate new element */ + opt = (struct edns_option*)regional_alloc(region, sizeof(*opt)); + if(!opt) + return 0; + opt->next = NULL; + opt->opt_code = LDNS_EDNS_EDE; + opt->opt_len = txt_len + sizeof(uint16_t); + opt->opt_data = regional_alloc(region, txt_len + sizeof(uint16_t)); + if(!opt->opt_data) + return 0; + sldns_write_uint16(opt->opt_data, (uint16_t)code); + if (txt_len) + memmove(opt->opt_data + 2, txt, txt_len); + + /* append at end of list */ + prevp = list; + while(*prevp != NULL) + prevp = &((*prevp)->next); + verbose(VERB_ALGO, "attached EDE code: %d with message: %s", code, txt); + *prevp = opt; + return 1; +} + int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, uint8_t* data, struct regional* region) { diff --git a/util/data/msgreply.h b/util/data/msgreply.h index 81c763fc7c3a..9538adc5a8b2 100644 --- a/util/data/msgreply.h +++ b/util/data/msgreply.h @@ -43,6 +43,7 @@ #define UTIL_DATA_MSGREPLY_H #include "util/storage/lruhash.h" #include "util/data/packed_rrset.h" +#include "sldns/rrdef.h" struct sldns_buffer; struct comm_reply; struct alloc_cache; @@ -168,6 +169,11 @@ struct reply_info { enum sec_status security; /** + * EDE (rfc8914) code with reason for DNSSEC bogus status. + */ + sldns_ede_code reason_bogus; + + /** * Number of RRsets in each section. * The answer section. Add up the RRs in every RRset to calculate * the number of RRs, and the count for the dns packet. @@ -528,7 +534,38 @@ void log_query_info(enum verbosity_value v, const char* str, * @return false on failure. */ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, - uint8_t* data, struct regional* region); + uint8_t* data, struct regional* region); + +/** + * Append edns EDE option to edns options list + * @param LIST: the edns option list to append the edns option to. + * @param REGION: region to allocate the new edns option. + * @param CODE: the EDE code. + * @param TXT: Additional text for the option + */ +#define EDNS_OPT_LIST_APPEND_EDE(LIST, REGION, CODE, TXT) \ + do { \ + struct { \ + uint16_t code; \ + char text[sizeof(TXT) - 1]; \ + } ede = { htons(CODE), TXT }; \ + verbose(VERB_ALGO, "attached EDE code: %d with" \ + " message: %s", CODE, TXT); \ + edns_opt_list_append((LIST), LDNS_EDNS_EDE, \ + sizeof(uint16_t) + sizeof(TXT) - 1, \ + (void *)&ede, (REGION)); \ + } while(0) + +/** + * Append edns EDE option to edns options list + * @param list: the edns option list to append the edns option to. + * @param region: region to allocate the new edns option. + * @param code: the EDE code. + * @param txt: Additional text for the option + * @return false on failure. + */ +int edns_opt_list_append_ede(struct edns_option** list, struct regional* region, + sldns_ede_code code, const char *txt); /** * Remove any option found on the edns option list that matches the code. |
