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

Numan Siddique numans at ovn.org
Tue Oct 29 12:52:48 UTC 2019


On Tue, Oct 29, 2019 at 4:39 PM Lorenzo Bianconi
<lorenzo.bianconi at redhat.com> wrote:
>
> > On Tue, Oct 29, 2019 at 3:29 PM Lorenzo Bianconi
> > <lorenzo.bianconi at 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.bianconi at redhat.com>
> > > ---
> > > Changes since v4:
> > > - update documentation
> > > - fix possible array out of bounds issue in packet_put_ra_dnssl_opt
> > > - fix strtok_r usage
> > > ---
> > >  controller/pinctrl.c | 59 ++++++++++++++++++++++++++++++++++++++++++++
> > >  lib/ovn-l7.h         | 11 +++++++++
> > >  northd/ovn-northd.c  |  4 +++
> > >  ovn-nb.xml           |  5 ++++
> > >  tests/ovn.at         | 30 ++++++++++++++--------
> > >  5 files changed, 99 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/controller/pinctrl.c b/controller/pinctrl.c
> > > index f105ebb5c..cddf98648 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,53 @@ 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)
> > > +{
> > > +    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);
> > > +    char *t0, *r0, dnssl[255] = {};
> > > +    int i = 0;
> > > +
> > > +    /* Multiple DNS Search List must be 'comma' separated
> > > +     * (e.g. "a.b.c, d.e.f") */
> >
> > Can you please add a comment on how the dns list will be encode with an example.
> > Like if dns list is a.b.c,www.ovn.org then it will be encoded as - 01
> > 61 01 62 01 63 00 03 77 77 77 03 6f 76 63 03 6f 72 67 00
> >
> > This will really help in understanding what's going on. Also can you
> > link the RFC version.
>
> Hi Numan,
>
> Thx for the review. Ack, will do in v6
>
> >
> > > +    for (t0 = strtok_r(dnssl_list, ",", &r0); t0;
> > > +         t0 = strtok_r(NULL, ",", &r0)) {
> > > +        char *t1, *r1;
> > > +
> > > +        size += strlen(t0) + 2;
> > > +        if (size > sizeof(dnssl)) {
> >
> > For the sake of simplicity let's assume the length of dnssl is 10.
> > Then if the dns list is a.b.c,d.e.f then this will cause the buffer to
> > overflow right ?
> >
> > For the first outer for loop with t0 = a.b.c, the 'size' will be 7. So 7 < 10.
> > In the next outer for loop with t0 = d.e.f, the size will be again 7
> > and it will cause the inner for loop  to copy the contents beyond
> > the size of dnssl right ?
> >
> > I think this code needs to be refined a bit to take all these things
> > into consideration.
> >
>
> I guess the check is fine since size value will not be reset:
> size += strlen(t0) + 2;

Ah right. I didn't notice "+=". Thank for pointing this out.


>
> Regards,
> Lorenzo
>
>
> > Thanks
> > Numan
> >
> > > +            return;
> > > +        }
> > > +
> >
> >
> >
> > > +        for (t1 = strtok_r(t0, ".", &r1); t1;
> > > +             t1 = strtok_r(NULL, ".", &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 +2437,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 33fe9363c..194e4bf4a 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..899089422 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. Multiple DNS Search List
> > > +        must be 'comma' separated (e.g. "a.b.c, d.e.f")
> > > +      </column>
> > >      </group>
> > >
> > >      <group title="Options">
> > > diff --git a/tests/ovn.at b/tests/ovn.at
> > > index 1cfc0796d..9f06059fa 100644
> > > --- a/tests/ovn.at
> > > +++ b/tests/ovn.at
> > > @@ -11408,14 +11408,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
> > > @@ -11429,8 +11430,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)
> > > @@ -11465,28 +11470,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
> > > dev at openvswitch.org
> > > https://mail.openvswitch.org/mailman/listinfo/ovs-dev


More information about the dev mailing list