[systemd-devel] [PATCH 05/11] sd-icmp6-nd: Add helper function to get the IPv6 link MTU

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


Update MTU according to the latest value received.
---
 src/libsystemd-network/sd-icmp6-nd.c | 30 ++++++++++++++++++++++++++++++
 src/systemd/sd-icmp6-nd.h            |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/src/libsystemd-network/sd-icmp6-nd.c b/src/libsystemd-network/sd-icmp6-nd.c
index 35d5f5f..3501055 100644
--- a/src/libsystemd-network/sd-icmp6-nd.c
+++ b/src/libsystemd-network/sd-icmp6-nd.c
@@ -271,10 +271,24 @@ int sd_icmp6_nd_new(sd_icmp6_nd **ret) {
         return 0;
 }
 
+int sd_icmp6_ra_get_mtu(sd_icmp6_nd *nd, uint32_t *mtu) {
+        assert_return(nd, -EINVAL);
+        assert_return(mtu, -EINVAL);
+
+        if (!nd->link || !nd->link->mtu)
+                return -ENOMSG;
+
+        *mtu = nd->link->mtu;
+
+        return 0;
+}
+
 static int icmp6_ra_parse(sd_icmp6_nd *nd, struct nd_router_advert *ra,
                         ssize_t len) {
         void *opt;
         struct nd_opt_hdr *opt_hdr;
+        struct nd_opt_mtu *opt_mtu;
+        uint32_t mtu;
 
         assert_return(nd, -EINVAL);
         assert_return(nd->link, -EINVAL);
@@ -293,6 +307,22 @@ static int icmp6_ra_parse(sd_icmp6_nd *nd, struct nd_router_advert *ra,
                         return -ENOMSG;
 
                 switch (opt_hdr->nd_opt_type) {
+                case ND_OPT_MTU:
+                        opt_mtu = opt;
+
+                        mtu = be32toh(opt_mtu->nd_opt_mtu_mtu);
+
+                        if (!nd->link->mtu || mtu < nd->link->mtu) {
+                                if (mtu < IP6_MIN_MTU)
+                                        nd->link->mtu = IP6_MIN_MTU;
+                                else
+                                        nd->link->mtu = mtu;
+
+                                log_icmp6_nd(nd, "Link MTU %d advertised %d",
+                                        nd->link->mtu, mtu);
+                        }
+
+                        break;
 
                 }
 
diff --git a/src/systemd/sd-icmp6-nd.h b/src/systemd/sd-icmp6-nd.h
index 73f91aa..73ebccf 100644
--- a/src/systemd/sd-icmp6-nd.h
+++ b/src/systemd/sd-icmp6-nd.h
@@ -51,6 +51,8 @@ sd_icmp6_nd *sd_icmp6_nd_ref(sd_icmp6_nd *nd);
 sd_icmp6_nd *sd_icmp6_nd_unref(sd_icmp6_nd *nd);
 int sd_icmp6_nd_new(sd_icmp6_nd **ret);
 
+int sd_icmp6_ra_get_mtu(sd_icmp6_nd *nd, uint32_t *mtu);
+
 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