iPXE
Data Structures | Functions | Variables
neighbour.h File Reference

Neighbour discovery. More...

#include <stdint.h>
#include <ipxe/refcnt.h>
#include <ipxe/list.h>
#include <ipxe/netdevice.h>
#include <ipxe/retry.h>

Go to the source code of this file.

Data Structures

struct  neighbour_discovery
 A neighbour discovery protocol. More...
 
struct  neighbour
 A neighbour cache entry. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int neighbour_has_ll_dest (struct neighbour *neighbour)
 Test if neighbour cache entry has a valid link-layer address. More...
 
int neighbour_tx (struct io_buffer *iobuf, struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest, struct neighbour_discovery *discovery, const void *net_source, const void *ll_source)
 Transmit packet, determining link-layer address via neighbour discovery. More...
 
int neighbour_update (struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest, const void *ll_dest)
 Update existing neighbour cache entry. More...
 
int neighbour_define (struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest, const void *ll_dest)
 Define neighbour cache entry. More...
 

Variables

struct list_head neighbours
 The neighbour cache. More...
 

Detailed Description

Neighbour discovery.

Definition in file neighbour.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ neighbour_has_ll_dest()

static int neighbour_has_ll_dest ( struct neighbour neighbour)
inlinestatic

Test if neighbour cache entry has a valid link-layer address.

Parameters
neighbourNeighbour cache entry
Return values
has_ll_destNeighbour cache entry has a valid link-layer address

Definition at line 70 of file neighbour.h.

70  {
71  return ( ! timer_running ( &neighbour->timer ) );
72 }
struct retry_timer timer
Retransmission timer.
Definition: neighbour.h:57
A neighbour cache entry.
Definition: neighbour.h:37

References neighbour::timer.

Referenced by neighbour_tx(), and nstat().

◆ neighbour_tx()

int neighbour_tx ( struct io_buffer iobuf,
struct net_device netdev,
struct net_protocol net_protocol,
const void *  net_dest,
struct neighbour_discovery discovery,
const void *  net_source,
const void *  ll_source 
)

Transmit packet, determining link-layer address via neighbour discovery.

Parameters
iobufI/O buffer
netdevNetwork device
discoveryNeighbour discovery protocol
net_protocolNetwork-layer protocol
net_destDestination network-layer address
net_sourceSource network-layer address
ll_sourceSource link-layer address
Return values
rcReturn status code

Definition at line 299 of file neighbour.c.

302  {
303  struct neighbour *neighbour;
304 
305  /* Find or create neighbour cache entry */
307  if ( ! neighbour ) {
309  if ( ! neighbour )
310  return -ENOMEM;
312  }
313 
314  /* If a link-layer address is available then transmit
315  * immediately, otherwise queue for later transmission.
316  */
317  if ( neighbour_has_ll_dest ( neighbour ) ) {
318  return net_tx ( iobuf, netdev, net_protocol, neighbour->ll_dest,
319  ll_source );
320  } else {
321  DBGC2 ( neighbour, "NEIGHBOUR %s %s %s deferring packet\n",
323  net_protocol->ntoa ( net_dest ) );
324  list_add_tail ( &iobuf->list, &neighbour->tx_queue );
325  return 0;
326  }
327 }
const char * name
Protocol name.
Definition: netdevice.h:66
static struct neighbour * neighbour_find(struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest)
Find neighbour cache entry.
Definition: neighbour.c:118
static struct neighbour * neighbour_create(struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest)
Create neighbour cache entry.
Definition: neighbour.c:83
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:48
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct neighbour_discovery * discovery
Neighbour discovery protocol (if any)
Definition: neighbour.h:53
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
const char *(* ntoa)(const void *net_addr)
Transcribe network-layer address.
Definition: netdevice.h:94
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head tx_queue
Pending I/O buffers.
Definition: neighbour.h:60
uint8_t ll_dest[MAX_LL_ADDR_LEN]
Link-layer destination address.
Definition: neighbour.h:50
A neighbour cache entry.
Definition: neighbour.h:37
A network-layer protocol.
Definition: netdevice.h:64
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
int net_tx(struct io_buffer *iobuf, struct net_device *netdev, struct net_protocol *net_protocol, const void *ll_dest, const void *ll_source)
Transmit network-layer packet.
Definition: netdevice.c:1073
#define DBGC2(...)
Definition: compiler.h:522
uint8_t net_source[MAX_NET_ADDR_LEN]
Network-layer source address (if any)
Definition: neighbour.h:55
static int neighbour_has_ll_dest(struct neighbour *neighbour)
Test if neighbour cache entry has a valid link-layer address.
Definition: neighbour.h:70
static void neighbour_discover(struct neighbour *neighbour, struct neighbour_discovery *discovery, const void *net_source)
Start neighbour discovery.
Definition: neighbour.c:146

References DBGC2, neighbour::discovery, ENOMEM, io_buffer::list, list_add_tail, neighbour::ll_dest, net_protocol::name, net_device::name, neighbour_create(), neighbour_discover(), neighbour_find(), neighbour_has_ll_dest(), neighbour::net_dest, neighbour::net_source, net_tx(), netdev, net_protocol::ntoa, and neighbour::tx_queue.

Referenced by arp_tx(), and ndp_tx().

◆ neighbour_update()

int neighbour_update ( struct net_device netdev,
struct net_protocol net_protocol,
const void *  net_dest,
const void *  ll_dest 
)

Update existing neighbour cache entry.

Parameters
netdevNetwork device
net_protocolNetwork-layer protocol
net_destDestination network-layer address
ll_destDestination link-layer address
Return values
rcReturn status code

Definition at line 338 of file neighbour.c.

340  {
341  struct neighbour *neighbour;
342 
343  /* Find neighbour cache entry */
345  if ( ! neighbour )
346  return -ENOENT;
347 
348  /* Set destination address */
350 
351  return 0;
352 }
static struct neighbour * neighbour_find(struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest)
Find neighbour cache entry.
Definition: neighbour.c:118
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:48
#define ENOENT
No such file or directory.
Definition: errno.h:514
static struct net_device * netdev
Definition: gdbudp.c:52
uint8_t ll_dest[MAX_LL_ADDR_LEN]
Link-layer destination address.
Definition: neighbour.h:50
static void neighbour_discovered(struct neighbour *neighbour, const void *ll_dest)
Complete neighbour discovery.
Definition: neighbour.c:172
A neighbour cache entry.
Definition: neighbour.h:37
A network-layer protocol.
Definition: netdevice.h:64

References ENOENT, neighbour::ll_dest, neighbour_discovered(), neighbour_find(), neighbour::net_dest, and netdev.

Referenced by arp_rx(), and ndp_rx_neighbour_advertisement_ll_target().

◆ neighbour_define()

int neighbour_define ( struct net_device netdev,
struct net_protocol net_protocol,
const void *  net_dest,
const void *  ll_dest 
)

Define neighbour cache entry.

Parameters
netdevNetwork device
net_protocolNetwork-layer protocol
net_destDestination network-layer address
ll_destDestination link-layer address, if known
Return values
rcReturn status code

Definition at line 363 of file neighbour.c.

365  {
366  struct neighbour *neighbour;
367 
368  /* Find or create neighbour cache entry */
370  if ( ! neighbour ) {
372  if ( ! neighbour )
373  return -ENOMEM;
374  }
375 
376  /* Set destination address */
378 
379  return 0;
380 }
static struct neighbour * neighbour_find(struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest)
Find neighbour cache entry.
Definition: neighbour.c:118
static struct neighbour * neighbour_create(struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest)
Create neighbour cache entry.
Definition: neighbour.c:83
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:48
#define ENOMEM
Not enough space.
Definition: errno.h:534
static struct net_device * netdev
Definition: gdbudp.c:52
uint8_t ll_dest[MAX_LL_ADDR_LEN]
Link-layer destination address.
Definition: neighbour.h:50
static void neighbour_discovered(struct neighbour *neighbour, const void *ll_dest)
Complete neighbour discovery.
Definition: neighbour.c:172
A neighbour cache entry.
Definition: neighbour.h:37
A network-layer protocol.
Definition: netdevice.h:64

References ENOMEM, neighbour::ll_dest, neighbour_create(), neighbour_discovered(), neighbour_find(), neighbour::net_dest, and netdev.

Referenced by ndp_rx_neighbour_solicitation_ll_source(), and ndp_rx_router_advertisement_ll_source().

Variable Documentation

◆ neighbours

struct list_head neighbours

The neighbour cache.

Definition at line 52 of file neighbour.c.

Referenced by neighbour_create(), neighbour_discard(), neighbour_find(), neighbour_flush(), and nstat().