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