On Mon, Oct 28, 2019 at 8:10 PM Lorenzo Bianconi
<lorenzo.bianc...@redhat.com> wrote:
>
> 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.bianc...@redhat.com>
> ---
>  controller/pinctrl.c | 51 ++++++++++++++++++++++++++++++++++++++++++++
>  lib/ovn-l7.h         | 11 ++++++++++
>  northd/ovn-northd.c  |  4 ++++
>  ovn-nb.xml           |  5 +++++
>  tests/ovn.at         | 30 +++++++++++++++++---------
>  5 files changed, 91 insertions(+), 10 deletions(-)
>
> diff --git a/controller/pinctrl.c b/controller/pinctrl.c
> index f105ebb5c..0bd1ef3ef 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 {
> @@ -2215,6 +2216,7 @@ ipv6_ra_config_delete(struct ipv6_ra_config *config)
>  {
>      if (config) {
>          destroy_lport_addresses(&config->prefixes);
> +        ds_destroy(&config->dnssl);
>          free(config);
>      }
>  }
> @@ -2253,6 +2255,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) {
> @@ -2298,6 +2301,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:
> @@ -2354,6 +2362,45 @@ packet_put_ra_rdnss_opt(struct dp_packet *b, uint8_t 
> num,
>                                                        prev_l4_size + len * 
> 8));
>  }
>
> +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);
> +    size_t size = sizeof(struct ovs_nd_dnssl);
> +    struct ip6_hdr *nh = dp_packet_l3(b);
> +    int i = 0;
> +
> +    while ((t0 = strtok_r(r0, ",", &r0))) {

Are we not suppose to pass NULL as the first argument to subsequent
calls of strtok_r ?

Is there a chance that we might cross dnssl 255 length and have a segfault ?

Can you please add comments on how the dnssl string is to be encoded ?

Since the code here, is already handling for multiple dnssl values in
the "dnssl_list", we can just accept
multiple values of dnssl right ? Right now the patch is restricting to
just 1 dnssl for the CMS to configure.

Thanks
Numan


> +        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, sizeof 
> *nd_dnssl);
> +    nd_dnssl->type = ND_OPT_DNSSL;
> +    nd_dnssl->len = size / 8;
> +    nd_dnssl->reserved = 0;
> +    put_16aligned_be32(&nd_dnssl->lifetime, lifetime);
> +
> +    dp_packet_put(b, dnssl, size - sizeof *nd_dnssl);
> +
> +    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)
> @@ -2382,6 +2429,10 @@ ipv6_ra_send(struct rconn *swconn, struct 
> ipv6_ra_state *ra)
>          packet_put_ra_rdnss_opt(&packet, 1, htonl(0xffffffff),
>                                  &ra->config->rdnss);
>      }
> +    if (ra->config->dnssl.length) {
> +        packet_put_ra_dnssl_opt(&packet, htonl(0xffffffff),
> +                                ra->config->dnssl.string);
> +    }
>
>      uint64_t ofpacts_stub[4096 / 8];
>      struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub);
> diff --git a/lib/ovn-l7.h b/lib/ovn-l7.h
> index 12cee6329..5fc370bf5 100644
> --- a/lib/ovn-l7.h
> +++ b/lib/ovn-l7.h
> @@ -231,6 +231,17 @@ struct nd_rdnss_opt {
>  };
>  BUILD_ASSERT_DECL(ND_RDNSS_OPT_LEN == sizeof(struct nd_rdnss_opt));
>
> +/* 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_16aligned_be32 lifetime;
> +};
> +BUILD_ASSERT_DECL(ND_DNSSL_OPT_LEN == sizeof(struct ovs_nd_dnssl));
> +
>  #define DHCPV6_DUID_LL      3
>  #define DHCPV6_HW_TYPE_ETH  1
>
> 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 2faf9390b..c49144848 100644
> --- a/ovn-nb.xml
> +++ b/ovn-nb.xml
> @@ -1890,6 +1890,11 @@
>          IPv6 address of RDNSS server announced in RA packets. At the moment
>          OVN supports just one RDNSS server.
>        </column>
> +
> +      <column name="ipv6_ra_configs" key="dnssl">
> +        DNS Search List announced in RA packets. At the moment OVN supports
> +        just one DNS Search entry
> +      </column>
>      </group>
>
>      <group title="Options">
> diff --git a/tests/ovn.at b/tests/ovn.at
> index 3e7692895..f4f5ddd5a 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
>
> _______________________________________________
> dev mailing list
> d...@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to