ethernet.c File Reference

Ethernet protocol. More...

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <byteswap.h>
#include <errno.h>
#include <assert.h>
#include <gpxe/if_arp.h>
#include <gpxe/if_ether.h>
#include <gpxe/in.h>
#include <gpxe/netdevice.h>
#include <gpxe/iobuf.h>
#include <gpxe/ethernet.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static int eth_push (struct net_device *netdev __unused, struct io_buffer *iobuf, const void *ll_dest, const void *ll_source, uint16_t net_proto)
 Add Ethernet link-layer header.
static int eth_pull (struct net_device *netdev __unused, struct io_buffer *iobuf, const void **ll_dest, const void **ll_source, uint16_t *net_proto)
 Remove Ethernet link-layer header.
void eth_init_addr (const void *hw_addr, void *ll_addr)
 Initialise Ethernet address.
const char * eth_ntoa (const void *ll_addr)
 Transcribe Ethernet address.
int eth_mc_hash (unsigned int af, const void *net_addr, void *ll_addr)
 Hash multicast address.
int eth_eth_addr (const void *ll_addr, void *eth_addr)
 Generate Ethernet-compatible compressed link-layer address.
struct net_devicealloc_etherdev (size_t priv_size)
 Allocate Ethernet device.

Variables

static uint8_t eth_broadcast [ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
 Ethernet broadcast MAC address.
struct ll_protocol
ethernet_protocol 
__ll_protocol
 Ethernet protocol.


Detailed Description

Ethernet protocol.

Definition in file ethernet.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static int eth_push ( struct net_device *netdev  __unused,
struct io_buffer iobuf,
const void *  ll_dest,
const void *  ll_source,
uint16_t  net_proto 
) [static]

Add Ethernet link-layer header.

Parameters:
netdev Network device
iobuf I/O buffer
ll_dest Link-layer destination address
ll_source Source link-layer address
net_proto Network-layer protocol, in network-byte order
Return values:
rc Return status code

Definition at line 53 of file ethernet.c.

References ETH_ALEN, ethhdr::h_dest, ethhdr::h_protocol, ethhdr::h_source, iob_push, and memcpy.

00055                                                                   {
00056         struct ethhdr *ethhdr = iob_push ( iobuf, sizeof ( *ethhdr ) );
00057 
00058         /* Build Ethernet header */
00059         memcpy ( ethhdr->h_dest, ll_dest, ETH_ALEN );
00060         memcpy ( ethhdr->h_source, ll_source, ETH_ALEN );
00061         ethhdr->h_protocol = net_proto;
00062 
00063         return 0;
00064 }

static int eth_pull ( struct net_device *netdev  __unused,
struct io_buffer iobuf,
const void **  ll_dest,
const void **  ll_source,
uint16_t net_proto 
) [static]

Remove Ethernet link-layer header.

Parameters:
netdev Network device
iobuf I/O buffer
Return values:
ll_dest Link-layer destination address
ll_source Source link-layer address
net_proto Network-layer protocol, in network-byte order
rc Return status code

Definition at line 76 of file ethernet.c.

References io_buffer::data, DBG, EINVAL, ethhdr::h_dest, ethhdr::h_protocol, ethhdr::h_source, iob_len(), and iob_pull.

00078                                                                     {
00079         struct ethhdr *ethhdr = iobuf->data;
00080 
00081         /* Sanity check */
00082         if ( iob_len ( iobuf ) < sizeof ( *ethhdr ) ) {
00083                 DBG ( "Ethernet packet too short (%zd bytes)\n",
00084                       iob_len ( iobuf ) );
00085                 return -EINVAL;
00086         }
00087 
00088         /* Strip off Ethernet header */
00089         iob_pull ( iobuf, sizeof ( *ethhdr ) );
00090 
00091         /* Fill in required fields */
00092         *ll_dest = ethhdr->h_dest;
00093         *ll_source = ethhdr->h_source;
00094         *net_proto = ethhdr->h_protocol;
00095 
00096         return 0;
00097 }

void eth_init_addr ( const void *  hw_addr,
void *  ll_addr 
)

Initialise Ethernet address.

Parameters:
hw_addr Hardware address
ll_addr Link-layer address

Definition at line 105 of file ethernet.c.

References ETH_ALEN, and memcpy.

00105                                                           {
00106         memcpy ( ll_addr, hw_addr, ETH_ALEN );
00107 }

const char* eth_ntoa ( const void *  ll_addr  ) 

Transcribe Ethernet address.

Parameters:
ll_addr Link-layer address
Return values:
string Link-layer address in human-readable format

Definition at line 115 of file ethernet.c.

References sprintf.

Referenced by amd8111e_get_mac_address(), aoe_rx_cfg(), b44_probe(), bnx2_probe(), corkscrew_probe1(), cs89x0_probe(), davicom_probe(), dmfe_probe(), eepro_probe(), epic100_probe(), eth_probe(), forcedeth_probe(), ibft_fill_nic(), iwlist(), mtd_probe(), ne_probe(), net80211_probe_step(), net80211_step_associate(), pcnet32_probe(), phantom_add_macaddr(), phantom_del_macaddr(), phantom_get_macaddr(), prism2_probe(), rhine_probe1(), rtl8169_probe(), smc9000_probe(), t595_probe(), t5x9_probe(), tg3_probe(), tlan_probe(), tulip_probe(), undinet_probe(), velocity_probe(), vxge_probe(), w89c840_probe(), and wpa_derive_ptk().

00115                                               {
00116         static char buf[18]; /* "00:00:00:00:00:00" */
00117         const uint8_t *eth_addr = ll_addr;
00118 
00119         sprintf ( buf, "%02x:%02x:%02x:%02x:%02x:%02x",
00120                   eth_addr[0], eth_addr[1], eth_addr[2],
00121                   eth_addr[3], eth_addr[4], eth_addr[5] );
00122         return buf;
00123 }

int eth_mc_hash ( unsigned int  af,
const void *  net_addr,
void *  ll_addr 
)

Hash multicast address.

Parameters:
af Address family
net_addr Network-layer address
ll_addr Link-layer address to fill in
Return values:
rc Return status code

Definition at line 133 of file ethernet.c.

References AF_INET, and ENOTSUP.

00133                                                                          {
00134         const uint8_t *net_addr_bytes = net_addr;
00135         uint8_t *ll_addr_bytes = ll_addr;
00136 
00137         switch ( af ) {
00138         case AF_INET:
00139                 ll_addr_bytes[0] = 0x01;
00140                 ll_addr_bytes[1] = 0x00;
00141                 ll_addr_bytes[2] = 0x5e;
00142                 ll_addr_bytes[3] = net_addr_bytes[1] & 0x7f;
00143                 ll_addr_bytes[4] = net_addr_bytes[2];
00144                 ll_addr_bytes[5] = net_addr_bytes[3];
00145                 return 0;
00146         default:
00147                 return -ENOTSUP;
00148         }
00149 }

int eth_eth_addr ( const void *  ll_addr,
void *  eth_addr 
)

Generate Ethernet-compatible compressed link-layer address.

Parameters:
ll_addr Link-layer address
eth_addr Ethernet-compatible address to fill in

Definition at line 157 of file ethernet.c.

References ETH_ALEN, and memcpy.

00157                                                          {
00158         memcpy ( eth_addr, ll_addr, ETH_ALEN );
00159         return 0;
00160 }

struct net_device* alloc_etherdev ( size_t  priv_size  )  [read]

Allocate Ethernet device.

Parameters:
priv_size Size of driver private data
Return values:
netdev Network device, or NULL

Definition at line 183 of file ethernet.c.

References alloc_netdev(), eth_broadcast, ETH_FRAME_LEN, net_device::ll_broadcast, net_device::ll_protocol, net_device::max_pkt_len, and netdev.

Referenced by a3c90x_probe(), atl1e_probe(), b44_probe(), e1000_probe(), e1000e_probe(), efab_probe(), ifec_pci_probe(), igb_probe(), legacy_probe(), mtnic_probe(), myri10ge_pci_probe(), natsemi_probe(), phantom_probe(), pnic_probe(), rtl8169_probe(), rtl_probe(), sis190_init_board(), skge_devinit(), sky2_init_netdev(), undinet_probe(), and vxge_device_register().

00183                                                         {
00184         struct net_device *netdev;
00185 
00186         netdev = alloc_netdev ( priv_size );
00187         if ( netdev ) {
00188                 netdev->ll_protocol = &ethernet_protocol;
00189                 netdev->ll_broadcast = eth_broadcast;
00190                 netdev->max_pkt_len = ETH_FRAME_LEN;
00191         }
00192         return netdev;
00193 }


Variable Documentation

uint8_t eth_broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} [static]

Ethernet broadcast MAC address.

Definition at line 41 of file ethernet.c.

Referenced by alloc_etherdev().

struct ll_protocol ethernet_protocol __ll_protocol

Initial value:

 {
        .name           = "Ethernet",
        .ll_proto       = htons ( ARPHRD_ETHER ),
        .hw_addr_len    = ETH_ALEN,
        .ll_addr_len    = ETH_ALEN,
        .ll_header_len  = ETH_HLEN,
        .push           = eth_push,
        .pull           = eth_pull,
        .init_addr      = eth_init_addr,
        .ntoa           = eth_ntoa,
        .mc_hash        = eth_mc_hash,
        .eth_addr       = eth_eth_addr,
}
Ethernet protocol.

Definition at line 163 of file ethernet.c.


Generated on Tue Apr 6 20:01:55 2010 for gPXE by  doxygen 1.5.7.1