bbaaef
From 114ca5e976d46bb7285c993879a2837146701386 Mon Sep 17 00:00:00 2001
bbaaef
Message-Id: <114ca5e976d46bb7285c993879a2837146701386.1593090759.git.lorenzo.bianconi@redhat.com>
bbaaef
From: Gabriele Cerami <gcerami@redhat.com>
bbaaef
Date: Sat, 13 Jun 2020 10:20:23 +0100
bbaaef
Subject: [PATCH] Honour router_preference for solicited RA
bbaaef
bbaaef
Replies to router solicitation follow a different flow than periodic RA.
bbaaef
This flow currently does not honour the router_preference configuration.
bbaaef
bbaaef
This patch modifies the flow to honour the flag, and send
bbaaef
router-preference indications in the reply RA following RFC4191
bbaaef
specifications
bbaaef
bbaaef
Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=1804576
bbaaef
Signed-off-by: Gabriele Cerami <gcerami@redhat.com>
bbaaef
Signed-off-by: Numan Siddique <numans@ovn.org>
bbaaef
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
bbaaef
---
bbaaef
 AUTHORS.rst             |  1 +
bbaaef
 ovn/lib/actions.c       | 29 +++++++++++++++++++++++++++--
bbaaef
 ovn/lib/ovn-l7.h        |  5 +++++
bbaaef
 ovn/northd/ovn-northd.c |  6 ++++++
bbaaef
 tests/ovn.at            | 26 ++++++++++++++++----------
bbaaef
 5 files changed, 55 insertions(+), 12 deletions(-)
bbaaef
bbaaef
--- a/AUTHORS.rst
bbaaef
+++ b/AUTHORS.rst
bbaaef
@@ -145,6 +145,7 @@ Frédéric Tobias Christ             fch
bbaaef
 Frode Nordahl                      frode.nordahl@gmail.com
bbaaef
 FUJITA Tomonori                    fujita.tomonori@lab.ntt.co.jp
bbaaef
 Gabe Beged-Dov                     gabe@begeddov.com
bbaaef
+Gabriele Cerami                    gcerami@redhat.com
bbaaef
 Gaetano Catalli                    gaetano.catalli@gmail.com
bbaaef
 Gal Sagie                          gal.sagie@gmail.com
bbaaef
 Genevieve LEsperance               glesperance@pivotal.io
bbaaef
--- a/ovn/lib/actions.c
bbaaef
+++ b/ovn/lib/actions.c
bbaaef
@@ -2298,6 +2298,12 @@ parse_put_nd_ra_opts(struct action_conte
bbaaef
             }
bbaaef
             break;
bbaaef
 
bbaaef
+        case ND_RA_FLAG_PRF:
bbaaef
+            ok = (c->string && (!strcmp(c->string, "MEDIUM") ||
bbaaef
+                                !strcmp(c->string, "HIGH") ||
bbaaef
+                                !strcmp(c->string, "LOW")));
bbaaef
+            break;
bbaaef
+
bbaaef
         case ND_OPT_SOURCE_LINKADDR:
bbaaef
             ok = c->format == LEX_F_ETHERNET;
bbaaef
             slla_present = true;
bbaaef
@@ -2352,9 +2358,22 @@ encode_put_nd_ra_option(const struct ovn
bbaaef
     {
bbaaef
         struct ovs_ra_msg *ra = ofpbuf_at(ofpacts, ra_offset, sizeof *ra);
bbaaef
         if (!strcmp(c->string, "dhcpv6_stateful")) {
bbaaef
-            ra->mo_flags = IPV6_ND_RA_FLAG_MANAGED_ADDR_CONFIG;
bbaaef
+            ra->mo_flags |= IPV6_ND_RA_FLAG_MANAGED_ADDR_CONFIG;
bbaaef
         } else if (!strcmp(c->string, "dhcpv6_stateless")) {
bbaaef
-            ra->mo_flags = IPV6_ND_RA_FLAG_OTHER_ADDR_CONFIG;
bbaaef
+            ra->mo_flags |= IPV6_ND_RA_FLAG_OTHER_ADDR_CONFIG;
bbaaef
+        }
bbaaef
+        break;
bbaaef
+    }
bbaaef
+
bbaaef
+    case ND_RA_FLAG_PRF:
bbaaef
+    {
bbaaef
+        struct ovs_ra_msg *ra = ofpbuf_at(ofpacts, ra_offset, sizeof *ra);
bbaaef
+        if (!strcmp(c->string, "LOW")) {
bbaaef
+            ra->mo_flags |= IPV6_ND_RA_OPT_PRF_LOW;
bbaaef
+        } else if (!strcmp(c->string, "HIGH")) {
bbaaef
+            ra->mo_flags |= IPV6_ND_RA_OPT_PRF_HIGH;
bbaaef
+        } else {
bbaaef
+            ra->mo_flags |= IPV6_ND_RA_OPT_PRF_NORMAL;
bbaaef
         }
bbaaef
         break;
bbaaef
     }
bbaaef
@@ -2435,6 +2454,12 @@ encode_PUT_ND_RA_OPTS(const struct ovnac
bbaaef
         encode_put_nd_ra_option(o, ofpacts, ra_offset);
bbaaef
     }
bbaaef
 
bbaaef
+    /* RFC4191 section 2.2 */
bbaaef
+    struct ovs_ra_msg *new_ra = ofpbuf_at(ofpacts, ra_offset, sizeof *new_ra);
bbaaef
+    if (ntohs(new_ra->router_lifetime) == 0) {
bbaaef
+        new_ra->mo_flags &= IPV6_ND_RA_OPT_PRF_RESET_MASK;
bbaaef
+    }
bbaaef
+
bbaaef
     encode_finish_controller_op(oc_offset, ofpacts);
bbaaef
 }
bbaaef
 
bbaaef
--- a/ovn/lib/ovn-l7.h
bbaaef
+++ b/ovn/lib/ovn-l7.h
bbaaef
@@ -295,6 +295,9 @@ nd_ra_opts_destroy(struct hmap *nd_ra_op
bbaaef
 
bbaaef
 
bbaaef
 #define ND_RA_FLAG_ADDR_MODE    0
bbaaef
+/* all small numbers seems to be all already taken but nothing guarantees this
bbaaef
+ * code will not be assigned by IANA to another option */
bbaaef
+#define ND_RA_FLAG_PRF          255
bbaaef
 
bbaaef
 
bbaaef
 /* Default values of various IPv6 Neighbor Discovery protocol options and
bbaaef
@@ -316,11 +319,13 @@ nd_ra_opts_destroy(struct hmap *nd_ra_op
bbaaef
 #define IPV6_ND_RA_OPT_PRF_NORMAL                   0x00
bbaaef
 #define IPV6_ND_RA_OPT_PRF_HIGH                     0x08
bbaaef
 #define IPV6_ND_RA_OPT_PRF_LOW                      0x18
bbaaef
+#define IPV6_ND_RA_OPT_PRF_RESET_MASK               0xe7
bbaaef
 
bbaaef
 static inline void
bbaaef
 nd_ra_opts_init(struct hmap *nd_ra_opts)
bbaaef
 {
bbaaef
     nd_ra_opt_add(nd_ra_opts, "addr_mode", ND_RA_FLAG_ADDR_MODE, "str");
bbaaef
+    nd_ra_opt_add(nd_ra_opts, "router_preference", ND_RA_FLAG_PRF, "str");
bbaaef
     nd_ra_opt_add(nd_ra_opts, "slla", ND_OPT_SOURCE_LINKADDR, "mac");
bbaaef
     nd_ra_opt_add(nd_ra_opts, "prefix", ND_OPT_PREFIX_INFORMATION, "ipv6");
bbaaef
     nd_ra_opt_add(nd_ra_opts, "mtu", ND_OPT_MTU, "uint32");
bbaaef
--- a/ovn/northd/ovn-northd.c
bbaaef
+++ b/ovn/northd/ovn-northd.c
bbaaef
@@ -8551,6 +8551,12 @@ build_lrouter_flows(struct hmap *datapat
bbaaef
             ds_put_format(&actions, ", mtu = %u", mtu);
bbaaef
         }
bbaaef
 
bbaaef
+        const char *prf = smap_get_def(
bbaaef
+            &op->nbrp->ipv6_ra_configs, "router_preference", "MEDIUM");
bbaaef
+        if (strcmp(prf, "MEDIUM")) {
bbaaef
+            ds_put_format(&actions, ", router_preference = \"%s\"", prf);
bbaaef
+        }
bbaaef
+
bbaaef
         bool add_rs_response_flow = false;
bbaaef
 
bbaaef
         for (size_t i = 0; i < op->lrp_networks.n_ipv6_addrs; i++) {
bbaaef
--- a/tests/ovn.at
bbaaef
+++ b/tests/ovn.at
bbaaef
@@ -1326,14 +1326,14 @@ log(severity=notice);
bbaaef
     Syntax error at `;' expecting verdict.
bbaaef
 
bbaaef
 # put_nd_ra_opts
bbaaef
-reg1[0] = put_nd_ra_opts(addr_mode = "slaac", mtu = 1500, prefix = aef0::/64, slla = ae:01:02:03:04:05);
bbaaef
-    encodes as controller(userdata=00.00.00.08.00.00.00.00.00.01.de.10.00.00.00.40.86.00.00.00.ff.00.ff.ff.00.00.00.00.00.00.00.00.05.01.00.00.00.00.05.dc.03.04.40.c0.ff.ff.ff.ff.ff.ff.ff.ff.00.00.00.00.ae.f0.00.00.00.00.00.00.00.00.00.00.00.00.00.00.01.01.ae.01.02.03.04.05,pause)
bbaaef
+reg1[0] = put_nd_ra_opts(addr_mode = "slaac", mtu = 1500, router_preference = "HIGH", prefix = aef0::/64, slla = ae:01:02:03:04:05);
bbaaef
+    encodes as controller(userdata=00.00.00.08.00.00.00.00.00.01.de.10.00.00.00.40.86.00.00.00.ff.08.ff.ff.00.00.00.00.00.00.00.00.05.01.00.00.00.00.05.dc.03.04.40.c0.ff.ff.ff.ff.ff.ff.ff.ff.00.00.00.00.ae.f0.00.00.00.00.00.00.00.00.00.00.00.00.00.00.01.01.ae.01.02.03.04.05,pause)
bbaaef
     has prereqs ip6
bbaaef
-reg1[0] = put_nd_ra_opts(addr_mode = "dhcpv6_stateful", slla = ae:01:02:03:04:10, mtu = 1450);
bbaaef
+reg1[0] = put_nd_ra_opts(addr_mode = "dhcpv6_stateful", router_preference = "MEDIUM", slla = ae:01:02:03:04:10, mtu = 1450);
bbaaef
     encodes as controller(userdata=00.00.00.08.00.00.00.00.00.01.de.10.00.00.00.40.86.00.00.00.ff.80.ff.ff.00.00.00.00.00.00.00.00.01.01.ae.01.02.03.04.10.05.01.00.00.00.00.05.aa,pause)
bbaaef
     has prereqs ip6
bbaaef
-reg1[0] = put_nd_ra_opts(addr_mode = "dhcpv6_stateless", slla = ae:01:02:03:04:06, prefix = aef0::/64);
bbaaef
-    encodes as controller(userdata=00.00.00.08.00.00.00.00.00.01.de.10.00.00.00.40.86.00.00.00.ff.40.ff.ff.00.00.00.00.00.00.00.00.01.01.ae.01.02.03.04.06.03.04.40.c0.ff.ff.ff.ff.ff.ff.ff.ff.00.00.00.00.ae.f0.00.00.00.00.00.00.00.00.00.00.00.00.00.00,pause)
bbaaef
+reg1[0] = put_nd_ra_opts(addr_mode = "dhcpv6_stateless", router_preference = "LOW", slla = ae:01:02:03:04:06, prefix = aef0::/64);
bbaaef
+    encodes as controller(userdata=00.00.00.08.00.00.00.00.00.01.de.10.00.00.00.40.86.00.00.00.ff.58.ff.ff.00.00.00.00.00.00.00.00.01.01.ae.01.02.03.04.06.03.04.40.c0.ff.ff.ff.ff.ff.ff.ff.ff.00.00.00.00.ae.f0.00.00.00.00.00.00.00.00.00.00.00.00.00.00,pause)
bbaaef
     has prereqs ip6
bbaaef
 reg1[0] = put_nd_ra_opts(addr_mode = "slaac", mtu = 1500, prefix = aef0::/64);
bbaaef
     slla option not present
bbaaef
@@ -10075,13 +10075,16 @@ reset_pcap_file hv1-vif1 hv1/vif1
bbaaef
 reset_pcap_file hv1-vif2 hv1/vif2
bbaaef
 reset_pcap_file hv1-vif3 hv1/vif3
bbaaef
 
bbaaef
-# Set the MTU to 1500
bbaaef
+# Set the MTU to 1500, send_periodic to false, preference to LOW
bbaaef
 ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:mtu=1500
bbaaef
+ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:send_periodic="false"
bbaaef
+ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:router_preference="LOW"
bbaaef
 
bbaaef
 # Make sure that ovn-controller has installed the corresponding OF Flow.
bbaaef
 OVS_WAIT_UNTIL([test 1 = `as hv1 ovs-ofctl dump-flows br-int | grep -c "ipv6_dst=ff02::2,nw_ttl=255,icmp_type=133,icmp_code=0"`])
bbaaef
 
bbaaef
-addr_mode=00
bbaaef
+# addr_mode byte also includes router preference information
bbaaef
+addr_mode=18
bbaaef
 default_prefix_option_config=030440c0ffffffffffffffff00000000
bbaaef
 src_mac=fa163e000003
bbaaef
 src_lla=fe80000000000000f8163efffe000003
bbaaef
@@ -10106,12 +10109,14 @@ reset_pcap_file hv1-vif1 hv1/vif1
bbaaef
 reset_pcap_file hv1-vif2 hv1/vif2
bbaaef
 reset_pcap_file hv1-vif3 hv1/vif3
bbaaef
 
bbaaef
-# Set the address mode to dhcpv6_stateful
bbaaef
+# Set the address mode to dhcpv6_stateful, router_preference to HIGH
bbaaef
 ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:address_mode=dhcpv6_stateful
bbaaef
+ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:router_preference="HIGH"
bbaaef
 # Make sure that ovn-controller has installed the corresponding OF Flow.
bbaaef
 OVS_WAIT_UNTIL([test 1 = `as hv1 ovs-ofctl dump-flows br-int | grep -c "ipv6_dst=ff02::2,nw_ttl=255,icmp_type=133,icmp_code=0"`])
bbaaef
 
bbaaef
-addr_mode=80
bbaaef
+# addr_mode byte also includes router preference information
bbaaef
+addr_mode=88
bbaaef
 default_prefix_option_config=03044080ffffffffffffffff00000000
bbaaef
 src_mac=fa163e000004
bbaaef
 src_lla=fe80000000000000f8163efffe000004
bbaaef
@@ -10136,8 +10141,9 @@ reset_pcap_file hv1-vif1 hv1/vif1
bbaaef
 reset_pcap_file hv1-vif2 hv1/vif2
bbaaef
 reset_pcap_file hv1-vif3 hv1/vif3
bbaaef
 
bbaaef
-# Set the address mode to dhcpv6_stateless
bbaaef
+# Set the address mode to dhcpv6_stateless, reset router preference to default
bbaaef
 ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:address_mode=dhcpv6_stateless
bbaaef
+ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:router_preference="MEDIUM"
bbaaef
 # Make sure that ovn-controller has installed the corresponding OF Flow.
bbaaef
 OVS_WAIT_UNTIL([test 1 = `as hv1 ovs-ofctl dump-flows br-int | grep -c "ipv6_dst=ff02::2,nw_ttl=255,icmp_type=133,icmp_code=0"`])
bbaaef