Blob Blame History Raw
From 17d3f4f18878ef706008575cd1565745c5936819 Mon Sep 17 00:00:00 2001
From: Gabriele Cerami <gcerami@redhat.com>
Date: Sat, 13 Jun 2020 10:20:23 +0100
Subject: [PATCH 2/3] Honour router_preference for solicited RA

Replies to router solicitation follow a different flow than periodic RA.
This flow currently does not honour the router_preference configuration.

This patch modifies the flow to honour the flag, and send
router-preference indications in the reply RA following RFC4191
specifications

Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=1804576
Signed-off-by: Gabriele Cerami <gcerami@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
---
 AUTHORS.rst         |  1 +
 lib/actions.c       | 29 +++++++++++++++++++++++++++--
 lib/ovn-l7.h        |  5 +++++
 northd/ovn-northd.c |  6 ++++++
 tests/ovn.at        | 26 ++++++++++++++++----------
 5 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/AUTHORS.rst b/AUTHORS.rst
index c80fc1bae..bba0d1d6f 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -145,6 +145,7 @@ Frédéric Tobias Christ             fchrist@live.de
 Frode Nordahl                      frode.nordahl@gmail.com
 FUJITA Tomonori                    fujita.tomonori@lab.ntt.co.jp
 Gabe Beged-Dov                     gabe@begeddov.com
+Gabriele Cerami                    gcerami@redhat.com
 Gaetano Catalli                    gaetano.catalli@gmail.com
 Gal Sagie                          gal.sagie@gmail.com
 Genevieve LEsperance               glesperance@pivotal.io
diff --git a/lib/actions.c b/lib/actions.c
index ee7ccae0d..3181126e6 100644
--- a/lib/actions.c
+++ b/lib/actions.c
@@ -2484,6 +2484,12 @@ parse_put_nd_ra_opts(struct action_context *ctx, const struct expr_field *dst,
             }
             break;
 
+        case ND_RA_FLAG_PRF:
+            ok = (c->string && (!strcmp(c->string, "MEDIUM") ||
+                                !strcmp(c->string, "HIGH") ||
+                                !strcmp(c->string, "LOW")));
+            break;
+
         case ND_OPT_SOURCE_LINKADDR:
             ok = c->format == LEX_F_ETHERNET;
             slla_present = true;
@@ -2538,9 +2544,22 @@ encode_put_nd_ra_option(const struct ovnact_gen_option *o,
     {
         struct ovs_ra_msg *ra = ofpbuf_at(ofpacts, ra_offset, sizeof *ra);
         if (!strcmp(c->string, "dhcpv6_stateful")) {
-            ra->mo_flags = IPV6_ND_RA_FLAG_MANAGED_ADDR_CONFIG;
+            ra->mo_flags |= IPV6_ND_RA_FLAG_MANAGED_ADDR_CONFIG;
         } else if (!strcmp(c->string, "dhcpv6_stateless")) {
-            ra->mo_flags = IPV6_ND_RA_FLAG_OTHER_ADDR_CONFIG;
+            ra->mo_flags |= IPV6_ND_RA_FLAG_OTHER_ADDR_CONFIG;
+        }
+        break;
+    }
+
+    case ND_RA_FLAG_PRF:
+    {
+        struct ovs_ra_msg *ra = ofpbuf_at(ofpacts, ra_offset, sizeof *ra);
+        if (!strcmp(c->string, "LOW")) {
+            ra->mo_flags |= IPV6_ND_RA_OPT_PRF_LOW;
+        } else if (!strcmp(c->string, "HIGH")) {
+            ra->mo_flags |= IPV6_ND_RA_OPT_PRF_HIGH;
+        } else {
+            ra->mo_flags |= IPV6_ND_RA_OPT_PRF_NORMAL;
         }
         break;
     }
@@ -2621,6 +2640,12 @@ encode_PUT_ND_RA_OPTS(const struct ovnact_put_opts *po,
         encode_put_nd_ra_option(o, ofpacts, ra_offset);
     }
 
+    /* RFC4191 section 2.2 */
+    struct ovs_ra_msg *new_ra = ofpbuf_at(ofpacts, ra_offset, sizeof *new_ra);
+    if (ntohs(new_ra->router_lifetime) == 0) {
+        new_ra->mo_flags &= IPV6_ND_RA_OPT_PRF_RESET_MASK;
+    }
+
     encode_finish_controller_op(oc_offset, ofpacts);
 }
 
diff --git a/lib/ovn-l7.h b/lib/ovn-l7.h
index cbea2a0c8..2da38fb65 100644
--- a/lib/ovn-l7.h
+++ b/lib/ovn-l7.h
@@ -304,6 +304,9 @@ nd_ra_opts_destroy(struct hmap *nd_ra_opts)
 
 
 #define ND_RA_FLAG_ADDR_MODE    0
+/* all small numbers seems to be all already taken but nothing guarantees this
+ * code will not be assigned by IANA to another option */
+#define ND_RA_FLAG_PRF          255
 
 
 /* Default values of various IPv6 Neighbor Discovery protocol options and
@@ -325,11 +328,13 @@ nd_ra_opts_destroy(struct hmap *nd_ra_opts)
 #define IPV6_ND_RA_OPT_PRF_NORMAL                   0x00
 #define IPV6_ND_RA_OPT_PRF_HIGH                     0x08
 #define IPV6_ND_RA_OPT_PRF_LOW                      0x18
+#define IPV6_ND_RA_OPT_PRF_RESET_MASK               0xe7
 
 static inline void
 nd_ra_opts_init(struct hmap *nd_ra_opts)
 {
     nd_ra_opt_add(nd_ra_opts, "addr_mode", ND_RA_FLAG_ADDR_MODE, "str");
+    nd_ra_opt_add(nd_ra_opts, "router_preference", ND_RA_FLAG_PRF, "str");
     nd_ra_opt_add(nd_ra_opts, "slla", ND_OPT_SOURCE_LINKADDR, "mac");
     nd_ra_opt_add(nd_ra_opts, "prefix", ND_OPT_PREFIX_INFORMATION, "ipv6");
     nd_ra_opt_add(nd_ra_opts, "mtu", ND_OPT_MTU, "uint32");
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index c1b4c13b7..cffe3de17 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -9408,6 +9408,12 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
             ds_put_format(&actions, ", mtu = %u", mtu);
         }
 
+        const char *prf = smap_get_def(
+            &op->nbrp->ipv6_ra_configs, "router_preference", "MEDIUM");
+        if (strcmp(prf, "MEDIUM")) {
+            ds_put_format(&actions, ", router_preference = \"%s\"", prf);
+        }
+
         bool add_rs_response_flow = false;
 
         for (size_t i = 0; i < op->lrp_networks.n_ipv6_addrs; i++) {
diff --git a/tests/ovn.at b/tests/ovn.at
index 57c1d90e4..d9df393d5 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -1346,14 +1346,14 @@ log(severity=notice);
     Syntax error at `;' expecting verdict.
 
 # put_nd_ra_opts
-reg1[0] = put_nd_ra_opts(addr_mode = "slaac", mtu = 1500, prefix = aef0::/64, slla = ae:01:02:03:04:05);
-    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)
+reg1[0] = put_nd_ra_opts(addr_mode = "slaac", mtu = 1500, router_preference = "HIGH", prefix = aef0::/64, slla = ae:01:02:03:04:05);
+    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)
     has prereqs ip6
-reg1[0] = put_nd_ra_opts(addr_mode = "dhcpv6_stateful", slla = ae:01:02:03:04:10, mtu = 1450);
+reg1[0] = put_nd_ra_opts(addr_mode = "dhcpv6_stateful", router_preference = "MEDIUM", slla = ae:01:02:03:04:10, mtu = 1450);
     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)
     has prereqs ip6
-reg1[0] = put_nd_ra_opts(addr_mode = "dhcpv6_stateless", slla = ae:01:02:03:04:06, prefix = aef0::/64);
-    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)
+reg1[0] = put_nd_ra_opts(addr_mode = "dhcpv6_stateless", router_preference = "LOW", slla = ae:01:02:03:04:06, prefix = aef0::/64);
+    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)
     has prereqs ip6
 reg1[0] = put_nd_ra_opts(addr_mode = "slaac", mtu = 1500, prefix = aef0::/64);
     slla option not present
@@ -10083,13 +10083,16 @@ reset_pcap_file hv1-vif1 hv1/vif1
 reset_pcap_file hv1-vif2 hv1/vif2
 reset_pcap_file hv1-vif3 hv1/vif3
 
-# Set the MTU to 1500
+# Set the MTU to 1500, send_periodic to false, preference to LOW
 ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:mtu=1500
+ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:send_periodic="false"
+ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:router_preference="LOW"
 
 # Make sure that ovn-controller has installed the corresponding OF Flow.
 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"`])
 
-addr_mode=00
+# addr_mode byte also includes router preference information
+addr_mode=18
 default_prefix_option_config=030440c0ffffffffffffffff00000000
 src_mac=fa163e000003
 src_lla=fe80000000000000f8163efffe000003
@@ -10114,12 +10117,14 @@ reset_pcap_file hv1-vif1 hv1/vif1
 reset_pcap_file hv1-vif2 hv1/vif2
 reset_pcap_file hv1-vif3 hv1/vif3
 
-# Set the address mode to dhcpv6_stateful
+# Set the address mode to dhcpv6_stateful, router_preference to HIGH
 ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:address_mode=dhcpv6_stateful
+ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:router_preference="HIGH"
 # Make sure that ovn-controller has installed the corresponding OF Flow.
 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"`])
 
-addr_mode=80
+# addr_mode byte also includes router preference information
+addr_mode=88
 default_prefix_option_config=03044080ffffffffffffffff00000000
 src_mac=fa163e000004
 src_lla=fe80000000000000f8163efffe000004
@@ -10144,8 +10149,9 @@ reset_pcap_file hv1-vif1 hv1/vif1
 reset_pcap_file hv1-vif2 hv1/vif2
 reset_pcap_file hv1-vif3 hv1/vif3
 
-# Set the address mode to dhcpv6_stateless
+# Set the address mode to dhcpv6_stateless, reset router preference to default
 ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:address_mode=dhcpv6_stateless
+ovn-nbctl --wait=hv set Logical_Router_Port lrp0 ipv6_ra_configs:router_preference="MEDIUM"
 # Make sure that ovn-controller has installed the corresponding OF Flow.
 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"`])
 
-- 
2.26.2