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...
 
struct  neighbour_delay
 A neighbour transmission delay pseudo-header. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
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)
 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  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 
)

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
Return values
rcReturn status code

Definition at line 377 of file neighbour.c.

380  {
381  struct neighbour *neighbour;
382  struct neighbour_delay *delay;
383  int rc;
384 
385  /* Find or create neighbour cache entry */
386  neighbour = neighbour_find ( netdev, net_protocol, net_dest );
387  if ( ! neighbour ) {
389  if ( ! neighbour )
390  return -ENOMEM;
391  neighbour_discover ( neighbour, discovery, net_source );
392  }
393 
394  /* If discovery is still in progress or if delay injection is
395  * in use, then queue for later transmission.
396  */
398 
399  /* Add to deferred packet queue */
400  DBGC2 ( neighbour, "NEIGHBOUR %s %s %s deferring packet\n",
402  net_protocol->ntoa ( net_dest ) );
403  list_add_tail ( &iobuf->list, &neighbour->tx_queue );
404 
405  /* Handle delay injection, if applicable */
406  if ( NEIGHBOUR_DELAY_MS ) {
407 
408  /* Record original transmission time */
409  delay = iob_push ( iobuf, sizeof ( *delay ) );
410  delay->start = currticks();
411 
412  /* Add pending operation */
414 
415  /* Process deferred packet queue, if possible */
416  if ( ! neighbour->discovery )
418  }
419 
420  return 0;
421  }
422 
423  /* Otherwise, transmit immediately */
424  if ( ( rc = net_tx ( iobuf, netdev, net_protocol, neighbour->ll_dest,
425  netdev->ll_addr ) ) != 0 ) {
426  return rc;
427  }
428 
429  return 0;
430 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Protocol name.
Definition: netdevice.h:67
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:136
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:101
#define iob_push(iobuf, len)
Definition: iobuf.h:89
#define ENOMEM
Not enough space.
Definition: errno.h:535
struct neighbour_discovery * discovery
Neighbour discovery protocol (if discovery is ongoing)
Definition: neighbour.h:54
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
const char *(* ntoa)(const void *net_addr)
Transcribe network-layer address.
Definition: netdevice.h:95
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head tx_queue
Pending I/O buffers.
Definition: neighbour.h:61
uint8_t ll_dest[MAX_LL_ADDR_LEN]
Link-layer destination address.
Definition: neighbour.h:51
#define NEIGHBOUR_DELAY_MS
Definition: fault.h:19
A neighbour cache entry.
Definition: neighbour.h:38
A network-layer protocol.
Definition: netdevice.h:65
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:45
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:1074
#define DBGC2(...)
Definition: compiler.h:522
uint16_t delay
Forward delay.
Definition: stp.h:41
static struct pending_operation neighbour_delayed
Pending operation for delayed transmissions.
Definition: neighbour.c:70
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
A neighbour transmission delay pseudo-header.
Definition: neighbour.h:65
unsigned long currticks(void)
Get current system time in ticks.
Definition: timer.c:43
void pending_get(struct pending_operation *pending)
Mark an operation as pending.
Definition: pending.c:46
static void neighbour_tx_queue(struct neighbour *neighbour)
Transmit deferred packets.
Definition: neighbour.c:189
static void neighbour_discover(struct neighbour *neighbour, struct neighbour_discovery *discovery, const void *net_source)
Start neighbour discovery.
Definition: neighbour.c:164

References currticks(), DBGC2, delay, neighbour::discovery, ENOMEM, iob_push, io_buffer::list, list_add_tail, net_device::ll_addr, neighbour::ll_dest, net_protocol::name, net_device::name, neighbour_create(), NEIGHBOUR_DELAY_MS, neighbour_delayed, neighbour_discover(), neighbour_find(), neighbour_tx_queue(), net_tx(), netdev, net_protocol::ntoa, pending_get(), rc, 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 441 of file neighbour.c.

443  {
444  struct neighbour *neighbour;
445 
446  /* Find neighbour cache entry */
448  if ( ! neighbour )
449  return -ENOENT;
450 
451  /* Set destination address */
453 
454  return 0;
455 }
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:136
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:49
#define ENOENT
No such file or directory.
Definition: errno.h:515
static struct net_device * netdev
Definition: gdbudp.c:52
uint8_t ll_dest[MAX_LL_ADDR_LEN]
Link-layer destination address.
Definition: neighbour.h:51
static void neighbour_discovered(struct neighbour *neighbour, const void *ll_dest)
Complete neighbour discovery.
Definition: neighbour.c:263
A neighbour cache entry.
Definition: neighbour.h:38
A network-layer protocol.
Definition: netdevice.h:65

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 466 of file neighbour.c.

468  {
469  struct neighbour *neighbour;
470 
471  /* Find or create neighbour cache entry */
473  if ( ! neighbour ) {
475  if ( ! neighbour )
476  return -ENOMEM;
477  }
478 
479  /* Set destination address */
481 
482  return 0;
483 }
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:136
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:101
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:49
#define ENOMEM
Not enough space.
Definition: errno.h:535
static struct net_device * netdev
Definition: gdbudp.c:52
uint8_t ll_dest[MAX_LL_ADDR_LEN]
Link-layer destination address.
Definition: neighbour.h:51
static void neighbour_discovered(struct neighbour *neighbour, const void *ll_dest)
Complete neighbour discovery.
Definition: neighbour.c:263
A neighbour cache entry.
Definition: neighbour.h:38
A network-layer protocol.
Definition: netdevice.h:65

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 67 of file neighbour.c.

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