NUD_INCOMPLETE NUD_REACHABLE NUD_STALE NUD_DELAY NUD_PROBE NUD_FAILED NUD_NOARP NUD_PERMANENT
NTF_PROXY NTF_ROUTER
// 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(handle); // 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);
// 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(nl_handle, neigh, NLM_F_REPLACE); // Free the memory rtnl_neigh_put(neigh);
// 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(handle, neigh, 0); // Free the memory rtnl_neigh_put(neigh);
// 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_change(handle, neigh, 0); // Free the memory rtnl_neigh_put(neigh);
Neighbour Object Allocation/Freeage | |
rtnl_neigh * | rtnl_neigh_alloc (void) |
void | rtnl_neigh_put (struct rtnl_neigh *neigh) |
Neighbour Cache Managament | |
nl_cache * | rtnl_neigh_alloc_cache (struct nl_handle *handle) |
Build a neighbour cache including all neighbours currently configured in the kernel. | |
rtnl_neigh * | rtnl_neigh_get (struct nl_cache *cache, int ifindex, struct nl_addr *dst) |
Look up a neighbour by interface index and destination address. | |
Neighbour Addition | |
nl_msg * | rtnl_neigh_build_add_request (struct rtnl_neigh *tmpl, int flags) |
Build netlink request message to add a new neighbour. | |
int | rtnl_neigh_add (struct nl_handle *handle, struct rtnl_neigh *tmpl, int flags) |
Add a new neighbour. | |
Neighbour Deletion | |
nl_msg * | rtnl_neigh_build_delete_request (struct rtnl_neigh *neigh, int flags) |
Build a netlink request message to delete a neighbour. | |
int | rtnl_neigh_delete (struct nl_handle *handle, struct rtnl_neigh *neigh, int flags) |
Delete a neighbour. | |
Neighbour Modification | |
nl_msg * | rtnl_neigh_build_change_request (struct rtnl_neigh *neigh, int flags) |
Build a netlink request message to change neighbour attributes. | |
int | rtnl_neigh_change (struct nl_handle *handle, struct rtnl_neigh *neigh, int flags) |
Change neighbour attributes. | |
Neighbour States Translations | |
char * | rtnl_neigh_state2str (int state, char *buf, size_t len) |
int | rtnl_neigh_str2state (const char *name) |
Neighbour Flags Translations | |
char * | rtnl_neigh_flags2str (int flags, char *buf, size_t len) |
int | rtnl_neigh_str2flag (const char *name) |
Attributes | |
void | rtnl_neigh_set_state (struct rtnl_neigh *neigh, int state) |
int | rtnl_neigh_get_state (struct rtnl_neigh *neigh) |
void | rtnl_neigh_unset_state (struct rtnl_neigh *neigh, int state) |
void | rtnl_neigh_set_flags (struct rtnl_neigh *neigh, unsigned int flags) |
unsigned int | rtnl_neigh_get_flags (struct rtnl_neigh *neigh) |
void | rtnl_neigh_unset_flags (struct rtnl_neigh *neigh, unsigned int flags) |
void | rtnl_neigh_set_ifindex (struct rtnl_neigh *neigh, int ifindex) |
int | rtnl_neigh_get_ifindex (struct rtnl_neigh *neigh) |
void | rtnl_neigh_set_lladdr (struct rtnl_neigh *neigh, struct nl_addr *addr) |
nl_addr * | rtnl_neigh_get_lladdr (struct rtnl_neigh *neigh) |
int | rtnl_neigh_set_dst (struct rtnl_neigh *neigh, struct nl_addr *addr) |
nl_addr * | rtnl_neigh_get_dst (struct rtnl_neigh *neigh) |
void | rtnl_neigh_set_family (struct rtnl_neigh *neigh, int family) |
void | rtnl_neigh_set_type (struct rtnl_neigh *neigh, int type) |
int | rtnl_neigh_get_type (struct rtnl_neigh *neigh) |
struct nl_cache* rtnl_neigh_alloc_cache | ( | struct nl_handle * | handle | ) |
handle | netlink handle |
Definition at line 534 of file neigh.c.
References nl_cache_alloc(), nl_cache_free(), and nl_cache_refill().
00535 { 00536 struct nl_cache *cache; 00537 00538 cache = nl_cache_alloc(&rtnl_neigh_ops); 00539 if (cache == NULL) 00540 return NULL; 00541 00542 if (handle && nl_cache_refill(handle, cache) < 0) { 00543 nl_cache_free(cache); 00544 return NULL; 00545 } 00546 00547 NL_DBG(2, "Returning new cache %p\n", cache); 00548 00549 return cache; 00550 }
struct rtnl_neigh* rtnl_neigh_get | ( | struct nl_cache * | cache, | |
int | ifindex, | |||
struct nl_addr * | dst | |||
) |
cache | neighbour cache | |
ifindex | interface index the neighbour is on | |
dst | destination address of the neighbour |
Definition at line 559 of file neigh.c.
References nl_addr_cmp(), and nl_object_get().
00561 { 00562 struct rtnl_neigh *neigh; 00563 00564 nl_list_for_each_entry(neigh, &cache->c_items, ce_list) { 00565 if (neigh->n_ifindex == ifindex && 00566 !nl_addr_cmp(neigh->n_dst, dst)) { 00567 nl_object_get((struct nl_object *) neigh); 00568 return neigh; 00569 } 00570 } 00571 00572 return NULL; 00573 }
struct nl_msg* rtnl_neigh_build_add_request | ( | struct rtnl_neigh * | tmpl, | |
int | flags | |||
) |
tmpl | template with data of new neighbour | |
flags | additional netlink message flags |
rtnl_neigh_set_*
functions.The following attributes must be set in the template:
Definition at line 633 of file neigh.c.
References NLM_F_CREATE.
Referenced by rtnl_neigh_add().
00634 { 00635 return build_neigh_msg(tmpl, RTM_NEWNEIGH, NLM_F_CREATE | flags); 00636 }
int rtnl_neigh_add | ( | struct nl_handle * | handle, | |
struct rtnl_neigh * | tmpl, | |||
int | flags | |||
) |
handle | netlink handle | |
tmpl | template with requested changes | |
flags | additional netlink message flags |
The following attributes must be set in the template:
Definition at line 656 of file neigh.c.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_neigh_build_add_request().
00657 { 00658 int err; 00659 struct nl_msg *msg; 00660 00661 msg = rtnl_neigh_build_add_request(tmpl, flags); 00662 if (!msg) 00663 return nl_errno(ENOMEM); 00664 00665 err = nl_send_auto_complete(handle, msg); 00666 nlmsg_free(msg); 00667 if (err < 0) 00668 return err; 00669 00670 return nl_wait_for_ack(handle); 00671 }
struct nl_msg* rtnl_neigh_build_delete_request | ( | struct rtnl_neigh * | neigh, | |
int | flags | |||
) |
neigh | neighbour to delete | |
flags | additional netlink message flags |
Definition at line 693 of file neigh.c.
Referenced by rtnl_neigh_delete().
int rtnl_neigh_delete | ( | struct nl_handle * | handle, | |
struct rtnl_neigh * | neigh, | |||
int | flags | |||
) |
handle | netlink handle | |
neigh | neighbour to delete | |
flags | additional netlink message flags |
Definition at line 711 of file neigh.c.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_neigh_build_delete_request().
00713 { 00714 int err; 00715 struct nl_msg *msg; 00716 00717 msg = rtnl_neigh_build_delete_request(neigh, flags); 00718 if (!msg) 00719 return nl_errno(ENOMEM); 00720 00721 err = nl_send_auto_complete(handle, msg); 00722 nlmsg_free(msg); 00723 if (err < 0) 00724 return err; 00725 00726 return nl_wait_for_ack(handle); 00727 }
struct nl_msg* rtnl_neigh_build_change_request | ( | struct rtnl_neigh * | neigh, | |
int | flags | |||
) |
neigh | the neighbour to change | |
flags | additional netlink message flags |
Definition at line 750 of file neigh.c.
References NLM_F_REPLACE.
Referenced by rtnl_neigh_change().
00752 { 00753 return build_neigh_msg(neigh, RTM_NEWNEIGH, NLM_F_REPLACE | flags); 00754 }
int rtnl_neigh_change | ( | struct nl_handle * | handle, | |
struct rtnl_neigh * | neigh, | |||
int | flags | |||
) |
handle | netlink handle | |
neigh | neighbour to be changed | |
flags | additional netlink message flags |
Definition at line 770 of file neigh.c.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_neigh_build_change_request().
00772 { 00773 int err; 00774 struct nl_msg *msg; 00775 00776 msg = rtnl_neigh_build_change_request(neigh, flags); 00777 if (!msg) 00778 return nl_errno(ENOMEM); 00779 00780 err = nl_send_auto_complete(handle, msg); 00781 nlmsg_free(msg); 00782 if (err < 0) 00783 return err; 00784 00785 return nl_wait_for_ack(handle); 00786 }