Changeset 59063 in vbox for trunk/src/VBox/Devices/Network/slirp
- Timestamp:
- Dec 8, 2015 9:39:32 PM (9 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/hostres.c
r59028 r59063 1 1 /* $Id$ */ 2 2 /** @file 3 * libalias helper for using the host resolver instead of dnsproxy.3 * Host resolver 4 4 */ 5 5 … … 22 22 #include <iprt/assert.h> 23 23 #include <slirp.h> 24 #include "alias.h" 25 #include "alias_local.h" 26 #include "alias_mod.h" 24 27 25 #define isdigit(ch) RT_C_IS_DIGIT(ch) 28 26 #define isalpha(ch) RT_C_IS_ALPHA(ch) … … 68 66 69 67 /* see RFC 1035(4.1) */ 70 static int dns_alias_handler(PNATState pData, int type);71 68 static void CStr2QStr(const char *pcszStr, char *pszQStr, size_t cQStr); 72 69 static void QStr2CStr(const char *pcszQStr, char *pszStr, size_t cStr); … … 75 72 #endif 76 73 77 static int 78 fingerprint(struct libalias *la, struct ip *pIp, struct alias_data *ah) 79 { 80 81 NOREF(la); 82 NOREF(pIp); 83 if (!ah->dport || !ah->sport || !ah->lnk) 84 return -1; 85 86 Log(("NAT:%s: ah(dport: %hd, sport: %hd) oaddr:%RTnaipv4 aaddr:%RTnaipv4\n", 87 RT_GCC_EXTENSION __FUNCTION__, ntohs(*ah->dport), ntohs(*ah->sport), 88 ah->oaddr, ah->aaddr)); 89 90 if ( (ntohs(*ah->dport) == DNS_CONTROL_PORT_NUMBER 91 || ntohs(*ah->sport) == DNS_CONTROL_PORT_NUMBER) 92 && (ah->oaddr->s_addr == htonl(ntohl(la->pData->special_addr.s_addr)|CTL_DNS))) 93 return 0; 94 95 return -1; 96 } 97 98 static void doanswer(union dnsmsg_header *pHdr, struct dns_meta_data *pReqMeta, char *pszQname, struct ip *pIp, struct hostent *pHostent) 99 { 74 75 static void 76 doanswer(struct mbuf *m, struct hostent *pHostent) 77 { 78 union dnsmsg_header *pHdr; 100 79 int i; 80 81 pHdr = mtod(m, union dnsmsg_header *); 101 82 102 83 if (!pHostent) … … 109 90 else 110 91 { 111 char *query;112 92 char *answers; 113 93 uint16_t off; 114 94 char **cstr; 115 95 char *c; 116 uint16_t packet_len = 0;96 size_t anslen = 0; 117 97 uint16_t addr_off = (uint16_t)~0; 118 98 struct dns_meta_data *meta; 119 99 120 #if 0121 /* here is no compressed names+answers + new query */122 m_inc(m, pHostent->h_length * sizeof(struct dnsmsg_answer) + strlen(pszQname) + 2 * sizeof(uint16_t));123 #endif124 packet_len = (pIp->ip_hl << 2)125 + sizeof(struct udphdr)126 + sizeof(union dnsmsg_header)127 + strlen(pszQname)128 + sizeof(struct dns_meta_data); /* ip + udp + header + query */129 query = (char *)&pHdr[1];130 131 strcpy(query, pszQname);132 query += strlen(pszQname) + 1;133 /* class & type informations lay right after symbolic inforamtion. */134 meta = (struct dns_meta_data *)query;135 meta->type = pReqMeta->type;136 meta->class = pReqMeta->class;137 138 100 /* answers zone lays after query in response packet */ 139 answers = (char *) &meta[1];101 answers = (char *)pHdr + m->m_len; 140 102 141 103 off = (char *)&pHdr[1] - (char *)pHdr; … … 161 123 addr_off = off; 162 124 answers = (char *)&ans[1] + len - 2; /* note: 1 symbol already counted */ 163 packet_len += sizeof(struct dnsmsg_answer) + len - 2;125 anslen += sizeof(struct dnsmsg_answer) + len - 2; 164 126 pHdr->X.ancount++; 165 127 } 128 166 129 /* add addresses */ 167 168 130 for(i = 0; i < pHostent->h_length && pHostent->h_addr_list[i] != NULL; ++i) 169 131 { … … 177 139 *(uint32_t *)ans->rdata = *(uint32_t *)pHostent->h_addr_list[i]; 178 140 answers = (char *)&ans[1] + 2; 179 packet_len += sizeof(struct dnsmsg_answer) + 3;141 anslen += sizeof(struct dnsmsg_answer) + 3; 180 142 pHdr->X.ancount++; 181 143 } … … 186 148 pHdr->X.rcode = 0; 187 149 HTONS(pHdr->X.ancount); 188 /* don't forget update m_len */ 189 pIp->ip_len = htons(packet_len);190 } 191 } 192 193 staticint194 protohandler(struct libalias *la, struct ip *pIp, struct alias_data *ah)150 151 m->m_len += anslen; 152 } 153 } 154 155 int 156 hostresolver(PNATState pData, struct mbuf *m) 195 157 { 196 158 int i; … … 202 164 struct dns_meta_data *meta; 203 165 204 struct udphdr *udp = NULL;205 166 union dnsmsg_header *pHdr = NULL; 206 NOREF(la); 207 NOREF(ah); 208 udp = (struct udphdr *)ip_next(pIp); 209 pHdr = (union dnsmsg_header *)udp_next(udp); 167 168 pHdr = mtod(m, union dnsmsg_header *); 210 169 211 170 if (pHdr->X.qr == 1) 212 return 0; /* this is respose */171 return 1; /* this is respose */ 213 172 214 173 memset(pszCname, 0, sizeof(pszCname)); 215 174 qw_qname = (char *)&pHdr[1]; 216 Assert((ntohs(pHdr->X.qdcount) == 1)); 175 217 176 if ((ntohs(pHdr->X.qdcount) != 1)) 218 177 { … … 226 185 } 227 186 228 for (i = 0; i < ntohs(pHdr->X.qdcount); ++i)229 187 { 230 188 meta = (struct dns_meta_data *)(qw_qname + strlen(qw_qname) + 1); … … 248 206 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 249 207 if ( pHostent 250 && !LIST_EMPTY(& la->pData->DNSMapHead))251 alterHostentWithDataFromDNSMap( la->pData, pHostent);208 && !LIST_EMPTY(&pData->DNSMapHead)) 209 alterHostentWithDataFromDNSMap(pData, pHostent); 252 210 #endif 253 doanswer(pHdr, meta, qw_qname, pIp, pHostent); 254 } 255 256 /* 257 * We have changed the size and the content of udp, to avoid double csum calculation 258 * will assign to zero 259 */ 260 udp->uh_sum = 0; 261 udp->uh_ulen = ntohs(htons(pIp->ip_len) - (pIp->ip_hl << 2)); 262 pIp->ip_sum = 0; 263 pIp->ip_sum = LibAliasInternetChecksum(la, (uint16_t *)pIp, pIp->ip_hl << 2); 211 doanswer(m, pHostent); 212 } 213 264 214 return 0; 265 215 } … … 324 274 } 325 275 *q = '\0'; 326 }327 328 329 int330 dns_alias_load(PNATState pData)331 {332 return dns_alias_handler(pData, MOD_LOAD);333 }334 335 int336 dns_alias_unload(PNATState pData)337 {338 return dns_alias_handler(pData, MOD_UNLOAD);339 }340 341 #define handlers pData->dns_module342 static int343 dns_alias_handler(PNATState pData, int type)344 {345 int error;346 347 if (!handlers)348 handlers = RTMemAllocZ(2 * sizeof(struct proto_handler));349 350 handlers[0].pri = 20;351 handlers[0].dir = IN;352 handlers[0].proto = UDP;353 handlers[0].fingerprint = &fingerprint;354 handlers[0].protohandler = &protohandler;355 handlers[1].pri = EOH;356 357 switch (type)358 {359 case MOD_LOAD:360 error = 0;361 LibAliasAttachHandlers(pData, handlers);362 break;363 364 case MOD_UNLOAD:365 error = 0;366 LibAliasDetachHandlers(pData, handlers);367 RTMemFree(handlers);368 handlers = NULL;369 break;370 371 default:372 error = EINVAL;373 }374 return error;375 276 } 376 277 -
trunk/src/VBox/Devices/Network/slirp/ip_input.c
r56960 r59063 114 114 else 115 115 m->m_flags &= ~M_SKIP_FIREWALL; 116 117 /* 118 * XXX: TODO: this is most likely a leftover spooky action at 119 * a distance from alias_dns.c host resolver code and can be 120 * g/c'ed. 121 */ 116 122 if (m->m_len != RT_N2H_U16(ip->ip_len)) 117 123 m->m_len = RT_N2H_U16(ip->ip_len); -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r58077 r59063 407 407 ftp_alias_load(pData); 408 408 nbt_alias_load(pData); 409 if (pData->fUseHostResolver)410 dns_alias_load(pData);411 409 } 412 410 #ifdef VBOX_WITH_NAT_SEND2HOME … … 523 521 if (pData->fUseHostResolver) 524 522 { 525 dns_alias_unload(pData);526 523 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 527 524 while (!LIST_EMPTY(&pData->DNSMapHead)) -
trunk/src/VBox/Devices/Network/slirp/slirp.h
r56292 r59063 351 351 struct tcpcb *tcp_drop(PNATState, struct tcpcb *tp, int err); 352 352 353 /* hostres.c */ 354 int hostresolver(PNATState, struct mbuf *); 355 353 356 /*slirp.c*/ 354 357 void slirp_arp_who_has(PNATState pData, uint32_t dst); … … 465 468 int nbt_alias_load(PNATState); 466 469 int nbt_alias_unload(PNATState); 467 int dns_alias_load(PNATState);468 int dns_alias_unload(PNATState);469 470 int slirp_arp_lookup_ip_by_ether(PNATState, const uint8_t *, uint32_t *); 470 471 int slirp_arp_lookup_ether_by_ip(PNATState, uint32_t, uint8_t *); -
trunk/src/VBox/Devices/Network/slirp/slirp_dns.c
r56292 r59063 246 246 if (get_dns_addr_domain(pData, NULL) < 0) 247 247 { 248 /* Load the DNS handler if host resolver mode was not used before. */249 if (!pData->fUseHostResolver)250 dns_alias_load(pData);251 248 pData->fUseHostResolver = true; 252 249 } 253 250 else 254 251 { 255 /* Unload to not intercept in the future. */256 if (pData->fUseHostResolver)257 dns_alias_unload(pData);258 252 pData->fUseHostResolver = false; 259 253 dnsproxy_init(pData); -
trunk/src/VBox/Devices/Network/slirp/udp.c
r59034 r59063 183 183 ip->ip_dst.s_addr, RT_N2H_U16(uh->uh_dport))); 184 184 185 /* 186 * handle DNS host resolver without creating a socket 187 */ 185 188 if ( pData->fUseHostResolver 186 189 && uh->uh_dport == RT_H2N_U16_C(53) … … 188 191 { 189 192 struct sockaddr_in dst, src; 193 int error; 194 190 195 src.sin_addr.s_addr = ip->ip_dst.s_addr; 191 196 src.sin_port = uh->uh_dport; … … 193 198 dst.sin_port = uh->uh_sport; 194 199 200 m_adj(m, sizeof(struct udpiphdr)); 201 202 error = hostresolver(pData, m); 203 if (error) 204 goto done_free_mbuf; 205 195 206 slirpMbufTagService(pData, m, CTL_DNS); 196 /* udp_output2() expects a pointer to the body of UDP packet. */ 197 m->m_data += sizeof(struct udpiphdr); 198 m->m_len -= sizeof(struct udpiphdr); 207 199 208 udp_output2(pData, NULL, m, &src, &dst, IPTOS_LOWDELAY); 200 209 LogFlowFuncLeave();
Note:
See TracChangeset
for help on using the changeset viewer.