From nobody Thu May 26 00:07:40 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E19F31AE0461; Thu, 26 May 2022 00:07:40 +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 4L7pCw5lMcz4jWF; Thu, 26 May 2022 00:07:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653523660; 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=h+EVA3UT1IJ2EHdyxPsKHLACx6Vmnz9o0jXgaRAAb90=; b=Vz6raFiEcCYQqqYlG3apd11NcISWgm90fI+sJNwap8w4Lys6+GoCZnKRuA8vJhM+yFiF9j ySi75ItK5/yVWjwxFpJQ5R3nWMmr9EuwSHD1JjsX8jP27/nUHvNSH/Gp0ErcdcNjEs0Tmg remsg8mQ1umS4DCvRkWx5QL5+UG609xAyF5nabrWCWqViqDX78tnpADgTfHzJUg6opRBnO aPEsauGD5SoVpoZoUSx1tAKmEnf6nYoKca81Vw0NHmJMGtV5eYXvDfZRiju/2SyMq4nnkz XNFpzJS7+9uY7FoPe6rIEga5Fi4yGNeZ7BMKwOVeIDj9ZffqNqUp22mB3HDWqQ== 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 A1DC8233BA; Thu, 26 May 2022 00:07:40 +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 24Q07egj034756; Thu, 26 May 2022 00:07:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24Q07e9Y034755; Thu, 26 May 2022 00:07:40 GMT (envelope-from git) Date: Thu, 26 May 2022 00:07:40 GMT Message-Id: <202205260007.24Q07e9Y034755@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John-Mark Gurney Subject: git: 35dc7f8f5dcd - main - dhclient: test against a real (ISC) dhcp server List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jmg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 35dc7f8f5dcd6a061b53b7c526d200320f41c014 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653523660; 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=h+EVA3UT1IJ2EHdyxPsKHLACx6Vmnz9o0jXgaRAAb90=; b=EIskbjB7PmiQZrUHZhvAuJkizyAZQJl9LSy0c2F2gHUhJGDyzUrA3FsWVmoKlglq/ZKbUL AF6cOTy7J+qEPGHObCLIBf8D36LPhqi7wTbK9DgZXFMZe/FIn8YH9tfK7BppdzZjqnuXqD 44jZ+aZ4vXa3r5qf5lrnBZpEqKj+A/ybXLZ6SHwxAv7AZl2PjhNEZLtV0Ngxu36rdSGzn1 8WZEii/YaKrmvTWrUnn1cBp/QTXfSR39XfR8hLl8CmxwIHoeXFgnHghndmTqcs3bIlJW+w YPDJYqakuN+HQKusB47p6+SNvdRAFTTZj0eKh0ee5dM8ekHww5tH7Khtndv1Jw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653523660; a=rsa-sha256; cv=none; b=CEg8Rd+3IjXV35EDUR+bwD2q2ENeDJOmFnAxDW/0AnCRyOm7nVtDMQBgHoytaAfviCS7ZT Ua4yAgyqX5sPaM6c1QILe3KnqZenO+ufnd2AXJWtcNTrvvirYMZNya/OtrwiP09mM2nkim nPIkQI1l8yqFK09ooCDSMUModb8lY7enIkaRdwyQPnM4/3jnUa3rOwJsXZ0AvlRWAQExz8 svVjw7rJlbG+J+7RGZrgtYkNh3Tbofeo3BQc3xCk/mKEZAYst9YzG+nEh+MMFBc2346aYa wEYqEj7JQRkEmyo7hJnuhVTJZFPWevsbbatnn0Ceb8mkhRxyYXNfdn21phtvzg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jmg: URL: https://cgit.FreeBSD.org/src/commit/?id=35dc7f8f5dcd6a061b53b7c526d200320f41c014 commit 35dc7f8f5dcd6a061b53b7c526d200320f41c014 Author: John-Mark Gurney AuthorDate: 2022-05-12 00:04:14 +0000 Commit: John-Mark Gurney CommitDate: 2022-05-26 00:02:38 +0000 dhclient: test against a real (ISC) dhcp server This tests both both normal (untagged), and pcp tagged (VLAN 0) networks which are now common for fiber ISPs. Reviewed by: markj, kp Differential Revision: https://reviews.freebsd.org/D35178 --- sbin/dhclient/tests/Makefile | 2 + sbin/dhclient/tests/pcp.sh | 196 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+) diff --git a/sbin/dhclient/tests/Makefile b/sbin/dhclient/tests/Makefile index 822699c9dd01..ce4c7acb822e 100644 --- a/sbin/dhclient/tests/Makefile +++ b/sbin/dhclient/tests/Makefile @@ -2,6 +2,8 @@ .PATH: ${.CURDIR:H} +ATF_TESTS_SH= pcp + PLAIN_TESTS_C= option-domain-search_test SRCS.option-domain-search_test= alloc.c convert.c hash.c options.c \ tables.c fake.c option-domain-search.c diff --git a/sbin/dhclient/tests/pcp.sh b/sbin/dhclient/tests/pcp.sh new file mode 100644 index 000000000000..88c39f452f7f --- /dev/null +++ b/sbin/dhclient/tests/pcp.sh @@ -0,0 +1,196 @@ +#!/usr/bin/env atf-sh +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright 2022 John-Mark Gurney +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * 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. +# +# 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 +# OWNER 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. + +# +# Run the tests: +# make WITH_TESTS=yes -j 4 all install && kyua test -k /usr/tests/Kyuafile sbin/dhclient/pcp +# +# Output last run: +# kyua report --verbose -r $(ls -tr ~/.kyua/store/results.*.db | tail -n 1) + +. $(atf_get_srcdir)/../../sys/common/vnet.subr + +generic_dhcp_cleanup() +{ + + # clean up programs + kill $(cat dhclient.test.pid) $(cat dhcpd.pid) + + # clean up files + rm -f dhclient.dhcpd.conf lease.dhclient.test dhclient.test.pid + + vnet_cleanup +} + +atf_test_case normal cleanup +normal_head() +{ + atf_set descr 'test dhclient against a server' + atf_set require.user root +} + +normal_body() +{ + dhcpd=$(which dhcpd) + + if ! [ -x "$dhcpd" ]; then + atf_skip "ISC dhcp server (isc-dhcp44-server) not installed" + fi + + vnet_init + + epair=$(vnet_mkepair) + + vnet_mkjail dhclient_normal_test ${epair}b + + # Set IP on server iface + ifconfig ${epair}a 192.0.2.2/24 up + + # Create dhcp server config + cat > dhclient.dhcpd.conf << EOF +default-lease-time 36000; +max-lease-time 86400; +authoritative; +subnet 192.0.2.0 netmask 255.255.255.0 { + range 192.0.2.10 192.0.2.10; + option routers 192.0.2.2; + option domain-name-servers 192.0.2.2; +} +EOF + + # Start dhcp server + touch dhcpd.leases.conf + atf_check -e ignore ${dhcpd} -cf ./dhclient.dhcpd.conf -lf ./dhcpd.leases.conf -pf ./dhcpd.pid ${epair}a + + # Expect that we get an IP assigned + atf_check -e match:'DHCPACK from 192.0.2.2' jexec dhclient_normal_test dhclient -c /dev/null -l ./lease.dhclient.test -p ./dhclient.test.pid ${epair}b + + # And it's the correct one + atf_check -o match:'inet 192.0.2.10' jexec dhclient_normal_test ifconfig ${epair}b + +} + +normal_cleanup() +{ + + generic_dhcp_cleanup +} + +atf_test_case pcp cleanup +pcp_head() +{ + atf_set descr 'test dhclient on pcp interface' + atf_set require.user root +} + +pcp_body() +{ + dhcpd=$(which dhcpd) + + if ! [ -x "$dhcpd" ]; then + atf_skip "ISC dhcp server (isc-dhcp44-server) not installed" + fi + + vnet_init + + epair=$(vnet_mkepair) + + # Server side needs to be up to pass packets + ifconfig ${epair}a up + + # Make sure necessary netgraph modules are loaded + kldstat -q -n ng_ether || kldload ng_ether + kldstat -q -n ng_iface || kldload ng_iface + kldstat -q -n ng_vlan || kldload ng_vlan + + # create vlan, and attach epair to it (has incoming/outgoing vlan + # 0 tagged frames) + ngctl mkpeer ${epair}a: vlan lower downstream + + # create new interface on other side of vlan (untagged/pcp) + ngctl mkpeer ${epair}a:lower. eiface vlan0 ether + + # get the interface created + ngiface=$(ngctl show ${epair}a:lower.vlan0 | head -n 1 | awk '{ print $2}') + + # schedule it for clean up + echo ${ngiface} >> ngctl.shutdown + + # set the filter on it + ngctl msg ${epair}a:lower. 'addfilter { vlan=0 hook="vlan0" }' + + vnet_mkjail dhclient_pcp_test ${epair}b + + # Set IP on server iface + ifconfig ${ngiface} up 192.0.2.2/24 + + # Set pcp in jail + jexec dhclient_pcp_test ifconfig ${epair}b pcp 0 up + + # Create dhcp server config + cat > dhclient.dhcpd.conf << EOF +default-lease-time 36000; +max-lease-time 86400; +authoritative; +subnet 192.0.2.0 netmask 255.255.255.0 { + range 192.0.2.10 192.0.2.10; + option routers 192.0.2.2; + option domain-name-servers 192.0.2.2; +} +EOF + + # Start dhcp server + touch dhcpd.leases.conf + atf_check -e ignore ${dhcpd} -cf ./dhclient.dhcpd.conf -lf ./dhcpd.leases.conf -pf ./dhcpd.pid ${ngiface} + + # Expect that we get an IP assigned + atf_check -e match:'DHCPACK from 192.0.2.2' jexec dhclient_pcp_test dhclient -c /dev/null -l ./lease.dhclient.test -p ./dhclient.test.pid ${epair}b + + # And it's the correct one + atf_check -o match:'inet 192.0.2.10' jexec dhclient_pcp_test ifconfig ${epair}b +} + +pcp_cleanup() +{ + + generic_dhcp_cleanup + + # Clean up netgraph nodes + for i in $(cat ngctl.shutdown); do + ngctl shutdown ${i}: + done + rm ngctl.shutdown +} + +atf_init_test_cases() +{ + atf_add_test_case normal + atf_add_test_case pcp +} +