Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: Tim Kourt <tim.a.kourt@linux.intel.com>
To: iwd@lists.01.org
Subject: [PATCH v2 10/14] rtnlutil: Add IPv6 address change helpers
Date: Fri, 27 Sep 2019 17:12:29 -0700	[thread overview]
Message-ID: <20190928001233.19217-10-tim.a.kourt@linux.intel.com> (raw)
In-Reply-To: <20190928001233.19217-1-tim.a.kourt@linux.intel.com>

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

Implements the IPv6 helper functions to add/delete IP addresses.
---
 src/rtnlutil.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/rtnlutil.h |  9 +++++++++
 2 files changed, 72 insertions(+)

diff --git a/src/rtnlutil.c b/src/rtnlutil.c
index 0cee5ff5..cca83a40 100644
--- a/src/rtnlutil.c
+++ b/src/rtnlutil.c
@@ -469,3 +469,66 @@ uint32_t rtnl_ifaddr_ipv6_get(struct l_netlink *rtnl,
 
 	return id;
 }
+
+static uint32_t rtnl_ifaddr_ipv6_change(struct l_netlink *rtnl,
+					uint16_t nlmsg_type,
+					int ifindex, uint8_t prefix_len,
+					const char *ip,
+					l_netlink_command_func_t cb,
+					void *user_data,
+					l_netlink_destroy_func_t destroy)
+{
+	struct ifaddrmsg *rtmmsg;
+	struct in6_addr in6_addr;
+	void *rta_buf;
+	size_t bufsize;
+	uint32_t id;
+
+	bufsize = NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
+					RTA_SPACE(sizeof(struct in6_addr));
+
+	rtmmsg = l_malloc(bufsize);
+	memset(rtmmsg, 0, bufsize);
+
+	rtmmsg->ifa_index = ifindex;
+	rtmmsg->ifa_family = AF_INET6;
+	rtmmsg->ifa_flags = IFA_F_PERMANENT;
+	rtmmsg->ifa_scope = RT_SCOPE_UNIVERSE;
+	rtmmsg->ifa_prefixlen = prefix_len;
+
+	rta_buf = (void *) rtmmsg + NLMSG_ALIGN(sizeof(struct ifaddrmsg));
+
+	if (inet_pton(AF_INET6, ip, &in6_addr) < 1) {
+		l_free(rtmmsg);
+		return 0;
+	}
+
+	rta_buf += rta_add_data(rta_buf, IFA_LOCAL, &in6_addr,
+						sizeof(struct in6_addr));
+
+	id = l_netlink_send(rtnl, nlmsg_type, 0, rtmmsg,
+						rta_buf - (void *) rtmmsg, cb,
+						user_data, destroy);
+	l_free(rtmmsg);
+
+	return id;
+}
+
+uint32_t rtnl_ifaddr_ipv6_add(struct l_netlink *rtnl, int ifindex,
+				uint8_t prefix_len, const char *ip,
+				l_netlink_command_func_t cb, void *user_data,
+				l_netlink_destroy_func_t destroy)
+{
+	return rtnl_ifaddr_ipv6_change(rtnl, RTM_NEWADDR, ifindex, prefix_len,
+						ip, cb, user_data, destroy);
+}
+
+uint32_t rtnl_ifaddr_ipv6_delete(struct l_netlink *rtnl, int ifindex,
+					uint8_t prefix_len, const char *ip,
+					l_netlink_command_func_t cb,
+					void *user_data,
+					l_netlink_destroy_func_t destroy)
+{
+	return rtnl_ifaddr_ipv6_change(rtnl, RTM_DELADDR, ifindex, prefix_len,
+						ip, cb, user_data, destroy);
+}
diff --git a/src/rtnlutil.h b/src/rtnlutil.h
index ff1427c5..5a901234 100644
--- a/src/rtnlutil.h
+++ b/src/rtnlutil.h
@@ -74,3 +74,12 @@ uint32_t rtnl_ifaddr_ipv6_get(struct l_netlink *rtnl,
 				l_netlink_command_func_t cb,
 				void *user_data,
 				l_netlink_destroy_func_t destroy);
+uint32_t rtnl_ifaddr_ipv6_add(struct l_netlink *rtnl, int ifindex,
+				uint8_t prefix_len, const char *ip,
+				l_netlink_command_func_t cb, void *user_data,
+				l_netlink_destroy_func_t destroy);
+uint32_t rtnl_ifaddr_ipv6_delete(struct l_netlink *rtnl, int ifindex,
+					uint8_t prefix_len, const char *ip,
+					l_netlink_command_func_t cb,
+					void *user_data,
+					l_netlink_destroy_func_t destroy);
-- 
2.13.6

  parent reply	other threads:[~2019-09-28  0:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-28  0:12 [PATCH v2 01/14] netconfig: Rename netconfig destructor Tim Kourt
2019-09-28  0:12 ` [PATCH v2 02/14] netconfig: Change public API Tim Kourt
2019-09-28  0:12 ` [PATCH v2 03/14] netconfig: Decouple from station state Tim Kourt
2019-09-28  0:12 ` [PATCH v2 04/14] station: netconfig devices based on " Tim Kourt
2019-09-28  0:12 ` [PATCH v2 05/14] netconfig: Switch to internal active network settings Tim Kourt
2019-09-28  0:12 ` [PATCH v2 06/14] rtnlutil: Add parser for IPv6 RTNL packet Tim Kourt
2019-09-28  0:12 ` [PATCH v2 07/14] netconfig: Subscribe for IPv6 address changes Tim Kourt
2019-09-28  0:12 ` [PATCH v2 08/14] rtnlutil: Add IPv6 address dump Tim Kourt
2019-09-28  0:12 ` [PATCH v2 09/14] netconfig: Request all known IPv6 addresses Tim Kourt
2019-09-28  0:12 ` Tim Kourt [this message]
2019-09-28  0:12 ` [PATCH v2 11/14] netconfig: Add IPv6 static address installation/removal Tim Kourt
2019-09-28  0:12 ` [PATCH v2 12/14] rtnlutil: Add IPv6 default route helper Tim Kourt
2019-09-28  0:12 ` [PATCH v2 13/14] netconfig: Install IPv6 default route Tim Kourt
2019-09-28  0:12 ` [PATCH v2 14/14] netconfig: Install IPv6 DNS Tim Kourt

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=20190928001233.19217-10-tim.a.kourt@linux.intel.com \
    --to=tim.a.kourt@linux.intel.com \
    --cc=iwd@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox