ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH 04/11] rtnl: Add l_rtnl_route getters for raw address data
@ 2022-04-18 19:21 Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2022-04-18 19:21 UTC (permalink / raw)
  To: ell

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

Hi Andrew,

On 4/11/22 09:20, Andrew Zaborowski wrote:
> Add l_rtnl_route_get_gateway_in_addr and l_rtnl_route_get_dst_in_addr
> for raw struct in_addr / struct in6_addr addresses, as opposed to string
> representations.  This is to be used to avoid unneeded string
> conversions in both directions.
> ---
>   ell/ell.sym |  2 ++
>   ell/rtnl.c  | 30 ++++++++++++++++++++++++++++++
>   ell/rtnl.h  |  3 +++
>   3 files changed, 35 insertions(+)
> 

Applied, thanks.

Regards,
-Denis

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

* [PATCH 04/11] rtnl: Add l_rtnl_route getters for raw address data
@ 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: 2879 bytes --]

Add l_rtnl_route_get_gateway_in_addr and l_rtnl_route_get_dst_in_addr
for raw struct in_addr / struct in6_addr addresses, as opposed to string
representations.  This is to be used to avoid unneeded string
conversions in both directions.
---
 ell/ell.sym |  2 ++
 ell/rtnl.c  | 30 ++++++++++++++++++++++++++++++
 ell/rtnl.h  |  3 +++
 3 files changed, 35 insertions(+)

diff --git a/ell/ell.sym b/ell/ell.sym
index 3816e3f..9b3a6e1 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -643,7 +643,9 @@ global:
 	l_rtnl_route_free;
 	l_rtnl_route_get_family;
 	l_rtnl_route_get_gateway;
+	l_rtnl_route_get_gateway_in_addr;
 	l_rtnl_route_get_dst;
+	l_rtnl_route_get_dst_in_addr;
 	l_rtnl_route_get_lifetime;
 	l_rtnl_route_set_lifetime;
 	l_rtnl_route_get_expiry;
diff --git a/ell/rtnl.c b/ell/rtnl.c
index dbaf97b..cbe9b87 100644
--- a/ell/rtnl.c
+++ b/ell/rtnl.c
@@ -473,6 +473,21 @@ LIB_EXPORT bool l_rtnl_route_get_gateway(const struct l_rtnl_route *rt,
 					out_buf);
 }
 
+LIB_EXPORT const void *l_rtnl_route_get_gateway_in_addr(
+						const struct l_rtnl_route *rt)
+{
+	if (unlikely(!rt))
+		return NULL;
+
+	if (address_is_null(rt->family, &rt->gw.in_addr, &rt->gw.in6_addr))
+		return NULL;
+
+	if (rt->family == AF_INET)
+		return &rt->gw.in_addr;
+	else
+		return &rt->gw.in6_addr;
+}
+
 LIB_EXPORT bool l_rtnl_route_get_dst(const struct l_rtnl_route *rt,
 						char *out_buf,
 						uint8_t *out_prefix_len)
@@ -488,6 +503,21 @@ LIB_EXPORT bool l_rtnl_route_get_dst(const struct l_rtnl_route *rt,
 	return true;
 }
 
+LIB_EXPORT const void *l_rtnl_route_get_dst_in_addr(
+						const struct l_rtnl_route *rt,
+						uint8_t *out_prefix_len)
+{
+	if (unlikely(!rt))
+		return NULL;
+
+	*out_prefix_len = rt->dst_prefix_len;
+
+	if (rt->family == AF_INET)
+		return &rt->dst.in_addr;
+	else
+		return &rt->dst.in6_addr;
+}
+
 LIB_EXPORT uint32_t l_rtnl_route_get_lifetime(const struct l_rtnl_route *rt)
 {
 	if (unlikely(!rt))
diff --git a/ell/rtnl.h b/ell/rtnl.h
index 55c4997..2617b1c 100644
--- a/ell/rtnl.h
+++ b/ell/rtnl.h
@@ -77,8 +77,11 @@ 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);
 bool l_rtnl_route_get_gateway(const struct l_rtnl_route *rt, char *out_buf);
+const void *l_rtnl_route_get_gateway_in_addr(const struct l_rtnl_route *rt);
 bool l_rtnl_route_get_dst(const struct l_rtnl_route *rt, char *out_buf,
 				uint8_t *out_prefix_len);
+const void *l_rtnl_route_get_dst_in_addr(const struct l_rtnl_route *rt,
+						uint8_t *out_prefix_len);
 uint32_t l_rtnl_route_get_lifetime(const struct l_rtnl_route *rt);
 bool l_rtnl_route_set_lifetime(struct l_rtnl_route *rt, uint32_t lt);
 uint64_t l_rtnl_route_get_expiry(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:21 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:21 [PATCH 04/11] rtnl: Add l_rtnl_route getters for raw address data Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2022-04-11 14:20 Andrew Zaborowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).