Home | History | Annotate | Download | only in src

Lines Matching refs:HEADER

19 static int add_resource_record(HEADER *header, char *limit, int *truncp, 
24 #define CHECK_LEN(header, pp, plen, len) \
25 ((size_t)((pp) - (unsigned char *)(header) + (len)) <= (plen))
27 #define ADD_RDLEN(header, pp, plen, len) \
28 (!CHECK_LEN(header, pp, plen, len) ? 0 : (long)((pp) += (len)), 1)
30 static int extract_name(HEADER *header, size_t plen, unsigned char **pp,
44 if (!CHECK_LEN(header, p, plen, 1))
51 if (!CHECK_LEN(header, p, plen, extrabytes))
75 if (!CHECK_LEN(header, p, plen, 1))
89 p = l + (unsigned char *)header;
111 if (!CHECK_LEN(header, p, plen, (count-1)>>3))
135 if (!CHECK_LEN(header, p, plen, l))
283 static unsigned char *skip_name(unsigned char *ansp, HEADER *header, size_t plen, int extrabytes)
289 if (!CHECK_LEN(header, ansp, plen, 1))
307 if (!CHECK_LEN(header, ansp, plen, 2))
324 if (!ADD_RDLEN(header, ansp, plen, len))
332 if (!CHECK_LEN(header, ansp, plen, extrabytes))
338 static unsigned char *skip_questions(HEADER *header, size_t plen)
341 unsigned char *ansp = (unsigned char *)(header+1);
343 for (q = ntohs(header->qdcount); q != 0; q--)
345 if (!(ansp = skip_name(ansp, header, plen, 4)))
353 static unsigned char *skip_section(unsigned char *ansp, int count, HEADER *header, size_t plen)
359 if (!(ansp = skip_name(ansp, header, plen, 10)))
363 if (!ADD_RDLEN(header, ansp, plen, rdlen))
376 unsigned int questions_crc(HEADER *header, size_t plen, char *name)
380 unsigned char *p1, *p = (unsigned char *)(header+1);
382 for (q = ntohs(header->qdcount); q != 0; q--)
384 if (!extract_name(header, plen, &p, name, 1, 4))
410 if (!CHECK_LEN(header, p, plen, 0))
418 size_t resize_packet(HEADER *header, size_t plen, unsigned char *pheader, size_t hlen)
420 unsigned char *ansp = skip_questions(header, plen);
426 if (!(ansp = skip_section(ansp, ntohs(header->ancount) + ntohs(header->nscount) + ntohs(header->arcount),
427 header, plen)))
431 if (pheader && ntohs(header->arcount) == 0)
435 header->arcount = htons(1);
439 return ansp - (unsigned char *)header;
442 unsigned char *find_pseudoheader(HEADER *header, size_t plen, size_t *len, unsigned char **p, int *is_sign)
449 int i, arcount = ntohs(header->arcount);
450 unsigned char *ansp = (unsigned char *)(header+1);
458 if (header->opcode == QUERY)
460 for (i = ntohs(header->qdcount); i != 0; i--)
462 if (!(ansp = skip_name(ansp, header, plen, 4)))
475 if (!(ansp = skip_questions(header, plen)))
482 if (!(ansp = skip_section(ansp, ntohs(header->ancount) + ntohs(header->nscount), header, plen)))
488 if (!(ansp = skip_name(ansp, header, plen, 10)))
496 if (!ADD_RDLEN(header, ansp, plen, rdlen))
530 static unsigned char *do_doctor(unsigned char *p, int count, HEADER *header, size_t qlen)
537 if (!(p = skip_name(p, header, qlen, 10)))
550 if (!CHECK_LEN(header, p, qlen, INADDRSZ))
570 header->aa = 0;
576 if (!ADD_RDLEN(header, p, qlen, rdlen))
583 static int find_soa(HEADER *header, size_t qlen)
591 if (!(p = skip_questions(header, qlen)) ||
592 !(p = do_doctor(p, ntohs(header->ancount), header, qlen)))
595 for (i = ntohs(header->nscount); i != 0; i--)
597 if (!(p = skip_name(p, header, qlen, 10)))
612 if (!(p = skip_name(p, header, qlen, 0)))
615 if (!(p = skip_name(p, header, qlen, 20)))
623 else if (!ADD_RDLEN(header, p, qlen, rdlen))
628 if (!do_doctor(p, ntohs(header->arcount), header, qlen))
641 int extract_addresses(HEADER *header, size_t qlen, char *name, time_t now)
654 ttl = find_soa(header, qlen);
658 p = (unsigned char *)(header+1);
660 for (i = ntohs(header->qdcount); i != 0; i--)
664 int flags = header->rcode == NXDOMAIN ? F_NXDOMAIN : 0;
668 if (!extract_name(header, qlen, &p, name, 1, 4))
689 if (!(p1 = skip_questions(header, qlen)))
692 for (j = ntohs(header->ancount); j != 0; j--)
696 if (!extract_name(header, qlen, &tmp, name, 1, 0) ||
697 !(res = extract_name(header, qlen, &p1, name, 0, 10)))
712 if (!extract_name(header, qlen, &p1, name, 1, 0))
727 if (!CHECK_LEN(header, p1, qlen, 0))
737 ttl = find_soa(header, qlen);
767 if (!(p1 = skip_questions(header, qlen)))
770 for (j = ntohs(header->ancount); j != 0; j--)
772 if (!(res = extract_name(header, qlen, &p1, name, 0, 10)))
798 if (!extract_name(header, qlen, &p1, name, 1, 0))
807 if (!CHECK_LEN(header, p1, qlen, addrlen))
828 if (!CHECK_LEN(header, p1, qlen, 0))
838 ttl = find_soa(header, qlen);
856 if (!header->tc)
866 unsigned short extract_request(HEADER *header, size_t qlen, char *name, unsigned short *typep)
868 unsigned char *p = (unsigned char *)(header+1);
874 if (ntohs(header->qdcount) != 1 || header->opcode != QUERY)
877 if (!extract_name(header, qlen, &p, name, 1, 4))
902 size_t setup_reply(HEADER *header, size_t qlen,
905 unsigned char *p = skip_questions(header, qlen);
907 header->qr = 1; /* response */
908 header->aa = 0; /* authoritive */
909 header->ra = 1; /* recursion if available */
910 header->tc = 0; /* not truncated */
911 header->nscount = htons(0);
912 header->arcount = htons(0);
913 header->ancount = htons(0); /* no answers unless changed below */
915 header->rcode = SERVFAIL; /* couldn't get memory */
917 header->rcode = NOERROR; /* empty domain */
919 header->rcode = NXDOMAIN;
922 header->rcode = NOERROR;
923 header->ancount = htons(1);
924 header->aa = 1;
925 add_resource_record(header, NULL, NULL, sizeof(HEADER), &p, ttl, NULL, T_A, C_IN, "4", addrp);
930 header->rcode = NOERROR;
931 header->ancount = htons(1);
932 header->aa = 1;
933 add_resource_record(header, NULL, NULL, sizeof(HEADER), &p, ttl, NULL, T_AAAA, C_IN, "6", addrp);
937 header->rcode = REFUSED;
939 return p - (unsigned char *)header;
977 int check_for_bogus_wildcard(HEADER *header, size_t qlen, char *name,
986 if (!(p = skip_questions(header, qlen)))
989 for (i = ntohs(header->ancount); i != 0; i--)
991 if (!extract_name(header, qlen, &p, name, 1, 10))
1001 if (!CHECK_LEN(header, p, qlen, INADDRSZ))
1017 if (!ADD_RDLEN(header, p, qlen, rdlen))
1024 static int add_resource_record(HEADER *header, char *limit, int *truncp, unsigned int nameoffset, unsigned char **pp,
1077 *offset = p - (unsigned char *)header;
1130 size_t answer_request(HEADER *header, char *limit, size_t qlen,
1152 if (find_pseudoheader(header, qlen, NULL, &pheader, &is_sign))
1173 if (ntohs(header->qdcount) == 0 || header->opcode != QUERY )
1181 if (!(ansp = skip_questions(header, qlen)))
1185 p = (unsigned char *)(header+1);
1187 for (q = ntohs(header->qdcount); q != 0; q--)
1190 nameoffset = p - (unsigned char *)header;
1193 if (!extract_name(header, qlen, &p, name, 1, 4))
1212 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1251 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1265 add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1298 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1339 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1365 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1407 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1444 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
1465 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
1482 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl, NULL,
1502 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
1531 if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
1581 if (add_resource_record(header, limit, NULL, rec->offset, &ansp,
1588 /* done all questions, set up header and return length of result */
1589 header->qr = 1; /* response */
1590 header->aa = auth; /* authoritive - only hosts and DHCP derived names. */
1591 header->ra = 1; /* recursion if available */
1592 header->tc = trunc; /* truncation */
1594 header->rcode = NXDOMAIN;
1596 header->rcode = NOERROR; /* no error */
1597 header->ancount = htons(anscount);
1598 header->nscount = htons(0);
1599 header->arcount = htons(addncount);
1600 return ansp - (unsigned char *)header;