- Timestamp:
- Jul 2, 2012 4:44:45 PM (12 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/slirp.c
r41977 r41987 354 354 rc = slirpInitializeDnsSettings(pData); 355 355 AssertRCReturn(rc, VINF_NAT_DNS); 356 rc = slirpTftpInit(pData); 357 AssertRCReturn(rc, VINF_NAT_DNS); 356 358 357 359 if (i32AliasMode & ~(PKT_ALIAS_LOG|PKT_ALIAS_SAME_PORTS|PKT_ALIAS_PROXY_ONLY)) -
trunk/src/VBox/Devices/Network/slirp/slirp_state.h
r41970 r41987 48 48 49 49 /** TFTP session entry. */ 50 typedef enum ENMTFTPSESSIONFMT51 {52 TFTPFMT_NONE = 0,53 TFTPFMT_OCTET,54 TFTPFMT_NETASCII,55 TFTPFMT_MAIL,56 TFTPFMT_NOT_FMT = 0xffff57 } ENMTFTPSESSIONFMT;58 59 typedef struct TFTPSESSION60 {61 int fInUse;62 unsigned char pszFilename[TFTP_FILENAME_MAX];63 struct in_addr IpClientAddress;64 uint16_t u16ClientPort;65 int iTimestamp;66 ENMTFTPSESSIONFMT enmTftpFmt;67 uint16_t u16BlkSize;68 uint16_t u16TSize;69 uint16_t u16Size;70 uint16_t u16Timeout;71 } TFTPSESSION, *PTFTPSESSION;72 73 typedef const PTFTPSESSION PCTFTPSESSION;74 75 50 struct dns_domain_entry 76 51 { … … 196 171 int tcp_reass_overflows; 197 172 /* Stuff from tftp.c */ 198 TFTPSESSION aTftpSessions[TFTP_SESSIONS_MAX]; 173 void *pvTftpSessions; 174 int cTftpSession; 199 175 const char *tftp_prefix; 200 176 /* Stuff from udp.c */ -
trunk/src/VBox/Devices/Network/slirp/tftp.c
r41970 r41987 46 46 #include <iprt/asm-math.h> 47 47 48 typedef enum ENMTFTPSESSIONFMT 49 { 50 TFTPFMT_NONE = 0, 51 TFTPFMT_OCTET, 52 TFTPFMT_NETASCII, 53 TFTPFMT_MAIL, 54 TFTPFMT_NOT_FMT = 0xffff 55 } ENMTFTPSESSIONFMT; 56 57 typedef struct TFTPSESSION 58 { 59 int fInUse; 60 unsigned char pszFilename[TFTP_FILENAME_MAX]; 61 struct in_addr IpClientAddress; 62 uint16_t u16ClientPort; 63 int iTimestamp; 64 ENMTFTPSESSIONFMT enmTftpFmt; 65 uint16_t u16BlkSize; 66 uint16_t u16TSize; 67 uint16_t u16Size; 68 uint16_t u16Timeout; 69 } TFTPSESSION, *PTFTPSESSION, **PPTFTPSESSION; 70 71 #pragma pack(1) 72 typedef struct TFTPCOREHDR 73 { 74 uint16_t u16TftpOpCode; 75 /* Data lays here (might be raw uint8_t* or header of payload ) */ 76 } TFTPCOREHDR, *PTFTPCOREHDR; 77 78 typedef struct TFTPIPHDR 79 { 80 struct ip IPv4Hdr; 81 struct udphdr UdpHdr; 82 uint16_t u16TftpOpType; 83 TFTPCOREHDR Core; 84 /* Data lays here */ 85 } TFTPIPHDR, *PTFTPIPHDR; 86 #pragma pack() 87 88 typedef const PTFTPIPHDR PCTFTPIPHDR; 89 90 typedef const PTFTPSESSION PCTFTPSESSION; 91 92 48 93 typedef struct TFTPOPTIONDESC 49 94 { … … 297 342 } 298 343 299 static int tftpAllocateSession(PNATState pData, PCTFTPIPHDR pcTftpIpHeader )300 { 301 PTFTPSESSION pTftpSession ;344 static int tftpAllocateSession(PNATState pData, PCTFTPIPHDR pcTftpIpHeader, PPTFTPSESSION ppTftpSession) 345 { 346 PTFTPSESSION pTftpSession = NULL; 302 347 int rc = VINF_SUCCESS; 303 348 int idxSession; 349 AssertPtrReturn(pData, VERR_INVALID_PARAMETER); 350 AssertPtrReturn(pcTftpIpHeader, VERR_INVALID_PARAMETER); 351 AssertPtrReturn(ppTftpSession, VERR_INVALID_PARAMETER); 304 352 305 353 for (idxSession = 0; idxSession < TFTP_SESSIONS_MAX; idxSession++) 306 354 { 307 pTftpSession = & pData->aTftpSessions[idxSession];355 pTftpSession = &((PTFTPSESSION)pData->pvTftpSessions)[idxSession]; 308 356 309 357 if (!pTftpSession->fInUse) … … 315 363 } 316 364 317 return -1;365 return VERR_NOT_FOUND; 318 366 319 367 found: … … 322 370 pTftpSession->u16ClientPort = pcTftpIpHeader->UdpHdr.uh_sport; 323 371 rc = tftpSessionOptionParse(pTftpSession, pcTftpIpHeader); 324 AssertRCReturn(rc, -1); 372 AssertRCReturn(rc, VERR_INTERNAL_ERROR); 373 *ppTftpSession = pTftpSession; 325 374 326 375 tftpSessionUpdate(pData, pTftpSession); 327 376 328 return idxSession;329 } 330 331 static int tftpSessionFind(PNATState pData, PCTFTPIPHDR pcTftpIpHeader )377 return VINF_SUCCESS; 378 } 379 380 static int tftpSessionFind(PNATState pData, PCTFTPIPHDR pcTftpIpHeader, PPTFTPSESSION ppTftpSessions) 332 381 { 333 382 PTFTPSESSION pTftpSession; 334 int k; 335 336 for (k = 0; k < TFTP_SESSIONS_MAX; k++) 337 { 338 pTftpSession = &pData->aTftpSessions[k]; 383 int idxTftpSession; 384 AssertPtrReturn(pData, VERR_INVALID_PARAMETER); 385 AssertPtrReturn(pcTftpIpHeader, VERR_INVALID_PARAMETER); 386 AssertPtrReturn(ppTftpSessions, VERR_INVALID_PARAMETER); 387 388 for (idxTftpSession = 0; idxTftpSession < TFTP_SESSIONS_MAX; idxTftpSession++) 389 { 390 pTftpSession = &((PTFTPSESSION)pData->pvTftpSessions)[idxTftpSession]; 339 391 340 392 if (pTftpSession->fInUse) … … 343 395 { 344 396 if (pTftpSession->u16ClientPort == pcTftpIpHeader->UdpHdr.uh_sport) 345 return k; 397 { 398 *ppTftpSessions = pTftpSession; 399 return VINF_SUCCESS; 400 } 346 401 } 347 402 } 348 403 } 349 404 350 return -1;405 return VERR_NOT_FOUND; 351 406 } 352 407 … … 647 702 DECLINLINE(void) tftpProcessRRQ(PNATState pData, PCTFTPIPHDR pTftpIpHeader, int pktlen) 648 703 { 649 PTFTPSESSION pTftpSession; 650 int idxTftpSession = 0; 704 PTFTPSESSION pTftpSession = NULL; 651 705 uint8_t *pu8Payload = NULL; 652 706 int cbPayload = 0; 653 707 int cbFileName = 0; 708 int rc = VINF_SUCCESS; 654 709 655 710 AssertPtrReturnVoid(pTftpIpHeader); … … 658 713 LogFlowFunc(("ENTER: pTftpIpHeader:%p, pktlen:%d\n", pTftpIpHeader, pktlen)); 659 714 660 idxTftpSession = tftpAllocateSession(pData, pTftpIpHeader); 661 if (idxTftpSession < 0) 715 rc = tftpAllocateSession(pData, pTftpIpHeader, &pTftpSession); 716 if ( RT_FAILURE(rc) 717 || pTftpSession == NULL) 662 718 { 663 719 LogFlowFuncLeave(); … … 665 721 } 666 722 667 pTftpSession = &pData->aTftpSessions[idxTftpSession];668 723 pu8Payload = (uint8_t *)&pTftpIpHeader->Core; 669 724 cbPayload = pktlen - sizeof(TFTPIPHDR); … … 702 757 static void tftpProcessACK(PNATState pData, PTFTPIPHDR pTftpIpHeader) 703 758 { 704 int s; 705 706 s = tftpSessionFind(pData, pTftpIpHeader); 707 if (s < 0) 759 int rc; 760 PTFTPSESSION pTftpSession = NULL; 761 762 rc = tftpSessionFind(pData, pTftpIpHeader, &pTftpSession); 763 if (RT_FAILURE(rc)) 708 764 return; 709 765 710 if (tftpSendData(pData, &pData->aTftpSessions[s], 711 RT_N2H_U16(pTftpIpHeader->Core.u16TftpOpCode) + 1, pTftpIpHeader) < 0) 712 { 713 /* XXX */ 714 } 715 } 716 717 DECLCALLBACK(void) tftp_input(PNATState pData, struct mbuf *pMbuf) 766 AssertReturnVoid(tftpSendData(pData, 767 pTftpSession, 768 RT_N2H_U16(pTftpIpHeader->Core.u16TftpOpCode) + 1, pTftpIpHeader)); 769 } 770 771 DECLCALLBACK(int) slirpTftpInit(PNATState pData) 772 { 773 AssertPtrReturn(pData, VERR_INVALID_PARAMETER); 774 pData->pvTftpSessions = RTMemAllocZ(sizeof(TFTPSESSION) * TFTP_SESSIONS_MAX); 775 AssertPtrReturn(pData->pvTftpSessions, VERR_NO_MEMORY); 776 return VINF_SUCCESS; 777 } 778 779 DECLCALLBACK(int) slirpTftpInput(PNATState pData, struct mbuf *pMbuf) 718 780 { 719 781 PTFTPIPHDR pTftpIpHeader = NULL; … … 731 793 tftpProcessACK(pData, pTftpIpHeader); 732 794 break; 733 default: 734 LogFlowFuncLeave();735 return;736 }737 } 795 default:; 796 } 797 LogFlowFuncLeaveRC(VINF_SUCCESS); 798 return VINF_SUCCESS; 799 } -
trunk/src/VBox/Devices/Network/slirp/tftp.h
r41970 r41987 18 18 /* tftp defines */ 19 19 20 #ifndef _SLIRP_TFTP_H_ 21 #define _SLIRP_TFTP_H_ 22 20 23 #define TFTP_SESSIONS_MAX 3 21 24 … … 31 34 #define TFTP_FILENAME_MAX 512 32 35 33 #if 0 34 struct tftp_t 35 { 36 struct ip ip; 37 struct udphdr udp; 38 u_int16_t tp_op; 39 union 40 { 41 struct 42 { 43 u_int16_t tp_block_nr; 44 u_int8_t tp_buf[512]; 45 } tp_data; 46 struct 47 { 48 u_int16_t tp_error_code; 49 u_int8_t tp_msg[512]; 50 } tp_error; 51 u_int8_t tp_buf[512 + 2]; 52 } x; 53 }; 54 #else 55 #pragma pack(0) 56 typedef struct TFTPCOREHDR 57 { 58 uint16_t u16TftpOpCode; 59 #if 0 60 union { 61 uint16_t u16BlockNum; 62 uint16_t u16TftpErrorCode; 63 } X; 36 37 int slirpTftpInput(PNATState pData, struct mbuf *m); 38 int slirpTftpInit(PNATState); 64 39 #endif 65 /* Data lays here (might be raw uint8_t* or header of payload ) */66 } TFTPCOREHDR, *PTFTPCOREHDR;67 68 typedef struct TFTPIPHDR69 {70 struct ip IPv4Hdr;71 struct udphdr UdpHdr;72 uint16_t u16TftpOpType;73 TFTPCOREHDR Core;74 /* Data lays here */75 } TFTPIPHDR, *PTFTPIPHDR;76 #pragma pack()77 78 typedef const PTFTPIPHDR PCTFTPIPHDR;79 #endif80 81 void tftp_input(PNATState pData, struct mbuf *m); -
trunk/src/VBox/Devices/Network/slirp/udp.c
r41856 r41987 204 204 && CTL_CHECK(ip->ip_dst.s_addr, CTL_TFTP)) 205 205 { 206 tftp_input(pData, m); 206 if (pData->pvTftpSessions) 207 slirpTftpInput(pData, m); 207 208 goto done_free_mbuf; 208 209 }
Note:
See TracChangeset
for help on using the changeset viewer.