The neighbour table establishes bindings between protocol addresses and link layer addresses for hosts sharing the same physical link.
More...
|
| struct nl_cache * | rtnl_neigh_alloc_cache (struct nl_handle *handle) |
| | 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.
|
| |
|
| struct 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.
|
| |
|
| struct 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.
|
| |
|
| struct 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.
|
| |
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
- 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);
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.
struct nl_cache * rtnl_neigh_alloc_cache(struct nl_handle *handle)
Build a neighbour cache including all neighbours currently configured in the kernel.
- 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);
#define NLM_F_REPLACE
Replace existing matching config object with this request.
int rtnl_neigh_add(struct nl_handle *handle, 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_handle *handle, 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);
int rtnl_neigh_change(struct nl_handle *handle, struct rtnl_neigh *neigh, int flags)
Change neighbour attributes.
◆ rtnl_neigh_alloc()
| struct rtnl_neigh * rtnl_neigh_alloc |
( |
void |
| ) |
|
Definition at line 506 of file neigh.c.
507{
509}
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
◆ rtnl_neigh_put()
| void rtnl_neigh_put |
( |
struct rtnl_neigh * |
neigh | ) |
|
Definition at line 511 of file neigh.c.
512{
514}
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
◆ rtnl_neigh_alloc_cache()
| struct nl_cache * rtnl_neigh_alloc_cache |
( |
struct nl_handle * |
handle | ) |
|
- Parameters
-
Allocates a new neighbour cache, initializes it properly and updates it to include all neighbours currently configured in the kernel.
- Note
- The caller is responsible for destroying and freeing the cache after using it.
- Returns
- The new cache or NULL if an error occured.
Definition at line 534 of file neigh.c.
535{
536 struct nl_cache *cache;
537
539 if (cache == NULL)
540 return NULL;
541
544 return NULL;
545 }
546
547 NL_DBG(2, "Returning new cache %p\n", cache);
548
549 return cache;
550}
void nl_cache_free(struct nl_cache *cache)
Free a cache.
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.
int nl_cache_refill(struct nl_handle *handle, struct nl_cache *cache)
(Re)fill a cache with the contents in the kernel.
References nl_cache_alloc(), nl_cache_free(), and nl_cache_refill().
◆ rtnl_neigh_get()
| struct rtnl_neigh * rtnl_neigh_get |
( |
struct nl_cache * |
cache, |
|
|
int |
ifindex, |
|
|
struct nl_addr * |
dst |
|
) |
| |
- 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 559 of file neigh.c.
561{
562 struct rtnl_neigh *neigh;
563
564 nl_list_for_each_entry(neigh, &cache->c_items, ce_list) {
565 if (neigh->n_ifindex == ifindex &&
568 return neigh;
569 }
570 }
571
572 return NULL;
573}
int nl_addr_cmp(struct nl_addr *a, struct nl_addr *b)
Compares two abstract address objects.
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
References nl_addr_cmp(), and nl_object_get().
◆ rtnl_neigh_build_add_request()
| struct nl_msg * rtnl_neigh_build_add_request |
( |
struct rtnl_neigh * |
tmpl, |
|
|
int |
flags |
|
) |
| |
- Parameters
-
| tmpl | template with data of new neighbour |
| flags | additional netlink message flags |
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
- The netlink message
Definition at line 633 of file neigh.c.
634{
635 return build_neigh_msg(tmpl, RTM_NEWNEIGH,
NLM_F_CREATE | flags);
636}
#define NLM_F_CREATE
Create config object if it doesn't already exist.
References NLM_F_CREATE.
Referenced by rtnl_neigh_add().
◆ rtnl_neigh_add()
| int rtnl_neigh_add |
( |
struct nl_handle * |
handle, |
|
|
struct rtnl_neigh * |
tmpl, |
|
|
int |
flags |
|
) |
| |
- Parameters
-
| handle | netlink handle |
| 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 sucess or a negative error if an error occured.
Definition at line 656 of file neigh.c.
657{
658 int err;
659 struct nl_msg *msg;
660
662 if (!msg)
663 return nl_errno(ENOMEM);
664
667 if (err < 0)
668 return err;
669
671}
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
struct nl_msg * rtnl_neigh_build_add_request(struct rtnl_neigh *tmpl, int flags)
Build netlink request message to add a new neighbour.
int nl_send_auto_complete(struct nl_handle *handle, struct nl_msg *msg)
Send netlink message and check & extend header values as needed.
int nl_wait_for_ack(struct nl_handle *handle)
Wait for ACK.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_neigh_build_add_request().
◆ rtnl_neigh_build_delete_request()
| struct nl_msg * rtnl_neigh_build_delete_request |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
flags |
|
) |
| |
- Parameters
-
| neigh | neighbour to delete |
| flags | additional netlink message flags |
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
- The netlink message
Definition at line 693 of file neigh.c.
695{
696 return build_neigh_msg(neigh, RTM_DELNEIGH, flags);
697}
Referenced by rtnl_neigh_delete().
◆ rtnl_neigh_delete()
| int rtnl_neigh_delete |
( |
struct nl_handle * |
handle, |
|
|
struct rtnl_neigh * |
neigh, |
|
|
int |
flags |
|
) |
| |
- Parameters
-
| handle | netlink handle |
| neigh | neighbour to delete |
| flags | additional netlink message flags |
Builds a netlink message by calling rtnl_neigh_build_delete_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.
- Returns
- 0 on sucess or a negative error if an error occured.
Definition at line 711 of file neigh.c.
713{
714 int err;
715 struct nl_msg *msg;
716
718 if (!msg)
719 return nl_errno(ENOMEM);
720
723 if (err < 0)
724 return err;
725
727}
struct nl_msg * rtnl_neigh_build_delete_request(struct rtnl_neigh *neigh, int flags)
Build a netlink request message to delete a neighbour.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_neigh_build_delete_request().
◆ rtnl_neigh_build_change_request()
| struct nl_msg * rtnl_neigh_build_change_request |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
flags |
|
) |
| |
- Parameters
-
| neigh | the neighbour to change |
| flags | additional netlink message flags |
Builds a new netlink message requesting a change of a neigh attributes. 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.
- Returns
- The netlink message
- Note
- Not all attributes can be changed, see Changeable Attributes for a list.
Definition at line 750 of file neigh.c.
752{
753 return build_neigh_msg(neigh, RTM_NEWNEIGH,
NLM_F_REPLACE | flags);
754}
References NLM_F_REPLACE.
Referenced by rtnl_neigh_change().
◆ rtnl_neigh_change()
| int rtnl_neigh_change |
( |
struct nl_handle * |
handle, |
|
|
struct rtnl_neigh * |
neigh, |
|
|
int |
flags |
|
) |
| |
- Parameters
-
| handle | netlink handle |
| neigh | neighbour to be changed |
| flags | additional netlink message flags |
Builds a netlink message by calling rtnl_neigh_build_change_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.
- Returns
- 0 on sucess or a negative error if an error occured.
- Note
- Not all attributes can be changed, see Changeable Attributes for a list.
Definition at line 770 of file neigh.c.
772{
773 int err;
774 struct nl_msg *msg;
775
777 if (!msg)
778 return nl_errno(ENOMEM);
779
782 if (err < 0)
783 return err;
784
786}
struct nl_msg * rtnl_neigh_build_change_request(struct rtnl_neigh *neigh, int flags)
Build a netlink request message to change neighbour attributes.
References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_neigh_build_change_request().
◆ rtnl_neigh_state2str()
| char * rtnl_neigh_state2str |
( |
int |
state, |
|
|
char * |
buf, |
|
|
size_t |
len |
|
) |
| |
Definition at line 806 of file neigh.c.
807{
808 return __flags2str(state, buf, len, neigh_states,
809 ARRAY_SIZE(neigh_states));
810}
◆ rtnl_neigh_str2state()
| int rtnl_neigh_str2state |
( |
const char * |
name | ) |
|
Definition at line 812 of file neigh.c.
813{
814 return __str2type(name, neigh_states, ARRAY_SIZE(neigh_states));
815}
◆ rtnl_neigh_flags2str()
| char * rtnl_neigh_flags2str |
( |
int |
flags, |
|
|
char * |
buf, |
|
|
size_t |
len |
|
) |
| |
Definition at line 829 of file neigh.c.
830{
831 return __flags2str(flags, buf, len, neigh_flags,
832 ARRAY_SIZE(neigh_flags));
833}
◆ rtnl_neigh_str2flag()
| int rtnl_neigh_str2flag |
( |
const char * |
name | ) |
|
Definition at line 835 of file neigh.c.
836{
837 return __str2type(name, neigh_flags, ARRAY_SIZE(neigh_flags));
838}
◆ rtnl_neigh_set_state()
| void rtnl_neigh_set_state |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
state |
|
) |
| |
Definition at line 847 of file neigh.c.
848{
849 neigh->n_state_mask |= state;
850 neigh->n_state |= state;
851 neigh->ce_mask |= NEIGH_ATTR_STATE;
852}
◆ rtnl_neigh_get_state()
| int rtnl_neigh_get_state |
( |
struct rtnl_neigh * |
neigh | ) |
|
Definition at line 854 of file neigh.c.
855{
856 if (neigh->ce_mask & NEIGH_ATTR_STATE)
857 return neigh->n_state;
858 else
859 return -1;
860}
◆ rtnl_neigh_unset_state()
| void rtnl_neigh_unset_state |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
state |
|
) |
| |
Definition at line 862 of file neigh.c.
863{
864 neigh->n_state_mask |= state;
865 neigh->n_state &= ~state;
866 neigh->ce_mask |= NEIGH_ATTR_STATE;
867}
◆ rtnl_neigh_set_flags()
| void rtnl_neigh_set_flags |
( |
struct rtnl_neigh * |
neigh, |
|
|
unsigned int |
flags |
|
) |
| |
Definition at line 869 of file neigh.c.
870{
871 neigh->n_flag_mask |= flags;
872 neigh->n_flags |= flags;
873 neigh->ce_mask |= NEIGH_ATTR_FLAGS;
874}
◆ rtnl_neigh_get_flags()
| unsigned int rtnl_neigh_get_flags |
( |
struct rtnl_neigh * |
neigh | ) |
|
Definition at line 876 of file neigh.c.
877{
878 return neigh->n_flags;
879}
◆ rtnl_neigh_unset_flags()
| void rtnl_neigh_unset_flags |
( |
struct rtnl_neigh * |
neigh, |
|
|
unsigned int |
flags |
|
) |
| |
Definition at line 881 of file neigh.c.
882{
883 neigh->n_flag_mask |= flags;
884 neigh->n_flags &= ~flags;
885 neigh->ce_mask |= NEIGH_ATTR_FLAGS;
886}
◆ rtnl_neigh_set_ifindex()
| void rtnl_neigh_set_ifindex |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
ifindex |
|
) |
| |
Definition at line 888 of file neigh.c.
889{
890 neigh->n_ifindex = ifindex;
891 neigh->ce_mask |= NEIGH_ATTR_IFINDEX;
892}
◆ rtnl_neigh_get_ifindex()
| int rtnl_neigh_get_ifindex |
( |
struct rtnl_neigh * |
neigh | ) |
|
Definition at line 894 of file neigh.c.
895{
896 if (neigh->ce_mask & NEIGH_ATTR_IFINDEX)
897 return neigh->n_ifindex;
898 else
900}
#define RTNL_LINK_NOT_FOUND
Special interface index stating the link was not found.
◆ rtnl_neigh_set_lladdr()
| void rtnl_neigh_set_lladdr |
( |
struct rtnl_neigh * |
neigh, |
|
|
struct nl_addr * |
addr |
|
) |
| |
Definition at line 927 of file neigh.c.
928{
929 __assign_addr(neigh, &neigh->n_lladdr, addr, NEIGH_ATTR_LLADDR, 1);
930}
◆ rtnl_neigh_get_lladdr()
| struct nl_addr * rtnl_neigh_get_lladdr |
( |
struct rtnl_neigh * |
neigh | ) |
|
Definition at line 932 of file neigh.c.
933{
934 if (neigh->ce_mask & NEIGH_ATTR_LLADDR)
935 return neigh->n_lladdr;
936 else
937 return NULL;
938}
◆ rtnl_neigh_set_dst()
| int rtnl_neigh_set_dst |
( |
struct rtnl_neigh * |
neigh, |
|
|
struct nl_addr * |
addr |
|
) |
| |
Definition at line 940 of file neigh.c.
941{
942 return __assign_addr(neigh, &neigh->n_dst, addr,
943 NEIGH_ATTR_DST, 0);
944}
◆ rtnl_neigh_get_dst()
| struct nl_addr * rtnl_neigh_get_dst |
( |
struct rtnl_neigh * |
neigh | ) |
|
Definition at line 946 of file neigh.c.
947{
948 if (neigh->ce_mask & NEIGH_ATTR_DST)
949 return neigh->n_dst;
950 else
951 return NULL;
952}
◆ rtnl_neigh_set_family()
| void rtnl_neigh_set_family |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
family |
|
) |
| |
Definition at line 954 of file neigh.c.
955{
956 neigh->n_family = family;
957 neigh->ce_mask |= NEIGH_ATTR_FAMILY;
958}
◆ rtnl_neigh_set_type()
| void rtnl_neigh_set_type |
( |
struct rtnl_neigh * |
neigh, |
|
|
int |
type |
|
) |
| |
Definition at line 960 of file neigh.c.
961{
962 neigh->n_type = type;
963 neigh->ce_mask = NEIGH_ATTR_TYPE;
964}
◆ rtnl_neigh_get_type()
| int rtnl_neigh_get_type |
( |
struct rtnl_neigh * |
neigh | ) |
|
Definition at line 966 of file neigh.c.
967{
968 if (neigh->ce_mask & NEIGH_ATTR_TYPE)
969 return neigh->n_type;
970 else
971 return -1;
972}