iPXE
Macros | Functions | Variables
neighbour.c File Reference

Neighbour discovery. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ipxe/iobuf.h>
#include <ipxe/retry.h>
#include <ipxe/timer.h>
#include <ipxe/malloc.h>
#include <ipxe/neighbour.h>
#include <config/fault.h>

Go to the source code of this file.

Macros

#define NEIGHBOUR_MIN_TIMEOUT   ( TICKS_PER_SEC / 8 )
 Neighbour discovery minimum timeout. More...
 
#define NEIGHBOUR_MAX_TIMEOUT   ( TICKS_PER_SEC * 3 )
 Neighbour discovery maximum timeout. More...
 
#define NEIGHBOUR_DELAY_MAX_BURST   2
 Neighbour discovery maximum burst count for delayed transmissions. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void neighbour_expired (struct retry_timer *timer, int fail)
 Handle neighbour timer expiry. More...
 
static void neighbour_free (struct refcnt *refcnt)
 Free neighbour cache entry. More...
 
static struct neighbourneighbour_create (struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest)
 Create neighbour cache entry. More...
 
static struct neighbourneighbour_find (struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest)
 Find neighbour cache entry. More...
 
static void neighbour_discover (struct neighbour *neighbour, struct neighbour_discovery *discovery, const void *net_source)
 Start neighbour discovery. More...
 
static void neighbour_tx_queue (struct neighbour *neighbour)
 Transmit deferred packets. More...
 
static void neighbour_discovered (struct neighbour *neighbour, const void *ll_dest)
 Complete neighbour discovery. More...
 
static void neighbour_destroy (struct neighbour *neighbour, int rc)
 Destroy neighbour cache entry. 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)
 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...
 
static void neighbour_flush (struct net_device *netdev, void *priv __unused)
 Update neighbour cache on network device state change or removal. More...
 
static unsigned int neighbour_discard (void)
 Discard some cached neighbour entries. More...
 
struct cache_discarder neighbour_discarder __cache_discarder (CACHE_EXPENSIVE)
 Neighbour cache discarder. More...
 

Variables

struct list_head neighbours = LIST_HEAD_INIT ( neighbours )
 The neighbour cache. More...
 
struct net_driver neighbour_net_driver __net_driver
 Neighbour driver (for net device notifications) More...
 

Detailed Description

Neighbour discovery.

This file implements the abstract functions of neighbour discovery, independent of the underlying network protocol (e.g. ARP or NDP).

Definition in file neighbour.c.

Macro Definition Documentation

◆ NEIGHBOUR_MIN_TIMEOUT

#define NEIGHBOUR_MIN_TIMEOUT   ( TICKS_PER_SEC / 8 )

Neighbour discovery minimum timeout.

Definition at line 47 of file neighbour.c.

◆ NEIGHBOUR_MAX_TIMEOUT

#define NEIGHBOUR_MAX_TIMEOUT   ( TICKS_PER_SEC * 3 )

Neighbour discovery maximum timeout.

Definition at line 50 of file neighbour.c.

◆ NEIGHBOUR_DELAY_MAX_BURST

#define NEIGHBOUR_DELAY_MAX_BURST   2

Neighbour discovery maximum burst count for delayed transmissions.

When using delay injection, timer quantisation can cause a large number of delayed packets to be scheduled at the same time. This can quickly exhaust available transmit descriptors, leading to packets that are dropped completely (not just delayed).

Limit the number of delayed packets that we will attempt to transmit at once, to allow time for transmit completions to occur.

Definition at line 62 of file neighbour.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ neighbour_expired()

static void neighbour_expired ( struct retry_timer timer,
int  fail 
)
static

Handle neighbour timer expiry.

Parameters
timerRetry timer
failFailure indicator

Definition at line 316 of file neighbour.c.

316  {
317  struct neighbour *neighbour =
318  container_of ( timer, struct neighbour, timer );
319  struct net_device *netdev = neighbour->netdev;
321  struct neighbour_discovery *discovery =
323  const void *net_dest = neighbour->net_dest;
324  const void *net_source = neighbour->net_source;
325  int rc;
326 
327  /* If the timer is being (ab)used for delay injection, then
328  * transmit the deferred packet queue.
329  */
330  if ( NEIGHBOUR_DELAY_MS && ( ! neighbour->discovery ) ) {
332  return;
333  }
334 
335  /* If we have failed, destroy the cache entry */
336  if ( fail ) {
338  return;
339  }
340 
341  /* Restart the timer */
343 
344  /* Transmit neighbour request */
345  if ( ( rc = discovery->tx_request ( netdev, net_protocol, net_dest,
346  net_source ) ) != 0 ) {
347  DBGC ( neighbour, "NEIGHBOUR %s %s %s could not transmit %s "
348  "request: %s\n", netdev->name, net_protocol->name,
351  /* Retransmit when timer expires */
352  return;
353  }
354 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Protocol name.
Definition: netdevice.h:66
const char * name
Name.
Definition: neighbour.h:21
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:48
struct net_protocol * net_protocol
Network-layer protocol.
Definition: neighbour.h:46
#define DBGC(...)
Definition: compiler.h:505
struct retry_timer timer
Retransmission timer.
Definition: neighbour.h:57
A neighbour discovery protocol.
Definition: neighbour.h:19
A timer.
Definition: timer.h:28
int(* tx_request)(struct net_device *netdev, struct net_protocol *net_protocol, const void *net_dest, const void *net_source)
Transmit neighbour discovery request.
Definition: neighbour.h:31
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct neighbour_discovery * discovery
Neighbour discovery protocol (if discovery is ongoing)
Definition: neighbour.h:53
const char *(* ntoa)(const void *net_addr)
Transcribe network-layer address.
Definition: netdevice.h:94
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define NEIGHBOUR_DELAY_MS
Definition: fault.h:18
A network device.
Definition: netdevice.h:352
A neighbour cache entry.
Definition: neighbour.h:37
void start_timer(struct retry_timer *timer)
Start timer.
Definition: retry.c:93
A network-layer protocol.
Definition: netdevice.h:64
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
struct net_device * netdev
Network device.
Definition: neighbour.h:44
static void neighbour_destroy(struct neighbour *neighbour, int rc)
Destroy neighbour cache entry.
Definition: neighbour.c:280
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
uint8_t net_source[MAX_NET_ADDR_LEN]
Network-layer source address (for discovery requests)
Definition: neighbour.h:55
static void neighbour_tx_queue(struct neighbour *neighbour)
Transmit deferred packets.
Definition: neighbour.c:184

References container_of, DBGC, neighbour::discovery, ETIMEDOUT, neighbour_discovery::name, net_protocol::name, net_device::name, NEIGHBOUR_DELAY_MS, neighbour_destroy(), neighbour_tx_queue(), neighbour::net_dest, neighbour::net_protocol, neighbour::net_source, neighbour::netdev, netdev, net_protocol::ntoa, rc, start_timer(), strerror(), neighbour::timer, and neighbour_discovery::tx_request.

Referenced by neighbour_create().

◆ neighbour_free()

static void neighbour_free ( struct refcnt refcnt)
static

Free neighbour cache entry.

Parameters
refcntReference count

Definition at line 74 of file neighbour.c.

74  {
75  struct neighbour *neighbour =
76  container_of ( refcnt, struct neighbour, refcnt );
77 
78  /* Sanity check */
80 
81  /* Drop reference to network device */
83 
84  /* Free neighbour */
85  free ( neighbour );
86 }
A reference counter.
Definition: refcnt.h:26
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:575
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct list_head tx_queue
Pending I/O buffers.
Definition: neighbour.h:60
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A neighbour cache entry.
Definition: neighbour.h:37
struct net_device * netdev
Network device.
Definition: neighbour.h:44

References assert(), container_of, free, list_empty, neighbour::netdev, netdev_put(), and neighbour::tx_queue.

Referenced by neighbour_create().

◆ neighbour_create()

static struct neighbour* neighbour_create ( struct net_device netdev,
struct net_protocol net_protocol,
const void *  net_dest 
)
static

Create neighbour cache entry.

Parameters
netdevNetwork device
net_protocolNetwork-layer protocol
net_destDestination network-layer address
Return values
neighbourNeighbour cache entry, or NULL if allocation failed

Definition at line 96 of file neighbour.c.

98  {
99  struct neighbour *neighbour;
100 
101  /* Allocate and initialise entry */
102  neighbour = zalloc ( sizeof ( *neighbour ) );
103  if ( ! neighbour )
104  return NULL;
110  timer_init ( &neighbour->timer, neighbour_expired, &neighbour->refcnt );
111  set_timer_limits ( &neighbour->timer, NEIGHBOUR_MIN_TIMEOUT,
114 
115  /* Transfer ownership to cache */
117 
118  DBGC ( neighbour, "NEIGHBOUR %s %s %s created\n", netdev->name,
120  return neighbour;
121 }
const char * name
Protocol name.
Definition: netdevice.h:66
#define NEIGHBOUR_MIN_TIMEOUT
Neighbour discovery minimum timeout.
Definition: neighbour.c:47
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:48
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
struct net_protocol * net_protocol
Network-layer protocol.
Definition: neighbour.h:46
#define DBGC(...)
Definition: compiler.h:505
struct list_head neighbours
The neighbour cache.
Definition: neighbour.c:65
struct retry_timer timer
Retransmission timer.
Definition: neighbour.h:57
struct refcnt refcnt
Reference count.
Definition: neighbour.h:39
struct list_head list
List of neighbour cache entries.
Definition: neighbour.h:41
void * memcpy(void *dest, const void *src, size_t len) __nonnull
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
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:564
A neighbour cache entry.
Definition: neighbour.h:37
A network-layer protocol.
Definition: netdevice.h:64
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
#define NEIGHBOUR_MAX_TIMEOUT
Neighbour discovery maximum timeout.
Definition: neighbour.c:50
uint8_t net_addr_len
Network-layer address length.
Definition: netdevice.h:101
static void neighbour_expired(struct retry_timer *timer, int over)
Handle neighbour timer expiry.
Definition: neighbour.c:316
struct net_device * netdev
Network device.
Definition: neighbour.h:44
static void neighbour_free(struct refcnt *refcnt)
Free neighbour cache entry.
Definition: neighbour.c:74
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References DBGC, INIT_LIST_HEAD, neighbour::list, list_add, memcpy(), net_protocol::name, net_device::name, neighbour_expired(), neighbour_free(), NEIGHBOUR_MAX_TIMEOUT, NEIGHBOUR_MIN_TIMEOUT, neighbours, net_protocol::net_addr_len, neighbour::net_dest, neighbour::net_protocol, neighbour::netdev, netdev, netdev_get(), net_protocol::ntoa, NULL, ref_init, neighbour::refcnt, neighbour::timer, neighbour::tx_queue, and zalloc().

Referenced by neighbour_define(), and neighbour_tx().

◆ neighbour_find()

static struct neighbour* neighbour_find ( struct net_device netdev,
struct net_protocol net_protocol,
const void *  net_dest 
)
static

Find neighbour cache entry.

Parameters
netdevNetwork device
net_protocolNetwork-layer protocol
net_destDestination network-layer address
Return values
neighbourNeighbour cache entry, or NULL if not found

Definition at line 131 of file neighbour.c.

133  {
134  struct neighbour *neighbour;
135 
137  if ( ( neighbour->netdev == netdev ) &&
140  net_protocol->net_addr_len ) == 0 ) ) {
141 
142  /* Move to start of cache */
143  list_del ( &neighbour->list );
145 
146  return neighbour;
147  }
148  }
149  return NULL;
150 }
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:48
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
struct net_protocol * net_protocol
Network-layer protocol.
Definition: neighbour.h:46
struct list_head neighbours
The neighbour cache.
Definition: neighbour.c:65
struct list_head list
List of neighbour cache entries.
Definition: neighbour.h:41
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
A neighbour cache entry.
Definition: neighbour.h:37
A network-layer protocol.
Definition: netdevice.h:64
uint8_t net_addr_len
Network-layer address length.
Definition: netdevice.h:101
struct net_device * netdev
Network device.
Definition: neighbour.h:44
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References neighbour::list, list_add, list_del, list_for_each_entry, memcmp(), neighbours, net_protocol::net_addr_len, neighbour::net_dest, neighbour::net_protocol, neighbour::netdev, netdev, and NULL.

Referenced by neighbour_define(), neighbour_tx(), and neighbour_update().

◆ neighbour_discover()

static void neighbour_discover ( struct neighbour neighbour,
struct neighbour_discovery discovery,
const void *  net_source 
)
static

Start neighbour discovery.

Parameters
neighbourNeighbour cache entry
discoveryNeighbour discovery protocol
net_sourceSource network-layer address

Definition at line 159 of file neighbour.c.

161  {
162  struct net_device *netdev = neighbour->netdev;
164 
165  /* Record discovery protocol and source network-layer address */
166  neighbour->discovery = discovery;
167  memcpy ( neighbour->net_source, net_source,
169 
170  /* Start timer to trigger neighbour discovery */
172 
173  DBGC ( neighbour, "NEIGHBOUR %s %s %s discovering via %s\n",
177 }
const char * name
Protocol name.
Definition: netdevice.h:66
const char * name
Name.
Definition: neighbour.h:21
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:48
struct net_protocol * net_protocol
Network-layer protocol.
Definition: neighbour.h:46
#define DBGC(...)
Definition: compiler.h:505
struct retry_timer timer
Retransmission timer.
Definition: neighbour.h:57
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct neighbour_discovery * discovery
Neighbour discovery protocol (if discovery is ongoing)
Definition: neighbour.h:53
const char *(* ntoa)(const void *net_addr)
Transcribe network-layer address.
Definition: netdevice.h:94
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:352
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
uint8_t net_addr_len
Network-layer address length.
Definition: netdevice.h:101
struct net_device * netdev
Network device.
Definition: neighbour.h:44
uint8_t net_source[MAX_NET_ADDR_LEN]
Network-layer source address (for discovery requests)
Definition: neighbour.h:55

References DBGC, neighbour::discovery, memcpy(), neighbour_discovery::name, net_protocol::name, net_device::name, net_protocol::net_addr_len, neighbour::net_dest, neighbour::net_protocol, neighbour::net_source, neighbour::netdev, netdev, net_protocol::ntoa, start_timer_nodelay(), and neighbour::timer.

Referenced by neighbour_tx().

◆ neighbour_tx_queue()

static void neighbour_tx_queue ( struct neighbour neighbour)
static

Transmit deferred packets.

Parameters
neighbourNeighbour cache entry

Definition at line 184 of file neighbour.c.

184  {
185  struct net_device *netdev = neighbour->netdev;
187  const void *ll_dest = neighbour->ll_dest;
188  struct neighbour_delay *delay;
189  struct io_buffer *iobuf;
190  unsigned long elapsed;
191  unsigned long threshold;
192  unsigned int count = 0;
193  int rc;
194 
195  /* Stop retransmission timer */
196  stop_timer ( &neighbour->timer );
197 
198  /* Transmit any packets in queue. Take out a temporary
199  * reference on the entry to prevent it from going out of
200  * scope during the call to net_tx().
201  */
202  ref_get ( &neighbour->refcnt );
203  while ( ( iobuf = list_first_entry ( &neighbour->tx_queue,
204  struct io_buffer, list )) != NULL){
205 
206  /* Handle delay injection */
207  if ( NEIGHBOUR_DELAY_MS ) {
208 
209  /* Determine elapsed time since transmission attempt */
210  delay = iobuf->data;
211  elapsed = ( currticks() - delay->start );
212  threshold = ( NEIGHBOUR_DELAY_MS * TICKS_PER_MS );
213 
214  /* Defer transmission if not yet scheduled */
215  if ( elapsed < threshold ) {
217  ( threshold - elapsed ) );
218  break;
219  }
220 
221  /* Defer transmission if maximum burst count reached */
222  if ( ++count >= NEIGHBOUR_DELAY_MAX_BURST ) {
224  break;
225  }
226 
227  /* Strip pseudo-header */
228  iob_pull ( iobuf, sizeof ( *delay ) );
229  }
230 
231  /* Transmit deferred packet */
232  DBGC2 ( neighbour, "NEIGHBOUR %s %s %s transmitting deferred "
233  "packet\n", netdev->name, net_protocol->name,
235  list_del ( &iobuf->list );
236  if ( ( rc = net_tx ( iobuf, netdev, net_protocol, ll_dest,
237  netdev->ll_addr ) ) != 0 ) {
238  DBGC ( neighbour, "NEIGHBOUR %s %s %s could not "
239  "transmit deferred packet: %s\n",
242  strerror ( rc ) );
243  /* Ignore error and continue */
244  }
245  }
246  ref_put ( &neighbour->refcnt );
247 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:106
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Protocol name.
Definition: netdevice.h:66
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:48
struct net_protocol * net_protocol
Network-layer protocol.
Definition: neighbour.h:46
#define DBGC(...)
Definition: compiler.h:505
struct retry_timer timer
Retransmission timer.
Definition: neighbour.h:57
#define NEIGHBOUR_DELAY_MAX_BURST
Neighbour discovery maximum burst count for delayed transmissions.
Definition: neighbour.c:62
struct refcnt refcnt
Reference count.
Definition: neighbour.h:39
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
const char *(* ntoa)(const void *net_addr)
Transcribe network-layer address.
Definition: netdevice.h:94
static struct net_device * netdev
Definition: gdbudp.c:52
static unsigned int count
Number of entries.
Definition: dwmac.h:225
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
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
#define NEIGHBOUR_DELAY_MS
Definition: fault.h:18
A network device.
Definition: netdevice.h:352
A neighbour cache entry.
Definition: neighbour.h:37
A network-layer protocol.
Definition: netdevice.h:64
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition: retry.c:64
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
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
void * data
Start of data.
Definition: iobuf.h:52
struct net_device * netdev
Network device.
Definition: neighbour.h:44
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
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define TICKS_PER_MS
Number of ticks per millisecond.
Definition: timer.h:25
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
A persistent I/O buffer.
Definition: iobuf.h:37

References count, currticks(), io_buffer::data, DBGC, DBGC2, delay, iob_pull, io_buffer::list, list_del, list_first_entry, net_device::ll_addr, neighbour::ll_dest, net_protocol::name, net_device::name, NEIGHBOUR_DELAY_MAX_BURST, NEIGHBOUR_DELAY_MS, neighbour::net_dest, neighbour::net_protocol, net_tx(), neighbour::netdev, netdev, net_protocol::ntoa, NULL, rc, ref_get, ref_put, neighbour::refcnt, start_timer_fixed(), start_timer_nodelay(), stop_timer(), strerror(), TICKS_PER_MS, neighbour::timer, and neighbour::tx_queue.

Referenced by neighbour_discovered(), neighbour_expired(), and neighbour_tx().

◆ neighbour_discovered()

static void neighbour_discovered ( struct neighbour neighbour,
const void *  ll_dest 
)
static

Complete neighbour discovery.

Parameters
neighbourNeighbour cache entry
ll_destDestination link-layer address

Definition at line 255 of file neighbour.c.

256  {
257  struct net_device *netdev = neighbour->netdev;
260 
261  /* Fill in link-layer address */
263  DBGC ( neighbour, "NEIGHBOUR %s %s %s is %s %s\n", netdev->name,
266 
267  /* Mark discovery as complete */
269 
270  /* Transmit any deferred packets */
272 }
const char * name
Protocol name.
Definition: netdevice.h:66
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:48
struct net_protocol * net_protocol
Network-layer protocol.
Definition: neighbour.h:46
#define DBGC(...)
Definition: compiler.h:505
A link-layer protocol.
Definition: netdevice.h:114
const char * name
Protocol name.
Definition: netdevice.h:116
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct neighbour_discovery * discovery
Neighbour discovery protocol (if discovery is ongoing)
Definition: neighbour.h:53
const char *(* ntoa)(const void *net_addr)
Transcribe network-layer address.
Definition: netdevice.h:94
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
A network device.
Definition: netdevice.h:352
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 net_device * netdev
Network device.
Definition: neighbour.h:44
const char *(* ntoa)(const void *ll_addr)
Transcribe link-layer address.
Definition: netdevice.h:163
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static void neighbour_tx_queue(struct neighbour *neighbour)
Transmit deferred packets.
Definition: neighbour.c:184
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

References DBGC, neighbour::discovery, ll_protocol::ll_addr_len, neighbour::ll_dest, net_device::ll_protocol, memcpy(), net_protocol::name, ll_protocol::name, net_device::name, neighbour_tx_queue(), neighbour::net_dest, neighbour::net_protocol, neighbour::netdev, netdev, net_protocol::ntoa, ll_protocol::ntoa, and NULL.

Referenced by neighbour_define(), and neighbour_update().

◆ neighbour_destroy()

static void neighbour_destroy ( struct neighbour neighbour,
int  rc 
)
static

Destroy neighbour cache entry.

Parameters
neighbourNeighbour cache entry
rcReason for destruction

Definition at line 280 of file neighbour.c.

280  {
281  struct net_device *netdev = neighbour->netdev;
283  struct io_buffer *iobuf;
284 
285  /* Take ownership from cache */
286  list_del ( &neighbour->list );
287 
288  /* Stop timer */
289  stop_timer ( &neighbour->timer );
290 
291  /* Discard any outstanding I/O buffers */
292  while ( ( iobuf = list_first_entry ( &neighbour->tx_queue,
293  struct io_buffer, list )) != NULL){
294  DBGC2 ( neighbour, "NEIGHBOUR %s %s %s discarding deferred "
295  "packet: %s\n", netdev->name, net_protocol->name,
297  strerror ( rc ) );
298  list_del ( &iobuf->list );
299  netdev_tx_err ( neighbour->netdev, iobuf, rc );
300  }
301 
302  DBGC ( neighbour, "NEIGHBOUR %s %s %s destroyed: %s\n", netdev->name,
304  strerror ( rc ) );
305 
306  /* Drop remaining reference */
307  ref_put ( &neighbour->refcnt );
308 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Protocol name.
Definition: netdevice.h:66
uint8_t net_dest[MAX_NET_ADDR_LEN]
Network-layer destination address.
Definition: neighbour.h:48
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:440
struct net_protocol * net_protocol
Network-layer protocol.
Definition: neighbour.h:46
#define DBGC(...)
Definition: compiler.h:505
struct retry_timer timer
Retransmission timer.
Definition: neighbour.h:57
struct refcnt refcnt
Reference count.
Definition: neighbour.h:39
struct list_head list
List of neighbour cache entries.
Definition: neighbour.h:41
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
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
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A network device.
Definition: netdevice.h:352
A neighbour cache entry.
Definition: neighbour.h:37
A network-layer protocol.
Definition: netdevice.h:64
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
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
#define DBGC2(...)
Definition: compiler.h:522
struct net_device * netdev
Network device.
Definition: neighbour.h:44
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
A persistent I/O buffer.
Definition: iobuf.h:37

References DBGC, DBGC2, neighbour::list, io_buffer::list, list_del, list_first_entry, net_protocol::name, net_device::name, neighbour::net_dest, neighbour::net_protocol, neighbour::netdev, netdev, netdev_tx_err(), net_protocol::ntoa, NULL, rc, ref_put, neighbour::refcnt, stop_timer(), strerror(), neighbour::timer, and neighbour::tx_queue.

Referenced by neighbour_discard(), neighbour_expired(), and neighbour_flush().

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

◆ neighbour_flush()

static void neighbour_flush ( struct net_device netdev,
void *priv  __unused 
)
static

Update neighbour cache on network device state change or removal.

Parameters
netdevNetwork device
privPrivate data

Definition at line 478 of file neighbour.c.

478  {
479  struct neighbour *neighbour;
480  struct neighbour *tmp;
481 
482  /* Remove all neighbour cache entries when a network device is closed */
483  if ( ! netdev_is_open ( netdev ) ) {
486  }
487 }
struct list_head neighbours
The neighbour cache.
Definition: neighbour.c:65
struct list_head list
List of neighbour cache entries.
Definition: neighbour.h:41
unsigned long tmp
Definition: linux_pci.h:64
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:661
static struct net_device * netdev
Definition: gdbudp.c:52
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:458
#define ENODEV
No such device.
Definition: errno.h:509
A neighbour cache entry.
Definition: neighbour.h:37
static void neighbour_destroy(struct neighbour *neighbour, int rc)
Destroy neighbour cache entry.
Definition: neighbour.c:280

References ENODEV, neighbour::list, list_for_each_entry_safe, neighbour_destroy(), neighbours, netdev, netdev_is_open(), and tmp.

◆ neighbour_discard()

static unsigned int neighbour_discard ( void  )
static

Discard some cached neighbour entries.

Return values
discardedNumber of cached items discarded

Definition at line 501 of file neighbour.c.

501  {
502  struct neighbour *neighbour;
503 
504  /* Drop oldest cache entry, if any */
506  if ( neighbour ) {
508  return 1;
509  } else {
510  return 0;
511  }
512 }
struct list_head neighbours
The neighbour cache.
Definition: neighbour.c:65
#define list_last_entry(list, type, member)
Get the container of the last entry in a list.
Definition: list.h:346
struct list_head list
List of neighbour cache entries.
Definition: neighbour.h:41
A neighbour cache entry.
Definition: neighbour.h:37
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
static void neighbour_destroy(struct neighbour *neighbour, int rc)
Destroy neighbour cache entry.
Definition: neighbour.c:280

References ENOBUFS, neighbour::list, list_last_entry, neighbour_destroy(), and neighbours.

◆ __cache_discarder()

struct cache_discarder neighbour_discarder __cache_discarder ( CACHE_EXPENSIVE  )

Neighbour cache discarder.

Neighbour cache entries are deemed to have a high replacement cost, since flushing an active neighbour cache entry midway through a TCP transfer will cause substantial disruption.

Variable Documentation

◆ neighbours

struct list_head neighbours = LIST_HEAD_INIT ( neighbours )

The neighbour cache.

Definition at line 65 of file neighbour.c.

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

◆ __net_driver

struct net_driver neighbour_net_driver __net_driver
Initial value:
= {
.name = "Neighbour",
.notify = neighbour_flush,
.remove = neighbour_flush,
}
static void neighbour_flush(struct net_device *netdev, void *priv __unused)
Update neighbour cache on network device state change or removal.
Definition: neighbour.c:478

Neighbour driver (for net device notifications)

Definition at line 490 of file neighbour.c.