All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 03/11] rtnl: Add l_rtnl_route_new_static
@ 2022-04-18 19:19 Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2022-04-18 19:19 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]

Hi Andrew,

On 4/11/22 09:20, Andrew Zaborowski wrote:
> Add a constructor for prefix routes through a specific gateway/router.
> ---
> Name follows suggestion in
> https://lists.01.org/hyperkitty/list/ell(a)lists.01.org/message/ZPJRBKRROCGZFVLLFUCL6GYHHG2JQZLW/
> ---
>   ell/ell.sym |  1 +
>   ell/rtnl.c  | 31 +++++++++++++++++++++++++++++++
>   ell/rtnl.h  |  2 ++
>   3 files changed, 34 insertions(+)
> 

Applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 03/11] rtnl: Add l_rtnl_route_new_static
@ 2022-04-11 14:20 Andrew Zaborowski
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Zaborowski @ 2022-04-11 14:20 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 2413 bytes --]

Add a constructor for prefix routes through a specific gateway/router.
---
Name follows suggestion in
https://lists.01.org/hyperkitty/list/ell(a)lists.01.org/message/ZPJRBKRROCGZFVLLFUCL6GYHHG2JQZLW/
---
 ell/ell.sym |  1 +
 ell/rtnl.c  | 31 +++++++++++++++++++++++++++++++
 ell/rtnl.h  |  2 ++
 3 files changed, 34 insertions(+)

diff --git a/ell/ell.sym b/ell/ell.sym
index ec995fc..3816e3f 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -639,6 +639,7 @@ global:
 	l_rtnl_address_set_scope;
 	l_rtnl_route_new_gateway;
 	l_rtnl_route_new_prefix;
+	l_rtnl_route_new_static;
 	l_rtnl_route_free;
 	l_rtnl_route_get_family;
 	l_rtnl_route_get_gateway;
diff --git a/ell/rtnl.c b/ell/rtnl.c
index afbff9d..dbaf97b 100644
--- a/ell/rtnl.c
+++ b/ell/rtnl.c
@@ -419,6 +419,37 @@ LIB_EXPORT struct l_rtnl_route *l_rtnl_route_new_prefix(const char *ip,
 	return rt;
 }
 
+LIB_EXPORT struct l_rtnl_route *l_rtnl_route_new_static(const char *gw,
+							const char *ip,
+							uint8_t prefix_len)
+{
+	struct in_addr gw_addr4;
+	struct in6_addr gw_addr6;
+	struct in_addr dst_addr4;
+	struct in6_addr dst_addr6;
+	int family;
+	struct l_rtnl_route *rt;
+
+	if ((family = address_get(gw, &gw_addr4, &gw_addr6)) < 0)
+		return NULL;
+
+	if (address_get(ip, &dst_addr4, &dst_addr6) != family)
+		return NULL;
+
+	if (prefix_len == 0 || prefix_len > (family == AF_INET ? 32 : 128))
+		return NULL;
+
+	rt = l_rtnl_route_new_gateway(gw);
+	rt->dst_prefix_len = prefix_len;
+
+	if (family == AF_INET6)
+		memcpy(&rt->dst.in6_addr, &dst_addr6, sizeof(dst_addr6));
+	else
+		memcpy(&rt->dst.in_addr, &dst_addr4, sizeof(dst_addr4));
+
+	return rt;
+}
+
 LIB_EXPORT void l_rtnl_route_free(struct l_rtnl_route *rt)
 {
 	l_free(rt);
diff --git a/ell/rtnl.h b/ell/rtnl.h
index bbd410e..55c4997 100644
--- a/ell/rtnl.h
+++ b/ell/rtnl.h
@@ -71,6 +71,8 @@ bool l_rtnl_address_set_scope(struct l_rtnl_address *addr, uint8_t scope);
 struct l_rtnl_route *l_rtnl_route_new_gateway(const char *gw);
 struct l_rtnl_route *l_rtnl_route_new_prefix(const char *ip,
 							uint8_t prefix_len);
+struct l_rtnl_route *l_rtnl_route_new_static(const char *gw, const char *ip,
+							uint8_t prefix_len);
 void l_rtnl_route_free(struct l_rtnl_route *rt);
 DEFINE_CLEANUP_FUNC(l_rtnl_route_free);
 uint8_t l_rtnl_route_get_family(const struct l_rtnl_route *rt);
-- 
2.32.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-18 19:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-18 19:19 [PATCH 03/11] rtnl: Add l_rtnl_route_new_static Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2022-04-11 14:20 Andrew Zaborowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.