Blob Blame History Raw
From 5dcb7ee1b36aa4a906f09a95479586f917d893c8 Mon Sep 17 00:00:00 2001
Message-Id: <5dcb7ee1b36aa4a906f09a95479586f917d893c8.1575382494.git.lorenzo.bianconi@redhat.com>
In-Reply-To: <d7b024a24ee249c3ce6bf593499fdb6a79d78706.1575382494.git.lorenzo.bianconi@redhat.com>
References: <d7b024a24ee249c3ce6bf593499fdb6a79d78706.1575382494.git.lorenzo.bianconi@redhat.com>
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Date: Thu, 28 Nov 2019 14:48:36 +0200
Subject: [PATCH 2/2] Add support for Route Info Option in RA - RFC 4191

Introduce support for Route Info Option sent in Router
Advertisement according to RFC 4191. Route Info Option are
configured providing route_info in ipv6_ra_configs column of
Logical_Router_Port table. route_info is a comma separated string
where each field provides PRF and prefix for a given route
(e.g: HIGH-aef1::11/48,LOW-aef2::11/96)

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
---
 ovn/controller/pinctrl.c | 80 ++++++++++++++++++++++++++++++++++++++++
 ovn/lib/ovn-l7.h         | 12 ++++++
 ovn/northd/ovn-northd.c  |  6 +++
 ovn/ovn-nb.xml           | 14 +++++++
 tests/ovn.at             | 32 ++++++++++------
 5 files changed, 133 insertions(+), 11 deletions(-)

--- a/ovn/controller/pinctrl.c
+++ b/ovn/controller/pinctrl.c
@@ -2199,6 +2199,7 @@ struct ipv6_ra_config {
     struct in6_addr rdnss;
     bool has_rdnss;
     struct ds dnssl;
+    struct ds route_info;
 };
 
 struct ipv6_ra_state {
@@ -2221,6 +2222,7 @@ ipv6_ra_config_delete(struct ipv6_ra_con
     if (config) {
         destroy_lport_addresses(&config->prefixes);
         ds_destroy(&config->dnssl);
+        ds_destroy(&config->route_info);
         free(config);
     }
 }
@@ -2260,6 +2262,7 @@ ipv6_ra_update_config(const struct sbrec
     config->mtu = smap_get_int(&pb->options, "ipv6_ra_mtu", ND_MTU_DEFAULT);
     config->la_flags = IPV6_ND_RA_OPT_PREFIX_ON_LINK;
     ds_init(&config->dnssl);
+    ds_init(&config->route_info);
 
     const char *address_mode = smap_get(&pb->options, "ipv6_ra_address_mode");
     if (!address_mode) {
@@ -2317,6 +2320,11 @@ ipv6_ra_update_config(const struct sbrec
         ds_put_buffer(&config->dnssl, dnssl, strlen(dnssl));
     }
 
+    const char *route_info = smap_get(&pb->options, "ipv6_ra_route_info");
+    if (route_info) {
+        ds_put_buffer(&config->route_info, route_info, strlen(route_info));
+    }
+
     return config;
 
 fail:
@@ -2424,6 +2432,74 @@ packet_put_ra_dnssl_opt(struct dp_packet
                                                       prev_l4_size + size));
 }
 
+static void
+packet_put_ra_route_info_opt(struct dp_packet *b, ovs_be32 lifetime,
+                             char *route_list)
+{
+    size_t prev_l4_size = dp_packet_l4_size(b);
+    struct ip6_hdr *nh = dp_packet_l3(b);
+    char *t0, *r0 = NULL;
+    size_t size = 0;
+
+    for (t0 = strtok_r(route_list, ",", &r0); t0;
+         t0 = strtok_r(NULL, ",", &r0)) {
+        struct ovs_nd_route_info nd_rinfo;
+        char *t1, *r1 = NULL;
+        int index;
+
+        for (t1 = strtok_r(t0, "-", &r1), index = 0; t1;
+             t1 = strtok_r(NULL, "-", &r1), index++) {
+
+            nd_rinfo.type = ND_OPT_ROUTE_INFO;
+            nd_rinfo.route_lifetime = lifetime;
+
+            switch (index) {
+            case 0:
+                if (!strcmp(t1, "HIGH")) {
+                    nd_rinfo.flags = IPV6_ND_RA_OPT_PRF_HIGH;
+                } else if (!strcmp(t1, "LOW")) {
+                    nd_rinfo.flags = IPV6_ND_RA_OPT_PRF_LOW;
+                } else {
+                    nd_rinfo.flags = IPV6_ND_RA_OPT_PRF_NORMAL;
+                }
+                break;
+            case 1: {
+                struct lport_addresses route;
+                uint8_t plen;
+
+                if (!extract_ip_addresses(t1, &route)) {
+                    return;
+                }
+                if (!route.n_ipv6_addrs) {
+                    destroy_lport_addresses(&route);
+                    return;
+                }
+
+                nd_rinfo.prefix_len = route.ipv6_addrs->plen;
+                plen = DIV_ROUND_UP(nd_rinfo.prefix_len, 64);
+                nd_rinfo.len = 1 + plen;
+                dp_packet_put(b, &nd_rinfo, sizeof(struct ovs_nd_route_info));
+                dp_packet_put(b, &route.ipv6_addrs->network, plen * 8);
+                size += sizeof(struct ovs_nd_route_info) + plen * 8;
+
+                destroy_lport_addresses(&route);
+                index = 0;
+                break;
+            }
+            default:
+                return;
+            }
+        }
+    }
+
+    nh->ip6_plen = htons(prev_l4_size + size);
+    struct ovs_ra_msg *ra = dp_packet_l4(b);
+    ra->icmph.icmp6_cksum = 0;
+    uint32_t icmp_csum = packet_csum_pseudoheader6(dp_packet_l3(b));
+    ra->icmph.icmp6_cksum = csum_finish(csum_continue(icmp_csum, ra,
+                                                      prev_l4_size + size));
+}
+
 /* Called with in the pinctrl_handler thread context. */
 static long long int
 ipv6_ra_send(struct rconn *swconn, struct ipv6_ra_state *ra)
@@ -2463,6 +2539,10 @@ ipv6_ra_send(struct rconn *swconn, struc
         packet_put_ra_dnssl_opt(&packet, htonl(0xffffffff),
                                 ra->config->dnssl.string);
     }
+    if (ra->config->route_info.length) {
+        packet_put_ra_route_info_opt(&packet, htonl(0xffffffff),
+                                     ra->config->route_info.string);
+    }
 
     uint64_t ofpacts_stub[4096 / 8];
     struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub);
--- a/ovn/lib/ovn-l7.h
+++ b/ovn/lib/ovn-l7.h
@@ -242,6 +242,18 @@ struct ovs_nd_dnssl {
 };
 BUILD_ASSERT_DECL(ND_DNSSL_OPT_LEN == sizeof(struct ovs_nd_dnssl));
 
+/* Route Information option RFC 4191 */
+#define ND_OPT_ROUTE_INFO       24
+#define ND_ROUTE_INFO_OPT_LEN    8
+struct ovs_nd_route_info {
+    u_int8_t type;  /* ND_OPT_ROUTE_INFO */
+    u_int8_t len;   /* 1, 2 or 3 */
+    u_int8_t prefix_len;
+    u_int8_t flags;
+    ovs_be32 route_lifetime;
+};
+BUILD_ASSERT_DECL(ND_ROUTE_INFO_OPT_LEN == sizeof(struct ovs_nd_route_info));
+
 #define DHCPV6_DUID_LL      3
 #define DHCPV6_HW_TYPE_ETH  1
 
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -6763,6 +6763,12 @@ copy_ra_to_sb(struct ovn_port *op, const
         smap_add(&options, "ipv6_ra_prf", prf);
     }
 
+    const char *route_info = smap_get(&op->nbrp->ipv6_ra_configs,
+                                      "route_info");
+    if (route_info) {
+        smap_add(&options, "ipv6_ra_route_info", route_info);
+    }
+
     sbrec_port_binding_set_options(op->sb, &options);
     smap_destroy(&options);
 }
--- a/ovn/ovn-nb.xml
+++ b/ovn/ovn-nb.xml
@@ -1871,6 +1871,20 @@
         </ul>
       </column>
 
+      <column name="ipv6_ra_configs" key="route_info">
+        Route Info is used to configure Route Info Option sent in Router
+        Advertisment according to RFC 4191. Route Info is a comma
+        separated string where each field provides PRF and prefix for a
+        given route (e.g: HIGH-aef1::11/48,LOW-aef2::11/96)
+        Possible PRF values are:
+
+        <ul>
+          <li>HIGH: mapped to 0x01 in RA PRF field</li>
+          <li>MEDIUM: mapped to 0x00 in RA PRF field</li>
+          <li>LOW: mapped to 0x11 in RA PRF field</li>
+        </ul>
+      </column>
+
       <column name="ipv6_ra_configs" key="mtu">
         The recommended MTU for the link. Default is 0, which means no MTU
         Option will be included in RA packet replied by ovn-controller.
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -11417,14 +11417,15 @@ construct_expected_ra() {
     local ra_mo=$2
     local rdnss=$3
     local dnssl=$4
-    local ra_prefix_la=$5
+    local route_info=$5
+    local ra_prefix_la=$6
 
     local slla=0101${src_mac}
     local mtu_opt=""
     if test $mtu != 0; then
         mtu_opt=05010000${mtu}
     fi
-    shift 5
+    shift 6
 
     local prefix=""
     while [[ $# -gt 0 ]] ; do
@@ -11442,8 +11443,12 @@ construct_expected_ra() {
     if test $dnssl != 0; then
         dnssl_opt=1f030000ffffffff${dnssl}
     fi
+    local route_info_opt=""
+    if test $route_info != 0; then
+        route_info_opt=${route_info}
+    fi
 
-    local ra=ff${ra_mo}ffff0000000000000000${slla}${mtu_opt}${prefix}${rdnss_opt}${dnssl_opt}
+    local ra=ff${ra_mo}ffff0000000000000000${slla}${mtu_opt}${prefix}${rdnss_opt}${dnssl_opt}${route_info_opt}
     local icmp=8600XXXX${ra}
 
     local ip_len=$(expr ${#icmp} / 2)
@@ -11478,38 +11483,43 @@ ra_test() {
 }
 
 # Baseline test with no MTU
-ra_test 0 00 0 0 c0 40 aef00000000000000000000000000000
+ra_test 0 00 0 0 0 c0 40 aef00000000000000000000000000000
 
 # Now make sure an MTU option makes it
 ovn-nbctl --wait=hv set Logical_Router_Port ro-sw ipv6_ra_configs:mtu=1500
-ra_test 000005dc 00 0 0 c0 40 aef00000000000000000000000000000
+ra_test 000005dc 00 0 0 0 c0 40 aef00000000000000000000000000000
 
 # Now test for multiple network prefixes
 ovn-nbctl --wait=hv set Logical_Router_port ro-sw networks='aef0\:\:1/64 fd0f\:\:1/48'
-ra_test 000005dc 00 0 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+ra_test 000005dc 00 0 0 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
 
 # Test PRF for default gw
 ovn-nbctl --wait=hv set Logical_Router_port ro-sw ipv6_ra_configs:router_preference="LOW"
-ra_test 000005dc 18 0 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+ra_test 000005dc 18 0 0 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
 
 # Now test for RDNSS
 ovn-nbctl --wait=hv set Logical_Router_port ro-sw ipv6_ra_configs:rdnss='aef0::11'
 dns_addr=aef00000000000000000000000000011
-ra_test 000005dc 18 $dns_addr 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+ra_test 000005dc 18 $dns_addr 0 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
 
 # Now test for DNSSL
 ovn-nbctl --wait=hv set Logical_Router_port ro-sw ipv6_ra_configs:dnssl="aa.bb.cc"
 ovn-nbctl --wait=hv set Logical_Router_port ro-sw ipv6_ra_configs:router_preference="HIGH"
 dnssl=02616102626202636300000000000000
-ra_test 000005dc 08 $dns_addr $dnssl c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+ra_test 000005dc 08 $dns_addr $dnssl 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+
+# Now test Route Info option
+ovn-nbctl --wait=hv set Logical_Router_port ro-sw ipv6_ra_configs:route_info="HIGH-aef1::11/48,LOW-aef2::11/96"
+route_info=18023008ffffffffaef100000000000018036018ffffffffaef20000000000000000000000000000
+ra_test 000005dc 08 $dns_addr $dnssl $route_info c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
 
 ## Test a different address mode now
 ovn-nbctl --wait=hv set Logical_Router_Port ro-sw ipv6_ra_configs:address_mode=dhcpv6_stateful
-ra_test 000005dc 88 $dns_addr $dnssl 80 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+ra_test 000005dc 88 $dns_addr $dnssl $route_info 80 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
 
 # And the other address mode
 ovn-nbctl --wait=hv set Logical_Router_Port ro-sw ipv6_ra_configs:address_mode=dhcpv6_stateless
-ra_test 000005dc 48 $dns_addr $dnssl c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+ra_test 000005dc 48 $dns_addr $dnssl $route_info c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
 
 OVN_CLEANUP([hv1],[hv2])
 AT_CLEANUP