Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[netdevice] Pass both link-layer addresses in net_tx() and net_rx()
FCoE requires the use of fabric-provided MAC addresses, which breaks
the assumption that the net device's MAC address is implicitly the
source address for net_tx() and the (unicast) destination address for
net_rx().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Oct 7, 2010
1 parent d57d499 commit 88dd921
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 31 deletions.
5 changes: 3 additions & 2 deletions src/include/ipxe/eapol.h
Expand Up @@ -90,7 +90,8 @@ struct eapol_handler
*
* @v iob I/O buffer containing packet payload
* @v netdev Network device from which packet was received
* @v ll_source Source link-layer address from which packet was received
* @V ll_dest Destination link-layer address
* @v ll_source Source link-layer address
* @ret rc Return status code
*
* The I/O buffer will have the EAPOL header pulled off it, so
Expand All @@ -99,7 +100,7 @@ struct eapol_handler
* This function takes ownership of the I/O buffer passed to it.
*/
int ( * rx ) ( struct io_buffer *iob, struct net_device *netdev,
const void *ll_source );
const void *ll_dest, const void *ll_source );
};

#define EAPOL_HANDLERS __table ( struct eapol_handler, "eapol_handlers" )
Expand Down
9 changes: 6 additions & 3 deletions src/include/ipxe/netdevice.h
Expand Up @@ -57,12 +57,13 @@ struct net_protocol {
*
* @v iobuf I/O buffer
* @v netdev Network device
* @v ll_dest Link-layer destination address
* @v ll_source Link-layer source address
*
* This method takes ownership of the I/O buffer.
*/
int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev,
const void *ll_source );
const void *ll_dest, const void *ll_source );
/**
* Transcribe network-layer address
*
Expand Down Expand Up @@ -534,9 +535,11 @@ extern struct net_device * find_netdev_by_location ( unsigned int bus_type,
unsigned int location );
extern struct net_device * last_opened_netdev ( void );
extern 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,
const void *ll_source );
extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
uint16_t net_proto, const void *ll_source );
uint16_t net_proto, const void *ll_dest,
const void *ll_source );

/**
* Complete network transmission
Expand Down
4 changes: 3 additions & 1 deletion src/net/80211/wpa.c
Expand Up @@ -455,7 +455,7 @@ static int wpa_send_eapol ( struct io_buffer *iob, struct wpa_common_ctx *ctx,
pkt->mic );

return net_tx ( iob, ctx->dev->netdev, &eapol_protocol,
ctx->dev->bssid );
ctx->dev->bssid, ctx->dev->netdev->ll_addr );
}


Expand Down Expand Up @@ -757,9 +757,11 @@ static int wpa_handle_1_of_2 ( struct wpa_common_ctx *ctx,
*
* @v iob I/O buffer
* @v netdev Network device
* @v ll_dest Link-layer destination address
* @v ll_source Source link-layer address
*/
static int eapol_key_rx ( struct io_buffer *iob, struct net_device *netdev,
const void *ll_dest __unused,
const void *ll_source )
{
struct net80211_device *dev = net80211_get ( netdev );
Expand Down
9 changes: 6 additions & 3 deletions src/net/aoe.c
Expand Up @@ -249,13 +249,14 @@ static void aoecmd_close ( struct aoe_command *aoecmd, int rc ) {
*/
static int aoecmd_tx ( struct aoe_command *aoecmd ) {
struct aoe_device *aoedev = aoecmd->aoedev;
struct net_device *netdev = aoedev->netdev;
struct io_buffer *iobuf;
struct aoehdr *aoehdr;
size_t cmd_len;
int rc;

/* Sanity check */
assert ( aoedev->netdev != NULL );
assert ( netdev != NULL );

/* If we are transmitting anything that requires a response,
* start the retransmission timer. Do this before attempting
Expand All @@ -281,8 +282,8 @@ static int aoecmd_tx ( struct aoe_command *aoecmd ) {
aoecmd->type->cmd ( aoecmd, iobuf->data, iob_len ( iobuf ) );

/* Send packet */
if ( ( rc = net_tx ( iobuf, aoedev->netdev, &aoe_protocol,
aoedev->target ) ) != 0 ) {
if ( ( rc = net_tx ( iobuf, netdev, &aoe_protocol, aoedev->target,
netdev->ll_addr ) ) != 0 ) {
DBGC ( aoedev, "AoE %s/%08x could not transmit: %s\n",
aoedev_name ( aoedev ), aoecmd->tag,
strerror ( rc ) );
Expand Down Expand Up @@ -903,12 +904,14 @@ static int aoedev_open ( struct interface *parent, struct net_device *netdev,
*
* @v iobuf I/O buffer
* @v netdev Network device
* @v ll_dest Link-layer destination address
* @v ll_source Link-layer source address
* @ret rc Return status code
*
*/
static int aoe_rx ( struct io_buffer *iobuf,
struct net_device *netdev __unused,
const void *ll_dest __unused,
const void *ll_source ) {
struct aoehdr *aoehdr = iobuf->data;
struct aoe_command *aoecmd;
Expand Down
7 changes: 4 additions & 3 deletions src/net/arp.c
Expand Up @@ -155,8 +155,8 @@ int arp_resolve ( struct net_device *netdev, struct net_protocol *net_protocol,
dest_net_addr, net_protocol->net_addr_len );

/* Transmit ARP request */
if ( ( rc = net_tx ( iobuf, netdev, &arp_protocol,
netdev->ll_broadcast ) ) != 0 )
if ( ( rc = net_tx ( iobuf, netdev, &arp_protocol,
netdev->ll_broadcast, netdev->ll_addr ) ) != 0 )
return rc;

return -ENOENT;
Expand Down Expand Up @@ -195,6 +195,7 @@ static struct arp_net_protocol * arp_find_protocol ( uint16_t net_proto ) {
* details.
*/
static int arp_rx ( struct io_buffer *iobuf, struct net_device *netdev,
const void *ll_dest __unused,
const void *ll_source __unused ) {
struct arphdr *arphdr = iobuf->data;
struct arp_net_protocol *arp_net_protocol;
Expand Down Expand Up @@ -261,7 +262,7 @@ static int arp_rx ( struct io_buffer *iobuf, struct net_device *netdev,

/* Send reply */
net_tx ( iob_disown ( iobuf ), netdev, &arp_protocol,
arp_target_ha ( arphdr ) );
arp_target_ha ( arphdr ), netdev->ll_addr );

done:
free_iob ( iobuf );
Expand Down
6 changes: 3 additions & 3 deletions src/net/eapol.c
Expand Up @@ -36,13 +36,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
* @v iob I/O buffer
* @v netdev Network device
* @v ll_dest Link-layer destination address
* @v ll_source Link-layer source address
*
* This function takes ownership of the I/O buffer passed to it.
*/
static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
const void *ll_source )
{
const void *ll_dest, const void *ll_source ) {
struct eapol_frame *eapol = iob->data;
struct eapol_handler *handler;

Expand All @@ -54,7 +54,7 @@ static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
for_each_table_entry ( handler, EAPOL_HANDLERS ) {
if ( handler->type == eapol->type ) {
iob_pull ( iob, EAPOL_HDR_LEN );
return handler->rx ( iob, netdev, ll_source );
return handler->rx ( iob, netdev, ll_dest, ll_source );
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/net/eth_slow.c
Expand Up @@ -174,7 +174,8 @@ static int eth_slow_lacp_rx ( struct io_buffer *iobuf,

/* Send response */
eth_slow_lacp_dump ( iobuf, netdev, "TX" );
return net_tx ( iobuf, netdev, &eth_slow_protocol, eth_slow_address );
return net_tx ( iobuf, netdev, &eth_slow_protocol, eth_slow_address,
netdev->ll_addr );
}

/**
Expand Down Expand Up @@ -218,7 +219,7 @@ static int eth_slow_marker_rx ( struct io_buffer *iobuf,
marker->marker.tlv.type = ETH_SLOW_TLV_MARKER_RESPONSE;
eth_slow_marker_dump ( iobuf, netdev, "TX" );
return net_tx ( iobuf, netdev, &eth_slow_protocol,
eth_slow_address );
eth_slow_address, netdev->ll_addr );
} else {
/* Discard all other marker packets */
free_iob ( iobuf );
Expand All @@ -231,11 +232,13 @@ static int eth_slow_marker_rx ( struct io_buffer *iobuf,
*
* @v iobuf I/O buffer
* @v netdev Network device
* @v ll_dest Link-layer destination address
* @v ll_source Link-layer source address
* @ret rc Return status code
*/
static int eth_slow_rx ( struct io_buffer *iobuf,
struct net_device *netdev,
const void *ll_dest __unused,
const void *ll_source __unused ) {
union eth_slow_packet *eth_slow = iobuf->data;

Expand Down
8 changes: 4 additions & 4 deletions src/net/fcoe.c
Expand Up @@ -129,7 +129,7 @@ static int fcoe_deliver ( struct fcoe_port *fcoe,

/* Transmit packet */
if ( ( rc = net_tx ( iob_disown ( iobuf ), fcoe->netdev, &fcoe_protocol,
fcoe->fcf_ll_addr ) ) != 0 ) {
fcoe->fcf_ll_addr, fcoe->netdev->ll_addr )) != 0){
DBGC ( fcoe, "FCoE %s could not transmit: %s\n",
fcoe->netdev->name, strerror ( rc ) );
goto done;
Expand Down Expand Up @@ -164,12 +164,12 @@ static struct io_buffer * fcoe_alloc_iob ( struct fcoe_port *fcoe __unused,
*
* @v iobuf I/O buffer
* @v netdev Network device
* @v ll_dest Link-layer destination address
* @v ll_source Link-layer source address
* @ret rc Return status code
*/
static int fcoe_rx ( struct io_buffer *iobuf,
struct net_device *netdev,
const void *ll_source ) {
static int fcoe_rx ( struct io_buffer *iobuf, struct net_device *netdev,
const void *ll_dest __unused, const void *ll_source ) {
struct fcoe_header *fcoehdr;
struct fcoe_footer *fcoeftr;
struct fcoe_port *fcoe;
Expand Down
8 changes: 6 additions & 2 deletions src/net/ipv4.c
Expand Up @@ -355,7 +355,8 @@ static int ipv4_tx ( struct io_buffer *iobuf,
ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );

/* Hand off to link layer */
if ( ( rc = net_tx ( iobuf, netdev, &ipv4_protocol, ll_dest ) ) != 0 ) {
if ( ( rc = net_tx ( iobuf, netdev, &ipv4_protocol, ll_dest,
netdev->ll_addr ) ) != 0 ) {
DBG ( "IPv4 could not transmit packet via %s: %s\n",
netdev->name, strerror ( rc ) );
return rc;
Expand All @@ -373,12 +374,15 @@ static int ipv4_tx ( struct io_buffer *iobuf,
*
* @v iobuf I/O buffer
* @v netdev Network device
* @v ll_dest Link-layer destination address
* @v ll_source Link-layer destination source
*
* This function expects an IP4 network datagram. It processes the headers
* and sends it to the transport layer.
*/
static int ipv4_rx ( struct io_buffer *iobuf, struct net_device *netdev __unused,
static int ipv4_rx ( struct io_buffer *iobuf,
struct net_device *netdev __unused,
const void *ll_dest __unused,
const void *ll_source __unused ) {
struct iphdr *iphdr = iobuf->data;
size_t hdrlen;
Expand Down
5 changes: 4 additions & 1 deletion src/net/ipv6.c
Expand Up @@ -242,7 +242,8 @@ static int ipv6_tx ( struct io_buffer *iobuf,
}

/* Transmit packet */
return net_tx ( iobuf, netdev, &ipv6_protocol, ll_dest );
return net_tx ( iobuf, netdev, &ipv6_protocol, ll_dest,
netdev->ll_addr );

err:
free_iob ( iobuf );
Expand Down Expand Up @@ -285,12 +286,14 @@ static int ipv6_process_nxt_hdr ( struct io_buffer *iobuf, uint8_t nxt_hdr,
*
* @v iobuf I/O buffer
* @v netdev Network device
* @v ll_dest Link-layer destination address
* @v ll_source Link-layer source address
*
* This function processes a IPv6 packet
*/
static int ipv6_rx ( struct io_buffer *iobuf,
__unused struct net_device *netdev,
__unused const void *ll_dest,
__unused const void *ll_source ) {

struct ip6_header *ip6hdr = iobuf->data;
Expand Down
15 changes: 10 additions & 5 deletions src/net/netdevice.c
Expand Up @@ -607,14 +607,16 @@ struct net_device * last_opened_netdev ( void ) {
* @v netdev Network device
* @v net_protocol Network-layer protocol
* @v ll_dest Destination link-layer address
* @v ll_source Source link-layer address
* @ret rc Return status code
*
* Prepends link-layer headers to the I/O buffer and transmits the
* packet via the specified network device. This function takes
* ownership of the I/O buffer.
*/
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,
const void *ll_source ) {
struct ll_protocol *ll_protocol = netdev->ll_protocol;
int rc;

Expand All @@ -626,7 +628,7 @@ int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
netdev_poll ( netdev );

/* Add link-layer header */
if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest, netdev->ll_addr,
if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest, ll_source,
net_protocol->net_proto ) ) != 0 ) {
free_iob ( iobuf );
return rc;
Expand All @@ -642,17 +644,19 @@ int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
* @v iobuf I/O buffer
* @v netdev Network device
* @v net_proto Network-layer protocol, in network-byte order
* @v ll_dest Destination link-layer address
* @v ll_source Source link-layer address
* @ret rc Return status code
*/
int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
uint16_t net_proto, const void *ll_source ) {
uint16_t net_proto, const void *ll_dest, const void *ll_source ) {
struct net_protocol *net_protocol;

/* Hand off to network-layer protocol, if any */
for_each_table_entry ( net_protocol, NET_PROTOCOLS ) {
if ( net_protocol->net_proto == net_proto )
return net_protocol->rx ( iobuf, netdev, ll_source );
return net_protocol->rx ( iobuf, netdev, ll_dest,
ll_source );
}

DBGC ( netdev, "NETDEV %p unknown network protocol %04x\n",
Expand Down Expand Up @@ -707,7 +711,8 @@ static void net_step ( struct process *process __unused ) {

/* Hand packet to network layer */
if ( ( rc = net_rx ( iob_disown ( iobuf ), netdev,
net_proto, ll_source ) ) != 0 ) {
net_proto, ll_dest,
ll_source ) ) != 0 ) {
/* Record error for diagnosis */
netdev_rx_err ( netdev, NULL, rc );
}
Expand Down
2 changes: 2 additions & 0 deletions src/net/rarp.c
Expand Up @@ -36,13 +36,15 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
* @v iobuf I/O buffer
* @v netdev Network device
* @v ll_dest Link-layer destination address
* @v ll_source Link-layer source address
* @ret rc Return status code
*
* This is a dummy method which simply discards RARP packets.
*/
static int rarp_rx ( struct io_buffer *iobuf,
struct net_device *netdev __unused,
const void *ll_dest __unused,
const void *ll_source __unused ) {
free_iob ( iobuf );
return 0;
Expand Down
6 changes: 4 additions & 2 deletions src/usr/lotest.c
Expand Up @@ -45,11 +45,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
* @v iobuf I/O buffer
* @v netdev Network device
* @v ll_dest Link-layer destination address
* @v ll_source Link-layer source address
* @ret rc Return status code
*/
static int lotest_rx ( struct io_buffer *iobuf,
struct net_device *netdev __unused,
const void *ll_dest __unused,
const void *ll_source __unused ) {
free_iob ( iobuf );
return -ENOTSUP;
Expand Down Expand Up @@ -138,8 +140,8 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,

/* Transmit packet */
if ( ( rc = net_tx ( iob_disown ( iobuf ), sender,
&lotest_protocol,
receiver->ll_addr ) ) != 0 ) {
&lotest_protocol, receiver->ll_addr,
sender->ll_addr ) ) != 0 ) {
printf ( "\nFailed to transmit packet: %s",
strerror ( rc ) );
goto done;
Expand Down

0 comments on commit 88dd921

Please sign in to comment.