[systemd-devel] [PATCH 09/11] sd-icmp6-nd: Add support for fetching the latest expired prefix

Patrik Flykt patrik.flykt at linux.intel.com
Tue Jan 13 04:02:19 PST 2015


Keep the expired prefix for the duration of the prefix expiration event
and remove it afterwards.
---
 src/libsystemd-network/sd-icmp6-nd.c | 23 +++++++++++++++++++++++
 src/systemd/sd-icmp6-nd.h            |  2 ++
 2 files changed, 25 insertions(+)

diff --git a/src/libsystemd-network/sd-icmp6-nd.c b/src/libsystemd-network/sd-icmp6-nd.c
index 4848912..ad9bbdb 100644
--- a/src/libsystemd-network/sd-icmp6-nd.c
+++ b/src/libsystemd-network/sd-icmp6-nd.c
@@ -58,6 +58,7 @@ struct icmp6_link {
         RefCount n_ref;
 
         uint32_t mtu;
+        struct icmp6_prefix *expired_prefix;
         LIST_HEAD(struct icmp6_prefix, prefixes);
 };
 
@@ -305,8 +306,11 @@ static int icmp6_ra_prefix_timeout(sd_event_source *s, uint64_t usec,
 
                 LIST_REMOVE(prefixes, nd->link->prefixes, prefix);
 
+                nd->link->expired_prefix = prefix;
                 icmp6_nd_notify(nd,
                                 ICMP6_EVENT_ROUTER_ADVERTISMENT_PREFIX_EXPIRED);
+                nd->link->expired_prefix = NULL;
+
                 prefix = icmp6_prefix_unref(prefix);
 
                 break;
@@ -419,6 +423,25 @@ int sd_icmp6_ra_get_prefixlen(sd_icmp6_nd *nd, const struct in6_addr *addr,
         return 0;
 }
 
+int sd_icmp6_ra_get_expired_prefix(sd_icmp6_nd *nd, struct in6_addr **addr,
+                                uint8_t *prefixlen)
+{
+        assert_return(nd, -EINVAL);
+        assert_return(addr, -EINVAL);
+        assert_return(prefixlen, -EINVAL);
+
+        if (!nd->link)
+                return -EADDRNOTAVAIL;
+
+        if (!nd->link->expired_prefix)
+                return -EADDRNOTAVAIL;
+
+        *addr = &nd->link->expired_prefix->addr;
+        *prefixlen = nd->link->expired_prefix->len;
+
+        return 0;
+}
+
 static int icmp6_ra_prefix_update(sd_icmp6_nd *nd, ssize_t len,
                                 const struct nd_opt_prefix_info *prefix_opt) {
         int r;
diff --git a/src/systemd/sd-icmp6-nd.h b/src/systemd/sd-icmp6-nd.h
index 9139c06..acb4107 100644
--- a/src/systemd/sd-icmp6-nd.h
+++ b/src/systemd/sd-icmp6-nd.h
@@ -58,6 +58,8 @@ int sd_icmp6_prefix_match(struct in6_addr *prefix, uint8_t prefixlen,
 int sd_icmp6_ra_get_mtu(sd_icmp6_nd *nd, uint32_t *mtu);
 int sd_icmp6_ra_get_prefixlen(sd_icmp6_nd *nd, const struct in6_addr *addr,
                         uint8_t *prefixlen);
+int sd_icmp6_ra_get_expired_prefix(sd_icmp6_nd *nd, struct in6_addr **addr,
+                                uint8_t *prefixlen);
 
 int sd_icmp6_nd_stop(sd_icmp6_nd *nd);
 int sd_icmp6_router_solicitation_start(sd_icmp6_nd *nd);
-- 
2.1.4



More information about the systemd-devel mailing list