- Timestamp:
- Sep 28, 2009 12:41:20 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 52893
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/bootp.c
r23158 r23369 47 47 uint8_t len; 48 48 /*@todo magic validation */ 49 q += 4; /*magic*/ 49 q += 4; /*magic*/ 50 50 while(*q != RFC1533_END) 51 51 { … … 56 56 q++; 57 57 len = *q; 58 q += 1 + len; 59 } 60 return NULL; 58 q += 1 + len; 59 } 60 return NULL; 61 61 } 62 62 static BOOTPClient *bc_alloc_client(PNATState pData) … … 135 135 * name or options name or options 136 136 * 'options' options options 137 * 137 * 138 138 * Option DHCPOFFER DHCPACK DHCPNAK 139 139 * ------ --------- ------- ------- … … 265 265 }while(0) 266 266 267 268 267 269 268 FILL_BOOTP_EXT(q, RFC1533_NETMASK, 4, &netmask); 270 269 FILL_BOOTP_EXT(q, RFC1533_GATEWAY, 4, &saddr); 271 270 272 271 if (pData->use_dns_proxy || pData->use_host_resolver) 273 272 { … … 276 275 goto skip_dns_servers; 277 276 } 278 279 if (!TAILQ_EMPTY(&pData->dns_list_head)) 277 278 if (!TAILQ_EMPTY(&pData->dns_list_head)) 280 279 { 281 280 de = TAILQ_LAST(&pData->dns_list_head, dns_list_head); … … 283 282 FILL_BOOTP_EXT(q, RFC1533_DNS, 4, &de->de_addr.s_addr); 284 283 } 285 284 286 285 TAILQ_FOREACH_REVERSE(de, &pData->dns_list_head, dns_list_head, de_list) 287 286 { … … 296 295 /* Microsoft dhcp client doen't like domain-less dhcp and trimmed packets*/ 297 296 /* dhcpcd client very sad if no domain name is passed */ 298 FILL_BOOTP_EXT(q, RFC1533_DOMAINNAME, 1, " "); 297 FILL_BOOTP_EXT(q, RFC1533_DOMAINNAME, 1, " "); 299 298 } 300 299 if (pData->fPassDomain && !pData->use_host_resolver) … … 302 301 LIST_FOREACH(dd, &pData->dns_domain_list_head, dd_list) 303 302 { 304 303 305 304 if (dd->dd_pszDomain == NULL) 306 305 continue; 307 306 /* never meet valid separator here in RFC1533*/ 308 if (added != 0) 309 FILL_BOOTP_EXT(q, RFC1533_DOMAINNAME, 1, ","); 307 if (added != 0) 308 FILL_BOOTP_EXT(q, RFC1533_DOMAINNAME, 1, ","); 310 309 else 311 310 added = 1; … … 314 313 } 315 314 } 316 315 317 316 FILL_BOOTP_EXT(q, RFC2132_LEASE_TIME, 4, &lease_time); 318 317 319 318 if (*slirp_hostname) 320 319 { … … 332 331 333 332 dhcp_create_msg(pData, bp, m, DHCPNAK); 334 333 335 334 return 7; 336 335 } … … 408 407 /*see table 4 rfc2131*/ 409 408 if (bp->bp_flags & DHCP_FLAGS_B) 410 dhcp_stat = REBINDING; 411 else 412 dhcp_stat = RENEWING; 409 dhcp_stat = REBINDING; 410 else 411 dhcp_stat = RENEWING; 413 412 } 414 413 } … … 416 415 switch (dhcp_stat) 417 416 { 418 case RENEWING: 419 { 420 Assert(( server_ip == NULL 417 case RENEWING: 418 { 419 Assert(( server_ip == NULL 421 420 && req_ip == NULL 422 421 && bp->bp_ciaddr.s_addr != INADDR_ANY)); … … 428 427 else 429 428 { 430 if ((bp->bp_ciaddr.s_addr & htonl(pData->netmask)) != special_addr.s_addr) 429 if ((bp->bp_ciaddr.s_addr & htonl(pData->netmask)) != special_addr.s_addr) 431 430 { 432 431 off = dhcp_send_nack(pData, bp, bc, m); … … 441 440 Assert((bp->bp_hlen == ETH_ALEN)); 442 441 memcpy(bc->macaddr, bp->bp_hwaddr, bp->bp_hlen); 443 bc->addr.s_addr = bp->bp_ciaddr.s_addr; 442 bc->addr.s_addr = bp->bp_ciaddr.s_addr; 444 443 slirp_arp_cache_update(pData, bp->bp_ciaddr.s_addr, bp->bp_hwaddr); 445 444 } … … 450 449 Assert(req_ip != NULL); 451 450 ui32 = *(uint32_t *)(req_ip + 2); 452 if ((ui32 & htonl(pData->netmask)) != special_addr.s_addr) 451 if ((ui32 & htonl(pData->netmask)) != special_addr.s_addr) 453 452 { 454 453 LogRel(("NAT: address %R[IP4] has been req.\n", &ui32)); … … 464 463 Assert((bp->bp_hlen == ETH_ALEN)); 465 464 memcpy(bc->macaddr, bp->bp_hwaddr, bp->bp_hlen); 466 bc->addr.s_addr = ui32; 465 bc->addr.s_addr = ui32; 467 466 slirp_arp_cache_update(pData, bp->bp_ciaddr.s_addr, bp->bp_hwaddr); 468 467 break; … … 499 498 bc->xid = bp->bp_xid; 500 499 /*bc isn't NULL */ 501 off = dhcp_send_offer(pData, bp, bc, m); 500 off = dhcp_send_offer(pData, bp, bc, m); 502 501 return off; 503 } 502 } 504 503 else 505 504 { … … 511 510 return -1; 512 511 } 513 off = dhcp_send_ack(pData, bp, bc, m, 0); 512 off = dhcp_send_ack(pData, bp, bc, m, 0); 514 513 return off; 515 514 } … … 584 583 * Site-specific MAY MAY MUST NOT 585 584 * All others MAY MAY MUST NOT 586 * 585 * 587 586 */ 588 587 static void dhcp_decode(PNATState pData, struct bootp_t *bp, const uint8_t *buf, int size) … … 590 589 const uint8_t *p, *p_end; 591 590 int rc; 592 int pmsg_type; 591 int pmsg_type; 593 592 struct in_addr req_ip; 594 593 int flag = 0; … … 655 654 static void bootp_reply(PNATState pData, struct mbuf *m, int off, uint16_t flags) 656 655 { 657 struct sockaddr_in saddr, daddr; 656 struct sockaddr_in saddr, daddr; 658 657 struct bootp_t *rbp = NULL; 659 658 uint8_t *q = NULL; … … 674 673 FILL_BOOTP_EXT(q, RFC2132_SRV_ID, 4, &saddr.sin_addr); 675 674 676 675 677 676 *q++ = RFC1533_END; /*end of message */ 678 677 679 678 680 679 #ifdef VBOX_WITH_SLIRP_BSD_MBUF … … 708 707 { 709 708 int rc = 1; 710 uint32_t ip = INADDR_ANY; 709 uint32_t ip = INADDR_ANY; 711 710 int i; 712 711 if (ether == NULL || pip == NULL) … … 746 745 747 746 /* 748 * Initialize dhcp server 747 * Initialize dhcp server 749 748 * @returns 0 - if initialization is ok, non-zero otherwise 750 749 */ -
trunk/src/VBox/Devices/Network/slirp/cksum.c
r14964 r23369 42 42 * This routine is very heavily used in the network 43 43 * code and should be modified for each CPU to be as fast as possible. 44 * 44 * 45 45 * XXX Since we will never span more than 1 mbuf, we can optimise this 46 46 */ … … 66 66 u_int32_t l; 67 67 } l_util; 68 68 69 69 if (m->m_len == 0) 70 70 goto cont; … … 72 72 73 73 mlen = m->m_len; 74 74 75 75 if (len < mlen) 76 76 mlen = len; … … 114 114 sum += *w++; 115 115 } 116 116 117 117 if (byte_swapped) 118 118 { … … 131 131 else if (mlen == -1) 132 132 s_util.c[0] = *(u_int8_t *)w; 133 133 134 134 cont: 135 135 #ifdef DEBUG -
trunk/src/VBox/Devices/Network/slirp/debug.c
r23154 r23369 249 249 AssertReturn(strcmp(pszType, "ether") == 0, 0); 250 250 if (ether != NULL) 251 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 251 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 252 252 "[ether %hhx:%hhx:%hhx:%hhx:%hhx:%hhx]", 253 ether[0], ether[1], ether[2], 253 ether[0], ether[1], ether[2], 254 254 ether[3], ether[4], ether[5]); 255 255 else … … 271 271 272 272 AssertReturn(strcmp(pszType, "natsock") == 0, 0); 273 if (so == NULL) 274 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 273 if (so == NULL) 274 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 275 275 "socket is null"); 276 if (so->so_state == SS_NOFDREF || so->s == -1) 277 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 276 if (so->so_state == SS_NOFDREF || so->s == -1) 277 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 278 278 "socket(%d) SS_NODREF",so->s); 279 279 status = getsockname(so->s, &addr, &socklen); … … 281 281 if(status != 0 || addr.sa_family != AF_INET) 282 282 { 283 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 283 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 284 284 "socket(%d) is invalid(probably closed)",so->s); 285 285 } … … 290 290 "state=%04x ip=" IP4_ADDR_PRINTF_FORMAT ":%d " 291 291 "name=" IP4_ADDR_PRINTF_FORMAT ":%d", 292 so->s, so->so_type, so->so_state, IP4_ADDR_PRINTF_DECOMP(ip), 293 ntohs(so->so_fport), 292 so->s, so->so_type, so->so_state, IP4_ADDR_PRINTF_DECOMP(ip), 293 ntohs(so->so_fport), 294 294 IP4_ADDR_PRINTF_DECOMP(ntohl(in_addr->sin_addr.s_addr)), 295 295 ntohs(in_addr->sin_port)); … … 309 309 AssertReturn(strcmp(pszType, "natwinnetevents") == 0, 0); 310 310 311 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "events=%02x (", 311 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "events=%02x (", 312 312 pNetworkEvents->lNetworkEvents); 313 313 # define DO_BIT(bit) \ … … 354 354 { 355 355 /* 356 * XXX(r - frank): Move this to IPRT using RTNETADDRIPV4. 356 * XXX(r - frank): Move this to IPRT using RTNETADDRIPV4. 357 357 * Use the specifier %RNAipv4. 358 358 */ … … 363 363 rc = RTStrFormatTypeRegister("natsock", print_socket, NULL); 364 364 AssertRC(rc); 365 rc = RTStrFormatTypeRegister("natwinnetevents", 365 rc = RTStrFormatTypeRegister("natwinnetevents", 366 366 print_networkevents, NULL); 367 367 AssertRC(rc); -
trunk/src/VBox/Devices/Network/slirp/if.c
r23163 r23369 146 146 ifq = TAILQ_LAST(&if_batchq, if_queue); 147 147 } 148 148 149 149 /* queue already created */ 150 150 #endif … … 282 282 if_encap(pData, ETH_P_IP, ifm); 283 283 284 if (!if_queued) 284 if (!if_queued) 285 285 { 286 286 return; -
trunk/src/VBox/Devices/Network/slirp/if.h
r15933 r23369 1 1 /* 2 2 * Copyright (c) 1995 Danny Gasparovski. 3 * 4 * Please read the file COPYRIGHT for the 3 * 4 * Please read the file COPYRIGHT for the 5 5 * terms and conditions of the copyright. 6 6 */ -
trunk/src/VBox/Devices/Network/slirp/ip_icmp.c
r23154 r23369 555 555 { 556 556 size = MCLBYTES; 557 } 557 } 558 558 else if (new_m_size < MCLBYTES) 559 559 { -
trunk/src/VBox/Devices/Network/slirp/ip_input.c
r23240 r23369 79 79 if (t = m_tag_find(m, PACKET_TAG_ALIAS, NULL) != 0) 80 80 { 81 return (struct libalias *)&t[1]; 81 return (struct libalias *)&t[1]; 82 82 } 83 83 #endif … … 234 234 return; 235 235 bad: 236 Log2(("NAT: IP datagram to %R[IP4] with size(%d) claimed as bad\n", 236 Log2(("NAT: IP datagram to %R[IP4] with size(%d) claimed as bad\n", 237 237 &ip->ip_dst, ip->ip_len)); 238 238 m_freem(pData, m); -
trunk/src/VBox/Devices/Network/slirp/ip_output.c
r23202 r23369 65 65 if (rc == 0) 66 66 return rc; 67 /* 68 * no chance to send this packet, sorry, we will request ether address via ARP 69 */ 70 slirp_arp_who_has(pData, dst); 71 return rc; 67 /* 68 * no chance to send this packet, sorry, we will request ether address via ARP 69 */ 70 slirp_arp_who_has(pData, dst); 71 return rc; 72 72 } 73 73 … … 152 152 } 153 153 #else 154 /* 154 /* 155 155 * (vvl) Assumption is that m_data points at the IP header and only 156 156 * in case of dhcp we know and have header before IP. … … 170 170 ip->ip_sum = 0; 171 171 ip->ip_sum = cksum(m, hlen); 172 172 173 173 { 174 174 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 175 175 STAM_PROFILE_START(&pData->StatALIAS_output, a); 176 rc = LibAliasOut((m->m_la ? m->m_la : pData->proxy_alias), 176 rc = LibAliasOut((m->m_la ? m->m_la : pData->proxy_alias), 177 177 mtod(m, char *), m->m_len); 178 178 Log2(("NAT: LibAlias return %d\n", rc)); … … 186 186 else 187 187 { 188 rc = LibAliasOut(pData->proxy_alias, mtod(m, char *), 188 rc = LibAliasOut(pData->proxy_alias, mtod(m, char *), 189 189 m_length(m, NULL)); 190 } 190 } 191 191 if (rc == PKT_ALIAS_IGNORED) 192 192 { … … 198 198 } 199 199 200 memcpy(eh->h_source, eth_dst, ETH_ALEN); 200 memcpy(eh->h_source, eth_dst, ETH_ALEN); 201 201 202 202 if_output(pData, so, m); … … 240 240 ip->ip_sum = cksum(m, hlen); 241 241 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 242 rc = LibAliasOut((m->m_la ? m->m_la : pData->proxy_alias), 242 rc = LibAliasOut((m->m_la ? m->m_la : pData->proxy_alias), 243 243 mtod(m, char *), m->m_len); 244 244 #else … … 264 264 { 265 265 rc = LibAliasOut(pData->proxy_alias, tmpbuf, tmplen); 266 } 266 } 267 267 if (m->m_next != NULL) 268 268 { … … 379 379 m->m_data += ETH_HLEN; 380 380 #endif 381 memcpy(eh->h_source, eth_dst, ETH_ALEN); 381 memcpy(eh->h_source, eth_dst, ETH_ALEN); 382 382 383 383 if_output(pData, so, m); 384 384 } 385 else 385 else 386 386 { 387 387 m_freem(pData, m); -
trunk/src/VBox/Devices/Network/slirp/libslirp.h
r23163 r23369 57 57 58 58 int slirp_redir(PNATState pData, int is_udp, struct in_addr host_addr, 59 int host_port, struct in_addr guest_addr, 59 int host_port, struct in_addr guest_addr, 60 60 int guest_port, const uint8_t *); 61 61 int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte, -
trunk/src/VBox/Devices/Network/slirp/mbuf.c
r23242 r23369 34 34 * Find a nice value for msize 35 35 */ 36 msize = (if_mtu>if_mru ? if_mtu : if_mru) 36 msize = (if_mtu>if_mru ? if_mtu : if_mru) 37 37 + sizeof(struct m_hdr) + sizeof(void *) /*pointer to the backstore*/ 38 38 + if_maxlinkhdr ; … … 244 244 else 245 245 { 246 if ( (char *)dat >= m->m_dat 246 if ( (char *)dat >= m->m_dat 247 247 && (char *)dat < (m->m_dat + m->m_size)) 248 248 return m; -
trunk/src/VBox/Devices/Network/slirp/misc.c
r23154 r23369 117 117 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 118 118 #define ITEM_MAGIC 0xdead0001 119 struct item 119 struct item 120 120 { 121 121 uint32_t magic; … … 146 146 147 147 148 static void *slirp_uma_alloc(uma_zone_t zone, 148 static void *slirp_uma_alloc(uma_zone_t zone, 149 149 int size, uint8_t *pflags, int wait) 150 150 { … … 155 155 { 156 156 /* 157 * @todo (r=vvl) here should be some 158 * accounting of extra items in case 157 * @todo (r=vvl) here should be some 158 * accounting of extra items in case 159 159 * breakthrough barrier 160 160 */ 161 161 if (LIST_EMPTY(&zone->free_items)) 162 return NULL; 162 return NULL; 163 163 it = LIST_FIRST(&zone->free_items); 164 LIST_REMOVE(it, list); 164 LIST_REMOVE(it, list); 165 165 LIST_INSERT_HEAD(&zone->used_items, it, list); 166 166 goto allocated; … … 188 188 struct item *it; 189 189 uma_zone_t zone; 190 Assert(item); 190 Assert(item); 191 191 it = &((struct item *)item)[-1]; 192 192 Assert(it->magic == ITEM_MAGIC); 193 193 zone = it->zone; 194 194 Assert(zone->magic == ZONE_MAGIC); 195 LIST_REMOVE(it, list); 195 LIST_REMOVE(it, list); 196 196 LIST_INSERT_HEAD(&zone->free_items, it, list); 197 197 } 198 198 199 uma_zone_t uma_zcreate(PNATState pData, char *name, size_t size, 199 uma_zone_t uma_zcreate(PNATState pData, char *name, size_t size, 200 200 ctor_t ctor, dtor_t dtor, zinit_t init, zfini_t fini, int flags1, int flags2) 201 201 { … … 213 213 zone->pfFree = slirp_uma_free; 214 214 return zone; 215 216 } 217 uma_zone_t uma_zsecond_create(char *name, ctor_t ctor, 215 216 } 217 uma_zone_t uma_zsecond_create(char *name, ctor_t ctor, 218 218 dtor_t dtor, zinit_t init, zfini_t fini, uma_zone_t master) 219 219 { 220 220 uma_zone_t zone; 221 221 #if 0 222 if (master->pfAlloc != NULL) 222 if (master->pfAlloc != NULL) 223 223 zone = (uma_zone_t)master->pfAlloc(master, sizeof(struct uma_zone), NULL, 0); 224 #endif 224 #endif 225 225 zone = RTMemAllocZ(sizeof(struct uma_zone)); 226 if (zone == NULL) 226 if (zone == NULL) 227 227 { 228 228 return NULL; … … 247 247 void uma_zone_set_allocf(uma_zone_t zone, uma_alloc_t pfAlloc) 248 248 { 249 zone->pfAlloc = pfAlloc; 249 zone->pfAlloc = pfAlloc; 250 250 } 251 251 void uma_zone_set_freef(uma_zone_t zone, uma_free_t pfFree) 252 252 { 253 zone->pfFree = pfFree; 253 zone->pfFree = pfFree; 254 254 } 255 255 256 256 uint32_t *uma_find_refcnt(uma_zone_t zone, void *mem) 257 257 { 258 /*@todo (r-vvl) this function supposed to work with special zone storing 259 reference counters */ 258 /*@todo (r-vvl) this function supposed to work with special zone storing 259 reference counters */ 260 260 struct item *it = (struct item *)mem; /* 1st element */ 261 261 Assert(zone->magic == ZONE_MAGIC); … … 288 288 return; 289 289 Assert((mem)); 290 it = &((struct item *)mem)[-1]; 290 it = &((struct item *)mem)[-1]; 291 291 if (it->magic != ITEM_MAGIC) 292 292 { … … 296 296 } 297 297 Assert((zone->magic == ZONE_MAGIC && zone == it->zone)); 298 298 299 299 if (zone->pfDtor) 300 300 zone->pfDtor(zone->pData, mem, zone->size, flags); … … 307 307 void zone_drain(uma_zone_t zone) 308 308 { 309 310 309 } 311 310 -
trunk/src/VBox/Devices/Network/slirp/sbuf.c
r23154 r23369 92 92 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 93 93 if (m->m_len <= 0) 94 #else 94 #else 95 95 mlen = m_length(m, NULL); 96 96 if (mlen <= 0) … … 127 127 ret = 0; 128 128 goto no_sent; 129 } 129 } 130 130 m_copydata(m, 0, mlen, buf); 131 131 if(!so->so_rcv.sb_cc) -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r23164 r23369 274 274 return VERR_NO_MEMORY; 275 275 } 276 LogRel(("NAT: adding %R[IP4] to DNS server list\n", 276 LogRel(("NAT: adding %R[IP4] to DNS server list\n", 277 277 &((struct sockaddr_in *)saddr)->sin_addr)); 278 if (((( struct sockaddr_in *)saddr)->sin_addr.s_addr & htonl(IN_CLASSA_NET)) == 278 if (((( struct sockaddr_in *)saddr)->sin_addr.s_addr & htonl(IN_CLASSA_NET)) == 279 279 ntohl(INADDR_LOOPBACK & IN_CLASSA_NET)) { 280 280 da->de_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS); … … 341 341 char *pu8Buf = (char *)pvBuf; 342 342 *pcbRead = 0; 343 while( RT_SUCCESS(rc = RTFileRead(File, &bTest, 1, &cbRead)) 343 while( RT_SUCCESS(rc = RTFileRead(File, &bTest, 1, &cbRead)) 344 344 && (pu8Buf - (char *)pvBuf) < cbBufSize) 345 345 { … … 549 549 { 550 550 LogRel(("NAT: DHCP server initialization was failed\n")); 551 return VINF_NAT_DNS; 551 return VINF_NAT_DNS; 552 552 } 553 553 debug_init(); … … 684 684 if (pData->use_host_resolver) 685 685 dns_alias_unload(pData); 686 while(!LIST_EMPTY(&instancehead)) 686 while(!LIST_EMPTY(&instancehead)) 687 687 { 688 688 struct libalias *la = LIST_FIRST(&instancehead); … … 690 690 LibAliasUninit(la); 691 691 } 692 while(!LIST_EMPTY(&pData->arp_cache)) 692 while(!LIST_EMPTY(&pData->arp_cache)) 693 693 { 694 694 struct arp_cache_entry *ac = LIST_FIRST(&pData->arp_cache); … … 1439 1439 && memcmp(eh->h_dest, broadcast_ethaddr, ETH_ALEN) == 0) 1440 1440 { 1441 /* we've received anounce about address asignment 1441 /* we've received anounce about address asignment 1442 1442 * Let's do ARP cache update 1443 1443 */ 1444 if (slirp_arp_cache_update(pData, *(uint32_t *)ah->ar_tip, &eh->h_dest[0]) == 0) 1444 if (slirp_arp_cache_update(pData, *(uint32_t *)ah->ar_tip, &eh->h_dest[0]) == 0) 1445 1445 { 1446 1446 m_free(pData, mr); … … 1448 1448 break; 1449 1449 } 1450 slirp_arp_cache_add(pData, *(uint32_t *)ah->ar_tip, &eh->h_dest[0]); 1450 slirp_arp_cache_add(pData, *(uint32_t *)ah->ar_tip, &eh->h_dest[0]); 1451 1451 /* good opportunity to activate port-forwarding on address (self)asignment*/ 1452 1452 activate_port_forwarding(pData, eh); … … 1463 1463 /*after/save restore we need up port forwarding again*/ 1464 1464 if (pData->port_forwarding_activated == 0) 1465 activate_port_forwarding(pData, eh); 1465 activate_port_forwarding(pData, eh); 1466 1466 m_free(pData, m); 1467 1467 } … … 1504 1504 { 1505 1505 size = MCLBYTES; 1506 } 1506 } 1507 1507 else if (pkt_len < MCLBYTES) 1508 1508 { … … 1898 1898 Log2(("NAT: DNS proxy switched %s\n", (fDNSProxy ? "on" : "off"))); 1899 1899 pData->use_dns_proxy = fDNSProxy; 1900 } 1900 } 1901 1901 else 1902 1902 { … … 2032 2032 } 2033 2033 2034 /* updates the arp cache 2034 /* updates the arp cache 2035 2035 * @returns 0 - if has found and updated 2036 2036 * 1 - if hasn't found. … … 2072 2072 mtu = 1500; 2073 2073 } 2074 if_mtu = 2074 if_mtu = 2075 2075 if_mru = mtu; 2076 2076 } -
trunk/src/VBox/Devices/Network/slirp/slirp.h
r23154 r23369 383 383 384 384 # define strncasecmp RTStrNICmp 385 # define stderr NULL 386 # define stdout NULL 385 # define stderr NULL 386 # define stdout NULL 387 387 388 388 # ifdef DEBUG … … 395 395 396 396 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 397 /* @todo might be useful to make it configurable, 397 /* @todo might be useful to make it configurable, 398 398 * especially in terms of Intnet behind NAT 399 399 */ 400 # define maxusers 32 400 # define maxusers 32 401 401 # define max_protohdr 0 402 402 /* @todo (r=vvl) for now ignore value, … … 416 416 void *newptr; 417 417 }; 418 418 419 419 #define SYSCTL_HANDLER_ARGS PNATState pData, void *oidp, struct dummy_req *req 420 420 -
trunk/src/VBox/Devices/Network/slirp/slirp_state.h
r23158 r23369 38 38 39 39 /* 40 * ARP cache this is naive implementaion of ARP 41 * cache of mapping 4 byte IPv4 address to 6 byte 40 * ARP cache this is naive implementaion of ARP 41 * cache of mapping 4 byte IPv4 address to 6 byte 42 42 * ethernet one. 43 43 */ … … 228 228 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 229 229 # ifdef zone_mbuf 230 # undef zone_mbuf 230 # undef zone_mbuf 231 231 # endif 232 232 uma_zone_t zone_mbuf; … … 261 261 uma_zone_t zone_ext_refcnt; 262 262 #endif 263 int use_host_resolver; 263 int use_host_resolver; 264 264 /* from dnsproxy/dnsproxy.h*/ 265 265 unsigned int authoritative_port; -
trunk/src/VBox/Devices/Network/slirp/socket.c
r23241 r23369 62 62 63 63 so = (struct socket *)RTMemAllocZ(sizeof(struct socket)); 64 if (so)64 if (so) 65 65 { 66 66 so->so_state = SS_NOFDREF; … … 91 91 m_free(pData, so->so_m); 92 92 #ifndef VBOX_WITH_SLIRP_MT 93 if (so->so_next && so->so_prev)93 if (so->so_next && so->so_prev) 94 94 { 95 95 remque(pData, so); /* crashes if so is not in a queue */ … … 167 167 iov[1].iov_base = sb->sb_data; 168 168 iov[1].iov_len = sb->sb_rptr - sb->sb_data; 169 if (iov[1].iov_len > len)169 if (iov[1].iov_len > len) 170 170 iov[1].iov_len = len; 171 171 total = iov[0].iov_len + iov[1].iov_len; … … 224 224 } 225 225 #endif 226 if (nn < 0 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) 226 if ( nn < 0 227 && ( errno == EINTR 228 || errno == EAGAIN 229 || errno == EWOULDBLOCK)) 227 230 { 228 231 SOCKET_UNLOCK(so); … … 272 275 nn += ret; 273 276 STAM_STATS( 274 if (ret > 0)277 if (ret > 0) 275 278 { 276 279 STAM_COUNTER_INC(&pData->StatIORead_in_2); … … 482 485 #endif 483 486 /* This should never happen, but people tell me it does *shrug* */ 484 if (nn < 0 && (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK)) 487 if ( nn < 0 488 && ( errno == EAGAIN 489 || errno == EINTR 490 || errno == EWOULDBLOCK)) 485 491 { 486 492 SOCKET_UNLOCK(so); … … 569 575 int size; 570 576 #endif 571 577 int rc = 0; 572 578 static int signaled = 0; 573 579 … … 593 599 { 594 600 rc = ioctlsocket(so->s, FIONREAD, &n); 595 if ( (rc == -1)596 && ( errno == EAGAIN601 if ( rc == -1 602 && ( errno == EAGAIN 597 603 || errno == EWOULDBLOCK 598 604 || errno == EINPROGRESS … … 608 614 m_free(pData, m); 609 615 return; 610 } 616 } 611 617 612 618 if (rc > 0 && n > len) … … 629 635 */ 630 636 rc = ioctlsocket(so->s, FIONREAD, &n); 631 632 637 if (rc == -1 && signaled == 0) 633 638 { 634 639 LogRel(("NAT: can't fetch amount of bytes on socket %R[natsock], so message will be truncated.\n", so)); 635 640 signaled = 1; 636 } 641 } 637 642 638 643 len = sizeof(struct udpiphdr) + ETH_HLEN; 639 644 len += n; 640 645 641 646 if (len < MSIZE) 642 647 { 643 648 size = MCLBYTES; 644 } 649 } 645 650 else if (len < MCLBYTES) 646 651 { 647 652 size = MCLBYTES; 648 653 } 649 else if (len < MJUM9BYTES)654 else if (len < MJUM9BYTES) 650 655 { 651 656 size = MJUM9BYTES; … … 660 665 } 661 666 m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size); 662 m->m_data += ETH_HLEN; 667 m->m_data += ETH_HLEN; 663 668 m->m_pkthdr.header = mtod(m, void *); 664 m->m_data += sizeof(struct udpiphdr); 669 m->m_data += sizeof(struct udpiphdr); 665 670 ret = recvfrom(so->s, mtod(m, char *), n, 0, 666 671 (struct sockaddr *)&addr, &addrlen); … … 668 673 #endif 669 674 m->m_len = ret; 670 if (ret < 0)675 if (ret < 0) 671 676 { 672 677 u_char code = ICMP_UNREACH_PORT; … … 674 679 if (errno == EHOSTUNREACH) 675 680 code = ICMP_UNREACH_HOST; 676 else if (errno == ENETUNREACH)681 else if (errno == ENETUNREACH) 677 682 code = ICMP_UNREACH_NET; 678 683 … … 750 755 DEBUG_ARG("so = %lx", (long)so); 751 756 DEBUG_ARG("m = %lx", (long)m); 752 757 753 758 memset(&addr, 0, sizeof(struct sockaddr)); 754 759 #ifdef RT_OS_DARWIN … … 1271 1276 int rc = 0; 1272 1277 static int signalled = 0; 1278 1273 1279 rc = ioctlsocket(so->s, FIONREAD, &len); 1274 if ( rc == -1 1275 && ( errno == EAGAIN1276 || errno == EWOULDBLOCK1277 || errno == EINPROGRESS1278 || errno == ENOTCONN))1280 if ( rc == -1 1281 && ( errno == EAGAIN 1282 || errno == EWOULDBLOCK 1283 || errno == EINPROGRESS 1284 || errno == ENOTCONN)) 1279 1285 { 1280 1286 return; … … 1296 1302 { 1297 1303 u_char code; 1298 if ( len == -1 1304 if ( len == -1 1299 1305 && (errno == EAGAIN 1300 1306 || errno == EWOULDBLOCK … … 1308 1314 if (errno == EHOSTUNREACH) 1309 1315 code = ICMP_UNREACH_HOST; 1310 else if (errno == ENETUNREACH)1316 else if (errno == ENETUNREACH) 1311 1317 code = ICMP_UNREACH_NET; 1312 1318 -
trunk/src/VBox/Devices/Network/slirp/socket.h
r22013 r23369 75 75 #else /* !RT_OS_WINDOWS */ 76 76 /* 77 * FD_CLOSE event has been occurred on socket 77 * FD_CLOSE event has been occurred on socket 78 78 */ 79 int so_close; 79 int so_close; 80 80 #endif /* RT_OS_WINDOWS */ 81 81 … … 85 85 #ifdef VBOX_WITH_NAT_SERVICE 86 86 /* storage of source ether address */ 87 unsigned char so_ethaddr[6]; 87 unsigned char so_ethaddr[6]; 88 88 #endif 89 89 /* required for port-forwarding */ -
trunk/src/VBox/Devices/Network/slirp/tcp_output.c
r23154 r23369 216 216 * TCP_MAXWIN << tp->rcv_scale. 217 217 */ 218 long adv = min(win, 219 (long)TCP_MAXWIN << tp->rcv_scale) - 218 long adv = min(win, 219 (long)TCP_MAXWIN << tp->rcv_scale) - 220 220 (tp->rcv_adv - tp->rcv_nxt); 221 221 … … 378 378 { 379 379 size = MCLBYTES; 380 } 380 } 381 381 else if ((len + hdrlen + ETH_HLEN) < MCLBYTES) 382 382 { … … 460 460 { 461 461 size = MCLBYTES; 462 } 462 } 463 463 else if ((hdrlen + ETH_HLEN) < MCLBYTES) 464 464 { … … 574 574 * the retransmit. In persist state, just set snd_max. 575 575 */ 576 if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0) 576 if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0) 577 577 { 578 578 tcp_seq startseq = tp->snd_nxt; -
trunk/src/VBox/Devices/Network/slirp/tcp_subr.c
r23166 r23369 447 447 socklen_t addrlen = sizeof(struct sockaddr_in); 448 448 struct tcpcb *tp; 449 int s, opt; 449 int s, opt; 450 450 int status; 451 451 socklen_t optlen; -
trunk/src/VBox/Devices/Network/slirp/tcp_timer.c
r22249 r23369 86 86 return; 87 87 QSOCKET_FOREACH(ip, ipnxt, tcp) 88 /* { */ 88 /* { */ 89 89 ipnxt = ip->so_next; 90 90 tp = sototcpcb(ip); -
trunk/src/VBox/Devices/Network/slirp/tftp.c
r22873 r23369 187 187 nobytes = 2; 188 188 189 m->m_len = sizeof(struct tftp_t) 189 m->m_len = sizeof(struct tftp_t) 190 190 - 514 191 + 3 191 + 3 192 192 + strlen(msg) 193 - sizeof(struct ip) 193 - sizeof(struct ip) 194 194 - sizeof(struct udphdr); 195 195 … … 242 242 } 243 243 244 m->m_len = sizeof(struct tftp_t) 245 - (512 - nobytes) 246 - sizeof(struct ip) 244 m->m_len = sizeof(struct tftp_t) 245 - (512 - nobytes) 246 - sizeof(struct ip) 247 247 - sizeof(struct udphdr); 248 248 -
trunk/src/VBox/Devices/Network/slirp/udp.c
r23161 r23369 162 162 } 163 163 164 if ( pData->use_host_resolver 164 if ( pData->use_host_resolver 165 165 && ntohs(uh->uh_dport) == 53 166 166 && CTL_CHECK(ntohl(ip->ip_dst.s_addr), CTL_DNS)) … … 172 172 dst.sin_port = uh->uh_sport; 173 173 /* udp_output2 will do opposite operations on mbuf*/ 174 174 175 175 m->m_data += sizeof(struct udpiphdr); 176 176 m->m_len -= sizeof(struct udpiphdr); … … 260 260 if ( pData->use_dns_proxy 261 261 && (ip->ip_dst.s_addr == htonl(ntohl(special_addr.s_addr) | CTL_DNS)) 262 && (ntohs(uh->uh_dport) == 53)) 262 && (ntohs(uh->uh_dport) == 53)) 263 263 { 264 264 dnsproxy_query(pData, so, m, iphlen); … … 287 287 m->m_data -= iphlen; 288 288 *ip = save_ip; 289 DEBUG_MISC((dfd,"NAT: UDP tx errno = %d-%s (on sent to %R[IP4])\n", errno, 289 DEBUG_MISC((dfd,"NAT: UDP tx errno = %d-%s (on sent to %R[IP4])\n", errno, 290 290 strerror(errno), &ip->ip_dst)); 291 291 icmp_error(pData, m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); 292 292 /* in case we receive ICMP on this socket we'll aware that ICMP has been already sent to host*/ 293 so->so_m = NULL; 293 so->so_m = NULL; 294 294 } 295 295 … … 306 306 307 307 bad: 308 Log2(("NAT: UDP(id: %hd) datagram to %R[IP4] with size(%d) claimed as bad\n", 308 Log2(("NAT: UDP(id: %hd) datagram to %R[IP4] with size(%d) claimed as bad\n", 309 309 ip->ip_id, &ip->ip_dst, ip->ip_len)); 310 done: 310 done: 311 311 /* some services like bootp(built-in), dns(buildt-in) and dhcp don't need sockets 312 * and create new m'buffers to send them to guest, so we'll free their incomming 313 * buffers here. 312 * and create new m'buffers to send them to guest, so we'll free their incomming 313 * buffers here. 314 314 */ 315 315 m_freem(pData, m); … … 343 343 memset(ui->ui_x1, 0, 9); 344 344 ui->ui_pr = IPPROTO_UDP; 345 ui->ui_len = htons(m->m_len - sizeof(struct ip)); 345 ui->ui_len = htons(m->m_len - sizeof(struct ip)); 346 346 /* XXXXX Check for from-one-location sockets, or from-any-location sockets */ 347 347 ui->ui_src = saddr->sin_addr;
Note:
See TracChangeset
for help on using the changeset viewer.