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

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

370  {
371  struct neighbour *neighbour;
372  struct neighbour_delay *delay;
373  int rc;
374 
375  /* Find or create neighbour cache entry */
376  neighbour = neighbour_find ( netdev, net_protocol, net_dest );
377  if ( ! neighbour ) {
379  if ( ! neighbour )
380  return -ENOMEM;
381  neighbour_discover ( neighbour, discovery, net_source );
382  }
383 
384  /* If discovery is still in progress or if delay injection is
385  * in use, then queue for later transmission.
386  */
388 
389  /* Add to deferred packet queue */
390  DBGC2 ( neighbour, "NEIGHBOUR %s %s %s deferring packet\n",
392  net_protocol->ntoa ( net_dest ) );
393  list_add_tail ( &iobuf->list, &neighbour->tx_queue );
394 
395  /* Handle delay injection, if applicable */
396  if ( NEIGHBOUR_DELAY_MS ) {
397 
398  /* Record original transmission time */
399  delay = iob_push ( iobuf, sizeof ( *delay ) );
400  delay->start = currticks();
401 
402  /* Process deferred packet queue, if possible */
403  if ( ! neighbour->discovery )
405  }
406 
407  return 0;
408  }
409 
410  /* Otherwise, transmit immediately */
411  if ( ( rc = net_tx ( iobuf, netdev, net_protocol, neighbour->ll_dest,
412  netdev->ll_addr ) ) != 0 ) {
413  return rc;
414  }
415 
416  return 0;
417 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
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:131
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:96
#define iob_push(iobuf, len)
Definition: iobuf.h:88
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct neighbour_discovery * discovery
Neighbour discovery protocol (if discovery is ongoing)
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
#define NEIGHBOUR_DELAY_MS
Definition: fault.h:18
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:44
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
uint16_t delay
Forward delay.
Definition: stp.h:40
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
A neighbour transmission delay pseudo-header.
Definition: neighbour.h:64
unsigned long currticks(void)
Get current system time in ticks.
Definition: timer.c:42
static void neighbour_tx_queue(struct neighbour *neighbour)
Transmit deferred packets.
Definition: neighbour.c:184
static void neighbour_discover(struct neighbour *neighbour, struct neighbour_discovery *discovery, const void *net_source)
Start neighbour discovery.
Definition: neighbour.c:159

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_discover(), neighbour_find(), neighbour_tx_queue(), net_tx(), netdev, net_protocol::ntoa, 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 428 of file neighbour.c.

430  {
431  struct neighbour *neighbour;
432 
433  /* Find neighbour cache entry */
435  if ( ! neighbour )
436  return -ENOENT;
437 
438  /* Set destination address */
440 
441  return 0;
442 }
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:131
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:255
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 453 of file neighbour.c.

455  {
456  struct neighbour *neighbour;
457 
458  /* Find or create neighbour cache entry */
460  if ( ! neighbour ) {
462  if ( ! neighbour )
463  return -ENOMEM;
464  }
465 
466  /* Set destination address */
468 
469  return 0;
470 }
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:131
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:96
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:255
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 65 of file neighbour.c.

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