diff options
author | Michael Brown | 2006-06-18 00:36:27 +0200 |
---|---|---|
committer | Michael Brown | 2006-06-18 00:36:27 +0200 |
commit | 3c8aafa2099c13799fdb4f42d06f1abd278b14f7 (patch) | |
tree | dda612574bf0c128cc58ff4f7231b73f019f8e2b /src/net/ethernet.c | |
parent | Remove dependency on arptable[] (which is no longer used). (diff) | |
download | ipxe-3c8aafa2099c13799fdb4f42d06f1abd278b14f7.tar.gz ipxe-3c8aafa2099c13799fdb4f42d06f1abd278b14f7.tar.xz ipxe-3c8aafa2099c13799fdb4f42d06f1abd278b14f7.zip |
Simplify RX data path.
Kill off the static single net device and move to proper dynamic
registration (which we need with the new device model).
Break the (flawed) assumption that all network-layer protocols can use
ARP; such network-layer protocols (i.e. IPv4) must now register as an ARP
protocol using ARP_NET_PROTOCOL() and provide a single method for checking
the existence of a local network-layer address.
Diffstat (limited to 'src/net/ethernet.c')
-rw-r--r-- | src/net/ethernet.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/net/ethernet.c b/src/net/ethernet.c index ab7d4277..13b3c2db 100644 --- a/src/net/ethernet.c +++ b/src/net/ethernet.c @@ -46,41 +46,43 @@ static uint8_t eth_broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; * * Prepends the Ethernet link-layer header and transmits the packet. */ -static int eth_transmit ( struct pk_buff *pkb, struct net_device *netdev, - struct net_protocol *net_protocol, - const void *ll_dest ) { +static int eth_tx ( struct pk_buff *pkb, struct net_device *netdev, + struct net_protocol *net_protocol, const void *ll_dest ) { struct ethhdr *ethhdr = pkb_push ( pkb, sizeof ( *ethhdr ) ); + /* Build Ethernet header */ memcpy ( ethhdr->h_dest, ll_dest, ETH_ALEN ); memcpy ( ethhdr->h_source, netdev->ll_addr, ETH_ALEN ); ethhdr->h_protocol = net_protocol->net_proto; - return netdev_transmit ( netdev, pkb ); + + /* Hand off to network device */ + return netdev_tx ( netdev, pkb ); } /** - * Parse Ethernet link-layer header + * Process received Ethernet packet * * @v pkb Packet buffer - * @v llhdr Generic link-layer header + * @v netdev Network device * - * Fills in the generic link-layer header based on information in the - * Ethernet link-layer header in the packet buffer. + * Strips off the Ethernet link-layer header and passes up to the + * network-layer protocol. */ -static void eth_parse_llh ( const struct pk_buff *pkb, - struct ll_header *llhdr ) { +static void eth_rx ( struct pk_buff *pkb, struct net_device *netdev ) { struct ethhdr *ethhdr = pkb->data; - memcpy ( llhdr->dest_ll_addr, ethhdr->h_dest, ETH_ALEN ); - memcpy ( llhdr->source_ll_addr, ethhdr->h_source, ETH_ALEN ); - llhdr->net_proto = ethhdr->h_protocol; - - if ( memcmp ( ethhdr->h_dest, eth_broadcast, ETH_ALEN ) == 0 ) { - llhdr->flags = PKT_FL_BROADCAST; - } else if ( ethhdr->h_dest[0] & 0x01 ) { - llhdr->flags = PKT_FL_MULTICAST; - } else { - llhdr->flags = 0; + /* Sanity check */ + if ( pkb_len ( pkb ) < sizeof ( *ethhdr ) ) { + DBG ( "Ethernet packet too short (%d bytes)\n", + pkb_len ( pkb ) ); + return; } + + /* Strip off Ethernet header */ + pkb_pull ( pkb, sizeof ( *ethhdr ) ); + + /* Hand off to network-layer protocol */ + net_rx ( pkb, netdev, ethhdr->h_protocol, ethhdr->h_source ); } /** @@ -105,8 +107,8 @@ struct ll_protocol ethernet_protocol = { .ll_proto = htons ( ARPHRD_ETHER ), .ll_addr_len = ETH_ALEN, .ll_broadcast = eth_broadcast, - .transmit = eth_transmit, - .parse_llh = eth_parse_llh, + .tx = eth_tx, + .rx = eth_rx, .ntoa = eth_ntoa, }; |