[ovs-dev] [PATCH v4 ovn 1/2] Add RDNSS support to OVN

Numan Siddique nusiddiq at redhat.com
Tue Oct 29 07:25:22 UTC 2019


On Mon, Oct 28, 2019 at 8:09 PM Lorenzo Bianconi
<lorenzo.bianconi at redhat.com> wrote:
>
> Introduce the possibility to specify a RDNSS option to Router
> Advertisement packets. DNS IPv6 address can be specified using
> 'rdnss' tag in the ipv6_ra_configs column of logical router
> port table
>
> Acked-by: Mark Michelson <mmichels at redhat.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi at redhat.com>

Thanks. I applied this patch to master.

Numan

> ---
>  controller/pinctrl.c | 39 +++++++++++++++++++++++++++++++++++++++
>  lib/ovn-l7.h         | 11 +++++++++++
>  northd/ovn-northd.c  |  5 +++++
>  ovn-nb.xml           |  5 +++++
>  tests/ovn.at         | 27 +++++++++++++++++++--------
>  5 files changed, 79 insertions(+), 8 deletions(-)
>
> diff --git a/controller/pinctrl.c b/controller/pinctrl.c
> index d826da186..f105ebb5c 100644
> --- a/controller/pinctrl.c
> +++ b/controller/pinctrl.c
> @@ -2192,6 +2192,8 @@ struct ipv6_ra_config {
>      uint8_t mo_flags; /* Managed/Other flags for RAs */
>      uint8_t la_flags; /* On-link/autonomous flags for address prefixes */
>      struct lport_addresses prefixes;
> +    struct in6_addr rdnss;
> +    bool has_rdnss;
>  };
>
>  struct ipv6_ra_state {
> @@ -2289,6 +2291,12 @@ ipv6_ra_update_config(const struct sbrec_port_binding *pb)
>          VLOG_WARN("Invalid IP source %s", ip_addr);
>          goto fail;
>      }
> +    const char *rdnss = smap_get(&pb->options, "ipv6_ra_rdnss");
> +    if (rdnss && !ipv6_parse(rdnss, &config->rdnss)) {
> +        VLOG_WARN("Invalid RDNSS source %s", rdnss);
> +        goto fail;
> +    }
> +    config->has_rdnss = !!rdnss;
>
>      return config;
>
> @@ -2319,6 +2327,33 @@ put_load(uint64_t value, enum mf_field_id dst, int ofs, int n_bits,
>      bitwise_one(ofpact_set_field_mask(sf), sf->field->n_bytes, ofs, n_bits);
>  }
>
> +static void
> +packet_put_ra_rdnss_opt(struct dp_packet *b, uint8_t num,
> +                        ovs_be32 lifetime, const struct in6_addr *dns)
> +{
> +    size_t prev_l4_size = dp_packet_l4_size(b);
> +    struct ip6_hdr *nh = dp_packet_l3(b);
> +    size_t len = 2 * num + 1;
> +
> +    nh->ip6_plen = htons(prev_l4_size + len * 8);
> +
> +    struct nd_rdnss_opt *nd_rdnss = dp_packet_put_uninit(b, sizeof *nd_rdnss);
> +    nd_rdnss->type = ND_OPT_RDNSS;
> +    nd_rdnss->len = len;
> +    nd_rdnss->reserved = 0;
> +    put_16aligned_be32(&nd_rdnss->lifetime, lifetime);
> +
> +    for (int i = 0; i < num; i++) {
> +        dp_packet_put(b, &dns[i], sizeof(ovs_be32[4]));
> +    }
> +
> +    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 + len * 8));
> +}
> +
>  /* Called with in the pinctrl_handler thread context. */
>  static long long int
>  ipv6_ra_send(struct rconn *swconn, struct ipv6_ra_state *ra)
> @@ -2343,6 +2378,10 @@ ipv6_ra_send(struct rconn *swconn, struct ipv6_ra_state *ra)
>              ra->config->la_flags, htonl(IPV6_ND_RA_OPT_PREFIX_VALID_LIFETIME),
>              htonl(IPV6_ND_RA_OPT_PREFIX_PREFERRED_LIFETIME), addr);
>      }
> +    if (ra->config->has_rdnss) {
> +        packet_put_ra_rdnss_opt(&packet, 1, htonl(0xffffffff),
> +                                &ra->config->rdnss);
> +    }
>
>      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 c93def450..12cee6329 100644
> --- a/lib/ovn-l7.h
> +++ b/lib/ovn-l7.h
> @@ -220,6 +220,17 @@ struct dhcpv6_opt_ia_na {
>      ovs_be32 t2;
>  });
>
> +/* RDNSS option RFC 6106 */
> +#define ND_RDNSS_OPT_LEN    8
> +#define ND_OPT_RDNSS        25
> +struct nd_rdnss_opt {
> +    uint8_t type;         /* ND_OPT_RDNSS. */
> +    uint8_t len;          /* >= 3. */
> +    ovs_be16 reserved;    /* Always 0. */
> +    ovs_16aligned_be32 lifetime;
> +};
> +BUILD_ASSERT_DECL(ND_RDNSS_OPT_LEN == sizeof(struct nd_rdnss_opt));
> +
>  #define DHCPV6_DUID_LL      3
>  #define DHCPV6_HW_TYPE_ETH  1
>
> diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
> index ea8ad7c2d..d1de36e08 100644
> --- a/northd/ovn-northd.c
> +++ b/northd/ovn-northd.c
> @@ -6485,6 +6485,11 @@ copy_ra_to_sb(struct ovn_port *op, const char *address_mode)
>      smap_add(&options, "ipv6_ra_prefixes", ds_cstr(&s));
>      ds_destroy(&s);
>
> +    const char *rdnss = smap_get(&op->nbrp->ipv6_ra_configs, "rdnss");
> +    if (rdnss) {
> +        smap_add(&options, "ipv6_ra_rdnss", rdnss);
> +    }
> +
>      smap_add(&options, "ipv6_ra_src_eth", op->lrp_networks.ea_s);
>
>      sbrec_port_binding_set_options(op->sb, &options);
> diff --git a/ovn-nb.xml b/ovn-nb.xml
> index 1504f8fca..2faf9390b 100644
> --- a/ovn-nb.xml
> +++ b/ovn-nb.xml
> @@ -1885,6 +1885,11 @@
>          is one-third of <ref column="ipv6_ra_configs" key="max_interval"/>,
>          i.e. 200 seconds if that key is unset.
>        </column>
> +
> +      <column name="ipv6_ra_configs" key="rdnss">
> +        IPv6 address of RDNSS server announced in RA packets. At the moment
> +        OVN supports just one RDNSS server.
> +      </column>
>      </group>
>
>      <group title="Options">
> diff --git a/tests/ovn.at b/tests/ovn.at
> index 22b272a60..3e7692895 100644
> --- a/tests/ovn.at
> +++ b/tests/ovn.at
> @@ -12537,14 +12537,15 @@ construct_expected_ra() {
>
>      local mtu=$1
>      local ra_mo=$2
> -    local ra_prefix_la=$3
> +    local rdnss=$3
> +    local ra_prefix_la=$4
>
>      local slla=0101${src_mac}
>      local mtu_opt=""
>      if test $mtu != 0; then
>          mtu_opt=05010000${mtu}
>      fi
> -    shift 3
> +    shift 4
>
>      local prefix=""
>      while [[ $# -gt 0 ]] ; do
> @@ -12554,7 +12555,12 @@ construct_expected_ra() {
>          shift 2
>      done
>
> -    local ra=ff${ra_mo}ffff0000000000000000${slla}${mtu_opt}${prefix}
> +    local rdnss_opt=""
> +    if test $rdnss != 0; then
> +        rdnss_opt=19030000ffffffff${rdnss}
> +    fi
> +
> +    local ra=ff${ra_mo}ffff0000000000000000${slla}${mtu_opt}${prefix}${rdnss_opt}
>      local icmp=8600XXXX${ra}
>
>      local ip_len=$(expr ${#icmp} / 2)
> @@ -12589,23 +12595,28 @@ ra_test() {
>  }
>
>  # Baseline test with no MTU
> -ra_test 0 00 c0 40 aef00000000000000000000000000000
> +ra_test 0 00 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 c0 40 aef00000000000000000000000000000
> +ra_test 000005dc 00 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 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
> +ra_test 000005dc 00 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
>
>  # 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 80 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
> +ra_test 000005dc 80 $dns_addr 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 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000
> +ra_test 000005dc 40 $dns_addr 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