All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtnl: Add l_rtnl_ifaddr_extract
@ 2021-05-18 22:20 Andrew Zaborowski
  2021-05-18 22:43 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Zaborowski @ 2021-05-18 22:20 UTC (permalink / raw)
  To: ell

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

Extracts information from struct ifaddrmsg directly into an
l_rtnl_address object.
---
 ell/ell.sym |  1 +
 ell/rtnl.c  | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 ell/rtnl.h  |  2 ++
 3 files changed, 56 insertions(+)

diff --git a/ell/ell.sym b/ell/ell.sym
index 5568ac2..ec44d3a 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -641,6 +641,7 @@ global:
 	l_rtnl_route6_delete_gateway;
 	l_rtnl_route_add;
 	l_rtnl_route_delete;
+	l_rtnl_ifaddr_extract;
 	l_rtnl_ifaddr_add;
 	l_rtnl_ifaddr_delete;
 /* icmp6 */
diff --git a/ell/rtnl.c b/ell/rtnl.c
index c5b479b..e2996a6 100644
--- a/ell/rtnl.c
+++ b/ell/rtnl.c
@@ -1126,6 +1126,59 @@ done:
 	return id;
 }
 
+LIB_EXPORT struct l_rtnl_address *l_rtnl_ifaddr_extract(
+						const struct ifaddrmsg *ifa,
+						int bytes)
+{
+	struct rtattr *attr;
+	struct ifa_cacheinfo *cinfo;
+	struct l_rtnl_address *addr;
+
+	if (unlikely(!ifa))
+		return NULL;
+
+	if (!L_IN_SET(ifa->ifa_family, AF_INET, AF_INET6))
+		return NULL;
+
+	addr = l_new(struct l_rtnl_address, 1);
+	addr->prefix_len = ifa->ifa_prefixlen;
+	addr->family = ifa->ifa_family;
+	addr->flags = ifa->ifa_flags;
+	addr->scope = ifa->ifa_scope;
+
+	for (attr = IFA_RTA(ifa); RTA_OK(attr, bytes);
+						attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case IFA_LOCAL:
+			if (ifa->ifa_family == AF_INET)
+				addr->in_addr =
+					*((struct in_addr *) RTA_DATA(attr));
+
+			break;
+		case IFA_ADDRESS:
+			if (ifa->ifa_family == AF_INET6)
+				addr->in6_addr =
+					*((struct in6_addr *) RTA_DATA(attr));
+
+			break;
+		case IFA_BROADCAST:
+			addr->broadcast = *((struct in_addr *) RTA_DATA(attr));
+			break;
+		case IFA_LABEL:
+			l_strlcpy(addr->label, RTA_DATA(attr),
+					sizeof(addr->label));
+			break;
+		case IFA_CACHEINFO:
+			cinfo = RTA_DATA(attr);
+			addr->preferred_lifetime = cinfo->ifa_prefered;
+			addr->valid_lifetime = cinfo->ifa_valid;
+			break;
+		}
+	}
+
+	return addr;
+}
+
 LIB_EXPORT uint32_t l_rtnl_ifaddr_add(struct l_netlink *rtnl, int ifindex,
 					const struct l_rtnl_address *addr,
 					l_netlink_command_func_t cb,
diff --git a/ell/rtnl.h b/ell/rtnl.h
index c54a287..adabcfe 100644
--- a/ell/rtnl.h
+++ b/ell/rtnl.h
@@ -164,6 +164,8 @@ uint32_t l_rtnl_route6_delete_gateway(struct l_netlink *rtnl, int ifindex,
 					void *user_data,
 					l_netlink_destroy_func_t destroy);
 
+struct l_rtnl_address *l_rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes);
+
 uint32_t l_rtnl_ifaddr_add(struct l_netlink *rtnl, int ifindex,
 					const struct l_rtnl_address *addr,
 					l_netlink_command_func_t cb,
-- 
2.27.0

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

* Re: [PATCH] rtnl: Add l_rtnl_ifaddr_extract
  2021-05-18 22:20 [PATCH] rtnl: Add l_rtnl_ifaddr_extract Andrew Zaborowski
@ 2021-05-18 22:43 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-05-18 22:43 UTC (permalink / raw)
  To: ell

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

Hi Andrew,

On 5/18/21 5:20 PM, Andrew Zaborowski wrote:
> Extracts information from struct ifaddrmsg directly into an
> l_rtnl_address object.
> ---
>   ell/ell.sym |  1 +
>   ell/rtnl.c  | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>   ell/rtnl.h  |  2 ++
>   3 files changed, 56 insertions(+)
> 

Applied, thanks.

Regards,
-Denis

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

end of thread, other threads:[~2021-05-18 22:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18 22:20 [PATCH] rtnl: Add l_rtnl_ifaddr_extract Andrew Zaborowski
2021-05-18 22:43 ` Denis Kenzior

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.