23 #include <vpp/app/version.h>
27 #include <dns/dns.api_enum.h>
28 #include <dns/dns.api_types.h>
30 #define REPLY_MSG_ID_BASE dm->msg_id_base
34 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
37 vl_print (handle, (char *)s); \
49 return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
82 return VNET_API_ERROR_NO_NAME_SERVERS;
103 if (n_vlib_mains > 1)
122 vl_api_dns_enable_disable_reply_t *rmp;
134 u8 * server_address_as_u8,
int is_add)
145 sizeof (ip6_address_t)))
150 clib_memcpy (ap, server_address_as_u8,
sizeof (*ap));
157 sizeof (ip6_address_t)))
163 return VNET_API_ERROR_NAME_SERVER_NOT_FOUND;
170 u8 * server_address_as_u8,
int is_add)
186 clib_memcpy (ap, server_address_as_u8,
sizeof (*ap));
199 return VNET_API_ERROR_NAME_SERVER_NOT_FOUND;
208 vl_api_dns_name_server_add_del_reply_t *rmp;
216 REPLY_MACRO (VL_API_DNS_NAME_SERVER_ADD_DEL_REPLY);
247 VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_LOCALLY_ORIGINATED;
256 dns_request = (
u8 *) (udp + 1);
259 ip->ip_version_and_header_length = 0x45;
262 ip->protocol = IP_PROTOCOL_UDP;
264 ip->dst_address.as_u32 = server->
as_u32;
268 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dns_reply);
269 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dns);
300 int junk __attribute__ ((unused));
316 VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_LOCALLY_ORIGINATED;
323 dns_request = (
u8 *) (udp + 1);
326 ip->ip_version_traffic_class_and_flow_label =
327 clib_host_to_net_u32 (0x6 << 28);
333 ip->protocol = IP_PROTOCOL_UDP;
335 clib_memcpy (&
ip->dst_address, server, sizeof (ip6_address_t));
338 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dns_reply);
339 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dns);
365 int last_label_index;
372 last_label_index = 0;
379 rv[last_label_index] = (
i - last_label_index) - 1;
380 if ((
i - last_label_index) > 63)
382 i - last_label_index);
383 last_label_index =
i;
389 rv[last_label_index] = (
i - last_label_index) - 1;
412 *parse_from_here = 0;
415 if ((
label[0] & 0xC0) == 0xC0)
417 *parse_from_here =
label + 2;
430 if ((
label[0] & 0xC0) == 0xC0)
432 *parse_from_here =
label + 2;
441 if (*parse_from_here == 0)
442 *parse_from_here =
label;
482 qp = (dns_query_t *) (
request + qp_offset);
484 qp->type = clib_host_to_net_u16 (DNS_TYPE_A);
488 qp = (dns_query_t *) (((
u8 *) qp) +
vec_len (name_copy));
491 qp->type = clib_host_to_net_u16 (DNS_TYPE_AAAA);
500 h->id = clib_host_to_net_u16 (ep - dm->
entries);
504 h->flags = clib_host_to_net_u16 (
tmp);
505 h->qdcount = clib_host_to_net_u16 (2);
578 return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
581 return VNET_API_ERROR_NO_SUCH_ENTRY;
592 clib_warning (
"pool elt %d supposedly pending, but not found...",
612 return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
619 return VNET_API_ERROR_NO_SUCH_ENTRY;
632 u32 victim_index, start_index,
i;
637 return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
645 return VNET_API_ERROR_UNSPECIFIED;
652 for (
i = 0;
i < limit;
i++)
654 victim_index = (start_index +
i) % limit;
672 return VNET_API_ERROR_UNSPECIFIED;
683 return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
690 return VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
737 return VNET_API_ERROR_INVALID_VALUE;
752 u32 *indices_to_delete = 0;
775 for (
i = 0;
i <
vec_len (indices_to_delete);
i++)
781 indices_to_delete[
i]);
786 (dm, indices_to_delete[
i]);
809 memcpy (pr, t,
sizeof (*pr));
867 #define foreach_notification_to_move \
877 u32 ep_index,
u8 * reply)
895 h = (dns_header_t *) reply;
896 flags = clib_net_to_host_u16 (
h->flags);
913 curpos = (
u8 *) (
h + 1);
918 for (
i = 0;
i < clib_net_to_host_u16 (
h->qdcount);
i++)
925 pos +=
sizeof (dns_query_t);
929 if ((pos2[0] & 0xC0) == 0xC0)
935 for (
i = 0;
i < clib_net_to_host_u16 (
h->anscount);
i++)
937 rr = (dns_rr_t *) pos;
938 switch (clib_net_to_host_u16 (rr->type))
957 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
959 if ((pos2[0] & 0xc0) == 0xc0)
968 h->flags = clib_host_to_net_u16 (
flags);
980 goto found_last_request;
982 clib_warning (
"pool elt %d supposedly pending, but not found...", ep_index);
991 _vec_len (cname) -= 1;
1010 _vec_len (next_ep->
name) -= 1;
1020 #define _(a) next_ep->a = ep->a; ep->a = 0;
1032 qp = (dns_query_t *) (
request + qp_offset);
1034 qp->type = clib_host_to_net_u16 (DNS_TYPE_A);
1037 qp = (dns_query_t *) (((
u8 *) qp) +
vec_len (name_copy));
1040 qp->type = clib_host_to_net_u16 (DNS_TYPE_AAAA);
1049 h->id = clib_host_to_net_u16 (next_ep - dm->
entries);
1053 h->qdcount = clib_host_to_net_u16 (2);
1080 u8 *curpos, *pos, *pos2;
1084 int pointer_chase, addr_set = 0;
1086 h = (dns_header_t *) response;
1087 flags = clib_net_to_host_u16 (
h->flags);
1099 return VNET_API_ERROR_NAME_SERVER_NO_SUCH_NAME;
1104 return VNET_API_ERROR_NAME_SERVER_NEXT_SERVER;
1108 if (clib_net_to_host_u16 (
h->anscount) < 1)
1109 return VNET_API_ERROR_NAME_SERVER_NO_ADDRESSES;
1111 curpos = (
u8 *) (
h + 1);
1117 if ((
len & 0xC0) == 0xC0)
1130 limit = clib_net_to_host_u16 (
h->qdcount);
1131 qp = (dns_query_t *) curpos;
1136 limit = clib_net_to_host_u16 (
h->anscount);
1138 for (
i = 0;
i < limit;
i++)
1140 pos = pos2 = curpos;
1144 if ((pos2[0] & 0xC0) == 0xC0)
1147 pos2 = response + ((pos2[0] & 0x3f) << 8) + pos2[1];
1156 if ((pos2[0] & 0xc0) == 0xc0)
1162 if (pointer_chase == 0)
1164 pos2 = response + ((pos2[0] & 0x3f) << 8) + pos2[1];
1172 if (pointer_chase == 0)
1175 rr = (dns_rr_t *) pos;
1177 switch (clib_net_to_host_u16 (rr->type))
1182 ttl = clib_net_to_host_u32 (rr->ttl);
1184 if (min_ttlp && *min_ttlp >
ttl)
1190 ttl = clib_net_to_host_u32 (rr->ttl);
1191 if (min_ttlp && *min_ttlp >
ttl)
1202 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1207 return VNET_API_ERROR_NAME_SERVER_NO_ADDRESSES;
1221 u8 *curpos, *pos, *pos2;
1226 u8 *junk __attribute__ ((unused));
1230 h = (dns_header_t *) response;
1231 flags = clib_net_to_host_u16 (
h->flags);
1243 return VNET_API_ERROR_NAME_SERVER_NO_SUCH_NAME;
1248 return VNET_API_ERROR_NAME_SERVER_NEXT_SERVER;
1252 if (clib_net_to_host_u16 (
h->anscount) < 1)
1253 return VNET_API_ERROR_NAME_SERVER_NO_ADDRESSES;
1255 curpos = (
u8 *) (
h + 1);
1261 if ((
len & 0xC0) == 0xC0)
1274 limit = clib_net_to_host_u16 (
h->qdcount);
1275 qp = (dns_query_t *) curpos;
1280 limit = clib_net_to_host_u16 (
h->anscount);
1282 for (
i = 0;
i < limit;
i++)
1284 pos = pos2 = curpos;
1288 if ((pos2[0] & 0xC0) == 0xC0)
1291 pos2 = response + ((pos2[0] & 0x3f) << 8) + pos2[1];
1300 if ((pos2[0] & 0xc0) == 0xc0)
1306 if (pointer_chase == 0)
1308 pos2 = response + ((pos2[0] & 0x3f) << 8) + pos2[1];
1316 if (pointer_chase == 0)
1319 rr = (dns_rr_t *) pos;
1321 switch (clib_net_to_host_u16 (rr->type))
1326 ttl = clib_net_to_host_u32 (rr->ttl);
1338 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1343 return VNET_API_ERROR_NAME_SERVER_NO_SUCH_NAME;
1417 u8 *lookup_name = 0;
1423 for (
i = 15;
i >= 0;
i--)
1426 nybble = (digit & 0x0F);
1428 vec_add1 (lookup_name, (nybble - 10) +
'a');
1430 vec_add1 (lookup_name, nybble +
'0');
1432 nybble = (digit & 0xF0) >> 4;
1434 vec_add1 (lookup_name, (nybble - 10) +
'a');
1436 vec_add1 (lookup_name, nybble +
'0');
1441 memcpy (lookup_name +
len,
"ip6.arpa", 8);
1445 for (
i = 3;
i >= 0;
i--)
1448 lookup_name =
format (lookup_name,
"%d.", digit);
1450 lookup_name =
format (lookup_name,
"in-addr.arpa");
1478 rmp->
retval = clib_host_to_net_u32 (
rv);
1506 u8 **result = va_arg (*args,
u8 **);
1507 u8 **namep = va_arg (*args,
u8 **);
1543 if (!(a4_set + a6_set))
1551 vec_validate (ce, qp_offset +
sizeof (dns_query_t) - 1);
1552 qp = (dns_query_t *) (ce + qp_offset);
1554 qp->type = clib_host_to_net_u16 (DNS_TYPE_ALL);
1560 h = (dns_header_t *) ce;
1566 h->qdcount = clib_host_to_net_u16 (1);
1567 h->anscount = clib_host_to_net_u16 (a4_set + a6_set);
1577 vec_add2 (ce, rru8,
sizeof (*rr) + 4);
1579 rr->type = clib_host_to_net_u16 (DNS_TYPE_A);
1581 rr->ttl = clib_host_to_net_u32 (86400);
1582 rr->rdlength = clib_host_to_net_u16 (4);
1583 memcpy (rr->rdata, &a4, sizeof (a4));
1590 vec_add2 (ce, rru8,
sizeof (*rr) + 16);
1592 rr->type = clib_host_to_net_u16 (DNS_TYPE_AAAA);
1594 rr->ttl = clib_host_to_net_u32 (86400);
1595 rr->rdlength = clib_host_to_net_u16 (16);
1596 memcpy (rr->rdata, &a6, sizeof (a6));
1610 u8 **curpos = va_arg (*args,
u8 **);
1611 int verbose = va_arg (*args,
int);
1616 s =
format (s,
" Name: ");
1624 for (
i = 0;
i <
len;
i++)
1637 qp = (dns_query_t *) pos;
1640 switch (clib_net_to_host_u16 (qp->type))
1643 s =
format (s,
"type A\n");
1646 s =
format (s,
"type AAAA\n");
1649 s =
format (s,
"type ALL\n");
1653 s =
format (s,
"type %d\n", clib_net_to_host_u16 (qp->type));
1658 pos +=
sizeof (*qp);
1674 u8 *reply = va_arg (*args,
u8 *);
1675 u8 **curpos = va_arg (*args,
u8 **);
1676 int verbose = va_arg (*args,
int);
1677 int *print_ip4 = va_arg (*args,
int *);
1678 int *print_ip6 = va_arg (*args,
int *);
1683 int pointer_chase = 0;
1685 u16 rrtype_host_byte_order;
1687 pos = pos2 = *curpos;
1693 if ((pos2[0] & 0xc0) == 0xc0)
1696 pos2 = reply + ((pos2[0] & 0x3f) << 8) + pos2[1];
1704 for (
i = 0;
i <
len;
i++)
1710 if ((pos2[0] & 0xc0) == 0xc0)
1716 if (pointer_chase == 0)
1718 pos2 = reply + ((pos2[0] & 0x3f) << 8) + pos2[1];
1736 if (pointer_chase == 0)
1739 rr = (dns_rr_t *) pos;
1740 rrtype_host_byte_order = clib_net_to_host_u16 (rr->type);
1742 switch (rrtype_host_byte_order)
1747 s =
format (s,
"A: ttl %d %U\n", clib_net_to_host_u32 (rr->ttl),
1754 clib_net_to_host_u32 (rr->ttl));
1759 pos +=
sizeof (*rr) + 4;
1765 s =
format (s,
"AAAA: ttl %d %U\n", clib_net_to_host_u32 (rr->ttl),
1772 clib_net_to_host_u32 (rr->ttl));
1776 pos +=
sizeof (*rr) + 16;
1782 s =
format (s,
"TEXT: ");
1783 for (
i = 0;
i < clib_net_to_host_u16 (rr->rdlength);
i++)
1787 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1790 case DNS_TYPE_HINFO:
1798 s =
format (s,
"HINFO: ");
1801 for (
i = 0;
i < *
len;
i++)
1806 for (
i = 0;
i < *
len;
i++)
1812 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1815 case DNS_TYPE_NAMESERVER:
1818 s =
format (s,
"Nameserver: ");
1822 if ((pos2[0] & 0xc0) == 0xc0)
1825 pos2 = reply + ((pos2[0] & 0x3f) << 8) + pos2[1];
1832 for (
i = 0;
i <
len;
i++)
1836 if (pos2[0] == 0xC0)
1837 pos2 = reply + pos2[1];
1846 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1849 case DNS_TYPE_MAIL_EXCHANGE:
1852 tp = (
u16 *) rr->rdata;
1854 s =
format (s,
"Mail Exchange: Preference %d ", (
u32)
1855 clib_net_to_host_u16 (*tp));
1857 pos2 = rr->rdata + 2;
1860 if (pos2[0] == 0xc0)
1861 pos2 = reply + pos2[1];
1867 for (
i = 0;
i <
len;
i++)
1871 if (pos2[0] == 0xC0)
1872 pos2 = reply + pos2[1];
1882 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1886 case DNS_TYPE_CNAME:
1889 tp = (
u16 *) rr->rdata;
1891 if (rrtype_host_byte_order == DNS_TYPE_CNAME)
1892 s =
format (s,
"CNAME: ");
1899 if (pos2[0] == 0xc0)
1900 pos2 = reply + pos2[1];
1906 for (
i = 0;
i <
len;
i++)
1910 if (pos2[0] == 0xC0)
1911 pos2 = reply + pos2[1];
1920 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1925 s =
format (s,
"type %d: len %d\n",
1926 (
int) clib_net_to_host_u16 (rr->type),
1927 sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength));
1928 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1940 u8 *reply_as_u8 = va_arg (*args,
u8 *);
1941 int verbose = va_arg (*args,
int);
1949 h = (dns_header_t *) reply_as_u8;
1950 id = clib_net_to_host_u16 (
h->id);
1951 flags = clib_net_to_host_u16 (
h->flags);
1957 s =
format (s,
" %s %s %s %s\n",
1962 s =
format (s,
" %d queries, %d answers, %d name-servers,"
1964 clib_net_to_host_u16 (
h->qdcount),
1965 clib_net_to_host_u16 (
h->anscount),
1966 clib_net_to_host_u16 (
h->nscount),
1967 clib_net_to_host_u16 (
h->arcount));
1970 curpos = (
u8 *) (
h + 1);
1975 s =
format (s,
" Queries:\n");
1976 for (
i = 0;
i < clib_net_to_host_u16 (
h->qdcount);
i++)
1985 s =
format (s,
" Replies:\n");
1987 for (
i = 0;
i < clib_net_to_host_u16 (
h->anscount);
i++)
1991 verbose, &print_ip4, &print_ip6);
2002 int verbose = va_arg (*args,
int);
2010 s =
format (s,
"The DNS cache is disabled...");
2016 s =
format (s,
"The DNS cache is empty...");
2027 s =
format (s,
"%s is not in the cache...",
name);
2037 s =
format (s,
"static u8 dns_reply_data_initializer[] =\n");
2069 if (time_left > 0.0)
2070 s =
format (s,
" TTL left %.1f", time_left);
2072 s =
format (s,
" EXPIRED");
2111 if (time_left > 0.0)
2112 s =
format (s,
" TTL left %.1f", time_left);
2114 s =
format (s,
" EXPIRED");
2117 s =
format (s,
" %d client notifications pending\n",
2148 if (
unformat (input,
"verbose %d", &verbose))
2150 else if (
unformat (input,
"verbose"))
2167 .path =
"show dns cache",
2168 .short_help =
"show dns cache [verbose [nn]]",
2204 .path =
"show dns servers",
2205 .short_help =
"show dns servers",
2231 if (is_add == -1 && is_clear == -1)
2242 case VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED:
2256 case VNET_API_ERROR_NO_SUCH_ENTRY:
2261 case VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED:
2287 case VNET_API_ERROR_ENTRY_ALREADY_EXISTS:
2306 .path =
"dns cache",
2307 .short_help =
"dns cache [add|del|clear] <name> [ip4][ip6]",
2312 #define DNS_FORMAT_TEST 1
2314 #if DNS_FORMAT_TEST > 0
2318 { 0x0, 0x0, 0x81, 0x80, 0x0, 0x1, 0x0, 0x10, 0x0, 0x0, 0x0, 0x0, 0x5,
2319 0x79, 0x61, 0x68, 0x6f, 0x6f, 0x3, 0x63, 0x6f, 0x6d,
2324 0x0, 0x10, 0x0, 0x1, 0x0, 0x0, 0x6, 0x5c, 0x0, 0x24, 0x23,
2325 0x76, 0x3d, 0x73, 0x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x1b, 0xaf, 0x80, 0x0, 0x0,
2366 0x00, 0x01, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
2367 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, 0x05,
2368 0x63, 0x69, 0x73, 0x63, 0x6f, 0x03, 0x63, 0x6f, 0x6d,
2370 0x00, 0x00, 0xff, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x05,
2371 0x00, 0x01, 0x00, 0x00, 0x0b, 0xd3, 0x00, 0x1a, 0x03,
2372 0x77, 0x77, 0x77, 0x05, 0x63, 0x69, 0x73, 0x63, 0x6f,
2373 0x03, 0x63, 0x6f, 0x6d, 0x06, 0x61, 0x6b, 0x61, 0x64,
2374 0x6e, 0x73, 0x03, 0x6e, 0x65, 0x74, 0x00,
2380 0x00, 0x01, 0x81, 0x80, 0x00, 0x01, 0x00, 0x08,
2382 0x00, 0x06, 0x00, 0x06, 0x0a, 0x6f, 0x72, 0x69,
2384 0x67, 0x69, 0x6e, 0x2d, 0x77, 0x77, 0x77, 0x05,
2386 0x63, 0x69, 0x73, 0x63, 0x6f, 0x03, 0x63, 0x6f,
2388 0x6d, 0x00, 0x00, 0xff, 0x00, 0x01, 0x0a, 0x6f,
2390 0x72, 0x69, 0x67, 0x69, 0x6e, 0x2d, 0x77, 0x77,
2392 0x77, 0x05, 0x43, 0x49, 0x53, 0x43, 0x4f, 0xc0,
2395 0x1d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x05,
2398 0x9a, 0x00, 0x18, 0x15, 0x72, 0x63, 0x64,
2399 0x6e, 0x39, 0x2d, 0x31, 0x34, 0x70, 0x2d, 0x64, 0x63,
2400 0x7a, 0x30, 0x35, 0x6e, 0x2d, 0x67, 0x73, 0x73, 0x31,
2401 0xc0, 0x17, 0xc0, 0x26, 0x00, 0x02, 0x00, 0x01, 0x00,
2402 0x00, 0x05, 0x9a, 0x00, 0x1a, 0x17, 0x61, 0x6c, 0x6c,
2403 0x6e, 0x30, 0x31, 0x2d, 0x61, 0x67, 0x30, 0x39, 0x2d,
2404 0x64, 0x63, 0x7a, 0x30, 0x33, 0x6e, 0x2d, 0x67, 0x73,
2405 0x73, 0x31, 0xc0, 0x17, 0xc0, 0x26, 0x00, 0x02, 0x00,
2406 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00, 0x10, 0x0d, 0x72,
2407 0x74, 0x70, 0x35, 0x2d, 0x64, 0x6d, 0x7a, 0x2d, 0x67,
2408 0x73, 0x73, 0x31, 0xc0, 0x17, 0xc0, 0x26, 0x00, 0x02,
2409 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00, 0x18, 0x15,
2410 0x6d, 0x74, 0x76, 0x35, 0x2d, 0x61, 0x70, 0x31, 0x30,
2411 0x2d, 0x64, 0x63, 0x7a, 0x30, 0x36, 0x6e, 0x2d, 0x67,
2412 0x73, 0x73, 0x31, 0xc0, 0x17, 0xc0, 0x26, 0x00, 0x02,
2413 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00, 0x1b, 0x18,
2414 0x73, 0x6e, 0x67, 0x64, 0x63, 0x30, 0x31, 0x2d, 0x61,
2415 0x62, 0x30, 0x37, 0x2d, 0x64, 0x63, 0x7a, 0x30, 0x31,
2416 0x6e, 0x2d, 0x67, 0x73, 0x73, 0x31, 0xc0, 0x17, 0xc0,
2417 0x26, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a,
2418 0x00, 0x1a, 0x17, 0x61, 0x65, 0x72, 0x30, 0x31, 0x2d,
2419 0x72, 0x34, 0x63, 0x32, 0x35, 0x2d, 0x64, 0x63, 0x7a,
2420 0x30, 0x31, 0x6e, 0x2d, 0x67, 0x73, 0x73, 0x31, 0xc0,
2421 0x17, 0xc0, 0x26, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
2422 0x00, 0x81, 0x00, 0x04, 0x48, 0xa3, 0x04, 0xa1, 0xc0,
2423 0x26, 0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x82,
2424 0x00, 0x10, 0x20, 0x01, 0x04, 0x20, 0x12, 0x01, 0x00,
2425 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
2426 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x05,
2427 0x9a, 0x00, 0x02, 0xc0, 0xf4, 0xc0, 0x0c, 0x00, 0x02,
2428 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00, 0x02, 0xc0,
2429 0xcd, 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00,
2430 0x05, 0x9a, 0x00, 0x02, 0xc0, 0x8d, 0xc0, 0x0c, 0x00,
2431 0x02, 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00, 0x02,
2432 0xc0, 0x43, 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00,
2433 0x00, 0x05, 0x9a, 0x00, 0x02, 0xc0, 0xa9, 0xc0, 0x0c,
2434 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00,
2435 0x02, 0xc0, 0x67, 0xc0, 0x8d, 0x00, 0x01, 0x00, 0x01,
2436 0x00, 0x00, 0x07, 0x08, 0x00, 0x04, 0x40, 0x66, 0xf6,
2437 0x05, 0xc0, 0xa9, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
2438 0x07, 0x08, 0x00, 0x04, 0xad, 0x24, 0xe0, 0x64, 0xc0,
2439 0x43, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x07, 0x08,
2440 0x00, 0x04, 0x48, 0xa3, 0x04, 0x1c, 0xc0, 0xf4, 0x00,
2441 0x01, 0x00, 0x01, 0x00, 0x00, 0x07, 0x08, 0x00, 0x04,
2442 0xad, 0x26, 0xd4, 0x6c, 0xc0, 0x67, 0x00, 0x01, 0x00,
2443 0x01, 0x00, 0x00, 0x07, 0x08, 0x00, 0x04, 0xad, 0x25,
2444 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0x0, 0x2,
2479 0x0, 0x9, 0x0, 0x14, 0x4, 0x61, 0x6c, 0x74, 0x31, 0xc0, 0x9b
2485 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
2486 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, 0x0b,
2487 0x77, 0x65, 0x61, 0x74, 0x68, 0x65, 0x72, 0x6c, 0x69,
2488 0x6e, 0x6b, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0xff,
2489 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00,
2490 0x00, 0x0c, 0x9e, 0x00, 0x1f, 0x0e, 0x64, 0x33, 0x6b,
2491 0x72, 0x30, 0x67, 0x75, 0x62, 0x61, 0x31, 0x64, 0x76,
2492 0x77, 0x66, 0x0a, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x66,
2493 0x72, 0x6f, 0x6e, 0x74, 0x03, 0x6e, 0x65, 0x74, 0x00,
2503 u8 *dns_reply_data = 0;
2510 if (
unformat (input,
"verbose %d", &verbose))
2512 else if (
unformat (input,
"verbose"))
2532 case VNET_API_ERROR_NAME_SERVER_NO_ADDRESSES:
2554 .path =
"test dns format",
2555 .short_help =
"test dns format",
2564 u8 *dns_reply_data = 0;
2570 if (
unformat (input,
"verbose %d", &verbose))
2572 else if (
unformat (input,
"verbose"))
2594 .path =
"test dns unformat",
2595 .short_help =
"test dns unformat <name> [ip4][ip6]",
2614 _vec_len (
name) -= 1;
2640 .path =
"test dns expire",
2641 .short_help =
"test dns expire <name>",
2679 int is_recycle = (b0 != 0);
2731 if (b0->
flags & VLIB_BUFFER_NEXT_PRESENT)
2741 b0->
flags |= (VNET_BUFFER_F_LOCALLY_ORIGINATED
2742 | VLIB_BUFFER_TOTAL_LENGTH_VALID);
2752 dns_response = (
u8 *) (udp + 1);
2766 vec_validate (reply, qp_offset +
sizeof (dns_query_t) - 1);
2768 qp = (dns_query_t *) (reply + qp_offset);
2771 qp->type = clib_host_to_net_u16 (DNS_TYPE_A);
2773 qp->type = clib_host_to_net_u16 (DNS_TYPE_PTR);
2778 vec_insert (reply,
sizeof (dns_header_t), 0);
2780 dh = (dns_header_t *) reply;
2789 dh->flags = clib_host_to_net_u16 (
tmp);
2790 dh->qdcount = clib_host_to_net_u16 (1);
2791 dh->anscount = (is_fail == 0) ? clib_host_to_net_u16 (1) : 0;
2806 rr = (dns_rr_t *) rrptr;
2808 rr->type = clib_host_to_net_u16 (DNS_TYPE_A);
2809 rr->class = clib_host_to_net_u16 (1 );
2810 rr->ttl = clib_host_to_net_u32 (
ttl);
2811 rr->rdlength = clib_host_to_net_u16 (
sizeof (
ip4_address_t));
2822 rr = (dns_rr_t *) rrptr;
2823 rr->type = clib_host_to_net_u16 (DNS_TYPE_PTR);
2824 rr->class = clib_host_to_net_u16 (1 );
2825 rr->ttl = clib_host_to_net_u32 (
ttl);
2826 rr->rdlength = clib_host_to_net_u16 (
vec_len (label_vec));
2837 ip->ip_version_and_header_length = 0x45;
2840 ip->protocol = IP_PROTOCOL_UDP;
2847 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dns);
2858 if (is_recycle == 0)
2868 #include <dns/dns.api.c>
2888 .init_order =
VLIB_INITS (
"flow_classify_init",
"dns_init"),
2893 .version = VPP_BUILD_VER,
2894 .description =
"Simple DNS name resolver",