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
Signed-off-by: Lorenzo Bianconi
---
controller/pinctrl.c | 41 +
lib/ovn-l7.h | 12
northd/ovn-northd.c | 5 +
ovn-nb.xml | 5 +
tests/ovn.at | 27 +++
5 files changed, 82 insertions(+), 8 deletions(-)
diff --git a/controller/pinctrl.c b/controller/pinctrl.c
index d826da186..1eaa53ad1 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,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;
+put_16aligned_be32(&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 +2380,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(0x),
+&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..44ad02949 100644
--- a/lib/ovn-l7.h
+++ b/lib/ovn-l7.h
@@ -220,6 +220,18 @@ struct dhcpv6_opt_ia_na {
ovs_be32 t2;
});
+/* RDNSS option RFC 6106 */
+#define ND_RDNSS_OPT_LEN8
+#define ND_OPT_RDNSS25
+struct nd_rdnss_opt {
+uint8_t type; /* ND_OPT_RDNSS. */
+uint8_t len; /* >= 3. */
+ovs_be16 reserved;/* Always 0. */
+ovs_16aligned_be32 lifetime;
+const ovs_be128 dns[0];
+};
+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 ,
i.e. 200 seconds if that key is unset.
+
+
+IPv6 address of RDNSS server announced in RA packets. At the moment
+OVN supports just one RDNSS server.
+
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() {