david/ipxe
Archived
1
0

[netdevice] Change link-layer push() and pull() methods to take raw types

EFI requires us to be able to specify the source address for
individual transmitted packets, and to be able to extract the
destination address on received packets.

Take advantage of this to rationalise the push() and pull() methods so
that push() takes a (dest,source,proto) tuple and pull() returns a
(dest,source,proto) tuple.
This commit is contained in:
Michael Brown 2008-10-15 04:17:48 +01:00
parent 6b9cc25556
commit 3a505dfc35
5 changed files with 56 additions and 64 deletions

View File

@ -153,21 +153,20 @@ static struct ipoib_mac ipoib_broadcast = {
* Add IPoIB link-layer header * Add IPoIB link-layer header
* *
* @v iobuf I/O buffer * @v iobuf I/O buffer
* @v netdev Network device
* @v net_protocol Network-layer protocol
* @v ll_dest Link-layer destination address * @v ll_dest Link-layer destination address
* @v ll_source Source link-layer address
* @v net_proto Network-layer protocol, in network-byte order
* @ret rc Return status code
*/ */
static int ipoib_push ( struct io_buffer *iobuf, static int ipoib_push ( struct io_buffer *iobuf, const void *ll_dest,
struct net_device *netdev __unused, const void *ll_source __unused, uint16_t net_proto ) {
struct net_protocol *net_protocol,
const void *ll_dest ) {
struct ipoib_hdr *ipoib_hdr = struct ipoib_hdr *ipoib_hdr =
iob_push ( iobuf, sizeof ( *ipoib_hdr ) ); iob_push ( iobuf, sizeof ( *ipoib_hdr ) );
/* Build IPoIB header */ /* Build IPoIB header */
memcpy ( &ipoib_hdr->pseudo.peer, ll_dest, memcpy ( &ipoib_hdr->pseudo.peer, ll_dest,
sizeof ( ipoib_hdr->pseudo.peer ) ); sizeof ( ipoib_hdr->pseudo.peer ) );
ipoib_hdr->real.proto = net_protocol->net_proto; ipoib_hdr->real.proto = net_proto;
ipoib_hdr->real.reserved = 0; ipoib_hdr->real.reserved = 0;
return 0; return 0;
@ -177,14 +176,13 @@ static int ipoib_push ( struct io_buffer *iobuf,
* Remove IPoIB link-layer header * Remove IPoIB link-layer header
* *
* @v iobuf I/O buffer * @v iobuf I/O buffer
* @v netdev Network device * @ret ll_dest Link-layer destination address
* @v net_proto Network-layer protocol, in network-byte order * @ret ll_source Source link-layer address
* @v ll_source Source link-layer address * @ret net_proto Network-layer protocol, in network-byte order
* @ret rc Return status code * @ret rc Return status code
*/ */
static int ipoib_pull ( struct io_buffer *iobuf, static int ipoib_pull ( struct io_buffer *iobuf, const void **ll_dest,
struct net_device *netdev __unused, const void **ll_source, uint16_t *net_proto ) {
uint16_t *net_proto, const void **ll_source ) {
struct ipoib_hdr *ipoib_hdr = iobuf->data; struct ipoib_hdr *ipoib_hdr = iobuf->data;
/* Sanity check */ /* Sanity check */
@ -198,8 +196,9 @@ static int ipoib_pull ( struct io_buffer *iobuf,
iob_pull ( iobuf, sizeof ( *ipoib_hdr ) ); iob_pull ( iobuf, sizeof ( *ipoib_hdr ) );
/* Fill in required fields */ /* Fill in required fields */
*net_proto = ipoib_hdr->real.proto; *ll_dest = &ipoib_broadcast; /* Doesn't really exist in packet */
*ll_source = &ipoib_hdr->pseudo.peer; *ll_source = &ipoib_hdr->pseudo.peer;
*net_proto = ipoib_hdr->real.proto;
return 0; return 0;
} }

View File

@ -79,34 +79,24 @@ struct ll_protocol {
* Add link-layer header * Add link-layer header
* *
* @v iobuf I/O buffer * @v iobuf I/O buffer
* @v netdev Network device
* @v net_protocol Network-layer protocol
* @v ll_dest Link-layer destination address * @v ll_dest Link-layer destination address
* @v ll_source Source link-layer address
* @v net_proto Network-layer protocol, in network-byte order
* @ret rc Return status code * @ret rc Return status code
*
* This method should prepend in the link-layer header
* (e.g. the Ethernet DIX header).
*/ */
int ( * push ) ( struct io_buffer *iobuf, struct net_device *netdev, int ( * push ) ( struct io_buffer *iobuf, const void *ll_dest,
struct net_protocol *net_protocol, const void *ll_source, uint16_t net_proto );
const void *ll_dest );
/** /**
* Remove link-layer header * Remove link-layer header
* *
* @v iobuf I/O buffer * @v iobuf I/O buffer
* @v netdev Network device * @ret ll_dest Link-layer destination address
* @v net_proto Network-layer protocol, in network-byte order * @ret ll_source Source link-layer address
* @v ll_source Source link-layer address * @ret net_proto Network-layer protocol, in network-byte order
* @ret rc Return status code * @ret rc Return status code
*
* This method should strip off the link-layer header
* (e.g. the Ethernet DIX header) and return the protocol and
* source link-layer address. The method must not alter the
* packet content, and may return the link-layer address as a
* pointer to data within the packet.
*/ */
int ( * pull ) ( struct io_buffer *iobuf, struct net_device *netdev, int ( * pull ) ( struct io_buffer *iobuf, const void **ll_dest,
uint16_t *net_proto, const void **ll_source ); const void **ll_source, uint16_t *net_proto );
/** /**
* Transcribe link-layer address * Transcribe link-layer address
* *

View File

@ -199,9 +199,10 @@ PXENV_EXIT_t pxenv_undi_transmit ( struct s_PXENV_UNDI_TRANSMIT
struct DataBlk *datablk; struct DataBlk *datablk;
struct io_buffer *iobuf; struct io_buffer *iobuf;
struct net_protocol *net_protocol; struct net_protocol *net_protocol;
struct ll_protocol *ll_protocol = pxe_netdev->ll_protocol;
char destaddr[MAX_LL_ADDR_LEN]; char destaddr[MAX_LL_ADDR_LEN];
const void *ll_dest; const void *ll_dest;
size_t ll_hlen = pxe_netdev->ll_protocol->ll_header_len; size_t ll_hlen = ll_protocol->ll_header_len;
size_t len; size_t len;
unsigned int i; unsigned int i;
int rc; int rc;
@ -259,17 +260,17 @@ PXENV_EXIT_t pxenv_undi_transmit ( struct s_PXENV_UNDI_TRANSMIT
copy_from_real ( destaddr, copy_from_real ( destaddr,
undi_transmit->DestAddr.segment, undi_transmit->DestAddr.segment,
undi_transmit->DestAddr.offset, undi_transmit->DestAddr.offset,
pxe_netdev->ll_protocol->ll_addr_len ); ll_protocol->ll_addr_len );
ll_dest = destaddr; ll_dest = destaddr;
} else { } else {
DBG ( " BCAST" ); DBG ( " BCAST" );
ll_dest = pxe_netdev->ll_protocol->ll_broadcast; ll_dest = ll_protocol->ll_broadcast;
} }
/* Add link-layer header */ /* Add link-layer header */
if ( ( rc = pxe_netdev->ll_protocol->push ( iobuf, pxe_netdev, if ( ( rc = ll_protocol->push ( iobuf, ll_dest,
net_protocol, pxe_netdev->ll_addr,
ll_dest )) != 0 ){ net_protocol->net_proto ))!=0){
free_iob ( iobuf ); free_iob ( iobuf );
undi_transmit->Status = PXENV_STATUS ( rc ); undi_transmit->Status = PXENV_STATUS ( rc );
return PXENV_EXIT_FAILURE; return PXENV_EXIT_FAILURE;
@ -545,6 +546,7 @@ PXENV_EXIT_t pxenv_undi_isr ( struct s_PXENV_UNDI_ISR *undi_isr ) {
struct io_buffer *iobuf; struct io_buffer *iobuf;
size_t len; size_t len;
struct ll_protocol *ll_protocol; struct ll_protocol *ll_protocol;
const void *ll_dest;
const void *ll_source; const void *ll_source;
uint16_t net_proto; uint16_t net_proto;
size_t ll_hlen; size_t ll_hlen;
@ -625,9 +627,8 @@ PXENV_EXIT_t pxenv_undi_isr ( struct s_PXENV_UNDI_ISR *undi_isr ) {
/* Strip link-layer header */ /* Strip link-layer header */
ll_protocol = pxe_netdev->ll_protocol; ll_protocol = pxe_netdev->ll_protocol;
if ( ( rc = ll_protocol->pull ( iobuf, pxe_netdev, if ( ( rc = ll_protocol->pull ( iobuf, &ll_dest, &ll_source,
&net_proto, &net_proto ) ) != 0 ) {
&ll_source ) ) != 0 ) {
/* Assume unknown net_proto and no ll_source */ /* Assume unknown net_proto and no ll_source */
net_proto = 0; net_proto = 0;
ll_source = NULL; ll_source = NULL;

View File

@ -42,19 +42,19 @@ static uint8_t eth_broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
* Add Ethernet link-layer header * Add Ethernet link-layer header
* *
* @v iobuf I/O buffer * @v iobuf I/O buffer
* @v netdev Network device
* @v net_protocol Network-layer protocol
* @v ll_dest Link-layer destination address * @v ll_dest Link-layer destination address
* @v ll_source Source link-layer address
* @v net_proto Network-layer protocol, in network-byte order
* @ret rc Return status code
*/ */
static int eth_push ( struct io_buffer *iobuf, struct net_device *netdev, static int eth_push ( struct io_buffer *iobuf, const void *ll_dest,
struct net_protocol *net_protocol, const void *ll_source, uint16_t net_proto ) {
const void *ll_dest ) {
struct ethhdr *ethhdr = iob_push ( iobuf, sizeof ( *ethhdr ) ); struct ethhdr *ethhdr = iob_push ( iobuf, sizeof ( *ethhdr ) );
/* Build Ethernet header */ /* Build Ethernet header */
memcpy ( ethhdr->h_dest, ll_dest, ETH_ALEN ); memcpy ( ethhdr->h_dest, ll_dest, ETH_ALEN );
memcpy ( ethhdr->h_source, netdev->ll_addr, ETH_ALEN ); memcpy ( ethhdr->h_source, ll_source, ETH_ALEN );
ethhdr->h_protocol = net_protocol->net_proto; ethhdr->h_protocol = net_proto;
return 0; return 0;
} }
@ -63,14 +63,13 @@ static int eth_push ( struct io_buffer *iobuf, struct net_device *netdev,
* Remove Ethernet link-layer header * Remove Ethernet link-layer header
* *
* @v iobuf I/O buffer * @v iobuf I/O buffer
* @v netdev Network device * @ret ll_dest Link-layer destination address
* @v net_proto Network-layer protocol, in network-byte order * @ret ll_source Source link-layer address
* @v ll_source Source link-layer address * @ret net_proto Network-layer protocol, in network-byte order
* @ret rc Return status code * @ret rc Return status code
*/ */
static int eth_pull ( struct io_buffer *iobuf, static int eth_pull ( struct io_buffer *iobuf, const void **ll_dest,
struct net_device *netdev __unused, const void **ll_source, uint16_t *net_proto ) {
uint16_t *net_proto, const void **ll_source ) {
struct ethhdr *ethhdr = iobuf->data; struct ethhdr *ethhdr = iobuf->data;
/* Sanity check */ /* Sanity check */
@ -84,8 +83,9 @@ static int eth_pull ( struct io_buffer *iobuf,
iob_pull ( iobuf, sizeof ( *ethhdr ) ); iob_pull ( iobuf, sizeof ( *ethhdr ) );
/* Fill in required fields */ /* Fill in required fields */
*net_proto = ethhdr->h_protocol; *ll_dest = ethhdr->h_dest;
*ll_source = ethhdr->h_source; *ll_source = ethhdr->h_source;
*net_proto = ethhdr->h_protocol;
return 0; return 0;
} }

View File

@ -439,6 +439,7 @@ struct net_device * find_netdev_by_location ( unsigned int bus_type,
*/ */
int net_tx ( struct io_buffer *iobuf, struct net_device *netdev, int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
struct net_protocol *net_protocol, const void *ll_dest ) { struct net_protocol *net_protocol, const void *ll_dest ) {
struct ll_protocol *ll_protocol = netdev->ll_protocol;
int rc; int rc;
/* Force a poll on the netdevice to (potentially) clear any /* Force a poll on the netdevice to (potentially) clear any
@ -449,8 +450,8 @@ int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
netdev_poll ( netdev ); netdev_poll ( netdev );
/* Add link-layer header */ /* Add link-layer header */
if ( ( rc = netdev->ll_protocol->push ( iobuf, netdev, net_protocol, if ( ( rc = ll_protocol->push ( iobuf, ll_dest, netdev->ll_addr,
ll_dest ) ) != 0 ) { net_protocol->net_proto ) ) != 0 ) {
free_iob ( iobuf ); free_iob ( iobuf );
return rc; return rc;
} }
@ -495,8 +496,9 @@ static void net_step ( struct process *process __unused ) {
struct net_device *netdev; struct net_device *netdev;
struct io_buffer *iobuf; struct io_buffer *iobuf;
struct ll_protocol *ll_protocol; struct ll_protocol *ll_protocol;
uint16_t net_proto; const void *ll_dest;
const void *ll_source; const void *ll_source;
uint16_t net_proto;
int rc; int rc;
/* Poll and process each network device */ /* Poll and process each network device */
@ -519,9 +521,9 @@ static void net_step ( struct process *process __unused ) {
/* Remove link-layer header */ /* Remove link-layer header */
ll_protocol = netdev->ll_protocol; ll_protocol = netdev->ll_protocol;
if ( ( rc = ll_protocol->pull ( iobuf, netdev, if ( ( rc = ll_protocol->pull ( iobuf, &ll_dest,
&net_proto, &ll_source,
&ll_source ) ) != 0 ) { &net_proto ) ) != 0 ) {
free_iob ( iobuf ); free_iob ( iobuf );
continue; continue;
} }