]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-icmp6-nd: Add helper function to get the IPv6 link MTU
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 20 Jan 2015 17:35:59 +0000 (19:35 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 27 Jan 2015 07:35:24 +0000 (09:35 +0200)
Update MTU according to the latest value received.

src/libsystemd-network/sd-icmp6-nd.c
src/systemd/sd-icmp6-nd.h

index 85b8ff93c57ff0596dfb8f488788379c7ca12198..8b567e3a5c73bfac2a5b550e5270267ca6bfeef8 100644 (file)
@@ -237,6 +237,18 @@ 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->mtu == 0)
+                return -ENOMSG;
+
+        *mtu = nd->mtu;
+
+        return 0;
+}
+
 static int icmp6_ra_parse(sd_icmp6_nd *nd, struct nd_router_advert *ra,
                           ssize_t len) {
         void *opt;
@@ -256,11 +268,26 @@ static int icmp6_ra_parse(sd_icmp6_nd *nd, struct nd_router_advert *ra,
         opt_hdr = opt;
 
         while (len != 0 && len >= opt_hdr->nd_opt_len * ICMP6_OPT_LEN_UNITS) {
+                struct nd_opt_mtu *opt_mtu;
+                uint32_t mtu;
 
                 if (opt_hdr->nd_opt_len == 0)
                         return -ENOMSG;
 
                 switch (opt_hdr->nd_opt_type) {
+                case ND_OPT_MTU:
+                        opt_mtu = opt;
+
+                        mtu = be32toh(opt_mtu->nd_opt_mtu_mtu);
+
+                        if (mtu != nd->mtu) {
+                                nd->mtu = MAX(mtu, IP6_MIN_MTU);
+
+                                log_icmp6_nd(nd, "Router Advertisement link MTU %d using %d",
+                                             mtu, nd->mtu);
+                        }
+
+                        break;
 
                 }
 
index 73f91aad1b99e4375d97b49bf2244c872465e1f2..73ebccfeddf1f7ffa2ec861009b2f9dea73f089b 100644 (file)
@@ -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);