]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Linux: Note router preference when adding routes
authorRoy Marples <roy@marples.name>
Thu, 9 Apr 2020 16:19:07 +0000 (16:19 +0000)
committerRoy Marples <roy@marples.name>
Thu, 9 Apr 2020 16:19:07 +0000 (16:19 +0000)
This appears to just be cosmetic.

src/if-linux.c
src/ipv6.c
src/ipv6nd.c
src/ipv6nd.h
src/route.c
src/route.h

index 8b8fe97322c656b497ee059756ba6e541cbe44b4..d139af43483027c1e99a9d3142c73259f73dd812 100644 (file)
@@ -34,6 +34,7 @@
 #include <sys/param.h>
 #include <sys/stat.h>
 
+#include <linux/icmpv6.h>
 #include <linux/if_addr.h>
 #include <linux/if_link.h>
 #include <linux/if_packet.h>
@@ -1061,6 +1062,14 @@ add_attr_l(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
        return 0;
 }
 
+static int
+add_attr_8(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
+    uint8_t data)
+{
+
+       return add_attr_l(n, maxlen, type, &data, sizeof(data));
+}
+
 static int
 add_attr_32(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
     uint32_t data)
@@ -1504,6 +1513,26 @@ if_route(unsigned char cmd, const struct rt *rt)
                            RTA_DATA(metrics),
                            (unsigned short)RTA_PAYLOAD(metrics));
                }
+
+               if (rt->rt_dflags & RTDF_RA) {
+                       uint8_t pref;
+
+                       switch(rt->rt_pref) {
+                       case RTPREF_LOW:
+                               pref = ICMPV6_ROUTER_PREF_LOW;
+                               break;
+                       case RTPREF_MEDIUM:
+                               pref = ICMPV6_ROUTER_PREF_MEDIUM;
+                               break;
+                       case RTPREF_HIGH:
+                               pref = ICMPV6_ROUTER_PREF_HIGH;
+                               break;
+                       default:
+                               pref = ICMPV6_ROUTER_PREF_INVALID;
+                               break;
+                       }
+                       add_attr_8(&nlm.hdr, sizeof(nlm), RTA_PREF, pref);
+               }
        }
 
        if (!sa_is_loopback(&rt->rt_gateway))
@@ -1878,14 +1907,6 @@ struct nlml
        char buffer[32];
 };
 
-static int
-add_attr_8(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
-    uint8_t data)
-{
-
-       return add_attr_l(n, maxlen, type, &data, sizeof(data));
-}
-
 static struct rtattr *
 add_attr_nest(struct nlmsghdr *n, unsigned short maxlen, unsigned short type)
 {
index ede87c3df29332ff93f93797c1da6f970f748e94..570879ae50c52cedb4f43aac2cd9e2ea0aa0d299 100644 (file)
@@ -2253,6 +2253,9 @@ inet6_raroutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx)
                        rt = inet6_makeprefix(rap->iface, rap, addr);
                        if (rt) {
                                rt->rt_dflags |= RTDF_RA;
+#ifdef HAVE_ROUTE_PREF
+                               rt->rt_pref = ipv6nd_rtpref(rap);
+#endif
                                rt_proto_add(routes, rt);
                        }
                }
@@ -2264,6 +2267,9 @@ inet6_raroutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx)
                if (rt == NULL)
                        continue;
                rt->rt_dflags |= RTDF_RA;
+#ifdef HAVE_ROUTE_PREF
+               rt->rt_pref = ipv6nd_rtpref(rap);
+#endif
                rt_proto_add(routes, rt);
        }
        return 0;
index 2860e67ce1b1a7d0be07ad96356b99fe4b6babfe..7ce34001c21b78227e86ca1913741651d340faa1 100644 (file)
@@ -101,13 +101,6 @@ __CTASSERT(sizeof(struct nd_opt_rdnss) == 8);
 #define ND_RA_FLAG_RTPREF_RSV          0x10
 #endif
 
-/* RTPREF_MEDIUM has to be 0! */
-#define RTPREF_HIGH    1
-#define RTPREF_MEDIUM  0
-#define RTPREF_LOW     (-1)
-#define RTPREF_RESERVED        (-2)
-#define RTPREF_INVALID (-3)    /* internal */
-
 #define        EXPIRED_MAX     5       /* Remember 5 expired routers to avoid
                                   logspam. */
 
@@ -580,7 +573,7 @@ ipv6nd_startexpire(struct interface *ifp)
            RTR_CARRIER_EXPIRE, ipv6nd_expire, ifp);
 }
 
-static int
+int
 ipv6nd_rtpref(struct ra *rap)
 {
 
index bb14d7b34d59a82e24a396f1ea04123db20ad73e..8d61699996d8cf70b316a88f7b76ffff31a18329 100644 (file)
@@ -104,6 +104,7 @@ int ipv6nd_open(struct interface *);
 int ipv6nd_open(struct dhcpcd_ctx *);
 #endif
 void ipv6nd_recvmsg(struct dhcpcd_ctx *, struct msghdr *);
+int ipv6nd_rtpref(struct ra *);
 void ipv6nd_printoptions(const struct dhcpcd_ctx *,
     const struct dhcp_opt *, size_t);
 void ipv6nd_startrs(struct interface *);
index 401ce07c6ff82ebe3b0d8eca528566d7bd01474d..125c9532e36a23d3c6c44f64e82244310e007510 100644 (file)
@@ -349,11 +349,8 @@ rt_new0(struct dhcpcd_ctx *ctx)
 #endif
        } else
 #endif
-       if ((rt = malloc(sizeof(*rt))) == NULL) {
+       if ((rt = calloc(1, sizeof(*rt))) == NULL)
                logerr(__func__);
-               return NULL;
-       }
-       memset(rt, 0, sizeof(*rt));
        return rt;
 }
 
index 629fb20073d985452acf6b1e528e46ea13fa615e..a061497c14a573c078b45ac048bc6d203a4166ff 100644 (file)
 # endif
 #endif
 
+#ifdef __linux__
+# define HAVE_ROUTE_PREF
+#endif
+
 #if defined(__OpenBSD__) || defined (__sun)
 #  define ROUTE_PER_GATEWAY
 /* XXX dhcpcd doesn't really support this yet.
@@ -86,6 +90,14 @@ struct rt {
 #ifdef HAVE_ROUTE_METRIC
        unsigned int            rt_metric;
 #endif
+#ifdef HAVE_ROUTE_PREF
+       int                     rt_pref;
+#endif
+#define RTPREF_HIGH    1
+#define RTPREF_MEDIUM  0       /* has to be zero */
+#define RTPREF_LOW     (-1)
+#define RTPREF_RESERVED        (-2)
+#define RTPREF_INVALID (-3)    /* internal */
        unsigned int            rt_dflags;
 #define        RTDF_IFA_ROUTE          0x02            /* Address generated route */
 #define        RTDF_FAKE               0x04            /* Maybe us on lease reboot  */