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

Mark Michelson mmichels at redhat.com
Fri Oct 18 18:38:39 UTC 2019


Acked-by: Mark Michelson <mmichels at redhat.com>

On 10/18/19 7:09 AM, Lorenzo Bianconi 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
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi at redhat.com>
> ---
>   controller/pinctrl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
>   northd/ovn-northd.c  |  5 +++++
>   ovn-nb.xml           |  4 ++++
>   tests/ovn.at         | 27 +++++++++++++++++-------
>   4 files changed, 78 insertions(+), 8 deletions(-)
> 
> diff --git a/controller/pinctrl.c b/controller/pinctrl.c
> index d826da186..5bc4b35e7 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 {
> @@ -2202,6 +2204,16 @@ struct ipv6_ra_state {
>       bool delete_me;
>   };
>   
> +#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_be32 lifetime;
> +    const ovs_be128 dns[0];
> +};
> +
>   static void
>   init_ipv6_ras(void)
>   {
> @@ -2289,6 +2301,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 +2337,35 @@ 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;
> +    size_t size = len * 8;
> +
> +    nh->ip6_plen = htons(prev_l4_size + len * 8);
> +
> +    struct nd_rdnss_opt *nd_rdnss = dp_packet_put_uninit(b, size);
> +    nd_rdnss->type = ND_OPT_RDNSS;
> +    nd_rdnss->len = len;
> +    nd_rdnss->reserved = 0;
> +    nd_rdnss->lifetime = lifetime;
> +
> +    ovs_be128 *addr = (ovs_be128 *)(nd_rdnss + 1);
> +    for (int i = 0; i < num; i++) {
> +        memcpy(addr + i, dns, 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 + size));
> +}
> +
>   /* 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 +2390,9 @@ 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, 0xffffffff, &ra->config->rdnss);
> +    }
>   
>       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 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..f1f9b969e 100644
> --- a/ovn-nb.xml
> +++ b/ovn-nb.xml
> @@ -1885,6 +1885,10 @@
>           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
> +      </column>
>       </group>
>   
>       <group title="Options">
> diff --git a/tests/ovn.at b/tests/ovn.at
> index 6bdb9e8ed..80d38ea4c 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
> 



More information about the dev mailing list