From patchwork Fri Nov 26 23:12:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valerio X-Patchwork-Id: 1560360 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WAVfFIRq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J19X31Yp0z9sS8 for ; Sat, 27 Nov 2021 10:13:06 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 3E9FE607B7; Fri, 26 Nov 2021 23:13:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id poK5zBEdidxC; Fri, 26 Nov 2021 23:13:04 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 391D1607C0; Fri, 26 Nov 2021 23:13:03 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id F2825C001C; Fri, 26 Nov 2021 23:13:02 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 060A8C000A for ; Fri, 26 Nov 2021 23:13:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 55E4C40247 for ; Fri, 26 Nov 2021 23:13:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JNdjY4VVal5A for ; Fri, 26 Nov 2021 23:12:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id 4AF674040A for ; Fri, 26 Nov 2021 23:12:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637968378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k9olOafwDpnicnG0WXBMuUlvRLcV3/Dp8Vpjf0mOceE=; b=WAVfFIRqEnDC28WIbF3J3z3VdkrVFfgp1Za1Q4HB2eLc/py0k0n+x/nyex8i7kaK+rsQWQ Sjc+zZ+Q040cCuf6eh5wEmh2HLD+vjaT8PWnUFDzDoDMe9jO3idJLBAs9JkJUa3R+LQj0R 6WjWPlFPHPQTvCbynrTJVrOGP4krd+I= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-349-1H_mU3ptMhm-3y0Hz_z-2w-1; Fri, 26 Nov 2021 18:12:55 -0500 X-MC-Unique: 1H_mU3ptMhm-3y0Hz_z-2w-1 Received: by mail-ed1-f71.google.com with SMTP id l15-20020a056402124f00b003e57269ab87so9005025edw.6 for ; Fri, 26 Nov 2021 15:12:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=k9olOafwDpnicnG0WXBMuUlvRLcV3/Dp8Vpjf0mOceE=; b=3eqGuklxNTHbgGdZg0Uc2UiZWtawPfVC0yTVbXSJfxCdcL56nUYeX2Vs5zxQaw8J2D MkWGS2681H8+k6kblUBOEEFuxVFDA6DP3XksIFL6Jo+Thoo3BZz+YxqoMagkLdOvk4HO 56kzwKZKEdqnkG1NN7gCUCf4MSSiclHAwyR0JAHOaWYBKoizpG+pX+9Xb/j2mh/r23uV jkyh0huWHZVufqT/lAdUkyEvC4puAAN4NDK2koBz117q4cYF7fkzRphbgp2WW8qM5lEg FxxKxjpHpQ/SvGsfdWA18hQpZBOzu7VIrSVzk2Bl/Wq6GbNVHNeavhR4UjGUhqbbwaIr JwrA== X-Gm-Message-State: AOAM532F6h9YuxY4HwLT+WdsnjwWPQdqjyvRezaKpylz1zXxRvbe1voL 89ONW48RU/BlV00zFWvKf6UVZhssnv72uH+XVeyq4j7JZPF9p4XTP2924tXGJMI6Lknah94KoOv inu8XLJwaLzxQFDPgsehZRZCeOgVxflqcet8UDRF5CGPrxZ+BdKsiDBpg/yTPwVsG X-Received: by 2002:aa7:c50b:: with SMTP id o11mr51312053edq.160.1637968373540; Fri, 26 Nov 2021 15:12:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwndmZuUyYMVk1kRfOMmzSNhwtEJ7/netHYTxlvJopW95efT5i0WQgRZlO6tdZ5XhgQhE2x2g== X-Received: by 2002:aa7:c50b:: with SMTP id o11mr51311998edq.160.1637968373099; Fri, 26 Nov 2021 15:12:53 -0800 (PST) Received: from localhost (net-5-88-23-84.cust.vodafonedsl.it. [5.88.23.84]) by smtp.gmail.com with ESMTPSA id em21sm3591976ejc.103.2021.11.26.15.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Nov 2021 15:12:52 -0800 (PST) From: Paolo Valerio To: dev@openvswitch.org Date: Sat, 27 Nov 2021 00:12:51 +0100 Message-ID: <163796837184.2039297.4052998257738616063.stgit@fed.void> In-Reply-To: <163796835468.2039297.16532895596358134508.stgit@fed.void> References: <163796835468.2039297.16532895596358134508.stgit@fed.void> User-Agent: StGit/1.1 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pvalerio@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: fbl@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v3 2/4] Native tunnel: Add tnl/neigh/aging command. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" with the command is now possible to change the aging time of the cache entries. For the existing entries the aging time is updated only if the current expiration is greater than the new one. In any case, the next refresh will set it to the new value. This is intended mostly for debugging purpose. Signed-off-by: Paolo Valerio Acked-by: Flavio Leitner --- v3: - turned NEIGH_ENTRY_MAX_AGEING_TIME -> NEIGH_ENTRY_MAX_AGEING_TIME_S v2: - fixed NEIGH_ENTRY_MAX_AGEING_TIME (turned to seconds) correcting a leftover. - turned relaxed atomics to acq/rel. - added range checks to tunnel-push-pop.at. It was useless to duplicate the test for both ipv6 and ipv4, so only the latter includes it. - slightly modified the NEWS entry. --- NEWS | 2 + lib/tnl-neigh-cache.c | 79 +++++++++++++++++++++++++++++++++++---- ofproto/ofproto-tnl-unixctl.man | 9 ++++ tests/tunnel-push-pop-ipv6.at | 30 +++++++++++++++ tests/tunnel-push-pop.at | 47 +++++++++++++++++++++++ 5 files changed, 158 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 434ee570f..1aa233a0d 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,8 @@ Post-v2.16.0 - ovs-dpctl and 'ovs-appctl dpctl/': * New commands 'cache-get-size' and 'cache-set-size' that allows to get or configure linux kernel datapath cache sizes. + - ovs-appctl: + * New command tnl/neigh/aging to read/write the neigh aging time. v2.16.0 - 16 Aug 2021 diff --git a/lib/tnl-neigh-cache.c b/lib/tnl-neigh-cache.c index 1e6cc31db..0b9098011 100644 --- a/lib/tnl-neigh-cache.c +++ b/lib/tnl-neigh-cache.c @@ -46,6 +46,7 @@ #define NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS (15 * 60 * 1000) +#define NEIGH_ENTRY_MAX_AGING_TIME_S 3600 struct tnl_neigh_entry { struct cmap_node cmap_node; @@ -57,6 +58,7 @@ struct tnl_neigh_entry { static struct cmap table = CMAP_INITIALIZER; static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER; +static atomic_uint32_t neigh_aging; static uint32_t tnl_neigh_hash(const struct in6_addr *ip) @@ -74,6 +76,15 @@ tnl_neigh_expired(struct tnl_neigh_entry *neigh) return expires <= time_msec(); } +static uint32_t +tnl_neigh_get_aging(void) +{ + unsigned int aging; + + atomic_read_explicit(&neigh_aging, &aging, memory_order_acquire); + return aging; +} + static struct tnl_neigh_entry * tnl_neigh_lookup__(const char br_name[IFNAMSIZ], const struct in6_addr *dst) { @@ -88,7 +99,7 @@ tnl_neigh_lookup__(const char br_name[IFNAMSIZ], const struct in6_addr *dst) } atomic_store_explicit(&neigh->expires, time_msec() + - NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS, + tnl_neigh_get_aging(), memory_order_release); return neigh; } @@ -134,7 +145,7 @@ tnl_neigh_set__(const char name[IFNAMSIZ], const struct in6_addr *dst, if (neigh) { if (eth_addr_equals(neigh->mac, mac)) { atomic_store_relaxed(&neigh->expires, time_msec() + - NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS); + tnl_neigh_get_aging()); ovs_mutex_unlock(&mutex); return; } @@ -147,7 +158,7 @@ tnl_neigh_set__(const char name[IFNAMSIZ], const struct in6_addr *dst, neigh->ip = *dst; neigh->mac = mac; atomic_store_relaxed(&neigh->expires, time_msec() + - NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS); + tnl_neigh_get_aging()); ovs_strlcpy(neigh->br_name, name, sizeof neigh->br_name); cmap_insert(&table, &neigh->cmap_node, tnl_neigh_hash(&neigh->ip)); ovs_mutex_unlock(&mutex); @@ -273,6 +284,45 @@ tnl_neigh_cache_flush(struct unixctl_conn *conn, int argc OVS_UNUSED, unixctl_command_reply(conn, "OK"); } +static void +tnl_neigh_cache_aging(struct unixctl_conn *conn, int argc, + const char *argv[], void *aux OVS_UNUSED) +{ + long long int new_exp, curr_exp; + struct tnl_neigh_entry *neigh; + uint32_t aging; + + if (argc == 1) { + struct ds ds = DS_EMPTY_INITIALIZER; + ds_put_format(&ds, "%"PRIu32, tnl_neigh_get_aging() / 1000); + unixctl_command_reply(conn, ds_cstr(&ds)); + ds_destroy(&ds); + + return; + } + + if (!ovs_scan(argv[1], "%"SCNu32, &aging) || + !aging || aging > NEIGH_ENTRY_MAX_AGING_TIME_S) { + unixctl_command_reply_error(conn, "bad aging value"); + return; + } + + aging *= 1000; + atomic_store_explicit(&neigh_aging, aging, memory_order_release); + new_exp = time_msec() + aging; + + CMAP_FOR_EACH (neigh, cmap_node, &table) { + atomic_read_explicit(&neigh->expires, &curr_exp, + memory_order_acquire); + if (new_exp < curr_exp) { + atomic_store_explicit(&neigh->expires, new_exp, + memory_order_release); + } + } + + unixctl_command_reply(conn, "OK"); +} + static int lookup_any(const char *host_name, struct in6_addr *address) { @@ -347,10 +397,21 @@ tnl_neigh_cache_show(struct unixctl_conn *conn, int argc OVS_UNUSED, void tnl_neigh_cache_init(void) { - unixctl_command_register("tnl/arp/show", "", 0, 0, tnl_neigh_cache_show, NULL); - unixctl_command_register("tnl/arp/set", "BRIDGE IP MAC", 3, 3, tnl_neigh_cache_add, NULL); - unixctl_command_register("tnl/arp/flush", "", 0, 0, tnl_neigh_cache_flush, NULL); - unixctl_command_register("tnl/neigh/show", "", 0, 0, tnl_neigh_cache_show, NULL); - unixctl_command_register("tnl/neigh/set", "BRIDGE IP MAC", 3, 3, tnl_neigh_cache_add, NULL); - unixctl_command_register("tnl/neigh/flush", "", 0, 0, tnl_neigh_cache_flush, NULL); + atomic_init(&neigh_aging, NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS); + unixctl_command_register("tnl/arp/show", "", 0, 0, + tnl_neigh_cache_show, NULL); + unixctl_command_register("tnl/arp/set", "BRIDGE IP MAC", 3, 3, + tnl_neigh_cache_add, NULL); + unixctl_command_register("tnl/arp/flush", "", 0, 0, + tnl_neigh_cache_flush, NULL); + unixctl_command_register("tnl/arp/aging", "[SECS]", 0, 1, + tnl_neigh_cache_aging, NULL); + unixctl_command_register("tnl/neigh/show", "", 0, 0, + tnl_neigh_cache_show, NULL); + unixctl_command_register("tnl/neigh/set", "BRIDGE IP MAC", 3, 3, + tnl_neigh_cache_add, NULL); + unixctl_command_register("tnl/neigh/flush", "", 0, 0, + tnl_neigh_cache_flush, NULL); + unixctl_command_register("tnl/neigh/aging", "[SECS]", 0, 1, + tnl_neigh_cache_aging, NULL); } diff --git a/ofproto/ofproto-tnl-unixctl.man b/ofproto/ofproto-tnl-unixctl.man index c70cca539..13a465119 100644 --- a/ofproto/ofproto-tnl-unixctl.man +++ b/ofproto/ofproto-tnl-unixctl.man @@ -27,6 +27,15 @@ to \fImac\fR. .IP "\fBtnl/arp/flush\fR" Flush ARP table. . +.IP "\fBtnl/neigh/aging [\fIseconds\fB]\fR" +.IP "\fBtnl/arp/aging [\fIseconds\fB]\fR" +Changes the aging time. The accepted values of \fIseconds\fR are +between 1 and 3600. The new entries will get the value as specified in +\fIseconds\fR. For the existing entries, the aging time is updated +only if the current expiration is greater than \fIseconds\fR. +.IP +If used without arguments, it prints the current aging value. +. .IP "\fBtnl/egress_port_range [num1] [num2]\fR" Set range for UDP source port used for UDP based Tunnels. For example VxLAN. If case of zero arguments this command prints diff --git a/tests/tunnel-push-pop-ipv6.at b/tests/tunnel-push-pop-ipv6.at index 59723e63b..327c0e61e 100644 --- a/tests/tunnel-push-pop-ipv6.at +++ b/tests/tunnel-push-pop-ipv6.at @@ -255,6 +255,36 @@ AT_CHECK([cat p0.pcap.txt | grep 93aa55aa55000086dd6000000000203aff2001cafe | un 3333ff000093aa55aa55000086dd6000000000203aff2001cafe000000000000000000000088ff0200000000000000000001ff00009387004d46000000002001cafe0000000000000000000000930101aa55aa550000 ]) +dnl Set the aging time to 5 seconds +AT_CHECK([ovs-appctl tnl/neigh/aging 5], [0], [OK +]) + +dnl Read the current aging time +AT_CHECK([ovs-appctl tnl/neigh/aging], [0], [5 +]) + +dnl Add an entry +AT_CHECK([ovs-appctl tnl/neigh/set br0 2001:cafe::92 aa:bb:cc:00:00:01], [0], [OK +]) + +AT_CHECK([ovs-appctl tnl/neigh/show | grep br0 | sort], [0], [dnl +2001:cafe::92 aa:bb:cc:00:00:01 br0 +]) + +ovs-appctl time/warp 5000 + +dnl Check the entry has been removed +AT_CHECK([ovs-appctl tnl/neigh/show | grep br0 | sort], [0], [dnl +]) + +dnl Restore the aging time to 900s (default) +AT_CHECK([ovs-appctl tnl/neigh/aging 900], [0], [OK +]) + +dnl Read the current aging time +AT_CHECK([ovs-appctl tnl/neigh/aging], [0], [900 +]) + dnl Check ARP Snoop AT_CHECK([ovs-appctl netdev-dummy/receive p0 'in_port(1),eth(src=f8:bc:12:44:34:c8,dst=aa:55:aa:55:00:00),eth_type(0x86dd),ipv6(src=2001:cafe::92,dst=2001:cafe::88,label=0,proto=58,tclass=0,hlimit=255,frag=no),icmpv6(type=136,code=0),nd(target=2001:cafe::92,sll=00:00:00:00:00:00,tll=f8:bc:12:44:34:c8)']) diff --git a/tests/tunnel-push-pop.at b/tests/tunnel-push-pop.at index 636465397..1f6249b20 100644 --- a/tests/tunnel-push-pop.at +++ b/tests/tunnel-push-pop.at @@ -270,6 +270,53 @@ AT_CHECK([cat p0.pcap.txt | grep 101025d | uniq], [0], [dnl ffffffffffffaa55aa55000008060001080006040001aa55aa550000010102580000000000000101025d ]) +dnl Check input range +AT_CHECK([ovs-appctl tnl/neigh/aging 0], [2], [], [dnl +bad aging value +ovs-appctl: ovs-vswitchd: server returned an error +]) + +AT_CHECK([ovs-appctl tnl/neigh/aging 3601], [2], [], [dnl +bad aging value +ovs-appctl: ovs-vswitchd: server returned an error +]) + +AT_CHECK([ovs-appctl tnl/neigh/aging 1], [0], [OK +]) + +AT_CHECK([ovs-appctl tnl/neigh/aging 3600], [0], [OK +]) + +dnl Set the aging time to 5 seconds +AT_CHECK([ovs-appctl tnl/neigh/aging 5], [0], [OK +]) + +dnl Read the current aging time +AT_CHECK([ovs-appctl tnl/neigh/aging], [0], [5 +]) + +dnl Add an entry +AT_CHECK([ovs-appctl tnl/neigh/set br0 1.1.2.92 aa:bb:cc:00:00:01], [0], [OK +]) + +AT_CHECK([ovs-appctl tnl/neigh/show | grep br0 | sort], [0], [dnl +1.1.2.92 aa:bb:cc:00:00:01 br0 +]) + +ovs-appctl time/warp 5000 + +dnl Check the entry has been removed +AT_CHECK([ovs-appctl tnl/neigh/show | grep br0 | sort], [0], [dnl +]) + +dnl Restore the aging time to 900s (default) +AT_CHECK([ovs-appctl tnl/neigh/aging 900], [0], [OK +]) + +dnl Read the current aging time +AT_CHECK([ovs-appctl tnl/neigh/aging], [0], [900 +]) + dnl Check ARP Snoop AT_CHECK([ovs-appctl netdev-dummy/receive p0 'recirc_id(0),in_port(1),eth(src=f8:bc:12:44:34:c8,dst=ff:ff:ff:ff:ff:ff),eth_type(0x0806),arp(sip=1.1.2.92,tip=1.1.2.88,op=2,sha=f8:bc:12:44:34:c8,tha=00:00:00:00:00:00)'])