Changeset 39766 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- Jan 13, 2012 7:28:55 PM (13 years ago)
- Location:
- trunk/src/VBox/Devices/Network
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DrvNAT.cpp
r39550 r39766 1009 1009 } 1010 1010 1011 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 1012 static int drvNATConstructDNSMappings(unsigned iInstance, PDRVNAT pThis, PCFGMNODE pMappingsCfg) 1013 { 1014 int rc = VINF_SUCCESS; 1015 LogFlowFunc(("ENTER: iInstance:%d\n", iInstance)); 1016 for (PCFGMNODE pNode = CFGMR3GetFirstChild(pMappingsCfg); pNode; pNode = CFGMR3GetNextChild(pNode)) 1017 { 1018 if (!CFGMR3AreValuesValid(pNode, "HostName\0HostIP\0")) 1019 return PDMDRV_SET_ERROR(pThis->pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES, 1020 N_("Unknown configuration in dns mapping")); 1021 char szHostName[255]; 1022 RT_ZERO(szHostName); 1023 GET_STRING(rc, pThis, pNode, "HostName", szHostName[0], sizeof(szHostName)); 1024 struct in_addr HostIP; 1025 GETIP_DEF(rc, pThis, pNode, HostIP, INADDR_ANY); 1026 slirp_add_host_resolver_mapping(pThis->pNATState, szHostName, HostIP.s_addr); 1027 } 1028 LogFlowFunc(("LEAVE: %Rrc\n", rc)); 1029 return rc; 1030 } 1031 #endif /* !VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER */ 1032 1011 1033 1012 1034 /** … … 1026 1048 for (PCFGMNODE pNode = CFGMR3GetFirstChild(pCfg); pNode; pNode = CFGMR3GetNextChild(pNode)) 1027 1049 { 1050 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 1051 char szNodeName[32]; 1052 CFGMR3GetName(pNode, szNodeName, 32); 1053 if ( !RTStrICmp(szNodeName, "HostResolverMappings") 1054 || !RTStrICmp(szNodeName, "AttachedDriver")) 1055 continue; 1056 #endif 1028 1057 /* 1029 1058 * Validate the port forwarding config. … … 1159 1188 "SockRcv\0SockSnd\0TcpRcv\0TcpSnd\0" 1160 1189 "ICMPCacheLimit\0" 1161 "SoMaxConnection\0")) 1190 "SoMaxConnection\0" 1191 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 1192 "HostResolverMappings\0" 1193 #endif 1194 )) 1162 1195 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES, 1163 1196 N_("Unknown NAT configuration option, only supports PassDomain," … … 1293 1326 #endif 1294 1327 1328 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 1329 PCFGMNODE pMappingsCfg = CFGMR3GetChild(pCfg, "HostResolverMappings"); 1330 1331 if (pMappingsCfg) 1332 { 1333 rc = drvNATConstructDNSMappings(pDrvIns->iInstance, pThis, pMappingsCfg); 1334 AssertRC(rc); 1335 } 1336 #endif 1295 1337 rc = drvNATConstructRedir(pDrvIns->iInstance, pThis, pCfg, Network); 1296 1338 if (RT_SUCCESS(rc)) -
trunk/src/VBox/Devices/Network/slirp/libalias/alias_dns.c
r39101 r39766 68 68 69 69 /* see RFC 1035(4.1) */ 70 static int dns_alias_handler(PNATState pData, int type);70 static int dns_alias_handler(PNATState pData, int type); 71 71 static void CStr2QStr(const char *pcszStr, char *pszQStr, size_t cQStr); 72 72 static void QStr2CStr(const char *pcszQStr, char *pszStr, size_t cStr); 73 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 74 static void alterHostentWithDataFromDNSMap(PNATState pData, struct hostent *pHostent); 75 #endif 73 76 74 77 static int 75 fingerprint(struct libalias *la, struct ip *p ip, struct alias_data *ah)78 fingerprint(struct libalias *la, struct ip *pIp, struct alias_data *ah) 76 79 { 77 80 78 81 NOREF(la); 79 NOREF(p ip);82 NOREF(pIp); 80 83 if (!ah->dport || !ah->sport || !ah->lnk) 81 84 return -1; … … 93 96 } 94 97 95 static void doanswer(union dnsmsg_header * hdr, struct dns_meta_data *pReqMeta, char *qname, struct ip *pip, struct hostent *h)98 static void doanswer(union dnsmsg_header *pHdr, struct dns_meta_data *pReqMeta, char *pszQname, struct ip *pIp, struct hostent *pHostent) 96 99 { 97 100 int i; 98 101 99 if (! h)100 { 101 hdr->X.qr = 1; /* response */102 hdr->X.aa = 1;103 hdr->X.rd = 1;104 hdr->X.rcode = 3;102 if (!pHostent) 103 { 104 pHdr->X.qr = 1; /* response */ 105 pHdr->X.aa = 1; 106 pHdr->X.rd = 1; 107 pHdr->X.rcode = 3; 105 108 } 106 109 else … … 117 120 #if 0 118 121 /* here is no compressed names+answers + new query */ 119 m_inc(m, h->h_length * sizeof(struct dnsmsg_answer) + strlen(qname) + 2 * sizeof(uint16_t));122 m_inc(m, pHostent->h_length * sizeof(struct dnsmsg_answer) + strlen(pszQname) + 2 * sizeof(uint16_t)); 120 123 #endif 121 packet_len = (p ip->ip_hl << 2)124 packet_len = (pIp->ip_hl << 2) 122 125 + sizeof(struct udphdr) 123 126 + sizeof(union dnsmsg_header) 124 + strlen( qname)127 + strlen(pszQname) 125 128 + sizeof(struct dns_meta_data); /* ip + udp + header + query */ 126 query = (char *)& hdr[1];127 128 strcpy(query, qname);129 query += strlen( qname) + 1;129 query = (char *)&pHdr[1]; 130 131 strcpy(query, pszQname); 132 query += strlen(pszQname) + 1; 130 133 /* class & type informations lay right after symbolic inforamtion. */ 131 134 meta = (struct dns_meta_data *)query; … … 136 139 answers = (char *)&meta[1]; 137 140 138 off = (char *)& hdr[1] - (char *)hdr;141 off = (char *)&pHdr[1] - (char *)pHdr; 139 142 off |= (0x3 << 14); 140 143 141 144 /* add aliases */ 142 for (cstr = h->h_aliases; *cstr; cstr++)145 for (cstr = pHostent->h_aliases; *cstr; cstr++) 143 146 { 144 147 uint16_t len; … … 148 151 ans->meta.class = htons(1); 149 152 *(uint32_t *)ans->ttl = htonl(3600); /* 1h */ 150 c = (addr_off == (uint16_t)~0 ? h->h_name : *cstr);153 c = (addr_off == (uint16_t)~0 ? pHostent->h_name : *cstr); 151 154 len = strlen(c) + 2; 152 155 ans->rdata_len = htons(len); 153 156 ans->rdata[len - 1] = 0; 154 157 CStr2QStr(c, (char *)ans->rdata, len); 155 off = (char *)&ans->rdata - (char *) hdr;158 off = (char *)&ans->rdata - (char *)pHdr; 156 159 off |= (0x3 << 14); 157 160 if (addr_off == (uint16_t)~0) … … 159 162 answers = (char *)&ans[1] + len - 2; /* note: 1 symbol already counted */ 160 163 packet_len += sizeof(struct dnsmsg_answer) + len - 2; 161 hdr->X.ancount++;164 pHdr->X.ancount++; 162 165 } 163 166 /* add addresses */ 164 167 165 for(i = 0; i < h->h_length && h->h_addr_list[i] != NULL; ++i)168 for(i = 0; i < pHostent->h_length && pHostent->h_addr_list[i] != NULL; ++i) 166 169 { 167 170 struct dnsmsg_answer *ans = (struct dnsmsg_answer *)answers; … … 172 175 *(uint32_t *)ans->ttl = htonl(3600); /* 1h */ 173 176 ans->rdata_len = htons(4); /* IPv4 */ 174 *(uint32_t *)ans->rdata = *(uint32_t *) h->h_addr_list[i];177 *(uint32_t *)ans->rdata = *(uint32_t *)pHostent->h_addr_list[i]; 175 178 answers = (char *)&ans[1] + 2; 176 179 packet_len += sizeof(struct dnsmsg_answer) + 3; 177 hdr->X.ancount++;178 } 179 hdr->X.qr = 1; /* response */180 hdr->X.aa = 1;181 hdr->X.rd = 1;182 hdr->X.ra = 1;183 hdr->X.rcode = 0;184 HTONS( hdr->X.ancount);180 pHdr->X.ancount++; 181 } 182 pHdr->X.qr = 1; /* response */ 183 pHdr->X.aa = 1; 184 pHdr->X.rd = 1; 185 pHdr->X.ra = 1; 186 pHdr->X.rcode = 0; 187 HTONS(pHdr->X.ancount); 185 188 /* don't forget update m_len */ 186 p ip->ip_len = htons(packet_len);189 pIp->ip_len = htons(packet_len); 187 190 } 188 191 } 189 192 190 193 static int 191 protohandler(struct libalias *la, struct ip *p ip, struct alias_data *ah)194 protohandler(struct libalias *la, struct ip *pIp, struct alias_data *ah) 192 195 { 193 196 int i; 194 197 /* Parse dns request */ 195 198 char *qw_qname = NULL; 196 struct hostent * h= NULL;197 char cname[255];199 struct hostent *pHostent = NULL; 200 char pszCname[255]; 198 201 int cname_len = 0; 199 202 struct dns_meta_data *meta; 200 203 201 204 struct udphdr *udp = NULL; 202 union dnsmsg_header * hdr = NULL;205 union dnsmsg_header *pHdr = NULL; 203 206 NOREF(la); 204 207 NOREF(ah); 205 udp = (struct udphdr *)ip_next(p ip);206 hdr = (union dnsmsg_header *)udp_next(udp);207 208 if ( hdr->X.qr == 1)208 udp = (struct udphdr *)ip_next(pIp); 209 pHdr = (union dnsmsg_header *)udp_next(udp); 210 211 if (pHdr->X.qr == 1) 209 212 return 0; /* this is respose */ 210 213 211 memset( cname, 0, sizeof(cname));212 qw_qname = (char *)& hdr[1];213 Assert((ntohs( hdr->X.qdcount) == 1));214 if ((ntohs( hdr->X.qdcount) != 1))214 memset(pszCname, 0, sizeof(pszCname)); 215 qw_qname = (char *)&pHdr[1]; 216 Assert((ntohs(pHdr->X.qdcount) == 1)); 217 if ((ntohs(pHdr->X.qdcount) != 1)) 215 218 { 216 219 static bool fMultiWarn; … … 223 226 } 224 227 225 for (i = 0; i < ntohs( hdr->X.qdcount); ++i)228 for (i = 0; i < ntohs(pHdr->X.qdcount); ++i) 226 229 { 227 230 meta = (struct dns_meta_data *)(qw_qname + strlen(qw_qname) + 1); 228 Log((" qname:%s qtype:%hd qclass:%hd\n",231 Log(("pszQname:%s qtype:%hd qclass:%hd\n", 229 232 qw_qname, ntohs(meta->type), ntohs(meta->class))); 230 233 231 QStr2CStr(qw_qname, cname, sizeof(cname));232 cname_len = RTStrNLen( cname, sizeof(cname));234 QStr2CStr(qw_qname, pszCname, sizeof(pszCname)); 235 cname_len = RTStrNLen(pszCname, sizeof(pszCname)); 233 236 /* Some guests like win-xp adds _dot_ after host name 234 237 * and after domain name (not passed with host resolver) … … 236 239 */ 237 240 if ( cname_len > 2 238 && cname[cname_len - 1] == '.' 239 && cname[cname_len - 2] == '.') 240 { 241 cname[cname_len - 1] = 0; 242 cname[cname_len - 2] = 0; 243 } 244 h = gethostbyname(cname); 245 fprintf(stderr, "cname:%s\n", cname); 246 doanswer(hdr, meta, qw_qname, pip, h); 241 && pszCname[cname_len - 1] == '.' 242 && pszCname[cname_len - 2] == '.') 243 { 244 pszCname[cname_len - 1] = 0; 245 pszCname[cname_len - 2] = 0; 246 } 247 pHostent = gethostbyname(pszCname); 248 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 249 if ( pHostent 250 && !LIST_EMPTY(&la->pData->DNSMapHead)) 251 alterHostentWithDataFromDNSMap(la->pData, pHostent); 252 #endif 253 fprintf(stderr, "pszCname:%s\n", pszCname); 254 doanswer(pHdr, meta, qw_qname, pIp, pHostent); 247 255 } 248 256 … … 252 260 */ 253 261 udp->uh_sum = 0; 254 udp->uh_ulen = ntohs(htons(p ip->ip_len) - (pip->ip_hl << 2));255 p ip->ip_sum = 0;256 p ip->ip_sum = LibAliasInternetChecksum(la, (uint16_t *)pip, pip->ip_hl << 2);262 udp->uh_ulen = ntohs(htons(pIp->ip_len) - (pIp->ip_hl << 2)); 263 pIp->ip_sum = 0; 264 pIp->ip_sum = LibAliasInternetChecksum(la, (uint16_t *)pIp, pIp->ip_hl << 2); 257 265 return 0; 258 266 } … … 367 375 return error; 368 376 } 377 378 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 379 static void alterHostentWithDataFromDNSMap(PNATState pData, struct hostent *pHostent) 380 { 381 PDNSMAPPINGENTRY pDNSMapingEntry = NULL; 382 bool fMatch = false; 383 LIST_FOREACH(pDNSMapingEntry, &pData->DNSMapHead, MapList) 384 { 385 char **pszAlias = NULL; 386 if (!strcmp(pDNSMapingEntry->pszCName, pHostent->h_name)) 387 { 388 fMatch = true; 389 break; 390 } 391 392 for (pszAlias = pHostent->h_aliases; *pszAlias && !fMatch; pszAlias++) 393 { 394 if (!strcmp(pDNSMapingEntry->pszCName, *pszAlias)) 395 { 396 397 PDNSMAPPINGENTRY pDnsMapping = RTMemAllocZ(sizeof(DNSMAPPINGENTRY)); 398 fMatch = true; 399 if (!pDnsMapping) 400 { 401 LogFunc(("Can't allocate DNSMAPPINGENTRY\n")); 402 LogFlowFuncLeave(); 403 return; 404 } 405 pDnsMapping->u32IpAddress = pDNSMapingEntry->u32IpAddress; 406 pDnsMapping->pszCName = RTStrDup(pHostent->h_name); 407 if (!pDnsMapping->pszCName) 408 { 409 LogFunc(("Can't allocate enough room for %s\n", pHostent->h_name)); 410 RTMemFree(pDnsMapping); 411 LogFlowFuncLeave(); 412 return; 413 } 414 LIST_INSERT_HEAD(&pData->DNSMapHead, pDnsMapping, MapList); 415 } 416 } 417 if (fMatch) 418 break; 419 } 420 421 /* h_lenght is lenght of h_addr_list in bytes, so we check that we have enough space for IPv4 address */ 422 if ( fMatch 423 && pHostent->h_length >= sizeof(uint32_t) 424 && pDNSMapingEntry) 425 { 426 pHostent->h_length = 1; 427 *(uint32_t *)pHostent->h_addr_list[0] = pDNSMapingEntry->u32IpAddress; 428 } 429 430 } 431 #endif -
trunk/src/VBox/Devices/Network/slirp/libslirp.h
r38971 r39766 148 148 # endif 149 149 150 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 151 void slirp_add_host_resolver_mapping(PNATState pData, const char *pszHostName, uint32_t u32HostIP); 152 #endif 153 150 154 #ifdef __cplusplus 151 155 } -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r39599 r39766 799 799 nbt_alias_unload(pData); 800 800 if (pData->fUseHostResolver) 801 { 801 802 dns_alias_unload(pData); 803 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 804 while (!LIST_EMPTY(&pData->DNSMapHead)) 805 { 806 PDNSMAPPINGENTRY pDnsEntry = LIST_FIRST(&pData->DNSMapHead); 807 LIST_REMOVE(pDnsEntry, MapList); 808 RTStrFree(pDnsEntry->pszCName); 809 RTMemFree(pDnsEntry); 810 } 811 #endif 812 } 802 813 while (!LIST_EMPTY(&instancehead)) 803 814 { … … 2147 2158 LogFlowFuncLeave(); 2148 2159 } 2160 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 2161 void slirp_add_host_resolver_mapping(PNATState pData, const char *pszHostName, uint32_t u32HostIP) 2162 { 2163 LogFlowFunc(("ENTER: pszHostName:%s, u32HostIP:%RTnaipv4\n", pszHostName, u32HostIP)); 2164 if ( pszHostName 2165 || u32HostIP != INADDR_ANY 2166 || u32HostIP != INADDR_BROADCAST) 2167 { 2168 PDNSMAPPINGENTRY pDnsMapping = RTMemAllocZ(sizeof(DNSMAPPINGENTRY)); 2169 if (!pDnsMapping) 2170 { 2171 LogFunc(("Can't allocate DNSMAPPINGENTRY\n")); 2172 LogFlowFuncLeave(); 2173 return; 2174 } 2175 pDnsMapping->u32IpAddress = u32HostIP; 2176 pDnsMapping->pszCName = RTStrDup(pszHostName); 2177 if (!pDnsMapping->pszCName) 2178 { 2179 LogFunc(("Can't allocate enough room for %s\n", pszHostName)); 2180 RTMemFree(pDnsMapping); 2181 LogFlowFuncLeave(); 2182 return; 2183 } 2184 LIST_INSERT_HEAD(&pData->DNSMapHead, pDnsMapping, MapList); 2185 } 2186 LogFlowFuncLeave(); 2187 } 2188 #endif 2149 2189 2150 2190 /* updates the arp cache -
trunk/src/VBox/Devices/Network/slirp/slirp_state.h
r39550 r39766 65 65 }; 66 66 LIST_HEAD(dns_domain_list_head, dns_domain_entry); 67 68 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 69 typedef struct DNSMAPPINGENTRY 70 { 71 char *pszCName; 72 uint32_t u32IpAddress; 73 LIST_ENTRY(DNSMAPPINGENTRY) MapList; 74 } DNSMAPPINGENTRY, *PDNSMAPPINGENTRY; 75 typedef LIST_HEAD(DNSMAPPINGLISTHEAD, DNSMAPPINGENTRY) DNSMAPPINGLISTHEAD; 76 #endif 67 77 68 78 struct dns_entry … … 298 308 int cInHomeAddressSize; 299 309 #endif 310 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 311 DNSMAPPINGLISTHEAD DNSMapHead; 312 #endif 300 313 } NATState; 301 314
Note:
See TracChangeset
for help on using the changeset viewer.