iPXE
neighbour.h
Go to the documentation of this file.
00001 #ifndef _IPXE_NEIGHBOUR_H
00002 #define _IPXE_NEIGHBOUR_H
00003 
00004 /** @file
00005  *
00006  * Neighbour discovery
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 #include <ipxe/refcnt.h>
00014 #include <ipxe/list.h>
00015 #include <ipxe/netdevice.h>
00016 #include <ipxe/retry.h>
00017 
00018 /** A neighbour discovery protocol */
00019 struct neighbour_discovery {
00020         /** Name */
00021         const char *name;
00022         /**
00023          * Transmit neighbour discovery request
00024          *
00025          * @v netdev            Network device
00026          * @v net_protocol      Network-layer protocol
00027          * @v net_dest          Destination network-layer address
00028          * @v net_source        Source network-layer address
00029          * @ret rc              Return status code
00030          */
00031         int ( * tx_request ) ( struct net_device *netdev,
00032                                struct net_protocol *net_protocol,
00033                                const void *net_dest, const void *net_source );
00034 };
00035 
00036 /** A neighbour cache entry */
00037 struct neighbour {
00038         /** Reference count */
00039         struct refcnt refcnt;
00040         /** List of neighbour cache entries */
00041         struct list_head list;
00042 
00043         /** Network device */
00044         struct net_device *netdev;
00045         /** Network-layer protocol */
00046         struct net_protocol *net_protocol;
00047         /** Network-layer destination address */
00048         uint8_t net_dest[MAX_NET_ADDR_LEN];
00049         /** Link-layer destination address */
00050         uint8_t ll_dest[MAX_LL_ADDR_LEN];
00051 
00052         /** Neighbour discovery protocol (if any) */
00053         struct neighbour_discovery *discovery;
00054         /** Network-layer source address (if any) */
00055         uint8_t net_source[MAX_NET_ADDR_LEN];
00056         /** Retransmission timer */
00057         struct retry_timer timer;
00058 
00059         /** Pending I/O buffers */
00060         struct list_head tx_queue;
00061 };
00062 
00063 /**
00064  * Test if neighbour cache entry has a valid link-layer address
00065  *
00066  * @v neighbour         Neighbour cache entry
00067  * @ret has_ll_dest     Neighbour cache entry has a valid link-layer address
00068  */
00069 static inline __attribute__ (( always_inline )) int
00070 neighbour_has_ll_dest ( struct neighbour *neighbour ) {
00071         return ( ! timer_running ( &neighbour->timer ) );
00072 }
00073 
00074 extern struct list_head neighbours;
00075 
00076 extern int neighbour_tx ( struct io_buffer *iobuf, struct net_device *netdev,
00077                           struct net_protocol *net_protocol,
00078                           const void *net_dest,
00079                           struct neighbour_discovery *discovery,
00080                           const void *net_source, const void *ll_source );
00081 extern int neighbour_update ( struct net_device *netdev,
00082                               struct net_protocol *net_protocol,
00083                               const void *net_dest, const void *ll_dest );
00084 extern int neighbour_define ( struct net_device *netdev,
00085                               struct net_protocol *net_protocol,
00086                               const void *net_dest, const void *ll_dest );
00087 
00088 #endif /* _IPXE_NEIGHBOUR_H */