From patchwork Fri Oct 18 11:09:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1179316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="d+NKDGWj"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46vjxp0NxMz9sPZ for ; Fri, 18 Oct 2019 22:10:36 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D86B8EF6; Fri, 18 Oct 2019 11:10:32 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id AAE4FED3 for ; Fri, 18 Oct 2019 11:10:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id B8283608 for ; Fri, 18 Oct 2019 11:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571397029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6TummQVDIP18Pa1NjWxS+Oy60pVPBOMAO4KK5qZ4S7k=; b=d+NKDGWje+DwQHFh5kpxaO72pQ0vdz5ApbK7qzdVb/bw06gKKGxTOrMf8mPPcOdBqdYXyg mSAp+0UxMaiFHra7fP0MylHVCgDptb/7pf6ZdSi+jbO0cIXAWOg3BKHd1YvG5FHCEWaBAQ D3+H/E/lhswaGi5rfnXmU3LQCfSunhQ= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-138-JmmplsP5M7eBt0vcDhzCZw-1; Fri, 18 Oct 2019 07:10:27 -0400 Received: by mail-wr1-f70.google.com with SMTP id s9so2450504wrw.23 for ; Fri, 18 Oct 2019 04:10:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=lz5TXA8lReJQuXFfm3RUs8shzCXBm4wxYkNk6S3g8pQ=; b=jabO4tBcMYl6Z5BEn8HmpxTRy/12BNJEkdOXQg+1sn61factc9wOHJPuk2UoEeoR9U rOm9pEP8M5yBvpPlIT1LegQQcTK2s41SWFRfDGLM5kTIiTz6OOisNxH75GXpIMDUWIhf v1futWPrUVkfxadH4BBARmcynXjiZfP3iT+guhmuhr6zRaddF1WXL/KQpePR9v60pD5K bgsEt70MuGWXwlDofQaHbtxY0Ja1JuFcG79qExTPwQtk8OtoZ/z6mTMQvQNz4BxpJtGI xVGq0pPv57U6sbxhnU9RLrVs1UGpxiSutOeJeGbESesVhvby7z/UFNa9Bg9YHZCzdISF mvhA== X-Gm-Message-State: APjAAAUo66x2OxdagAG4ye3evDHnIqrpVNO3KKMw5juziGm4CAwr6pjU XUyTax+vwWCj6v7lW5jBONV/mHIVT/yTIGSpQ4EfLBPZdR+WCSyr3N3NRkx8sijjZhfLiUR6JZ4 w4wPrqLHGl25Z X-Received: by 2002:a7b:c1d2:: with SMTP id a18mr7201294wmj.7.1571397026183; Fri, 18 Oct 2019 04:10:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7mxPPvmYlZO9NzvUTvVBIdUR5sII64hk9Eot3bAXEj/r4wksEEfxZp5zJlOMK+yqbzA7crg== X-Received: by 2002:a7b:c1d2:: with SMTP id a18mr7201263wmj.7.1571397025800; Fri, 18 Oct 2019 04:10:25 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id y1sm6103407wrw.6.2019.10.18.04.10.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2019 04:10:24 -0700 (PDT) From: Lorenzo Bianconi To: dev@openvswitch.org Date: Fri, 18 Oct 2019 13:09:48 +0200 Message-Id: <278860271818df83cb95e26b4c4db3dd27485d95.1571396897.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-MC-Unique: JmmplsP5M7eBt0vcDhzCZw-1 X-Mimecast-Spam-Score: 0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH ovn] Add RDNSS support to OVN X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 Acked-by: Mark Michelson --- 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 , i.e. 200 seconds if that key is unset. + + + IPv6 address of RDNSS server announced in RA packets + 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