From: Tim Kourt <tim.a.kourt@linux.intel.com>
To: iwd@lists.01.org
Subject: [PATCH v4 4/5] netconfig: Install IPv6 default route
Date: Tue, 01 Oct 2019 16:44:24 -0700 [thread overview]
Message-ID: <20191001234425.22913-4-tim.a.kourt@linux.intel.com> (raw)
In-Reply-To: <20191001234425.22913-1-tim.a.kourt@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 2535 bytes --]
---
src/netconfig.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 70 insertions(+), 1 deletion(-)
diff --git a/src/netconfig.c b/src/netconfig.c
index 7d26acb0..129fe518 100644
--- a/src/netconfig.c
+++ b/src/netconfig.c
@@ -289,6 +289,40 @@ proceed:
return NULL;
}
+static char *netconfig_ipv6_get_gateway(struct netconfig *netconfig)
+{
+ struct in6_addr in6_addr;
+ char *gateway;
+
+ switch (netconfig->rtm_v6_protocol) {
+ case RTPROT_STATIC:
+ if (!netconfig->active_settings)
+ return NULL;
+
+ gateway = l_settings_get_string(netconfig->active_settings,
+ "IPv6", "gateway");
+
+ if (inet_pton(AF_INET6, gateway, &in6_addr) < 1) {
+ l_error("netconfig: Invalid IPv6 gateway address %s is "
+ "provided in network configuration file.",
+ gateway);
+
+ l_free(gateway);
+
+ return NULL;
+ }
+
+ return gateway;
+
+ case RTPROT_DHCP:
+ /* TODO */
+
+ return NULL;
+ }
+
+ return NULL;
+}
+
static bool netconfig_ifaddr_match(const void *a, const void *b)
{
const struct netconfig_ifaddr *entry = a;
@@ -606,17 +640,52 @@ done:
netconfig_ifaddr_destroy(ifaddr);
}
+static bool netconfig_ipv6_routes_install(struct netconfig *netconfig)
+{
+ L_AUTO_FREE_VAR(char *, gateway) = NULL;
+
+ gateway = netconfig_ipv6_get_gateway(netconfig);
+ if (!gateway) {
+ l_error("netconfig: Failed to obtain gateway from %s.",
+ netconfig->rtm_v6_protocol == RTPROT_STATIC ?
+ "settings file" : "DHCPv6 lease");
+
+ return false;
+ }
+
+ if (!rtnl_route_ipv6_add_gateway(rtnl, netconfig->ifindex, gateway,
+ ROUTE_PRIORITY_OFFSET,
+ netconfig->rtm_v6_protocol,
+ netconfig_route_cmd_cb,
+ NULL, NULL)) {
+ l_error("netconfig: Failed to add route for: %s gateway.",
+ gateway);
+
+ return false;
+ }
+
+ return true;
+}
+
static void netconfig_ipv6_ifaddr_add_cmd_cb(int error, uint16_t type,
const void *data, uint32_t len,
void *user_data)
{
+ struct netconfig *netconfig = user_data;
+
if (error && error != -EEXIST) {
l_error("netconfig: Failed to add IPv6 address. "
"Error %d: %s", error, strerror(-error));
return;
}
- /* TODO Install routes and DNS */
+ if (!netconfig_ipv6_routes_install(netconfig)) {
+ l_error("netconfig: Failed to install IPv6 routes.");
+
+ return;
+ }
+
+ /* TODO Install DNS */
}
static void netconfig_install_address(struct netconfig *netconfig,
--
2.13.6
next prev parent reply other threads:[~2019-10-01 23:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-01 23:44 [PATCH v4 1/5] netconfig: Subscribe for IPv6 address changes Tim Kourt
2019-10-01 23:44 ` [PATCH v4 2/5] netconfig: Request all known IPv6 addresses Tim Kourt
2019-10-01 23:44 ` [PATCH v4 3/5] netconfig: Add IPv6 static address installation/removal Tim Kourt
2019-10-02 17:08 ` Denis Kenzior
2019-10-01 23:44 ` Tim Kourt [this message]
2019-10-02 17:12 ` [PATCH v4 4/5] netconfig: Install IPv6 default route Denis Kenzior
2019-10-01 23:44 ` [PATCH v4 5/5] netconfig: Install IPv6 DNS Tim Kourt
2019-10-02 17:14 ` Denis Kenzior
2019-10-02 17:03 ` [PATCH v4 1/5] netconfig: Subscribe for IPv6 address changes 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=20191001234425.22913-4-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