From owner-dev-commits-src-branches@freebsd.org Wed Jun 16 11:46:02 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 773F6660E9C; Wed, 16 Jun 2021 11:46:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4G4k0V2jRLz3j7q; Wed, 16 Jun 2021 11:46:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3AB811B29A; Wed, 16 Jun 2021 11:46:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 15GBk2io035409; Wed, 16 Jun 2021 11:46:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15GBk2Vk035408; Wed, 16 Jun 2021 11:46:02 GMT (envelope-from git) Date: Wed, 16 Jun 2021 11:46:02 GMT Message-Id: <202106161146.15GBk2Vk035408@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Lutz Donnerhacke Subject: git: 1818c5a49a99 - stable/12 - tests/netgraph: Tests for ng_hub MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: donner X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 1818c5a49a99da36ade0fe5e347c5b389dc90a00 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jun 2021 11:46:02 -0000 The branch stable/12 has been updated by donner: URL: https://cgit.FreeBSD.org/src/commit/?id=1818c5a49a99da36ade0fe5e347c5b389dc90a00 commit 1818c5a49a99da36ade0fe5e347c5b389dc90a00 Author: Lutz Donnerhacke AuthorDate: 2021-06-03 22:22:29 +0000 Commit: Lutz Donnerhacke CommitDate: 2021-06-16 11:44:15 +0000 tests/netgraph: Tests for ng_hub Test functionality of ng_hub(4): - replicting traffic to anything but the sending hook - persistence - an unrestricted loop - implementation limits with many hooks. Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D30633 (cherry picked from commit 7863faa78ae271017c404c635b2a9d07379d4316) --- tests/sys/netgraph/Makefile | 2 + tests/sys/netgraph/hub.c | 231 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 233 insertions(+) diff --git a/tests/sys/netgraph/Makefile b/tests/sys/netgraph/Makefile index 7ec036139850..9c5faedbc8e1 100644 --- a/tests/sys/netgraph/Makefile +++ b/tests/sys/netgraph/Makefile @@ -7,9 +7,11 @@ BINDIR= ${TESTSDIR} ATF_TESTS_C+= basic \ bridge \ + hub \ SRCS.basic= basic.c util.c SRCS.bridge= bridge.c util.c +SRCS.hub= hub.c util.c LIBADD+= netgraph diff --git a/tests/sys/netgraph/hub.c b/tests/sys/netgraph/hub.c new file mode 100644 index 000000000000..08d083ad9605 --- /dev/null +++ b/tests/sys/netgraph/hub.c @@ -0,0 +1,231 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright 2021 Lutz Donnerhacke + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include +#include +#include + +#include "util.h" + +ATF_TC(basic); +ATF_TC_HEAD(basic, conf) +{ + atf_tc_set_md_var(conf, "require.user", "root"); +} + +ATF_TC_BODY(basic, dummy) +{ + char msg[] = "test"; + ng_counter_t r; + + ng_errors(PASS); + ng_shutdown("hub:"); + ng_errors(FAIL); + + ng_init(); + ng_mkpeer(".", "a", "hub", "a"); + ng_name("a", "hub"); + ng_connect(".", "b", "hub:", "b"); + ng_connect(".", "c", "hub:", "c"); + + /* do not bounce back */ + ng_register_data("a", get_data0); + ng_counter_clear(r); + ng_send_data("a", msg, sizeof(msg)); + ng_handle_events(50, r); + ATF_CHECK(r[0] == 0); + + /* send to others */ + ng_register_data("b", get_data0); + ng_register_data("c", get_data0); + ng_counter_clear(r); + ng_send_data("a", msg, sizeof(msg)); + ng_handle_events(50, r); + ATF_CHECK(r[0] == 2); + + ng_counter_clear(r); + ng_send_data("b", msg, sizeof(msg)); + ng_handle_events(50, r); + ATF_CHECK(r[0] == 2); + + ng_counter_clear(r); + ng_send_data("c", msg, sizeof(msg)); + ng_handle_events(50, r); + ATF_CHECK(r[0] == 2); + + /* remove a link */ + ng_rmhook(".", "b"); + ng_counter_clear(r); + ng_send_data("a", msg, sizeof(msg)); + ng_handle_events(50, r); + ATF_CHECK(r[0] == 1); + + ng_shutdown("hub:"); +} + +ATF_TC(persistence); +ATF_TC_HEAD(persistence, conf) +{ + atf_tc_set_md_var(conf, "require.user", "root"); +} + +ATF_TC_BODY(persistence, dummy) +{ + ng_errors(PASS); + ng_shutdown("hub:"); + ng_errors(FAIL); + + ng_init(); + ng_mkpeer(".", "a", "hub", "a"); + ng_name("a", "hub"); + + ng_send_msg("hub:", "setpersistent"); + ng_rmhook(".", "a"); + + ng_shutdown("hub:"); +} + +ATF_TC(loop); +ATF_TC_HEAD(loop, conf) +{ + atf_tc_set_md_var(conf, "require.user", "root"); +} + +ATF_TC_BODY(loop, dummy) +{ + ng_counter_t r; + int i; + char msg[] = "LOOP Alert!"; + + ng_errors(PASS); + ng_shutdown("hub1:"); + ng_shutdown("hub2:"); + ng_errors(FAIL); + + ng_init(); + ng_mkpeer(".", "a", "hub", "a"); + ng_name("a", "hub1"); + ng_mkpeer(".", "b", "hub", "b"); + ng_name("b", "hub2"); + + ng_register_data("a", get_data0); + ng_register_data("b", get_data0); + + /*- + * Open loop + * + * /-- hub1 + * . < | + * \-- hub2 + */ + ng_connect("hub1:", "xc1", "hub2:", "xc1"); + + ng_counter_clear(r); + ng_send_data("a", msg, sizeof(msg)); + ng_handle_events(50, r); + ATF_CHECK(r[0] == 1); + + /*- + * Closed loop, DANGEROUS! + * + * /-- hub1 -\ + * . < | | + * \-- hub2 -/ + */ + ng_connect("hub1:", "xc2", "hub2:", "xc2"); + + ng_counter_clear(r); + ng_send_data("a", msg, sizeof(msg)); + for (i = 0; i < 10; i++) /* don't run forever */ + if (!ng_handle_event(50, r)) + break; + ATF_CHECK(r[0] > 7); + + ng_shutdown("hub1:"); + ng_shutdown("hub2:"); +} + +ATF_TC(many_hooks); +ATF_TC_HEAD(many_hooks, conf) +{ + atf_tc_set_md_var(conf, "require.user", "root"); +} + +ATF_TC_BODY(many_hooks, dummy) +{ + ng_counter_t r; + int i; + char msg[] = "test"; + const int HOOKS = 1000; + + ng_errors(PASS); + ng_shutdown("hub:"); + ng_errors(FAIL); + + ng_init(); + ng_mkpeer(".", "a", "hub", "a"); + ng_name("a", "hub"); + + ng_register_data("a", get_data0); + ng_counter_clear(r); + for (i = 0; i < HOOKS; i++) + { + char hook[20]; + + snprintf(hook, sizeof(hook), "hook%d", i); + ng_connect(".", hook, "hub:", hook); + ng_errors(PASS); + ng_send_data(hook, msg, sizeof(msg)); + ng_errors(FAIL); + if (errno != 0) + break; + ng_handle_events(50, r); + } + ATF_CHECK(r[0] > 100); + atf_tc_expect_fail("Implementation limitation (%d)", i); + ATF_CHECK(r[0] == HOOKS); + atf_tc_expect_pass(); + + ng_shutdown("hub:"); +} + + +ATF_TP_ADD_TCS(hub) +{ + ATF_TP_ADD_TC(hub, basic); + ATF_TP_ADD_TC(hub, loop); + ATF_TP_ADD_TC(hub, persistence); + ATF_TP_ADD_TC(hub, many_hooks); + + return atf_no_error(); +}