Changeset 23154 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Sep 19, 2009 11:02:11 AM (15 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/bootp.c
r22669 r23154 176 176 uint8_t *q; 177 177 178 eh = mtod(m, struct ethhdr *); 179 memcpy(eh->h_source, bp->bp_hwaddr, ETH_ALEN); /* XXX: if_encap just swap source with dest*/ 180 181 m->m_data += if_maxlinkhdr; /*reserve ether header */ 182 178 183 rbp = mtod(m, struct bootp_t *); 179 184 memset(rbp, 0, sizeof(struct bootp_t)); 180 eh = mtod(m, struct ethhdr *);181 memcpy(eh->h_source, bp->bp_hwaddr, ETH_ALEN); /* XXX: if_encap just swap source with dest*/182 m->m_data += if_maxlinkhdr; /*reserve ether header */183 rbp = mtod(m, struct bootp_t *);184 185 rbp->bp_op = BOOTP_REPLY; 185 186 rbp->bp_xid = bp->bp_xid; /* see table 3 of rfc2131*/ … … 607 608 if (p == NULL) 608 609 return; 610 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 609 611 if ((m = m_get(pData)) == NULL) 612 #else 613 if ((m = m_getcl(pData, M_DONTWAIT, MT_HEADER, M_PKTHDR)) == NULL) 614 #endif 610 615 { 611 616 LogRel(("NAT: can't alocate memory for response!\n")); … … 673 678 674 679 680 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 681 m->m_pkthdr.header = mtod(m, void *); 682 #endif 675 683 m->m_len = sizeof(struct bootp_t) 676 684 - sizeof(struct ip) -
trunk/src/VBox/Devices/Network/slirp/counters.h
r23141 r23154 34 34 do { \ 35 35 PDMDrvHlpSTAMRegisterF(pDrvIns, \ 36 &(storage)->Stat ## name, 36 &(storage)->Stat ## name, \ 37 37 type, \ 38 38 STAMVISIBILITY_ALWAYS, \ -
trunk/src/VBox/Devices/Network/slirp/debug.c
r22873 r23154 159 159 mbufstats(PNATState pData) 160 160 { 161 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 161 162 struct mbuf *m; 162 163 int i; … … 178 179 lprint(" %6d mbufs on used list\n", i); 179 180 lprint(" %6d mbufs queued as packets\n\n", if_queued); 181 #endif 180 182 } 181 183 -
trunk/src/VBox/Devices/Network/slirp/ext.h
r22894 r23154 57 57 #ifndef _EXT_H_ 58 58 #define _EXT_H_ 59 # define fprintf vbox_slirp_fprintf 60 # define printf vbox_slirp_printf 59 61 #ifndef vbox_slirp_printfV 60 62 static void vbox_slirp_printV(char *format, va_list args) -
trunk/src/VBox/Devices/Network/slirp/if.c
r22206 r23154 9 9 10 10 11 #define ifs_init(ifm) ((ifm)->ifs_next = (ifm)->ifs_prev = (ifm)) 11 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 12 # define ifs_init(ifm) ((ifm)->ifs_next = (ifm)->ifs_prev = (ifm)) 12 13 13 14 static void ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead) … … 24 25 ifm->ifs_next->ifs_prev = ifm->ifs_prev; 25 26 } 27 #else 28 #endif 26 29 27 30 void … … 32 35 if_queued = 0; 33 36 if_thresh = 10; 37 if_comp = IF_AUTOCOMP; 38 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 34 39 if_mtu = 1500; 35 40 if_mru = 1500; 36 if_comp = IF_AUTOCOMP;37 41 if_fastq.ifq_next = if_fastq.ifq_prev = &if_fastq; 38 42 if_batchq.ifq_next = if_batchq.ifq_prev = &if_batchq; 39 43 /* sl_compress_init(&comp_s); */ 40 44 next_m = &if_batchq; 45 #else 46 if_mtu = 1500; 47 if_mru = 1500; 48 TAILQ_INIT(&if_fastq); 49 TAILQ_INIT(&if_batchq); 50 next_m = TAILQ_FIRST(&if_fastq); 51 #endif 41 52 } 42 53 … … 64 75 DEBUG_ARG("ifm = %lx", (long)ifm); 65 76 77 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 66 78 /* 67 79 * First remove the mbuf from m_usedlist, … … 74 86 ifm->m_flags &= ~M_USEDLIST; 75 87 } 88 #endif 76 89 77 90 /* … … 82 95 * XXX add cache here? 83 96 */ 97 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 84 98 for (ifq = if_batchq.ifq_prev; ifq != &if_batchq; ifq = ifq->ifq_prev) 99 #else 100 TAILQ_FOREACH_REVERSE(ifq, &if_batchq, if_queue, m_ifq) 101 #endif 85 102 { 86 103 if (so == ifq->ifq_so) … … 88 105 /* A match! */ 89 106 ifm->ifq_so = so; 107 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 90 108 ifs_insque(ifm, ifq->ifs_prev); 109 #endif 91 110 goto diddit; 92 111 } … … 96 115 if (so && (so->so_iptos & IPTOS_LOWDELAY)) 97 116 { 117 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 98 118 ifq = if_fastq.ifq_prev; 119 #else 120 ifq = TAILQ_LAST(&if_fastq, if_queue); 121 #endif 99 122 on_fastq = 1; 100 123 /* … … 105 128 { 106 129 ifm->ifq_so = so; 130 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 107 131 ifs_insque(ifm, ifq->ifs_prev); 132 #endif 108 133 goto diddit; 109 134 } 110 135 } 136 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 111 137 else 112 138 ifq = if_batchq.ifq_prev; … … 116 142 ifs_init(ifm); 117 143 insque(pData, ifm, ifq); 144 #else 145 else 146 { 147 TAILQ_INSERT_TAIL(&if_batchq, ifm, m_ifq); 148 ifq = TAILQ_LAST(&if_batchq, if_queue); 149 } 150 151 /* queue already created */ 152 #endif 118 153 119 154 diddit: … … 136 171 && (so->so_nqueued - so->so_queued) >= 3) 137 172 { 173 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 138 174 /* Remove from current queue... */ 139 175 remque(pData, ifm->ifs_next); … … 141 177 /* ...And insert in the new. That'll teach ya! */ 142 178 insque(pData, ifm->ifs_next, &if_batchq); 179 #endif 143 180 } 144 181 } … … 172 209 { 173 210 struct mbuf *ifm, *ifqt; 211 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 212 struct if_queue *pqueue = NULL; 213 ifm = NULL; 214 ifqt = NULL; 215 #endif 174 216 175 217 DEBUG_CALL("if_start"); … … 187 229 } 188 230 231 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 189 232 /* 190 233 * See which queue to get next packet from … … 215 258 ifs_remque(ifm); 216 259 } 260 #else 261 if (!TAILQ_EMPTY(&if_fastq)) 262 { 263 pqueue = &if_fastq; 264 } 265 else if (!TAILQ_EMPTY(&if_batchq)) 266 { 267 pqueue = &if_batchq; 268 } 269 if (pqueue != NULL) { 270 ifm = TAILQ_FIRST(pqueue); 271 TAILQ_REMOVE(pqueue, ifm, m_ifq); 272 --if_queued; 273 } 274 #endif 217 275 218 276 /* Update so_queued */ -
trunk/src/VBox/Devices/Network/slirp/ip_icmp.c
r22897 r23154 326 326 m->m_len -= hlen; 327 327 m->m_data += hlen; 328 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 328 329 icp = mtod(m, struct icmp *); 330 #else 331 if (m->m_next != NULL) 332 { 333 char *buf = RTMemAlloc(icmplen); 334 m_copydata(m, 0, icmplen, buf); 335 icp = (struct icmp *)buf; 336 } 337 else 338 { 339 icp = mtod(m, struct icmp *); 340 } 341 #endif 329 342 if (cksum(m, icmplen)) 330 343 { … … 388 401 (struct sockaddr *)&addr, sizeof(addr)) == -1) 389 402 { 390 Log ((dfd,"icmp_input udp sendto tx errno = %d-%s\n",403 LogRel((dfd,"icmp_input udp sendto tx errno = %d-%s\n", 391 404 errno, strerror(errno))); 392 405 icmp_error(pData, m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); … … 455 468 m_freem(pData, m); 456 469 } /* switch */ 470 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 471 if (m->m_next != NULL && icp != NULL) 472 RTMemFree(icp); 473 #endif 457 474 458 475 end_error: … … 487 504 register struct icmp *icp; 488 505 register struct mbuf *m; 489 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 490 uint8_t *buf; /*(vvl) probably should be used mbuf of corresponded size instead*/ 491 #endif 506 int new_m_size = 0; 507 int size = 0; 492 508 493 509 DEBUG_CALL("icmp_error"); … … 495 511 DEBUG_ARG("msrc_len = %d", msrc ? msrc->m_len : 0); 496 512 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 497 M_ASSERTPKTHDR(msrc); 513 if (msrc != NULL) 514 M_ASSERTPKTHDR(msrc); 498 515 #endif 499 516 … … 532 549 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 533 550 /* make a copy */ 534 if (!(m = m_get(pData))) 551 m = m_get(pData); 552 #else 553 new_m_size = sizeof(struct ip) + ICMP_MINLEN + msrc->m_len + ICMP_MAXDATALEN; 554 if (new_m_size < MSIZE) 555 { 556 size = MCLBYTES; 557 } 558 else if (new_m_size < MCLBYTES) 559 { 560 size = MCLBYTES; 561 } 562 else if(new_m_size < MJUM9BYTES) 563 { 564 size = MJUM9BYTES; 565 } 566 else if (new_m_size < MJUM16BYTES) 567 { 568 size = MJUM16BYTES; 569 } 570 else 571 { 572 AssertMsgFailed(("Unsupported size")); 573 } 574 m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size); 575 #endif 576 if (m == NULL) 535 577 goto end_error; /* get mbuf */ 536 { 537 int new_m_size; 538 m->m_data += if_maxlinkhdr; 539 new_m_size = sizeof(struct ip) + ICMP_MINLEN + msrc->m_len + ICMP_MAXDATALEN; 540 if (new_m_size > m->m_size) 541 m_inc(m, new_m_size); 542 } 578 579 m->m_data += if_maxlinkhdr; 580 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 581 m->m_pkthdr.header = mtod(m, void *); 582 #else 583 new_m_size = sizeof(struct ip) + ICMP_MINLEN + msrc->m_len + ICMP_MAXDATALEN; 584 if (new_m_size > m->m_size) 585 m_inc(m, new_m_size); 586 #endif 543 587 544 588 memcpy(m->m_data, msrc->m_data, msrc->m_len); 545 589 m->m_len = msrc->m_len; /* copy msrc to m */ 546 #else547 if (!(m = m_gethdr(pData, M_DONTWAIT, MT_HEADER)))548 goto end_error; /* get mbuf */549 if (m_append(pData, m, m_length(msrc, NULL), mtod(msrc, const char *)) == 0)550 {551 m_freem(pData, m);552 goto end_error;553 }554 m->m_pkthdr.header = mtod(m, void *);555 #endif556 590 557 591 /* make the header of the reply packet */ … … 560 594 561 595 /* fill in icmp */ 562 #ifndef VBOX_WITH_SLIRP_BSD_MBUF563 596 m->m_data += hlen; 564 597 m->m_len -= hlen; 565 #else566 m_adj(m, hlen);567 #endif568 598 569 599 icp = mtod(m, struct icmp *); … … 574 604 s_ip_len = ICMP_MAXDATALEN; 575 605 576 #ifndef VBOX_WITH_SLIRP_BSD_MBUF577 606 m->m_len = ICMP_MINLEN + s_ip_len; /* 8 bytes ICMP header */ 578 #else579 m_adj(m, ICMP_MINLEN);580 #endif581 607 582 608 /* min. size = 8+sizeof(struct ip)+8 */ … … 587 613 icp->icmp_seq = 0; 588 614 589 #ifndef VBOX_WITH_SLIRP_BSD_MBUF590 615 memcpy(&icp->icmp_ip, msrc->m_data, s_ip_len); /* report the ip packet */ 591 #else 592 buf = RTMemAlloc(s_ip_len); 593 if (buf == NULL) 594 { 595 m_free(pData, m); 596 LogRel(("NAT:ICMP: can't allocate intermediate buffer, icmp error wasn't sent\n")); 597 goto end_error; 598 } 599 m_copydata(msrc, 0, s_ip_len, buf); 600 m_append(pData, m, s_ip_len, buf); 601 #endif 616 602 617 HTONS(icp->icmp_ip.ip_len); 603 618 HTONS(icp->icmp_ip.ip_id); -
trunk/src/VBox/Devices/Network/slirp/ip_input.c
r23005 r23154 72 72 struct ip *pip = NULL; 73 73 74 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 74 75 if (m->m_la) 75 76 return m->m_la; 76 77 #if 0 78 pip = mtod(m, struct ip *); 79 if (pip->ip_p == IPPROTO_UDP) { 80 udp = (struct udphdr *)((uint8_t *)pip + (pip->ip_hl << 2)); 81 if ( pip->ip_dst.s_addr == htonl(ntohl(special_addr.s_addr) | CTL_DNS) 82 && htons(udp->uh_dport) == 53) 83 { 84 return pData->dns_alias; 85 } 86 /* here we can add catch for dhcp and tftp servers */ 77 #else 78 struct m_tag *t; 79 if (t = m_tag_find(m, PACKET_TAG_ALIAS, NULL) != 0) 80 { 81 return (struct libalias *)&t[1]; 87 82 } 88 83 #endif 84 89 85 return la; 90 86 } … … 99 95 register struct ip *ip; 100 96 int hlen = 0; 97 int mlen = 0; 98 101 99 STAM_PROFILE_START(&pData->StatIP_input, a); 102 100 … … 116 114 } 117 115 118 if (m->m_len < sizeof(struct ip)) 116 mlen = m->m_len; 117 118 if (mlen < sizeof(struct ip)) 119 119 { 120 120 ipstat.ips_toosmall++; … … 168 168 * Drop packet if shorter than we expect. 169 169 */ 170 if (m ->m_len < ip->ip_len)170 if (mlen < ip->ip_len) 171 171 { 172 172 ipstat.ips_tooshort++; … … 175 175 176 176 /* Should drop packet if mbuf too long? hmmm... */ 177 if (m ->m_len > ip->ip_len)177 if (mlen > ip->ip_len) 178 178 m_adj(m, ip->ip_len - m->m_len); 179 179 … … 371 371 } 372 372 373 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 373 374 #define GETIP(m) ((struct ip*)(MBUF_IP_HEADER(m))) 375 #else 376 #define GETIP(m) ((struct ip*)((m)->m_pkthdr.header)) 377 #endif 374 378 375 379 -
trunk/src/VBox/Devices/Network/slirp/ip_output.c
r23007 r23154 46 46 #include "alias.h" 47 47 48 static const uint8_t broadcast_ethaddr[6] = 49 { 50 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 51 }; 52 48 53 static int rt_lookup_in_cache(PNATState pData, uint32_t dst, uint8_t *ether) 49 54 { 50 55 int rc = 1; 56 if (dst == INADDR_BROADCAST) 57 { 58 memcpy(ether, broadcast_ethaddr, ETH_ALEN); 59 return 0; 60 } 51 61 rc = slirp_arp_lookup_ether_by_ip(pData, dst, ether); 52 62 if (rc == 0) … … 104 114 } 105 115 #endif 106 #ifdef VBOX_WITH_SLIRP_BSD_MBUF107 M_ASSERTPKTHDR(m);108 Assert(m->m_pkthdr.header);109 ip = (struct ip *)m->m_pkthdr.header;110 #else111 116 ip = mtod(m, struct ip *); 112 #endif113 117 /* 114 118 * Fill in IP header. … … 149 153 #else 150 154 /* 151 * (vvl) Note: Here we should care about dhcp and other services152 * aware of ethernet address155 * (vvl) Assumption is that m_data points at the IP header and only 156 * in case of dhcp we know and have header before IP. 153 157 */ 154 158 rc = rt_lookup_in_cache(pData, ip->ip_dst.s_addr, eth_dst); 155 159 if (rc != 0) 156 160 goto bad; 161 eh = (struct ethhdr *)(m->m_data - ETH_HLEN); 157 162 #endif 158 163 /* … … 191 196 STAM_PROFILE_STOP(&pData->StatALIAS_output, a); 192 197 } 193 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 194 /*todo: make prepend */ 195 m = m_prepend(pData, m, ETH_HLEN, M_DONTWAIT); 196 Assert(m); 197 eh = mtod(m, struct ethhdr *); 198 #endif 198 199 199 memcpy(eh->h_source, eth_dst, ETH_ALEN); 200 200 … … 225 225 struct mbuf **mnext = &m->m_nextpkt; 226 226 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 227 uint8_t buf[len]; /* intermediate buffer we'll use for copy from orriginal packet*/227 uint8_t *buf; /* intermediate buffer we'll use for copy from orriginal packet*/ 228 228 #endif 229 229 { 230 230 int rc; 231 HTONS(ip->ip_len); 232 HTONS(ip->ip_off); 233 ip->ip_sum = 0; 234 ip->ip_sum = cksum(m, hlen); 231 235 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 232 236 rc = LibAliasOut((m->m_la ? m->m_la : pData->proxy_alias), … … 234 238 #else 235 239 struct m_tag *t; 240 char *tmpbuf = NULL; 241 int tmplen = 0; 242 if (m->m_next != NULL) 243 { 244 /*we've receives packet in fragments*/ 245 tmplen = m_length(m, NULL); 246 tmpbuf = RTMemAlloc(tmplen); 247 Assert(tmpbuf); 248 m_copydata(m, 0, tmplen, tmpbuf); 249 } 250 else 251 { 252 tmpbuf = mtod(m, char *); 253 tmplen = m_length(m, NULL); 254 255 } 236 256 if (t = m_tag_find(m, PACKET_TAG_ALIAS, NULL) != 0) 237 257 { 238 rc = LibAliasOut((struct libalias *)&t[1], mtod(m, char *), m_length(m, NULL));258 rc = LibAliasOut((struct libalias *)&t[1], tmpbuf, tmplen); 239 259 } 240 260 else 241 261 { 242 rc = LibAliasOut(pData->proxy_alias, mtod(m, char *), 243 m_length(m, NULL)); 262 rc = LibAliasOut(pData->proxy_alias, tmpbuf, tmplen); 244 263 } 264 if (m->m_next != NULL) 265 { 266 if (rc != PKT_ALIAS_IGNORED) 267 { 268 struct ip *tmpip = (struct ip *)tmpbuf; 269 m_copyback(pData, m, 0, ntohs(tmpip->ip_len) + (tmpip->ip_hl << 2), tmpbuf); 270 } 271 if (tmpbuf != NULL) 272 RTMemFree(tmpbuf); 273 } 245 274 if (rc == PKT_ALIAS_IGNORED) 246 275 { … … 249 278 } 250 279 #endif 280 NTOHS(ip->ip_len); 281 NTOHS(ip->ip_off); 251 282 Log2(("NAT: LibAlias return %d\n", rc)); 252 283 } … … 264 295 m = m_get(pData); 265 296 #else 266 m = m_get hdr(pData, M_DONTWAIT, MT_HEADER);297 m = m_getcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR); 267 298 #endif 268 299 if (m == 0) … … 272 303 goto sendorfree; 273 304 } 274 #ifndef VBOX_WITH_SLIRP_BSD_MBUF275 305 m->m_data += if_maxlinkhdr; 276 306 mhip = mtod(m, struct ip *); 277 307 *mhip = *ip; 278 #else 279 m_copyback(pData, m, 0, mhlen, ip); 308 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 280 309 m->m_pkthdr.header = mtod(m, void *); 281 mhip = mtod(m, struct ip *);282 m_adj(m, mhlen);283 310 #endif 284 311 /* we've calculated eth_dst for first packet */ … … 289 316 mhip->ip_hl = mhlen >> 2; 290 317 } 291 #endif292 #ifndef VBOX_WITH_SLIRP_BSD_MBUF293 m->m_len = mhlen;294 318 #endif 295 319 mhip->ip_off = ((off - hlen) >> 3) + (ip->ip_off & ~IP_MF); … … 309 333 } 310 334 #else 335 buf = RTMemAlloc(len); 311 336 m_copydata(m0, off, len, buf); /* copy to buffer */ 312 m_append(pData, m, len, buf); /* copy from buffer */ 337 m->m_data += mhlen; 338 m_copyback(pData, m, 0, len, buf); /* copy from buffer */ 339 m->m_data -= mhlen; 340 m->m_len += mhlen; 341 RTMemFree(buf); 342 m->m_len = ntohs(mhip->ip_len); 313 343 #endif 314 344 … … 341 371 eh = (struct ethhdr *)MBUF_HEAD(m); 342 372 #else 343 m = m_prepend(pData, m, ETH_HLEN, M_DONTWAIT); 344 Assert(m); 373 m->m_data -= ETH_HLEN; 345 374 eh = mtod(m, struct ethhdr *); 375 m->m_data += ETH_HLEN; 346 376 #endif 347 377 memcpy(eh->h_source, eth_dst, ETH_ALEN); -
trunk/src/VBox/Devices/Network/slirp/libalias/alias.c
r20958 r23154 1666 1666 #endif 1667 1667 1668 #if def _KERNEL1668 #if defined(_KERNEL) || (defined(VBOX) && defined(VBOX_WITH_SLIRP_BSD_MBUF)) 1669 1669 /* 1670 1670 * m_megapullup() - this function is a big hack. … … 1680 1680 */ 1681 1681 struct mbuf * 1682 m_megapullup(struct mbuf *m, int len) { 1682 #ifndef VBOX 1683 m_megapullup(struct mbuf *m, int len) 1684 #else 1685 m_megapullup(PNATState pData, struct mbuf *m, int len) 1686 #endif 1687 { 1683 1688 struct mbuf *mcl; 1684 1689 … … 1694 1699 1695 1700 if (len <= MCLBYTES - RESERVE) { 1701 #ifndef VBOX 1696 1702 mcl = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); 1703 #else 1704 mcl = m_getcl(pData, M_DONTWAIT, MT_DATA, M_PKTHDR); 1705 #endif 1697 1706 } else if (len < MJUM16BYTES) { 1698 1707 int size; … … 1704 1713 size = MJUM16BYTES; 1705 1714 }; 1715 #ifndef VBOX 1706 1716 mcl = m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, size); 1717 #else 1718 mcl = m_getjcl(pData, M_DONTWAIT, MT_DATA, M_PKTHDR, size); 1719 #endif 1707 1720 } else { 1708 1721 goto bad; … … 1714 1727 m_copydata(m, 0, len, mtod(mcl, caddr_t)); 1715 1728 mcl->m_len = mcl->m_pkthdr.len = len; 1729 #ifndef VBOX 1716 1730 m_freem(m); 1731 #else 1732 m_freem(pData, m); 1733 #endif 1717 1734 1718 1735 return (mcl); 1719 1736 bad: 1737 #ifndef VBOX 1720 1738 m_freem(m); 1739 #else 1740 m_freem(pData, m); 1741 #endif 1721 1742 return (NULL); 1722 1743 } -
trunk/src/VBox/Devices/Network/slirp/libalias/alias.h
r20958 r23154 205 205 206 206 /* Mbuf helper function. */ 207 #ifndef VBOX 207 208 struct mbuf *m_megapullup(struct mbuf *, int); 209 #else 210 struct mbuf *m_megapullup(PNATState, struct mbuf *, int); 211 #endif 208 212 209 213 /* -
trunk/src/VBox/Devices/Network/slirp/libalias/alias_db.c
r21718 r23154 175 175 #else /* !VBOX */ 176 176 # include <iprt/assert.h> 177 # include <slirp.h>178 177 # include "alias.h" 179 178 # include "alias_local.h" 180 179 # include "alias_mod.h" 180 # include <slirp.h> 181 181 #endif /* VBOX */ 182 182 -
trunk/src/VBox/Devices/Network/slirp/libalias/alias_dns.c
r22881 r23154 83 83 uint16_t addr_off = (uint16_t)~0; 84 84 85 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 85 86 m = dtom(la->pData, hdr); 87 #else 88 AssertMsgFailed(("Unimplemented")); 89 #endif 86 90 Assert((m)); 87 91 -
trunk/src/VBox/Devices/Network/slirp/mbuf.h
r22013 r23154 37 37 #ifndef _MBUF_H_ 38 38 #define _MBUF_H_ 39 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 39 40 40 41 #define m_freem m_free … … 150 151 #define MBUF_IP_HEADER(m) (caddr_t)(MBUF_HEAD(m) + if_maxlinkhdr) 151 152 153 #else 154 # include "bsd/sys/mbuf.h" 152 155 #endif 156 #endif -
trunk/src/VBox/Devices/Network/slirp/misc.c
r22942 r23154 238 238 zone->pfAlloc = slirp_uma_alloc; 239 239 zone->pfFree = slirp_uma_free; 240 zone->size = master->size; 240 241 return zone; 241 242 } -
trunk/src/VBox/Devices/Network/slirp/sbuf.c
r22576 r23154 77 77 { 78 78 int ret = 0; 79 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 80 int mlen = 0; 81 uint8_t *buf = NULL; 82 #endif 79 83 80 84 STAM_PROFILE_START(&pData->StatIOSBAppend_pf, a); … … 86 90 STAM_COUNTER_INC(&pData->StatIOSBAppend); 87 91 /* Shouldn't happen, but... e.g. foreign host closes connection */ 92 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 88 93 if (m->m_len <= 0) 94 #else 95 mlen = m_length(m, NULL); 96 if (mlen <= 0) 97 #endif 89 98 { 90 99 STAM_COUNTER_INC(&pData->StatIOSBAppend_zm); … … 109 118 * ottherwise it'll arrive out of order, and hence corrupt 110 119 */ 111 if (!so->so_rcv.sb_cc) 120 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 121 if(!so->so_rcv.sb_cc) 112 122 ret = send(so->s, m->m_data, m->m_len, 0); 123 #else 124 buf = RTMemAlloc(mlen); 125 if (buf == NULL) 126 { 127 ret = 0; 128 goto no_sent; 129 } 130 m_copydata(m, 0, mlen, buf); 131 if(!so->so_rcv.sb_cc) 132 ret = send(so->s, buf, mlen, 0); 133 RTMemFree(buf); 134 no_sent: 135 #endif 113 136 114 137 if (ret <= 0) … … 125 148 goto done; 126 149 } 150 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 127 151 else if (ret != m->m_len) 152 #else 153 else if (ret != mlen) 154 #endif 128 155 { 129 156 STAM_COUNTER_INC(&pData->StatIOSBAppend_wp); … … 132 159 * sbappendsb the rest 133 160 */ 161 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 134 162 m->m_len -= ret; 135 163 m->m_data += ret; 164 #else 165 m_adj(m, ret); 166 #endif 136 167 sbappendsb(pData, &so->so_rcv, m); 137 168 STAM_PROFILE_STOP(&pData->StatIOSBAppend_pf_wp, a); … … 154 185 int len, n, nn; 155 186 187 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 156 188 len = m->m_len; 189 #else 190 len = m_length(m, NULL); 191 #endif 157 192 158 193 STAM_COUNTER_INC(&pData->StatIOSBAppendSB); … … 163 198 if (n > len) 164 199 n = len; 200 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 165 201 memcpy(sb->sb_wptr, m->m_data, n); 202 #else 203 m_copydata(m, 0, n, sb->sb_wptr); 204 #endif 166 205 } 167 206 else … … 172 211 if (n > len) 173 212 n = len; 213 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 174 214 memcpy(sb->sb_wptr, m->m_data, n); 215 #else 216 m_copydata(m, 0, n, sb->sb_wptr); 217 #endif 175 218 len -= n; 176 219 if (len) … … 180 223 if (nn > len) 181 224 nn = len; 225 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 182 226 memcpy(sb->sb_data, m->m_data+n, nn); 227 #else 228 m_copydata(m, n, nn, sb->sb_wptr); 229 #endif 183 230 n += nn; 184 231 } -
trunk/src/VBox/Devices/Network/slirp/sbuf.h
r20377 r23154 29 29 void sbappendsb (PNATState, struct sbuf *, struct mbuf *); 30 30 void sbcopy (struct sbuf *, int, int, char *); 31 32 31 #endif -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r22941 r23154 576 576 fNATfailed = 1; 577 577 578 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 578 579 dnsproxy_init(pData); 580 #endif 579 581 580 582 getouraddr(pData); … … 1380 1382 rah = mtod(mr, struct arphdr *); 1381 1383 #else 1382 mr = m_gethdr(pData, M_NOWAIT, MT_HEADER); 1384 mr = m_getcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR); 1385 reh = mtod(mr, struct ethhdr *); 1386 mr->m_data += ETH_HLEN; 1383 1387 rah = mtod(mr, struct arphdr *); 1388 mr->m_len = sizeof(struct arphdr); 1384 1389 Assert(mr); 1385 mr->m_pkthdr.len = mr->m_len = sizeof(* rah);1386 mr = m_prepend(pData, mr, ETH_HLEN, M_DONTWAIT);1387 reh = mtod(mr, struct ethhdr *);1388 1390 memcpy(reh->h_source, eh->h_source, ETH_ALEN); /* XXX: if_encap will swap src and dst*/ 1389 1391 #endif … … 1472 1474 static bool fWarnedIpv6; 1473 1475 struct ethhdr *eh = (struct ethhdr*)pkt; 1476 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 1477 int size = 0; 1478 #endif 1474 1479 1475 1480 Log2(("NAT: slirp_input %d\n", pkt_len)); … … 1492 1497 m = m_get(pData); 1493 1498 #else 1494 m = m_gethdr(pData, M_NOWAIT, MT_HEADER); 1499 if (pkt_len < MSIZE) 1500 { 1501 size = MCLBYTES; 1502 } 1503 else if (pkt_len < MCLBYTES) 1504 { 1505 size = MCLBYTES; 1506 } 1507 else if(pkt_len < MJUM9BYTES) 1508 { 1509 size = MJUM9BYTES; 1510 } 1511 else if (pkt_len < MJUM16BYTES) 1512 { 1513 size = MJUM16BYTES; 1514 } 1515 else 1516 { 1517 AssertMsgFailed(("Unsupported size")); 1518 } 1519 m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size); 1495 1520 #endif 1496 1521 if (!m) … … 1506 1531 if (M_FREEROOM(m) < pkt_len) 1507 1532 m_inc(m, pkt_len); 1533 #endif 1508 1534 1509 1535 m->m_len = pkt_len ; 1510 1536 memcpy(m->m_data, pkt, pkt_len); 1511 #else 1512 if (m_append(pData, m, pkt_len, pkt) != 1) 1513 { 1514 AssertMsgFailed(("Can't append incommin to mbuf")); 1515 RTMemFree(pkt); 1516 m_free(pData, m); 1517 } 1518 #endif 1519 1520 #if 1 1537 1521 1538 if (pData->port_forwarding_activated == 0) 1522 1539 activate_port_forwarding(pData, mtod(m, struct ethhdr *)); 1523 #endif1524 1540 1525 1541 proto = ntohs(*(uint16_t *)(pkt + 12)); … … 1576 1592 #else 1577 1593 M_ASSERTPKTHDR(m); 1594 m->m_data -= ETH_HLEN; 1595 m->m_len += ETH_HLEN; 1578 1596 eh = mtod(m, struct ethhdr *); 1579 1597 #endif … … 1593 1611 mlen = m->m_len; 1594 1612 #else 1595 mlen = m_length( pData, m);1613 mlen = m_length(m, NULL); 1596 1614 #endif 1597 1615 buf = RTMemAlloc(mlen); … … 1970 1988 struct arphdr *ahdr; 1971 1989 1990 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 1972 1991 m = m_get(pData); 1992 #else 1993 m = m_getcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR); 1994 #endif 1973 1995 if (m == NULL) 1974 1996 { … … 1988 2010 memset(ahdr->ar_tha, 0xff, ETH_ALEN); /*broadcast*/ 1989 2011 *(uint32_t *)ahdr->ar_tip = dst; 2012 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 1990 2013 m->m_data += if_maxlinkhdr; 1991 2014 m->m_len = sizeof(struct arphdr); 2015 #else 2016 /* warn!!! should falls in mbuf minimal size */ 2017 m->m_len = sizeof(struct arphdr) + ETH_HLEN; 2018 #endif 1992 2019 if_encap(pData, ETH_P_ARP, m); 1993 2020 LogRel(("NAT: ARP request sent\n")); -
trunk/src/VBox/Devices/Network/slirp/slirp.h
r23135 r23154 355 355 int sscanf(const char *s, const char *format, ...); 356 356 357 #if defined(VBOX_SLIRP_ALIAS) 357 #if defined(VBOX_SLIRP_ALIAS) || defined(VBOX_SLIRP_BSD) 358 358 359 359 # define ip_next(ip) (void *)((uint8_t *)(ip) + ((ip)->ip_hl << 2)) … … 385 385 # define stderr NULL 386 386 # define stdout NULL 387 387 388 # ifdef DEBUG 388 389 # define LIBALIAS_DEBUG 389 390 # endif 390 # ifdef fprintf 391 # undef fprintf 392 # endif 393 # ifdef fflush 394 # undef fflush 395 # endif 396 # ifdef printf 397 # undef printf 398 # endif 391 399 392 # define fflush(x) do{} while(0) 400 # define fprintf vbox_slirp_fprintf401 # define printf vbox_slirp_printf402 393 # include "ext.h" 403 394 #endif /*VBOX_SLIRP_ALIAS*/ -
trunk/src/VBox/Devices/Network/slirp/slirp_state.h
r23135 r23154 100 100 typedef struct NATState 101 101 { 102 #define PROFILE_COUNTER(name, dsc) STAMPROFILE Stat ## name 103 #define COUNTING_COUNTER(name, dsc) STAMCOUNTER Stat ## name 104 #include "counters.h" 102 105 /* Stuff from boot.c */ 103 106 void *pbootp_clients; … … 301 304 struct proto_handler *nbt_module; 302 305 struct proto_handler *dns_module; 303 304 #define PROFILE_COUNTER(name, dsc) STAMPROFILE Stat ## name305 #define COUNTING_COUNTER(name, dsc) STAMCOUNTER Stat ## name306 307 #include "counters.h"308 306 309 307 } NATState; -
trunk/src/VBox/Devices/Network/slirp/socket.c
r23004 r23154 566 566 u_long n = 0; 567 567 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 568 uint8_t *buffer;568 int size; 569 569 #endif 570 570 … … 610 610 m->m_len, errno, strerror(errno))); 611 611 #else 612 if (!(m = m_gethdr(pData, M_NOWAIT, MT_HEADER)))613 {614 SOCKET_UNLOCK(so);615 return;616 }617 612 /*How many data has been received ?*/ 618 613 /* … … 621 616 * 3. attach buffer to allocated header mbuf 622 617 */ 623 ioctlsocket(so->s, FIONREAD, &n); 624 Assert(n > 0); 625 buffer = RTMemAlloc(n); 626 Assert(buffer); 627 len = recvfrom(so->s, buffer, n, 0, 618 static int signaled = 0; 619 int rc = ioctlsocket(so->s, FIONREAD, &n); 620 621 if (rc == -1 && signaled == 0) 622 { 623 LogRel(("NAT: can't fetch amount of bytes on socket %R[natsock], so message will be truncated.\n", so)); 624 signaled = 1; 625 } 626 627 len = sizeof(struct udpiphdr) + ETH_HLEN; 628 len += n; 629 630 if (len < MSIZE) 631 { 632 size = MCLBYTES; 633 } 634 else if (len < MCLBYTES) 635 { 636 size = MCLBYTES; 637 } 638 else if(len < MJUM9BYTES) 639 { 640 size = MJUM9BYTES; 641 } 642 else if (len < MJUM16BYTES) 643 { 644 size = MJUM16BYTES; 645 } 646 else 647 { 648 AssertMsgFailed(("Unsupported size")); 649 } 650 m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size); 651 m->m_data += ETH_HLEN; 652 m->m_pkthdr.header = mtod(m, void *); 653 m->m_data += sizeof(struct udpiphdr); 654 len = recvfrom(so->s, mtod(m, char *), n, 0, 628 655 (struct sockaddr *)&addr, &addrlen); 656 m->m_len = len; 629 657 /* @todo (r=vvl) check which flags and type should be passed */ 630 if (len > 0)631 m_append(pData, m, len, buffer);632 RTMemFree(buffer);633 658 #endif 634 659 if(len < 0) … … 663 688 * Note: Here we can't check if dnsproxy's sent initial request 664 689 */ 690 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 665 691 if (so->so_fport == htons(53)) 666 692 dnsproxy_answer(pData, so, m); 693 #endif 667 694 668 695 #if 0 … … 1056 1083 /* saves original ip header and options */ 1057 1084 memcpy(m->m_data + original_hlen, buff + hlen, len - hlen); 1085 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 1058 1086 m->m_len = len - hlen + original_hlen; 1059 1087 ip->ip_len = m->m_len; 1088 #else 1089 ip->ip_len = m_length(m, NULL); 1090 #endif 1060 1091 ip->ip_p = IPPROTO_ICMP; /* the original package could be whatever, but we're response via ICMP*/ 1061 1092 -
trunk/src/VBox/Devices/Network/slirp/tcp.h
r15054 r23154 116 116 * We make this 1460 because we only care about Ethernet in the qemu context. 117 117 */ 118 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 118 119 #define TCP_MSS 1460 120 #else 121 #define TCP_MSS (if_mtu - 80) 122 #endif 119 123 120 124 #define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ -
trunk/src/VBox/Devices/Network/slirp/tcp_output.c
r22896 r23154 81 81 unsigned optlen, hdrlen; 82 82 int idle, sendalot; 83 int size; 83 84 84 85 DEBUG_CALL("tcp_output"); … … 374 375 m = m_get(pData); 375 376 #else 376 m = m_gethdr(pData, M_NOWAIT, MT_HEADER); 377 /* @todo (r=vvl) should we append other bufs here ???*/ 377 if ((len + hdrlen + ETH_HLEN) < MSIZE) 378 { 379 size = MCLBYTES; 380 } 381 else if ((len + hdrlen + ETH_HLEN) < MCLBYTES) 382 { 383 size = MCLBYTES; 384 } 385 else if((len + hdrlen + ETH_HLEN) < MJUM9BYTES) 386 { 387 size = MJUM9BYTES; 388 } 389 else if ((len + hdrlen + ETH_HLEN) < MJUM16BYTES) 390 { 391 size = MJUM16BYTES; 392 } 393 else 394 { 395 AssertMsgFailed(("Unsupported size")); 396 } 397 m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size); 378 398 #endif 379 399 if (m == NULL) … … 383 403 goto out; 384 404 } 385 #ifndef VBOX_WITH_SLIRP_BSD_MBUF386 405 m->m_data += if_maxlinkhdr; 406 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 407 m->m_pkthdr.header = mtod(m, void *); 408 #endif 387 409 m->m_len = hdrlen; 388 #endif389 410 390 411 /* … … 396 417 { 397 418 #endif 398 #ifndef VBOX_WITH_SLIRP_BSD_MBUF399 419 sbcopy(&so->so_snd, off, (int) len, mtod(m, caddr_t) + hdrlen); 400 420 m->m_len += len; 401 #else402 sbcopy(pData, &so->so_snd, off, (int) len, m);403 m = m_prepend(pData, m, sizeof (struct tcpiphdr), M_DONTWAIT);404 #endif405 421 #if 0 406 422 } … … 440 456 goto out; 441 457 } 442 m->m_data += if_maxlinkhdr;443 m->m_len = hdrlen;444 458 #else 445 m = m_gethdr(pData, M_NOWAIT, MT_HEADER); 459 if ((hdrlen + ETH_HLEN) < MSIZE) 460 { 461 size = MCLBYTES; 462 } 463 else if ((hdrlen + ETH_HLEN) < MCLBYTES) 464 { 465 size = MCLBYTES; 466 } 467 else if((hdrlen + ETH_HLEN) < MJUM9BYTES) 468 { 469 size = MJUM9BYTES; 470 } 471 else if ((hdrlen + ETH_HLEN) < MJUM16BYTES) 472 { 473 size = MJUM16BYTES; 474 } 475 else 476 { 477 AssertMsgFailed(("Unsupported size")); 478 } 479 m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size); 480 #endif 446 481 if (m == NULL) 447 482 { … … 450 485 goto out; 451 486 } 452 #endif 453 } 454 455 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 487 m->m_data += if_maxlinkhdr; 488 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 489 m->m_pkthdr.header = mtod(m, void *); 490 #endif 491 m->m_len = hdrlen; 492 } 493 456 494 ti = mtod(m, struct tcpiphdr *); 457 495 458 496 memcpy((caddr_t)ti, &tp->t_template, sizeof (struct tcpiphdr)); 459 #else460 /*already copied header from template */461 462 m_copyback(pData, m, 0, sizeof (struct tcpiphdr), &tp->t_template);463 ti = mtod(m, struct tcpiphdr *);464 #endif465 497 466 498 /* … … 493 525 if (optlen) 494 526 { 495 #ifndef VBOX_WITH_SLIRP_BSD_MBUF496 527 memcpy((caddr_t)(ti + 1), (caddr_t)opt, optlen); 497 #else498 m_append(pData, m, optlen, opt);499 #endif500 528 ti->ti_off = (sizeof (struct tcphdr) + optlen) >> 2; 501 529 } … … 610 638 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 611 639 Assert(m->m_len == (hdrlen + len)); 612 m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */613 640 #else 614 641 M_ASSERTPKTHDR(m); 615 642 m->m_pkthdr.header = mtod(m, void *); 616 643 #endif 617 618 { 619 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 644 m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */ 645 646 { 620 647 ((struct ip *)ti)->ip_len = m->m_len; 621 #else622 ((struct ip *)ti)->ip_len = m_length(m, NULL);623 #endif624 648 ((struct ip *)ti)->ip_ttl = ip_defttl; 625 649 ((struct ip *)ti)->ip_tos = so->so_iptos; -
trunk/src/VBox/Devices/Network/slirp/tcp_subr.c
r22664 r23154 122 122 if (m == 0) 123 123 { 124 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 124 125 if ((m = m_get(pData)) == NULL) 126 #else 127 if ((m = m_gethdr(pData, M_DONTWAIT, MT_HEADER)) == NULL) 128 #endif 125 129 return; 126 130 #ifdef TCP_COMPAT_42 -
trunk/src/VBox/Devices/Network/slirp/udp.c
r22976 r23154 180 180 * handle TFTP 181 181 */ 182 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 182 183 if ( ntohs(uh->uh_dport) == TFTP_SERVER 183 184 && CTL_CHECK(ntohl(ip->ip_dst.s_addr), CTL_TFTP)) … … 186 187 goto done; 187 188 } 189 #endif 188 190 189 191 /* … … 292 294 } 293 295 294 m_free(pData, so->so_m); /* used for ICMP if error on sorecvfrom */ 296 if (so->so_m) 297 m_free(pData, so->so_m); /* used for ICMP if error on sorecvfrom */ 295 298 296 299 /* restore the orig mbuf packet */ … … 340 343 memset(ui->ui_x1, 0, 9); 341 344 ui->ui_pr = IPPROTO_UDP; 342 ui->ui_len = htons(m->m_len - sizeof(struct ip)); /* + sizeof (struct udphdr)); */345 ui->ui_len = htons(m->m_len - sizeof(struct ip)); 343 346 /* XXXXX Check for from-one-location sockets, or from-any-location sockets */ 344 347 ui->ui_src = saddr->sin_addr;
Note:
See TracChangeset
for help on using the changeset viewer.