[ovs-dev,v2,ovn,1/2] Add RDNSS support to OVN
diff mbox series

Message ID 0facf1da8334bb56821127b3aa80c85ca0b5dfde.1571843596.git.lorenzo.bianconi@redhat.com
State New
Headers show
Series
  • add RDNSS/DNSSL support to OVN
Related show

Commit Message

Lorenzo Bianconi Oct. 23, 2019, 3:18 p.m. UTC
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@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 controller/pinctrl.c | 51 ++++++++++++++++++++++++++++++++++++++++++++
 northd/ovn-northd.c  |  5 +++++
 ovn-nb.xml           |  4 ++++
 tests/ovn.at         | 27 ++++++++++++++++-------
 4 files changed, 79 insertions(+), 8 deletions(-)

Comments

Numan Siddique Oct. 25, 2019, 4:55 a.m. UTC | #1
On Wed, Oct 23, 2019 at 8:49 PM Lorenzo Bianconi <
lorenzo.bianconi@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@redhat.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> ---
>  controller/pinctrl.c | 51 ++++++++++++++++++++++++++++++++++++++++++++
>  northd/ovn-northd.c  |  5 +++++
>  ovn-nb.xml           |  4 ++++
>  tests/ovn.at         | 27 ++++++++++++++++-------
>  4 files changed, 79 insertions(+), 8 deletions(-)
>
> diff --git a/controller/pinctrl.c b/controller/pinctrl.c
> index d826da186..1125f2ef3 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];
> +};
> +
>

I think this structure definition can be moved to lib/ovn-l7.h.
Can you please change the lifetime type to ovs_16aligned_be32, the way it
is done here -
https://github.com/openvswitch/ovs/blob/master/lib/packets.h#L1032
And also a macro - BUILD_ASSERT_DECL like it is done for the struct
- ovs_nd_prefix_opt.
If this function is later required in OVS, we can easily move these to the
ovs repo.

Also can you please add the RFC number for RDNSS in the comments ? It would
be easier for some one to
look into the RFC if required.

As per the RFC, I can see that we can include multiple RDNSS addressed in
the RA message, where as this patch restricts to just 1 address.
Any particular reason for this ?

Thanks
Numan



>  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,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/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 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@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
Lorenzo Bianconi Oct. 25, 2019, 10:48 a.m. UTC | #2
> On Wed, Oct 23, 2019 at 8:49 PM Lorenzo Bianconi <
> lorenzo.bianconi@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@redhat.com>
> > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> > ---
> >  controller/pinctrl.c | 51 ++++++++++++++++++++++++++++++++++++++++++++
> >  northd/ovn-northd.c  |  5 +++++
> >  ovn-nb.xml           |  4 ++++
> >  tests/ovn.at         | 27 ++++++++++++++++-------
> >  4 files changed, 79 insertions(+), 8 deletions(-)
> >
> > diff --git a/controller/pinctrl.c b/controller/pinctrl.c
> > index d826da186..1125f2ef3 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];
> > +};
> > +
> >
> 
> I think this structure definition can be moved to lib/ovn-l7.h.
> Can you please change the lifetime type to ovs_16aligned_be32, the way it
> is done here -
> https://github.com/openvswitch/ovs/blob/master/lib/packets.h#L1032
> And also a macro - BUILD_ASSERT_DECL like it is done for the struct
> - ovs_nd_prefix_opt.
> If this function is later required in OVS, we can easily move these to the
> ovs repo.
> 
> Also can you please add the RFC number for RDNSS in the comments ? It would
> be easier for some one to
> look into the RFC if required.

Hi Numan,

thx for the review. Will do in v3

> 
> As per the RFC, I can see that we can include multiple RDNSS addressed in
> the RA message, where as this patch restricts to just 1 address.
> Any particular reason for this ?

packet_put_ra_rdnss_opt supports 'multiple' rdnss addresses but for the moment
northd (just for simplicity) adds a single server address. I think we can add
multiple server support in the future if needed. What do you think?

Regards,
Lorenzo

> 
> Thanks
> Numan
> 
> 
> 
> >  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,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/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 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@openvswitch.org
> > https://mail.openvswitch.org/mailman/listinfo/ovs-dev
> >
Numan Siddique Oct. 25, 2019, 11:55 a.m. UTC | #3
On Fri, Oct 25, 2019 at 4:18 PM Lorenzo Bianconi <
lorenzo.bianconi@redhat.com> wrote:

> > On Wed, Oct 23, 2019 at 8:49 PM Lorenzo Bianconi <
> > lorenzo.bianconi@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@redhat.com>
> > > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> > > ---
> > >  controller/pinctrl.c | 51 ++++++++++++++++++++++++++++++++++++++++++++
> > >  northd/ovn-northd.c  |  5 +++++
> > >  ovn-nb.xml           |  4 ++++
> > >  tests/ovn.at         | 27 ++++++++++++++++-------
> > >  4 files changed, 79 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/controller/pinctrl.c b/controller/pinctrl.c
> > > index d826da186..1125f2ef3 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];
> > > +};
> > > +
> > >
> >
> > I think this structure definition can be moved to lib/ovn-l7.h.
> > Can you please change the lifetime type to ovs_16aligned_be32, the way it
> > is done here -
> > https://github.com/openvswitch/ovs/blob/master/lib/packets.h#L1032
> > And also a macro - BUILD_ASSERT_DECL like it is done for the struct
> > - ovs_nd_prefix_opt.
> > If this function is later required in OVS, we can easily move these to
> the
> > ovs repo.
> >
> > Also can you please add the RFC number for RDNSS in the comments ? It
> would
> > be easier for some one to
> > look into the RFC if required.
>
> Hi Numan,
>
> thx for the review. Will do in v3
>
> >
> > As per the RFC, I can see that we can include multiple RDNSS addressed in
> > the RA message, where as this patch restricts to just 1 address.
> > Any particular reason for this ?
>
> packet_put_ra_rdnss_opt supports 'multiple' rdnss addresses but for the
> moment
> northd (just for simplicity) adds a single server address. I think we can
> add
> multiple server support in the future if needed. What do you think?
>

I am fine with it. Can you please add this limitation to the documentation.

Thanks
Numan


>
> Regards,
> Lorenzo
>
> >
> > Thanks
> > Numan
> >
> >
> >
> > >  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,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/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 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@openvswitch.org
> > > https://mail.openvswitch.org/mailman/listinfo/ovs-dev
> > >
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>

Patch
diff mbox series

diff --git a/controller/pinctrl.c b/controller/pinctrl.c
index d826da186..1125f2ef3 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,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/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 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