The neighbour table establishes bindings between protocol addresses and link layer addresses for hosts sharing the same physical link.
More...
|
int | rtnl_neigh_alloc_cache (struct nl_sock *sock, struct nl_cache **result) |
| Build a neighbour cache including all neighbours currently configured in the kernel. More...
|
|
int | rtnl_neigh_alloc_cache_flags (struct nl_sock *sock, struct nl_cache **result, unsigned int flags) |
| Build a neighbour cache including all neighbours currently configured in the kernel. More...
|
|
struct 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. More...
|
|
struct rtnl_neigh * | rtnl_neigh_get_by_vlan (struct nl_cache *cache, int ifindex, struct nl_addr *lladdr, int vlan) |
| Look up a neighbour by interface index, link layer address and vlan id. More...
|
|
|
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) |
|
struct nl_addr * | rtnl_neigh_get_lladdr (struct rtnl_neigh *neigh) |
|
int | rtnl_neigh_set_dst (struct rtnl_neigh *neigh, struct nl_addr *addr) |
|
struct nl_addr * | rtnl_neigh_get_dst (struct rtnl_neigh *neigh) |
|
void | rtnl_neigh_set_family (struct rtnl_neigh *neigh, int family) |
|
int | rtnl_neigh_get_family (struct rtnl_neigh *neigh) |
|
void | rtnl_neigh_set_type (struct rtnl_neigh *neigh, int type) |
|
int | rtnl_neigh_get_type (struct rtnl_neigh *neigh) |
|
void | rtnl_neigh_set_vlan (struct rtnl_neigh *neigh, int vlan) |
|
int | rtnl_neigh_get_vlan (struct rtnl_neigh *neigh) |
|
void | rtnl_neigh_set_master (struct rtnl_neigh *neigh, int ifindex) |
|
int | rtnl_neigh_get_master (struct rtnl_neigh *neigh) |
|
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_USE
NTF_PROXY
NTF_ROUTER
NTF_SELF
- 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
rtnl_neigh_put(neigh);
int rtnl_neigh_alloc_cache(struct nl_sock *sock, struct nl_cache **result)
Build a neighbour cache including all neighbours currently configured in the kernel.
struct 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.
- 2) Adding new neighbours
struct rtnl_neigh *neigh = rtnl_neigh_alloc();
rtnl_neigh_set_ifindex(neigh, ifindex);
rtnl_neigh_set_dst(neigh, dst_addr);
rtnl_neigh_set_state(neigh, rtnl_neigh_str2state("permanent"));
rtnl_neigh_put(neigh);
int rtnl_neigh_add(struct nl_sock *sk, struct rtnl_neigh *tmpl, int flags)
Add a new neighbour.
- 3) Deleting an existing neighbour
struct rtnl_neigh *neigh = rtnl_neigh_alloc();
rtnl_neigh_set_ifindex(neigh, ifindex);
rtnl_neigh_set_dst(neigh, dst_addr);
rtnl_neigh_put(neigh);
int rtnl_neigh_delete(struct nl_sock *sk, struct rtnl_neigh *neigh, int flags)
Delete a neighbour.
- 4) Changing neighbour attributes
struct rtnl_neigh *neigh = rtnl_neigh_alloc();
rtnl_neigh_set_ifindex(neigh, ifindex);
rtnl_neigh_set_dst(neigh, dst_addr);
rtnl_neigh_set_lladdr(neigh, lladdr);
rtnl_neigh_set_state(neigh, state);
rtnl_neigh_put(neigh);
◆ rtnl_neigh_parse()
int rtnl_neigh_parse |
( |
struct nlmsghdr * |
n, |
|
|
struct rtnl_neigh ** |
result |
|
) |
| |
◆ rtnl_neigh_alloc()
struct rtnl_neigh * rtnl_neigh_alloc |
( |
void |
| ) |
|
◆ rtnl_neigh_put()
void rtnl_neigh_put |
( |
struct rtnl_neigh * |
neigh | ) |
|
◆ rtnl_neigh_alloc_cache()
int rtnl_neigh_alloc_cache |
( |
struct nl_sock * |
sock, |
|
|
struct nl_cache ** |
result |
|
) |
| |
Build a neighbour cache including all neighbours currently configured in the kernel.
- Parameters
-
sock | Netlink socket. |
result | Pointer to store resulting cache. |
Allocates a new neighbour cache, initializes it properly and updates it to include all neighbours currently configured in the kernel.
- Returns
- 0 on success or a negative error code.
Definition at line 590 of file neigh.c.
References nl_cache_alloc_and_fill().
◆ rtnl_neigh_alloc_cache_flags()
int rtnl_neigh_alloc_cache_flags |
( |
struct nl_sock * |
sock, |
|
|
struct nl_cache ** |
result, |
|
|
unsigned int |
flags |
|
) |
| |
Build a neighbour cache including all neighbours currently configured in the kernel.
- Parameters
-
sock | Netlink socket. |
result | Pointer to store resulting cache. |
flags | Flags to apply to cache before filling |
Allocates a new neighbour cache, initializes it properly and updates it to include all neighbours currently configured in the kernel.
- Returns
- 0 on success or a negative error code.
Definition at line 606 of file neigh.c.
References nl_cache_alloc(), nl_cache_free(), nl_cache_refill(), and nl_cache_set_flags().
◆ rtnl_neigh_get()
struct 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.
- Parameters
-
cache | neighbour cache |
ifindex | interface index the neighbour is on |
dst | destination address of the neighbour |
- Returns
- neighbour handle or NULL if no match was found.
Definition at line 635 of file neigh.c.
References nl_addr_cmp(), and nl_object_get().
◆ rtnl_neigh_get_by_vlan()
struct rtnl_neigh * rtnl_neigh_get_by_vlan |
( |
struct nl_cache * |
cache, |
|
|
int |
ifindex, |
|
|
struct nl_addr * |
lladdr, |
|
|
int |
vlan |
|
) |
| |
Look up a neighbour by interface index, link layer address and vlan id.
- Parameters
-
cache | neighbour cache |
ifindex | interface index the neighbour is on |
lladdr | link layer address of the neighbour |
vlan | vlan id of the neighbour |
- Returns
- neighbour handle or NULL if no match was found.
Definition at line 661 of file neigh.c.
References nl_addr_cmp(), and nl_object_get().
◆ rtnl_neigh_build_add_request()
int rtnl_neigh_build_add_request |
( |
struct rtnl_neigh * |
tmpl, |
|
|
int |
flags, |
|
|
struct nl_msg ** |
result |
|
) |
| |
Build netlink request message to add a new neighbour.
- Parameters
-
tmpl | template with data of new neighbour |
flags | additional netlink message flags |
result | Pointer to store resulting message. |
Builds a new netlink message requesting a addition of a new neighbour. The netlink message header isn't fully equipped with all relevant fields and must thus be sent out via nl_send_auto_complete() or supplemented as needed. tmpl must contain the attributes of the new neighbour set via rtnl_neigh_set_*
functions.
The following attributes must be set in the template:
- Interface index (rtnl_neigh_set_ifindex())
- State (rtnl_neigh_set_state())
- Destination address (rtnl_neigh_set_dst())
- Link layer address (rtnl_neigh_set_lladdr())
- Returns
- 0 on success or a negative error code.
Definition at line 752 of file neigh.c.
Referenced by rtnl_neigh_add().
◆ rtnl_neigh_add()
int rtnl_neigh_add |
( |
struct nl_sock * |
sk, |
|
|
struct rtnl_neigh * |
tmpl, |
|
|
int |
flags |
|
) |
| |
Add a new neighbour.
- Parameters
-
sk | Netlink socket. |
tmpl | template with requested changes |
flags | additional netlink message flags |
Builds a netlink message by calling rtnl_neigh_build_add_request(), sends the request to the kernel and waits for the next ACK to be received and thus blocks until the request has been fullfilled.
The following attributes must be set in the template:
- Interface index (rtnl_neigh_set_ifindex())
- State (rtnl_neigh_set_state())
- Destination address (rtnl_neigh_set_dst())
- Link layer address (rtnl_neigh_set_lladdr())
- Returns
- 0 on success or a negative error if an error occured.
Definition at line 776 of file neigh.c.
References nl_send_auto_complete(), nlmsg_free(), and rtnl_neigh_build_add_request().
◆ rtnl_neigh_build_delete_request()
int rtnl_neigh_build_delete_request |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
flags, |
|
|
struct nl_msg ** |
result |
|
) |
| |
Build a netlink request message to delete a neighbour.
- Parameters
-
neigh | neighbour to delete |
flags | additional netlink message flags |
result | Pointer to store resulting message. |
Builds a new netlink message requesting a deletion of a neighbour. The netlink message header isn't fully equipped with all relevant fields and must thus be sent out via nl_send_auto_complete() or supplemented as needed. neigh must point to an existing neighbour.
- Returns
- 0 on success or a negative error code.
Definition at line 813 of file neigh.c.
Referenced by rtnl_neigh_delete().
◆ rtnl_neigh_delete()
int rtnl_neigh_delete |
( |
struct nl_sock * |
sk, |
|
|
struct rtnl_neigh * |
neigh, |
|
|
int |
flags |
|
) |
| |
◆ rtnl_neigh_state2str()
char * rtnl_neigh_state2str |
( |
int |
state, |
|
|
char * |
buf, |
|
|
size_t |
len |
|
) |
| |
◆ rtnl_neigh_str2state()
int rtnl_neigh_str2state |
( |
const char * |
name | ) |
|
◆ rtnl_neigh_flags2str()
char * rtnl_neigh_flags2str |
( |
int |
flags, |
|
|
char * |
buf, |
|
|
size_t |
len |
|
) |
| |
◆ rtnl_neigh_str2flag()
int rtnl_neigh_str2flag |
( |
const char * |
name | ) |
|
◆ rtnl_neigh_set_state()
void rtnl_neigh_set_state |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
state |
|
) |
| |
◆ rtnl_neigh_get_state()
int rtnl_neigh_get_state |
( |
struct rtnl_neigh * |
neigh | ) |
|
◆ rtnl_neigh_unset_state()
void rtnl_neigh_unset_state |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
state |
|
) |
| |
◆ rtnl_neigh_set_flags()
void rtnl_neigh_set_flags |
( |
struct rtnl_neigh * |
neigh, |
|
|
unsigned int |
flags |
|
) |
| |
◆ rtnl_neigh_get_flags()
unsigned int rtnl_neigh_get_flags |
( |
struct rtnl_neigh * |
neigh | ) |
|
◆ rtnl_neigh_unset_flags()
void rtnl_neigh_unset_flags |
( |
struct rtnl_neigh * |
neigh, |
|
|
unsigned int |
flags |
|
) |
| |
◆ rtnl_neigh_set_ifindex()
void rtnl_neigh_set_ifindex |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
ifindex |
|
) |
| |
◆ rtnl_neigh_get_ifindex()
int rtnl_neigh_get_ifindex |
( |
struct rtnl_neigh * |
neigh | ) |
|
◆ rtnl_neigh_set_lladdr()
void rtnl_neigh_set_lladdr |
( |
struct rtnl_neigh * |
neigh, |
|
|
struct nl_addr * |
addr |
|
) |
| |
◆ rtnl_neigh_get_lladdr()
struct nl_addr * rtnl_neigh_get_lladdr |
( |
struct rtnl_neigh * |
neigh | ) |
|
◆ rtnl_neigh_set_dst()
int rtnl_neigh_set_dst |
( |
struct rtnl_neigh * |
neigh, |
|
|
struct nl_addr * |
addr |
|
) |
| |
◆ rtnl_neigh_get_dst()
struct nl_addr * rtnl_neigh_get_dst |
( |
struct rtnl_neigh * |
neigh | ) |
|
◆ rtnl_neigh_set_family()
void rtnl_neigh_set_family |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
family |
|
) |
| |
◆ rtnl_neigh_get_family()
int rtnl_neigh_get_family |
( |
struct rtnl_neigh * |
neigh | ) |
|
◆ rtnl_neigh_set_type()
void rtnl_neigh_set_type |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
type |
|
) |
| |
◆ rtnl_neigh_get_type()
int rtnl_neigh_get_type |
( |
struct rtnl_neigh * |
neigh | ) |
|
◆ rtnl_neigh_set_vlan()
void rtnl_neigh_set_vlan |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
vlan |
|
) |
| |
◆ rtnl_neigh_get_vlan()
int rtnl_neigh_get_vlan |
( |
struct rtnl_neigh * |
neigh | ) |
|
◆ rtnl_neigh_set_master()
void rtnl_neigh_set_master |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
ifindex |
|
) |
| |
◆ rtnl_neigh_get_master()
int rtnl_neigh_get_master |
( |
struct rtnl_neigh * |
neigh | ) |
|