1 #ifndef _IPXE_NEIGHBOUR_H
2 #define _IPXE_NEIGHBOUR_H
3 
4 /** @file
5  *
6  * Neighbour discovery
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 #include <ipxe/refcnt.h>
14 #include <ipxe/list.h>
15 #include <ipxe/netdevice.h>
16 #include <ipxe/retry.h>
17 
18 /** A neighbour discovery protocol */
19 struct neighbour_discovery {
20 	/** Name */
21 	const char *name;
22 	/**
23 	 * Transmit neighbour discovery request
24 	 *
25 	 * @v netdev		Network device
26 	 * @v net_protocol	Network-layer protocol
27 	 * @v net_dest		Destination network-layer address
28 	 * @v net_source	Source network-layer address
29 	 * @ret rc		Return status code
30 	 */
31 	int ( * tx_request ) ( struct net_device *netdev,
32 			       struct net_protocol *net_protocol,
33 			       const void *net_dest, const void *net_source );
34 };
35 
36 /** A neighbour cache entry */
37 struct neighbour {
38 	/** Reference count */
39 	struct refcnt refcnt;
40 	/** List of neighbour cache entries */
41 	struct list_head list;
42 
43 	/** Network device */
44 	struct net_device *netdev;
45 	/** Network-layer protocol */
46 	struct net_protocol *net_protocol;
47 	/** Network-layer destination address */
48 	uint8_t net_dest[MAX_NET_ADDR_LEN];
49 	/** Link-layer destination address */
50 	uint8_t ll_dest[MAX_LL_ADDR_LEN];
51 
52 	/** Neighbour discovery protocol (if any) */
53 	struct neighbour_discovery *discovery;
54 	/** Network-layer source address (if any) */
55 	uint8_t net_source[MAX_NET_ADDR_LEN];
56 	/** Retransmission timer */
57 	struct retry_timer timer;
58 
59 	/** Pending I/O buffers */
60 	struct list_head tx_queue;
61 };
62 
63 /**
64  * Test if neighbour cache entry has a valid link-layer address
65  *
66  * @v neighbour		Neighbour cache entry
67  * @ret has_ll_dest	Neighbour cache entry has a valid link-layer address
68  */
69 static inline __attribute__ (( always_inline )) int
neighbour_has_ll_dest(struct neighbour * neighbour)70 neighbour_has_ll_dest ( struct neighbour *neighbour ) {
71 	return ( ! timer_running ( &neighbour->timer ) );
72 }
73 
74 extern struct list_head neighbours;
75 
76 extern int neighbour_tx ( struct io_buffer *iobuf, struct net_device *netdev,
77 			  struct net_protocol *net_protocol,
78 			  const void *net_dest,
79 			  struct neighbour_discovery *discovery,
80 			  const void *net_source, const void *ll_source );
81 extern int neighbour_update ( struct net_device *netdev,
82 			      struct net_protocol *net_protocol,
83 			      const void *net_dest, const void *ll_dest );
84 extern int neighbour_define ( struct net_device *netdev,
85 			      struct net_protocol *net_protocol,
86 			      const void *net_dest, const void *ll_dest );
87 
88 #endif /* _IPXE_NEIGHBOUR_H */
89