Skip to content

Commit

Permalink
[netdevice] Add concept of a network device index
Browse files Browse the repository at this point in the history
IPv6 link-local socket addresses require some way to specify a local
network device.  We cannot simply use a pointer to the network device,
since a struct sockaddr_in6 may be long-lived and has no way to hold a
reference to the network device.

Using a network device index allows a socket address to cleanly refer
to a network device without worrying about whether or not that device
continues to exist.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Sep 3, 2013
1 parent c9ed9cb commit d5f69e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/include/ipxe/netdevice.h
Expand Up @@ -300,6 +300,8 @@ struct net_device {
struct list_head list;
/** List of open network devices */
struct list_head open_list;
/** Index of this network device */
unsigned int index;
/** Name of this network device */
char name[12];
/** Underlying hardware device */
Expand Down
5 changes: 3 additions & 2 deletions src/net/netdevice.c
Expand Up @@ -498,10 +498,11 @@ int register_netdev ( struct net_device *netdev ) {
uint32_t seed;
int rc;

/* Create device name */
/* Record device index and create device name */
netdev->index = ifindex++;
if ( netdev->name[0] == '\0' ) {
snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
ifindex++ );
netdev->index );
}

/* Set initial link-layer address, if not already set */
Expand Down

0 comments on commit d5f69e9

Please sign in to comment.