Introduce support for Route Info Option sent in Router Advertisement according to RFC 4191. Route Info Option are configured providing route_info in ipv6_ra_configs column of Logical_Router_Port table. route_info is a comma separated string where each field provides PRF and prefix for a given route (e.g: HIGH-aef1::11/48,LOW-aef2::11/96)
Signed-off-by: Lorenzo Bianconi <lorenzo.bianc...@redhat.com> --- controller/pinctrl.c | 80 ++++++++++++++++++++++++++++++++++++++++++++ lib/ovn-l7.h | 12 +++++++ northd/ovn-northd.c | 6 ++++ ovn-nb.xml | 14 ++++++++ tests/ovn.at | 32 ++++++++++++------ 5 files changed, 133 insertions(+), 11 deletions(-) diff --git a/controller/pinctrl.c b/controller/pinctrl.c index b736b60ad..51c7f8a36 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -2195,6 +2195,7 @@ struct ipv6_ra_config { struct in6_addr rdnss; bool has_rdnss; struct ds dnssl; + struct ds route_info; }; struct ipv6_ra_state { @@ -2217,6 +2218,7 @@ ipv6_ra_config_delete(struct ipv6_ra_config *config) if (config) { destroy_lport_addresses(&config->prefixes); ds_destroy(&config->dnssl); + ds_destroy(&config->route_info); free(config); } } @@ -2256,6 +2258,7 @@ ipv6_ra_update_config(const struct sbrec_port_binding *pb) 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); + ds_init(&config->route_info); const char *address_mode = smap_get(&pb->options, "ipv6_ra_address_mode"); if (!address_mode) { @@ -2313,6 +2316,11 @@ ipv6_ra_update_config(const struct sbrec_port_binding *pb) ds_put_buffer(&config->dnssl, dnssl, strlen(dnssl)); } + const char *route_info = smap_get(&pb->options, "ipv6_ra_route_info"); + if (route_info) { + ds_put_buffer(&config->route_info, route_info, strlen(route_info)); + } + return config; fail: @@ -2420,6 +2428,74 @@ packet_put_ra_dnssl_opt(struct dp_packet *b, ovs_be32 lifetime, prev_l4_size + size)); } +static void +packet_put_ra_route_info_opt(struct dp_packet *b, ovs_be32 lifetime, + char *route_list) +{ + size_t prev_l4_size = dp_packet_l4_size(b); + struct ip6_hdr *nh = dp_packet_l3(b); + char *t0, *r0 = NULL; + size_t size = 0; + + for (t0 = strtok_r(route_list, ",", &r0); t0; + t0 = strtok_r(NULL, ",", &r0)) { + struct ovs_nd_route_info *nd_rinfo = + dp_packet_put_uninit(b, sizeof *nd_rinfo); + char *t1, *r1 = NULL; + int index; + + for (t1 = strtok_r(t0, "-", &r1), index = 0; t1; + t1 = strtok_r(NULL, "-", &r1), index++) { + + nd_rinfo->type = ND_OPT_ROUTE_INFO; + nd_rinfo->route_lifetime = lifetime; + + switch (index) { + case 0: + if (!strcmp(t1, "HIGH")) { + nd_rinfo->flags = IPV6_ND_RA_OPT_PRF_HIGH; + } else if (!strcmp(t1, "LOW")) { + nd_rinfo->flags = IPV6_ND_RA_OPT_PRF_LOW; + } else { + nd_rinfo->flags = IPV6_ND_RA_OPT_PRF_NORMAL; + } + break; + case 1: { + struct lport_addresses route; + uint8_t plen; + + if (!extract_ip_addresses(t1, &route)) { + return; + } + if (!route.n_ipv6_addrs) { + destroy_lport_addresses(&route); + return; + } + + nd_rinfo->prefix_len = route.ipv6_addrs->plen; + plen = DIV_ROUND_UP(nd_rinfo->prefix_len, 64); + nd_rinfo->len = 1 + plen; + dp_packet_put(b, &route.ipv6_addrs->network, plen * 8); + size += sizeof *nd_rinfo + plen * 8; + + destroy_lport_addresses(&route); + index = 0; + break; + } + default: + return; + } + } + } + + nh->ip6_plen = htons(prev_l4_size + size); + 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) @@ -2459,6 +2535,10 @@ ipv6_ra_send(struct rconn *swconn, struct ipv6_ra_state *ra) packet_put_ra_dnssl_opt(&packet, htonl(0xffffffff), ra->config->dnssl.string); } + if (ra->config->route_info.length) { + packet_put_ra_route_info_opt(&packet, htonl(0xffffffff), + ra->config->route_info.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 fd898b0dc..ae6dbfdfb 100644 --- a/lib/ovn-l7.h +++ b/lib/ovn-l7.h @@ -242,6 +242,18 @@ struct ovs_nd_dnssl { }; BUILD_ASSERT_DECL(ND_DNSSL_OPT_LEN == sizeof(struct ovs_nd_dnssl)); +/* Route Information option RFC 4191 */ +#define ND_OPT_ROUTE_INFO 24 +#define ND_ROUTE_INFO_OPT_LEN 8 +struct ovs_nd_route_info { + u_int8_t type; /* ND_OPT_ROUTE_INFO */ + u_int8_t len; /* 1, 2 or 3 */ + u_int8_t prefix_len; + u_int8_t flags; + ovs_be32 route_lifetime; +}; +BUILD_ASSERT_DECL(ND_ROUTE_INFO_OPT_LEN == sizeof(struct ovs_nd_route_info)); + #define DHCPV6_DUID_LL 3 #define DHCPV6_HW_TYPE_ETH 1 diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index a1eaa9071..8785cbbf3 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -6764,6 +6764,12 @@ copy_ra_to_sb(struct ovn_port *op, const char *address_mode) smap_add(&options, "ipv6_ra_prf", prf); } + const char *route_info = smap_get(&op->nbrp->ipv6_ra_configs, + "route_info"); + if (route_info) { + smap_add(&options, "ipv6_ra_route_info", route_info); + } + sbrec_port_binding_set_options(op->sb, &options); smap_destroy(&options); } diff --git a/ovn-nb.xml b/ovn-nb.xml index 89d23ad7b..5f7ec76ee 100644 --- a/ovn-nb.xml +++ b/ovn-nb.xml @@ -1871,6 +1871,20 @@ </ul> </column> + <column name="ipv6_ra_configs" key="route_info"> + Route Info is used to configure Route Info Option sent in Router + Advertisment according to RFC 4191. Route Info is a comma + separated string where each field provides PRF and prefix for a + given route (e.g: HIGH-aef1::11/48,LOW-aef2::11/96) + Possible PRF values are: + + <ul> + <li>HIGH: mapped to 0x01 in RA PRF field</li> + <li>MEDIUM: mapped to 0x00 in RA PRF field</li> + <li>LOW: mapped to 0x11 in RA PRF field</li> + </ul> + </column> + <column name="ipv6_ra_configs" key="mtu"> The recommended MTU for the link. Default is 0, which means no MTU Option will be included in RA packet replied by ovn-controller. diff --git a/tests/ovn.at b/tests/ovn.at index 85d539c78..6c14a40b0 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -11433,14 +11433,15 @@ construct_expected_ra() { local ra_mo=$2 local rdnss=$3 local dnssl=$4 - local ra_prefix_la=$5 + local route_info=$5 + local ra_prefix_la=$6 local slla=0101${src_mac} local mtu_opt="" if test $mtu != 0; then mtu_opt=05010000${mtu} fi - shift 5 + shift 6 local prefix="" while [[ $# -gt 0 ]] ; do @@ -11458,8 +11459,12 @@ construct_expected_ra() { if test $dnssl != 0; then dnssl_opt=1f030000ffffffff${dnssl} fi + local route_info_opt="" + if test $route_info != 0; then + route_info_opt=${route_info} + fi - local ra=ff${ra_mo}ffff0000000000000000${slla}${mtu_opt}${prefix}${rdnss_opt}${dnssl_opt} + local ra=ff${ra_mo}ffff0000000000000000${slla}${mtu_opt}${prefix}${rdnss_opt}${dnssl_opt}${route_info_opt} local icmp=8600XXXX${ra} local ip_len=$(expr ${#icmp} / 2) @@ -11494,38 +11499,43 @@ ra_test() { } # Baseline test with no MTU -ra_test 0 00 0 0 c0 40 aef00000000000000000000000000000 +ra_test 0 00 0 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 0 c0 40 aef00000000000000000000000000000 +ra_test 000005dc 00 0 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 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000 +ra_test 000005dc 00 0 0 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000 # Test PRF for default gw ovn-nbctl --wait=hv set Logical_Router_port ro-sw ipv6_ra_configs:prf="LOW" -ra_test 000005dc 18 0 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000 +ra_test 000005dc 18 0 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 18 $dns_addr 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000 +ra_test 000005dc 18 $dns_addr 0 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" ovn-nbctl --wait=hv set Logical_Router_port ro-sw ipv6_ra_configs:prf="HIGH" dnssl=02616102626202636300000000000000 -ra_test 000005dc 08 $dns_addr $dnssl c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000 +ra_test 000005dc 08 $dns_addr $dnssl 0 c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000 + +# Now test Route Info option +ovn-nbctl --wait=hv set Logical_Router_port ro-sw ipv6_ra_configs:route_info="HIGH-aef1::11/48,LOW-aef2::11/96" +route_info=18023008ffffffffaef100000000000018036018ffffffffaef20000000000000000000000000000 +ra_test 000005dc 08 $dns_addr $dnssl $route_info 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 88 $dns_addr $dnssl 80 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000 +ra_test 000005dc 88 $dns_addr $dnssl $route_info 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 48 $dns_addr $dnssl c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000 +ra_test 000005dc 48 $dns_addr $dnssl $route_info c0 40 aef00000000000000000000000000000 30 fd0f0000000000000000000000000000 OVN_CLEANUP([hv1],[hv2]) AT_CLEANUP -- 2.21.0 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev