All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Wagner <wagi@monom.org>
To: ell@lists.01.org
Subject: [PATCH 3/3] rtnl: Extract table, priority and pref
Date: Fri, 14 Feb 2020 19:52:53 +0100	[thread overview]
Message-ID: <20200214185253.32658-4-wagi@monom.org> (raw)
In-Reply-To: <20200214185253.32658-1-wagi@monom.org>

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

---
 ell/rtnl.c       | 38 ++++++++++++++++++++++++++++++--------
 ell/rtnl.h       |  8 ++++----
 unit/test-rtnl.c | 16 ++++++++++------
 3 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/ell/rtnl.c b/ell/rtnl.c
index c94531144eb4..4600a7e42001 100644
--- a/ell/rtnl.c
+++ b/ell/rtnl.c
@@ -69,12 +69,14 @@ static size_t rta_add_data(void *rta_buf, unsigned short type, void *data,
 }
 
 static void l_rtnl_route_extract(const struct rtmsg *rtmsg, uint32_t len,
-				int family, uint32_t *ifindex, char **dst,
-				char **gateway,	char **src)
+				int family, uint32_t *table, uint32_t *ifindex,
+				uint32_t *priority, uint8_t *pref,
+				char **dst, char **gateway, char **src)
 {
 	struct rtattr *attr;
 	char buf[INET6_ADDRSTRLEN];
 
+	/* Not extracted at the moment: RTA_CACHEINFO for IPv6 */
 	for (attr = RTM_RTA(rtmsg); RTA_OK(attr, len);
 						attr = RTA_NEXT(attr, len)) {
 		switch (attr->rta_type) {
@@ -101,6 +103,24 @@ static void l_rtnl_route_extract(const struct rtmsg *rtmsg, uint32_t len,
 			inet_ntop(family, RTA_DATA(attr), buf, sizeof(buf));
 			*src = l_strdup(buf);
 
+			break;
+		case RTA_TABLE:
+			if (!table)
+				break;
+
+			*table = *((uint32_t *) RTA_DATA(attr));
+			break;
+		case RTA_PRIORITY:
+			if (!priority)
+				break;
+
+			*priority = *((uint32_t *) RTA_DATA(attr));
+			break;
+		case RTA_PREF:
+			if (!pref)
+				break;
+
+			*pref = *((uint8_t *) RTA_DATA(attr));
 			break;
 		case RTA_OIF:
 			if (!ifindex)
@@ -335,10 +355,11 @@ uint32_t l_rtnl_ifaddr4_delete(struct l_netlink *rtnl, int ifindex,
 }
 
 void l_rtnl_route4_extract(const struct rtmsg *rtmsg, uint32_t len,
-				uint32_t *ifindex, char **dst, char **gateway,
-				char **src)
+				uint32_t *table, uint32_t *ifindex,
+				char **dst, char **gateway, char **src)
 {
-	l_rtnl_route_extract(rtmsg, len, AF_INET, ifindex, dst, gateway, src);
+	l_rtnl_route_extract(rtmsg, len, AF_INET, table, ifindex,
+				NULL, NULL, dst, gateway, src);
 }
 
 uint32_t l_rtnl_route4_dump(struct l_netlink *rtnl,
@@ -568,10 +589,11 @@ uint32_t l_rtnl_ifaddr6_delete(struct l_netlink *rtnl, int ifindex,
 }
 
 void l_rtnl_route6_extract(const struct rtmsg *rtmsg, uint32_t len,
-				uint32_t *ifindex, char **dst, char **gateway,
-				char **src)
+				uint32_t *table, uint32_t *ifindex,
+				char **dst, char **gateway, char **src)
 {
-	l_rtnl_route_extract(rtmsg, len, AF_INET6, ifindex, dst, gateway, src);
+	l_rtnl_route_extract(rtmsg, len, AF_INET6, table, ifindex,
+				NULL, NULL, dst, gateway, src);
 }
 
 uint32_t l_rtnl_route6_dump(struct l_netlink *rtnl,
diff --git a/ell/rtnl.h b/ell/rtnl.h
index 2be2eaee99e2..ea283c1c5a6e 100644
--- a/ell/rtnl.h
+++ b/ell/rtnl.h
@@ -63,8 +63,8 @@ uint32_t l_rtnl_ifaddr4_delete(struct l_netlink *rtnl, int ifindex,
 				l_netlink_destroy_func_t destroy);
 
 void l_rtnl_route4_extract(const struct rtmsg *rtmsg, uint32_t len,
-				uint32_t *ifindex, char **dst, char **gateway,
-				char **src);
+				uint32_t *table, uint32_t *ifindex,
+				char **dst, char **gateway, char **src);
 uint32_t l_rtnl_route4_dump(struct l_netlink *rtnl,
 				l_netlink_command_func_t cb, void *user_data,
 				l_netlink_destroy_func_t destroy);
@@ -98,8 +98,8 @@ uint32_t l_rtnl_ifaddr6_delete(struct l_netlink *rtnl, int ifindex,
 					void *user_data,
 					l_netlink_destroy_func_t destroy);
 void l_rtnl_route6_extract(const struct rtmsg *rtmsg, uint32_t len,
-				uint32_t *ifindex, char **dst, char **gateway,
-				char **src);
+				uint32_t *table, uint32_t *ifindex,
+				char **dst, char **gateway, char **src);
 uint32_t l_rtnl_route6_dump(struct l_netlink *rtnl,
 				l_netlink_command_func_t cb, void *user_data,
 				l_netlink_destroy_func_t destroy);
diff --git a/unit/test-rtnl.c b/unit/test-rtnl.c
index 37db73dc6f2f..107f69a76da1 100644
--- a/unit/test-rtnl.c
+++ b/unit/test-rtnl.c
@@ -114,14 +114,16 @@ static void route4_dump_cb(int error,
 {
 	const struct rtmsg *rtmsg = data;
 	char *dst = NULL, *gateway = NULL, *src = NULL;
-	uint32_t idx;
+	uint32_t table, ifindex;
 
 	test_assert(!error);
 	test_assert(type == RTM_NEWROUTE);
 
-	l_rtnl_route4_extract(rtmsg, len, &idx, &dst, &gateway, &src);
+	l_rtnl_route4_extract(rtmsg, len, &table, &ifindex,
+				&dst, &gateway, &src);
 
-	l_info("idx %d dst %s gateway %s src %s", idx, dst, gateway, src);
+	l_info("table %d ifindex %d dst %s gateway %s src %s",
+		table, ifindex, dst, gateway, src);
 
 	l_free(dst);
 	l_free(gateway);
@@ -145,14 +147,16 @@ static void route6_dump_cb(int error,
 {
 	const struct rtmsg *rtmsg = data;
 	char *dst = NULL, *gateway = NULL, *src = NULL;
-	uint32_t idx;
+	uint32_t table, ifindex;
 
 	test_assert(!error);
 	test_assert(type == RTM_NEWROUTE);
 
-	l_rtnl_route6_extract(rtmsg, len, &idx, &dst, &gateway, &src);
+	l_rtnl_route6_extract(rtmsg, len, &table, &ifindex,
+				&dst, &gateway, &src);
 
-	l_info("idx %d dst %s gateway %s src %s", idx, dst, gateway, src);
+	l_info("table %d ifindex %d dst %s gateway %s src %s",
+		table, ifindex, dst, gateway, src);
 
 	l_free(dst);
 	l_free(gateway);
-- 
2.25.0

  parent reply	other threads:[~2020-02-14 18:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14 18:52 [PATCH 0/3] rtnl: add missing APIs Daniel Wagner
2020-02-14 18:52 ` [PATCH 1/3] rtnl: Add l_rtnl_route6_dump() and l_rtnl_route6_extract() Daniel Wagner
2020-02-14 18:52 ` [PATCH 2/3] unit: Add unit test for l_rtnl_route6_{dump|extract} Daniel Wagner
2020-02-14 18:52 ` Daniel Wagner [this message]
2020-02-14 19:05 ` [PATCH 0/3] rtnl: add missing APIs Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200214185253.32658-4-wagi@monom.org \
    --to=wagi@monom.org \
    --cc=ell@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.