[ovs-dev] [PATCH ovn] Add DNSSL support to OVN

Lorenzo Bianconi lorenzo.bianconi at redhat.com
Mon Oct 21 17:19:15 UTC 2019


Introduce the possibility to specify a DNSSL option to Router
Advertisement packets. DNS Search list can be specified using
'dnssl' tag in the ipv6_ra_configs column of logical router
port table

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi at redhat.com>
---
 controller/pinctrl.c | 62 +++++++++++++++++++++++++++++++++++++++++++-
 northd/ovn-northd.c  |  4 +++
 ovn-nb.xml           |  4 +++
 tests/ovn.at         | 30 ++++++++++++++-------
 4 files changed, 89 insertions(+), 11 deletions(-)

diff --git a/controller/pinctrl.c b/controller/pinctrl.c
index 5bc4b35e7..b522e3359 100644
--- a/controller/pinctrl.c
+++ b/controller/pinctrl.c
@@ -2194,6 +2194,7 @@ struct ipv6_ra_config {
     struct lport_addresses prefixes;
     struct in6_addr rdnss;
     bool has_rdnss;
+    struct ds dnssl;
 };
 
 struct ipv6_ra_state {
@@ -2214,6 +2215,17 @@ struct nd_rdnss_opt {
     const ovs_be128 dns[0];
 };
 
+/* DNSSL option RFC 6106 */
+#define ND_OPT_DNSSL        31
+#define ND_DNSSL_OPT_LEN    8
+struct ovs_nd_dnssl {
+    u_int8_t type;  /* ND_OPT_DNSSL */
+    u_int8_t len;   /* >= 2 */
+    ovs_be16 reserved;
+    ovs_be32 lifetime;
+    char dnssl[0];
+};
+
 static void
 init_ipv6_ras(void)
 {
@@ -2225,6 +2237,7 @@ ipv6_ra_config_delete(struct ipv6_ra_config *config)
 {
     if (config) {
         destroy_lport_addresses(&config->prefixes);
+        ds_destroy(&config->dnssl);
         free(config);
     }
 }
@@ -2263,6 +2276,7 @@ ipv6_ra_update_config(const struct sbrec_port_binding *pb)
             nd_ra_min_interval_default(config->max_interval));
     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);
 
     const char *address_mode = smap_get(&pb->options, "ipv6_ra_address_mode");
     if (!address_mode) {
@@ -2308,6 +2322,11 @@ ipv6_ra_update_config(const struct sbrec_port_binding *pb)
     }
     config->has_rdnss = !!rdnss;
 
+    const char *dnssl = smap_get(&pb->options, "ipv6_ra_dnssl");
+    if (dnssl) {
+        ds_put_buffer(&config->dnssl, dnssl, strlen(dnssl));
+    }
+
     return config;
 
 fail:
@@ -2366,6 +2385,44 @@ packet_put_ra_rdnss_opt(struct dp_packet *b, uint8_t num,
                                                       prev_l4_size + size));
 }
 
+static void
+packet_put_ra_dnssl_opt(struct dp_packet *b, ovs_be32 lifetime,
+                        char *dnssl_list)
+{
+    char *t0, *r0 = dnssl_list, dnssl[255] = {};
+    size_t prev_l4_size = dp_packet_l4_size(b);
+    struct ip6_hdr *nh = dp_packet_l3(b);
+    size_t size = 8;
+    int i = 0;
+
+    while ((t0 = strtok_r(r0, ",", &r0))) {
+        char *t1, *r1 = t0;
+
+        size += strlen(t0) + 2;
+        while ((t1 = strtok_r(r1, ".", &r1))) {
+            dnssl[i++] = strlen(t1);
+            memcpy(&dnssl[i], t1, strlen(t1));
+            i += strlen(t1);
+        }
+        dnssl[i++] = 0;
+    }
+    size = ROUND_UP(size, 8);
+    nh->ip6_plen = htons(prev_l4_size + size);
+
+    struct ovs_nd_dnssl *nd_dnssl = dp_packet_put_uninit(b, size);
+    nd_dnssl->type = ND_OPT_DNSSL;
+    nd_dnssl->len = size / 8;
+    nd_dnssl->reserved = 0;
+    nd_dnssl->lifetime = lifetime;
+    memcpy(&nd_dnssl->dnssl[0], dnssl, 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)
@@ -2374,7 +2431,7 @@ ipv6_ra_send(struct rconn *swconn, struct ipv6_ra_state *ra)
         return ra->next_announce;
     }
 
-    uint64_t packet_stub[128 / 8];
+    uint64_t packet_stub[512 / 8];
     struct dp_packet packet;
     dp_packet_use_stub(&packet, packet_stub, sizeof packet_stub);
     compose_nd_ra(&packet, ra->config->eth_src, ra->config->eth_dst,
@@ -2393,6 +2450,9 @@ ipv6_ra_send(struct rconn *swconn, struct ipv6_ra_state *ra)
     if (ra->config->has_rdnss) {
         packet_put_ra_rdnss_opt(&packet, 1, 0xffffffff, &ra->config->rdnss);
     }
+    if (ra->config->dnssl.length) {
+        packet_put_ra_dnssl_opt(&packet, 0xffffffff, ra->config->dnssl.string);
+    }
 
     uint64_t ofpacts_stub[4096 / 8];
     struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub);
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index d1de36e08..dbb279052 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -6489,6 +6489,10 @@ copy_ra_to_sb(struct ovn_port *op, const char *address_mode)
     if (rdnss) {
         smap_add(&options, "ipv6_ra_rdnss", rdnss);
     }
+    const char *dnssl = smap_get(&op->nbrp->ipv6_ra_configs, "dnssl");
+    if (dnssl) {
+        smap_add(&options, "ipv6_ra_dnssl", dnssl);
+    }
 
     smap_add(&options, "ipv6_ra_src_eth", op->lrp_networks.ea_s);
 
diff --git a/ovn-nb.xml b/ovn-nb.xml
index f1f9b969e..6f2e7dc72 100644
--- a/ovn-nb.xml
+++ b/ovn-nb.xml
@@ -1889,6 +1889,10 @@
       <column name="ipv6_ra_configs" key="rdnss">
         IPv6 address of RDNSS server announced in RA packets
       </column>
+
+      <column name="ipv6_ra_configs" key="dnssl">
+        DNS Search List announced in RA packets
+      </column>
     </group>
 
     <group title="Options">
diff --git a/tests/ovn.at b/tests/ovn.at
index 80d38ea4c..daf8335cf 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -12538,14 +12538,15 @@ construct_expected_ra() {
     local mtu=$1
     local ra_mo=$2
     local rdnss=$3
-    local ra_prefix_la=$4
+    local dnssl=$4
+    local ra_prefix_la=$5
 
     local slla=0101${src_mac}
     local mtu_opt=""
     if test $mtu != 0; then
         mtu_opt=05010000${mtu}
     fi
-    shift 4
+    shift 5
 
     local prefix=""
     while [[ $# -gt 0 ]] ; do
@@ -12559,8 +12560,12 @@ construct_expected_ra() {
     if test $rdnss != 0; then
         rdnss_opt=19030000ffffffff${rdnss}
     fi
+    local dnssl_opt=""
+    if test $dnssl != 0; then
+        dnssl_opt=1f030000ffffffff${dnssl}
+    fi
 
-    local ra=ff${ra_mo}ffff0000000000000000${slla}${mtu_opt}${prefix}${rdnss_opt}
+    local ra=ff${ra_mo}ffff0000000000000000${slla}${mtu_opt}${prefix}${rdnss_opt}${dnssl_opt}
     local icmp=8600XXXX${ra}
 
     local ip_len=$(expr ${#icmp} / 2)
@@ -12595,28 +12600,33 @@ ra_test() {
 }
 
 # Baseline test with no MTU
-ra_test 0 00 0 c0 40 aef00000000000000000000000000000
+ra_test 0 00 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 c0 40 aef00000000000000000000000000000
+ra_test 000005dc 00 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 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+ra_test 000005dc 00 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 00 $dns_addr c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+ra_test 000005dc 00 $dns_addr 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"
+dnssl=02616102626202636300000000000000
+ra_test 000005dc 00 $dns_addr $dnssl c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
 
-# Test a different address mode now
+## 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 80 $dns_addr 80 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+ra_test 000005dc 80 $dns_addr $dnssl 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 40 $dns_addr c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
+ra_test 000005dc 40 $dns_addr $dnssl c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
 
 OVN_CLEANUP([hv1],[hv2])
 AT_CLEANUP
-- 
2.21.0



More information about the dev mailing list