Lines Matching refs:header
19 int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
33 if (!CHECK_LEN(header, p, plen, 1))
40 if (!CHECK_LEN(header, p, plen, extrabytes))
64 if (!CHECK_LEN(header, p, plen, 1))
78 p = l + (unsigned char *)header;
85 if (!CHECK_LEN(header, p, plen, l))
251 unsigned char *skip_name(unsigned char *ansp, struct dns_header *header, size_t plen, int extrabytes)
257 if (!CHECK_LEN(header, ansp, plen, 1))
275 if (!CHECK_LEN(header, ansp, plen, 2))
292 if (!ADD_RDLEN(header, ansp, plen, len))
300 if (!CHECK_LEN(header, ansp, plen, extrabytes))
306 unsigned char *skip_questions(struct dns_header *header, size_t plen)
309 unsigned char *ansp = (unsigned char *)(header+1);
311 for (q = ntohs(header->qdcount); q != 0; q--)
313 if (!(ansp = skip_name(ansp, header, plen, 4)))
321 unsigned char *skip_section(unsigned char *ansp, int count, struct dns_header *header, size_t plen)
327 if (!(ansp = skip_name(ansp, header, plen, 10)))
331 if (!ADD_RDLEN(header, ansp, plen, rdlen))
345 unsigned int questions_crc(struct dns_header *header, size_t plen, char *name)
349 unsigned char *p1, *p = (unsigned char *)(header+1);
351 for (q = ntohs(header->qdcount); q != 0; q--)
353 if (!extract_name(header, plen, &p, name, 1, 4))
379 if (!CHECK_LEN(header, p, plen, 0))
387 size_t resize_packet(struct dns_header *header, size_t plen, unsigned char *pheader, size_t hlen)
389 unsigned char *ansp = skip_questions(header, plen);
395 if (!(ansp = skip_section(ansp, ntohs(header->ancount) + ntohs(header->nscount) + ntohs(header->arcount),
396 header, plen)))
400 if (pheader && ntohs(header->arcount) == 0)
404 header->arcount = htons(1);
408 return ansp - (unsigned char *)header;
411 unsigned char *find_pseudoheader(struct dns_header *header, size_t plen, size_t *len, unsigned char **p, int *is_sign)
418 int i, arcount = ntohs(header->arcount);
419 unsigned char *ansp = (unsigned char *)(header+1);
427 if (OPCODE(header) == QUERY)
429 for (i = ntohs(header->qdcount); i != 0; i--)
431 if (!(ansp = skip_name(ansp, header, plen, 4)))
444 if (!(ansp = skip_questions(header, plen)))
451 if (!(ansp = skip_section(ansp, ntohs(header->ancount) + ntohs(header->nscount), header, plen)))
457 if (!(ansp = skip_name(ansp, header, plen, 10)))
465 if (!ADD_RDLEN(header, ansp, plen, rdlen))
487 struct dns_header *header;
492 static size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *limit,
498 if (!(p = find_pseudoheader(header, plen, NULL, NULL, &is_sign)))
504 if (!(p = skip_questions(header, plen)) ||
506 ntohs(header->ancount) + ntohs(header->nscount) + ntohs(header->arcount),
507 header, plen)))
519 header->arcount = htons(ntohs(header->arcount) + 1);
528 if (ntohs(header->arcount) != 1 ||
530 (!(p = skip_name(p, header, plen, 10))))
543 if (!CHECK_LEN(header, p, plen, rdlen))
574 return p - (unsigned char *)header;
597 parm->plen = add_pseudoheader(parm->header, parm->plen, parm->limit, EDNS0_OPTION_MAC, (unsigned char *)mac, maclen, 0);
602 size_t add_mac(struct dns_header *header, size_t plen, char *limit, union mysockaddr *l3)
609 if (ntohs(header->arcount) > 1)
612 parm.header = header;
694 size_t add_source_addr(struct dns_header *header, size_t plen, char *limit, union mysockaddr *source)
702 return add_pseudoheader(header, plen, (unsigned char *)limit, EDNS0_OPTION_CLIENT_SUBNET, (unsigned char *)&opt, len, 0);
706 size_t add_do_bit(struct dns_header *header, size_t plen, char *limit)
708 return add_pseudoheader(header, plen, (unsigned char *)limit, 0, NULL, 0, 1);
712 int check_source(struct dns_header *header, size_t plen, unsigned char *pseudoheader, union mysockaddr *peer)
724 if (!(p = skip_name(pseudoheader, header, plen, 10)))
730 if (!CHECK_LEN(header, p, plen, rdlen))
769 static unsigned char *do_doctor(unsigned char *p, int count, struct dns_header *header, size_t qlen, char *name, int *doctored)
777 if (!extract_name(header, qlen, &p, name, 1, 10))
780 else if (!(p = skip_name(p, header, qlen, 10)))
793 if (!CHECK_LEN(header, p, qlen, INADDRSZ))
813 header->hb3 &= ~HB3_AA;
822 if (!CHECK_LEN(header, p1, qlen, rdlen))
846 if (!ADD_RDLEN(header, p, qlen, rdlen))
853 static int find_soa(struct dns_header *header, size_t qlen, char *name, int *doctored)
861 if (!(p = skip_questions(header, qlen)) ||
862 !(p = do_doctor(p, ntohs(header->ancount), header, qlen, name, doctored)))
865 for (i = ntohs(header->nscount); i != 0; i--)
867 if (!(p = skip_name(p, header, qlen, 10)))
882 if (!(p = skip_name(p, header, qlen, 0)))
885 if (!(p = skip_name(p, header, qlen, 20)))
893 else if (!ADD_RDLEN(header, p, qlen, rdlen))
898 if (!do_doctor(p, ntohs(header->arcount), header, qlen, NULL, doctored))
911 int extract_addresses(struct dns_header *header, size_t qlen, char *name, time_t now,
930 ttl = find_soa(header, qlen, name, doctored);
938 p = (unsigned char *)(header+1);
940 for (i = ntohs(header->qdcount); i != 0; i--)
944 int flags = RCODE(header) == NXDOMAIN ? F_NXDOMAIN : 0;
949 if (!extract_name(header, qlen, &p, name, 1, 4))
970 if (!(p1 = skip_questions(header, qlen)))
973 for (j = ntohs(header->ancount); j != 0; j--)
977 if (!extract_name(header, qlen, &tmp, name, 1, 0) ||
978 !(res = extract_name(header, qlen, &p1, name, 0, 10)))
998 if (!extract_name(header, qlen, &p1, name, 1, 0))
1013 if (!CHECK_LEN(header, p1, qlen, 0))
1023 ttl = find_soa(header, qlen, NULL, doctored);
1051 if (!(p1 = skip_questions(header, qlen)))
1054 for (j = ntohs(header->ancount); j != 0; j--)
1056 if (!(res = extract_name(header, qlen, &p1, name, 0, 10)))
1093 if (!extract_name(header, qlen, &p1, name, 1, 0))
1102 if (!CHECK_LEN(header, p1, qlen, addrlen))
1148 if (!CHECK_LEN(header, p1, qlen, 0))
1157 ttl = find_soa(header, qlen, NULL, doctored);
1178 if (!(header->hb3 & HB3_TC) &&
1179 !(header->hb4 & HB4_CD) &&
1180 (header->hb4 & HB4_RA) &&
1189 unsigned int extract_request(struct dns_header *header, size_t qlen, char *name, unsigned short *typep)
1191 unsigned char *p = (unsigned char *)(header+1);
1197 if (ntohs(header->qdcount) != 1 || OPCODE(header) != QUERY)
1200 if (!extract_name(header, qlen, &p, name, 1, 4))
1223 size_t setup_reply(struct dns_header *header, size_t qlen,
1228 if (!(p = skip_questions(header, qlen)))
1232 header->hb3 = (header->hb3 & ~(HB3_AA | HB3_TC)) | HB3_QR;
1234 header->hb4 |= HB4_RA;
1236 header->nscount = htons(0);
1237 header->arcount = htons(0);
1238 header->ancount = htons(0); /* no answers unless changed below */
1240 SET_RCODE(header, SERVFAIL); /* couldn't get memory */
1242 SET_RCODE(header, NOERROR); /* empty domain */
1244 SET_RCODE(header, NXDOMAIN);
1247 SET_RCODE(header, NOERROR);
1248 header->ancount = htons(1);
1249 header->hb3 |= HB3_AA;
1250 add_resource_record(header, NULL, NULL, sizeof(struct dns_header), &p, ttl, NULL, T_A, C_IN, "4", addrp);
1255 SET_RCODE(header, NOERROR);
1256 header->ancount = htons(1);
1257 header->hb3 |= HB3_AA;
1258 add_resource_record(header, NULL, NULL, sizeof(struct dns_header), &p, ttl, NULL, T_AAAA, C_IN, "6", addrp);
1262 SET_RCODE(header, REFUSED);
1264 return p - (unsigned char *)header;
1312 int check_for_bogus_wildcard(struct dns_header *header, size_t qlen, char *name,
1321 if (!(p = skip_questions(header, qlen)))
1324 for (i = ntohs(header->ancount); i != 0; i--)
1326 if (!extract_name(header, qlen, &p, name, 1, 10))
1336 if (!CHECK_LEN(header, p, qlen, INADDRSZ))
1352 if (!ADD_RDLEN(header, p, qlen, rdlen))
1359 int check_for_ignored_address(struct dns_header *header, size_t qlen, struct bogus_addr *baddr)
1366 if (!(p = skip_questions(header, qlen)))
1369 for (i = ntohs(header->ancount); i != 0; i--)
1371 if (!(p = skip_name(p, header, qlen, 10)))
1381 if (!CHECK_LEN(header, p, qlen, INADDRSZ))
1389 if (!ADD_RDLEN(header, p, qlen, rdlen))
1396 int add_resource_record(struct dns_header *header, char *limit, int *truncp, int nameoffset, unsigned char **pp,
1470 *offset = p - (unsigned char *)header;
1528 size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
1546 if (header->hb4 & HB4_CD)
1550 *ad_reqd = header->hb4 & HB4_AD;
1559 if (find_pseudoheader(header, qlen, NULL, &pheader, NULL))
1575 if (ntohs(header->qdcount) == 0 || OPCODE(header) != QUERY )
1583 if (!(ansp = skip_questions(header, qlen)))
1587 p = (unsigned char *)(header+1);
1589 for (q = ntohs(header->qdcount); q != 0; q--)
1592 nameoffset = p - (unsigned char *)header;
1595 if (!extract_name(header, qlen, &p, name, 1, 4))
1629 if (ok && add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1676 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1699 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1721 add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1742 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1799 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1813 add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1840 add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1883 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1899 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1962 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
2000 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
2063 add_resource_record(header, limit, &trunc, nameoffset, &ansp,
2094 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
2140 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
2154 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
2173 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
2192 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
2209 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl, NULL,
2230 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
2277 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
2327 if (add_resource_record(header, limit, NULL, rec->offset, &ansp,
2334 /* done all questions, set up header and return length of result */
2336 header->hb3 = (header->hb3 & ~(HB3_AA | HB3_TC)) | HB3_QR;
2338 header->hb4 |= HB4_RA;
2342 header->hb3 |= HB3_AA;
2346 header->hb3 |= HB3_TC;
2349 SET_RCODE(header, NXDOMAIN);
2351 SET_RCODE(header, NOERROR); /* no error */
2352 header->ancount = htons(anscount);
2353 header->nscount = htons(0);
2354 header->arcount = htons(addncount);
2356 len = ansp - (unsigned char *)header;
2359 len = add_pseudoheader(header, len, (unsigned char *)limit, 0, NULL, 0, sec_reqd);
2362 header->hb4 |= HB4_AD;
2364 header->hb4 &= ~HB4_AD;