Changeset 1033 in vbox
- Timestamp:
- Feb 23, 2007 2:22:00 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 18906
- Location:
- trunk/src/VBox/Devices/Network
- Files:
-
- 35 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DrvNAT.cpp
r792 r1033 59 59 /** Link state */ 60 60 PDMNETWORKLINKSTATE enmLinkState; 61 /** NAT state for this instance. */ 62 PNATState pNATState; 61 63 } DRVNAT, *PDRVNAT; 62 64 63 65 /** Converts a pointer to NAT::INetworkConnector to a PRDVNAT. */ 64 66 #define PDMINETWORKCONNECTOR_2_DRVNAT(pInterface) ( (PDRVNAT)((uintptr_t)pInterface - RT_OFFSETOF(DRVNAT, INetworkConnector)) ) 65 66 67 67 68 /******************************************************************************* 68 69 * Global Variables * 69 70 *******************************************************************************/ 70 /** @todo change this into a MAC -> PDRVNAT translation list. */71 /** Pointer to the driver instance.72 * This is required by slirp. */73 static PDRVNAT g_pDrv = NULL;74 71 #if 0 75 72 /** If set the thread should terminate. */ … … 103 100 Assert(pData->enmLinkState == PDMNETWORKLINKSTATE_UP); 104 101 if (pData->enmLinkState == PDMNETWORKLINKSTATE_UP) 105 slirp_input( (uint8_t *)pvBuf, cb);102 slirp_input(pData->pNATState, (uint8_t *)pvBuf, cb); 106 103 RTCritSectLeave(&pData->CritSect); 107 104 LogFlow(("drvNATSend: end\n")); … … 148 145 case PDMNETWORKLINKSTATE_UP: 149 146 LogRel(("NAT: link up\n")); 150 slirp_link_up( );147 slirp_link_up(pData->pNATState); 151 148 break; 152 149 … … 154 151 case PDMNETWORKLINKSTATE_DOWN_RESUME: 155 152 LogRel(("NAT: link down\n")); 156 slirp_link_down( );153 slirp_link_down(pData->pNATState); 157 154 break; 158 155 … … 196 193 AssertReleaseRC(rc); 197 194 198 slirp_select_fill( &cFDs, &ReadFDs, &WriteFDs, &XcptFDs);195 slirp_select_fill(pData->pNATState, &cFDs, &ReadFDs, &WriteFDs, &XcptFDs); 199 196 200 197 struct timeval tv = {0, 0}; /* no wait */ 201 198 int cReadFDs = select(cFDs + 1, &ReadFDs, &WriteFDs, &XcptFDs, &tv); 202 199 if (cReadFDs >= 0) 203 slirp_select_poll( &ReadFDs, &WriteFDs, &XcptFDs);200 slirp_select_poll(pData->pNATState, &ReadFDs, &WriteFDs, &XcptFDs); 204 201 205 202 RTCritSectLeave(&pData->CritSect); … … 212 209 * @returns 0 if not possible. 213 210 */ 214 int slirp_can_output(void) 215 { 211 int slirp_can_output(void *pvUser) 212 { 213 PDRVNAT pData = (PDRVNAT)pvUser; 214 215 Assert(pData); 216 216 217 /** Happens during termination */ 217 if (!RTCritSectIsOwner(& g_pDrv->CritSect))218 if (!RTCritSectIsOwner(&pData->CritSect)) 218 219 return 0; 219 220 220 if (g_pDrv) 221 return g_pDrv->pPort->pfnCanReceive(g_pDrv->pPort); 221 return pData->pPort->pfnCanReceive(pData->pPort); 222 222 223 223 return 0; … … 228 228 * Function called by slirp to feed incoming data to the network port. 229 229 */ 230 void slirp_output(const uint8_t *pu8Buf, int cb) 231 { 230 void slirp_output(void *pvUser, const uint8_t *pu8Buf, int cb) 231 { 232 PDRVNAT pData = (PDRVNAT)pvUser; 233 232 234 LogFlow(("slirp_output BEGING %x %d\n", pu8Buf, cb)); 233 Log2(("slirp_output: pu8Buf=%p cb=%#x ( g_pDrv=%p)\n"235 Log2(("slirp_output: pu8Buf=%p cb=%#x (pData=%p)\n" 234 236 "%.*Vhxd\n", 235 pu8Buf, cb, g_pDrv,237 pu8Buf, cb, pData, 236 238 cb, pu8Buf)); 237 if (g_pDrv) 238 {239 /** Happens during termination */ 240 if (!RTCritSectIsOwner(&g_pDrv->CritSect))241 return;242 243 int rc = g_pDrv->pPort->pfnReceive(g_pDrv->pPort, pu8Buf, cb); 244 AssertRC(rc);245 }239 240 Assert(pData); 241 242 /** Happens during termination */ 243 if (!RTCritSectIsOwner(&pData->CritSect)) 244 return; 245 246 int rc = pData->pPort->pfnReceive(pData->pPort, pu8Buf, cb); 247 AssertRC(rc); 246 248 LogFlow(("slirp_output END %x %d\n", pu8Buf, cb)); 247 249 } … … 289 291 LogRel(("NAT: g_cpvHashUsed=%RU32 g_cpvHashCollisions=%RU32 g_cpvHashInserts=%RU64 g_cpvHashDone=%RU64\n", 290 292 g_cpvHashUsed, g_cpvHashCollisions, g_cpvHashInserts, g_cpvHashDone)); 291 #endif 293 #endif 292 294 int rc = RTCritSectEnter(&pData->CritSect); 293 295 AssertReleaseRC(rc); 294 slirp_term( );295 g_pDrv= NULL;296 slirp_term(pData->pNATState); 297 pData->pNATState = NULL; 296 298 RTCritSectLeave(&pData->CritSect); 297 299 … … 306 308 * @param pCfgHandle The drivers configuration handle. 307 309 */ 308 static int drvNATConstructRedir(P CFGMNODE pCfgHandle)310 static int drvNATConstructRedir(PDRVNAT pData, PCFGMNODE pCfgHandle) 309 311 { 310 312 /* … … 363 365 */ 364 366 Log(("drvNATConstruct: Redir %d -> %s:%d\n", iHostPort, szGuestIP, iGuestPort)); 365 if (slirp_redir( fUDP, iHostPort, GuestIP, iGuestPort) < 0)367 if (slirp_redir(pData->pNATState, fUDP, iHostPort, GuestIP, iGuestPort) < 0) 366 368 { 367 369 AssertMsgFailed(("Configuration error: failed to setup redirection of %d to %s:%d. Probably a conflict with existing services or other rules.\n", … … 388 390 { 389 391 PDRVNAT pData = PDMINS2DATA(pDrvIns, PDRVNAT); 392 char szNetAddr[16]; 390 393 LogFlow(("drvNATConstruct:\n")); 391 394 … … 407 410 pData->INetworkConnector.pfnNotifyLinkChanged = drvNATNotifyLinkChanged; 408 411 pData->INetworkConnector.pfnNotifyCanReceive = drvNATNotifyCanReceive; 412 413 pData->pNATState = NULL; 409 414 410 415 /* … … 415 420 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE, 416 421 N_("Configuration error: the above device/driver didn't export the network port interface!\n")); 422 423 /* Generate a network address for this network card. */ 424 RTStrPrintf(szNetAddr, sizeof(szNetAddr), "10.0.%d.0", pDrvIns->iInstance + 2); 417 425 418 426 /* … … 437 445 * Initialize slirp. 438 446 */ 439 rc = slirp_init( );447 rc = slirp_init(&pData->pNATState, &szNetAddr[0], pData); 440 448 if (VBOX_SUCCESS(rc)) 441 449 { 442 rc = drvNATConstructRedir(p CfgHandle);450 rc = drvNATConstructRedir(pData, pCfgHandle); 443 451 if (VBOX_SUCCESS(rc)) 444 452 { 445 453 pDrvIns->pDrvHlp->pfnPDMPollerRegister(pDrvIns, drvNATPoller); 446 g_pDrv = pData;447 454 448 455 pData->enmLinkState = PDMNETWORKLINKSTATE_UP; … … 454 461 } 455 462 /* failure path */ 456 slirp_term(); 463 slirp_term(pData->pNATState); 464 pData->pNATState = NULL; 457 465 } 458 466 else … … 500 508 PDM_DRVREG_CLASS_NETWORK, 501 509 /* cMaxInstances */ 502 1 ,510 16, 503 511 /* cbInstance */ 504 512 sizeof(DRVNAT), -
trunk/src/VBox/Devices/Network/slirp/bootp.c
r1023 r1033 1 1 /* 2 2 * QEMU BOOTP/DHCP server 3 * 3 * 4 4 * Copyright (c) 2004 Fabrice Bellard 5 * 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 7 * of this software and associated documentation files (the "Software"), to deal … … 26 26 /* XXX: only DHCP is supported */ 27 27 28 #ifndef VBOX 28 29 #define NB_ADDR 16 29 30 … … 40 41 41 42 const char *bootp_filename; 43 #endif /* !VBOX */ 42 44 43 45 static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE }; … … 58 60 Log(("dhcp: %N", pszFormat, &args)); 59 61 va_end(args); 60 #endif 61 } 62 #endif /* VBOX */ 63 62 #endif 63 } 64 #endif /* VBOX */ 65 66 #ifdef VBOX 67 static BOOTPClient *get_new_addr(PNATState pData, struct in_addr *paddr) 68 #else /* !VBOX */ 64 69 static BOOTPClient *get_new_addr(struct in_addr *paddr) 70 #endif /* !VBOX */ 65 71 { 66 72 BOOTPClient *bc; … … 80 86 81 87 #ifdef VBOX 82 static void release_addr( struct in_addr *paddr)88 static void release_addr(PNATState pData, struct in_addr *paddr) 83 89 { 84 90 int i; … … 92 98 #endif /* VBOX */ 93 99 100 #ifdef VBOX 101 static BOOTPClient *find_addr(PNATState pData, struct in_addr *paddr, const uint8_t *macaddr) 102 #else /* !VBOX */ 94 103 static BOOTPClient *find_addr(struct in_addr *paddr, const uint8_t *macaddr) 104 #endif /* !VBOX */ 95 105 { 96 106 BOOTPClient *bc; … … 115 125 int len, tag; 116 126 117 *pmsg_type = 0; 127 *pmsg_type = 0; 118 128 119 129 p = buf; … … 127 137 tag = p[0]; 128 138 if (tag == RFC1533_PAD) { 129 p++; 139 p++; 130 140 } else if (tag == RFC1533_END) { 131 141 break; … … 150 160 } 151 161 162 #ifdef VBOX 163 static void bootp_reply(PNATState pData, struct bootp_t *bp) 164 #else /* !VBOX */ 152 165 static void bootp_reply(struct bootp_t *bp) 166 #endif /* !VBOX */ 153 167 { 154 168 BOOTPClient *bc; … … 156 170 struct bootp_t *rbp; 157 171 struct sockaddr_in saddr, daddr; 172 #ifdef VBOX 173 struct in_addr dns_addr_dhcp; 174 #else /* !VBOX */ 158 175 struct in_addr dns_addr; 176 #endif /* !VBOX */ 159 177 int dhcp_msg_type, val; 160 178 uint8_t *q; … … 163 181 dhcp_decode(bp->bp_vend, DHCP_OPT_LEN, &dhcp_msg_type); 164 182 dprintf("bootp packet op=%d msgtype=%d\n", bp->bp_op, dhcp_msg_type); 165 183 166 184 if (dhcp_msg_type == 0) 167 185 dhcp_msg_type = DHCPREQUEST; /* Force reply for old BOOTP clients */ 168 186 169 187 #ifdef VBOX 170 188 if (dhcp_msg_type == DHCPRELEASE) { 171 189 uint32_t addr = ntohl(bp->bp_ciaddr.s_addr); 172 release_addr( &bp->bp_ciaddr);190 release_addr(pData, &bp->bp_ciaddr); 173 191 LogRel(("NAT: DHCP released IP address %u.%u.%u.%u\n", 174 192 addr >> 24, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff)); … … 178 196 } 179 197 #endif /* VBOX */ 180 if (dhcp_msg_type != DHCPDISCOVER && 198 if (dhcp_msg_type != DHCPDISCOVER && 181 199 dhcp_msg_type != DHCPREQUEST) 182 200 return; 183 201 /* XXX: this is a hack to get the client mac address */ 184 202 memcpy(client_ethaddr, bp->bp_hwaddr, 6); 185 203 204 #ifdef VBOX 205 if ((m = m_get(pData)) == NULL) 206 #else /* !VBOX */ 186 207 if ((m = m_get()) == NULL) 208 #endif /* !VBOX */ 187 209 return; 188 210 m->m_data += if_maxlinkhdr; … … 194 216 #ifdef VBOX 195 217 /* Do not allocate a new lease for clients that forgot that they had a lease. */ 196 bc = find_addr( &daddr.sin_addr, bp->bp_hwaddr);218 bc = find_addr(pData, &daddr.sin_addr, bp->bp_hwaddr); 197 219 if (bc) 198 220 goto reuse_lease; 199 221 #endif /* VBOX */ 200 222 new_addr: 223 #ifdef VBOX 224 bc = get_new_addr(pData, &daddr.sin_addr); 225 #else /* !VBOX */ 201 226 bc = get_new_addr(&daddr.sin_addr); 227 #endif /* !VBOX */ 202 228 if (!bc) { 203 229 #ifdef VBOX … … 212 238 #endif /* VBOX */ 213 239 } else { 240 #ifdef VBOX 241 bc = find_addr(pData, &daddr.sin_addr, bp->bp_hwaddr); 242 #else /* !VBOX */ 214 243 bc = find_addr(&daddr.sin_addr, bp->bp_hwaddr); 244 #endif /* !VBOX */ 215 245 if (!bc) { 216 246 /* if never assigned, behaves as if it was already … … 230 260 { 231 261 uint32_t addr = ntohl(daddr.sin_addr.s_addr); 232 LogRel(("NAT: DHCP offered IP address %u.%u.%u.%u\n", 262 LogRel(("NAT: DHCP offered IP address %u.%u.%u.%u\n", 233 263 addr >> 24, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff)); 234 264 } … … 263 293 *q++ = DHCPACK; 264 294 } 265 295 266 296 if (dhcp_msg_type == DHCPDISCOVER || 267 297 dhcp_msg_type == DHCPREQUEST) { … … 277 307 *q++ = 0xff; 278 308 *q++ = 0x00; 279 309 280 310 *q++ = RFC1533_GATEWAY; 281 311 *q++ = 4; 282 312 memcpy(q, &saddr.sin_addr, 4); 283 313 q += 4; 284 314 285 315 *q++ = RFC1533_DNS; 286 316 *q++ = 4; 317 #ifdef VBOX 318 dns_addr_dhcp.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_DNS); 319 memcpy(q, &dns_addr_dhcp, 4); 320 #else /* !VBOX */ 287 321 dns_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_DNS); 288 322 memcpy(q, &dns_addr, 4); 323 #endif /* !VBOX */ 289 324 q += 4; 290 325 … … 304 339 } 305 340 *q++ = RFC1533_END; 306 307 m->m_len = sizeof(struct bootp_t) - 341 342 m->m_len = sizeof(struct bootp_t) - 308 343 sizeof(struct ip) - sizeof(struct udphdr); 309 344 #ifdef VBOX 310 345 /* Reply to the broadcast address, as some clients perform paranoid checks. */ 311 346 daddr.sin_addr.s_addr = INADDR_BROADCAST; 312 #endif /* VBOX */ 347 udp_output2(pData, NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); 348 #else /* !VBOX */ 313 349 udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); 314 } 315 350 #endif /* !VBOX */ 351 } 352 353 #ifdef VBOX 354 void bootp_input(PNATState pData, struct mbuf *m) 355 #else /* !VBOX */ 316 356 void bootp_input(struct mbuf *m) 357 #endif /* !VBOX */ 317 358 { 318 359 struct bootp_t *bp = mtod(m, struct bootp_t *); 319 360 320 361 if (bp->bp_op == BOOTP_REQUEST) { 362 #ifdef VBOX 363 bootp_reply(pData, bp); 364 #else /* !VBOX */ 321 365 bootp_reply(bp); 322 } 323 } 366 #endif /* !VBOX */ 367 } 368 } -
trunk/src/VBox/Devices/Network/slirp/bootp.h
r1 r1033 114 114 }; 115 115 116 #ifdef VBOX 117 void bootp_input(PNATState, struct mbuf *m); 118 #else /* !VBOX */ 116 119 void bootp_input(struct mbuf *m); 120 #endif /* !VBOX */ -
trunk/src/VBox/Devices/Network/slirp/debug.c
r1 r1033 2 2 * Copyright (c) 1995 Danny Gasparovski. 3 3 * Portions copyright (c) 2000 Kelly Price. 4 * 5 * Please read the file COPYRIGHT for the 4 * 5 * Please read the file COPYRIGHT for the 6 6 * terms and conditions of the copyright. 7 7 */ … … 9 9 #include <slirp.h> 10 10 11 #ifndef VBOX 11 12 FILE *dfd = NULL; 12 13 #ifdef DEBUG … … 16 17 #endif 17 18 int slirp_debug = 0; 19 #endif /* !VBOX */ 18 20 19 21 #ifndef VBOX 20 22 extern char *strerror _P((int)); 21 #endif 22 23 /* Carry over one item from main.c so that the tty's restored. 23 #endif 24 25 /* Carry over one item from main.c so that the tty's restored. 24 26 * Only done when the tty being used is /dev/tty --RedWolf */ 25 27 extern struct termios slirp_tty_settings; … … 36 38 if (dfd) 37 39 fclose(dfd); 38 40 39 41 dfd = fopen(file,"w"); 40 42 if (dfd != NULL) { … … 65 67 u_char *pptr = (u_char *)dat; 66 68 int j,k; 67 69 68 70 n /= 16; 69 71 n++; … … 85 87 /* 86 88 * Statistic routines 87 * 89 * 88 90 * These will print statistics to the screen, the debug file (dfd), or 89 91 * a buffer, depending on "type", so that the stats can be sent over … … 97 99 struct slirp_ifstats *is = &ttyp->ifstats; 98 100 char buff[512]; 99 101 100 102 lprint(" \r\n"); 101 103 102 104 if (if_comp & IF_COMPRESS) 103 105 strcpy(buff, "on"); … … 134 136 { 135 137 struct ttys *ttyp; 136 138 137 139 for (ttyp = ttys; ttyp; ttyp = ttyp->next) 138 140 ttystats(ttyp); … … 141 143 142 144 void 145 #ifdef VBOX 146 ipstats(PNATState pData) 147 #else /* !VBOX */ 143 148 ipstats() 144 { 145 lprint(" \r\n"); 149 #endif /* !VBOX */ 150 { 151 lprint(" \r\n"); 146 152 147 153 lprint("IP stats:\r\n"); … … 169 175 { 170 176 lprint(" \r\n"); 171 177 172 178 lprint("VJ compression stats:\r\n"); 173 179 174 180 lprint(" %6d outbound packets (%d compressed)\r\n", 175 181 comp_s.sls_packets, comp_s.sls_compressed); … … 184 190 185 191 void 192 #ifdef VBOX 193 tcpstats(PNATState pData) 194 #else /* !VBOX */ 186 195 tcpstats() 196 #endif /* !VBOX */ 187 197 { 188 198 lprint(" \r\n"); 189 199 190 200 lprint("TCP stats:\r\n"); 191 201 192 202 lprint(" %6d packets sent\r\n", tcpstat.tcps_sndtotal); 193 203 lprint(" %6d data packets (%d bytes)\r\n", … … 202 212 lprint(" %6d control (SYN/FIN/RST) packets\r\n", tcpstat.tcps_sndctrl); 203 213 lprint(" %6d times tcp_output did nothing\r\n", tcpstat.tcps_didnuttin); 204 205 lprint(" %6d packets received\r\n", tcpstat.tcps_rcvtotal); 214 215 lprint(" %6d packets received\r\n", tcpstat.tcps_rcvtotal); 206 216 lprint(" %6d acks (for %d bytes)\r\n", 207 217 tcpstat.tcps_rcvackpack, tcpstat.tcps_rcvackbyte); … … 212 222 lprint(" %6d completely duplicate packets (%d bytes)\r\n", 213 223 tcpstat.tcps_rcvduppack, tcpstat.tcps_rcvdupbyte); 214 224 215 225 lprint(" %6d packets with some duplicate data (%d bytes duped)\r\n", 216 226 tcpstat.tcps_rcvpartduppack, tcpstat.tcps_rcvpartdupbyte); … … 225 235 lprint(" %6d discarded for bad header offset fields\r\n", 226 236 tcpstat.tcps_rcvbadoff); 227 237 228 238 lprint(" %6d connection requests\r\n", tcpstat.tcps_connattempt); 229 239 lprint(" %6d connection accepts\r\n", tcpstat.tcps_accepts); … … 244 254 lprint(" %6d correct data packet header predictions\n", tcpstat.tcps_preddat); 245 255 lprint(" %6d TCP cache misses\r\n", tcpstat.tcps_socachemiss); 246 247 256 257 248 258 /* lprint(" Packets received too short: %d\r\n", tcpstat.tcps_rcvshort); */ 249 259 /* lprint(" Segments dropped due to PAWS: %d\r\n", tcpstat.tcps_pawsdrop); */ … … 252 262 253 263 void 264 #ifdef VBOX 265 udpstats(PNATState pData) 266 #else /* !VBOX */ 254 267 udpstats() 268 #endif /* !VBOX */ 255 269 { 256 270 lprint(" \r\n"); … … 266 280 267 281 void 282 #ifdef VBOX 283 icmpstats(PNATState pData) 284 #else /* !VBOX */ 268 285 icmpstats() 286 #endif /* !VBOX */ 269 287 { 270 288 lprint(" \r\n"); … … 279 297 280 298 void 299 #ifdef VBOX 300 mbufstats(PNATState pData) 301 #else /* !VBOX */ 281 302 mbufstats() 303 #endif /* !VBOX */ 282 304 { 283 305 struct mbuf *m; 284 306 int i; 285 307 286 308 lprint(" \r\n"); 287 309 288 310 lprint("Mbuf stats:\r\n"); 289 311 290 312 lprint(" %6d mbufs allocated (%d max)\r\n", mbuf_alloced, mbuf_max); 291 313 292 314 i = 0; 293 315 for (m = m_freelist.m_next; m != &m_freelist; m = m->m_next) 294 316 i++; 295 317 lprint(" %6d mbufs on free list\r\n", i); 296 318 297 319 i = 0; 298 320 for (m = m_usedlist.m_next; m != &m_usedlist; m = m->m_next) … … 303 325 304 326 void 327 #ifdef VBOX 328 sockstats(PNATState pData) 329 #else /* !VBOX */ 305 330 sockstats() 331 #endif /* !VBOX */ 306 332 { 307 333 char buff[256]; … … 310 336 311 337 lprint(" \r\n"); 312 338 313 339 lprint( 314 340 "Proto[state] Sock Local Address, Port Remote Address, Port RecvQ SendQ\r\n"); 315 341 316 342 for (so = tcb.so_next; so != &tcb; so = so->so_next) { 317 343 318 344 n = sprintf(buff, "tcp[%s]", so->so_tcpcb?tcpstates[so->so_tcpcb->t_state]:"NONE"); 319 345 while (n < 17) … … 327 353 so->so_rcv.sb_cc, so->so_snd.sb_cc); 328 354 } 329 355 330 356 for (so = udb.so_next; so != &udb; so = so->so_next) { 331 357 332 358 n = sprintf(buff, "udp[%d sec]", (so->so_expire - curtime) / 1000); 333 359 while (n < 17) … … 349 375 { 350 376 struct ttys *ttyp; 351 377 352 378 DEBUG_CALL("slirp_exit"); 353 379 DEBUG_ARG("exit_status = %d", exit_status); … … 358 384 debug_init("slirp_stats", 0xf); 359 385 lprint_arg = (char **)&dfd; 360 386 361 387 ipstats(); 362 388 tcpstats(); … … 368 394 vjstats(); 369 395 } 370 396 371 397 for (ttyp = ttys; ttyp; ttyp = ttyp->next) 372 398 tty_detached(ttyp, 1); 373 399 374 400 if (slirp_forked) { 375 401 /* Menendez time */ … … 378 404 (long) getppid()); 379 405 } 380 406 381 407 /* Restore the terminal if we gotta */ 382 408 if(slirp_tty_restore) -
trunk/src/VBox/Devices/Network/slirp/debug.h
r1 r1033 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 */ … … 9 9 #define PRN_SPRINTF 2 10 10 11 #ifdef VBOX 12 /* Unused anyway, using VBox Log facility. */ 13 #define dfd NULL 14 #else /* !VBOX */ 11 15 extern FILE *dfd; 12 16 extern FILE *lfd; 17 #endif /* !VBOX */ 13 18 extern int dostats; 14 19 extern int slirp_debug; … … 87 92 /*void ttystats _P((struct ttys *)); */ 88 93 void allttystats _P((void)); 94 #ifdef VBOX 95 void ipstats _P((PNATState)); 96 void tcpstats _P((PNATState)); 97 void udpstats _P((PNATState)); 98 void icmpstats _P((PNATState)); 99 void mbufstats _P((PNATState)); 100 void sockstats _P((PNATState)); 101 #else /* !VBOX */ 89 102 void ipstats _P((void)); 90 #ifndef VBOX91 103 void vjstats _P((void)); 92 #endif /* VBOX */93 104 void tcpstats _P((void)); 94 105 void udpstats _P((void)); … … 96 107 void mbufstats _P((void)); 97 108 void sockstats _P((void)); 109 #endif /* VBOX */ 98 110 #ifndef VBOX 99 111 void slirp_exit _P((int)); -
trunk/src/VBox/Devices/Network/slirp/icmp_var.h
r1 r1033 42 42 * of the internet control message protocol. 43 43 */ 44 #ifdef VBOX 45 struct icmpstat_t { 46 #else /* !VBOX */ 44 47 struct icmpstat { 48 #endif /* !VBOX */ 45 49 /* statistics related to input messages processed */ 46 50 u_long icps_received; /* #ICMP packets received */ … … 65 69 } 66 70 71 #ifndef VBOX 67 72 extern struct icmpstat icmpstat; 73 #endif /* !VBOX */ 68 74 69 75 #endif -
trunk/src/VBox/Devices/Network/slirp/if.c
r1 r1033 8 8 #include <slirp.h> 9 9 10 #ifndef VBOX 10 11 int if_mtu, if_mru; 11 12 int if_comp; … … 18 19 struct mbuf if_batchq; /* queue for non-interactive data */ 19 20 struct mbuf *next_m; /* Pointer to next mbuf to output */ 21 #endif /* !VBOX */ 20 22 21 23 #define ifs_init(ifm) ((ifm)->ifs_next = (ifm)->ifs_prev = (ifm)) … … 48 50 49 51 void 52 #ifdef VBOX 53 if_init(PNATState pData) 54 #else /* !VBOX */ 50 55 if_init() 56 #endif /* !VBOX */ 51 57 { 52 58 #if 0 … … 64 70 if_maxlinkhdr = 2 + 14 + 40; 65 71 #endif 72 #ifdef VBOX 73 if_queued = 0; 74 if_thresh = 10; 75 #endif /* VBOX */ 66 76 if_mtu = 1500; 67 77 if_mru = 1500; … … 86 96 int ret; 87 97 int total; 88 98 89 99 /* This should succeed most of the time */ 90 100 ret = send(fd, bptr, n,0); 91 101 if (ret == n || ret <= 0) 92 102 return ret; 93 103 94 104 /* Didn't write everything, go into the loop */ 95 105 total = ret; … … 106 116 * if_input - read() the tty, do "top level" processing (ie: check for any escapes), 107 117 * and pass onto (*ttyp->if_input) 108 * 118 * 109 119 * XXXXX Any zeros arriving by themselves are NOT placed into the arriving packet. 110 120 */ … … 116 126 u_char if_inbuff[INBUFF_SIZE]; 117 127 int if_n; 118 128 119 129 DEBUG_CALL("if_input"); 120 130 DEBUG_ARG("ttyp = %lx", (long)ttyp); 121 131 122 132 if_n = recv(ttyp->fd, (char *)if_inbuff, INBUFF_SIZE,0); 123 133 124 134 DEBUG_MISC((dfd, " read %d bytes\n", if_n)); 125 135 126 136 if (if_n <= 0) { 127 137 if (if_n == 0 || (errno != EINTR && errno != EAGAIN)) { … … 147 157 } 148 158 ttyp->ones = ttyp->zeros = 0; 149 159 150 160 (*ttyp->if_input)(ttyp, if_inbuff, if_n); 151 161 } 152 #endif 153 162 #endif 163 154 164 /* 155 165 * if_output: Queue packet into an output queue. 156 * There are 2 output queue's, if_fastq and if_batchq. 166 * There are 2 output queue's, if_fastq and if_batchq. 157 167 * Each output queue is a doubly linked list of double linked lists 158 168 * of mbufs, each list belonging to one "session" (socket). This 159 169 * way, we can output packets fairly by sending one packet from each 160 170 * session, instead of all the packets from one session, then all packets 161 * from the next session, etc. Packets on the if_fastq get absolute 171 * from the next session, etc. Packets on the if_fastq get absolute 162 172 * priority, but if one session hogs the link, it gets "downgraded" 163 173 * to the batchq until it runs out of packets, then it'll return … … 166 176 */ 167 177 void 178 #ifdef VBOX 179 if_output(PNATState pData, struct socket *so, struct mbuf *ifm) 180 #else /* !VBOX */ 168 181 if_output(so, ifm) 169 182 struct socket *so; 170 183 struct mbuf *ifm; 184 #endif /* !VBOX */ 171 185 { 172 186 struct mbuf *ifq; 173 187 int on_fastq = 1; 174 188 175 189 DEBUG_CALL("if_output"); 176 190 DEBUG_ARG("so = %lx", (long)so); 177 191 DEBUG_ARG("ifm = %lx", (long)ifm); 178 192 179 193 /* 180 194 * First remove the mbuf from m_usedlist, … … 186 200 ifm->m_flags &= ~M_USEDLIST; 187 201 } 188 189 /* 190 * See if there's already a batchq list for this session. 202 203 /* 204 * See if there's already a batchq list for this session. 191 205 * This can include an interactive session, which should go on fastq, 192 206 * but gets too greedy... hence it'll be downgraded from fastq to batchq. … … 202 216 } 203 217 } 204 218 205 219 /* No match, check which queue to put it on */ 206 220 if (so && (so->so_iptos & IPTOS_LOWDELAY)) { … … 218 232 } else 219 233 ifq = if_batchq.ifq_prev; 220 234 221 235 /* Create a new doubly linked list for this session */ 222 236 ifm->ifq_so = so; 223 237 ifs_init(ifm); 224 238 insque(ifm, ifq); 225 239 226 240 diddit: 227 241 ++if_queued; 228 242 229 243 if (so) { 230 244 /* Update *_queued */ … … 238 252 * (XXX These are arbitrary numbers, probably not optimal..) 239 253 */ 240 if (on_fastq && ((so->so_nqueued >= 6) && 254 if (on_fastq && ((so->so_nqueued >= 6) && 241 255 (so->so_nqueued - so->so_queued) >= 3)) { 242 256 243 257 /* Remove from current queue... */ 244 258 remque(ifm->ifs_next); 245 259 246 260 /* ...And insert in the new. That'll teach ya! */ 247 261 insque(ifm->ifs_next, &if_batchq); … … 255 269 if (link_up) { 256 270 /* if_start will check towrite */ 271 #ifdef VBOX 272 if_start(pData); 273 #else /* !VBOX */ 257 274 if_start(); 275 #endif /* !VBOX */ 258 276 } 259 277 #endif … … 273 291 */ 274 292 void 293 #ifdef VBOX 294 if_start(PNATState pData) 295 #else /* !VBOX */ 275 296 if_start(void) 297 #endif /* !VBOX */ 276 298 { 277 299 struct mbuf *ifm, *ifqt; 278 300 279 301 DEBUG_CALL("if_start"); 280 302 281 303 if (if_queued == 0) 282 304 return; /* Nothing to do */ 283 305 284 306 again: 285 307 /* check if we can really output */ 308 #ifdef VBOX 309 if (!slirp_can_output(pData->pvUser)) 310 #else /* !VBOX */ 286 311 if (!slirp_can_output()) 312 #endif /* !VBOX */ 287 313 return; 288 314 … … 299 325 else 300 326 ifm = if_batchq.ifq_next; 301 327 302 328 /* Set which packet to send on next iteration */ 303 329 next_m = ifm->ifq_next; … … 307 333 remque(ifm); 308 334 --if_queued; 309 335 310 336 /* If there are more packets for this session, re-queue them */ 311 337 if (ifm->ifs_next != /* ifm->ifs_prev != */ ifm) { … … 313 339 ifs_remque(ifm); 314 340 } 315 341 316 342 /* Update so_queued */ 317 343 if (ifm->ifq_so) { … … 320 346 ifm->ifq_so->so_nqueued = 0; 321 347 } 322 348 323 349 /* Encapsulate the packet for sending */ 324 350 #ifndef VBOX 325 351 if_encap(ifm->m_data, ifm->m_len); 326 352 #else /* VBOX */ 327 if_encap( (const uint8_t *)ifm->m_data, ifm->m_len);353 if_encap(pData, (const uint8_t *)ifm->m_data, ifm->m_len); 328 354 #endif /* VBOX */ 329 355 356 #ifdef VBOX 357 m_free(pData, ifm); 358 #else /* !VBOX */ 330 359 m_free(ifm); 360 #endif /* !VBOX */ 331 361 332 362 if (if_queued) -
trunk/src/VBox/Devices/Network/slirp/ip.h
r1 r1033 213 213 214 214 #if SIZEOF_CHAR_P == 4 215 typedef struct ipq *ipqp_32;215 typedef struct ipq_t *ipqp_32; 216 216 typedef struct ipasfrag *ipasfragp_32; 217 217 #else … … 239 239 * size 28 bytes 240 240 */ 241 struct ipq {241 struct ipq_t { 242 242 ipqp_32 next,prev; /* to other reass headers */ 243 243 u_int8_t ipq_ttl; /* time for reass q to live */ … … 300 300 */ 301 301 302 #ifdef VBOX 303 struct ipstat_t { 304 #else /* !VBOX */ 302 305 struct ipstat { 306 #endif /* !VBOX */ 303 307 u_long ips_total; /* total packets received */ 304 308 u_long ips_badsum; /* checksum bad */ … … 328 332 }; 329 333 334 #ifndef VBOX 330 335 extern struct ipstat ipstat; 331 336 extern struct ipq ipq; /* ip reass. queue */ 332 337 extern u_int16_t ip_id; /* ip packet ctr, for ids */ 333 338 extern int ip_defttl; /* default IP ttl */ 334 335 #endif 339 #endif /* !VBOX */ 340 341 #endif -
trunk/src/VBox/Devices/Network/slirp/ip_icmp.c
r1 r1033 38 38 #include "ip_icmp.h" 39 39 40 #ifndef VBOX 40 41 struct icmpstat icmpstat; 42 #endif /* !VBOX */ 41 43 42 44 /* The message sent when emulating PING */ 43 45 /* Be nice and tell them it's just a psuedo-ping packet */ 46 #ifdef VBOX 47 static const char icmp_ping_msg[] = "This is a psuedo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n"; 48 #else /* !VBOX */ 44 49 char icmp_ping_msg[] = "This is a psuedo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n"; 50 #endif /* !VBOX */ 45 51 46 52 /* list of actions for icmp_error() on RX of an icmp message */ 53 #ifdef VBOX 54 static const int icmp_flush[19] = { 55 #else /* !VBOX */ 47 56 static int icmp_flush[19] = { 57 #endif /* !VBOX */ 48 58 /* ECHO REPLY (0) */ 0, 49 59 1, … … 64 74 /* INFO REPLY (16) */ 0, 65 75 /* ADDR MASK (17) */ 0, 66 /* ADDR MASK REPLY (18) */ 0 76 /* ADDR MASK REPLY (18) */ 0 67 77 }; 68 78 … … 71 81 */ 72 82 void 83 #ifdef VBOX 84 icmp_input(PNATState pData, struct mbuf *m, int hlen) 85 #else /* !VBOX */ 73 86 icmp_input(m, hlen) 74 87 struct mbuf *m; 75 88 int hlen; 89 #endif /* !VBOX */ 76 90 { 77 91 register struct icmp *icp; … … 79 93 int icmplen=ip->ip_len; 80 94 /* int code; */ 81 95 82 96 DEBUG_CALL("icmp_input"); 83 97 DEBUG_ARG("m = %lx", (long )m); … … 85 99 86 100 icmpstat.icps_received++; 87 101 88 102 /* 89 103 * Locate icmp structure in mbuf, and check … … 93 107 icmpstat.icps_tooshort++; 94 108 freeit: 109 #ifdef VBOX 110 m_freem(pData, m); 111 #else /* !VBOX */ 95 112 m_freem(m); 113 #endif /* !VBOX */ 96 114 goto end_error; 97 115 } … … 106 124 m->m_len += hlen; 107 125 m->m_data -= hlen; 108 126 109 127 /* icmpstat.icps_inhist[icp->icmp_type]++; */ 110 128 /* code = icp->icmp_code; */ … … 116 134 ip->ip_len += hlen; /* since ip_input subtracts this */ 117 135 if (ip->ip_dst.s_addr == alias_addr.s_addr) { 136 #ifdef VBOX 137 icmp_reflect(pData, m); 138 #else /* !VBOX */ 118 139 icmp_reflect(m); 140 #endif /* !VBOX */ 119 141 } else { 120 142 struct socket *so; 121 143 struct sockaddr_in addr; 122 144 if ((so = socreate()) == NULL) goto freeit; 145 #ifdef VBOX 146 if(udp_attach(pData, so) == -1) { 147 #else /* !VBOX */ 123 148 if(udp_attach(so) == -1) { 124 DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n", 149 #endif /* !VBOX */ 150 DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n", 125 151 errno,strerror(errno))); 152 #ifdef VBOX 153 sofree(pData, so); 154 m_free(pData, m); 155 #else /* !VBOX */ 126 156 sofree(so); 127 157 m_free(m); 158 #endif /* !VBOX */ 128 159 goto end_error; 129 160 } … … 136 167 so->so_type = IPPROTO_ICMP; 137 168 so->so_state = SS_ISFCONNECTED; 138 169 139 170 /* Send the packet */ 140 171 addr.sin_family = AF_INET; … … 158 189 DEBUG_MISC((dfd,"icmp_input udp sendto tx errno = %d-%s\n", 159 190 errno,strerror(errno))); 160 icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno)); 191 #ifdef VBOX 192 icmp_error(pData, m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno)); 193 udp_detach(pData, so); 194 #else /* !VBOX */ 195 icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno)); 161 196 udp_detach(so); 197 #endif /* !VBOX */ 162 198 } 163 199 } /* if ip->ip_dst.s_addr == alias_addr.s_addr */ … … 172 208 case ICMP_REDIRECT: 173 209 icmpstat.icps_notsupp++; 210 #ifdef VBOX 211 m_freem(pData, m); 212 #else /* !VBOX */ 174 213 m_freem(m); 214 #endif /* !VBOX */ 175 215 break; 176 216 177 217 default: 178 218 icmpstat.icps_badtype++; 219 #ifdef VBOX 220 m_freem(pData, m); 221 #else /* !VBOX */ 179 222 m_freem(m); 223 #endif /* !VBOX */ 180 224 } /* swith */ 181 225 … … 200 244 * It is reported as the bad ip packet. The header should 201 245 * be fully correct and in host byte order. 202 * ICMP fragmentation is illegal. All machines must accept 576 bytes in one 246 * ICMP fragmentation is illegal. All machines must accept 576 bytes in one 203 247 * packet. The maximum payload is 576-20(ip hdr)-8(icmp hdr)=548 204 248 */ … … 214 258 char *message; 215 259 #else /* VBOX */ 216 void icmp_error( struct mbuf *msrc, u_char type, u_char code, int minsize, char *message)260 void icmp_error(PNATState pData, struct mbuf *msrc, u_char type, u_char code, int minsize, char *message) 217 261 #endif /* VBOX */ 218 262 { … … 231 275 if(!msrc) goto end_error; 232 276 ip = mtod(msrc, struct ip *); 233 #if DEBUG 277 #if DEBUG 234 278 { char bufa[20], bufb[20]; 235 279 strcpy(bufa, inet_ntoa(ip->ip_src)); … … 252 296 253 297 /* make a copy */ 298 #ifdef VBOX 299 if(!(m=m_get(pData))) goto end_error; /* get mbuf */ 300 #else /* !VBOX */ 254 301 if(!(m=m_get())) goto end_error; /* get mbuf */ 302 #endif /* !VBOX */ 255 303 { int new_m_size; 256 304 new_m_size=sizeof(struct ip )+ICMP_MINLEN+msrc->m_len+ICMP_MAXDATALEN; … … 263 311 ip = mtod(m, struct ip *); 264 312 hlen= sizeof(struct ip ); /* no options in reply */ 265 313 266 314 /* fill in icmp */ 267 m->m_data += hlen; 315 m->m_data += hlen; 268 316 m->m_len -= hlen; 269 317 … … 274 322 s_ip_len=ICMP_MAXDATALEN; 275 323 276 m->m_len=ICMP_MINLEN+s_ip_len; /* 8 bytes ICMP header */ 324 m->m_len=ICMP_MINLEN+s_ip_len; /* 8 bytes ICMP header */ 277 325 278 326 /* min. size = 8+sizeof(struct ip)+8 */ … … 309 357 ip->ip_hl = hlen >> 2; 310 358 ip->ip_len = m->m_len; 311 359 312 360 ip->ip_tos=((ip->ip_tos & 0x1E) | 0xC0); /* high priority for errors */ 313 361 … … 317 365 ip->ip_src = alias_addr; 318 366 367 #ifdef VBOX 368 (void ) ip_output(pData, (struct socket *)NULL, m); 369 #else /* !VBOX */ 319 370 (void ) ip_output((struct socket *)NULL, m); 320 371 #endif /* !VBOX */ 372 321 373 icmpstat.icps_reflect++; 322 374 … … 330 382 */ 331 383 void 384 #ifdef VBOX 385 icmp_reflect(PNATState pData, struct mbuf *m) 386 #else /* !VBOX */ 332 387 icmp_reflect(m) 333 388 struct mbuf *m; 389 #endif /* !VBOX */ 334 390 { 335 391 register struct ip *ip = mtod(m, struct ip *); … … 374 430 } 375 431 432 #ifdef VBOX 433 (void ) ip_output(pData, (struct socket *)NULL, m); 434 #else /* !VBOX */ 376 435 (void ) ip_output((struct socket *)NULL, m); 436 #endif /* !VBOX */ 377 437 378 438 icmpstat.icps_reflect++; -
trunk/src/VBox/Devices/Network/slirp/ip_icmp.h
r1 r1033 158 158 (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) 159 159 160 #ifdef VBOX 161 void icmp_input _P((PNATState, struct mbuf *, int)); 162 void icmp_error _P((PNATState, struct mbuf *, u_char, u_char, int, char *)); 163 void icmp_reflect _P((PNATState, struct mbuf *)); 164 #else /* !VBOX */ 160 165 void icmp_input _P((struct mbuf *, int)); 161 166 void icmp_error _P((struct mbuf *, u_char, u_char, int, char *)); 162 167 void icmp_reflect _P((struct mbuf *)); 168 #endif /* !VBOX */ 163 169 164 170 #endif -
trunk/src/VBox/Devices/Network/slirp/ip_input.c
r530 r1033 38 38 * Changes and additions relating to SLiRP are 39 39 * Copyright (c) 1995 Danny Gasparovski. 40 * 40 * 41 41 * Please read the file COPYRIGHT for the 42 42 * terms and conditions of the copyright. … … 46 46 #include "ip_icmp.h" 47 47 48 #ifndef VBOX 48 49 int ip_defttl; 49 50 struct ipstat ipstat; 50 51 struct ipq ipq; 52 #endif /* !VBOX */ 51 53 52 54 /* … … 55 57 */ 56 58 void 59 #ifdef VBOX 60 ip_init(PNATState pData) 61 #else /* !VBOX */ 57 62 ip_init() 63 #endif /* !VBOX */ 58 64 { 59 65 ipq.next = ipq.prev = ptr_to_u32(&ipq); 66 #ifdef VBOX 67 ip_currid = tt.tv_sec & 0xffff; 68 udp_init(pData); 69 tcp_init(pData); 70 #else /* !VBOX */ 60 71 ip_id = tt.tv_sec & 0xffff; 61 72 udp_init(); 62 73 tcp_init(); 74 #endif /* !VBOX */ 75 #ifndef VBOX 63 76 ip_defttl = IPDEFTTL; 77 #endif /* !VBOX */ 64 78 } 65 79 … … 69 83 */ 70 84 void 85 #ifdef VBOX 86 ip_input(PNATState pData, struct mbuf *m) 87 #else /* !VBOX */ 71 88 ip_input(m) 72 89 struct mbuf *m; 90 #endif /* !VBOX */ 73 91 { 74 92 register struct ip *ip; 75 93 int hlen; 76 94 77 95 DEBUG_CALL("ip_input"); 78 96 DEBUG_ARG("m = %lx", (long)m); … … 80 98 81 99 ipstat.ips_total++; 82 100 83 101 if (m->m_len < sizeof (struct ip)) { 84 102 ipstat.ips_toosmall++; 85 103 return; 86 104 } 87 105 88 106 ip = mtod(m, struct ip *); 89 107 90 108 if (ip->ip_v != IPVERSION) { 91 109 ipstat.ips_badvers++; … … 100 118 101 119 /* keep ip header intact for ICMP reply 102 * ip->ip_sum = cksum(m, hlen); 103 * if (ip->ip_sum) { 120 * ip->ip_sum = cksum(m, hlen); 121 * if (ip->ip_sum) { 104 122 */ 105 123 if(cksum(m,hlen)) { … … 135 153 /* check ip_ttl for a correct ICMP reply */ 136 154 if(ip->ip_ttl==0 || ip->ip_ttl==1) { 155 #ifdef VBOX 156 icmp_error(pData, m, ICMP_TIMXCEED,ICMP_TIMXCEED_INTRANS, 0,"ttl"); 157 #else /* !VBOX */ 137 158 icmp_error(m, ICMP_TIMXCEED,ICMP_TIMXCEED_INTRANS, 0,"ttl"); 159 #endif /* !VBOX */ 138 160 goto bad; 139 161 } … … 155 177 * if the packet was previously fragmented, 156 178 * but it's not worth the time; just let them time out.) 157 * 179 * 158 180 * XXX This should fail, don't fragment yet 159 181 */ 160 182 if (ip->ip_off &~ IP_DF) { 161 register struct ipq *fp;183 register struct ipq_t *fp; 162 184 /* 163 185 * Look for queue of fragments 164 186 * of this datagram. 165 187 */ 166 for (fp = u32_to_ptr(ipq.next, struct ipq *); fp != &ipq;167 fp = u32_to_ptr(fp->next, struct ipq *))188 for (fp = u32_to_ptr(ipq.next, struct ipq_t *); fp != &ipq; 189 fp = u32_to_ptr(fp->next, struct ipq_t *)) 168 190 if (ip->ip_id == fp->ipq_id && 169 191 ip->ip_src.s_addr == fp->ipq_src.s_addr && … … 182 204 if (ip->ip_off & IP_MF) 183 205 ((struct ipasfrag *)ip)->ipf_mff |= 1; 184 else 206 else 185 207 ((struct ipasfrag *)ip)->ipf_mff &= ~1; 186 208 … … 194 216 if (((struct ipasfrag *)ip)->ipf_mff & 1 || ip->ip_off) { 195 217 ipstat.ips_fragments++; 218 #ifdef VBOX 219 ip = ip_reass(pData, (struct ipasfrag *)ip, fp); 220 #else /* !VBOX */ 196 221 ip = ip_reass((struct ipasfrag *)ip, fp); 222 #endif /* !VBOX */ 197 223 if (ip == 0) 198 224 return; 199 225 ipstat.ips_reassembled++; 226 #ifdef VBOX 227 m = dtom(pData, ip); 228 #else /* !VBOX */ 200 229 m = dtom(ip); 230 #endif /* !VBOX */ 201 231 } else 202 232 if (fp) 233 #ifdef VBOX 234 ip_freef(pData, fp); 235 #else /* !VBOX */ 203 236 ip_freef(fp); 237 #endif /* !VBOX */ 204 238 205 239 } else … … 212 246 switch (ip->ip_p) { 213 247 case IPPROTO_TCP: 248 #ifdef VBOX 249 tcp_input(pData, m, hlen, (struct socket *)NULL); 250 #else /* !VBOX */ 214 251 tcp_input(m, hlen, (struct socket *)NULL); 252 #endif /* !VBOX */ 215 253 break; 216 254 case IPPROTO_UDP: 255 #ifdef VBOX 256 udp_input(pData, m, hlen); 257 #else /* !VBOX */ 217 258 udp_input(m, hlen); 259 #endif /* !VBOX */ 218 260 break; 219 261 case IPPROTO_ICMP: 262 #ifdef VBOX 263 icmp_input(pData, m, hlen); 264 #else /* !VBOX */ 220 265 icmp_input(m, hlen); 266 #endif /* !VBOX */ 221 267 break; 222 268 default: 223 269 ipstat.ips_noproto++; 270 #ifdef VBOX 271 m_free(pData, m); 272 #else /* !VBOX */ 224 273 m_free(m); 274 #endif /* !VBOX */ 225 275 } 226 276 return; 227 277 bad: 278 #ifdef VBOX 279 m_freem(pData, m); 280 #else /* !VBOX */ 228 281 m_freem(m); 282 #endif /* !VBOX */ 229 283 return; 230 284 } … … 237 291 */ 238 292 struct ip * 293 #ifdef VBOX 294 ip_reass(PNATState pData, register struct ipasfrag *ip, register struct ipq_t *fp) 295 #else /* !VBOX */ 239 296 ip_reass(ip, fp) 240 297 register struct ipasfrag *ip; 241 register struct ipq *fp; 298 register struct ipq_t *fp; 299 #endif /* !VBOX */ 242 300 { 301 #ifdef VBOX 302 register struct mbuf *m = dtom(pData, ip); 303 #else /* !VBOX */ 243 304 register struct mbuf *m = dtom(ip); 305 #endif /* !VBOX */ 244 306 register struct ipasfrag *q; 245 307 int hlen = ip->ip_hl << 2; 246 308 int i, next; 247 309 248 310 DEBUG_CALL("ip_reass"); 249 311 DEBUG_ARG("ip = %lx", (long)ip); … … 264 326 if (fp == 0) { 265 327 struct mbuf *t; 328 #ifdef VBOX 329 if ((t = m_get(pData)) == NULL) goto dropfrag; 330 #else /* !VBOX */ 266 331 if ((t = m_get()) == NULL) goto dropfrag; 267 fp = mtod(t, struct ipq *); 332 #endif /* !VBOX */ 333 fp = mtod(t, struct ipq_t *); 268 334 insque_32(fp, &ipq); 269 335 fp->ipq_ttl = IPFRAGTTL; … … 276 342 goto insert; 277 343 } 278 344 279 345 /* 280 346 * Find a segment which begins after this one does. … … 290 356 * segment. If it provides all of our data, drop us. 291 357 */ 292 if (u32_to_ptr(q->ipf_prev, struct ipq *) != fp) {358 if (u32_to_ptr(q->ipf_prev, struct ipq_t *) != fp) { 293 359 i = (u32_to_ptr(q->ipf_prev, struct ipasfrag *))->ip_off + 294 360 (u32_to_ptr(q->ipf_prev, struct ipasfrag *))->ip_len - ip->ip_off; … … 296 362 if (i >= ip->ip_len) 297 363 goto dropfrag; 364 #ifdef VBOX 365 m_adj(dtom(pData, ip), i); 366 #else /* !VBOX */ 298 367 m_adj(dtom(ip), i); 368 #endif /* !VBOX */ 299 369 ip->ip_off += i; 300 370 ip->ip_len -= i; … … 311 381 q->ip_len -= i; 312 382 q->ip_off += i; 383 #ifdef VBOX 384 m_adj(dtom(pData, q), i); 385 #else /* !VBOX */ 313 386 m_adj(dtom(q), i); 387 #endif /* !VBOX */ 314 388 break; 315 389 } 316 390 q = u32_to_ptr(q->ipf_next, struct ipasfrag *); 317 m_freem( dtom(u32_to_ptr(q->ipf_prev, struct ipasfrag *)));391 m_freem(pData, dtom(pData, u32_to_ptr(q->ipf_prev, struct ipasfrag *))); 318 392 ip_deq(u32_to_ptr(q->ipf_prev, struct ipasfrag *)); 319 393 } … … 339 413 */ 340 414 q = u32_to_ptr(fp->ipq_next, struct ipasfrag *); 415 #ifdef VBOX 416 m = dtom(pData, q); 417 #else /* !VBOX */ 341 418 m = dtom(q); 419 #endif /* !VBOX */ 342 420 343 421 q = u32_to_ptr(q->ipf_next, struct ipasfrag *); 344 422 while (q != (struct ipasfrag *)fp) { 345 423 struct mbuf *t; 424 #ifdef VBOX 425 t = dtom(pData, q); 426 #else /* !VBOX */ 346 427 t = dtom(q); 428 #endif /* !VBOX */ 347 429 q = u32_to_ptr(q->ipf_next, struct ipasfrag *); 430 #ifdef VBOX 431 m_cat(pData, m, t); 432 #else /* !VBOX */ 348 433 m_cat(m, t); 434 #endif /* !VBOX */ 349 435 } 350 436 … … 370 456 } 371 457 372 /* DEBUG_ARG("ip = %lx", (long)ip); 458 /* DEBUG_ARG("ip = %lx", (long)ip); 373 459 * ip=(struct ipasfrag *)m->m_data; */ 374 460 … … 378 464 ((struct ip *)ip)->ip_dst = fp->ipq_dst; 379 465 remque_32(fp); 466 #ifdef VBOX 467 (void) m_free(pData, dtom(pData, fp)); 468 m = dtom(pData, ip); 469 #else /* !VBOX */ 380 470 (void) m_free(dtom(fp)); 381 471 m = dtom(ip); 472 #endif /* !VBOX */ 382 473 m->m_len += (ip->ip_hl << 2); 383 474 m->m_data -= (ip->ip_hl << 2); … … 387 478 dropfrag: 388 479 ipstat.ips_fragdropped++; 480 #ifdef VBOX 481 m_freem(pData, m); 482 #else /* !VBOX */ 389 483 m_freem(m); 484 #endif /* !VBOX */ 390 485 return (0); 391 486 } … … 396 491 */ 397 492 void 493 #ifdef VBOX 494 ip_freef(PNATState pData, struct ipq_t *fp) 495 #else /* !VBOX */ 398 496 ip_freef(fp) 399 struct ipq *fp; 497 struct ipq_t *fp; 498 #endif /* !VBOX */ 400 499 { 401 500 register struct ipasfrag *q, *p; … … 405 504 p = u32_to_ptr(q->ipf_next, struct ipasfrag *); 406 505 ip_deq(q); 506 #ifdef VBOX 507 m_freem(pData, dtom(pData, q)); 508 #else /* !VBOX */ 407 509 m_freem(dtom(q)); 510 #endif /* !VBOX */ 408 511 } 409 512 remque_32(fp); 513 #ifdef VBOX 514 (void) m_free(pData, dtom(pData, fp)); 515 #else /* !VBOX */ 410 516 (void) m_free(dtom(fp)); 517 #endif /* !VBOX */ 411 518 } 412 519 … … 447 554 */ 448 555 void 556 #ifdef VBOX 557 ip_slowtimo(PNATState pData) 558 #else /* !VBOX */ 449 559 ip_slowtimo() 560 #endif /* !VBOX */ 450 561 { 451 register struct ipq *fp;452 562 register struct ipq_t *fp; 563 453 564 DEBUG_CALL("ip_slowtimo"); 454 455 fp = u32_to_ptr(ipq.next, struct ipq *);565 566 fp = u32_to_ptr(ipq.next, struct ipq_t *); 456 567 if (fp == 0) 457 568 return; … … 459 570 while (fp != &ipq) { 460 571 --fp->ipq_ttl; 461 fp = u32_to_ptr(fp->next, struct ipq *);462 if (u32_to_ptr(fp->prev, struct ipq *)->ipq_ttl == 0) {572 fp = u32_to_ptr(fp->next, struct ipq_t *); 573 if (u32_to_ptr(fp->prev, struct ipq_t *)->ipq_ttl == 0) { 463 574 ipstat.ips_fragtimeout++; 464 ip_freef( u32_to_ptr(fp->prev, struct ipq*));575 ip_freef(pData, u32_to_ptr(fp->prev, struct ipq_t *)); 465 576 } 466 577 } … … 696 807 memcpy(opts, opts + olen, (unsigned)i); 697 808 m->m_len -= olen; 698 809 699 810 ip->ip_hl = sizeof(struct ip) >> 2; 700 811 } -
trunk/src/VBox/Devices/Network/slirp/ip_output.c
r1 r1033 45 45 #include <slirp.h> 46 46 47 #ifndef VBOX 47 48 u_int16_t ip_id; 49 #endif /* !VBOX */ 48 50 49 51 /* … … 54 56 */ 55 57 int 58 #ifdef VBOX 59 ip_output(PNATState pData, struct socket *so, struct mbuf *m0) 60 #else /* !VBOX */ 56 61 ip_output(so, m0) 57 62 struct socket *so; 58 63 struct mbuf *m0; 64 #endif /* !VBOX */ 59 65 { 60 66 register struct ip *ip; … … 66 72 DEBUG_ARG("so = %lx", (long)so); 67 73 DEBUG_ARG("m0 = %lx", (long)m0); 68 74 69 75 /* We do no options */ 70 76 /* if (opt) { … … 79 85 ip->ip_v = IPVERSION; 80 86 ip->ip_off &= IP_DF; 87 #ifdef VBOX 88 ip->ip_id = htons(ip_currid++); 89 #else /* !VBOX */ 81 90 ip->ip_id = htons(ip_id++); 91 #endif /* !VBOX */ 82 92 ip->ip_hl = hlen >> 2; 83 93 ipstat.ips_localout++; … … 93 103 * } 94 104 */ 95 105 96 106 /* 97 107 * If small enough for interface, can just send directly. … … 103 113 ip->ip_sum = cksum(m, hlen); 104 114 115 #ifdef VBOX 116 if_output(pData, so, m); 117 #else /* !VBOX */ 105 118 if_output(so, m); 119 #endif /* !VBOX */ 106 120 goto done; 107 121 } … … 116 130 goto bad; 117 131 } 118 132 119 133 len = (if_mtu - hlen) &~ 7; /* ip databytes per packet */ 120 134 if (len < 8) { … … 135 149 for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) { 136 150 register struct ip *mhip; 151 #ifdef VBOX 152 m = m_get(pData); 153 #else /* !VBOX */ 137 154 m = m_get(); 155 #endif /* !VBOX */ 138 156 if (m == 0) { 139 157 error = -1; … … 144 162 mhip = mtod(m, struct ip *); 145 163 *mhip = *ip; 146 164 147 165 /* No options */ 148 166 /* if (hlen > sizeof (struct ip)) { … … 157 175 if (off + len >= (u_int16_t)ip->ip_len) 158 176 len = (u_int16_t)ip->ip_len - off; 159 else 177 else 160 178 mhip->ip_off |= IP_MF; 161 179 mhip->ip_len = htons((u_int16_t)(len + mhlen)); 162 180 163 181 if (m_copy(m, m0, off, len) < 0) { 164 182 error = -1; 165 183 goto sendorfree; 166 184 } 167 185 168 186 mhip->ip_off = htons((u_int16_t)mhip->ip_off); 169 187 mhip->ip_sum = 0; … … 188 206 m->m_nextpkt = 0; 189 207 if (error == 0) 208 #ifdef VBOX 209 if_output(pData, so, m); 210 #else /* !VBOX */ 190 211 if_output(so, m); 212 #endif /* !VBOX */ 191 213 else 214 #ifdef VBOX 215 m_freem(pData, m); 216 #else /* !VBOX */ 192 217 m_freem(m); 218 #endif /* !VBOX */ 193 219 } 194 220 … … 201 227 202 228 bad: 229 #ifdef VBOX 230 m_freem(pData, m0); 231 #else /* !VBOX */ 203 232 m_freem(m0); 233 #endif /* !VBOX */ 204 234 goto done; 205 235 } -
trunk/src/VBox/Devices/Network/slirp/libslirp.h
r530 r1033 21 21 #ifdef VBOX 22 22 #include <VBox/types.h> 23 24 typedef struct NATState *PNATState; 23 25 #endif /* VBOX */ 24 26 … … 30 32 void slirp_init(void); 31 33 #else /* VBOX */ 32 int slirp_init( void);33 void slirp_term( void);34 void slirp_link_up( void);35 void slirp_link_down( void);34 int slirp_init(PNATState *, const char *, void *); 35 void slirp_term(PNATState); 36 void slirp_link_up(PNATState); 37 void slirp_link_down(PNATState); 36 38 # if ARCH_BITS == 64 39 error fix the last remaining global variables..... 37 40 extern uint32_t g_cpvHashUsed; 38 41 extern uint32_t g_cpvHashCollisions; 39 42 extern uint64_t g_cpvHashInserts; 40 43 extern uint64_t g_cpvHashDone; 41 # endif 44 # endif 42 45 #endif /* VBOX */ 43 46 47 #ifdef VBOX 48 void slirp_select_fill(PNATState pData, int *pnfds, 49 fd_set *readfds, fd_set *writefds, fd_set *xfds); 50 51 void slirp_select_poll(PNATState pData, fd_set *readfds, fd_set *writefds, fd_set *xfds); 52 53 void slirp_input(PNATState pData, const uint8_t *pkt, int pkt_len); 54 #else /* !VBOX */ 44 55 void slirp_select_fill(int *pnfds, 45 56 fd_set *readfds, fd_set *writefds, fd_set *xfds); … … 48 59 49 60 void slirp_input(const uint8_t *pkt, int pkt_len); 61 #endif /* !VBOX */ 50 62 63 #ifdef VBOX 64 /* you must provide the following functions: */ 65 int slirp_can_output(void * pvUser); 66 void slirp_output(void * pvUser, const uint8_t *pkt, int pkt_len); 67 68 int slirp_redir(PNATState pData, int is_udp, int host_port, 69 struct in_addr guest_addr, int guest_port); 70 int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte, 71 int guest_port); 72 #else /* !VBOX */ 51 73 /* you must provide the following functions: */ 52 74 int slirp_can_output(void); … … 57 79 int slirp_add_exec(int do_pty, const char *args, int addr_low_byte, 58 80 int guest_port); 81 #endif /* !VBOX */ 59 82 83 #ifndef VBOX 60 84 extern const char *tftp_prefix; 61 85 extern char slirp_hostname[33]; 86 #endif /* !VBOX */ 62 87 63 88 #ifdef __cplusplus -
trunk/src/VBox/Devices/Network/slirp/main.h
r1 r1033 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 */ … … 12 12 #define TOWRITEMAX 512 13 13 14 #ifndef VBOX 14 15 extern struct timeval tt; 15 16 extern int link_up; … … 20 21 extern char *slirp_socket_passwd; 21 22 extern int ctty_closed; 23 #endif /* !VBOX */ 22 24 23 25 /* … … 29 31 #define TIME_DIFF(x,y) (x)-(y) < 0 ? ~0-(y)+(x) : (x)-(y) 30 32 33 #ifndef VBOX 31 34 extern char *slirp_tty; 32 35 extern char *exec_shell; … … 46 49 extern int tcp_keepintvl; 47 50 extern uint8_t client_ethaddr[6]; 51 #endif /* !VBOX */ 48 52 49 53 #define PROTO_SLIP 0x1 … … 52 56 #endif 53 57 58 #ifdef VBOX 59 void if_encap(PNATState pData, const uint8_t *ip_data, int ip_data_len); 60 #else /* !VBOX */ 54 61 void if_encap(const uint8_t *ip_data, int ip_data_len); 62 #endif /* !VBOX */ -
trunk/src/VBox/Devices/Network/slirp/mbuf.c
r531 r1033 18 18 #include <slirp.h> 19 19 20 #ifndef VBOX 20 21 struct mbuf *mbutl; 21 22 char *mclrefcnt; … … 25 26 int mbuf_max = 0; 26 27 int msize; 27 28 void 28 #endif /* !VBOX */ 29 30 void 31 #ifdef VBOX 32 m_init(PNATState pData) 33 #else /* !VBOX */ 29 34 m_init() 35 #endif /* !VBOX */ 30 36 { 31 37 m_freelist.m_next = m_freelist.m_prev = &m_freelist; 32 38 m_usedlist.m_next = m_usedlist.m_prev = &m_usedlist; 39 #ifdef VBOX 40 mbuf_alloced = 0; 41 msize_init(pData); 42 #else /* !VBOX */ 33 43 msize_init(); 34 } 35 36 void 44 #endif /* !VBOX */ 45 } 46 47 void 48 #ifdef VBOX 49 msize_init(PNATState pData) 50 #else /* !VBOX */ 37 51 msize_init() 52 #endif /* !VBOX */ 38 53 { 39 54 /* … … 41 56 * XXX if_maxlinkhdr already in mtu 42 57 */ 43 msize = (if_mtu>if_mru?if_mtu:if_mru) + 58 msize = (if_mtu>if_mru?if_mtu:if_mru) + 44 59 if_maxlinkhdr + sizeof(struct m_hdr ) + 6; 45 60 } … … 48 63 * Get an mbuf from the free list, if there are none 49 64 * malloc one 50 * 65 * 51 66 * Because fragmentation can occur if we alloc new mbufs and 52 67 * free old mbufs, we mark all mbufs above mbuf_thresh as M_DOFREE, … … 54 69 */ 55 70 struct mbuf * 71 #ifdef VBOX 72 m_get(PNATState pData) 73 #else /* !VBOX */ 56 74 m_get() 75 #endif /* !VBOX */ 57 76 { 58 77 register struct mbuf *m; 59 78 int flags = 0; 60 79 61 80 DEBUG_CALL("m_get"); 62 81 63 82 if (m_freelist.m_next == &m_freelist) { 64 83 m = (struct mbuf *)malloc(msize); … … 73 92 remque(m); 74 93 } 75 94 76 95 /* Insert it in the used list */ 77 96 insque(m,&m_usedlist); 78 97 m->m_flags = (flags | M_USEDLIST); 79 98 80 99 /* Initialise it */ 81 100 m->m_size = msize - sizeof(struct m_hdr); … … 90 109 91 110 void 111 #ifdef VBOX 112 m_free(PNATState pData, struct mbuf *m) 113 #else /* !VBOX */ 92 114 m_free(m) 93 115 struct mbuf *m; 94 { 95 116 #endif /* !VBOX */ 117 { 118 96 119 DEBUG_CALL("m_free"); 97 120 DEBUG_ARG("m = %lx", (long )m); 98 121 99 122 if(m) { 100 123 /* Remove from m_usedlist */ 101 124 if (m->m_flags & M_USEDLIST) 102 125 remque(m); 103 126 104 127 /* If it's M_EXT, free() it */ 105 128 if (m->m_flags & M_EXT) … … 126 149 */ 127 150 void 151 #ifdef VBOX 152 m_cat(PNATState pData, register struct mbuf *m, register struct mbuf *n) 153 #else /* !VBOX */ 128 154 m_cat(m, n) 129 155 register struct mbuf *m, *n; 156 #endif /* !VBOX */ 130 157 { 131 158 /* … … 134 161 if (M_FREEROOM(m) < n->m_len) 135 162 m_inc(m,m->m_size+MINCSIZE); 136 163 137 164 memcpy(m->m_data+m->m_len, n->m_data, n->m_len); 138 165 m->m_len += n->m_len; 139 166 167 #ifdef VBOX 168 m_free(pData, n); 169 #else /* !VBOX */ 140 170 m_free(n); 171 #endif /* !VBOX */ 141 172 } 142 173 … … 158 189 /* if (m->m_ext == NULL) 159 190 * return (struct mbuf *)NULL; 160 */ 191 */ 161 192 m->m_data = m->m_ext + datasize; 162 193 } else { … … 168 199 */ 169 200 memcpy(dat, m->m_dat, m->m_size); 170 201 171 202 m->m_ext = dat; 172 203 m->m_data = m->m_ext + datasize; 173 204 m->m_flags |= M_EXT; 174 205 } 175 206 176 207 m->m_size = size; 177 208 … … 222 253 */ 223 254 struct mbuf * 255 #ifdef VBOX 256 dtom(PNATState pData, void *dat) 257 #else /* !VBOX */ 224 258 dtom(dat) 225 259 void *dat; 260 #endif /* !VBOX */ 226 261 { 227 262 struct mbuf *m; 228 263 229 264 DEBUG_CALL("dtom"); 230 265 DEBUG_ARG("dat = %lx", (long )dat); … … 240 275 } 241 276 } 242 277 243 278 DEBUG_ERROR((dfd, "dtom failed")); 244 279 245 280 return (struct mbuf *)0; 246 281 } -
trunk/src/VBox/Devices/Network/slirp/mbuf.h
r1 r1033 70 70 int mh_size; /* Size of data */ 71 71 struct socket *mh_so; 72 72 73 73 caddr_t mh_data; /* Location of data */ 74 74 int mh_len; /* Amount of data in this mbuf */ 75 75 }; 76 76 77 /* 77 /* 78 78 * How much room is in the mbuf, from m_data to the end of the mbuf 79 79 */ … … 127 127 struct mbstat { 128 128 int mbs_alloced; /* Number of mbufs allocated */ 129 129 130 130 }; 131 131 … … 135 135 extern int mbuf_max; 136 136 137 #ifdef VBOX 138 void m_init _P((PNATState)); 139 void msize_init _P((PNATState)); 140 struct mbuf * m_get _P((PNATState)); 141 void m_free _P((PNATState, struct mbuf *)); 142 void m_cat _P((PNATState, register struct mbuf *, register struct mbuf *)); 143 #else /* !VBOX */ 137 144 void m_init _P((void)); 138 145 void msize_init _P((void)); … … 140 147 void m_free _P((struct mbuf *)); 141 148 void m_cat _P((register struct mbuf *, register struct mbuf *)); 149 #endif /* !VBOX */ 142 150 void m_inc _P((struct mbuf *, int)); 143 151 void m_adj _P((struct mbuf *, int)); 144 152 int m_copy _P((struct mbuf *, struct mbuf *, int, int)); 153 #ifdef VBOX 154 struct mbuf * dtom _P((PNATState, void *)); 155 #else /* !VBOX */ 145 156 struct mbuf * dtom _P((void *)); 157 #endif /* !VBOX */ 146 158 147 159 #endif -
trunk/src/VBox/Devices/Network/slirp/misc.c
r674 r1033 1 1 /* 2 2 * Copyright (c) 1995 Danny Gasparovski. 3 * 3 * 4 4 * Please read the file COPYRIGHT for the 5 5 * terms and conditions of the copyright. … … 9 9 #include <slirp.h> 10 10 11 #ifndef VBOX 11 12 u_int curtime, time_fasttimo, last_slowtimo, detach_time; 12 13 u_int detach_wait = 600000; /* 10 minutes */ 14 #endif /* !VBOX */ 13 15 14 16 #if 0 … … 32 34 lprint("X Redir: Redirecting to display %d\r\n", x_display); 33 35 } 34 36 35 37 return CFG_OK; 36 38 } … … 48 50 { 49 51 int i; 50 52 51 53 if (x_port >= 0) { 52 54 lprint("X Redir: X already being redirected.\r\n"); … … 86 88 */ 87 89 void 90 #ifdef VBOX 91 getouraddr(PNATState pData) 92 #else /* !VBOX */ 88 93 getouraddr() 94 #endif /* !VBOX */ 89 95 { 90 96 char buff[256]; 91 97 struct hostent *he = NULL; 92 98 93 99 if (gethostname(buff,256) == 0) 94 100 he = gethostbyname(buff); … … 125 131 126 132 #ifndef _MSC_VER 127 inline 133 inline 128 134 #endif 129 135 void … … 192 198 { 193 199 struct ex_list *tmp_ptr; 194 200 195 201 /* First, check if the port is "bound" */ 196 202 for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) { … … 198 204 return -1; 199 205 } 200 206 201 207 tmp_ptr = *ex_ptr; 202 208 *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list)); … … 245 251 #else 246 252 253 #ifndef VBOX 247 254 int 248 255 slirp_openpty(amaster, aslave) … … 253 260 #ifdef HAVE_GRANTPT 254 261 char *ptr; 255 262 256 263 if ((master = open("/dev/ptmx", O_RDWR)) < 0 || 257 264 grantpt(master) < 0 || … … 261 268 return -1; 262 269 } 263 270 264 271 if ((slave = open(ptr, O_RDWR)) < 0 || 265 272 ioctl(slave, I_PUSH, "ptem") < 0 || … … 270 277 return -1; 271 278 } 272 279 273 280 *amaster = master; 274 281 *aslave = slave; 275 282 return 0; 276 277 #else 278 283 284 #else 285 279 286 static char line[] = "/dev/ptyXX"; 280 287 register const char *cp1, *cp2; 281 288 282 289 for (cp1 = "pqrsPQRS"; *cp1; cp1++) { 283 290 line[8] = *cp1; … … 309 316 #endif 310 317 } 318 #endif /* !VBOX */ 311 319 312 320 /* … … 316 324 * exec the wanted program. If something (strange) happens, 317 325 * the accept() call could block us forever. 318 * 326 * 319 327 * do_pty = 0 Fork/exec inetd style 320 328 * do_pty = 1 Fork/exec using slirp.telnetd … … 322 330 */ 323 331 int 332 #ifdef VBOX 333 fork_exec(PNATState pData, struct socket *so, char *ex, int do_pty) 334 #else /* !VBOX */ 324 335 fork_exec(so, ex, do_pty) 325 336 struct socket *so; 326 337 char *ex; 327 338 int do_pty; 339 #endif /* !VBOX */ 328 340 { 329 341 int s; … … 344 356 char *curarg; 345 357 int c, i, ret; 346 358 347 359 DEBUG_CALL("fork_exec"); 348 360 DEBUG_ARG("so = %lx", (long)so); 349 361 DEBUG_ARG("ex = %lx", (long)ex); 350 362 DEBUG_ARG("do_pty = %lx", (long)do_pty); 351 363 352 364 if (do_pty == 2) { 365 #ifdef VBOX 366 AssertRelease(do_pty != 2); 367 #else /* !VBOX */ 353 368 if (slirp_openpty(&master, &s) == -1) { 354 369 lprint("Error: openpty failed: %s\n", strerror(errno)); 355 370 return 0; 356 371 } 372 #endif /* !VBOX */ 357 373 } else { 358 374 addr.sin_family = AF_INET; 359 375 addr.sin_port = 0; 360 376 addr.sin_addr.s_addr = INADDR_ANY; 361 377 362 378 if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0 || 363 379 bind(s, (struct sockaddr *)&addr, addrlen) < 0 || … … 365 381 lprint("Error: inet socket: %s\n", strerror(errno)); 366 382 closesocket(s); 367 383 368 384 return 0; 369 385 } 370 386 } 371 387 372 388 switch(fork()) { 373 389 case -1: … … 377 393 close(master); 378 394 return 0; 379 395 380 396 case 0: 381 397 /* Set the DISPLAY */ … … 399 415 } while (ret < 0 && errno == EINTR); 400 416 } 401 417 402 418 #if 0 403 419 if (x_port >= 0) { … … 410 426 #endif 411 427 } 412 #endif 428 #endif 413 429 dup2(s, 0); 414 430 dup2(s, 1); … … 416 432 for (s = 3; s <= 255; s++) 417 433 close(s); 418 434 419 435 i = 0; 420 436 bptr = strdup(ex); /* No need to free() this */ … … 434 450 argv[i++] = strdup(curarg); 435 451 } while (c); 436 452 437 453 argv[i] = 0; 438 454 execvp(argv[0], argv); 439 455 440 456 /* Ooops, failed, let's tell the user why */ 441 457 { 442 458 char buff[256]; 443 444 sprintf(buff, "Error: execvp of %s failed: %s\n", 459 460 sprintf(buff, "Error: execvp of %s failed: %s\n", 445 461 argv[0], strerror(errno)); 446 462 write(2, buff, strlen(buff)+1); … … 448 464 close(0); close(1); close(2); /* XXX */ 449 465 exit(1); 450 466 451 467 default: 452 468 if (do_pty == 2) { … … 471 487 } 472 488 fd_nonblock(so->s); 473 489 474 490 /* Append the telnet options now */ 475 491 if (so->so_m != 0 && do_pty == 1) { 492 #ifdef VBOX 493 sbappend(pData, so, so->so_m); 494 #else /* !VBOX */ 476 495 sbappend(so, so->so_m); 496 #endif /* !VBOX */ 477 497 so->so_m = 0; 478 498 } 479 499 480 500 return 1; 481 501 } … … 489 509 { 490 510 char *bptr; 491 511 492 512 bptr = (char *)malloc(strlen(str)+1); 493 513 strcpy(bptr, str); 494 514 495 515 return bptr; 496 516 } … … 508 528 struct sockaddr_in sock_in; 509 529 char buff[256]; 510 530 511 531 ret = -1; 512 532 if (slirp_socket_passwd) { … … 538 558 slirp_exit(0); 539 559 } 540 541 560 561 542 562 void 543 563 snooze() … … 545 565 sigset_t s; 546 566 int i; 547 567 548 568 /* Don't need our data anymore */ 549 569 /* XXX This makes SunOS barf */ 550 570 /* brk(0); */ 551 571 552 572 /* Close all fd's */ 553 573 for (i = 255; i >= 0; i--) 554 574 close(i); 555 575 556 576 signal(SIGQUIT, slirp_exit); 557 577 signal(SIGHUP, snooze_hup); 558 578 sigemptyset(&s); 559 579 560 580 /* Wait for any signal */ 561 581 sigsuspend(&s); 562 582 563 583 /* Just in case ... */ 564 584 exit(255); … … 573 593 fd_set readfds; 574 594 struct ttys *ttyp; 575 595 576 596 /* Don't need our data anymore */ 577 597 /* XXX This makes SunOS barf */ 578 598 /* brk(0); */ 579 599 580 600 signal(SIGQUIT, slirp_exit); 581 601 signal(SIGHUP, slirp_exit); 582 602 signal(SIGINT, slirp_exit); 583 603 signal(SIGTERM, slirp_exit); 584 604 585 605 /* Fudge to get term_raw and term_restore to work */ 586 606 if (NULL == (ttyp = tty_attach (0, slirp_tty))) { … … 591 611 ttyp->flags |= TTY_CTTY; 592 612 term_raw(ttyp); 593 613 594 614 while (1) { 595 615 FD_ZERO(&readfds); 596 616 597 617 FD_SET(0, &readfds); 598 618 FD_SET(s, &readfds); 599 619 600 620 n = select(s+1, &readfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0); 601 621 602 622 if (n <= 0) 603 623 slirp_exit(0); 604 624 605 625 if (FD_ISSET(0, &readfds)) { 606 626 n = read(0, buf, 8192); … … 611 631 slirp_exit(0); 612 632 } 613 633 614 634 if (FD_ISSET(s, &readfds)) { 615 635 n = read(s, buf, 8192); … … 621 641 } 622 642 } 623 643 624 644 /* Just in case.... */ 625 645 exit(1); … … 639 659 { 640 660 va_list args; 641 661 642 662 #ifdef __STDC__ 643 663 va_start(args, format); … … 656 676 int deltar = lprint_sb->sb_rptr - lprint_sb->sb_data; 657 677 int deltap = lprint_ptr - lprint_sb->sb_data; 658 678 659 679 lprint_sb->sb_data = (char *)realloc(lprint_sb->sb_data, 660 680 lprint_sb->sb_datalen + TCP_SNDSPACE); 661 681 662 682 /* Adjust all values */ 663 683 lprint_sb->sb_wptr = lprint_sb->sb_data + deltaw; 664 684 lprint_sb->sb_rptr = lprint_sb->sb_data + deltar; 665 685 lprint_ptr = lprint_sb->sb_data + deltap; 666 686 667 687 lprint_sb->sb_datalen += TCP_SNDSPACE; 668 688 } 669 689 } 670 #endif 690 #endif 671 691 if (lprint_print) 672 692 lprint_ptr += (*lprint_print)(*lprint_arg, format, args); 673 693 674 694 /* Check if they want output to be logged to file as well */ 675 695 if (lfd) { 676 /* 696 /* 677 697 * Remove \r's 678 698 * otherwise you'll get ^M all over the file … … 680 700 int len = strlen(format); 681 701 char *bptr1, *bptr2; 682 702 683 703 bptr1 = bptr2 = strdup(format); 684 704 685 705 while (len--) { 686 706 if (*bptr1 == '\r') … … 705 725 struct emu_t *emup; 706 726 struct socket *so; 707 727 708 728 if (sscanf(buff, "%256s %256s", buff2, buff1) != 2) { 709 729 lprint("Error: Bad arguments\r\n"); 710 730 return; 711 731 } 712 732 713 733 if (sscanf(buff1, "%d:%d", &lport, &fport) != 2) { 714 734 lport = 0; … … 718 738 } 719 739 } 720 740 721 741 if (sscanf(buff2, "%128[^:]:%128s", buff1, buff3) != 2) { 722 742 buff3 = 0; … … 726 746 } 727 747 } 728 748 729 749 if (buff3) { 730 750 if (strcmp(buff3, "lowdelay") == 0) … … 737 757 } 738 758 } 739 759 740 760 if (strcmp(buff1, "ftp") == 0) 741 761 emu = EMU_FTP; … … 748 768 return; 749 769 } 750 770 751 771 /* First, check that it isn't already emulated */ 752 772 for (emup = tcpemu; emup; emup = emup->next) { … … 756 776 } 757 777 } 758 778 759 779 /* link it */ 760 780 emup = (struct emu_t *)malloc(sizeof (struct emu_t)); … … 765 785 emup->next = tcpemu; 766 786 tcpemu = emup; 767 787 768 788 /* And finally, mark all current sessions, if any, as being emulated */ 769 789 for (so = tcb.so_next; so != &tcb; so = so->so_next) { … … 776 796 } 777 797 } 778 798 779 799 lprint("Adding emulation for %s to port %d/%d\r\n", buff1, emup->lport, emup->fport); 780 800 } … … 829 849 struct timeval t; 830 850 fd_set fdset; 831 851 832 852 FD_ZERO(&fdset); 833 853 834 854 t.tv_sec = 0; 835 855 t.tv_usec = usec * 1000; 836 856 837 857 select(0, &fdset, &fdset, &fdset, &t); 838 858 } … … 848 868 #ifdef FIONBIO 849 869 int opt = 1; 850 870 851 871 ioctlsocket(fd, FIONBIO, &opt); 852 872 #else 853 873 int opt; 854 874 855 875 opt = fcntl(fd, F_GETFL, 0); 856 876 opt |= O_NONBLOCK; … … 865 885 #ifdef FIONBIO 866 886 int opt = 0; 867 887 868 888 ioctlsocket(fd, FIONBIO, &opt); 869 889 #else 870 890 int opt; 871 891 872 892 opt = fcntl(fd, F_GETFL, 0); 873 893 opt &= ~O_NONBLOCK; … … 893 913 int s; 894 914 char buff[256]; 895 915 896 916 DEBUG_CALL("rsh_exec"); 897 917 DEBUG_ARG("so = %lx", (long)so); 898 918 899 919 if (pipe(fd)<0) { 900 920 lprint("Error: pipe failed: %s\n", strerror(errno)); … … 917 937 } 918 938 #endif 919 939 920 940 switch(fork()) { 921 941 case -1: … … 926 946 close(fd0[1]); 927 947 return 0; 928 948 929 949 case 0: 930 950 close(fd[0]); 931 951 close(fd0[0]); 932 952 933 953 /* Set the DISPLAY */ 934 954 if (x_port >= 0) { … … 941 961 #endif 942 962 } 943 963 944 964 dup2(fd0[1], 0); 945 965 dup2(fd0[1], 1); … … 947 967 for (s = 3; s <= 255; s++) 948 968 close(s); 949 969 950 970 execlp("rsh","rsh","-l", user, host, args, NULL); 951 971 952 972 /* Ooops, failed, let's tell the user why */ 953 954 sprintf(buff, "Error: execlp of %s failed: %s\n", 973 974 sprintf(buff, "Error: execlp of %s failed: %s\n", 955 975 "rsh", strerror(errno)); 956 976 write(2, buff, strlen(buff)+1); 957 977 close(0); close(1); close(2); /* XXX */ 958 978 exit(1); 959 979 960 980 default: 961 981 close(fd[1]); … … 963 983 ns->s=fd[0]; 964 984 so->s=fd0[0]; 965 985 966 986 return 1; 967 987 } -
trunk/src/VBox/Devices/Network/slirp/misc.h
r1 r1033 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 */ … … 18 18 19 19 extern struct ex_list *exec_list; 20 #ifndef VBOX 20 21 extern u_int curtime, time_fasttimo, last_slowtimo, detach_time, detach_wait; 22 #endif /* !VBOX */ 21 23 22 24 #ifndef VBOX … … 72 74 int show_x _P((char *, struct socket *)); 73 75 void redir_x _P((u_int32_t, int, int, int)); 76 #ifdef VBOX 77 void getouraddr _P((PNATState)); 78 #else /* !VBOX */ 74 79 void getouraddr _P((void)); 80 #endif /* !VBOX */ 75 81 inline void slirp_insque _P((void *, void *)); 76 82 inline void slirp_remque _P((void *)); 77 83 int add_exec _P((struct ex_list **, int, char *, int, int)); 78 84 int slirp_openpty _P((int *, int *)); 85 #ifdef VBOX 86 int fork_exec _P((PNATState, struct socket *, char *, int)); 87 #else /* !VBOX */ 79 88 int fork_exec _P((struct socket *, char *, int)); 89 #endif /* !VBOX */ 80 90 void snooze_hup _P((int)); 81 91 void snooze _P((void)); -
trunk/src/VBox/Devices/Network/slirp/sbuf.c
r1 r1033 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 */ … … 10 10 /* Done as a macro in socket.h */ 11 11 /* int 12 * sbspace(struct sockbuff *sb) 12 * sbspace(struct sockbuff *sb) 13 13 * { 14 14 * return SB_DATALEN - sb->sb_cc; … … 26 26 sbdrop(sb, num) 27 27 struct sbuf *sb; 28 int num; 29 { 30 /* 28 int num; 29 { 30 /* 31 31 * We can only drop how much we have 32 * This should never succeed 32 * This should never succeed 33 33 */ 34 34 if(num > sb->sb_cc) … … 38 38 if(sb->sb_rptr >= sb->sb_data + sb->sb_datalen) 39 39 sb->sb_rptr -= sb->sb_datalen; 40 40 41 41 } 42 42 … … 73 73 */ 74 74 void 75 #ifdef VBOX 76 sbappend(PNATState pData, struct socket *so, struct mbuf *m) 77 #else /* !VBOX */ 75 78 sbappend(so, m) 76 79 struct socket *so; 77 80 struct mbuf *m; 81 #endif /* !VBOX */ 78 82 { 79 83 int ret = 0; 80 84 81 85 DEBUG_CALL("sbappend"); 82 86 DEBUG_ARG("so = %lx", (long)so); 83 87 DEBUG_ARG("m = %lx", (long)m); 84 88 DEBUG_ARG("m->m_len = %d", m->m_len); 85 89 86 90 /* Shouldn't happen, but... e.g. foreign host closes connection */ 87 91 if (m->m_len <= 0) { 92 #ifdef VBOX 93 m_free(pData, m); 94 #else /* !VBOX */ 88 95 m_free(m); 96 #endif /* !VBOX */ 89 97 return; 90 98 } 91 99 92 100 /* 93 101 * If there is urgent data, call sosendoob … … 97 105 if (so->so_urgc) { 98 106 sbappendsb(&so->so_rcv, m); 107 #ifdef VBOX 108 m_free(pData, m); 109 #else /* !VBOX */ 99 110 m_free(m); 111 #endif /* !VBOX */ 100 112 sosendoob(so); 101 113 return; 102 114 } 103 115 104 116 /* 105 117 * We only write if there's nothing in the buffer, … … 108 120 if (!so->so_rcv.sb_cc) 109 121 ret = send(so->s, m->m_data, m->m_len, 0); 110 122 111 123 if (ret <= 0) { 112 /* 124 /* 113 125 * Nothing was written 114 126 * It's possible that the socket has closed, but … … 127 139 } /* else */ 128 140 /* Whatever happened, we free the mbuf */ 141 #ifdef VBOX 142 m_free(pData, m); 143 #else /* !VBOX */ 129 144 m_free(m); 145 #endif /* !VBOX */ 130 146 } 131 147 … … 140 156 { 141 157 int len, n, nn; 142 158 143 159 len = m->m_len; 144 160 … … 181 197 { 182 198 char *from; 183 199 184 200 from = sb->sb_rptr + off; 185 201 if (from >= sb->sb_data + sb->sb_datalen) … … 199 215 } 200 216 } 201 217 -
trunk/src/VBox/Devices/Network/slirp/sbuf.h
r1 r1033 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 */ … … 25 25 void sbdrop _P((struct sbuf *, int)); 26 26 void sbreserve _P((struct sbuf *, int)); 27 #ifdef VBOX 28 void sbappend _P((PNATState, struct socket *, struct mbuf *)); 29 #else /* !VBOX */ 27 30 void sbappend _P((struct socket *, struct mbuf *)); 31 #endif /* !VBOX */ 28 32 void sbappendsb _P((struct sbuf *, struct mbuf *)); 29 33 void sbcopy _P((struct sbuf *, int, int, char *)); -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r926 r1033 8 8 #endif 9 9 10 #ifndef VBOX 10 11 /* host address */ 11 12 struct in_addr our_addr; … … 19 20 /* virtual address alias for host */ 20 21 struct in_addr alias_addr; 21 22 #endif /* !VBOX */ 23 24 #ifdef VBOX 25 static const uint8_t special_ethaddr[6] = { 26 #else /* !VBOX */ 22 27 const uint8_t special_ethaddr[6] = { 28 #endif /* !VBOX */ 23 29 0x52, 0x54, 0x00, 0x12, 0x35, 0x00 24 30 }; 25 31 32 #ifndef VBOX 26 33 uint8_t client_ethaddr[6]; 27 34 … … 31 38 FILE *lfd; 32 39 struct ex_list *exec_list; 40 #endif /* !VBOX */ 33 41 34 42 #ifndef VBOX 35 43 /* XXX: suppress those select globals */ 36 44 fd_set *global_readfds, *global_writefds, *global_xfds; 37 #endif /* !VBOX */38 45 39 46 char slirp_hostname[33]; 47 #endif /* !VBOX */ 40 48 41 49 #ifdef _WIN32 … … 106 114 #else 107 115 116 #ifdef VBOX 117 static int get_dns_addr(PNATState pData, struct in_addr *pdns_addr) 118 #else /* !VBOX */ 108 119 static int get_dns_addr(struct in_addr *pdns_addr) 120 #endif /* !VBOX */ 109 121 { 110 122 char buff[512]; … … 193 205 #else /* VBOX */ 194 206 /** Number of slirp users. Used for making sure init and term are only executed once. */ 195 static int g_cUsers = 0; 196 int slirp_init(void) 197 { 198 if (g_cUsers != 0) { 199 g_cUsers++; 200 return VINF_SUCCESS; 201 } 207 int slirp_init(PNATState *ppData, const char *pszNetAddr, void *pvUser) 208 { 209 PNATState pData = malloc(sizeof(NATState)); 210 *ppData = pData; 211 if (!pData) 212 return VERR_NO_MEMORY; 213 memset(pData, '\0', sizeof(NATState)); 214 pData->pvUser = pvUser; 202 215 #endif /* VBOX */ 203 216 … … 217 230 link_up = 1; 218 231 232 #ifdef VBOX 233 if_init(pData); 234 ip_init(pData); 235 #else /* !VBOX */ 219 236 if_init(); 220 237 ip_init(); 238 #endif /* !VBOX */ 221 239 222 240 /* Initialise mbufs *after* setting the MTU */ 241 #ifdef VBOX 242 m_init(pData); 243 #else /* !VBOX */ 223 244 m_init(); 245 #endif /* !VBOX */ 224 246 225 247 /* set default addresses */ 226 248 inet_aton("127.0.0.1", &loopback_addr); 227 249 250 #ifdef VBOX 251 if (get_dns_addr(pData, &dns_addr) < 0) { 252 #else /* !VBOX */ 228 253 if (get_dns_addr(&dns_addr) < 0) { 254 #endif /* !VBOX */ 229 255 #ifndef VBOX 230 256 dns_addr = loopback_addr; … … 235 261 } 236 262 263 #ifdef VBOX 264 inet_aton(pszNetAddr, &special_addr); 265 #else /* !VBOX */ 237 266 inet_aton(CTL_SPECIAL, &special_addr); 267 #endif /* !VBOX */ 238 268 alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS); 269 #ifdef VBOX 270 getouraddr(pData); 271 return VINF_SUCCESS; 272 #else /* !VBOX */ 239 273 getouraddr(); 240 #ifdef VBOX 241 g_cUsers++; 242 return VINF_SUCCESS; 243 #endif 274 #endif /* !VBOX */ 244 275 } 245 276 … … 248 279 * Marks the link as up, making it possible to establish new connections. 249 280 */ 250 void slirp_link_up( void)281 void slirp_link_up(PNATState pData) 251 282 { 252 283 link_up = 1; … … 256 287 * Marks the link as down and cleans up the current connections. 257 288 */ 258 void slirp_link_down( void)289 void slirp_link_down(PNATState pData) 259 290 { 260 291 struct socket *so; … … 263 294 { 264 295 if (so->so_state & SS_NOFDREF || so->s == -1) 265 sofree( so);296 sofree(pData, so); 266 297 else 267 tcp_drop( sototcpcb(so), 0);298 tcp_drop(pData, sototcpcb(so), 0); 268 299 } 269 300 270 301 while ((so = udb.so_next) != &udb) 271 udp_detach( so);302 udp_detach(pData, so); 272 303 273 304 link_up = 0; … … 277 308 * Terminates the slirp component. 278 309 */ 279 void slirp_term(void) 280 { 281 if (--g_cUsers > 0) 282 return; 283 slirp_link_down(); 310 void slirp_term(PNATState pData) 311 { 312 slirp_link_down(pData); 284 313 #ifdef WIN32 285 314 WSACleanup(); … … 290 319 "--------------\n" 291 320 "\n")); 292 ipstats( );293 tcpstats( );294 udpstats( );295 icmpstats( );296 mbufstats( );297 sockstats( );321 ipstats(pData); 322 tcpstats(pData); 323 udpstats(pData); 324 icmpstats(pData); 325 mbufstats(pData); 326 sockstats(pData); 298 327 Log(("\n" 299 328 "\n" 300 329 "\n")); 301 330 #endif 331 free(pData); 302 332 } 303 333 #endif /* VBOX */ … … 312 342 */ 313 343 #ifdef _WIN32 344 #ifdef VBOX 345 static void updtime(PNATState pData) 346 #else /* !VBOX */ 314 347 static void updtime(void) 348 #endif /* !VBOX */ 315 349 { 316 350 struct _timeb tb; … … 321 355 } 322 356 #else 357 #ifdef VBOX 358 static void updtime(PNATState pData) 359 #else /* !VBOX */ 323 360 static void updtime(void) 361 #endif /* !VBOX */ 324 362 { 325 363 gettimeofday(&tt, 0); … … 333 371 #endif 334 372 373 #ifdef VBOX 374 void slirp_select_fill(PNATState pData, int *pnfds, 375 fd_set *readfds, fd_set *writefds, fd_set *xfds) 376 #else /* !VBOX */ 335 377 void slirp_select_fill(int *pnfds, 336 378 fd_set *readfds, fd_set *writefds, fd_set *xfds) 379 #endif /* !VBOX */ 337 380 { 338 381 struct socket *so, *so_next; … … 426 469 if (so->so_expire) { 427 470 if (so->so_expire <= curtime) { 471 #ifdef VBOX 472 udp_detach(pData, so); 473 #else /* !VBOX */ 428 474 udp_detach(so); 475 #endif /* !VBOX */ 429 476 continue; 430 477 } else … … 485 532 } 486 533 534 #ifdef VBOX 535 void slirp_select_poll(PNATState pData, fd_set *readfds, fd_set *writefds, fd_set *xfds) 536 #else /* !VBOX */ 487 537 void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds) 538 #endif /* !VBOX */ 488 539 { 489 540 struct socket *so, *so_next; … … 497 548 498 549 /* Update time */ 550 #ifdef VBOX 551 updtime(pData); 552 #else /* !VBOX */ 499 553 updtime(); 554 #endif /* !VBOX */ 500 555 501 556 /* … … 504 559 if (link_up) { 505 560 if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) { 561 #ifdef VBOX 562 tcp_fasttimo(pData); 563 #else /* !VBOX */ 506 564 tcp_fasttimo(); 565 #endif /* !VBOX */ 507 566 time_fasttimo = 0; 508 567 } 509 568 if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) { 569 #ifdef VBOX 570 ip_slowtimo(pData); 571 tcp_slowtimo(pData); 572 #else /* !VBOX */ 510 573 ip_slowtimo(); 511 574 tcp_slowtimo(); 575 #endif /* !VBOX */ 512 576 last_slowtimo = curtime; 513 577 } … … 537 601 */ 538 602 if (FD_ISSET(so->s, xfds)) 603 #ifdef VBOX 604 sorecvoob(pData, so); 605 #else /* !VBOX */ 539 606 sorecvoob(so); 607 #endif /* !VBOX */ 540 608 /* 541 609 * Check sockets for reading … … 546 614 */ 547 615 if (so->so_state & SS_FACCEPTCONN) { 616 #ifdef VBOX 617 tcp_connect(pData, so); 618 #else /* !VBOX */ 548 619 tcp_connect(so); 620 #endif /* !VBOX */ 549 621 continue; 550 622 } /* else */ 623 #ifdef VBOX 624 ret = soread(pData, so); 625 #else /* !VBOX */ 551 626 ret = soread(so); 627 #endif /* !VBOX */ 552 628 553 629 /* Output it if we read something */ 554 630 if (ret > 0) 631 #ifdef VBOX 632 tcp_output(pData, sototcpcb(so)); 633 #else /* !VBOX */ 555 634 tcp_output(sototcpcb(so)); 635 #endif /* !VBOX */ 556 636 } 557 637 … … 582 662 * Continue tcp_input 583 663 */ 664 #ifdef VBOX 665 tcp_input(pData, (struct mbuf *)NULL, sizeof(struct ip), so); 666 #else /* !VBOX */ 584 667 tcp_input((struct mbuf *)NULL, sizeof(struct ip), so); 668 #endif /* !VBOX */ 585 669 /* continue; */ 586 670 } else 671 #ifdef VBOX 672 ret = sowrite(pData, so); 673 #else /* !VBOX */ 587 674 ret = sowrite(so); 675 #endif /* !VBOX */ 588 676 /* 589 677 * XXXXX If we wrote something (a lot), there … … 639 727 640 728 if (so->s != -1 && FD_ISSET(so->s, readfds)) { 729 #ifdef VBOX 730 sorecvfrom(pData, so); 731 #else /* !VBOX */ 641 732 sorecvfrom(so); 733 #endif /* !VBOX */ 642 734 } 643 735 } … … 648 740 */ 649 741 if (if_queued && link_up) 742 #ifdef VBOX 743 if_start(pData); 744 #else /* !VBOX */ 650 745 if_start(); 746 #endif /* !VBOX */ 651 747 652 748 #ifndef VBOX … … 697 793 #ifdef VBOX 698 794 static 699 #endif 795 void arp_input(PNATState pData, const uint8_t *pkt, int pkt_len) 796 #else /* !VBOX */ 700 797 void arp_input(const uint8_t *pkt, int pkt_len) 798 #endif /* !VBOX */ 701 799 { 702 800 struct ethhdr *eh = (struct ethhdr *)pkt; … … 738 836 memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN); 739 837 memcpy(rah->ar_tip, ah->ar_sip, 4); 838 #ifdef VBOX 839 slirp_output(pData->pvUser, arp_reply, sizeof(arp_reply)); 840 #else /* !VBOX */ 740 841 slirp_output(arp_reply, sizeof(arp_reply)); 842 #endif /* !VBOX */ 741 843 } 742 844 break; … … 746 848 } 747 849 850 #ifdef VBOX 851 void slirp_input(PNATState pData, const uint8_t *pkt, int pkt_len) 852 #else /* !VBOX */ 748 853 void slirp_input(const uint8_t *pkt, int pkt_len) 854 #endif /* !VBOX */ 749 855 { 750 856 struct mbuf *m; … … 757 863 switch(proto) { 758 864 case ETH_P_ARP: 865 #ifdef VBOX 866 arp_input(pData, pkt, pkt_len); 867 #else /* !VBOX */ 759 868 arp_input(pkt, pkt_len); 869 #endif /* !VBOX */ 760 870 break; 761 871 case ETH_P_IP: 872 #ifdef VBOX 873 m = m_get(pData); 874 #else /* !VBOX */ 762 875 m = m_get(); 876 #endif /* !VBOX */ 763 877 if (!m) 764 878 return; … … 770 884 m->m_len -= 2 + ETH_HLEN; 771 885 886 #ifdef VBOX 887 ip_input(pData, m); 888 #else /* !VBOX */ 772 889 ip_input(m); 890 #endif /* !VBOX */ 773 891 break; 774 892 default: … … 778 896 779 897 /* output the IP packet to the ethernet device */ 898 #ifdef VBOX 899 void if_encap(PNATState pData, const uint8_t *ip_data, int ip_data_len) 900 #else /* !VBOX */ 780 901 void if_encap(const uint8_t *ip_data, int ip_data_len) 902 #endif /* !VBOX */ 781 903 { 782 904 uint8_t buf[1600]; … … 792 914 eh->h_proto = htons(ETH_P_IP); 793 915 memcpy(buf + sizeof(struct ethhdr), ip_data, ip_data_len); 916 #ifdef VBOX 917 slirp_output(pData->pvUser, buf, ip_data_len + ETH_HLEN); 918 #else /* !VBOX */ 794 919 slirp_output(buf, ip_data_len + ETH_HLEN); 795 } 796 797 int slirp_redir(int is_udp, int host_port, 920 #endif /* !VBOX */ 921 } 922 923 int slirp_redir(PNATState pData, int is_udp, int host_port, 798 924 struct in_addr guest_addr, int guest_port) 799 925 { 800 926 if (is_udp) { 927 #ifdef VBOX 928 if (!udp_listen(pData, htons(host_port), guest_addr.s_addr, 929 htons(guest_port), 0)) 930 #else /* !VBOX */ 801 931 if (!udp_listen(htons(host_port), guest_addr.s_addr, 802 932 htons(guest_port), 0)) 933 #endif /* !VBOX */ 803 934 return -1; 804 935 } else { 936 #ifdef VBOX 937 if (!solisten(pData, htons(host_port), guest_addr.s_addr, 938 htons(guest_port), 0)) 939 #else /* !VBOX */ 805 940 if (!solisten(htons(host_port), guest_addr.s_addr, 806 941 htons(guest_port), 0)) 942 #endif /* !VBOX */ 807 943 return -1; 808 944 } … … 810 946 } 811 947 948 #ifdef VBOX 949 int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte, 950 int guest_port) 951 #else /* !VBOX */ 812 952 int slirp_add_exec(int do_pty, const char *args, int addr_low_byte, 813 953 int guest_port) 954 #endif /* !VBOX */ 814 955 { 815 956 return add_exec(&exec_list, do_pty, (char *)args, -
trunk/src/VBox/Devices/Network/slirp/slirp.h
r1023 r1033 37 37 # include <io.h> 38 38 # endif 39 # include <iprt/assert.h> 39 40 # include <iprt/string.h> 40 41 # include <VBox/types.h> … … 236 237 #include <sys/stropts.h> 237 238 #endif 239 240 #ifdef VBOX 241 #include "libslirp.h" 242 #endif /* !VBOX */ 238 243 239 244 #include "debug.h" … … 260 265 #include "bootp.h" 261 266 #include "tftp.h" 267 #ifndef VBOX 262 268 #include "libslirp.h" 263 269 #endif /* !VBOX */ 270 271 #ifdef VBOX 272 #include "slirp_state.h" 273 #endif /* VBOX */ 274 275 #ifndef VBOX 264 276 extern struct ttys *ttys_unit[MAX_INTERFACES]; 277 #endif /* !VBOX */ 265 278 266 279 #ifndef NULL … … 268 281 #endif 269 282 283 #ifdef VBOX 284 void if_start _P((PNATState)); 285 #else /* !VBOX */ 270 286 #ifndef FULL_BOLT 271 287 void if_start _P((void)); … … 273 289 void if_start _P((struct ttys *)); 274 290 #endif 291 #endif /* !VBOX */ 275 292 276 293 #ifdef BAD_SPRINTF … … 330 347 inline void insque_32 _P((void *, void *)); 331 348 inline void remque_32 _P((void *)); 332 # endif 349 # endif 333 350 #endif 334 351 … … 343 360 344 361 /* if.c */ 362 #ifdef VBOX 363 void if_init _P((PNATState)); 364 void if_output _P((PNATState, struct socket *, struct mbuf *)); 365 #else /* VBOX */ 345 366 void if_init _P((void)); 346 367 void if_output _P((struct socket *, struct mbuf *)); 368 #endif /* VBOX */ 347 369 348 370 /* ip_input.c */ 371 #ifdef VBOX 372 void ip_init _P((PNATState)); 373 void ip_input _P((PNATState, struct mbuf *)); 374 struct ip * ip_reass _P((PNATState, register struct ipasfrag *, register struct ipq_t *)); 375 void ip_freef _P((PNATState, struct ipq_t *)); 376 #else /* !VBOX */ 349 377 void ip_init _P((void)); 350 378 void ip_input _P((struct mbuf *)); 351 379 struct ip * ip_reass _P((register struct ipasfrag *, register struct ipq *)); 352 380 void ip_freef _P((struct ipq *)); 381 #endif /* !VBOX */ 353 382 void ip_enq _P((register struct ipasfrag *, register struct ipasfrag *)); 354 383 void ip_deq _P((register struct ipasfrag *)); 384 #ifdef VBOX 385 void ip_slowtimo _P((PNATState)); 386 #else /* !VBOX */ 355 387 void ip_slowtimo _P((void)); 388 #endif /* !VBOX */ 356 389 void ip_stripoptions _P((register struct mbuf *, struct mbuf *)); 357 390 358 391 /* ip_output.c */ 392 #ifdef VBOX 393 int ip_output _P((PNATState, struct socket *, struct mbuf *)); 394 #else /* !VBOX */ 359 395 int ip_output _P((struct socket *, struct mbuf *)); 396 #endif /* !VBOX */ 360 397 361 398 /* tcp_input.c */ 399 #ifdef VBOX 400 int tcp_reass _P((PNATState, register struct tcpcb *, register struct tcpiphdr *, struct mbuf *)); 401 void tcp_input _P((PNATState, register struct mbuf *, int, struct socket *)); 402 void tcp_dooptions _P((PNATState, struct tcpcb *, u_char *, int, struct tcpiphdr *)); 403 void tcp_xmit_timer _P((PNATState, register struct tcpcb *, int)); 404 int tcp_mss _P((PNATState, register struct tcpcb *, u_int)); 405 #else /* !VBOX */ 362 406 int tcp_reass _P((register struct tcpcb *, register struct tcpiphdr *, struct mbuf *)); 363 407 void tcp_input _P((register struct mbuf *, int, struct socket *)); … … 365 409 void tcp_xmit_timer _P((register struct tcpcb *, int)); 366 410 int tcp_mss _P((register struct tcpcb *, u_int)); 411 #endif /* !VBOX */ 367 412 368 413 /* tcp_output.c */ 414 #ifdef VBOX 415 int tcp_output _P((PNATState, register struct tcpcb *)); 416 #else /* !VBOX */ 369 417 int tcp_output _P((register struct tcpcb *)); 418 #endif /* !VBOX */ 370 419 void tcp_setpersist _P((register struct tcpcb *)); 371 420 372 421 /* tcp_subr.c */ 422 #ifdef VBOX 423 void tcp_init _P((PNATState)); 424 #else /* !VBOX */ 373 425 void tcp_init _P((void)); 426 #endif /* !VBOX */ 374 427 void tcp_template _P((struct tcpcb *)); 428 #ifdef VBOX 429 void tcp_respond _P((PNATState, struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int)); 430 #else /* !VBOX */ 375 431 void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int)); 432 #endif /* !VBOX */ 376 433 struct tcpcb * tcp_newtcpcb _P((struct socket *)); 434 #ifdef VBOX 435 struct tcpcb * tcp_close _P((PNATState, register struct tcpcb *)); 436 #else /* !VBOX */ 377 437 struct tcpcb * tcp_close _P((register struct tcpcb *)); 438 #endif /* !VBOX */ 378 439 void tcp_drain _P((void)); 440 #ifdef VBOX 441 void tcp_sockclosed _P((PNATState, struct tcpcb *)); 442 int tcp_fconnect _P((PNATState, struct socket *)); 443 void tcp_connect _P((PNATState, struct socket *)); 444 int tcp_attach _P((PNATState, struct socket *)); 445 #else /* !VBOX */ 379 446 void tcp_sockclosed _P((struct tcpcb *)); 380 447 int tcp_fconnect _P((struct socket *)); 381 448 void tcp_connect _P((struct socket *)); 382 449 int tcp_attach _P((struct socket *)); 450 #endif /* !VBOX */ 383 451 u_int8_t tcp_tos _P((struct socket *)); 452 #ifdef VBOX 453 int tcp_emu _P((PNATState, struct socket *, struct mbuf *)); 454 int tcp_ctl _P((PNATState, struct socket *)); 455 struct tcpcb *tcp_drop(PNATState, struct tcpcb *tp, int err); 456 #else /* !VBOX */ 384 457 int tcp_emu _P((struct socket *, struct mbuf *)); 385 458 int tcp_ctl _P((struct socket *)); 386 459 struct tcpcb *tcp_drop(struct tcpcb *tp, int err); 460 #endif /* !VBOX */ 387 461 388 462 #ifdef USE_PPP -
trunk/src/VBox/Devices/Network/slirp/socket.c
r926 r1033 68 68 */ 69 69 void 70 #ifdef VBOX 71 sofree(PNATState pData, struct socket *so) 72 #else /* !VBOX */ 70 73 sofree(so) 71 74 struct socket *so; 75 #endif /* !VBOX */ 72 76 { 73 77 if (so->so_emu==EMU_RSH && so->extra) { 78 #ifdef VBOX 79 sofree(pData, so->extra); 80 #else /* !VBOX */ 74 81 sofree(so->extra); 82 #endif /* !VBOX */ 75 83 so->extra=NULL; 76 84 } … … 80 88 udp_last_so = &udb; 81 89 90 #ifdef VBOX 91 m_free(pData, so->so_m); 92 #else /* !VBOX */ 82 93 m_free(so->so_m); 94 #endif /* !VBOX */ 83 95 84 96 if(so->so_next && so->so_prev) … … 94 106 */ 95 107 int 108 #ifdef VBOX 109 soread(PNATState pData, struct socket *so) 110 #else /* !VBOX */ 96 111 soread(so) 97 112 struct socket *so; 113 #endif /* !VBOX */ 98 114 { 99 115 int n, nn, lss, total; … … 164 180 DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno))); 165 181 sofcantrcvmore(so); 182 #ifdef VBOX 183 tcp_sockclosed(pData, sototcpcb(so)); 184 #else /* !VBOX */ 166 185 tcp_sockclosed(sototcpcb(so)); 186 #endif /* !VBOX */ 167 187 return -1; 168 188 } … … 205 225 */ 206 226 void 227 #ifdef VBOX 228 sorecvoob(PNATState pData, struct socket *so) 229 #else /* !VBOX */ 207 230 sorecvoob(so) 208 231 struct socket *so; 232 #endif /* !VBOX */ 209 233 { 210 234 struct tcpcb *tp = sototcpcb(so); … … 221 245 * urgent data. 222 246 */ 247 #ifdef VBOX 248 soread(pData, so); 249 #else /* !VBOX */ 223 250 soread(so); 251 #endif /* !VBOX */ 224 252 tp->snd_up = tp->snd_una + so->so_snd.sb_cc; 225 253 tp->t_force = 1; 254 #ifdef VBOX 255 tcp_output(pData, tp); 256 #else /* !VBOX */ 226 257 tcp_output(tp); 258 #endif /* !VBOX */ 227 259 tp->t_force = 0; 228 260 } … … 292 324 */ 293 325 int 326 #ifdef VBOX 327 sowrite(PNATState pData, struct socket *so) 328 #else /* !VBOX */ 294 329 sowrite(so) 295 330 struct socket *so; 331 #endif /* !VBOX */ 296 332 { 297 333 int n,nn; … … 351 387 so->so_state, errno)); 352 388 sofcantsendmore(so); 389 #ifdef VBOX 390 tcp_sockclosed(pData, sototcpcb(so)); 391 #else /* !VBOX */ 353 392 tcp_sockclosed(sototcpcb(so)); 393 #endif /* !VBOX */ 354 394 return -1; 355 395 } … … 385 425 */ 386 426 void 427 #ifdef VBOX 428 sorecvfrom(PNATState pData, struct socket *so) 429 #else /* !VBOX */ 387 430 sorecvfrom(so) 388 431 struct socket *so; 432 #endif /* !VBOX */ 389 433 { 390 434 struct sockaddr_in addr; … … 414 458 DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n", 415 459 errno,strerror(errno))); 460 #ifdef VBOX 461 icmp_error(pData, so->so_m, ICMP_UNREACH,code, 0,strerror(errno)); 462 #else /* !VBOX */ 416 463 icmp_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno)); 464 #endif /* !VBOX */ 417 465 } else { 466 #ifdef VBOX 467 icmp_reflect(pData, so->so_m); 468 #else /* !VBOX */ 418 469 icmp_reflect(so->so_m); 470 #endif /* !VBOX */ 419 471 so->so_m = 0; /* Don't m_free() it again! */ 420 472 } 421 473 /* No need for this socket anymore, udp_detach it */ 474 #ifdef VBOX 475 udp_detach(pData, so); 476 #else /* !VBOX */ 422 477 udp_detach(so); 478 #endif /* !VBOX */ 423 479 } else { /* A "normal" UDP packet */ 424 480 struct mbuf *m; 425 481 int len, n; 426 482 483 #ifdef VBOX 484 if (!(m = m_get(pData))) return; 485 #else /* !VBOX */ 427 486 if (!(m = m_get())) return; 487 #endif /* !VBOX */ 428 488 m->m_data += if_maxlinkhdr; 429 489 … … 454 514 455 515 DEBUG_MISC((dfd," rx error, tx icmp ICMP_UNREACH:%i\n", code)); 516 #ifdef VBOX 517 icmp_error(pData, so->so_m, ICMP_UNREACH,code, 0,strerror(errno)); 518 m_free(pData, m); 519 #else /* !VBOX */ 456 520 icmp_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno)); 457 521 m_free(m); 522 #endif /* !VBOX */ 458 523 } else { 459 524 /* … … 480 545 * make it look like that's where it came from, done by udp_output 481 546 */ 547 #ifdef VBOX 548 udp_output(pData, so, m, &addr); 549 #else /* !VBOX */ 482 550 udp_output(so, m, &addr); 551 #endif /* !VBOX */ 483 552 } /* rx error */ 484 553 } /* if ping packet */ … … 489 558 */ 490 559 int 560 #ifdef VBOX 561 sosendto(PNATState pData, struct socket *so, struct mbuf *m) 562 #else /* !VBOX */ 491 563 sosendto(so, m) 492 564 struct socket *so; 493 565 struct mbuf *m; 566 #endif /* !VBOX */ 494 567 { 495 568 int ret; … … 538 611 */ 539 612 struct socket * 613 #ifdef VBOX 614 solisten(PNATState pData, u_int port, u_int32_t laddr, u_int lport, int flags) 615 #else /* !VBOX */ 540 616 solisten(port, laddr, lport, flags) 541 617 u_int port; … … 543 619 u_int lport; 544 620 int flags; 621 #endif /* !VBOX */ 545 622 { 546 623 struct sockaddr_in addr; … … 604 681 int tmperrno = WSAGetLastError(); /* Don't clobber the real reason we failed */ 605 682 closesocket(s); 606 sofree( so);683 sofree(pData, so); 607 684 /* Restore the real errno */ 608 685 WSASetLastError(tmperrno); … … 610 687 int tmperrno = errno; /* Don't clobber the real reason we failed */ 611 688 close(s); 612 sofree( so);689 sofree(pData, so); 613 690 /* Restore the real errno */ 614 691 errno = tmperrno; -
trunk/src/VBox/Devices/Network/slirp/socket.h
r1 r1033 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 */ … … 34 34 u_int16_t so_fport; /* foreign port */ 35 35 u_int16_t so_lport; /* local port */ 36 36 37 37 u_int8_t so_iptos; /* Type of service */ 38 38 u_int8_t so_emu; /* Is the socket emulated? */ 39 39 40 40 u_char so_type; /* Type of socket, UDP or TCP */ 41 41 int so_state; /* internal state flags SS_*, below */ 42 42 43 43 struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */ 44 44 u_int so_expire; /* When the socket will expire */ 45 45 46 46 int so_queued; /* Number of packets queued from this socket */ 47 47 int so_nqueued; /* Number of packets queued in a row 48 48 * Used to determine when to "downgrade" a session 49 49 * from fastq to batchq */ 50 50 51 51 struct sbuf so_rcv; /* Receive buffer */ 52 52 struct sbuf so_snd; /* Send buffer */ … … 85 85 struct socket * solookup _P((struct socket *, struct in_addr, u_int, struct in_addr, u_int)); 86 86 struct socket * socreate _P((void)); 87 #ifdef VBOX 88 void sofree _P((PNATState, struct socket *)); 89 int soread _P((PNATState, struct socket *)); 90 void sorecvoob _P((PNATState, struct socket *)); 91 #else /* !VBOX */ 87 92 void sofree _P((struct socket *)); 88 93 int soread _P((struct socket *)); 89 94 void sorecvoob _P((struct socket *)); 95 #endif /* !VBOX */ 90 96 int sosendoob _P((struct socket *)); 97 #ifdef VBOX 98 int sowrite _P((PNATState, struct socket *)); 99 void sorecvfrom _P((PNATState, struct socket *)); 100 int sosendto _P((PNATState, struct socket *, struct mbuf *)); 101 struct socket * solisten _P((PNATState, u_int, u_int32_t, u_int, int)); 102 #else /* !VBOX */ 91 103 int sowrite _P((struct socket *)); 92 104 void sorecvfrom _P((struct socket *)); 93 105 int sosendto _P((struct socket *, struct mbuf *)); 94 106 struct socket * solisten _P((u_int, u_int32_t, u_int, int)); 107 #endif /* !VBOX */ 95 108 void sorwakeup _P((struct socket *)); 96 109 void sowwakeup _P((struct socket *)); -
trunk/src/VBox/Devices/Network/slirp/tcp.h
r478 r1033 180 180 #define TCP_ISSINCR (125*1024) /* increment for tcp_iss each second */ 181 181 182 #ifndef VBOX 182 183 extern tcp_seq tcp_iss; /* tcp initial send seq # */ 184 #endif /* !VBOX */ 183 185 186 #ifdef VBOX 187 extern const char * const tcpstates[]; 188 #else /* !VBOX */ 184 189 extern char *tcpstates[]; 190 #endif /* !VBOX */ 185 191 186 192 #endif -
trunk/src/VBox/Devices/Network/slirp/tcp_input.c
r530 r1033 38 38 * Changes and additions relating to SLiRP 39 39 * Copyright (c) 1995 Danny Gasparovski. 40 * 41 * Please read the file COPYRIGHT for the 40 * 41 * Please read the file COPYRIGHT for the 42 42 * terms and conditions of the copyright. 43 43 */ … … 46 46 #include "ip_icmp.h" 47 47 48 #ifndef VBOX 48 49 struct socket tcb; 49 50 … … 52 53 53 54 tcp_seq tcp_iss; /* tcp initial send seq # */ 55 #endif /* !VBOX */ 54 56 55 57 #define TCP_PAWS_IDLE (24 * 24 * 60 * 60 * PR_SLOWHZ) … … 69 71 * when segments are out of order (so fast retransmit can work). 70 72 */ 73 #ifdef VBOX 74 #ifdef TCP_ACK_HACK 75 #define TCP_REASS(pData, tp, ti, m, so, flags) {\ 76 if ((ti)->ti_seq == (tp)->rcv_nxt && \ 77 u32_to_ptr((tp)->seg_next, struct tcpcb *) == (tp) && \ 78 (tp)->t_state == TCPS_ESTABLISHED) {\ 79 if (ti->ti_flags & TH_PUSH) \ 80 tp->t_flags |= TF_ACKNOW; \ 81 else \ 82 tp->t_flags |= TF_DELACK; \ 83 (tp)->rcv_nxt += (ti)->ti_len; \ 84 flags = (ti)->ti_flags & TH_FIN; \ 85 tcpstat.tcps_rcvpack++;\ 86 tcpstat.tcps_rcvbyte += (ti)->ti_len;\ 87 if (so->so_emu) { \ 88 if (tcp_emu((pData), (so),(m))) sbappend((pData), (so), (m)); \ 89 } else \ 90 sbappend((pData), (so), (m)); \ 91 /* sorwakeup(so); */ \ 92 } else {\ 93 (flags) = tcp_reass((pData), (tp), (ti), (m)); \ 94 tp->t_flags |= TF_ACKNOW; \ 95 } \ 96 } 97 #else 98 #define TCP_REASS(pData, tp, ti, m, so, flags) { \ 99 if ((ti)->ti_seq == (tp)->rcv_nxt && \ 100 u32_to_ptr((tp)->seg_next, struct tcpcb *) == (tp) && \ 101 (tp)->t_state == TCPS_ESTABLISHED) { \ 102 tp->t_flags |= TF_DELACK; \ 103 (tp)->rcv_nxt += (ti)->ti_len; \ 104 flags = (ti)->ti_flags & TH_FIN; \ 105 tcpstat.tcps_rcvpack++;\ 106 tcpstat.tcps_rcvbyte += (ti)->ti_len;\ 107 if (so->so_emu) { \ 108 if (tcp_emu((pData), (so),(m))) sbappend((pData), (so), (m)); \ 109 } else \ 110 sbappend((pData), (so), (m)); \ 111 /* sorwakeup(so); */ \ 112 } else { \ 113 (flags) = tcp_reass((pData), (tp), (ti), (m)); \ 114 tp->t_flags |= TF_ACKNOW; \ 115 } \ 116 } 117 #endif 118 #else /* !VBOX */ 71 119 #ifdef TCP_ACK_HACK 72 120 #define TCP_REASS(tp, ti, m, so, flags) {\ … … 113 161 } 114 162 #endif 163 #endif /* !VBOX */ 115 164 116 165 int 166 #ifdef VBOX 167 tcp_reass(PNATState pData, register struct tcpcb *tp, register struct tcpiphdr *ti, struct mbuf *m) 168 #else /* !VBOX */ 117 169 tcp_reass(tp, ti, m) 118 170 register struct tcpcb *tp; 119 171 register struct tcpiphdr *ti; 120 172 struct mbuf *m; 173 #endif /* !VBOX */ 121 174 { 122 175 register struct tcpiphdr *q; 123 176 struct socket *so = tp->t_socket; 124 177 int flags; 125 178 126 179 /* 127 180 * Call with ti==0 after become established to … … 153 206 tcpstat.tcps_rcvduppack++; 154 207 tcpstat.tcps_rcvdupbyte += ti->ti_len; 208 #ifdef VBOX 209 m_freem(pData, m); 210 #else /* !VBOX */ 155 211 m_freem(m); 212 #endif /* !VBOX */ 156 213 /* 157 214 * Try to present any queued data … … 189 246 m = REASS_MBUF_GET(u32_to_ptr(q->ti_prev, struct tcpiphdr *)); 190 247 remque_32(u32_to_ptr(q->ti_prev, struct tcpiphdr *)); 248 #ifdef VBOX 249 m_freem(pData, m); 250 #else /* !VBOX */ 191 251 m_freem(m); 252 #endif /* !VBOX */ 192 253 } 193 254 … … 217 278 /* if (so->so_state & SS_FCANTRCVMORE) */ 218 279 if (so->so_state & SS_FCANTSENDMORE) 280 #ifdef VBOX 281 m_freem(pData, m); 282 #else /* !VBOX */ 219 283 m_freem(m); 284 #endif /* !VBOX */ 220 285 else { 221 286 if (so->so_emu) { 287 #ifdef VBOX 288 if (tcp_emu(pData, so,m)) sbappend(pData, so, m); 289 #else /* !VBOX */ 222 290 if (tcp_emu(so,m)) sbappend(so, m); 291 #endif /* !VBOX */ 223 292 } else 293 #ifdef VBOX 294 sbappend(pData, so, m); 295 #else /* !VBOX */ 224 296 sbappend(so, m); 297 #endif /* !VBOX */ 225 298 } 226 299 } while (ti != (struct tcpiphdr *)tp && ti->ti_seq == tp->rcv_nxt); … … 234 307 */ 235 308 void 309 #ifdef VBOX 310 tcp_input(PNATState pData, register struct mbuf *m, int iphlen, struct socket *inso) 311 #else /* !VBOX */ 236 312 tcp_input(m, iphlen, inso) 237 313 register struct mbuf *m; 238 314 int iphlen; 239 315 struct socket *inso; 316 #endif /* !VBOX */ 240 317 { 241 318 struct ip save_ip, *ip; … … 255 332 256 333 DEBUG_CALL("tcp_input"); 257 DEBUG_ARGS((dfd," m = %8lx iphlen = %2d inso = %lx\n", 334 DEBUG_ARGS((dfd," m = %8lx iphlen = %2d inso = %lx\n", 258 335 (long )m, iphlen, (long )inso )); 259 336 260 337 /* 261 338 * If called with m == 0, then we're continuing the connect … … 263 340 if (m == NULL) { 264 341 so = inso; 265 342 266 343 /* Re-set a few variables */ 267 344 tp = sototcpcb(so); … … 271 348 tiwin = ti->ti_win; 272 349 tiflags = ti->ti_flags; 273 350 274 351 goto cont_conn; 275 352 } 276 277 353 354 278 355 tcpstat.tcps_rcvtotal++; 279 356 /* … … 287 364 } 288 365 /* XXX Check if too short */ 289 366 290 367 291 368 /* … … 294 371 */ 295 372 ip=mtod(m, struct ip *); 296 save_ip = *ip; 373 save_ip = *ip; 297 374 save_ip.ip_len+= iphlen; 298 375 … … 306 383 len = sizeof(struct ip ) + tlen; 307 384 /* keep checksum for ICMP reply 308 * ti->ti_sum = cksum(m, len); 385 * ti->ti_sum = cksum(m, len); 309 386 * if (ti->ti_sum) { */ 310 387 if(cksum(m, len)) { … … 328 405 optp = mtod(m, caddr_t) + sizeof (struct tcpiphdr); 329 406 330 /* 407 /* 331 408 * Do quick retrieval of timestamp options ("options 332 409 * prediction?"). If timestamp is the only option and it's … … 348 425 } 349 426 tiflags = ti->ti_flags; 350 427 351 428 /* 352 429 * Convert TCP protocol specific fields to host format. … … 362 439 m->m_data += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr); 363 440 m->m_len -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr); 364 441 365 442 /* 366 443 * Locate pcb for segment. … … 386 463 * 387 464 * state == CLOSED means we've done socreate() but haven't 388 * attached it to a protocol yet... 389 * 465 * attached it to a protocol yet... 466 * 390 467 * XXX If a TCB does not exist, and the TH_SYN flag is 391 468 * the only flag set, then create a session, mark it … … 395 472 if ((tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) != TH_SYN) 396 473 goto dropwithreset; 397 474 398 475 if ((so = socreate()) == NULL) 399 476 goto dropwithreset; 477 #ifdef VBOX 478 if (tcp_attach(pData, so) < 0) { 479 #else /* !VBOX */ 400 480 if (tcp_attach(so) < 0) { 481 #endif /* !VBOX */ 401 482 free(so); /* Not sofree (if it failed, it's not insqued) */ 402 483 goto dropwithreset; 403 484 } 404 485 405 486 sbreserve(&so->so_snd, tcp_sndspace); 406 487 sbreserve(&so->so_rcv, tcp_rcvspace); 407 488 408 489 /* tcp_last_so = so; */ /* XXX ? */ 409 490 /* tp = sototcpcb(so); */ 410 491 411 492 so->so_laddr = ti->ti_src; 412 493 so->so_lport = ti->ti_sport; 413 494 so->so_faddr = ti->ti_dst; 414 495 so->so_fport = ti->ti_dport; 415 496 416 497 if ((so->so_iptos = tcp_tos(so)) == 0) 417 498 so->so_iptos = ((struct ip *)ti)->ip_tos; 418 499 419 500 tp = sototcpcb(so); 420 501 tp->t_state = TCPS_LISTEN; 421 502 } 422 503 423 504 /* 424 505 * If this is a still-connecting socket, this probably … … 430 511 431 512 tp = sototcpcb(so); 432 513 433 514 /* XXX Should never fail */ 434 515 if (tp == 0) … … 436 517 if (tp->t_state == TCPS_CLOSED) 437 518 goto drop; 438 519 439 520 /* Unscale the window into a 32-bit value. */ 440 521 /* if ((tiflags & TH_SYN) == 0) … … 459 540 */ 460 541 if (optp && tp->t_state != TCPS_LISTEN) 461 tcp_dooptions(tp, (u_char *)optp, optlen, ti); 542 #ifdef VBOX 543 tcp_dooptions(pData, tp, (u_char *)optp, optlen, ti); 544 #else /* !VBOX */ 545 tcp_dooptions(tp, (u_char *)optp, optlen, ti); 546 #endif /* !VBOX */ 462 547 /* , */ 463 548 /* &ts_present, &ts_val, &ts_ecr); */ 464 549 465 /* 550 /* 466 551 * Header prediction: check for the two common cases 467 552 * of a uni-directional data xfer. If the packet has … … 487 572 tiwin && tiwin == tp->snd_wnd && 488 573 tp->snd_nxt == tp->snd_max) { 489 /* 574 /* 490 575 * If last ACK falls within this segment's sequence numbers, 491 576 * record the timestamp. … … 507 592 /* if (ts_present) 508 593 * tcp_xmit_timer(tp, tcp_now-ts_ecr+1); 509 * else 594 * else 510 595 */ if (tp->t_rtt && 511 596 SEQ_GT(ti->ti_ack, tp->t_rtseq)) 597 #ifdef VBOX 598 tcp_xmit_timer(pData, tp, tp->t_rtt); 599 #else /* !VBOX */ 512 600 tcp_xmit_timer(tp, tp->t_rtt); 601 #endif /* !VBOX */ 513 602 acked = ti->ti_ack - tp->snd_una; 514 603 tcpstat.tcps_rcvackpack++; … … 516 605 sbdrop(&so->so_snd, acked); 517 606 tp->snd_una = ti->ti_ack; 607 #ifdef VBOX 608 m_freem(pData, m); 609 #else /* !VBOX */ 518 610 m_freem(m); 611 #endif /* !VBOX */ 519 612 520 613 /* … … 532 625 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; 533 626 534 /* 627 /* 535 628 * There's room in so_snd, sowwakup will read() 536 629 * from the socket if we can … … 539 632 * sowwakeup(so); 540 633 */ 541 /* 634 /* 542 635 * This is called because sowwakeup might have 543 636 * put data into so_snd. Since we don't so sowwakeup, … … 545 638 */ 546 639 if (so->so_snd.sb_cc) 640 #ifdef VBOX 641 (void) tcp_output(pData, tp); 642 #else /* !VBOX */ 547 643 (void) tcp_output(tp); 644 #endif /* !VBOX */ 548 645 549 646 return; … … 565 662 */ 566 663 if (so->so_emu) { 664 #ifdef VBOX 665 if (tcp_emu(pData, so,m)) sbappend(pData, so, m); 666 #else /* !VBOX */ 567 667 if (tcp_emu(so,m)) sbappend(so, m); 668 #endif /* !VBOX */ 568 669 } else 670 #ifdef VBOX 671 sbappend(pData, so, m); 672 #else /* !VBOX */ 569 673 sbappend(so, m); 570 571 /* 674 #endif /* !VBOX */ 675 676 /* 572 677 * XXX This is called when data arrives. Later, check 573 678 * if we can actually write() to the socket … … 575 680 */ 576 681 /* sorwakeup(so); */ 577 682 578 683 /* 579 684 * If this is a short packet, then ACK now - with Nagel 580 685 * congestion avoidance sender won't send more until 581 686 * he gets an ACK. 582 * 687 * 583 688 * It is better to not delay acks at all to maximize 584 689 * TCP throughput. See RFC 2581. 585 */ 690 */ 586 691 tp->t_flags |= TF_ACKNOW; 692 #ifdef VBOX 693 tcp_output(pData, tp); 694 #else /* !VBOX */ 587 695 tcp_output(tp); 696 #endif /* !VBOX */ 588 697 return; 589 698 } … … 625 734 if ((tiflags & TH_SYN) == 0) 626 735 goto drop; 627 736 628 737 /* 629 738 * This has way too many gotos... 630 739 * But a bit of spaghetti code never hurt anybody :) 631 740 */ 632 741 633 742 /* 634 743 * If this is destined for the control address, then flag to … … 642 751 /* Command or exec adress */ 643 752 so->so_state |= SS_CTL; 644 } else 753 } else 645 754 #endif 646 755 { … … 648 757 struct ex_list *ex_ptr; 649 758 for(ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { 650 if(ex_ptr->ex_fport == so->so_fport && 759 if(ex_ptr->ex_fport == so->so_fport && 651 760 lastbyte == ex_ptr->ex_addr) { 652 761 so->so_state |= SS_CTL; … … 659 768 /* CTL_ALIAS: Do nothing, tcp_fconnect will be called on it */ 660 769 } 661 770 662 771 if (so->so_emu & EMU_NOCONNECT) { 663 772 so->so_emu &= ~EMU_NOCONNECT; 664 773 goto cont_input; 665 774 } 666 775 776 #ifdef VBOX 777 if((tcp_fconnect(pData, so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) { 778 #else /* !VBOX */ 667 779 if((tcp_fconnect(so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) { 780 #endif /* !VBOX */ 668 781 u_char code=ICMP_UNREACH_NET; 669 782 DEBUG_MISC((dfd," tcp fconnect errno = %d-%s\n", … … 671 784 if(errno == ECONNREFUSED) { 672 785 /* ACK the SYN, send RST to refuse the connection */ 786 #ifdef VBOX 787 tcp_respond(pData, tp, ti, m, ti->ti_seq+1, (tcp_seq)0, 788 TH_RST|TH_ACK); 789 #else /* !VBOX */ 673 790 tcp_respond(tp, ti, m, ti->ti_seq+1, (tcp_seq)0, 674 TH_RST|TH_ACK); 791 TH_RST|TH_ACK); 792 #endif /* !VBOX */ 675 793 } else { 676 794 if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST; … … 682 800 m->m_len += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr); 683 801 *ip=save_ip; 802 #ifdef VBOX 803 icmp_error(pData, m, ICMP_UNREACH,code, 0,strerror(errno)); 804 #else /* !VBOX */ 684 805 icmp_error(m, ICMP_UNREACH,code, 0,strerror(errno)); 806 #endif /* !VBOX */ 685 807 } 808 #ifdef VBOX 809 tp = tcp_close(pData, tp); 810 m_free(pData, m); 811 #else /* !VBOX */ 686 812 tp = tcp_close(tp); 687 813 m_free(m); 814 #endif /* !VBOX */ 688 815 } else { 689 816 /* … … 700 827 return; 701 828 702 cont_conn: 703 /* m==NULL 829 cont_conn: 830 /* m==NULL 704 831 * Check if the connect succeeded 705 832 */ 706 833 if (so->so_state & SS_NOFDREF) { 834 #ifdef VBOX 835 tp = tcp_close(pData, tp); 836 #else /* !VBOX */ 707 837 tp = tcp_close(tp); 838 #endif /* !VBOX */ 708 839 goto dropwithreset; 709 840 } 710 cont_input: 841 cont_input: 711 842 tcp_template(tp); 712 843 713 844 if (optp) 845 #ifdef VBOX 846 tcp_dooptions(pData, tp, (u_char *)optp, optlen, ti); 847 #else /* !VBOX */ 714 848 tcp_dooptions(tp, (u_char *)optp, optlen, ti); 849 #endif /* !VBOX */ 715 850 /* , */ 716 851 /* &ts_present, &ts_val, &ts_ecr); */ 717 852 718 853 if (iss) 719 854 tp->iss = iss; 720 else 855 else 721 856 tp->iss = tcp_iss; 722 857 tcp_iss += TCP_ISSINCR/2; … … 730 865 goto trimthenstep6; 731 866 } /* case TCPS_LISTEN */ 732 867 733 868 /* 734 869 * If the state is SYN_SENT: … … 751 886 if (tiflags & TH_RST) { 752 887 if (tiflags & TH_ACK) 888 #ifdef VBOX 889 tp = tcp_drop(pData, tp,0); /* XXX Check t_softerror! */ 890 #else /* !VBOX */ 753 891 tp = tcp_drop(tp,0); /* XXX Check t_softerror! */ 892 #endif /* !VBOX */ 754 893 goto drop; 755 894 } … … 771 910 soisfconnected(so); 772 911 tp->t_state = TCPS_ESTABLISHED; 773 912 774 913 /* Do window scaling on this connection? */ 775 914 /* if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == … … 779 918 * } 780 919 */ 920 #ifdef VBOX 921 (void) tcp_reass(pData, tp, (struct tcpiphdr *)0, 922 (struct mbuf *)0); 923 #else /* !VBOX */ 781 924 (void) tcp_reass(tp, (struct tcpiphdr *)0, 782 925 (struct mbuf *)0); 926 #endif /* !VBOX */ 783 927 /* 784 928 * if we didn't have to retransmit the SYN, … … 786 930 */ 787 931 if (tp->t_rtt) 932 #ifdef VBOX 933 tcp_xmit_timer(pData, tp, tp->t_rtt); 934 #else /* !VBOX */ 788 935 tcp_xmit_timer(tp, tp->t_rtt); 936 #endif /* !VBOX */ 789 937 } else 790 938 tp->t_state = TCPS_SYN_RECEIVED; … … 812 960 * States other than LISTEN or SYN_SENT. 813 961 * First check timestamp, if present. 814 * Then check that at least some bytes of segment are within 962 * Then check that at least some bytes of segment are within 815 963 * receive window. If segment begins before rcv_nxt, 816 964 * drop leading data (and SYN); if nothing left, just ack. 817 * 965 * 818 966 * RFC 1323 PAWS: If we have a timestamp reply on this segment 819 967 * and it's less than ts_recent, drop it. … … 850 998 tiflags &= ~TH_SYN; 851 999 ti->ti_seq++; 852 if (ti->ti_urp > 1) 1000 if (ti->ti_urp > 1) 853 1001 ti->ti_urp--; 854 1002 else … … 867 1015 */ 868 1016 tiflags &= ~TH_FIN; 869 1017 870 1018 /* 871 1019 * Send an ACK to resynchronize and drop any data. … … 896 1044 if ((so->so_state & SS_NOFDREF) && 897 1045 tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len) { 1046 #ifdef VBOX 1047 tp = tcp_close(pData, tp); 1048 #else /* !VBOX */ 898 1049 tp = tcp_close(tp); 1050 #endif /* !VBOX */ 899 1051 tcpstat.tcps_rcvafterclose++; 900 1052 goto dropwithreset; … … 920 1072 SEQ_GT(ti->ti_seq, tp->rcv_nxt)) { 921 1073 iss = tp->rcv_nxt + TCP_ISSINCR; 1074 #ifdef VBOX 1075 tp = tcp_close(pData, tp); 1076 #else /* !VBOX */ 922 1077 tp = tcp_close(tp); 1078 #endif /* !VBOX */ 923 1079 goto findso; 924 1080 } … … 978 1134 tp->t_state = TCPS_CLOSED; 979 1135 tcpstat.tcps_drops++; 1136 #ifdef VBOX 1137 tp = tcp_close(pData, tp); 1138 #else /* !VBOX */ 980 1139 tp = tcp_close(tp); 1140 #endif /* !VBOX */ 981 1141 goto drop; 982 1142 … … 984 1144 case TCPS_LAST_ACK: 985 1145 case TCPS_TIME_WAIT: 1146 #ifdef VBOX 1147 tp = tcp_close(pData, tp); 1148 #else /* !VBOX */ 986 1149 tp = tcp_close(tp); 1150 #endif /* !VBOX */ 987 1151 goto drop; 988 1152 } … … 993 1157 */ 994 1158 if (tiflags & TH_SYN) { 1159 #ifdef VBOX 1160 tp = tcp_drop(pData, tp,0); 1161 #else /* !VBOX */ 995 1162 tp = tcp_drop(tp,0); 1163 #endif /* !VBOX */ 996 1164 goto dropwithreset; 997 1165 } … … 1018 1186 tcpstat.tcps_connects++; 1019 1187 tp->t_state = TCPS_ESTABLISHED; 1020 /* 1021 * The sent SYN is ack'ed with our sequence number +1 1022 * The first data byte already in the buffer will get 1188 /* 1189 * The sent SYN is ack'ed with our sequence number +1 1190 * The first data byte already in the buffer will get 1023 1191 * lost if no correction is made. This is only needed for 1024 1192 * SS_CTL since the buffer is empty otherwise. 1025 * tp->snd_una++; or: 1193 * tp->snd_una++; or: 1026 1194 */ 1027 1195 tp->snd_una=ti->ti_ack; 1028 1196 if (so->so_state & SS_CTL) { 1029 1197 /* So tcp_ctl reports the right state */ 1198 #ifdef VBOX 1199 ret = tcp_ctl(pData, so); 1200 #else /* !VBOX */ 1030 1201 ret = tcp_ctl(so); 1202 #endif /* !VBOX */ 1031 1203 if (ret == 1) { 1032 1204 soisfconnected(so); … … 1041 1213 soisfconnected(so); 1042 1214 } 1043 1215 1044 1216 /* Do window scaling? */ 1045 1217 /* if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == … … 1049 1221 * } 1050 1222 */ 1223 #ifdef VBOX 1224 (void) tcp_reass(pData, tp, (struct tcpiphdr *)0, (struct mbuf *)0); 1225 #else /* !VBOX */ 1051 1226 (void) tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0); 1227 #endif /* !VBOX */ 1052 1228 tp->snd_wl1 = ti->ti_seq - 1; 1053 1229 /* Avoid ack processing; snd_una==ti_ack => dup ack */ … … 1095 1271 * 1096 1272 * Dup acks mean that packets have left the 1097 * network (they're now cached at the receiver) 1273 * network (they're now cached at the receiver) 1098 1274 * so bump cwnd by the amount in the receiver 1099 1275 * to keep a constant cwnd packets in the … … 1116 1292 tp->snd_nxt = ti->ti_ack; 1117 1293 tp->snd_cwnd = tp->t_maxseg; 1294 #ifdef VBOX 1295 (void) tcp_output(pData, tp); 1296 #else /* !VBOX */ 1118 1297 (void) tcp_output(tp); 1298 #endif /* !VBOX */ 1119 1299 tp->snd_cwnd = tp->snd_ssthresh + 1120 1300 tp->t_maxseg * tp->t_dupacks; … … 1124 1304 } else if (tp->t_dupacks > tcprexmtthresh) { 1125 1305 tp->snd_cwnd += tp->t_maxseg; 1306 #ifdef VBOX 1307 (void) tcp_output(pData, tp); 1308 #else /* !VBOX */ 1126 1309 (void) tcp_output(tp); 1310 #endif /* !VBOX */ 1127 1311 goto drop; 1128 1312 } … … 1160 1344 * tcp_xmit_timer(tp, tcp_now-ts_ecr+1); 1161 1345 * else 1162 */ 1346 */ 1163 1347 if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq)) 1348 #ifdef VBOX 1349 tcp_xmit_timer(pData, tp,tp->t_rtt); 1350 #else /* !VBOX */ 1164 1351 tcp_xmit_timer(tp,tp->t_rtt); 1352 #endif /* !VBOX */ 1165 1353 1166 1354 /* … … 1201 1389 /* 1202 1390 * XXX sowwakup is called when data is acked and there's room for 1203 * for more data... it should read() the socket 1391 * for more data... it should read() the socket 1204 1392 */ 1205 1393 /* if (so->so_snd.sb_flags & SB_NOTIFY) … … 1257 1445 case TCPS_LAST_ACK: 1258 1446 if (ourfinisacked) { 1447 #ifdef VBOX 1448 tp = tcp_close(pData, tp); 1449 #else /* !VBOX */ 1259 1450 tp = tcp_close(tp); 1451 #endif /* !VBOX */ 1260 1452 goto drop; 1261 1453 } … … 1279 1471 */ 1280 1472 if ((tiflags & TH_ACK) && 1281 (SEQ_LT(tp->snd_wl1, ti->ti_seq) || 1473 (SEQ_LT(tp->snd_wl1, ti->ti_seq) || 1282 1474 (tp->snd_wl1 == ti->ti_seq && (SEQ_LT(tp->snd_wl2, ti->ti_ack) || 1283 1475 (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) { … … 1314 1506 * then mark the data stream. This should not happen 1315 1507 * in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since 1316 * a FIN has been received from the remote side. 1508 * a FIN has been received from the remote side. 1317 1509 * In these states we ignore the URG. 1318 1510 * … … 1321 1513 * of urgent data. We continue, however, 1322 1514 * to consider it to indicate the first octet 1323 * of data past the urgent section as the original 1515 * of data past the urgent section as the original 1324 1516 * spec states (in one of two places). 1325 1517 */ … … 1329 1521 (tp->rcv_up - tp->rcv_nxt); /* -1; */ 1330 1522 tp->rcv_up = ti->ti_seq + ti->ti_urp; 1331 1523 1332 1524 } 1333 1525 } else … … 1351 1543 if ((ti->ti_len || (tiflags&TH_FIN)) && 1352 1544 TCPS_HAVERCVDFIN(tp->t_state) == 0) { 1545 #ifdef VBOX 1546 TCP_REASS(pData, tp, ti, m, so, tiflags); 1547 #else /* !VBOX */ 1353 1548 TCP_REASS(tp, ti, m, so, tiflags); 1549 #endif /* !VBOX */ 1354 1550 /* 1355 1551 * Note the amount of data that peer has sent into … … 1359 1555 len = so->so_rcv.sb_datalen - (tp->rcv_adv - tp->rcv_nxt); 1360 1556 } else { 1557 #ifdef VBOX 1558 m_free(pData, m); 1559 #else /* !VBOX */ 1361 1560 m_free(m); 1561 #endif /* !VBOX */ 1362 1562 tiflags &= ~TH_FIN; 1363 1563 } … … 1380 1580 /* sofcantrcvmore(so); */ 1381 1581 sofwdrain(so); 1382 1582 1383 1583 tp->t_flags |= TF_ACKNOW; 1384 1584 tp->rcv_nxt++; … … 1394 1594 if(so->so_emu == EMU_CTL) /* no shutdown on socket */ 1395 1595 tp->t_state = TCPS_LAST_ACK; 1396 else 1596 else 1397 1597 tp->t_state = TCPS_CLOSE_WAIT; 1398 1598 break; … … 1408 1608 /* 1409 1609 * In FIN_WAIT_2 state enter the TIME_WAIT state, 1410 * starting the time-wait timer, turning off the other 1610 * starting the time-wait timer, turning off the other 1411 1611 * standard timers. 1412 1612 */ … … 1431 1631 * congestion avoidance sender won't send more until 1432 1632 * he gets an ACK. 1433 * 1633 * 1434 1634 * See above. 1435 1635 */ … … 1450 1650 */ 1451 1651 if (needoutput || (tp->t_flags & TF_ACKNOW)) { 1652 #ifdef VBOX 1653 (void) tcp_output(pData, tp); 1654 #else /* !VBOX */ 1452 1655 (void) tcp_output(tp); 1656 #endif /* !VBOX */ 1453 1657 } 1454 1658 return; … … 1461 1665 if (tiflags & TH_RST) 1462 1666 goto drop; 1667 #ifdef VBOX 1668 m_freem(pData, m); 1669 #else /* !VBOX */ 1463 1670 m_freem(m); 1671 #endif /* !VBOX */ 1464 1672 tp->t_flags |= TF_ACKNOW; 1673 #ifdef VBOX 1674 (void) tcp_output(pData, tp); 1675 #else /* !VBOX */ 1465 1676 (void) tcp_output(tp); 1677 #endif /* !VBOX */ 1466 1678 return; 1467 1679 … … 1469 1681 /* reuses m if m!=NULL, m_free() unnecessary */ 1470 1682 if (tiflags & TH_ACK) 1683 #ifdef VBOX 1684 tcp_respond(pData, tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST); 1685 #else /* !VBOX */ 1471 1686 tcp_respond(tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST); 1687 #endif /* !VBOX */ 1472 1688 else { 1473 1689 if (tiflags & TH_SYN) ti->ti_len++; 1690 #ifdef VBOX 1691 tcp_respond(pData, tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0, 1692 TH_RST|TH_ACK); 1693 #else /* !VBOX */ 1474 1694 tcp_respond(tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0, 1475 1695 TH_RST|TH_ACK); 1696 #endif /* !VBOX */ 1476 1697 } 1477 1698 … … 1482 1703 * Drop space held by incoming segment and return. 1483 1704 */ 1705 #ifdef VBOX 1706 m_free(pData, m); 1707 #else /* !VBOX */ 1484 1708 m_free(m); 1709 #endif /* !VBOX */ 1485 1710 1486 1711 return; … … 1492 1717 */ 1493 1718 void 1719 #ifdef VBOX 1720 tcp_dooptions(PNATState pData, struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti) 1721 #else /* !VBOX */ 1494 1722 tcp_dooptions(tp, cp, cnt, ti) 1495 1723 struct tcpcb *tp; … … 1497 1725 int cnt; 1498 1726 struct tcpiphdr *ti; 1727 #endif /* !VBOX */ 1499 1728 { 1500 1729 u_int16_t mss; … … 1527 1756 memcpy((char *) &mss, (char *) cp + 2, sizeof(mss)); 1528 1757 NTOHS(mss); 1758 #ifdef VBOX 1759 (void) tcp_mss(pData, tp, mss); /* sets t_maxseg */ 1760 #else /* !VBOX */ 1529 1761 (void) tcp_mss(tp, mss); /* sets t_maxseg */ 1762 #endif /* !VBOX */ 1530 1763 break; 1531 1764 … … 1548 1781 * NTOHL(*ts_ecr); 1549 1782 * 1550 */ /* 1783 */ /* 1551 1784 * * A timestamp received in a SYN makes 1552 1785 * * it ok to send timestamp requests and replies. … … 1579 1812 { 1580 1813 int cnt = ti->ti_urp - 1; 1581 1814 1582 1815 while (cnt >= 0) { 1583 1816 if (m->m_len > cnt) { … … 1607 1840 1608 1841 void 1842 #ifdef VBOX 1843 tcp_xmit_timer(PNATState pData, register struct tcpcb *tp, int rtt) 1844 #else /* !VBOX */ 1609 1845 tcp_xmit_timer(tp, rtt) 1610 1846 register struct tcpcb *tp; 1611 1847 int rtt; 1848 #endif /* !VBOX */ 1612 1849 { 1613 1850 register short delta; … … 1616 1853 DEBUG_ARG("tp = %lx", (long)tp); 1617 1854 DEBUG_ARG("rtt = %d", rtt); 1618 1855 1619 1856 tcpstat.tcps_rttupdated++; 1620 1857 if (tp->t_srtt != 0) { … … 1645 1882 tp->t_rttvar = 1; 1646 1883 } else { 1647 /* 1884 /* 1648 1885 * No rtt measurement yet - use the unsmoothed rtt. 1649 1886 * Set the variance to half the rtt (so our first … … 1669 1906 TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp), 1670 1907 (short)tp->t_rttmin, TCPTV_REXMTMAX); /* XXX */ 1671 1908 1672 1909 /* 1673 1910 * We received an ack for a packet that wasn't retransmitted; … … 1697 1934 1698 1935 int 1936 #ifdef VBOX 1937 tcp_mss(PNATState pData, register struct tcpcb *tp, u_int offer) 1938 #else /* !VBOX */ 1699 1939 tcp_mss(tp, offer) 1700 1940 register struct tcpcb *tp; 1701 1941 u_int offer; 1942 #endif /* !VBOX */ 1702 1943 { 1703 1944 struct socket *so = tp->t_socket; 1704 1945 int mss; 1705 1946 1706 1947 DEBUG_CALL("tcp_mss"); 1707 1948 DEBUG_ARG("tp = %lx", (long)tp); 1708 1949 DEBUG_ARG("offer = %d", offer); 1709 1950 1710 1951 mss = min(if_mtu, if_mru) - sizeof(struct tcpiphdr); 1711 1952 if (offer) … … 1714 1955 if (mss < tp->t_maxseg || offer != 0) 1715 1956 tp->t_maxseg = mss; 1716 1957 1717 1958 tp->snd_cwnd = mss; 1718 1959 1719 1960 sbreserve(&so->so_snd, tcp_sndspace+((tcp_sndspace%mss)?(mss-(tcp_sndspace%mss)):0)); 1720 1961 sbreserve(&so->so_rcv, tcp_rcvspace+((tcp_rcvspace%mss)?(mss-(tcp_rcvspace%mss)):0)); 1721 1962 1722 1963 DEBUG_MISC((dfd, " returning mss = %d\n", mss)); 1723 1964 1724 1965 return mss; 1725 1966 } -
trunk/src/VBox/Devices/Network/slirp/tcp_output.c
r1 r1033 38 38 * Changes and additions relating to SLiRP 39 39 * Copyright (c) 1995 Danny Gasparovski. 40 * 41 * Please read the file COPYRIGHT for the 40 * 41 * Please read the file COPYRIGHT for the 42 42 * terms and conditions of the copyright. 43 43 */ … … 49 49 * names instead of the REAL names 50 50 */ 51 #ifdef VBOX 52 const char * const tcpstates[] = { 53 #else /* !VBOX */ 51 54 char *tcpstates[] = { 55 #endif /* !VBOX */ 52 56 /* "CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD", */ 53 57 "REDIRECT", "LISTEN", "SYN_SENT", "SYN_RCVD", … … 56 60 }; 57 61 62 #ifdef VBOX 63 static const u_char tcp_outflags[TCP_NSTATES] = { 64 #else /* !VBOX */ 58 65 u_char tcp_outflags[TCP_NSTATES] = { 66 #endif /* !VBOX */ 59 67 TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK, 60 TH_ACK, TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, 68 TH_ACK, TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, 61 69 TH_FIN|TH_ACK, TH_ACK, TH_ACK, 62 70 }; … … 69 77 */ 70 78 int 79 #ifdef VBOX 80 tcp_output(PNATState pData, register struct tcpcb *tp) 81 #else /* !VBOX */ 71 82 tcp_output(tp) 72 83 register struct tcpcb *tp; 84 #endif /* !VBOX */ 73 85 { 74 86 register struct socket *so = tp->t_socket; … … 80 92 unsigned optlen, hdrlen; 81 93 int idle, sendalot; 82 94 83 95 DEBUG_CALL("tcp_output"); 84 96 DEBUG_ARG("tp = %lx", (long )tp); 85 97 86 98 /* 87 99 * Determine length of data that should be transmitted, … … 104 116 105 117 flags = tcp_outflags[tp->t_state]; 106 118 107 119 DEBUG_MISC((dfd, " --- tcp_output flags = 0x%x\n",flags)); 108 120 109 121 /* 110 122 * If in persist timeout with window of 0, send 1 byte. … … 159 171 } 160 172 } 161 173 162 174 if (len > tp->t_maxseg) { 163 175 len = tp->t_maxseg; … … 201 213 */ 202 214 if (win > 0) { 203 /* 215 /* 204 216 * "adv" is the amount we can increase the window, 205 217 * taking into account that we are limited by … … 265 277 */ 266 278 tcpstat.tcps_didnuttin++; 267 279 268 280 return (0); 269 281 … … 286 298 opt[0] = TCPOPT_MAXSEG; 287 299 opt[1] = 4; 300 #ifdef VBOX 301 mss = htons((u_int16_t) tcp_mss(pData, tp, 0)); 302 #else /* !VBOX */ 288 303 mss = htons((u_int16_t) tcp_mss(tp, 0)); 304 #endif /* !VBOX */ 289 305 memcpy((caddr_t)(opt + 2), (caddr_t)&mss, sizeof(mss)); 290 306 optlen = 4; … … 303 319 } 304 320 } 305 321 306 322 /* 307 * Send a timestamp and echo-reply if this is a SYN and our side 323 * Send a timestamp and echo-reply if this is a SYN and our side 308 324 * wants to use timestamps (TF_REQ_TSTMP is set) or both our side 309 325 * and our peer have sent timestamps in our SYN's. … … 323 339 */ 324 340 hdrlen += optlen; 325 341 326 342 /* 327 343 * Adjust data length if insertion of options will … … 349 365 } 350 366 367 #ifdef VBOX 368 m = m_get(pData); 369 #else /* !VBOX */ 351 370 m = m_get(); 371 #endif /* !VBOX */ 352 372 if (m == NULL) { 353 373 /* error = ENOBUFS; */ … … 357 377 m->m_data += if_maxlinkhdr; 358 378 m->m_len = hdrlen; 359 360 /* 379 380 /* 361 381 * This will always succeed, since we make sure our mbufs 362 382 * are big enough to hold one MSS packet + header + ... etc. … … 391 411 tcpstat.tcps_sndwinup++; 392 412 413 #ifdef VBOX 414 m = m_get(pData); 415 #else /* !VBOX */ 393 416 m = m_get(); 417 #endif /* !VBOX */ 394 418 if (m == NULL) { 395 419 /* error = ENOBUFS; */ … … 402 426 403 427 ti = mtod(m, struct tcpiphdr *); 404 428 405 429 memcpy((caddr_t)ti, &tp->t_template, sizeof (struct tcpiphdr)); 406 430 … … 410 434 * If resending a FIN, be sure not to use a new sequence number. 411 435 */ 412 if (flags & TH_FIN && tp->t_flags & TF_SENTFIN && 436 if (flags & TH_FIN && tp->t_flags & TF_SENTFIN && 413 437 tp->snd_nxt == tp->snd_max) 414 438 tp->snd_nxt--; … … 447 471 win = (long)(tp->rcv_adv - tp->rcv_nxt); 448 472 ti->ti_win = htons((u_int16_t) (win>>tp->rcv_scale)); 449 473 450 474 if (SEQ_GT(tp->snd_up, tp->snd_una)) { 451 475 ti->ti_urp = htons((u_int16_t)(tp->snd_up - ntohl(ti->ti_seq))); 452 #ifdef notdef 476 #ifdef notdef 453 477 if (SEQ_GT(tp->snd_up, tp->snd_nxt)) { 454 478 ti->ti_urp = htons((u_int16_t)(tp->snd_up - tp->snd_nxt)); … … 532 556 */ 533 557 m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */ 534 558 535 559 { 536 560 537 561 ((struct ip *)ti)->ip_len = m->m_len; 538 562 539 563 ((struct ip *)ti)->ip_ttl = ip_defttl; 540 564 ((struct ip *)ti)->ip_tos = so->so_iptos; 541 565 542 566 /* #if BSD >= 43 */ 543 567 /* Don't do IP options... */ … … 545 569 * so->so_options & SO_DONTROUTE, 0); 546 570 */ 571 #ifdef VBOX 572 error = ip_output(pData, so, m); 573 #else /* !VBOX */ 547 574 error = ip_output(so, m); 575 #endif /* !VBOX */ 548 576 549 577 /* #else 550 * error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route, 578 * error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route, 551 579 * so->so_options & SO_DONTROUTE); 552 580 * #endif -
trunk/src/VBox/Devices/Network/slirp/tcp_subr.c
r532 r1033 38 38 * Changes and additions relating to SLiRP 39 39 * Copyright (c) 1995 Danny Gasparovski. 40 * 41 * Please read the file COPYRIGHT for the 40 * 41 * Please read the file COPYRIGHT for the 42 42 * terms and conditions of the copyright. 43 43 */ … … 46 46 #include <slirp.h> 47 47 48 #ifndef VBOX 48 49 /* patchable/settable parameters for tcp */ 49 50 int tcp_mssdflt = TCP_MSS; … … 52 53 int tcp_rcvspace; /* You may want to change this */ 53 54 int tcp_sndspace; /* Keep small if you have an error prone link */ 55 #endif /* !VBOX */ 54 56 55 57 /* … … 57 59 */ 58 60 void 61 #ifdef VBOX 62 tcp_init(PNATState pData) 63 #else /* !VBOX */ 59 64 tcp_init() 65 #endif /* !VBOX */ 60 66 { 61 67 tcp_iss = 1; /* wrong */ 62 68 tcb.so_next = tcb.so_prev = &tcb; 63 69 #ifdef VBOX 70 tcp_last_so = &tcb; 71 #endif /* VBOX */ 72 73 #ifndef VBOX 64 74 /* tcp_rcvspace = our Window we advertise to the remote */ 65 75 tcp_rcvspace = TCP_RCVSPACE; 66 76 tcp_sndspace = TCP_SNDSPACE; 67 77 68 78 /* Make sure tcp_sndspace is at least 2*MSS */ 69 79 if (tcp_sndspace < 2*(min(if_mtu, if_mru) - sizeof(struct tcpiphdr))) 70 80 tcp_sndspace = 2*(min(if_mtu, if_mru) - sizeof(struct tcpiphdr)); 81 #endif /* !VBOX */ 71 82 } 72 83 … … 93 104 n->ti_sport = so->so_fport; 94 105 n->ti_dport = so->so_lport; 95 106 96 107 n->ti_seq = 0; 97 108 n->ti_ack = 0; … … 118 129 */ 119 130 void 131 #ifdef VBOX 132 tcp_respond(PNATState pData, struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m, tcp_seq ack, tcp_seq seq, int flags) 133 #else /* !VBOX */ 120 134 tcp_respond(tp, ti, m, ack, seq, flags) 121 135 struct tcpcb *tp; … … 124 138 tcp_seq ack, seq; 125 139 int flags; 140 #endif /* !VBOX */ 126 141 { 127 142 register int tlen; … … 135 150 DEBUG_ARG("seq = %u", seq); 136 151 DEBUG_ARG("flags = %x", flags); 137 152 138 153 if (tp) 139 154 win = sbspace(&tp->t_socket->so_rcv); 140 155 if (m == 0) { 156 #ifdef VBOX 157 if ((m = m_get(pData)) == NULL) 158 #else /* !VBOX */ 141 159 if ((m = m_get()) == NULL) 160 #endif /* !VBOX */ 142 161 return; 143 162 #ifdef TCP_COMPAT_42 … … 151 170 flags = TH_ACK; 152 171 } else { 153 /* 172 /* 154 173 * ti points into m so the next line is just making 155 174 * the mbuf point to ti 156 175 */ 157 176 m->m_data = (caddr_t)ti; 158 177 159 178 m->m_len = sizeof (struct tcpiphdr); 160 179 tlen = 0; … … 184 203 ((struct ip *)ti)->ip_len = tlen; 185 204 186 if(flags & TH_RST) 205 if(flags & TH_RST) 187 206 ((struct ip *)ti)->ip_ttl = MAXTTL; 188 else 207 else 189 208 ((struct ip *)ti)->ip_ttl = ip_defttl; 190 209 210 #ifdef VBOX 211 (void) ip_output(pData, (struct socket *)0, m); 212 #else /* !VBOX */ 191 213 (void) ip_output((struct socket *)0, m); 214 #endif /* !VBOX */ 192 215 } 193 216 … … 202 225 { 203 226 register struct tcpcb *tp; 204 227 205 228 tp = (struct tcpcb *)malloc(sizeof(*tp)); 206 229 if (tp == NULL) 207 230 return ((struct tcpcb *)0); 208 231 209 232 memset((char *) tp, 0, sizeof(struct tcpcb)); 210 233 tp->seg_next = tp->seg_prev = ptr_to_u32((struct tcpiphdr *)tp); 211 234 tp->t_maxseg = tcp_mssdflt; 212 235 213 236 tp->t_flags = tcp_do_rfc1323 ? (TF_REQ_SCALE|TF_REQ_TSTMP) : 0; 214 237 tp->t_socket = so; 215 238 216 239 /* 217 240 * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no … … 223 246 tp->t_rttmin = TCPTV_MIN; 224 247 225 TCPT_RANGESET(tp->t_rxtcur, 248 TCPT_RANGESET(tp->t_rxtcur, 226 249 ((TCPTV_SRTTBASE >> 2) + (TCPTV_SRTTDFLT << 2)) >> 1, 227 250 TCPTV_MIN, TCPTV_REXMTMAX); … … 230 253 tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT; 231 254 tp->t_state = TCPS_CLOSED; 232 255 233 256 so->so_tcpcb = tp; 234 257 … … 241 264 * then send a RST to peer. 242 265 */ 243 struct tcpcb *tcp_drop(struct tcpcb *tp, int err) 266 #ifdef VBOX 267 struct tcpcb *tcp_drop(PNATState pData, struct tcpcb *tp, int err) 268 #else /* !VBOX */ 269 struct tcpcb *tcp_drop(struct tcpcb *tp, int err) 270 #endif /* !VBOX */ 244 271 { 245 272 /* tcp_drop(tp, errno) … … 252 279 DEBUG_ARG("tp = %lx", (long)tp); 253 280 DEBUG_ARG("errno = %d", errno); 254 281 255 282 if (TCPS_HAVERCVDSYN(tp->t_state)) { 256 283 tp->t_state = TCPS_CLOSED; 284 #ifdef VBOX 285 (void) tcp_output(pData, tp); 286 #else /* !VBOX */ 257 287 (void) tcp_output(tp); 288 #endif /* !VBOX */ 258 289 tcpstat.tcps_drops++; 259 290 } else … … 263 294 */ 264 295 /* so->so_error = errno; */ 296 #ifdef VBOX 297 return (tcp_close(pData, tp)); 298 #else /* !VBOX */ 265 299 return (tcp_close(tp)); 300 #endif /* !VBOX */ 266 301 } 267 302 … … 273 308 */ 274 309 struct tcpcb * 310 #ifdef VBOX 311 tcp_close(PNATState pData, register struct tcpcb *tp) 312 #else /* !VBOX */ 275 313 tcp_close(tp) 276 314 register struct tcpcb *tp; 315 #endif /* !VBOX */ 277 316 { 278 317 register struct tcpiphdr *t; … … 282 321 DEBUG_CALL("tcp_close"); 283 322 DEBUG_ARG("tp = %lx", (long )tp); 284 323 285 324 /* free the reassembly queue, if any */ 286 325 t = u32_to_ptr(tp->seg_next, struct tcpiphdr *); … … 289 328 m = REASS_MBUF_GET(u32_to_ptr(t->ti_prev, struct tcpiphdr *)); 290 329 remque_32(u32_to_ptr(t->ti_prev, struct tcpiphdr *)); 330 #ifdef VBOX 331 m_freem(pData, m); 332 #else /* !VBOX */ 291 333 m_freem(m); 334 #endif /* !VBOX */ 292 335 } 293 336 /* It's static */ … … 306 349 sbfree(&so->so_rcv); 307 350 sbfree(&so->so_snd); 351 #ifdef VBOX 352 sofree(pData, so); 353 #else /* !VBOX */ 308 354 sofree(so); 355 #endif /* !VBOX */ 309 356 tcpstat.tcps_closed++; 310 357 return ((struct tcpcb *)0); … … 352 399 */ 353 400 void 401 #ifdef VBOX 402 tcp_sockclosed(PNATState pData, struct tcpcb *tp) 403 #else /* !VBOX */ 354 404 tcp_sockclosed(tp) 355 405 struct tcpcb *tp; 406 #endif /* !VBOX */ 356 407 { 357 408 358 409 DEBUG_CALL("tcp_sockclosed"); 359 410 DEBUG_ARG("tp = %lx", (long)tp); 360 411 361 412 switch (tp->t_state) { 362 413 … … 365 416 case TCPS_SYN_SENT: 366 417 tp->t_state = TCPS_CLOSED; 418 #ifdef VBOX 419 tp = tcp_close(pData, tp); 420 #else /* !VBOX */ 367 421 tp = tcp_close(tp); 422 #endif /* !VBOX */ 368 423 break; 369 424 … … 381 436 soisfdisconnected(tp->t_socket); 382 437 if (tp) 438 #ifdef VBOX 439 tcp_output(pData, tp); 440 #else /* !VBOX */ 383 441 tcp_output(tp); 442 #endif /* !VBOX */ 384 443 } 385 444 386 /* 445 /* 387 446 * Connect to a host on the Internet 388 447 * Called by tcp_input … … 391 450 * else return -1 means we're still connecting 392 451 * The return value is almost always -1 since the socket is 393 * nonblocking. Connect returns after the SYN is sent, and does 452 * nonblocking. Connect returns after the SYN is sent, and does 394 453 * not wait for ACK+SYN. 395 454 */ 455 #ifdef VBOX 456 int tcp_fconnect(PNATState pData, struct socket *so) 457 #else /* !VBOX */ 396 458 int tcp_fconnect(so) 397 459 struct socket *so; 460 #endif /* !VBOX */ 398 461 { 399 462 int ret=0; 400 463 401 464 DEBUG_CALL("tcp_fconnect"); 402 465 DEBUG_ARG("so = %lx", (long )so); … … 411 474 opt = 1; 412 475 setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(opt )); 413 476 414 477 addr.sin_family = AF_INET; 415 478 if ((so->so_faddr.s_addr & htonl(0xffffff00)) == special_addr.s_addr) { … … 427 490 addr.sin_addr = so->so_faddr; 428 491 addr.sin_port = so->so_fport; 429 492 430 493 DEBUG_MISC((dfd, " connect()ing, addr.sin_port=%d, " 431 "addr.sin_addr.s_addr=%.16s\n", 494 "addr.sin_addr.s_addr=%.16s\n", 432 495 ntohs(addr.sin_port), inet_ntoa(addr.sin_addr))); 433 496 /* We don't care what port we get */ 434 497 ret = connect(s,(struct sockaddr *)&addr,sizeof (addr)); 435 498 436 499 /* 437 500 * If it's not in progress, it failed, so we just return 0, … … 446 509 /* 447 510 * Accept the socket and connect to the local-host 448 * 511 * 449 512 * We have a problem. The correct thing to do would be 450 513 * to first connect to the local-host, and only if the 451 514 * connection is accepted, then do an accept() here. 452 * But, a) we need to know who's trying to connect 515 * But, a) we need to know who's trying to connect 453 516 * to the socket to be able to SYN the local-host, and 454 517 * b) we are already connected to the foreign host by 455 518 * the time it gets to accept(), so... We simply accept 456 519 * here and SYN the local-host. 457 */ 520 */ 458 521 void 522 #ifdef VBOX 523 tcp_connect(PNATState pData, struct socket *inso) 524 #else /* !VBOX */ 459 525 tcp_connect(inso) 460 526 struct socket *inso; 527 #endif /* !VBOX */ 461 528 { 462 529 struct socket *so; … … 472 539 DEBUG_CALL("tcp_connect"); 473 540 DEBUG_ARG("inso = %lx", (long)inso); 474 541 475 542 /* 476 543 * If it's an SS_ACCEPTONCE socket, no need to socreate() … … 486 553 return; 487 554 } 555 #ifdef VBOX 556 if (tcp_attach(pData, so) < 0) { 557 #else /* !VBOX */ 488 558 if (tcp_attach(so) < 0) { 559 #endif /* !VBOX */ 489 560 free(so); /* NOT sofree */ 490 561 return; … … 493 564 so->so_lport = inso->so_lport; 494 565 } 495 566 567 #ifdef VBOX 568 (void) tcp_mss(pData, sototcpcb(so), 0); 569 #else /* !VBOX */ 496 570 (void) tcp_mss(sototcpcb(so), 0); 571 #endif /* !VBOX */ 497 572 498 573 if ((s = accept(inso->s,(struct sockaddr *)&addr,&addrlen)) < 0) { 574 #ifdef VBOX 575 tcp_close(pData, sototcpcb(so)); /* This will sofree() as well */ 576 #else /* !VBOX */ 499 577 tcp_close(sototcpcb(so)); /* This will sofree() as well */ 578 #endif /* !VBOX */ 500 579 return; 501 580 } … … 513 592 if (so->so_faddr.s_addr == 0 || so->so_faddr.s_addr == loopback_addr.s_addr) 514 593 so->so_faddr = alias_addr; 515 594 516 595 /* Close the accept() socket, set right state */ 517 596 if (inso->so_state & SS_FACCEPTONCE) { … … 521 600 } 522 601 so->s = s; 523 602 524 603 so->so_iptos = tcp_tos(so); 525 604 tp = sototcpcb(so); 526 605 527 606 tcp_template(tp); 528 607 529 608 /* Compute window scaling to request. */ 530 609 /* while (tp->request_r_scale < TCP_MAX_WINSHIFT && … … 535 614 /* soisconnecting(so); */ /* NOFDREF used instead */ 536 615 tcpstat.tcps_connattempt++; 537 616 538 617 tp->t_state = TCPS_SYN_SENT; 539 618 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; 540 tp->iss = tcp_iss; 619 tp->iss = tcp_iss; 541 620 tcp_iss += TCP_ISSINCR/2; 542 621 tcp_sendseqinit(tp); 622 #ifdef VBOX 623 tcp_output(pData, tp); 624 #else /* !VBOX */ 543 625 tcp_output(tp); 626 #endif /* !VBOX */ 544 627 } 545 628 … … 548 631 */ 549 632 int 633 #ifdef VBOX 634 tcp_attach(PNATState pData, struct socket *so) 635 #else /* !VBOX */ 550 636 tcp_attach(so) 551 637 struct socket *so; 638 #endif /* !VBOX */ 552 639 { 553 640 if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) 554 641 return -1; 555 642 556 643 insque(so, &tcb); 557 644 … … 562 649 * Set the socket's type of service field 563 650 */ 651 #ifdef VBOX 652 static const struct tos_t tcptos[] = { 653 #else /* !VBOX */ 564 654 struct tos_t tcptos[] = { 655 #endif /* !VBOX */ 565 656 {0, 20, IPTOS_THROUGHPUT, 0}, /* ftp data */ 566 657 {21, 21, IPTOS_LOWDELAY, EMU_FTP}, /* ftp control */ … … 578 669 }; 579 670 671 #ifndef VBOX 580 672 struct emu_t *tcpemu = 0; 581 673 #endif /* !VBOX */ 674 582 675 /* 583 676 * Return TOS according to the above table … … 588 681 { 589 682 int i = 0; 683 #ifndef VBOX 590 684 struct emu_t *emup; 591 685 #endif /* !VBOX */ 686 592 687 while(tcptos[i].tos) { 593 688 if ((tcptos[i].fport && (ntohs(so->so_fport) == tcptos[i].fport)) || … … 598 693 i++; 599 694 } 600 695 696 #ifdef VBOX 697 /* No user-added emulators supported. */ 698 #else /* !VBOX */ 601 699 /* Nope, lets see if there's a user-added one */ 602 700 for (emup = tcpemu; emup; emup = emup->next) { … … 607 705 } 608 706 } 609 707 #endif /* !VBOX */ 708 610 709 return 0; 611 710 } 612 711 712 #ifndef VBOX 613 713 int do_echo = -1; 714 #endif /* !VBOX */ 614 715 615 716 /* … … 618 719 * initiated by the server) and IRC (DCC CHAT and 619 720 * DCC SEND) for now 620 * 721 * 621 722 * NOTE: It's possible to crash SLiRP by sending it 622 723 * unstandard strings to emulate... if this is a problem, … … 624 725 * 625 726 * XXX Assumes the whole command came in one packet 626 * 727 * 627 728 * XXX Some ftp clients will have their TOS set to 628 729 * LOWDELAY and so Nagel will kick in. Because of this, … … 631 732 * DCC doesn't have this problem because there's other stuff 632 733 * in the packet before the DCC command. 633 * 634 * Return 1 if the mbuf m is still valid and should be 734 * 735 * Return 1 if the mbuf m is still valid and should be 635 736 * sbappend()ed 636 * 737 * 637 738 * NOTE: if you return 0 you MUST m_free() the mbuf! 638 739 */ 639 740 int 741 #ifdef VBOX 742 tcp_emu(PNATState pData, struct socket *so, struct mbuf *m) 743 #else /* !VBOX */ 640 744 tcp_emu(so, m) 641 745 struct socket *so; 642 746 struct mbuf *m; 747 #endif /* !VBOX */ 643 748 { 644 749 u_int n1, n2, n3, n4, n5, n6; … … 647 752 u_int lport; 648 753 char *bptr; 649 754 650 755 DEBUG_CALL("tcp_emu"); 651 756 DEBUG_ARG("so = %lx", (long)so); 652 757 DEBUG_ARG("m = %lx", (long)m); 653 758 654 759 switch(so->so_emu) { 655 760 int x, i; 656 761 657 762 case EMU_IDENT: 658 763 /* 659 764 * Identification protocol as per rfc-1413 660 765 */ 661 766 662 767 { 663 768 struct socket *tmpso; … … 669 774 #endif /* VBOX */ 670 775 struct sbuf *so_rcv = &so->so_rcv; 671 776 672 777 memcpy(so_rcv->sb_wptr, m->m_data, m->m_len); 673 778 so_rcv->sb_wptr += m->m_len; … … 699 804 so_rcv->sb_wptr = so_rcv->sb_data + so_rcv->sb_cc; 700 805 } 806 #ifdef VBOX 807 m_free(pData, m); 808 #else /* !VBOX */ 701 809 m_free(m); 810 #endif /* !VBOX */ 702 811 return 0; 703 812 } 704 813 705 814 #if 0 706 815 case EMU_RLOGIN: … … 717 826 struct sbuf *so_snd = &so->so_snd; 718 827 struct sbuf *so_rcv = &so->so_rcv; 719 828 720 829 /* First check if they have a priveladged port, or too much data has arrived */ 721 830 if (ntohs(so->so_lport) > 1023 || ntohs(so->so_lport) < 512 || … … 728 837 return 0; 729 838 } 730 839 731 840 /* Append the current data */ 732 841 memcpy(so_rcv->sb_wptr, m->m_data, m->m_len); … … 734 843 so_rcv->sb_rptr += m->m_len; 735 844 m_free(m); 736 845 737 846 /* 738 847 * Check if we have all the initial options, … … 766 875 } 767 876 } 768 877 769 878 if (n != 4) 770 879 return 0; 771 880 772 881 /* We have it, set our term variable and fork_exec() */ 773 882 #ifdef HAVE_SETENV … … 779 888 term[0] = 0; 780 889 so->so_emu = 0; 781 890 782 891 /* And finally, send the client a 0 character */ 783 892 so_snd->sb_wptr[0] = 0; 784 893 so_snd->sb_wptr++; 785 894 so_snd->sb_cc++; 786 895 787 896 return 0; 788 897 } 789 898 790 899 case EMU_RSH: 791 900 /* … … 801 910 struct sbuf *so_snd = &so->so_snd; 802 911 struct sbuf *so_rcv = &so->so_rcv; 803 912 804 913 /* First check if they have a priveladged port, or too much data has arrived */ 805 914 if (ntohs(so->so_lport) > 1023 || ntohs(so->so_lport) < 512 || … … 812 921 return 0; 813 922 } 814 923 815 924 /* Append the current data */ 816 925 memcpy(so_rcv->sb_wptr, m->m_data, m->m_len); … … 818 927 so_rcv->sb_rptr += m->m_len; 819 928 m_free(m); 820 929 821 930 /* 822 931 * Check if we have all the initial options, … … 854 963 ns->so_fport=htons(IPPORT_RESERVED-1); /* Use a fake port. */ 855 964 856 if (ns->so_faddr.s_addr == 0 || 965 if (ns->so_faddr.s_addr == 0 || 857 966 ns->so_faddr.s_addr == loopback_addr.s_addr) 858 967 ns->so_faddr = alias_addr; … … 860 969 ns->so_iptos = tcp_tos(ns); 861 970 tp = sototcpcb(ns); 862 971 863 972 tcp_template(tp); 864 973 865 974 /* Compute window scaling to request. */ 866 975 /* while (tp->request_r_scale < TCP_MAX_WINSHIFT && … … 872 981 873 982 tcpstat.tcps_connattempt++; 874 983 875 984 tp->t_state = TCPS_SYN_SENT; 876 985 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; 877 tp->iss = tcp_iss; 986 tp->iss = tcp_iss; 878 987 tcp_iss += TCP_ISSINCR/2; 879 988 tcp_sendseqinit(tp); … … 891 1000 } 892 1001 } 893 1002 894 1003 if (n != 4) 895 1004 return 0; 896 1005 897 1006 rsh_exec(so,so->extra, user, inet_ntoa(so->so_faddr), args); 898 1007 so->so_emu = 0; 899 1008 so->extra=NULL; 900 1009 901 1010 /* And finally, send the client a 0 character */ 902 1011 so_snd->sb_wptr[0] = 0; 903 1012 so_snd->sb_wptr++; 904 1013 so_snd->sb_cc++; 905 1014 906 1015 return 0; 907 1016 } … … 912 1021 struct sbuf *so_snd = &so->so_snd; 913 1022 struct sbuf *so_rcv = &so->so_rcv; 914 1023 915 1024 /* 916 1025 * If there is binary data here, we save it in so->so_m … … 927 1036 } 928 1037 } /* if(so->so_m==NULL) */ 929 1038 930 1039 /* 931 1040 * Append the line 932 1041 */ 933 1042 sbappendsb(so_rcv, m); 934 1043 935 1044 /* To avoid going over the edge of the buffer, we reset it */ 936 1045 if (so_snd->sb_cc == 0) 937 1046 so_snd->sb_wptr = so_snd->sb_rptr = so_snd->sb_data; 938 1047 939 1048 /* 940 1049 * A bit of a hack: … … 955 1064 } else 956 1065 m_free(m); 957 1066 958 1067 num = 0; 959 1068 while (num < so->so_rcv.sb_cc) { … … 961 1070 *(so->so_rcv.sb_rptr + num) == '\r') { 962 1071 int n; 963 1072 964 1073 *(so_rcv->sb_rptr + num) = 0; 965 1074 if (ctl_password && !ctl_password_ok) { … … 998 1107 return 0; 999 1108 } 1000 #endif 1109 #endif 1001 1110 case EMU_FTP: /* ftp */ 1002 1111 *(m->m_data+m->m_len) = 0; /* NULL terminate for strstr */ … … 1004 1113 /* 1005 1114 * Need to emulate the PORT command 1006 */ 1007 #ifdef VBOX 1008 x = sscanf(bptr, "ORT %u,%u,%u,%u,%u,%u\r\n%256[^\177]", 1115 */ 1116 #ifdef VBOX 1117 x = sscanf(bptr, "ORT %u,%u,%u,%u,%u,%u\r\n%256[^\177]", 1009 1118 &n1, &n2, &n3, &n4, &n5, &n6, buff); 1010 1119 #else 1011 x = sscanf(bptr, "ORT %d,%d,%d,%d,%d,%d\r\n%256[^\177]", 1120 x = sscanf(bptr, "ORT %d,%d,%d,%d,%d,%d\r\n%256[^\177]", 1012 1121 &n1, &n2, &n3, &n4, &n5, &n6, buff); 1013 1122 #endif 1014 1123 if (x < 6) 1015 1124 return 1; 1016 1125 1017 1126 laddr = htonl((n1 << 24) | (n2 << 16) | (n3 << 8) | (n4)); 1018 1127 lport = htons((n5 << 8) | (n6)); 1019 1128 1129 #ifdef VBOX 1130 if ((so = solisten(pData, 0, laddr, lport, SS_FACCEPTONCE)) == NULL) 1131 #else /* !VBOX */ 1020 1132 if ((so = solisten(0, laddr, lport, SS_FACCEPTONCE)) == NULL) 1133 #endif /* !VBOX */ 1021 1134 return 1; 1022 1135 1023 1136 n6 = ntohs(so->so_fport); 1024 1137 1025 1138 n5 = (n6 >> 8) & 0xff; 1026 1139 n6 &= 0xff; 1027 1140 1028 1141 laddr = ntohl(so->so_faddr.s_addr); 1029 1142 1030 1143 n1 = ((laddr >> 24) & 0xff); 1031 1144 n2 = ((laddr >> 16) & 0xff); 1032 1145 n3 = ((laddr >> 8) & 0xff); 1033 1146 n4 = (laddr & 0xff); 1034 1147 1035 1148 m->m_len = bptr - m->m_data; /* Adjust length */ 1036 m->m_len += sprintf(bptr,"ORT %d,%d,%d,%d,%d,%d\r\n%s", 1149 m->m_len += sprintf(bptr,"ORT %d,%d,%d,%d,%d,%d\r\n%s", 1037 1150 n1, n2, n3, n4, n5, n6, x==7?buff:""); 1038 1151 return 1; … … 1050 1163 if (x < 6) 1051 1164 return 1; 1052 1165 1053 1166 laddr = htonl((n1 << 24) | (n2 << 16) | (n3 << 8) | (n4)); 1054 1167 lport = htons((n5 << 8) | (n6)); 1055 1168 1169 #ifdef VBOX 1170 if ((so = solisten(pData, 0, laddr, lport, SS_FACCEPTONCE)) == NULL) 1171 #else /* !VBOX */ 1056 1172 if ((so = solisten(0, laddr, lport, SS_FACCEPTONCE)) == NULL) 1173 #endif /* !VBOX */ 1057 1174 return 1; 1058 1175 1059 1176 n6 = ntohs(so->so_fport); 1060 1177 1061 1178 n5 = (n6 >> 8) & 0xff; 1062 1179 n6 &= 0xff; 1063 1180 1064 1181 laddr = ntohl(so->so_faddr.s_addr); 1065 1182 1066 1183 n1 = ((laddr >> 24) & 0xff); 1067 1184 n2 = ((laddr >> 16) & 0xff); 1068 1185 n3 = ((laddr >> 8) & 0xff); 1069 1186 n4 = (laddr & 0xff); 1070 1187 1071 1188 m->m_len = bptr - m->m_data; /* Adjust length */ 1072 1189 m->m_len += sprintf(bptr,"27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%s", 1073 1190 n1, n2, n3, n4, n5, n6, x==7?buff:""); 1074 1191 1075 1192 return 1; 1076 1193 } 1077 1194 1078 1195 return 1; 1079 1196 1080 1197 case EMU_KSH: 1081 1198 /* … … 1093 1210 } 1094 1211 if (m->m_data[m->m_len-1] == '\0' && lport != 0 && 1212 #ifdef VBOX 1213 (so = solisten(pData, 0, so->so_laddr.s_addr, htons(lport), SS_FACCEPTONCE)) != NULL) 1214 #else /* !VBOX */ 1095 1215 (so = solisten(0, so->so_laddr.s_addr, htons(lport), SS_FACCEPTONCE)) != NULL) 1216 #endif /* !VBOX */ 1096 1217 m->m_len = sprintf(m->m_data, "%d", ntohs(so->so_fport))+1; 1097 1218 return 1; 1098 1219 1099 1220 case EMU_IRC: 1100 1221 /* … … 1104 1225 if ((bptr = (char *)strstr(m->m_data, "DCC")) == NULL) 1105 1226 return 1; 1106 1227 1107 1228 /* The %256s is for the broken mIRC */ 1108 1229 if (sscanf(bptr, "DCC CHAT %256s %u %u", buff, &laddr, &lport) == 3) { 1230 #ifdef VBOX 1231 if ((so = solisten(pData, 0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL) 1232 #else /* !VBOX */ 1109 1233 if ((so = solisten(0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL) 1234 #endif /* !VBOX */ 1110 1235 return 1; 1111 1236 1112 1237 m->m_len = bptr - m->m_data; /* Adjust length */ 1113 1238 m->m_len += sprintf(bptr, "DCC CHAT chat %lu %u%c\n", … … 1115 1240 ntohs(so->so_fport), 1); 1116 1241 } else if (sscanf(bptr, "DCC SEND %256s %u %u %u", buff, &laddr, &lport, &n1) == 4) { 1242 #ifdef VBOX 1243 if ((so = solisten(pData, 0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL) 1244 #else /* !VBOX */ 1117 1245 if ((so = solisten(0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL) 1246 #endif /* !VBOX */ 1118 1247 return 1; 1119 1248 1120 1249 m->m_len = bptr - m->m_data; /* Adjust length */ 1121 m->m_len += sprintf(bptr, "DCC SEND %s %lu %u %u%c\n", 1250 m->m_len += sprintf(bptr, "DCC SEND %s %lu %u %u%c\n", 1122 1251 buff, (unsigned long)ntohl(so->so_faddr.s_addr), 1123 1252 ntohs(so->so_fport), n1, 1); 1124 1253 } else if (sscanf(bptr, "DCC MOVE %256s %u %u %u", buff, &laddr, &lport, &n1) == 4) { 1254 #ifdef VBOX 1255 if ((so = solisten(pData, 0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL) 1256 #else /* !VBOX */ 1125 1257 if ((so = solisten(0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL) 1258 #endif /* !VBOX */ 1126 1259 return 1; 1127 1260 1128 1261 m->m_len = bptr - m->m_data; /* Adjust length */ 1129 1262 m->m_len += sprintf(bptr, "DCC MOVE %s %lu %u %u%c\n", … … 1133 1266 return 1; 1134 1267 1268 #ifdef VBOX 1269 /** @todo Disabled EMU_REALAUDIO, because it uses a static variable. 1270 * This is not legal when more than one slirp instance is active. */ 1271 #else /* !VBOX */ 1135 1272 case EMU_REALAUDIO: 1136 /* 1273 /* 1137 1274 * RealAudio emulation - JP. We must try to parse the incoming 1138 1275 * data and try to find the two characters that contain the … … 1142 1279 * The 1.0 beta versions of the player are not supported 1143 1280 * any more. 1144 * 1281 * 1145 1282 * A typical packet for player version 1.0 (release version): 1146 * 1147 * 0000:50 4E 41 00 05 1283 * 1284 * 0000:50 4E 41 00 05 1148 1285 * 0000:00 01 00 02 1B D7 00 00 67 E6 6C DC 63 00 12 50 .....×..gælÜc..P 1149 1286 * 0010:4E 43 4C 49 45 4E 54 20 31 30 31 20 41 4C 50 48 NCLIENT 101 ALPH 1150 1287 * 0020:41 6C 00 00 52 00 17 72 61 66 69 6C 65 73 2F 76 Al..R..rafiles/v 1151 1288 * 0030:6F 61 2F 65 6E 67 6C 69 73 68 5F 2E 72 61 79 42 oa/english_.rayB 1152 * 1289 * 1153 1290 * Now the port number 0x1BD7 is found at offset 0x04 of the 1154 1291 * Now the port number 0x1BD7 is found at offset 0x04 of the … … 1157 1294 * 1158 1295 * A typical packet for player version 2.0 (beta): 1159 * 1296 * 1160 1297 * 0000:50 4E 41 00 06 00 02 00 00 00 01 00 02 1B C1 00 PNA...........Á. 1161 1298 * 0010:00 67 75 78 F5 63 00 0A 57 69 6E 32 2E 30 2E 30 .guxõc..Win2.0.0 … … 1163 1300 * 0030:77 65 62 73 69 74 65 2F 32 30 72 65 6C 65 61 73 website/20releas 1164 1301 * 0040:65 2E 72 61 79 53 00 00 06 36 42 e.rayS...6B 1165 * 1302 * 1166 1303 * Port number 0x1BC1 is found at offset 0x0d. 1167 * 1304 * 1168 1305 * This is just a horrible switch statement. Variable ra tells 1169 1306 * us where we're going. 1170 1307 */ 1171 1308 1172 1309 bptr = m->m_data; 1173 1310 while (bptr < m->m_data + m->m_len) { 1174 1311 u_short p; 1175 1312 static int ra = 0; 1176 char ra_tbl[4]; 1177 1313 char ra_tbl[4]; 1314 1178 1315 ra_tbl[0] = 0x50; 1179 1316 ra_tbl[1] = 0x4e; 1180 1317 ra_tbl[2] = 0x41; 1181 1318 ra_tbl[3] = 0; 1182 1319 1183 1320 switch (ra) { 1184 1321 case 0: … … 1190 1327 } 1191 1328 break; 1192 1329 1193 1330 case 1: 1194 1331 /* … … 1204 1341 } 1205 1342 break; 1206 1207 case 4: 1208 /* 1343 1344 case 4: 1345 /* 1209 1346 * skip version number 1210 1347 */ 1211 1348 bptr++; 1212 1349 break; 1213 1214 case 5: 1350 1351 case 5: 1215 1352 /* 1216 1353 * The difference between versions 1.0 and … … 1222 1359 else 1223 1360 bptr += 4; 1224 break; 1225 1361 break; 1362 1226 1363 case 6: 1227 1364 /* This is the field containing the port 1228 1365 * number that RA-player is listening to. 1229 1366 */ 1230 lport = (((u_char*)bptr)[0] << 8) 1367 lport = (((u_char*)bptr)[0] << 8) 1231 1368 + ((u_char *)bptr)[1]; 1232 if (lport < 6970) 1369 if (lport < 6970) 1233 1370 lport += 256; /* don't know why */ 1234 1371 if (lport < 6970 || lport > 7170) 1235 1372 return 1; /* failed */ 1236 1373 1237 1374 /* try to get udp port between 6970 - 7170 */ 1238 1375 for (p = 6970; p < 7071; p++) { … … 1248 1385 *(u_char *)bptr++ = (p >> 8) & 0xff; 1249 1386 *(u_char *)bptr++ = p & 0xff; 1250 ra = 0; 1387 ra = 0; 1251 1388 return 1; /* port redirected, we're done */ 1252 break; 1253 1389 break; 1390 1254 1391 default: 1255 ra = 0; 1392 ra = 0; 1256 1393 } 1257 1394 ra++; 1258 1395 } 1259 return 1; 1260 1396 return 1; 1397 #endif /* !VBOX */ 1398 1261 1399 default: 1262 1400 /* Ooops, not emulated, won't call tcp_emu again */ … … 1272 1410 */ 1273 1411 int 1412 #ifdef VBOX 1413 tcp_ctl(PNATState pData, struct socket *so) 1414 #else /* !VBOX */ 1274 1415 tcp_ctl(so) 1275 1416 struct socket *so; 1417 #endif /* !VBOX */ 1276 1418 { 1277 1419 struct sbuf *sb = &so->so_snd; … … 1280 1422 int do_pty; 1281 1423 /* struct socket *tmpso; */ 1282 1424 1283 1425 DEBUG_CALL("tcp_ctl"); 1284 1426 DEBUG_ARG("so = %lx", (long )so); 1285 1427 1286 1428 #if 0 1287 1429 /* … … 1293 1435 return 0; 1294 1436 } 1295 #endif 1437 #endif 1296 1438 command = (ntohl(so->so_faddr.s_addr) & 0xff); 1297 1439 1298 1440 switch(command) { 1299 1441 default: /* Check for exec's */ 1300 1442 1301 1443 /* 1302 1444 * Check if it's pty_exec … … 1309 1451 } 1310 1452 } 1311 1453 1312 1454 /* 1313 1455 * Nothing bound.. 1314 1456 */ 1315 1457 /* tcp_fconnect(so); */ 1316 1458 1317 1459 /* FALLTHROUGH */ 1318 1460 case CTL_ALIAS: … … 1324 1466 do_exec: 1325 1467 DEBUG_MISC((dfd, " executing %s \n",ex_ptr->ex_exec)); 1468 #ifdef VBOX 1469 return(fork_exec(pData, so, ex_ptr->ex_exec, do_pty)); 1470 #else /* !VBOX */ 1326 1471 return(fork_exec(so, ex_ptr->ex_exec, do_pty)); 1327 1472 #endif /* !VBOX */ 1473 1328 1474 #if 0 1329 1475 case CTL_CMD: 1330 1476 for (tmpso = tcb.so_next; tmpso != &tcb; tmpso = tmpso->so_next) { 1331 if (tmpso->so_emu == EMU_CTL && 1332 !(tmpso->so_tcpcb? 1477 if (tmpso->so_emu == EMU_CTL && 1478 !(tmpso->so_tcpcb? 1333 1479 (tmpso->so_tcpcb->t_state & (TCPS_TIME_WAIT|TCPS_LAST_ACK)) 1334 1480 :0)) { … … 1350 1496 1351 1497 #if defined(VBOX) && SIZEOF_CHAR_P != 4 1352 /** Hash table used for translating pointers to unique uint32_t entries. 1498 /** Hash table used for translating pointers to unique uint32_t entries. 1353 1499 * The 0 entry is reserved for NULL pointers. */ 1354 1500 void *g_apvHash[16384]; … … 1377 1523 else 1378 1524 { 1379 /* 1380 * Try up to 10 times then assume it's an insertion. 1381 * If we didn't find a free entry by then, try another 100 times. 1525 /* 1526 * Try up to 10 times then assume it's an insertion. 1527 * If we didn't find a free entry by then, try another 100 times. 1382 1528 * If that fails, give up. 1383 1529 */ … … 1391 1537 { 1392 1538 /* check if we should give in.*/ 1393 if (--cTries > 0) 1539 if (--cTries > 0) 1394 1540 { 1395 1541 if (i1stFree != 0) … … 1405 1551 if (!cTries2) 1406 1552 { 1407 AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p g_cpvHashUsed=%d g_cpvHashCollisions=%u\n", 1553 AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p g_cpvHashUsed=%d g_cpvHashCollisions=%u\n", 1408 1554 pv, g_cpvHashUsed, g_cpvHashCollisions)); 1409 1555 i = 0; … … 1452 1598 if (RT_UNLIKELY(g_apvHash[iHint] != pv)) 1453 1599 { 1454 /* 1600 /* 1455 1601 * Try up to 120 times then assert. 1456 1602 */ … … 1469 1615 if (--cTries > 0) 1470 1616 { 1471 AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p g_cpvHashUsed=%u g_cpvHashCollisions=%u\n", 1617 AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p g_cpvHashUsed=%u g_cpvHashCollisions=%u\n", 1472 1618 pv, g_cpvHashUsed, g_cpvHashCollisions)); 1473 1619 return; … … 1481 1627 } 1482 1628 1483 #endif 1629 #endif -
trunk/src/VBox/Devices/Network/slirp/tcp_timer.c
r1 r1033 37 37 #include <slirp.h> 38 38 39 #ifndef VBOX 39 40 int tcp_keepidle = TCPTV_KEEP_IDLE; 40 41 int tcp_keepintvl = TCPTV_KEEPINTVL; … … 44 45 struct tcpstat tcpstat; /* tcp statistics */ 45 46 u_int32_t tcp_now; /* for RFC 1323 timestamps */ 47 #endif /* !VBOX */ 46 48 47 49 /* … … 49 51 */ 50 52 void 53 #ifdef VBOX 54 tcp_fasttimo(PNATState pData) 55 #else /* !VBOX */ 51 56 tcp_fasttimo() 57 #endif /* !VBOX */ 52 58 { 53 59 register struct socket *so; … … 55 61 56 62 DEBUG_CALL("tcp_fasttimo"); 57 63 58 64 so = tcb.so_next; 59 65 if (so) … … 64 70 tp->t_flags |= TF_ACKNOW; 65 71 tcpstat.tcps_delack++; 72 #ifdef VBOX 73 (void) tcp_output(pData, tp); 74 #else /*! VBOX */ 66 75 (void) tcp_output(tp); 76 #endif /* !VBOX */ 67 77 } 68 78 } … … 74 84 */ 75 85 void 86 #ifdef VBOX 87 tcp_slowtimo(PNATState pData) 88 #else /* !VBOX */ 76 89 tcp_slowtimo() 90 #endif /* !VBOX */ 77 91 { 78 92 register struct socket *ip, *ipnxt; … … 81 95 82 96 DEBUG_CALL("tcp_slowtimo"); 83 97 98 #ifndef VBOX 84 99 tcp_maxidle = TCPTV_KEEPCNT * tcp_keepintvl; 100 #endif /* !VBOX */ 85 101 /* 86 102 * Search through tcb's and update active timers. … … 96 112 for (i = 0; i < TCPT_NTIMERS; i++) { 97 113 if (tp->t_timer[i] && --tp->t_timer[i] == 0) { 114 #ifdef VBOX 115 tcp_timers(pData, tp,i); 116 #else /* !VBOX */ 98 117 tcp_timers(tp,i); 118 #endif /* !VBOX */ 99 119 if (ipnxt->so_prev != ip) 100 120 goto tpgone; … … 128 148 } 129 149 150 #ifdef VBOX 151 const int tcp_backoff[TCP_MAXRXTSHIFT + 1] = 152 #else /* !VBOX */ 130 153 int tcp_backoff[TCP_MAXRXTSHIFT + 1] = 154 #endif /* !VBOX */ 131 155 { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 }; 132 156 … … 135 159 */ 136 160 struct tcpcb * 161 #ifdef VBOX 162 tcp_timers(PNATState pData, register struct tcpcb *tp, int timer) 163 #else /* !VBOX */ 137 164 tcp_timers(tp, timer) 138 165 register struct tcpcb *tp; 139 166 int timer; 167 #endif /* !VBOX */ 140 168 { 141 169 register int rexmt; 142 170 143 171 DEBUG_CALL("tcp_timers"); 144 172 145 173 switch (timer) { 146 174 … … 156 184 tp->t_timer[TCPT_2MSL] = tcp_keepintvl; 157 185 else 186 #ifdef VBOX 187 tp = tcp_close(pData, tp); 188 #else /* !VBOX */ 158 189 tp = tcp_close(tp); 190 #endif /* !VBOX */ 159 191 break; 160 192 … … 165 197 */ 166 198 case TCPT_REXMT: 167 199 168 200 /* 169 201 * XXXXX If a packet has timed out, then remove all the queued 170 202 * packets for that session. 171 203 */ 172 204 173 205 if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) { 174 206 /* … … 179 211 * retransmitting, and eventually the connection dies... 180 212 * (this only happens on incoming data) 181 * 213 * 182 214 * So, if we were gonna drop the connection from too many retransmits, 183 215 * don't... instead halve the t_maxseg, which might break up the NULLs and 184 216 * let them through 185 * 217 * 186 218 * *sigh* 187 219 */ 188 220 189 221 tp->t_maxseg >>= 1; 190 222 if (tp->t_maxseg < 32) { … … 194 226 tp->t_rxtshift = TCP_MAXRXTSHIFT; 195 227 tcpstat.tcps_timeoutdrop++; 228 #ifdef VBOX 229 tp = tcp_drop(pData, tp, tp->t_softerror); 230 #else /* !VBOX */ 196 231 tp = tcp_drop(tp, tp->t_softerror); 232 #endif /* !VBOX */ 197 233 /* tp->t_softerror : ETIMEDOUT); */ /* XXX */ 198 234 return (tp); /* XXX */ 199 235 } 200 236 201 237 /* 202 238 * Set rxtshift to 6, which is still at the maximum … … 241 277 * window is larger than the path can handle, this 242 278 * exponential growth results in dropped packet(s) 243 * almost immediately. To get more time between 279 * almost immediately. To get more time between 244 280 * drops but still "push" the network to take advantage 245 281 * of improving conditions, we switch from exponential … … 260 296 tp->t_dupacks = 0; 261 297 } 298 #ifdef VBOX 299 (void) tcp_output(pData, tp); 300 #else /* !VBOX */ 262 301 (void) tcp_output(tp); 302 #endif /* !VBOX */ 263 303 break; 264 304 … … 271 311 tcp_setpersist(tp); 272 312 tp->t_force = 1; 313 #ifdef VBOX 314 (void) tcp_output(pData, tp); 315 #else /* !VBOX */ 273 316 (void) tcp_output(tp); 317 #endif /* !VBOX */ 274 318 tp->t_force = 0; 275 319 break; … … 309 353 tp->rcv_nxt - 1, tp->snd_una - 1, 0); 310 354 #else 355 #ifdef VBOX 356 tcp_respond(pData, tp, &tp->t_template, (struct mbuf *)NULL, 357 tp->rcv_nxt, tp->snd_una - 1, 0); 358 #else /* !VBOX */ 311 359 tcp_respond(tp, &tp->t_template, (struct mbuf *)NULL, 312 360 tp->rcv_nxt, tp->snd_una - 1, 0); 361 #endif /* !VBOX */ 313 362 #endif 314 363 tp->t_timer[TCPT_KEEP] = tcp_keepintvl; … … 319 368 dropit: 320 369 tcpstat.tcps_keepdrops++; 370 #ifdef VBOX 371 tp = tcp_drop(pData, tp, 0); /* ETIMEDOUT); */ 372 #else /* !VBOX */ 321 373 tp = tcp_drop(tp, 0); /* ETIMEDOUT); */ 374 #endif /* !VBOX */ 322 375 break; 323 376 } -
trunk/src/VBox/Devices/Network/slirp/tcp_timer.h
r1 r1033 127 127 } 128 128 129 #ifndef VBOX 129 130 extern int tcp_keepidle; /* time before keepalive probes begin */ 130 131 extern int tcp_keepintvl; /* time between keepalive probes */ 131 132 extern int tcp_maxidle; /* time to drop after starting probes */ 133 #endif /* !VBOX */ 132 134 extern int tcp_ttl; /* time to live for TCP segs */ 135 #ifdef VBOX 136 extern const int tcp_backoff[]; 137 #else /* !VBOX */ 133 138 extern int tcp_backoff[]; 139 #endif /* !VBOX */ 134 140 135 141 struct tcpcb; 136 142 143 #ifdef VBOX 144 void tcp_fasttimo _P((PNATState)); 145 void tcp_slowtimo _P((PNATState)); 146 #else /* !VBOX */ 137 147 void tcp_fasttimo _P((void)); 138 148 void tcp_slowtimo _P((void)); 149 #endif /* !VBOX */ 139 150 void tcp_canceltimers _P((struct tcpcb *)); 151 #ifdef VBOX 152 struct tcpcb * tcp_timers _P((PNATState, register struct tcpcb *, int)); 153 #else /* !VBOX */ 140 154 struct tcpcb * tcp_timers _P((register struct tcpcb *, int)); 155 #endif /* !VBOX */ 141 156 142 157 #endif -
trunk/src/VBox/Devices/Network/slirp/tcp_var.h
r530 r1033 50 50 typedef u_int32_t tcpiphdrp_32; 51 51 # ifdef VBOX 52 # include <iprt/types.h> 52 # include <iprt/types.h> 53 53 # include <iprt/assert.h> 54 54 55 55 /* VBox change that's to much bother to #ifdef. */ 56 # define u32ptr_done(u32, ptr) VBoxU32PtrDone((ptr), (u32)) 56 # define u32ptr_done(u32, ptr) VBoxU32PtrDone((ptr), (u32)) 57 57 # define ptr_to_u32(ptr) VBoxU32PtrHash((ptr)) 58 58 # define u32_to_ptr(u32, type) ((type)VBoxU32PtrLookup(u32)) … … 62 62 extern void VBoxU32PtrDone(void *pv, uint32_t iHint); 63 63 extern uint32_t VBoxU32PtrHashSlow(void *pv); 64 64 65 65 /** Hash the pointer, inserting it if need be. */ 66 66 DECLINLINE(uint32_t) VBoxU32PtrHash(void *pv) … … 77 77 Assert(i < RT_ELEMENTS(g_apvHash)); 78 78 pv = g_apvHash[i]; 79 Assert(pv || !i); 79 Assert(pv || !i); 80 80 return pv; 81 81 } … … 238 238 * but that's inconvenient at the moment. 239 239 */ 240 #ifdef VBOX 241 struct tcpstat_t { 242 #else /* !VBOX */ 240 243 struct tcpstat { 244 #endif /* !VBOX */ 241 245 u_long tcps_connattempt; /* connections initiated */ 242 246 u_long tcps_accepts; /* connections accepted */ … … 294 298 }; 295 299 300 #ifndef VBOX 296 301 extern struct tcpstat tcpstat; /* tcp statistics */ 297 302 extern u_int32_t tcp_now; /* for RFC 1323 timestamps */ 303 #endif /* !VBOX */ 298 304 299 305 #endif -
trunk/src/VBox/Devices/Network/slirp/tftp.c
r1023 r1033 1 1 /* 2 2 * tftp.c - a simple, read-only tftp server for qemu 3 * 3 * 4 4 * Copyright (c) 2004 Magnus Damm <[email protected]> 5 * 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 7 * of this software and associated documentation files (the "Software"), to deal … … 25 25 #include <slirp.h> 26 26 27 #ifndef VBOX 27 28 struct tftp_session { 28 29 int in_use; 29 30 unsigned char filename[TFTP_FILENAME_MAX]; 30 31 31 32 struct in_addr client_ip; 32 33 u_int16_t client_port; 33 34 34 35 int timestamp; 35 36 }; … … 38 39 39 40 const char *tftp_prefix; 40 41 #endif /* !VBOX */ 42 43 #ifdef VBOX 44 static void tftp_session_update(PNATState pData, struct tftp_session *spt) 45 #else /* !VBOX */ 41 46 static void tftp_session_update(struct tftp_session *spt) 47 #endif /* !VBOX */ 42 48 { 43 49 spt->timestamp = curtime; … … 50 56 } 51 57 58 #ifdef VBOX 59 static int tftp_session_allocate(PNATState pData, struct tftp_t *tp) 60 #else /* !VBOX */ 52 61 static int tftp_session_allocate(struct tftp_t *tp) 62 #endif /* !VBOX */ 53 63 { 54 64 struct tftp_session *spt; … … 73 83 spt->client_port = tp->udp.uh_sport; 74 84 85 #ifdef VBOX 86 tftp_session_update(pData, spt); 87 #else /* !VBOX */ 75 88 tftp_session_update(spt); 89 #endif /* !VBOX */ 76 90 77 91 return k; 78 92 } 79 93 94 #ifdef VBOX 95 static int tftp_session_find(PNATState pData, struct tftp_t *tp) 96 #else /* !VBOX */ 80 97 static int tftp_session_find(struct tftp_t *tp) 98 #endif /* !VBOX */ 81 99 { 82 100 struct tftp_session *spt; … … 98 116 } 99 117 118 #ifdef VBOX 119 static int tftp_read_data(PNATState pData, struct tftp_session *spt, u_int16_t block_nr, 120 u_int8_t *buf, int len) 121 #else /* !VBOX */ 100 122 static int tftp_read_data(struct tftp_session *spt, u_int16_t block_nr, 101 123 u_int8_t *buf, int len) 124 #endif /* !VBOX */ 102 125 { 103 126 int fd; … … 133 156 } 134 157 135 static int tftp_send_oack(struct tftp_session *spt, 158 #ifdef VBOX 159 static int tftp_send_oack(PNATState pData, 160 struct tftp_session *spt, 136 161 const char *key, uint32_t value, 137 162 struct tftp_t *recv_tp) 163 #else /* !VBOX */ 164 static int tftp_send_oack(struct tftp_session *spt, 165 const char *key, uint32_t value, 166 struct tftp_t *recv_tp) 167 #endif /* !VBOX */ 138 168 { 139 169 struct sockaddr_in saddr, daddr; … … 142 172 int n = 0; 143 173 174 #ifdef VBOX 175 m = m_get(pData); 176 #else /* !VBOX */ 144 177 m = m_get(); 178 #endif /* !VBOX */ 145 179 146 180 if (!m) … … 152 186 tp = (void *)m->m_data; 153 187 m->m_data += sizeof(struct udpiphdr); 154 188 155 189 tp->tp_op = htons(TFTP_OACK); 190 #ifdef VBOX 191 n += sprintf((char *)tp->x.tp_buf + n, "%s", key) + 1; 192 n += sprintf((char *)tp->x.tp_buf + n, "%u", value) + 1; 193 #else /* !VBOX */ 156 194 n += sprintf(tp->x.tp_buf + n, "%s", key) + 1; 157 195 n += sprintf(tp->x.tp_buf + n, "%u", value) + 1; 196 #endif /* !VBOX */ 158 197 159 198 saddr.sin_addr = recv_tp->ip.ip_dst; 160 199 saddr.sin_port = recv_tp->udp.uh_dport; 161 200 162 201 daddr.sin_addr = spt->client_ip; 163 202 daddr.sin_port = spt->client_port; 164 203 165 m->m_len = sizeof(struct tftp_t) - 514 + n - 204 m->m_len = sizeof(struct tftp_t) - 514 + n - 166 205 sizeof(struct ip) - sizeof(struct udphdr); 206 #ifdef VBOX 207 udp_output2(pData, NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); 208 #else /* !VBOX */ 167 209 udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); 210 #endif /* !VBOX */ 168 211 169 212 return 0; … … 172 215 173 216 174 static int tftp_send_error(struct tftp_session *spt, 217 #ifdef VBOX 218 static int tftp_send_error(PNATState pData, 219 struct tftp_session *spt, 175 220 u_int16_t errorcode, const char *msg, 176 221 struct tftp_t *recv_tp) 222 #else /* !VBOX */ 223 static int tftp_send_error(struct tftp_session *spt, 224 u_int16_t errorcode, const char *msg, 225 struct tftp_t *recv_tp) 226 #endif /* !VBOX */ 177 227 { 178 228 struct sockaddr_in saddr, daddr; … … 181 231 int nobytes; 182 232 233 #ifdef VBOX 234 m = m_get(pData); 235 #else /* !VBOX */ 183 236 m = m_get(); 237 #endif /* !VBOX */ 184 238 185 239 if (!m) { … … 192 246 tp = (void *)m->m_data; 193 247 m->m_data += sizeof(struct udpiphdr); 194 248 195 249 tp->tp_op = htons(TFTP_ERROR); 196 250 tp->x.tp_error.tp_error_code = htons(errorcode); … … 209 263 nobytes = 2; 210 264 211 m->m_len = sizeof(struct tftp_t) - 514 + 3 + strlen(msg) - 265 m->m_len = sizeof(struct tftp_t) - 514 + 3 + strlen(msg) - 212 266 sizeof(struct ip) - sizeof(struct udphdr); 213 267 268 #ifdef VBOX 269 udp_output2(pData, NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); 270 #else /* !VBOX */ 214 271 udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); 272 #endif /* !VBOX */ 215 273 216 274 tftp_session_terminate(spt); … … 219 277 } 220 278 221 static int tftp_send_data(struct tftp_session *spt, 279 #ifdef VBOX 280 static int tftp_send_data(PNATState pData, 281 struct tftp_session *spt, 222 282 u_int16_t block_nr, 223 283 struct tftp_t *recv_tp) 284 #else /* !VBOX */ 285 static int tftp_send_data(struct tftp_session *spt, 286 u_int16_t block_nr, 287 struct tftp_t *recv_tp) 288 #endif /* !VBOX */ 224 289 { 225 290 struct sockaddr_in saddr, daddr; … … 232 297 } 233 298 299 #ifdef VBOX 300 m = m_get(pData); 301 #else /* !VBOX */ 234 302 m = m_get(); 303 #endif /* !VBOX */ 235 304 236 305 if (!m) { … … 243 312 tp = (void *)m->m_data; 244 313 m->m_data += sizeof(struct udpiphdr); 245 314 246 315 tp->tp_op = htons(TFTP_DATA); 247 316 tp->x.tp_data.tp_block_nr = htons(block_nr); … … 253 322 daddr.sin_port = spt->client_port; 254 323 324 #ifdef VBOX 325 nobytes = tftp_read_data(pData, spt, block_nr - 1, tp->x.tp_data.tp_buf, 512); 326 #else /* !VBOX */ 255 327 nobytes = tftp_read_data(spt, block_nr - 1, tp->x.tp_data.tp_buf, 512); 328 #endif /* !VBOX */ 256 329 257 330 if (nobytes < 0) { 331 #ifdef VBOX 332 m_free(pData, m); 333 #else /* !VBOX */ 258 334 m_free(m); 335 #endif /* !VBOX */ 259 336 260 337 /* send "file not found" error back */ 261 338 339 #ifdef VBOX 340 tftp_send_error(pData, spt, 1, "File not found", tp); 341 #else /* !VBOX */ 262 342 tftp_send_error(spt, 1, "File not found", tp); 343 #endif /* !VBOX */ 263 344 264 345 return -1; 265 346 } 266 347 267 m->m_len = sizeof(struct tftp_t) - (512 - nobytes) - 348 m->m_len = sizeof(struct tftp_t) - (512 - nobytes) - 268 349 sizeof(struct ip) - sizeof(struct udphdr); 269 350 351 #ifdef VBOX 352 udp_output2(pData, NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); 353 #else /* !VBOX */ 270 354 udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); 355 #endif /* !VBOX */ 271 356 272 357 if (nobytes == 512) { 358 #ifdef VBOX 359 tftp_session_update(pData, spt); 360 #else /* !VBOX */ 273 361 tftp_session_update(spt); 362 #endif /* !VBOX */ 274 363 } 275 364 else { … … 280 369 } 281 370 371 #ifdef VBOX 372 static void tftp_handle_rrq(PNATState pData, struct tftp_t *tp, int pktlen) 373 #else /* !VBOX */ 282 374 static void tftp_handle_rrq(struct tftp_t *tp, int pktlen) 375 #endif /* !VBOX */ 283 376 { 284 377 struct tftp_session *spt; … … 286 379 u_int8_t *src, *dst; 287 380 381 #ifdef VBOX 382 s = tftp_session_allocate(pData, tp); 383 #else /* !VBOX */ 288 384 s = tftp_session_allocate(tp); 385 #endif /* !VBOX */ 289 386 290 387 if (s < 0) { … … 307 404 return; 308 405 } 309 406 310 407 if (src[k] == '\0') { 311 408 break; 312 409 } 313 410 } 314 411 315 412 if (k >= n) { 316 413 return; 317 414 } 318 415 319 416 k++; 320 417 321 418 /* check mode */ 322 419 if ((n - k) < 6) { 323 420 return; 324 421 } 325 422 326 423 if (memcmp(&src[k], "octet\0", 6) != 0) { 424 #ifdef VBOX 425 tftp_send_error(pData, spt, 4, "Unsupported transfer mode", tp); 426 #else /* !VBOX */ 327 427 tftp_send_error(spt, 4, "Unsupported transfer mode", tp); 428 #endif /* !VBOX */ 328 429 return; 329 430 } … … 337 438 || (spt->filename[strlen(spt->filename) - 1] == '/') 338 439 || strstr(spt->filename, "/../")) { 440 tftp_send_error(spt, 2, "Access violation", tp); 339 441 #else /* VBOX */ 340 442 if ((spt->filename[0] != '/') 341 443 || (spt->filename[strlen((const char *)spt->filename) - 1] == '/') 342 444 || strstr((char *)spt->filename, "/../")) { 445 tftp_send_error(pData, spt, 2, "Access violation", tp); 343 446 #endif /* VBOX */ 447 return; 448 } 449 450 /* only allow exported prefixes */ 451 452 if (!tftp_prefix) { 453 #ifdef VBOX 454 tftp_send_error(pData, spt, 2, "Access violation", tp); 455 #else /* !VBOX */ 344 456 tftp_send_error(spt, 2, "Access violation", tp); 457 #endif /* !VBOX */ 345 458 return; 346 459 } 347 460 348 /* only allow exported prefixes */349 350 if (!tftp_prefix) {351 tftp_send_error(spt, 2, "Access violation", tp);352 return;353 }354 355 461 /* check if the file exists */ 356 462 463 #ifdef VBOX 464 if (tftp_read_data(pData, spt, 0, spt->filename, 0) < 0) { 465 tftp_send_error(pData, spt, 1, "File not found", tp); 466 #else /* !VBOX */ 357 467 if (tftp_read_data(spt, 0, spt->filename, 0) < 0) { 358 468 tftp_send_error(spt, 1, "File not found", tp); 469 #endif /* !VBOX */ 359 470 return; 360 471 } 361 472 362 473 if (src[n - 1] != 0) { 474 #ifdef VBOX 475 tftp_send_error(pData, spt, 2, "Access violation", tp); 476 #else /* !VBOX */ 363 477 tftp_send_error(spt, 2, "Access violation", tp); 478 #endif /* !VBOX */ 364 479 return; 365 480 } … … 368 483 const char *key, *value; 369 484 485 #ifdef VBOX 486 key = (const char *)src + k; 487 #else /* !VBOX */ 370 488 key = src + k; 489 #endif /* !VBOX */ 371 490 k += strlen(key) + 1; 372 491 373 492 if (k >= n) { 493 #ifdef VBOX 494 tftp_send_error(pData, spt, 2, "Access violation", tp); 495 #else /* !VBOX */ 374 496 tftp_send_error(spt, 2, "Access violation", tp); 497 #endif /* !VBOX */ 375 498 return; 376 499 } 377 500 501 #ifdef VBOX 502 value = (const char *)src + k; 503 #else /* !VBOX */ 378 504 value = src + k; 505 #endif /* !VBOX */ 379 506 k += strlen(value) + 1; 380 507 … … 398 525 tsize = stat_p.st_size; 399 526 else { 527 #ifdef VBOX 528 tftp_send_error(pData, spt, 1, "File not found", tp); 529 #else /* !VBOX */ 400 530 tftp_send_error(spt, 1, "File not found", tp); 531 #endif /* !VBOX */ 401 532 return; 402 533 } 403 534 } 404 535 536 #ifdef VBOX 537 tftp_send_oack(pData, spt, "tsize", tsize, tp); 538 #else /* !VBOX */ 405 539 tftp_send_oack(spt, "tsize", tsize, tp); 540 #endif /* !VBOX */ 406 541 } 407 542 } 408 543 544 #ifdef VBOX 545 tftp_send_data(pData, spt, 1, tp); 546 #else /* !VBOX */ 409 547 tftp_send_data(spt, 1, tp); 410 } 411 548 #endif /* !VBOX */ 549 } 550 551 #ifdef VBOX 552 static void tftp_handle_ack(PNATState pData, struct tftp_t *tp, int pktlen) 553 #else /* !VBOX */ 412 554 static void tftp_handle_ack(struct tftp_t *tp, int pktlen) 555 #endif /* !VBOX */ 413 556 { 414 557 int s; 415 558 559 #ifdef VBOX 560 s = tftp_session_find(pData, tp); 561 #else /* !VBOX */ 416 562 s = tftp_session_find(tp); 563 #endif /* !VBOX */ 417 564 418 565 if (s < 0) { … … 420 567 } 421 568 422 if (tftp_send_data(&tftp_sessions[s], 423 ntohs(tp->x.tp_data.tp_block_nr) + 1, 569 #ifdef VBOX 570 if (tftp_send_data(pData, &tftp_sessions[s], 571 ntohs(tp->x.tp_data.tp_block_nr) + 1, 424 572 tp) < 0) { 573 #else /* !VBOX */ 574 if (tftp_send_data(&tftp_sessions[s], 575 ntohs(tp->x.tp_data.tp_block_nr) + 1, 576 tp) < 0) { 577 #endif /* !VBOX */ 425 578 return; 426 579 } 427 580 } 428 581 582 #ifdef VBOX 583 void tftp_input(PNATState pData, struct mbuf *m) 584 #else /* !VBOX */ 429 585 void tftp_input(struct mbuf *m) 586 #endif /* !VBOX */ 430 587 { 431 588 struct tftp_t *tp = (struct tftp_t *)m->m_data; … … 433 590 switch(ntohs(tp->tp_op)) { 434 591 case TFTP_RRQ: 592 #ifdef VBOX 593 tftp_handle_rrq(pData, tp, m->m_len); 594 #else /* !VBOX */ 435 595 tftp_handle_rrq(tp, m->m_len); 596 #endif /* !VBOX */ 436 597 break; 437 598 438 599 case TFTP_ACK: 600 #ifdef VBOX 601 tftp_handle_ack(pData, tp, m->m_len); 602 #else /* !VBOX */ 439 603 tftp_handle_ack(tp, m->m_len); 604 #endif /* !VBOX */ 440 605 break; 441 606 } -
trunk/src/VBox/Devices/Network/slirp/tftp.h
r1016 r1033 19 19 u_int16_t tp_op; 20 20 union { 21 struct { 21 struct { 22 22 u_int16_t tp_block_nr; 23 23 u_int8_t tp_buf[512]; 24 24 } tp_data; 25 struct { 25 struct { 26 26 u_int16_t tp_error_code; 27 27 u_int8_t tp_msg[512]; … … 31 31 }; 32 32 33 #ifdef VBOX 34 void tftp_input(PNATState pData, struct mbuf *m); 35 #else /* !VBOX */ 33 36 void tftp_input(struct mbuf *m); 37 #endif /* !VBOX */ -
trunk/src/VBox/Devices/Network/slirp/udp.c
r1022 r1033 46 46 #include "ip_icmp.h" 47 47 48 #ifndef VBOX 48 49 struct udpstat udpstat; 49 50 50 51 struct socket udb; 52 #endif /* !VBOX */ 51 53 52 54 /* … … 54 56 * Per RFC 768, August, 1980. 55 57 */ 58 #ifdef VBOX 59 #define udpcksum 1 60 #else /* !VBOX */ 56 61 #ifndef COMPAT_42 57 62 int udpcksum = 1; … … 59 64 int udpcksum = 0; /* XXX */ 60 65 #endif 61 66 #endif /* !VBOX */ 67 68 #ifndef VBOX 62 69 struct socket *udp_last_so = &udb; 70 #endif /* !VBOX */ 63 71 64 72 void 73 #ifdef VBOX 74 udp_init(PNATState pData) 75 #else /* !VBOX */ 65 76 udp_init() 66 { 77 #endif /* !VBOX */ 78 { 79 #ifdef VBOX 80 udp_last_so = &udb; 81 #endif /* VBOX */ 67 82 udb.so_next = udb.so_prev = &udb; 68 83 } … … 72 87 */ 73 88 void 89 #ifdef VBOX 90 udp_input(PNATState pData, register struct mbuf *m, int iphlen) 91 #else /* !VBOX */ 74 92 udp_input(m, iphlen) 75 93 register struct mbuf *m; 76 94 int iphlen; 95 #endif /* !VBOX */ 77 96 { 78 97 register struct ip *ip; … … 150 169 */ 151 170 if (ntohs(uh->uh_dport) == BOOTP_SERVER) { 171 #ifdef VBOX 172 bootp_input(pData, m); 173 #else /* !VBOX */ 152 174 bootp_input(m); 175 #endif /* !VBOX */ 153 176 goto bad; 154 177 } … … 158 181 */ 159 182 if (ntohs(uh->uh_dport) == TFTP_SERVER) { 183 #ifdef VBOX 184 tftp_input(pData, m); 185 #else /* !VBOX */ 160 186 tftp_input(m); 187 #endif /* !VBOX */ 161 188 goto bad; 162 189 } … … 195 222 */ 196 223 if ((so = socreate()) == NULL) goto bad; 224 #ifdef VBOX 225 if(udp_attach(pData, so) == -1) { 226 #else /* !VBOX */ 197 227 if(udp_attach(so) == -1) { 228 #endif /* !VBOX */ 198 229 DEBUG_MISC((dfd," udp_attach errno = %d-%s\n", 199 230 errno,strerror(errno))); 231 #ifdef VBOX 232 sofree(pData, so); 233 #else /* !VBOX */ 200 234 sofree(so); 235 #endif /* !VBOX */ 201 236 goto bad; 202 237 } … … 229 264 */ 230 265 if (so->so_emu) 266 #ifdef VBOX 267 udp_emu(pData, so, m); 268 #else /* !VBOX */ 231 269 udp_emu(so, m); 232 270 #endif /* !VBOX */ 271 272 #ifdef VBOX 273 if(sosendto(pData, so,m) == -1) { 274 #else /* !VBOX */ 233 275 if(sosendto(so,m) == -1) { 276 #endif /* !VBOX */ 234 277 m->m_len += iphlen; 235 278 m->m_data -= iphlen; 236 279 *ip=save_ip; 237 280 DEBUG_MISC((dfd,"udp tx errno = %d-%s\n",errno,strerror(errno))); 281 #ifdef VBOX 282 icmp_error(pData, m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno)); 283 #else /* !VBOX */ 238 284 icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno)); 239 } 240 285 #endif /* !VBOX */ 286 } 287 288 #ifdef VBOX 289 m_free(pData, so->so_m); /* used for ICMP if error on sorecvfrom */ 290 #else /* !VBOX */ 241 291 m_free(so->so_m); /* used for ICMP if error on sorecvfrom */ 292 #endif /* !VBOX */ 242 293 243 294 /* restore the orig mbuf packet */ … … 249 300 return; 250 301 bad: 302 #ifdef VBOX 303 m_freem(pData, m); 304 #else /* !VBOX */ 251 305 m_freem(m); 306 #endif /* !VBOX */ 252 307 /* if (opts) m_freem(opts); */ 253 308 return; 254 309 } 255 310 311 #ifdef VBOX 312 int udp_output2(PNATState pData, struct socket *so, struct mbuf *m, 313 struct sockaddr_in *saddr, struct sockaddr_in *daddr, 314 int iptos) 315 #else /* !VBOX */ 256 316 int udp_output2(struct socket *so, struct mbuf *m, 257 317 struct sockaddr_in *saddr, struct sockaddr_in *daddr, 258 318 int iptos) 319 #endif /* !VBOX */ 259 320 { 260 321 register struct udpiphdr *ui; … … 304 365 udpstat.udps_opackets++; 305 366 367 #ifdef VBOX 368 error = ip_output(pData, so, m); 369 #else /* !VBOX */ 306 370 error = ip_output(so, m); 371 #endif /* !VBOX */ 307 372 308 373 return (error); 309 374 } 310 375 376 #ifdef VBOX 377 int udp_output(PNATState pData, struct socket *so, struct mbuf *m, 378 struct sockaddr_in *addr) 379 #else /* !VBOX */ 311 380 int udp_output(struct socket *so, struct mbuf *m, 312 381 struct sockaddr_in *addr) 313 382 #endif /* !VBOX */ 314 383 { 315 384 struct sockaddr_in saddr, daddr; … … 324 393 daddr.sin_port = so->so_lport; 325 394 395 #ifdef VBOX 396 return udp_output2(pData, so, m, &saddr, &daddr, so->so_iptos); 397 #else /* !VBOX */ 326 398 return udp_output2(so, m, &saddr, &daddr, so->so_iptos); 399 #endif /* !VBOX */ 327 400 } 328 401 329 402 int 403 #ifdef VBOX 404 udp_attach(PNATState pData, struct socket *so) 405 #else /* !VBOX */ 330 406 udp_attach(so) 331 407 struct socket *so; 408 #endif /* !VBPX */ 332 409 { 333 410 struct sockaddr_in addr; … … 354 431 /* success, insert in queue */ 355 432 so->so_expire = curtime + SO_EXPIRE; 433 so->so_expire = curtime + SO_EXPIRE; 356 434 insque(so,&udb); 357 435 } … … 361 439 362 440 void 441 #ifdef VBOX 442 udp_detach(PNATState pData, struct socket *so) 443 #else /* !VBOX */ 363 444 udp_detach(so) 364 445 struct socket *so; 446 #endif /* !VBOX */ 365 447 { 366 448 #ifdef VBOX … … 371 453 /* if (so->so_m) m_free(so->so_m); done by sofree */ 372 454 455 #ifdef VBOX 456 sofree(pData, so); 457 #else /* !VBOX */ 373 458 sofree(so); 374 } 375 459 #endif /* !VBOX */ 460 } 461 462 #ifdef VBOX 463 static const struct tos_t udptos[] = { 464 #else /* !VBOX */ 376 465 struct tos_t udptos[] = { 466 #endif /* !VBOX */ 377 467 {0, 53, IPTOS_LOWDELAY, 0}, /* DNS */ 378 468 {517, 517, IPTOS_LOWDELAY, EMU_TALK}, /* talk */ … … 408 498 */ 409 499 void 500 #ifdef VBOX 501 udp_emu(PNATState pData, struct socket *so, struct mbuf *m) 502 #else /* !VBOX */ 410 503 udp_emu(so, m) 411 504 struct socket *so; 412 505 struct mbuf *m; 506 #endif /* !VBOX */ 413 507 { 414 508 struct sockaddr_in addr; … … 640 734 641 735 struct socket * 736 #ifdef VBOX 737 udp_listen(PNATState pData, u_int port, u_int32_t laddr, u_int lport, int flags) 738 #else /* !VBOX */ 642 739 udp_listen(port, laddr, lport, flags) 643 740 u_int port; … … 645 742 u_int lport; 646 743 int flags; 744 #endif /* !VBOX */ 647 745 { 648 746 struct sockaddr_in addr; … … 668 766 669 767 if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0) { 768 #ifdef VBOX 769 udp_detach(pData, so); 770 #else /* !VBOX */ 670 771 udp_detach(so); 772 #endif /* !VBOX */ 671 773 return NULL; 672 774 } -
trunk/src/VBox/Devices/Network/slirp/udp.h
r1 r1033 73 73 #define ui_sum ui_u.uh_sum 74 74 75 #ifdef VBOX 76 struct udpstat_t { 77 #else /* !VBOX */ 75 78 struct udpstat { 79 #endif /* !VBOX */ 76 80 /* input statistics: */ 77 81 u_long udps_ipackets; /* total input packets */ … … 97 101 struct mbuf; 98 102 103 #ifdef VBOX 104 void udp_init _P((PNATState)); 105 void udp_input _P((PNATState, register struct mbuf *, int)); 106 int udp_output _P((PNATState, struct socket *, struct mbuf *, struct sockaddr_in *)); 107 int udp_attach _P((PNATState, struct socket *)); 108 void udp_detach _P((PNATState, struct socket *)); 109 #else /* !VBOX */ 99 110 void udp_init _P((void)); 100 111 void udp_input _P((register struct mbuf *, int)); … … 102 113 int udp_attach _P((struct socket *)); 103 114 void udp_detach _P((struct socket *)); 115 #endif /* !VBOX */ 104 116 u_int8_t udp_tos _P((struct socket *)); 117 #ifdef VBOX 118 #else /* !VBOX */ 119 #endif /* !VBOX */ 120 #ifdef VBOX 121 void udp_emu _P((PNATState, struct socket *, struct mbuf *)); 122 struct socket * udp_listen _P((PNATState, u_int, u_int32_t, u_int, int)); 123 int udp_output2(PNATState pData, struct socket *so, struct mbuf *m, 124 struct sockaddr_in *saddr, struct sockaddr_in *daddr, 125 int iptos); 126 #else /* !VBOX */ 105 127 void udp_emu _P((struct socket *, struct mbuf *)); 106 128 struct socket * udp_listen _P((u_int, u_int32_t, u_int, int)); 107 int udp_output2(struct socket *so, struct mbuf *m, 129 int udp_output2(struct socket *so, struct mbuf *m, 108 130 struct sockaddr_in *saddr, struct sockaddr_in *daddr, 109 131 int iptos); 132 #endif /* !VBOX */ 133 110 134 #endif
Note:
See TracChangeset
for help on using the changeset viewer.