[neighbour] Generalise concept of neighbour discovery

Split the protocol-independent portions of arp.c into a separate file
neighbour.c, to allow for sharing of functionality between IPv4+ARP
and IPv6+NDP.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2013-09-01 16:13:58 +01:00
parent 6bf36f57a0
commit c6a04085d2
5 changed files with 579 additions and 357 deletions

View File

@@ -11,6 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/tables.h>
#include <ipxe/netdevice.h>
#include <ipxe/neighbour.h>
/** A network-layer protocol that relies upon ARP */
struct arp_net_protocol {
@@ -34,9 +35,26 @@ struct arp_net_protocol {
#define __arp_net_protocol __table_entry ( ARP_NET_PROTOCOLS, 01 )
extern struct net_protocol arp_protocol __net_protocol;
extern struct neighbour_discovery arp_discovery;
extern int arp_tx ( struct io_buffer *iobuf, struct net_device *netdev,
struct net_protocol *net_protocol, const void *net_dest,
const void *net_source, const void *ll_source );
/**
* Transmit packet, determining link-layer address via ARP
*
* @v iobuf I/O buffer
* @v netdev Network device
* @v net_protocol Network-layer protocol
* @v net_dest Destination network-layer address
* @v net_source Source network-layer address
* @v ll_source Source link-layer address
* @ret rc Return status code
*/
static inline int arp_tx ( struct io_buffer *iobuf, struct net_device *netdev,
struct net_protocol *net_protocol,
const void *net_dest, const void *net_source,
const void *ll_source ) {
return neighbour_tx ( iobuf, netdev, net_protocol, net_dest,
&arp_discovery, net_source, ll_source );
}
#endif /* _IPXE_ARP_H */

View File

@@ -214,6 +214,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define ERRFILE_nfs_open ( ERRFILE_NET | 0x00340000 )
#define ERRFILE_mount ( ERRFILE_NET | 0x00350000 )
#define ERRFILE_oncrpc_iob ( ERRFILE_NET | 0x00360000 )
#define ERRFILE_neighbour ( ERRFILE_NET | 0x00370000 )
#define ERRFILE_image ( ERRFILE_IMAGE | 0x00000000 )
#define ERRFILE_elf ( ERRFILE_IMAGE | 0x00010000 )

View File

@@ -0,0 +1,44 @@
#ifndef _IPXE_NEIGHBOUR_H
#define _IPXE_NEIGHBOUR_H
/** @file
*
* Neighbour discovery
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/netdevice.h>
/** A neighbour discovery protocol */
struct neighbour_discovery {
/** Name */
const char *name;
/**
* Transmit neighbour discovery request
*
* @v netdev Network device
* @v net_protocol Network-layer protocol
* @v net_dest Destination network-layer address
* @v net_source Source network-layer address
* @ret rc Return status code
*/
int ( * tx_request ) ( struct net_device *netdev,
struct net_protocol *net_protocol,
const void *net_dest, const void *net_source );
};
extern 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, const void *ll_source );
extern int neighbour_update ( struct net_device *netdev,
struct net_protocol *net_protocol,
const void *net_dest, const void *ll_dest );
extern int neighbour_define ( struct net_device *netdev,
struct net_protocol *net_protocol,
const void *net_dest, const void *ll_dest );
#endif /* _IPXE_NEIGHBOUR_H */