git: 5311e7333714 - main - netinet tests: basic VRRP tests

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Wed, 08 May 2024 11:19:59 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=5311e73337143b2a32e06bd68fb125089c827323

commit 5311e73337143b2a32e06bd68fb125089c827323
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2024-04-11 16:40:19 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2024-05-08 11:19:04 +0000

    netinet tests: basic VRRP tests
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D44775
---
 tests/sys/netinet/carp.py | 14 +++++++
 tests/sys/netinet/carp.sh | 98 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 111 insertions(+), 1 deletion(-)

diff --git a/tests/sys/netinet/carp.py b/tests/sys/netinet/carp.py
index ac2c5547fe97..0db31e79ba84 100644
--- a/tests/sys/netinet/carp.py
+++ b/tests/sys/netinet/carp.py
@@ -51,3 +51,17 @@ class TestCarp(VnetTestTemplate):
         carp_pkts = sc.sniff(iface=if1.name, stop_filter=filter_f, timeout=5)
 
         self.check_carp_src_mac(carp_pkts)
+
+    def test_source_mac_vrrp(self):
+        "Test VRRP packets source address"
+
+        if1 = self.vnet.iface_alias_map["if1"]
+
+        ToolsHelper.print_output(
+            "ifconfig {} add vhid 1 carpver 3 192.0.2.203/24".format(if1.name)
+        )
+
+        carp_pkts = sc.sniff(iface=if1.name, stop_filter=filter_f, timeout=5)
+
+        self.check_carp_src_mac(carp_pkts)
+
diff --git a/tests/sys/netinet/carp.sh b/tests/sys/netinet/carp.sh
index d08940d433d7..e10e24747c2d 100755
--- a/tests/sys/netinet/carp.sh
+++ b/tests/sys/netinet/carp.sh
@@ -31,7 +31,7 @@ is_master()
 	jail=$1
 	itf=$2
 
-	jexec ${jail} ifconfig ${itf} | grep carp | grep MASTER
+	jexec ${jail} ifconfig ${itf} | grep -E '(carp|vrrp)' | grep MASTER
 }
 
 wait_for_carp()
@@ -105,6 +105,51 @@ basic_v4_cleanup()
 	vnet_cleanup
 }
 
+atf_test_case "vrrp_v4" "cleanup"
+vrrp_v4_head()
+{
+	atf_set descr 'Basic VRRP test (IPv4)'
+	atf_set require.user root
+}
+
+vrrp_v4_body()
+{
+	carp_init
+
+	j=vrrp_basic_v4
+
+	bridge=$(vnet_mkbridge)
+	epair_one=$(vnet_mkepair)
+	epair_two=$(vnet_mkepair)
+
+	vnet_mkjail ${j}_one ${bridge} ${epair_one}a ${epair_two}a
+	vnet_mkjail ${j}_two ${epair_one}b
+	vnet_mkjail ${j}_three ${epair_two}b
+
+	jexec ${j}_one ifconfig ${bridge} 192.0.2.4/29 up
+	jexec ${j}_one ifconfig ${bridge} addm ${epair_one}a \
+	    addm ${epair_two}a
+	jexec ${j}_one ifconfig ${epair_one}a up
+	jexec ${j}_one ifconfig ${epair_two}a up
+
+	jexec ${j}_two ifconfig ${epair_one}b 192.0.2.202/29 up
+	jexec ${j}_two ifconfig ${epair_one}b add vhid 1 carpver 3 192.0.2.1/29
+
+	jexec ${j}_three ifconfig ${epair_two}b 192.0.2.203/29 up
+	jexec ${j}_three ifconfig ${epair_two}b add vhid 1 carpver 3 \
+	    192.0.2.1/29
+
+	wait_for_carp ${j}_two ${epair_one}b \
+	    ${j}_three ${epair_two}b
+
+	atf_check -s exit:0 -o ignore jexec ${j}_one \
+	    ping -c 3 192.0.2.1
+}
+
+vrrp_v4_cleanup()
+{
+	vnet_cleanup
+}
 
 atf_test_case "unicast_v4" "cleanup"
 unicast_v4_head()
@@ -210,6 +255,55 @@ basic_v6_cleanup()
 	vnet_cleanup
 }
 
+atf_test_case "vrrp_v6" "cleanup"
+vrrp_v6_head()
+{
+	atf_set descr 'Basic VRRP test (IPv6)'
+	atf_set require.user root
+}
+
+vrrp_v6_body()
+{
+	carp_init
+
+	j=carp_basic_v6
+
+	bridge=$(vnet_mkbridge)
+	epair_one=$(vnet_mkepair)
+	epair_two=$(vnet_mkepair)
+
+	vnet_mkjail ${j}_one ${bridge} ${epair_one}a ${epair_two}a
+	vnet_mkjail ${j}_two ${epair_one}b
+	vnet_mkjail ${j}_three ${epair_two}b
+
+	jexec ${j}_one ifconfig ${bridge} inet6 2001:db8::0:4/64 up \
+	    no_dad
+	jexec ${j}_one ifconfig ${bridge} addm ${epair_one}a \
+	    addm ${epair_two}a
+	jexec ${j}_one ifconfig ${epair_one}a up
+	jexec ${j}_one ifconfig ${epair_two}a up
+
+	jexec ${j}_two ifconfig ${epair_one}b inet6 \
+	    2001:db8::1:2/64 up no_dad
+	jexec ${j}_two ifconfig ${epair_one}b inet6 add vhid 1 carpver 3 \
+	    2001:db8::0:1/64
+
+	jexec ${j}_three ifconfig ${epair_two}b inet6 2001:db8::1:3/64 up no_dad
+	jexec ${j}_three ifconfig ${epair_two}b inet6 add vhid 1 carpver 3 \
+	    2001:db8::0:1/64
+
+	wait_for_carp ${j}_two ${epair_one}b \
+	    ${j}_three ${epair_two}b
+
+	atf_check -s exit:0 -o ignore jexec ${j}_one \
+	    ping -6 -c 3 2001:db8::0:1
+}
+
+vrrp_v6_cleanup()
+{
+	vnet_cleanup
+}
+
 atf_test_case "unicast_v6" "cleanup"
 unicast_v6_head()
 {
@@ -469,8 +563,10 @@ switch_cleanup()
 atf_init_test_cases()
 {
 	atf_add_test_case "basic_v4"
+	atf_add_test_case "vrrp_v4"
 	atf_add_test_case "unicast_v4"
 	atf_add_test_case "basic_v6"
+	atf_add_test_case "vrrp_v6"
 	atf_add_test_case "unicast_v6"
 	atf_add_test_case "unicast_ll_v6"
 	atf_add_test_case "negative_demotion"