From nobody Wed Nov 27 22:27:17 2024 X-Original-To: dev-commits-src-main@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 4XzDZt4NMqz5fsYw; Wed, 27 Nov 2024 22:27:18 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XzDZt0Zp8z4VKT; Wed, 27 Nov 2024 22:27:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732746438; 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=foUVecylVe/VH9dQlHzYYbB3E6yx7VMMdyrzZKHkg04=; b=BalW+3x0W9SVDAO2M35h30gxCiKvSjOug6T0uSZSgUiQnxbsH6p/j+EsqIs+xs/FZRpQdQ 1GWF5NmRvu0WywP5v++OJqA/eEKHPuyM/IRPHfuzpWMvTzF5VYFTIKLSgdupw2itVl2gh+ tnncZjShKMGA0elgJzmUL2s/1a1eMUkBoJzun97JUGchBfkrvsZbohTTgNevcb/tix5Gcn 7I6GHyXBkZc87rkWdNC5TZIudizPS91xfzrbmnQuga47W8HXCHXVx3n96Q+QQwCpWDjh+Q hwz2YslTFYE/jYtqOQgWKXRLmYZbKJS3asiEToR8SGj9Mh5eVQevVtMV+/AEvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732746438; 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=foUVecylVe/VH9dQlHzYYbB3E6yx7VMMdyrzZKHkg04=; b=oHZ5LjOf5UXPhMYgvxZw7uNfPjIQ9IHRpvSbteQ779VMX8qypGFFSdnOySxme1ZncFuaZ0 hCg8UwnTCCLM+S/h6NxnVCR0fVJHEo82QiayFut7TIT4WOxJVZLvCy2pLfskzmswZHLMgG FFQUQc6aFJrqDFPW+aFKsUK6z3jrIFG5Jco6Z8mAJT4Ks0SGoyD5KNiIqD5X6jFXqYfHr+ ciMmel1VLnb7l3oTqVyrSjvuF5jQdpVQ/4wtrGbpCnNLt6dqlQfryodS5MuQlzi3rF0Xmi JiDn71fGMWrZJTSlrO3N8X1WxHtTWhlWZPw2iwOAmNasuBjQ9FqTh83nVxlkdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732746438; a=rsa-sha256; cv=none; b=Smif9/ZPNPjsyGbjBsuV2x93oob6isNNT0IORAOx0sqmvDiwKPi9dBXcgeNzyzk3F6x1K7 kwET4wV9E5C5niTgvwyOAfhLG241W54b7P+yH2IImyJKMB0JErnO/rhZfvmSfeyyRhQ16f 79FVPliURw5KPizlN2llXqBIGsdX4AoccSvGIFzSJXUqGyXmLVXnYVvhYyGJoyqhiwolhM Vn9aFAe3Ps/4lCAVGWalWOMdN/EtNzCObhdYRDUxQABZU7jq/6Sr7tislOsH4kUoUEDLn1 bFgrXzTzGCxvRGj6G2UtQPOdZ+6axQyQyusDzvkrpNZalyNJvO4wI0bp8AWgkA== 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 4XzDZt00JVz1Rwc; Wed, 27 Nov 2024 22:27:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4ARMRHKc026903; Wed, 27 Nov 2024 22:27:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4ARMRHYS026900; Wed, 27 Nov 2024 22:27:17 GMT (envelope-from git) Date: Wed, 27 Nov 2024 22:27:17 GMT Message-Id: <202411272227.4ARMRHYS026900@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jake Freeland Subject: git: 8b63477e5e00 - main - syslogd: Add host forwarding test List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jfree X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8b63477e5e008574cfdc14185e993234244dc908 Auto-Submitted: auto-generated The branch main has been updated by jfree: URL: https://cgit.FreeBSD.org/src/commit/?id=8b63477e5e008574cfdc14185e993234244dc908 commit 8b63477e5e008574cfdc14185e993234244dc908 Author: Jake Freeland AuthorDate: 2024-11-27 22:26:10 +0000 Commit: Jake Freeland CommitDate: 2024-11-27 22:26:10 +0000 syslogd: Add host forwarding test Test communication between hosts by setting up two syslogd instances, each binded to their own addresses, and sending a message from one to the other. The tests passes if the message was delivered and logged successfully. This required some tweaking to the syslogd start and stop routines so they could handle launching multiple syslogd instances with different runtime files. Run the tests in jails with an isolated VNET so they don't fail due to an address bind collision in the host's VNET. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D47649 --- usr.sbin/syslogd/tests/Makefile | 4 ++ usr.sbin/syslogd/tests/syslogd_test.sh | 125 ++++++++++++++++++++++++++++----- 2 files changed, 110 insertions(+), 19 deletions(-) diff --git a/usr.sbin/syslogd/tests/Makefile b/usr.sbin/syslogd/tests/Makefile index 781730a1102a..30972d3fced5 100644 --- a/usr.sbin/syslogd/tests/Makefile +++ b/usr.sbin/syslogd/tests/Makefile @@ -1,5 +1,9 @@ ATF_TESTS_SH+= syslogd_test +# Run in jail with new vnet so we don't need to worry about address conflicts +TEST_METADATA+= execenv="jail" +TEST_METADATA+= execenv_jail_params="vnet=new" # Several syslogd listening on the same port prevent parallel operation TEST_METADATA+= is_exclusive="true" +TEST_METADATA+= timeout=20 .include diff --git a/usr.sbin/syslogd/tests/syslogd_test.sh b/usr.sbin/syslogd/tests/syslogd_test.sh index 08e6d76b9ba6..aa8d48e64f5c 100644 --- a/usr.sbin/syslogd/tests/syslogd_test.sh +++ b/usr.sbin/syslogd/tests/syslogd_test.sh @@ -11,7 +11,7 @@ # # Tests to-do: -# actions: hostname, users +# actions: users readonly SYSLOGD_UDP_PORT="5140" readonly SYSLOGD_CONFIG="${PWD}/syslog.conf" @@ -22,27 +22,72 @@ readonly SYSLOGD_LOCAL_PRIVSOCKET="${PWD}/logpriv.sock" # Start a private syslogd instance. syslogd_start() { - local jail + local jail bind_addr conf_file pid_file socket privsocket + local opt next other_args + + # Setup loopback so we can deliver messages to ourself. + atf_check ifconfig lo0 inet 127.0.0.1/16 + + OPTIND=1 + while getopts ":b:f:j:P:p:S:" opt; do + case "${opt}" in + b) + bind_addr="${OPTARG}" + ;; + f) + conf_file="${OPTARG}" + ;; + j) + jail="jexec ${OPTARG}" + ;; + P) + pid_file="${OPTARG}" + ;; + p) + socket="${OPTARG}" + ;; + S) + privsocket="${OPTARG}" + ;; + ?) + opt="${OPTARG}" + next="$(eval echo \${${OPTIND}})" + + case "${next}" in + -* | "") + other_args="${other_args} -${opt}" + shift $((OPTIND - 1)) + ;; + *) + other_args="${other_args} -${opt} ${next}" + shift ${OPTIND} + ;; + esac + + # Tell getopts to continue parsing. + OPTIND=1 + ;; + :) + atf_fail "The -${OPTARG} flag requires an argument" + ;; + esac + done - if [ "$1" = "-j" ]; then - jail="jexec $2" - shift 2 - fi $jail syslogd \ - -b ":${SYSLOGD_UDP_PORT}" \ + -b "${bind_addr:-":${SYSLOGD_UDP_PORT}"}" \ -C \ -d \ - -f "${SYSLOGD_CONFIG}" \ + -f "${conf_file:-${SYSLOGD_CONFIG}}" \ -H \ - -p "${SYSLOGD_LOCAL_SOCKET}" \ - -P "${SYSLOGD_PIDFILE}" \ - -S "${SYSLOGD_LOCAL_PRIVSOCKET}" \ - $@ \ + -P "${pid_file:-${SYSLOGD_PIDFILE}}" \ + -p "${socket:-${SYSLOGD_LOCAL_SOCKET}}" \ + -S "${privsocket:-${SYSLOGD_LOCAL_PRIVSOCKET}}" \ + ${other_args} \ & # Give syslogd a bit of time to spin up. while [ "$((i+=1))" -le 20 ]; do - [ -S "${SYSLOGD_LOCAL_SOCKET}" ] && return + [ -S "${socket:-${SYSLOGD_LOCAL_SOCKET}}" ] && return sleep 0.1 done atf_fail "timed out waiting for syslogd to start" @@ -57,17 +102,19 @@ syslogd_log() # Make syslogd reload its configuration file. syslogd_reload() { - pkill -HUP -F "${SYSLOGD_PIDFILE}" + pkill -HUP -F "${1:-${SYSLOGD_PIDFILE}}" } # Stop a private syslogd instance. syslogd_stop() { - pid=$(cat "${SYSLOGD_PIDFILE}") - if pkill -F "${SYSLOGD_PIDFILE}"; then + local pid_file="${1:-${SYSLOGD_PIDFILE}}" + + pid=$(cat "${pid_file}") + if pkill -F "${pid_file}"; then wait "${pid}" - rm -f "${SYSLOGD_PIDFILE}" "${SYSLOGD_LOCAL_SOCKET}" \ - "${SYSLOGD_LOCAL_PRIVSOCKET}" + rm -f "${pid_file}" "${2:-${SYSLOGD_LOCAL_SOCKET}}" \ + "${3:-${SYSLOGD_LOCAL_PRIVSOCKET}}" fi } @@ -270,6 +317,45 @@ prop_filter_cleanup() syslogd_stop } +atf_test_case "host_action" "cleanup" +host_action_head() +{ + atf_set descr "Sends a message to a specified host" +} +host_action_body() +{ + local addr="192.0.2.100" + local logfile="${PWD}/host_action.log" + + atf_check ifconfig lo1 create + atf_check ifconfig lo1 inet "${addr}/24" + atf_check ifconfig lo1 up + + printf "user.debug\t${logfile}\n" > "${SYSLOGD_CONFIG}" + syslogd_start -b "${addr}" + + printf "user.debug\t@${addr}\n" > "${SYSLOGD_CONFIG}.2" + syslogd_start \ + -f "${SYSLOGD_CONFIG}.2" \ + -P "${SYSLOGD_PIDFILE}.2" \ + -p "${SYSLOGD_LOCAL_SOCKET}.2" \ + -S "${SYSLOGD_LOCAL_PRIVSOCKET}.2" + + syslogd_log -p user.debug -t "test" -h "${SYSLOGD_LOCAL_SOCKET}.2" \ + "message from syslogd2" + atf_check -s exit:0 -o match:"test: message from syslogd2" \ + cat "${logfile}" +} +host_action_cleanup() +{ + syslogd_stop + syslogd_stop \ + "${SYSLOGD_PIDFILE}.2" \ + "${SYSLOGD_LOCAL_SOCKET}.2" \ + "${SYSLOGD_LOCAL_PRIVSOCKET}.2" + atf_check ifconfig lo1 destroy +} + atf_test_case "pipe_action" "cleanup" pipe_action_head() { @@ -308,7 +394,7 @@ jail_noinet_body() logfile="${PWD}/jail_noinet.log" printf "user.debug\t${logfile}\n" > "${SYSLOGD_CONFIG}" - syslogd_start -j syslogd_noinet -ss + syslogd_start -j syslogd_noinet -s -s syslogd_log -p user.debug -t "test" -h "${SYSLOGD_LOCAL_SOCKET}" \ "hello, world" @@ -326,6 +412,7 @@ atf_init_test_cases() atf_add_test_case "prog_filter" atf_add_test_case "host_filter" atf_add_test_case "prop_filter" + atf_add_test_case "host_action" atf_add_test_case "pipe_action" atf_add_test_case "jail_noinet" }