Skip to contentSkip to conversation

rtnl: Add neighbor discovery utilities

PATCH Applied Andrew Zaborowski 2 participants 2 messages Aug 26, 2021 – Aug 28, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtnl: Add neighbor discovery utilities

Add a few variants of RTNL utilities to look up addresses in the kernel's neighbour table entries and to add new entries. This is basically the ARP (for IPv4) and NDP (for IPv6) tables, that map IP addresses to hardware addresses.

---
 ell/ell.sym  |   2 +
 ell/rtnl.c   | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++
 ell/rtnl.h   |  17 +++++++
 ell/useful.h |   4 ++
 4 files changed, 150 insertions(+)
ell/ell.sym +2 -0
index b29d98d..9fcf334 100644
@@ -663,6 +663,8 @@ global:
 	l_rtnl_ifaddr_extract;
 	l_rtnl_ifaddr_add;
 	l_rtnl_ifaddr_delete;
+	l_rtnl_neighbor_get_hwaddr;
+	l_rtnl_neighbor_set_hwaddr;
 /* icmp6 */
 	l_icmp6_client_new;
 	l_icmp6_client_free;
ell/rtnl.c +127 -0

142 lines not on this page · raw message

ell/rtnl.h +17 -0
index 9ea24f5..85b1370 100644
@@ -33,6 +33,10 @@ extern "C" {
 struct l_rtnl_address;
 struct l_rtnl_route;
 
+typedef void (*l_rtnl_neighbor_get_cb_t) (int error, const uint8_t *hwaddr,
+						size_t hwaddr_len,
+						void *user_data);
+
 struct l_rtnl_address *l_rtnl_address_new(const char *ip, uint8_t prefix_len);
 struct l_rtnl_address *l_rtnl_address_clone(const struct l_rtnl_address *orig);
 void l_rtnl_address_free(struct l_rtnl_address *addr);
@@ -191,6 +195,19 @@ uint32_t l_rtnl_route_delete(struct l_netlink *rtnl, int ifindex,
 					void *user_data,
 					l_netlink_destroy_func_t destroy);
 
+uint32_t l_rtnl_neighbor_get_hwaddr(struct l_netlink *rtnl, int ifindex,
+					int family, const void *ip,
+					l_rtnl_neighbor_get_cb_t cb,
+					void *user_data,
+					l_netlink_destroy_func_t destroy);
+uint32_t l_rtnl_neighbor_set_hwaddr(struct l_netlink *rtnl, int ifindex,
+					int family, const void *ip,
+					const uint8_t *hwaddr,
+					size_t hwaddr_len,
+					l_netlink_command_func_t cb,
+					void *user_data,
+					l_netlink_destroy_func_t destroy);
+
 #ifdef __cplusplus
 }
 #endif
ell/useful.h +4 -0
index d696bc3..b4783ce 100644
@@ -83,3 +83,7 @@ static inline int secure_select(int select_left, int l, int r)
 
 	return r ^ ((l ^ r) & mask);
 }
+
+#define struct_alloc(structname, ...) \
+	(struct structname *) l_memdup(&(struct structname) { __VA_ARGS__ }, \
+					sizeof(struct structname))
Signature · 1 line
2.30.2
#1 lore raw

Hi Andrew,

Quoted 11 lines · Andrew Zaborowski

Add a few variants of RTNL utilities to look up addresses in the kernel's neighbour table entries and to add new entries. This is basically the ARP (for IPv4) and NDP (for IPv6) tables, that map IP addresses to hardware addresses.

---
  ell/ell.sym  |   2 +
  ell/rtnl.c   | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++
  ell/rtnl.h   |  17 +++++++
  ell/useful.h |   4 ++
  4 files changed, 150 insertions(+)

Applied, thanks.

Regards,
-Denis