24 #include <vpp/app/version.h>
28 #include <dns/dns.api_enum.h>
29 #include <dns/dns.api_types.h>
31 #define REPLY_MSG_ID_BASE dm->msg_id_base
35 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
38 vl_print (handle, (char *)s); \
50 return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
83 return VNET_API_ERROR_NO_NAME_SERVERS;
104 if (n_vlib_mains > 1)
123 vl_api_dns_enable_disable_reply_t *rmp;
135 u8 * server_address_as_u8,
int is_add)
146 sizeof (ip6_address_t)))
151 clib_memcpy (ap, server_address_as_u8,
sizeof (*ap));
158 sizeof (ip6_address_t)))
164 return VNET_API_ERROR_NAME_SERVER_NOT_FOUND;
171 u8 * server_address_as_u8,
int is_add)
187 clib_memcpy (ap, server_address_as_u8,
sizeof (*ap));
200 return VNET_API_ERROR_NAME_SERVER_NOT_FOUND;
209 vl_api_dns_name_server_add_del_reply_t *rmp;
217 REPLY_MACRO (VL_API_DNS_NAME_SERVER_ADD_DEL_REPLY);
248 if (fib_index == (
u32) ~ 0)
271 (
"route to %U exists, fei %d, get_resolving_interface returned"
280 goto found_src_address;
298 VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_LOCALLY_ORIGINATED;
307 dns_request = (
u8 *) (udp + 1);
310 ip->ip_version_and_header_length = 0x45;
313 ip->protocol = IP_PROTOCOL_UDP;
315 ip->dst_address.as_u32 = server->
as_u32;
319 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dns_reply);
320 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dns);
357 int junk __attribute__ ((unused));
367 if (fib_index == (
u32) ~ 0)
388 goto found_src_address;
406 VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_LOCALLY_ORIGINATED;
413 dns_request = (
u8 *) (udp + 1);
416 ip->ip_version_traffic_class_and_flow_label =
417 clib_host_to_net_u32 (0x6 << 28);
423 ip->protocol = IP_PROTOCOL_UDP;
425 clib_memcpy (&
ip->dst_address, server, sizeof (ip6_address_t));
428 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dns_reply);
429 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dns);
455 int last_label_index;
462 last_label_index = 0;
469 rv[last_label_index] = (
i - last_label_index) - 1;
470 if ((
i - last_label_index) > 63)
472 i - last_label_index);
473 last_label_index =
i;
479 rv[last_label_index] = (
i - last_label_index) - 1;
502 *parse_from_here = 0;
505 if ((
label[0] & 0xC0) == 0xC0)
507 *parse_from_here =
label + 2;
520 if ((
label[0] & 0xC0) == 0xC0)
522 *parse_from_here =
label + 2;
531 if (*parse_from_here == 0)
532 *parse_from_here =
label;
572 qp = (dns_query_t *) (
request + qp_offset);
574 qp->type = clib_host_to_net_u16 (DNS_TYPE_A);
578 qp = (dns_query_t *) (((
u8 *) qp) +
vec_len (name_copy));
581 qp->type = clib_host_to_net_u16 (DNS_TYPE_AAAA);
590 h->id = clib_host_to_net_u16 (ep - dm->
entries);
594 h->flags = clib_host_to_net_u16 (
tmp);
595 h->qdcount = clib_host_to_net_u16 (2);
668 return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
671 return VNET_API_ERROR_NO_SUCH_ENTRY;
682 clib_warning (
"pool elt %d supposedly pending, but not found...",
702 return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
709 return VNET_API_ERROR_NO_SUCH_ENTRY;
722 u32 victim_index, start_index,
i;
727 return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
735 return VNET_API_ERROR_UNSPECIFIED;
742 for (
i = 0;
i < limit;
i++)
744 victim_index = (start_index +
i) % limit;
762 return VNET_API_ERROR_UNSPECIFIED;
773 return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
780 return VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
827 return VNET_API_ERROR_INVALID_VALUE;
842 u32 *indices_to_delete = 0;
865 for (
i = 0;
i <
vec_len (indices_to_delete);
i++)
871 indices_to_delete[
i]);
876 (dm, indices_to_delete[
i]);
899 memcpy (pr, t,
sizeof (*pr));
957 #define foreach_notification_to_move \
967 u32 ep_index,
u8 * reply)
985 h = (dns_header_t *) reply;
986 flags = clib_net_to_host_u16 (
h->flags);
1003 curpos = (
u8 *) (
h + 1);
1008 for (
i = 0;
i < clib_net_to_host_u16 (
h->qdcount);
i++)
1015 pos +=
sizeof (dns_query_t);
1019 if ((pos2[0] & 0xC0) == 0xC0)
1025 for (
i = 0;
i < clib_net_to_host_u16 (
h->anscount);
i++)
1027 rr = (dns_rr_t *) pos;
1028 switch (clib_net_to_host_u16 (rr->type))
1039 case DNS_TYPE_CNAME:
1047 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1049 if ((pos2[0] & 0xc0) == 0xc0)
1058 h->flags = clib_host_to_net_u16 (
flags);
1070 goto found_last_request;
1072 clib_warning (
"pool elt %d supposedly pending, but not found...", ep_index);
1081 _vec_len (cname) -= 1;
1100 _vec_len (next_ep->
name) -= 1;
1110 #define _(a) next_ep->a = ep->a; ep->a = 0;
1122 qp = (dns_query_t *) (
request + qp_offset);
1124 qp->type = clib_host_to_net_u16 (DNS_TYPE_A);
1127 qp = (dns_query_t *) (((
u8 *) qp) +
vec_len (name_copy));
1130 qp->type = clib_host_to_net_u16 (DNS_TYPE_AAAA);
1139 h->id = clib_host_to_net_u16 (next_ep - dm->
entries);
1143 h->qdcount = clib_host_to_net_u16 (2);
1170 u8 *curpos, *pos, *pos2;
1174 int pointer_chase, addr_set = 0;
1176 h = (dns_header_t *) response;
1177 flags = clib_net_to_host_u16 (
h->flags);
1189 return VNET_API_ERROR_NAME_SERVER_NO_SUCH_NAME;
1194 return VNET_API_ERROR_NAME_SERVER_NEXT_SERVER;
1198 if (clib_net_to_host_u16 (
h->anscount) < 1)
1199 return VNET_API_ERROR_NAME_SERVER_NO_ADDRESSES;
1201 curpos = (
u8 *) (
h + 1);
1207 if ((
len & 0xC0) == 0xC0)
1220 limit = clib_net_to_host_u16 (
h->qdcount);
1221 qp = (dns_query_t *) curpos;
1226 limit = clib_net_to_host_u16 (
h->anscount);
1228 for (
i = 0;
i < limit;
i++)
1230 pos = pos2 = curpos;
1234 if ((pos2[0] & 0xC0) == 0xC0)
1237 pos2 = response + ((pos2[0] & 0x3f) << 8) + pos2[1];
1246 if ((pos2[0] & 0xc0) == 0xc0)
1252 if (pointer_chase == 0)
1254 pos2 = response + ((pos2[0] & 0x3f) << 8) + pos2[1];
1262 if (pointer_chase == 0)
1265 rr = (dns_rr_t *) pos;
1267 switch (clib_net_to_host_u16 (rr->type))
1272 ttl = clib_net_to_host_u32 (rr->ttl);
1274 if (min_ttlp && *min_ttlp >
ttl)
1280 ttl = clib_net_to_host_u32 (rr->ttl);
1281 if (min_ttlp && *min_ttlp >
ttl)
1292 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1297 return VNET_API_ERROR_NAME_SERVER_NO_ADDRESSES;
1311 u8 *curpos, *pos, *pos2;
1316 u8 *junk __attribute__ ((unused));
1320 h = (dns_header_t *) response;
1321 flags = clib_net_to_host_u16 (
h->flags);
1333 return VNET_API_ERROR_NAME_SERVER_NO_SUCH_NAME;
1338 return VNET_API_ERROR_NAME_SERVER_NEXT_SERVER;
1342 if (clib_net_to_host_u16 (
h->anscount) < 1)
1343 return VNET_API_ERROR_NAME_SERVER_NO_ADDRESSES;
1345 curpos = (
u8 *) (
h + 1);
1351 if ((
len & 0xC0) == 0xC0)
1364 limit = clib_net_to_host_u16 (
h->qdcount);
1365 qp = (dns_query_t *) curpos;
1370 limit = clib_net_to_host_u16 (
h->anscount);
1372 for (
i = 0;
i < limit;
i++)
1374 pos = pos2 = curpos;
1378 if ((pos2[0] & 0xC0) == 0xC0)
1381 pos2 = response + ((pos2[0] & 0x3f) << 8) + pos2[1];
1390 if ((pos2[0] & 0xc0) == 0xc0)
1396 if (pointer_chase == 0)
1398 pos2 = response + ((pos2[0] & 0x3f) << 8) + pos2[1];
1406 if (pointer_chase == 0)
1409 rr = (dns_rr_t *) pos;
1411 switch (clib_net_to_host_u16 (rr->type))
1416 ttl = clib_net_to_host_u32 (rr->ttl);
1428 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1433 return VNET_API_ERROR_NAME_SERVER_NO_SUCH_NAME;
1507 u8 *lookup_name = 0;
1513 for (
i = 15;
i >= 0;
i--)
1516 nybble = (digit & 0x0F);
1518 vec_add1 (lookup_name, (nybble - 10) +
'a');
1520 vec_add1 (lookup_name, nybble +
'0');
1522 nybble = (digit & 0xF0) >> 4;
1524 vec_add1 (lookup_name, (nybble - 10) +
'a');
1526 vec_add1 (lookup_name, nybble +
'0');
1531 memcpy (lookup_name +
len,
"ip6.arpa", 8);
1535 for (
i = 3;
i >= 0;
i--)
1538 lookup_name =
format (lookup_name,
"%d.", digit);
1540 lookup_name =
format (lookup_name,
"in-addr.arpa");
1568 rmp->
retval = clib_host_to_net_u32 (
rv);
1596 u8 **result = va_arg (*args,
u8 **);
1597 u8 **namep = va_arg (*args,
u8 **);
1633 if (!(a4_set + a6_set))
1641 vec_validate (ce, qp_offset +
sizeof (dns_query_t) - 1);
1642 qp = (dns_query_t *) (ce + qp_offset);
1644 qp->type = clib_host_to_net_u16 (DNS_TYPE_ALL);
1650 h = (dns_header_t *) ce;
1656 h->qdcount = clib_host_to_net_u16 (1);
1657 h->anscount = clib_host_to_net_u16 (a4_set + a6_set);
1667 vec_add2 (ce, rru8,
sizeof (*rr) + 4);
1669 rr->type = clib_host_to_net_u16 (DNS_TYPE_A);
1671 rr->ttl = clib_host_to_net_u32 (86400);
1672 rr->rdlength = clib_host_to_net_u16 (4);
1673 memcpy (rr->rdata, &a4, sizeof (a4));
1680 vec_add2 (ce, rru8,
sizeof (*rr) + 16);
1682 rr->type = clib_host_to_net_u16 (DNS_TYPE_AAAA);
1684 rr->ttl = clib_host_to_net_u32 (86400);
1685 rr->rdlength = clib_host_to_net_u16 (16);
1686 memcpy (rr->rdata, &a6, sizeof (a6));
1700 u8 **curpos = va_arg (*args,
u8 **);
1701 int verbose = va_arg (*args,
int);
1706 s =
format (s,
" Name: ");
1714 for (
i = 0;
i <
len;
i++)
1727 qp = (dns_query_t *) pos;
1730 switch (clib_net_to_host_u16 (qp->type))
1733 s =
format (s,
"type A\n");
1736 s =
format (s,
"type AAAA\n");
1739 s =
format (s,
"type ALL\n");
1743 s =
format (s,
"type %d\n", clib_net_to_host_u16 (qp->type));
1748 pos +=
sizeof (*qp);
1764 u8 *reply = va_arg (*args,
u8 *);
1765 u8 **curpos = va_arg (*args,
u8 **);
1766 int verbose = va_arg (*args,
int);
1767 int *print_ip4 = va_arg (*args,
int *);
1768 int *print_ip6 = va_arg (*args,
int *);
1773 int pointer_chase = 0;
1775 u16 rrtype_host_byte_order;
1777 pos = pos2 = *curpos;
1783 if ((pos2[0] & 0xc0) == 0xc0)
1786 pos2 = reply + ((pos2[0] & 0x3f) << 8) + pos2[1];
1794 for (
i = 0;
i <
len;
i++)
1800 if ((pos2[0] & 0xc0) == 0xc0)
1806 if (pointer_chase == 0)
1808 pos2 = reply + ((pos2[0] & 0x3f) << 8) + pos2[1];
1826 if (pointer_chase == 0)
1829 rr = (dns_rr_t *) pos;
1830 rrtype_host_byte_order = clib_net_to_host_u16 (rr->type);
1832 switch (rrtype_host_byte_order)
1837 s =
format (s,
"A: ttl %d %U\n", clib_net_to_host_u32 (rr->ttl),
1844 clib_net_to_host_u32 (rr->ttl));
1849 pos +=
sizeof (*rr) + 4;
1855 s =
format (s,
"AAAA: ttl %d %U\n", clib_net_to_host_u32 (rr->ttl),
1862 clib_net_to_host_u32 (rr->ttl));
1866 pos +=
sizeof (*rr) + 16;
1872 s =
format (s,
"TEXT: ");
1873 for (
i = 0;
i < clib_net_to_host_u16 (rr->rdlength);
i++)
1877 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1880 case DNS_TYPE_HINFO:
1888 s =
format (s,
"HINFO: ");
1891 for (
i = 0;
i < *
len;
i++)
1896 for (
i = 0;
i < *
len;
i++)
1902 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1905 case DNS_TYPE_NAMESERVER:
1908 s =
format (s,
"Nameserver: ");
1912 if ((pos2[0] & 0xc0) == 0xc0)
1915 pos2 = reply + ((pos2[0] & 0x3f) << 8) + pos2[1];
1922 for (
i = 0;
i <
len;
i++)
1926 if (pos2[0] == 0xC0)
1927 pos2 = reply + pos2[1];
1936 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1939 case DNS_TYPE_MAIL_EXCHANGE:
1942 tp = (
u16 *) rr->rdata;
1944 s =
format (s,
"Mail Exchange: Preference %d ", (
u32)
1945 clib_net_to_host_u16 (*tp));
1947 pos2 = rr->rdata + 2;
1950 if (pos2[0] == 0xc0)
1951 pos2 = reply + pos2[1];
1957 for (
i = 0;
i <
len;
i++)
1961 if (pos2[0] == 0xC0)
1962 pos2 = reply + pos2[1];
1972 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
1976 case DNS_TYPE_CNAME:
1979 tp = (
u16 *) rr->rdata;
1981 if (rrtype_host_byte_order == DNS_TYPE_CNAME)
1982 s =
format (s,
"CNAME: ");
1989 if (pos2[0] == 0xc0)
1990 pos2 = reply + pos2[1];
1996 for (
i = 0;
i <
len;
i++)
2000 if (pos2[0] == 0xC0)
2001 pos2 = reply + pos2[1];
2010 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
2015 s =
format (s,
"type %d: len %d\n",
2016 (
int) clib_net_to_host_u16 (rr->type),
2017 sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength));
2018 pos +=
sizeof (*rr) + clib_net_to_host_u16 (rr->rdlength);
2030 u8 *reply_as_u8 = va_arg (*args,
u8 *);
2031 int verbose = va_arg (*args,
int);
2039 h = (dns_header_t *) reply_as_u8;
2040 id = clib_net_to_host_u16 (
h->id);
2041 flags = clib_net_to_host_u16 (
h->flags);
2047 s =
format (s,
" %s %s %s %s\n",
2052 s =
format (s,
" %d queries, %d answers, %d name-servers,"
2054 clib_net_to_host_u16 (
h->qdcount),
2055 clib_net_to_host_u16 (
h->anscount),
2056 clib_net_to_host_u16 (
h->nscount),
2057 clib_net_to_host_u16 (
h->arcount));
2060 curpos = (
u8 *) (
h + 1);
2065 s =
format (s,
" Queries:\n");
2066 for (
i = 0;
i < clib_net_to_host_u16 (
h->qdcount);
i++)
2075 s =
format (s,
" Replies:\n");
2077 for (
i = 0;
i < clib_net_to_host_u16 (
h->anscount);
i++)
2081 verbose, &print_ip4, &print_ip6);
2092 int verbose = va_arg (*args,
int);
2100 s =
format (s,
"The DNS cache is disabled...");
2106 s =
format (s,
"The DNS cache is empty...");
2117 s =
format (s,
"%s is not in the cache...",
name);
2127 s =
format (s,
"static u8 dns_reply_data_initializer[] =\n");
2159 if (time_left > 0.0)
2160 s =
format (s,
" TTL left %.1f", time_left);
2162 s =
format (s,
" EXPIRED");
2201 if (time_left > 0.0)
2202 s =
format (s,
" TTL left %.1f", time_left);
2204 s =
format (s,
" EXPIRED");
2207 s =
format (s,
" %d client notifications pending\n",
2238 if (
unformat (input,
"verbose %d", &verbose))
2240 else if (
unformat (input,
"verbose"))
2257 .path =
"show dns cache",
2258 .short_help =
"show dns cache [verbose [nn]]",
2294 .path =
"show dns servers",
2295 .short_help =
"show dns servers",
2321 if (is_add == -1 && is_clear == -1)
2332 case VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED:
2346 case VNET_API_ERROR_NO_SUCH_ENTRY:
2351 case VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED:
2377 case VNET_API_ERROR_ENTRY_ALREADY_EXISTS:
2396 .path =
"dns cache",
2397 .short_help =
"dns cache [add|del|clear] <name> [ip4][ip6]",
2402 #define DNS_FORMAT_TEST 1
2404 #if DNS_FORMAT_TEST > 0
2408 { 0x0, 0x0, 0x81, 0x80, 0x0, 0x1, 0x0, 0x10, 0x0, 0x0, 0x0, 0x0, 0x5,
2409 0x79,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 0x68,
2449 0x6f, 0x6f, 0x2d, 0x69, 0x6e, 0x63, 0xc0, 0x12, 0x78, 0x3a, 0x85, 0x44,
2450 0x0, 0x0, 0xe, 0x10, 0x0, 0x0, 0x1, 0x2c, 0x0, 0x1b, 0xaf, 0x80, 0x0, 0x0,
2456 0x00, 0x01, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
2457 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, 0x05,
2458 0x63, 0x69, 0x73, 0x63, 0x6f, 0x03, 0x63, 0x6f, 0x6d,
2460 0x00, 0x00, 0xff, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x05,
2461 0x00, 0x01, 0x00, 0x00, 0x0b, 0xd3, 0x00, 0x1a, 0x03,
2462 0x77, 0x77, 0x77, 0x05, 0x63, 0x69, 0x73, 0x63, 0x6f,
2463 0x03, 0x63, 0x6f, 0x6d, 0x06, 0x61, 0x6b, 0x61, 0x64,
2464 0x6e, 0x73, 0x03, 0x6e, 0x65, 0x74, 0x00,
2470 0x00, 0x01, 0x81, 0x80, 0x00, 0x01, 0x00, 0x08,
2472 0x00, 0x06, 0x00, 0x06, 0x0a, 0x6f, 0x72, 0x69,
2474 0x67, 0x69, 0x6e, 0x2d, 0x77, 0x77, 0x77, 0x05,
2476 0x63, 0x69, 0x73, 0x63, 0x6f, 0x03, 0x63, 0x6f,
2478 0x6d, 0x00, 0x00, 0xff, 0x00, 0x01, 0x0a, 0x6f,
2480 0x72, 0x69, 0x67, 0x69, 0x6e, 0x2d, 0x77, 0x77,
2482 0x77, 0x05, 0x43, 0x49, 0x53, 0x43, 0x4f, 0xc0,
2485 0x1d, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x05,
2488 0x9a, 0x00, 0x18, 0x15, 0x72, 0x63, 0x64,
2489 0x6e, 0x39, 0x2d, 0x31, 0x34, 0x70, 0x2d, 0x64, 0x63,
2490 0x7a, 0x30, 0x35, 0x6e, 0x2d, 0x67, 0x73, 0x73, 0x31,
2491 0xc0, 0x17, 0xc0, 0x26, 0x00, 0x02, 0x00, 0x01, 0x00,
2492 0x00, 0x05, 0x9a, 0x00, 0x1a, 0x17, 0x61, 0x6c, 0x6c,
2493 0x6e, 0x30, 0x31, 0x2d, 0x61, 0x67, 0x30, 0x39, 0x2d,
2494 0x64, 0x63, 0x7a, 0x30, 0x33, 0x6e, 0x2d, 0x67, 0x73,
2495 0x73, 0x31, 0xc0, 0x17, 0xc0, 0x26, 0x00, 0x02, 0x00,
2496 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00, 0x10, 0x0d, 0x72,
2497 0x74, 0x70, 0x35, 0x2d, 0x64, 0x6d, 0x7a, 0x2d, 0x67,
2498 0x73, 0x73, 0x31, 0xc0, 0x17, 0xc0, 0x26, 0x00, 0x02,
2499 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00, 0x18, 0x15,
2500 0x6d, 0x74, 0x76, 0x35, 0x2d, 0x61, 0x70, 0x31, 0x30,
2501 0x2d, 0x64, 0x63, 0x7a, 0x30, 0x36, 0x6e, 0x2d, 0x67,
2502 0x73, 0x73, 0x31, 0xc0, 0x17, 0xc0, 0x26, 0x00, 0x02,
2503 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00, 0x1b, 0x18,
2504 0x73, 0x6e, 0x67, 0x64, 0x63, 0x30, 0x31, 0x2d, 0x61,
2505 0x62, 0x30, 0x37, 0x2d, 0x64, 0x63, 0x7a, 0x30, 0x31,
2506 0x6e, 0x2d, 0x67, 0x73, 0x73, 0x31, 0xc0, 0x17, 0xc0,
2507 0x26, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a,
2508 0x00, 0x1a, 0x17, 0x61, 0x65, 0x72, 0x30, 0x31, 0x2d,
2509 0x72, 0x34, 0x63, 0x32, 0x35, 0x2d, 0x64, 0x63, 0x7a,
2510 0x30, 0x31, 0x6e, 0x2d, 0x67, 0x73, 0x73, 0x31, 0xc0,
2511 0x17, 0xc0, 0x26, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
2512 0x00, 0x81, 0x00, 0x04, 0x48, 0xa3, 0x04, 0xa1, 0xc0,
2513 0x26, 0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x82,
2514 0x00, 0x10, 0x20, 0x01, 0x04, 0x20, 0x12, 0x01, 0x00,
2515 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
2516 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x05,
2517 0x9a, 0x00, 0x02, 0xc0, 0xf4, 0xc0, 0x0c, 0x00, 0x02,
2518 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00, 0x02, 0xc0,
2519 0xcd, 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00,
2520 0x05, 0x9a, 0x00, 0x02, 0xc0, 0x8d, 0xc0, 0x0c, 0x00,
2521 0x02, 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00, 0x02,
2522 0xc0, 0x43, 0xc0, 0x0c, 0x00, 0x02, 0x00, 0x01, 0x00,
2523 0x00, 0x05, 0x9a, 0x00, 0x02, 0xc0, 0xa9, 0xc0, 0x0c,
2524 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x05, 0x9a, 0x00,
2525 0x02, 0xc0, 0x67, 0xc0, 0x8d, 0x00, 0x01, 0x00, 0x01,
2526 0x00, 0x00, 0x07, 0x08, 0x00, 0x04, 0x40, 0x66, 0xf6,
2527 0x05, 0xc0, 0xa9, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
2528 0x07, 0x08, 0x00, 0x04, 0xad, 0x24, 0xe0, 0x64, 0xc0,
2529 0x43, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x07, 0x08,
2530 0x00, 0x04, 0x48, 0xa3, 0x04, 0x1c, 0xc0, 0xf4, 0x00,
2531 0x01, 0x00, 0x01, 0x00, 0x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0, 0x1, 0x0, 0x0, 0x2, 0x57, 0x0, 0x9, 0x0, 0x32, 0x4, 0x61, 0x6c,
2567 0x74, 0x34, 0xc0, 0x9b, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2,
2569 0x0, 0x9, 0x0, 0x14, 0x4, 0x61, 0x6c, 0x74, 0x31, 0xc0, 0x9b
2575 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
2576 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, 0x0b,
2577 0x77, 0x65, 0x61, 0x74, 0x68, 0x65, 0x72, 0x6c, 0x69,
2578 0x6e, 0x6b, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0xff,
2579 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00,
2580 0x00, 0x0c, 0x9e, 0x00, 0x1f, 0x0e, 0x64, 0x33, 0x6b,
2581 0x72, 0x30, 0x67, 0x75, 0x62, 0x61, 0x31, 0x64, 0x76,
2582 0x77, 0x66, 0x0a, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x66,
2583 0x72, 0x6f, 0x6e, 0x74, 0x03, 0x6e, 0x65, 0x74, 0x00,
2593 u8 *dns_reply_data = 0;
2600 if (
unformat (input,
"verbose %d", &verbose))
2602 else if (
unformat (input,
"verbose"))
2622 case VNET_API_ERROR_NAME_SERVER_NO_ADDRESSES:
2644 .path =
"test dns format",
2645 .short_help =
"test dns format",
2654 u8 *dns_reply_data = 0;
2660 if (
unformat (input,
"verbose %d", &verbose))
2662 else if (
unformat (input,
"verbose"))
2684 .path =
"test dns unformat",
2685 .short_help =
"test dns unformat <name> [ip4][ip6]",
2704 _vec_len (
name) -= 1;
2730 .path =
"test dns expire",
2731 .short_help =
"test dns expire <name>",
2775 int is_recycle = (b0 != 0);
2827 if (b0->
flags & VLIB_BUFFER_NEXT_PRESENT)
2837 b0->
flags |= (VNET_BUFFER_F_LOCALLY_ORIGINATED
2838 | VLIB_BUFFER_TOTAL_LENGTH_VALID);
2848 if (fib_index == (
u32) ~ 0)
2868 "route to %U exists, fei %d, get_resolving_interface returned"
2878 goto found_src_address;
2889 dns_response = (
u8 *) (udp + 1);
2903 vec_validate (reply, qp_offset +
sizeof (dns_query_t) - 1);
2905 qp = (dns_query_t *) (reply + qp_offset);
2908 qp->type = clib_host_to_net_u16 (DNS_TYPE_A);
2910 qp->type = clib_host_to_net_u16 (DNS_TYPE_PTR);
2915 vec_insert (reply,
sizeof (dns_header_t), 0);
2917 dh = (dns_header_t *) reply;
2926 dh->flags = clib_host_to_net_u16 (
tmp);
2927 dh->qdcount = clib_host_to_net_u16 (1);
2928 dh->anscount = (is_fail == 0) ? clib_host_to_net_u16 (1) : 0;
2943 rr = (dns_rr_t *) rrptr;
2945 rr->type = clib_host_to_net_u16 (DNS_TYPE_A);
2946 rr->class = clib_host_to_net_u16 (1 );
2947 rr->ttl = clib_host_to_net_u32 (
ttl);
2948 rr->rdlength = clib_host_to_net_u16 (
sizeof (
ip4_address_t));
2959 rr = (dns_rr_t *) rrptr;
2960 rr->type = clib_host_to_net_u16 (DNS_TYPE_PTR);
2961 rr->class = clib_host_to_net_u16 (1 );
2962 rr->ttl = clib_host_to_net_u32 (
ttl);
2963 rr->rdlength = clib_host_to_net_u16 (
vec_len (label_vec));
2974 ip->ip_version_and_header_length = 0x45;
2977 ip->protocol = IP_PROTOCOL_UDP;
2984 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dns);
2995 if (is_recycle == 0)
3005 #include <dns/dns.api.c>
3028 .version = VPP_BUILD_VER,
3029 .description =
"Simple DNS name resolver",