Changeset 9735 in vbox for trunk/include
- Timestamp:
- Jun 16, 2008 5:39:08 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/intnet.h
r8155 r9735 122 122 STAMCOUNTER cbStatSend; 123 123 } INTNETBUF; 124 /** Pointer to an interface buffer. */ 124 125 typedef INTNETBUF *PINTNETBUF; 126 /** Pointer to a const interface buffer. */ 127 typedef INTNETBUF const *PCINTNETBUF; 125 128 126 129 /** Internal networking interface handle. */ … … 152 155 { 153 156 /** Header type. This is currently serving as a magic, it 154 * can be extended later to encode special command packets and stuff. .*/157 * can be extended later to encode special command packets and stuff. */ 155 158 uint16_t u16Type; 156 159 /** The size of the frame. */ … … 160 163 * thereby both simplify reading and */ 161 164 int32_t offFrame; 162 } INTNETHDR , *PINTNETHDR;165 } INTNETHDR; 163 166 #pragma pack() 167 /** Pointer to a packet header.*/ 168 typedef INTNETHDR *PINTNETHDR; 169 /** Pointer to a const packet header.*/ 170 typedef INTNETHDR const *PCINTNETHDR; 164 171 165 172 /** INTNETHDR::u16Type value for normal frames. */ … … 174 181 * @param pBuf The buffer the header is within. Only used in strict builds. 175 182 */ 176 DECLINLINE(void *) INTNETHdrGetFramePtr(P INTNETHDR pHdr, PINTNETBUF pBuf)183 DECLINLINE(void *) INTNETHdrGetFramePtr(PCINTNETHDR pHdr, PCINTNETBUF pBuf) 177 184 { 178 185 uint8_t *pu8 = (uint8_t *)pHdr + pHdr->offFrame; … … 211 218 } 212 219 220 221 /** 222 * Scatter / Gather segment (internal networking). 223 */ 224 typedef struct INTNETSEG 225 { 226 /** The physical address. NIL_RTHCPHYS is not set. */ 227 RTHCPHYS Phys; 228 /** Pointer to the segment data. */ 229 void *pv; 230 /** The segment size. */ 231 uint32_t cb; 232 } INTNETSEG; 233 /** Pointer to a internal networking packet segment. */ 234 typedef INTNETSEG *PINTNETSEG; 235 /** Pointer to a internal networking packet segment. */ 236 typedef INTNETSEG const *PCINTNETSEG; 237 238 239 /** 240 * Scatter / Gather list (internal networking). 241 * 242 * This is used when communicating with the trunk port. 243 */ 244 typedef struct INTNETSG 245 { 246 /** The total length of the scatter gather list. */ 247 uint32_t cbTotal; 248 /** The number of users (references). 249 * This is used by the SGRelease code to decide when it can be freed. */ 250 uint16_t volatile cUsers; 251 /** Flags, see INTNETSG_FLAGS_* */ 252 uint16_t volatile fFlags; 253 /** The number of segments allocated. */ 254 uint16_t cSegsAlloc; 255 /** The number of segments actually used. */ 256 uint16_t cSegsUsed; 257 /** Variable sized list of segments. */ 258 INTNETSEG aSegs[1]; 259 } INTNETSG; 260 /** Pointer to a scatter / gather list. */ 261 typedef INTNETSG *PINTNETSG; 262 /** Pointer to a const scatter / gather list. */ 263 typedef INTNETSG const *PCINTNETSG; 264 265 /** @name INTNETSG::fFlags definitions. 266 * @{ */ 267 /** Set if the SG is free. */ 268 #define INTNETSG_FLAGS_FREE RT_BIT_32(1) 269 /** Set if the SG is a temporary one that will become invalid upon return. 270 * Try to finish using it before returning, and if that's not possible copy 271 * to other buffers. 272 * When not set, the callee should always free the SG. 273 * Attempts to free it made by the callee will be quietly ignored. */ 274 #define INTNETSG_FLAGS_TEMP RT_BIT_32(2) 275 /** @} */ 276 277 278 /** 279 * Initializes a scatter / gather buffer from a internal networking packet. 280 * 281 * @returns Pointer to the start of the frame. 282 * @param pSG Pointer to the scatter / gather structure. 283 * (The fFlags, cUsers, and cSegsAlloc members are left untouched.) 284 * @param pHdr Pointer to the packet header. 285 * @param pBuf The buffer the header is within. Only used in strict builds. 286 * @remarks Perhaps move this... 287 */ 288 DECLINLINE(void) INTNETSgInitFromPkt(PINTNETSG pSG, PCINTNETHDR pPktHdr, PCINTNETBUF pBuf) 289 { 290 pSG->cSegsUsed = 1; 291 pSG->cbTotal = pSG->aSegs[0].cb = pPktHdr->cbFrame; 292 pSG->aSegs[0].pv = INTNETHdrGetFramePtr(pPktHdr, pBuf); 293 pSG->aSegs[0].Phys = NIL_RTHCPHYS; 294 } 295 296 297 298 /** Pointer to the switch side of a trunk port. */ 299 typedef struct INTNETTRUNKSWPORT *PINTNETTRUNKSWPORT; 300 /** 301 * This is the port on the internal network 'switch', i.e. 302 * what the driver is connected to. 303 * 304 * This is only used for the in-kernel trunk connections. 305 */ 306 typedef struct INTNETTRUNKSWPORT 307 { 308 /** Structure version number. (INTNETTRUNKSWPORT_VERSION) */ 309 uint32_t u32Version; 310 311 /** 312 * Selects whether outgoing SGs should have their physical address set. 313 * 314 * By enabling physical addresses in the scatter / gather segments it should 315 * be possible to save some unnecessary address translation and memory locking 316 * in the network stack. (Internal networking knows the physical address for 317 * all the INTNETBUF data and that it's locked memory.) There is a negative 318 * side effects though, frames that crosses page boundraries will require 319 * multiple scather / gather segments. 320 * 321 * @returns The old setting. 322 * 323 * @param pIfPort Pointer to this structure. 324 * @param fEnable Whether to enable or disable it. 325 * 326 * @remarks Will grab the network semaphore. 327 */ 328 DECLR0CALLBACKMEMBER(bool, pfnSetSGPhys,(PINTNETTRUNKSWPORT pIfPort, bool fEnable)); 329 330 /** 331 * Frame from the host that's about to hit the wire. 332 * 333 * @returns true if we've handled it and it should be dropped. 334 * false if it should hit the wire. 335 * 336 * @param pIfPort Pointer to this structure. 337 * @param pSG The (scatter /) gather structure for the frame. 338 * This will only be use during the call, so a temporary one can 339 * be used. The Phys member will not be used. 340 * 341 * @remarks Will grab the network semaphore. 342 * 343 * @remark NAT and TAP will use this interface. 344 */ 345 DECLR0CALLBACKMEMBER(bool, pfnRecvHost,(PINTNETTRUNKSWPORT pIfPort, PINTNETSG pSG)); 346 347 /** 348 * Frame from the wire that's about to hit the network stack. 349 * 350 * @returns true if we've handled it and it should be dropped. 351 * false if it should hit the network stack. 352 * 353 * @param pIfPort Pointer to this structure. 354 * @param pSG The (scatter /) gather structure for the frame. 355 * This will only be use during the call, so a temporary one can 356 * be used. The Phys member will not be used. 357 * 358 * @remarks Will grab the network semaphore. 359 * 360 * @remark NAT and TAP will not this interface. 361 */ 362 DECLR0CALLBACKMEMBER(bool, pfnRecvWire,(PINTNETTRUNKSWPORT pIfPort, PINTNETSG pSG)); 363 364 /** Structure version number. (INTNETTRUNKSWPORT_VERSION) */ 365 uint32_t u32VersionEnd; 366 } INTNETTRUNKSWPORT; 367 368 /** Version number for the INTNETTRUNKIFPORT::u32Version and INTNETTRUNKIFPORT::u32VersionEnd fields. */ 369 #define INTNETTRUNKSWPORT_VERSION UINT32_C(0xA2CDf001) 370 371 372 /** Pointer to the interface side of a trunk port. */ 373 typedef struct INTNETTRUNKIFPORT *PINTNETTRUNKIFPORT; 374 /** 375 * This is the port on the trunk interface, i.e. the driver 376 * side which the internal network is connected to. 377 * 378 * This is only used for the in-kernel trunk connections. 379 */ 380 typedef struct INTNETTRUNKIFPORT 381 { 382 /** Structure version number. (INTNETTRUNKIFPORT_VERSION) */ 383 uint32_t u32Version; 384 385 /** 386 * Changes the active state of the interface. 387 * 388 * The interface is created in the suspended (non-active) state and then activated 389 * when the VM/network is started. It may be suspended and re-activated later 390 * for various reasons. It will finally be suspended again before disconnecting 391 * the interface from the internal network, however, this might be done immediately 392 * before disconnecting and may leave an incoming frame waiting on the internal network 393 * semaphore. 394 * 395 * @returns The previous state. 396 * 397 * @param pIfPort Pointer to this structure. 398 * @param fActive True if the new state is 'active', false if the new state is 'suspended'. 399 * 400 * @remarks Called while owning the network semaphore. 401 */ 402 DECLR0CALLBACKMEMBER(bool, pfnSetActive,(PINTNETTRUNKIFPORT pIfPort, bool fActive)); 403 404 /** 405 * Tests if the mac address belongs to any of the host NICs 406 * and should take the pfnSendToHost route. 407 * 408 * @returns true / false. 409 * 410 * @param pIfPort Pointer to this structure. 411 * @param pvMac Pointer to the mac address. This can be cast to PCPDMMAC (fixme: make it an common type?) 412 * 413 * @remarks Called while owning the network semaphore. 414 * 415 * @remarks TAP and NAT will compare with their own MAC address and let all their 416 * traffic go over the pfnSendToHost method. 417 */ 418 DECLR0CALLBACKMEMBER(bool, pfnIsHostMac,(PINTNETTRUNKIFPORT pIfPort, /*PCPDMMAC*/ void const *pvMac)); 419 420 /** 421 * Tests whether the host is operating the interface is promiscuous mode. 422 * 423 * The default behavior of internal networking 'switch' is to 'autodetect' 424 * promiscuous mode on the trunk port, which is where this method is used. 425 * For security reasons this default my of course be overridden so that the 426 * host cannot sniff at what's going on. 427 * 428 * Note that this differs from operating the trunk port on the switch in 429 * 'promiscuous' mode, because that relates to the bits going to the wire. 430 * 431 * @returns true / false. 432 * 433 * @param pIfPort Pointer to this structure. 434 * 435 * @remarks Called while owning the network semaphore. 436 */ 437 DECLR0CALLBACKMEMBER(bool, pfnIsPromiscuous,(PINTNETTRUNKIFPORT pIfPort)); 438 439 /** 440 * Send the frame to the host. 441 * 442 * This path is taken if pfnIsHostMac returns true and the trunk port on the 443 * internal network is configured to let traffic thru to the host. It may also 444 * be taken if the host is in promiscuous mode and the internal network is 445 * configured to respect this for internal targets. 446 * 447 * @return VBox status code. Error generally means we'll drop the packet. 448 * @param pIfPort Pointer to this structure. 449 * @param pSG Pointer to the (scatter /) gather structure for the frame. 450 * This will never be a temporary one, so, it's safe to 451 * do this asynchronously to save unnecessary buffer 452 * allocating and copying. 453 * 454 * @remarks Called while owning the network semaphore? 455 * 456 * @remarks TAP and NAT will use this interface for all their traffic, see pfnIsHostMac. 457 */ 458 DECLR0CALLBACKMEMBER(int, pfnSendToHost,(PINTNETTRUNKIFPORT pIfPort, PINTNETSG pSG)); 459 460 /** 461 * Put the frame on the wire. 462 * 463 * This path is taken if pfnIsHostMac returns false and the trunk port on the 464 * internal network is configured to let traffic out on the wire. This may also 465 * be taken for both internal and host traffic if the trunk port is configured 466 * to be in promiscuous mode. 467 * 468 * @return VBox status code. Error generally means we'll drop the packet. 469 * @param pIfPort Pointer to this structure. 470 * @param pSG Pointer to the (scatter /) gather structure for the frame. 471 * This will never be a temporary one, so, it's safe to 472 * do this asynchronously to save unnecessary buffer 473 * allocating and copying. 474 * 475 * @remarks Called while owning the network semaphore? 476 * 477 * @remarks TAP and NAT will call pfnSGRelease and return successfully. 478 */ 479 DECLR0CALLBACKMEMBER(int, pfnSendToWire,(PINTNETTRUNKIFPORT pIfPort, PINTNETSG pSG)); 480 481 /** 482 * This is called by the pfnSendToHost and pfnSendToWire code when they are 483 * done with a SG. 484 * 485 * It may be called after they return if the frame was pushed in an 486 * async manner. 487 * 488 * @param pIfPort Pointer to this structure. 489 * @param pSG Pointer to the (scatter /) gather structure. 490 * 491 * @remarks Will grab the network semaphore. 492 */ 493 DECLR0CALLBACKMEMBER(void, pfnSGRelease,(PINTNETTRUNKIFPORT pIfPort, PINTNETSG pSG)); 494 495 /** 496 * Destroys this network interface port. 497 * 498 * This is called either when disconnecting the trunk interface at runtime or 499 * when the network is being torn down. In both cases, the interface will be 500 * suspended first. Note that this may still cause races in the receive path... 501 * 502 * @param pIfPort Pointer to this structure. 503 * 504 * @remarks Called while owning the network semaphore. 505 */ 506 DECLR0CALLBACKMEMBER(bool, pfnDestroy,(PINTNETTRUNKIFPORT pIfPort)); 507 508 /** Structure version number. (INTNETTRUNKIFPORT_VERSION) */ 509 uint32_t u32VersionEnd; 510 } INTNETTRUNKIFPORT; 511 512 /** Version number for the INTNETTRUNKIFPORT::u32Version and INTNETTRUNKIFPORT::u32VersionEnd fields. */ 513 #define INTNETTRUNKIFPORT_VERSION UINT32_C(0xA2CDe001) 514 515 516 /** 517 * The component factory interface for create a network 518 * interface filter (like VBoxNetFlt). 519 */ 520 typedef struct INTNETTRUNKNETFLTFACTORY 521 { 522 /** 523 * Create an instance for the specfied host interface. 524 * 525 * The initial interface active state is false (suspended). 526 * 527 * 528 * @returns VBox status code. 529 * @retval VINF_SUCCESS and *ppIfPort set on success. 530 * @retval VERR_INTNET_FLT_IF_NOT_FOUND if the interface was not found. 531 * @retval VERR_INTNET_FLT_IF_BUSY if the interface is already connected. 532 * @retval VERR_INTNET_FLT_IF_FAILED if it failed for some other reason. 533 * 534 * @param pIfFactory Pointer to this structure. 535 * @param pszName The interface name (OS specific). 536 * @param pSwitchPort Pointer to the port interface on the switch that 537 * this interface is being connected to. 538 * @param ppIfPort Where to store the pointer to the interface port 539 * on success. 540 * 541 * @remarks Called while owning the network semaphore. 542 */ 543 DECLR0CALLBACKMEMBER(int, pfnCreate,(INTNETTRUNKNETFLTFACTORY pIfFactory, const char *pszName, 544 PINTNETTRUNKSWPORT pSwitchPort, PINTNETTRUNKIFPORT *ppIfPort)); 545 } INTNETTRUNKNETFLTFACTORY; 546 /** Pointer to the trunk factory. */ 547 typedef INTNETTRUNKNETFLTFACTORY *PINTNETTRUNKNETFLTFACTORY; 548 549 /** The UUID for the current network interface filter factory. */ 550 #define INTNETTRUNKNETFLTFACTORY_UUID_STR "0e32db7d-165d-4fc9-9bce-acb2798ce7fb" 551 552 553 554 213 555 /** The maximum length of a network name. */ 214 #define INTNET_MAX_NETWORK_NAME 128556 #define INTNET_MAX_NETWORK_NAME 128 215 557 216 558
Note:
See TracChangeset
for help on using the changeset viewer.