33#include "ipv6/ip64-addr.h"
34#include "ip64/ip64-dns64.h"
39#define LOG_MODULE "IP64"
40#define LOG_LEVEL LOG_LEVEL_IP64
46 uint8_t flags1, flags2;
47#define DNS_FLAG1_RESPONSE 0x80
48#define DNS_FLAG1_OPCODE_STATUS 0x10
49#define DNS_FLAG1_OPCODE_INVERSE 0x08
50#define DNS_FLAG1_OPCODE_STANDARD 0x00
51#define DNS_FLAG1_AUTHORATIVE 0x04
52#define DNS_FLAG1_TRUNC 0x02
53#define DNS_FLAG1_RD 0x01
54#define DNS_FLAG2_RA 0x80
55#define DNS_FLAG2_ERR_MASK 0x0f
56#define DNS_FLAG2_ERR_NONE 0x00
57#define DNS_FLAG2_ERR_NAME 0x03
58 uint8_t numquestions[2];
59 uint8_t numanswers[2];
61 uint8_t numextrarr[2];
64#define DNS_QUESTION_TYPE0 0
65#define DNS_QUESTION_TYPE1 1
66#define DNS_QUESTION_CLASS0 2
67#define DNS_QUESTION_CLASS1 3
68#define DNS_QUESTION_SIZE 4
84#define DNS_TYPE_AAAA 28
87#define DNS_CLASS_ANY 255
91ip64_dns64_6to4(
const uint8_t *ipv6data,
int ipv6datalen,
92 uint8_t *ipv4data,
int ipv4datalen)
100 hdr = (
struct dns_hdr *)ipv4data;
101 LOG_DBG(
"dns64_6to4 id: %02x%02x\n", hdr->id[0], hdr->id[1]);
102 LOG_DBG(
"dns64_6to4 flags1: 0x%02x\n", hdr->flags1);
103 LOG_DBG(
"ip64_dns64_6to4 flags2: 0x%02x\n", hdr->flags2);
104 LOG_DBG(
"dns64_6to4 numquestions: 0x%02x\n",
105 ((hdr->numquestions[0] << 8) + hdr->numquestions[1]));
106 LOG_DBG(
"dns64_6to4 numanswers: 0x%02x\n",
107 ((hdr->numanswers[0] << 8) + hdr->numanswers[1]));
108 LOG_DBG(
"dns64_6to4 numauthrr: 0x%02x\n",
109 ((hdr->numauthrr[0] << 8) + hdr->numauthrr[1]));
110 LOG_DBG(
"dns64_6to4 numextrarr: 0x%02x\n",
111 ((hdr->numextrarr[0] << 8) + hdr->numextrarr[1]));
115 qdata = ipv4data +
sizeof(
struct dns_hdr);
116 for(i = 0; i < ((hdr->numquestions[0] << 8) + hdr->numquestions[1]); i++) {
120 for(j = 0; j < qlen; j++) {
122 if(qdata > ipv4data + ipv4datalen) {
123 LOG_WARN(
"dns64_6to4: Packet ended while parsing\n");
129 if(q[DNS_QUESTION_CLASS0] == 0 && q[DNS_QUESTION_CLASS1] == DNS_CLASS_IN &&
130 q[DNS_QUESTION_TYPE0] == 0 && q[DNS_QUESTION_TYPE1] == DNS_TYPE_AAAA) {
131 q[DNS_QUESTION_TYPE1] = DNS_TYPE_A;
134 qdata += DNS_QUESTION_SIZE;
139ip64_dns64_4to6(
const uint8_t *ipv4data,
int ipv4datalen,
140 uint8_t *ipv6data,
int ipv6datalen)
145 const uint8_t *qdata, *adata;
146 uint8_t *qcopy, *acopy, *lenptr;
150 hdr = (
struct dns_hdr *)ipv4data;
151 LOG_DBG(
"dns64_4to6 id: %02x%02x\n", hdr->id[0], hdr->id[1]);
152 LOG_DBG(
"dns64_4to6 flags1: 0x%02x\n", hdr->flags1);
153 LOG_DBG(
"dns64_4to6 flags2: 0x%02x\n", hdr->flags2);
154 LOG_DBG(
"dns64_4to6 numquestions: 0x%02x\n",
155 ((hdr->numquestions[0] << 8) + hdr->numquestions[1]));
156 LOG_DBG(
"dns64_4to6 numanswers: 0x%02x\n",
157 ((hdr->numanswers[0] << 8) + hdr->numanswers[1]));
158 LOG_DBG(
"dns64_4to6 numauthrr: 0x%02x\n",
159 ((hdr->numauthrr[0] << 8) + hdr->numauthrr[1]));
160 LOG_DBG(
"dns64_4to6 numextrarr: 0x%02x\n",
161 ((hdr->numextrarr[0] << 8) + hdr->numextrarr[1]));
165 qdata = ipv4data +
sizeof(
struct dns_hdr);
166 qcopy = ipv6data +
sizeof(
struct dns_hdr);
167 for(i = 0; i < ((hdr->numquestions[0] << 8) + hdr->numquestions[1]); i++) {
172 for(j = 0; j < qlen; j++) {
175 if(qdata > ipv4data + ipv4datalen) {
176 LOG_WARN(
"dns64_4to6: packet ended while parsing\n");
182 if(q[DNS_QUESTION_CLASS0] == 0 && q[DNS_QUESTION_CLASS1] == DNS_CLASS_IN &&
183 q[DNS_QUESTION_TYPE0] == 0 && q[DNS_QUESTION_TYPE1] == DNS_TYPE_AAAA) {
184 q[DNS_QUESTION_TYPE1] = DNS_TYPE_AAAA;
187 qdata += DNS_QUESTION_SIZE;
188 qcopy += DNS_QUESTION_SIZE;
195 for(i = 0; i < ((hdr->numanswers[0] << 8) + hdr->numanswers[1]); i++) {
208 for(j = 0; j < n; j++) {
214 if(adata[0] == 0 && adata[1] == DNS_TYPE_A) {
219 *acopy = DNS_TYPE_AAAA;
225 len = (adata[6] << 8) + adata[7];
228 memcpy(acopy, adata, 2 + 4 + 2);
235 ip64_addr_4to6(&
addr, (uip_ip6addr_t *)acopy);
244 memcpy(acopy, adata, len);
249 len = (adata[8] << 8) + adata[9];
252 memcpy(acopy, adata, 2 + 2 + 4 + 2);
257 memcpy(acopy, adata, len);
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
Header file for the logging system.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Representation of an IP address.