VBoxNetUDP.cpp revision 9fedc2d001e8b57f81b15829898cd8247e9c46eb
/* $Id$ */
/** @file
* VBoxNetUDP - UDP Library for IntNet.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DEFAULT
#include "VBoxNetUDP.h"
/**
* Checks if the head of the receive ring is a UDP packet matching the given
* criteria.
*
* @returns Pointer to the data if it matches.
* @param pBuf The IntNet buffers.
* @param uDstPort The destination port to match.
* @param pDstMac The destination address to match if
* VBOXNETUDP_MATCH_UNICAST is specied.
* @param fFlags Flags indicating what to match and some debug stuff.
* See VBOXNETUDP_MATCH_*.
* @param pHdrs Where to return the pointers to the headers.
* Optional.
* @param pcb Where to return the size of the data on success.
*/
void *VBoxNetUDPMatch(PCINTNETBUF pBuf, unsigned uDstPort, PCRTMAC pDstMac, uint32_t fFlags, PVBOXNETUDPHDRS pHdrs, size_t *pcb)
{
/*
* Clear return values so we can return easier on mismatch.
*/
*pcb = 0;
if (pHdrs)
{
}
/*
* Valid IntNet Ethernet frame?
*/
return NULL;
if (pHdrs)
#ifdef IN_RING3
{
}
#endif
/*
* Ethernet matching.
*/
/* Ethernet min frame size. */
if (cbFrame < 64)
return NULL;
/* Match Ethertype: IPV4? */
/** @todo VLAN tagging? */
return NULL;
/* Match destination address (ethernet) */
if ( ( !(fFlags & VBOXNETUDP_MATCH_UNICAST)
&& ( !(fFlags & VBOXNETUDP_MATCH_BROADCAST)
return NULL;
/*
* IP validation and matching.
*/
if (pHdrs)
/* Protocol: UDP */
return NULL;
/* Valid IPv4 header? */
return NULL;
/*
* UDP matching and validation.
*/
if (pHdrs)
/* Destination port */
return NULL;
/* Validate the UDP header according to flags. */
{
return NULL;
if ( (fFlags & VBOXNETUDP_MATCH_REQUIRE_CHECKSUM)
return NULL;
}
else
{
return NULL;
}
/*
* We've got a match!
*/
return (void *)(pUdpHdr + 1);
}
/**
* Flushes the send buffer.
*
* @returns VBox status code.
* @param pSession The support driver session.
* @param hIf The interface handle to flush.
*/
{
}
/**
* Copys the SG segments into the specified fram.
*
* @param pvFrame The frame buffer.
* @param cSegs The number of segments.
* @param paSegs The segments.
*/
{
{
}
}
/**
* Writes a frame packet to the buffer.
*
* @returns VBox status code.
* @param pBuf The buffer.
* @param pRingBuf The ring buffer to read from.
* @param cSegs The number of segments.
* @param paSegs The segments.
* @remark This is the same as INTNETRingWriteFrame and
* drvIntNetRingWriteFrame.
*/
{
/*
* Validate input.
*/
/* Calc frame size. */
{
/*
* Try fit it all before the end of the buffer.
*/
{
return VINF_SUCCESS;
}
/*
* Try fit the frame at the start of the buffer.
* (The header fits before the end of the buffer because of alignment.)
*/
AssertMsg(pRingBuf->offEnd - offWrite >= sizeof(INTNETHDR), ("offEnd=%x offWrite=%x\n", pRingBuf->offEnd, offWrite));
{
return VINF_SUCCESS;
}
}
/*
* The reader is ahead of the writer, try fit it into that space.
*/
{
return VINF_SUCCESS;
}
/* (it didn't fit) */
/** @todo stats */
return VERR_BUFFER_OVERFLOW;
}
/** Internal worker for VBoxNetUDPUnicast and VBoxNetUDPBroadcast. */
{
/* the Ethernet header */
/* the IP header */
/* the UDP bit */
#if 0
#else
#endif
/* the payload */
/* write it */
if (RT_FAILURE(rc))
{
}
if (RT_SUCCESS(rc))
return rc;
}
/**
* Sends an unicast UDP packet.
*
* @returns VBox status code.
* @param pSession The support driver session handle.
* @param hIf The interface handle.
* @param pBuf The interface buffer.
* @param SrcIPv4Addr The source IPv4 address.
* @param pSrcMacAddr The source MAC address.
* @param uSrcPort The source port number.
* @param DstIPv4Addr The destination IPv4 address. Can be broadcast.
* @param pDstMacAddr The destination MAC address.
* @param uDstPort The destination port number.
* @param pvData The data payload.
* @param cbData The size of the data payload.
*/
{
}
/**
* Sends a broadcast UDP packet.
*
* @returns VBox status code.
* @param pSession The support driver session handle.
* @param hIf The interface handle.
* @param pBuf The interface buffer.
* @param SrcIPv4Addr The source IPv4 address.
* @param pSrcMacAddr The source MAC address.
* @param uSrcPort The source port number.
* @param uDstPort The destination port number.
* @param pvData The data payload.
* @param cbData The size of the data payload.
*/
unsigned uDstPort,
{
}