Skip to content

Commit 313c502

Browse files
vmsh0davem330
authored andcommitted
ipv4: fix bind address validity regression tests
Commit 8ff978b ("ipv4/raw: support binding to nonlocal addresses") introduces support for binding to nonlocal addresses, as well as some basic test coverage for some of the related cases. Commit b4a028c ("ipv4: ping: fix bind address validity check") fixes a regression which incorrectly removed some checks for bind address validation. In addition, it introduces regression tests for those specific checks. However, those regression tests are defective, in that they perform the tests using an incorrect combination of bind flags. As a result, those tests fail when they should succeed. This commit introduces additional regression tests for nonlocal binding and fixes the defective regression tests. It also introduces new set_sysctl calls for the ipv4_bind test group, as to perform the ICMP binding tests it is necessary to allow ICMP socket creation by setting the net.ipv4.ping_group_range knob. Fixes: b4a028c ("ipv4: ping: fix bind address validity check") Reported-by: Riccardo Paolo Bestetti <pbl@bestov.io> Signed-off-by: Riccardo Paolo Bestetti <pbl@bestov.io> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9926de7 commit 313c502

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

tools/testing/selftests/net/fcnal-test.sh

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,24 +1800,32 @@ ipv4_addr_bind_novrf()
18001800
done
18011801

18021802
#
1803-
# raw socket with nonlocal bind
1803+
# tests for nonlocal bind
18041804
#
18051805
a=${NL_IP}
18061806
log_start
1807-
run_cmd nettest -s -R -P icmp -f -l ${a} -I ${NSA_DEV} -b
1808-
log_test_addr ${a} $? 0 "Raw socket bind to nonlocal address after device bind"
1807+
run_cmd nettest -s -R -f -l ${a} -b
1808+
log_test_addr ${a} $? 0 "Raw socket bind to nonlocal address"
1809+
1810+
log_start
1811+
run_cmd nettest -s -f -l ${a} -b
1812+
log_test_addr ${a} $? 0 "TCP socket bind to nonlocal address"
1813+
1814+
log_start
1815+
run_cmd nettest -s -D -P icmp -f -l ${a} -b
1816+
log_test_addr ${a} $? 0 "ICMP socket bind to nonlocal address"
18091817

18101818
#
18111819
# check that ICMP sockets cannot bind to broadcast and multicast addresses
18121820
#
18131821
a=${BCAST_IP}
18141822
log_start
1815-
run_cmd nettest -s -R -P icmp -l ${a} -b
1823+
run_cmd nettest -s -D -P icmp -l ${a} -b
18161824
log_test_addr ${a} $? 1 "ICMP socket bind to broadcast address"
18171825

18181826
a=${MCAST_IP}
18191827
log_start
1820-
run_cmd nettest -s -R -P icmp -f -l ${a} -b
1828+
run_cmd nettest -s -D -P icmp -l ${a} -b
18211829
log_test_addr ${a} $? 1 "ICMP socket bind to multicast address"
18221830

18231831
#
@@ -1870,24 +1878,32 @@ ipv4_addr_bind_vrf()
18701878
log_test_addr ${a} $? 1 "Raw socket bind to out of scope address after VRF bind"
18711879

18721880
#
1873-
# raw socket with nonlocal bind
1881+
# tests for nonlocal bind
18741882
#
18751883
a=${NL_IP}
18761884
log_start
1877-
run_cmd nettest -s -R -P icmp -f -l ${a} -I ${VRF} -b
1885+
run_cmd nettest -s -R -f -l ${a} -I ${VRF} -b
18781886
log_test_addr ${a} $? 0 "Raw socket bind to nonlocal address after VRF bind"
18791887

1888+
log_start
1889+
run_cmd nettest -s -f -l ${a} -I ${VRF} -b
1890+
log_test_addr ${a} $? 0 "TCP socket bind to nonlocal address after VRF bind"
1891+
1892+
log_start
1893+
run_cmd nettest -s -D -P icmp -f -l ${a} -I ${VRF} -b
1894+
log_test_addr ${a} $? 0 "ICMP socket bind to nonlocal address after VRF bind"
1895+
18801896
#
18811897
# check that ICMP sockets cannot bind to broadcast and multicast addresses
18821898
#
18831899
a=${BCAST_IP}
18841900
log_start
1885-
run_cmd nettest -s -R -P icmp -l ${a} -I ${VRF} -b
1901+
run_cmd nettest -s -D -P icmp -l ${a} -I ${VRF} -b
18861902
log_test_addr ${a} $? 1 "ICMP socket bind to broadcast address after VRF bind"
18871903

18881904
a=${MCAST_IP}
18891905
log_start
1890-
run_cmd nettest -s -R -P icmp -f -l ${a} -I ${VRF} -b
1906+
run_cmd nettest -s -D -P icmp -l ${a} -I ${VRF} -b
18911907
log_test_addr ${a} $? 1 "ICMP socket bind to multicast address after VRF bind"
18921908

18931909
#
@@ -1922,10 +1938,12 @@ ipv4_addr_bind()
19221938

19231939
log_subsection "No VRF"
19241940
setup
1941+
set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
19251942
ipv4_addr_bind_novrf
19261943

19271944
log_subsection "With VRF"
19281945
setup "yes"
1946+
set_sysctl net.ipv4.ping_group_range='0 2147483647' 2>/dev/null
19291947
ipv4_addr_bind_vrf
19301948
}
19311949

0 commit comments

Comments
 (0)