Logo Search packages:      
Sourcecode: libnl2 version File versions  Download package

Neighbours
[Routing Family]


Detailed Description

The neighbour table establishes bindings between protocol addresses and link layer addresses for hosts sharing the same physical link. This module allows you to access and manipulate the content of these tables.

Neighbour States
 NUD_INCOMPLETE
 NUD_REACHABLE
 NUD_STALE
 NUD_DELAY
 NUD_PROBE
 NUD_FAILED
 NUD_NOARP
 NUD_PERMANENT
Neighbour Flags
 NTF_PROXY
 NTF_ROUTER
Neighbour Identification
A neighbour is uniquely identified by the attributes listed below, whenever you refer to an existing neighbour all of the attributes must be set. Neighbours from caches automatically have all required attributes set.
  • interface index (rtnl_neigh_set_ifindex())
  • destination address (rtnl_neigh_set_dst())
Changeable Attributes
  • state (rtnl_neigh_set_state())
  • link layer address (rtnl_neigh_set_lladdr())
Required Caches for Dumping
In order to dump neighbour attributes you must provide the following caches via nl_cache_provide()
  • link cache holding all links
TODO
  • Document proxy settings
  • Document states and their influence
1) Retrieving information about configured neighbours
 // The first step is to retrieve a list of all available neighbour within
 // the kernel and put them into a cache.
 struct nl_cache *cache = rtnl_neigh_alloc_cache(sk);

 // Neighbours can then be looked up by the interface and destination
 // address:
 struct rtnl_neigh *neigh = rtnl_neigh_get(cache, ifindex, dst_addr);
 
 // After successful usage, the object must be given back to the cache
 rtnl_neigh_put(neigh);
2) Adding new neighbours
 // Allocate an empty neighbour handle to be filled out with the attributes
 // of the new neighbour.
 struct rtnl_neigh *neigh = rtnl_neigh_alloc();

 // Fill out the attributes of the new neighbour
 rtnl_neigh_set_ifindex(neigh, ifindex);
 rtnl_neigh_set_dst(neigh, dst_addr);
 rtnl_neigh_set_state(neigh, rtnl_neigh_str2state("permanent"));

 // Build the netlink message and send it to the kernel, the operation will
 // block until the operation has been completed. Alternatively the required
 // netlink message can be built using rtnl_neigh_build_add_request()
 // to be sent out using nl_send_auto_complete().
 rtnl_neigh_add(sk, neigh, NLM_F_CREATE);

 // Free the memory
 rtnl_neigh_put(neigh);
3) Deleting an existing neighbour
 // Allocate an empty neighbour object to be filled out with the attributes
 // matching the neighbour to be deleted. Alternatively a fully equipped
 // neighbour object out of a cache can be used instead.
 struct rtnl_neigh *neigh = rtnl_neigh_alloc();

 // Neighbours are uniquely identified by their interface index and
 // destination address, you may fill out other attributes but they
 // will have no influence.
 rtnl_neigh_set_ifindex(neigh, ifindex);
 rtnl_neigh_set_dst(neigh, dst_addr);

 // Build the netlink message and send it to the kernel, the operation will
 // block until the operation has been completed. Alternatively the required
 // netlink message can be built using rtnl_neigh_build_delete_request()
 // to be sent out using nl_send_auto_complete().
 rtnl_neigh_delete(sk, neigh, 0);

 // Free the memory
 rtnl_neigh_put(neigh);
4) Changing neighbour attributes
 // Allocate an empty neighbour object to be filled out with the attributes
 // matching the neighbour to be changed and the new parameters. Alternatively
 // a fully equipped modified neighbour object out of a cache can be used.
 struct rtnl_neigh *neigh = rtnl_neigh_alloc();

 // Identify the neighbour to be changed by its interface index and
 // destination address
 rtnl_neigh_set_ifindex(neigh, ifindex);
 rtnl_neigh_set_dst(neigh, dst_addr);

 // The link layer address may be modified, if so it is wise to change
 // its state to "permanent" in order to avoid having it overwritten.
 rtnl_neigh_set_lladdr(neigh, lladdr);

 // Secondly the state can be modified allowing normal neighbours to be
 // converted into permanent entries or to manually confirm a neighbour.
 rtnl_neigh_set_state(neigh, state);

 // Build the netlink message and send it to the kernel, the operation will
 // block until the operation has been completed. Alternatively the required
 // netlink message can be built using rtnl_neigh_build_change_request()
 // to be sent out using nl_send_auto_complete().
 rtnl_neigh_add(sk, neigh, NLM_F_REPLACE);

 // Free the memory
 rtnl_neigh_put(neigh);


Neighbour Flags Translations

static struct trans_tbl neigh_flags []
char * rtnl_neigh_flags2str (int flags, char *buf, size_t len)
int rtnl_neigh_str2flag (const char *name)

Neighbour States Translations

static struct trans_tbl neigh_states []
char * rtnl_neigh_state2str (int state, char *buf, size_t len)
int rtnl_neigh_str2state (const char *name)

Attributes

static int __assign_addr (struct rtnl_neigh *neigh, struct nl_addr **pos, struct nl_addr *new, int flag, int nocheck)
struct nl_addr * rtnl_neigh_get_dst (struct rtnl_neigh *neigh)
int rtnl_neigh_get_family (struct rtnl_neigh *neigh)
unsigned int rtnl_neigh_get_flags (struct rtnl_neigh *neigh)
int rtnl_neigh_get_ifindex (struct rtnl_neigh *neigh)
struct nl_addr * rtnl_neigh_get_lladdr (struct rtnl_neigh *neigh)
int rtnl_neigh_get_state (struct rtnl_neigh *neigh)
int rtnl_neigh_get_type (struct rtnl_neigh *neigh)
int rtnl_neigh_set_dst (struct rtnl_neigh *neigh, struct nl_addr *addr)
void rtnl_neigh_set_family (struct rtnl_neigh *neigh, int family)
void rtnl_neigh_set_flags (struct rtnl_neigh *neigh, unsigned int flags)
void rtnl_neigh_set_ifindex (struct rtnl_neigh *neigh, int ifindex)
void rtnl_neigh_set_lladdr (struct rtnl_neigh *neigh, struct nl_addr *addr)
void rtnl_neigh_set_state (struct rtnl_neigh *neigh, int state)
void rtnl_neigh_set_type (struct rtnl_neigh *neigh, int type)
void rtnl_neigh_unset_flags (struct rtnl_neigh *neigh, unsigned int flags)
void rtnl_neigh_unset_state (struct rtnl_neigh *neigh, int state)

Neighbour Addition

static int build_neigh_msg (struct rtnl_neigh *tmpl, int cmd, int flags, struct nl_msg **result)
int rtnl_neigh_add (struct nl_sock *sk, struct rtnl_neigh *tmpl, int flags)
int rtnl_neigh_build_add_request (struct rtnl_neigh *tmpl, int flags, struct nl_msg **result)

Neighbour Object Allocation/Freeage

struct rtnl_neigh * rtnl_neigh_alloc (void)
void rtnl_neigh_put (struct rtnl_neigh *neigh)

Neighbour Cache Managament

int rtnl_neigh_alloc_cache (struct nl_sock *sock, struct nl_cache **result)
struct rtnl_neigh * rtnl_neigh_get (struct nl_cache *cache, int ifindex, struct nl_addr *dst)

Neighbour Deletion

int rtnl_neigh_build_delete_request (struct rtnl_neigh *neigh, int flags, struct nl_msg **result)
int rtnl_neigh_delete (struct nl_sock *sk, struct rtnl_neigh *neigh, int flags)

Functions

static char * neigh_attrs2str (int attrs, char *buf, size_t len)
static int neigh_clone (struct nl_object *_dst, struct nl_object *_src)
static int neigh_compare (struct nl_object *_a, struct nl_object *_b, uint32_t attrs, int flags)
static void neigh_dump_details (struct nl_object *a, struct nl_dump_params *p)
static void neigh_dump_env (struct nl_object *obj, struct nl_dump_params *p)
static void neigh_dump_line (struct nl_object *a, struct nl_dump_params *p)
static void neigh_dump_stats (struct nl_object *a, struct nl_dump_params *p)
static void __exit neigh_exit (void)
static void neigh_free_data (struct nl_object *c)
static void __init neigh_init (void)
static int neigh_msg_parser (struct nl_cache_ops *ops, struct sockaddr_nl *who, struct nlmsghdr *n, struct nl_parser_param *pp)
static int neigh_request_update (struct nl_cache *c, struct nl_sock *h)

Variables

static struct trans_tbl neigh_attrs []
static struct nl_af_group neigh_groups []
static struct nl_object_ops neigh_obj_ops
static struct nla_policy neigh_policy [NDA_MAX+1]
static struct nl_cache_ops rtnl_neigh_ops


Generated by  Doxygen 1.6.0   Back to index