@@ -216,6 +216,21 @@ fd00:a1b2:c3d4::1020:3040:5060:7080 eth-noipv4-ipv6.host123.libpcap.test
216216fd00:a1b2:c3d4::1020:3040:5060:7080 eth-ipv4-ipv6.host123.libpcap.test
217217EOF
218218
219+ # Dotted-quad is the only portable syntax common to all implementations of
220+ # getnetbyname().
221+ # These 3 lines can be copied into networks(5) directly (except on OpenBSD):
222+ my @networks_lines = split /\n/, <<EOF ;
223+ net-10-0-0-0.libpcap.test 10.0.0.0
224+ net-10-20-0-0.libpcap.test 10.20.0.0
225+ net-10-20-30-0.libpcap.test 10.20.30.0
226+ EOF
227+ # These 3 lines can be copied into hosts(5) directly (on OpenBSD only):
228+ my @networks_lines_swapped = split /\n/, <<EOF ;
229+ 10.0.0.0 net-10-0-0-0.libpcap.test
230+ 10.20.0.0 net-10-20-0-0.libpcap.test
231+ 10.20.30.0 net-10-20-30-0.libpcap.test
232+ EOF
233+
219234# Skip if /etc/ethers (or the equivalent) has not been configured for tests.
220235#
221236# Do not use getent(1): it works, but experiences some portability issues and
@@ -272,6 +287,29 @@ sub skip_no_hosts_casecmp {
272287 skip_musl_libc();
273288}
274289
290+ # Skip if /etc/networks (or the equivalent) has not been configured for tests.
291+ my $cached_skip_no_networks ;
292+ sub skip_no_networks {
293+ $cached_skip_no_networks =
294+ # Does not implement getnetbyname().
295+ skip_os (' msys' ) ||
296+ # getnetbyname() is a no-op.
297+ skip_musl_libc() ||
298+ skip_unless_file_contains_lines (
299+ $^O eq ' solaris' ? ' /etc/inet/networks' :
300+ $^O eq ' haiku' ? ' /etc/networks' : # May change, see haiku bug report 19432.
301+ $^O eq ' openbsd' ? ' /etc/hosts' : # (sic)
302+ ' /etc/networks' ,
303+ $^O eq ' openbsd' ? @networks_lines_swapped : @networks_lines
304+ ) unless defined $cached_skip_no_networks ;
305+ return $cached_skip_no_networks ;
306+ }
307+
308+ sub skip_no_networks_casecmp {
309+ return skip_no_networks ||
310+ skip_os (' solaris' );
311+ }
312+
275313# In accept_blocks the top-level keys are test block names. Each test block
276314# defines one or more tests. When possible, a test block name should be easy
277315# to relate with the main filter expression, for example, ip_multicast for
@@ -4994,7 +5032,7 @@ my %accept_blocks = (
49945032 (006) ret #0
49955033 ' ,
49965034 }, # ip_dst_host_NAME
4997- ip_net => {
5035+ ip_net_addr => {
49985036 DLT => ' RAW' ,
49995037 snaplen => 2000,
50005038 aliases => [
@@ -5041,8 +5079,46 @@ my %accept_blocks = (
50415079 (009) ret #2000
50425080 (010) ret #0
50435081 ' ,
5044- }, # ip_net
5045- ip_src_net => {
5082+ }, # ip_net_addr
5083+ ip_net_name => {
5084+ skip => skip_no_networks(),
5085+ DLT => ' RAW' ,
5086+ aliases => [
5087+ ' ip net net-10-0-0-0.libpcap.test' ,
5088+ ' ip src or dst net net-10-0-0-0.libpcap.test' ,
5089+ ],
5090+ opt => '
5091+ (000) ldb [0]
5092+ (001) and #0xf0
5093+ (002) jeq #0x40 jt 3 jf 8
5094+ (003) ld [12]
5095+ (004) jeq #0xa000000 jt 7 jf 5
5096+ (005) ld [16]
5097+ (006) jeq #0xa000000 jt 7 jf 8
5098+ (007) ret #262144
5099+ (008) ret #0
5100+ ' ,
5101+ }, # ip_net_name
5102+ ip_net_NAME => {
5103+ skip => skip_no_networks_casecmp(),
5104+ DLT => ' RAW' ,
5105+ aliases => [
5106+ ' ip net NET-10-0-0-0.LIBPCAP.TEST' ,
5107+ ' ip src or dst net NET-10-0-0-0.LIBPCAP.TEST' ,
5108+ ],
5109+ opt => '
5110+ (000) ldb [0]
5111+ (001) and #0xf0
5112+ (002) jeq #0x40 jt 3 jf 8
5113+ (003) ld [12]
5114+ (004) jeq #0xa000000 jt 7 jf 5
5115+ (005) ld [16]
5116+ (006) jeq #0xa000000 jt 7 jf 8
5117+ (007) ret #262144
5118+ (008) ret #0
5119+ ' ,
5120+ }, # ip_net_NAME
5121+ ip_src_net_addr => {
50465122 DLT => ' RAW' ,
50475123 snaplen => 2000,
50485124 aliases => [
@@ -5072,8 +5148,42 @@ my %accept_blocks = (
50725148 (006) ret #2000
50735149 (007) ret #0
50745150 ' ,
5075- }, # ip_src_net
5076- ip_dst_net => {
5151+ }, # ip_src_net_addr
5152+ ip_src_net_name => {
5153+ skip => skip_no_networks(),
5154+ DLT => ' RAW' ,
5155+ aliases => [
5156+ ' ip src net net-10-20-0-0.libpcap.test' ,
5157+ ' src net net-10-20-0-0.libpcap.test' ,
5158+ ],
5159+ opt => '
5160+ (000) ldb [0]
5161+ (001) and #0xf0
5162+ (002) jeq #0x40 jt 3 jf 6
5163+ (003) ld [12]
5164+ (004) jeq #0xa140000 jt 5 jf 6
5165+ (005) ret #262144
5166+ (006) ret #0
5167+ ' ,
5168+ }, # ip_src_net_name
5169+ ip_src_net_NAME => {
5170+ skip => skip_no_networks_casecmp(),
5171+ DLT => ' RAW' ,
5172+ aliases => [
5173+ ' ip src net NET-10-20-0-0.LIBPCAP.TEST' ,
5174+ ' src net NET-10-20-0-0.LIBPCAP.TEST' ,
5175+ ],
5176+ opt => '
5177+ (000) ldb [0]
5178+ (001) and #0xf0
5179+ (002) jeq #0x40 jt 3 jf 6
5180+ (003) ld [12]
5181+ (004) jeq #0xa140000 jt 5 jf 6
5182+ (005) ret #262144
5183+ (006) ret #0
5184+ ' ,
5185+ }, # ip_src_net_NAME
5186+ ip_dst_net_addr => {
50775187 DLT => ' RAW' ,
50785188 snaplen => 2000,
50795189 aliases => [
@@ -5097,7 +5207,41 @@ my %accept_blocks = (
50975207 (006) ret #2000
50985208 (007) ret #0
50995209 ' ,
5100- }, # ip_dst_net
5210+ }, # ip_dst_net_addr
5211+ ip_dst_net_name => {
5212+ skip => skip_no_networks(),
5213+ DLT => ' RAW' ,
5214+ aliases => [
5215+ ' ip dst net net-10-20-30-0.libpcap.test' ,
5216+ ' dst net net-10-20-30-0.libpcap.test' ,
5217+ ],
5218+ opt => '
5219+ (000) ldb [0]
5220+ (001) and #0xf0
5221+ (002) jeq #0x40 jt 3 jf 6
5222+ (003) ld [16]
5223+ (004) jeq #0xa141e00 jt 5 jf 6
5224+ (005) ret #262144
5225+ (006) ret #0
5226+ ' ,
5227+ }, # ip_dst_net_name
5228+ ip_dst_net_NAME => {
5229+ skip => skip_no_networks_casecmp(),
5230+ DLT => ' RAW' ,
5231+ aliases => [
5232+ ' ip dst net NET-10-20-30-0.LIBPCAP.TEST' ,
5233+ ' dst net NET-10-20-30-0.LIBPCAP.TEST' ,
5234+ ],
5235+ opt => '
5236+ (000) ldb [0]
5237+ (001) and #0xf0
5238+ (002) jeq #0x40 jt 3 jf 6
5239+ (003) ld [16]
5240+ (004) jeq #0xa141e00 jt 5 jf 6
5241+ (005) ret #262144
5242+ (006) ret #0
5243+ ' ,
5244+ }, # ip_dst_net_NAME
51015245 # TODO: Verify identity with DLT_NETANALYZER and
51025246 # DLT_NETANALYZER_TRANSPARENT in all DLT_EN10MB gateway tests.
51035247 gateway_name_en10mb => {
@@ -9136,6 +9280,41 @@ my %reject_tests = (
91369280 expr => ' net 10 mask 255' ,
91379281 errstr => ' syntax error' ,
91389282 },
9283+ ip_net_unknown => {
9284+ DLT => ' EN10MB' ,
9285+ expr => " ip net ${nonexistent} " ,
9286+ errstr => " unknown network '${nonexistent} '" ,
9287+ },
9288+ ip_src_net_unknown => {
9289+ DLT => ' EN10MB' ,
9290+ expr => " ip src net ${nonexistent} " ,
9291+ errstr => " unknown network '${nonexistent} '" ,
9292+ },
9293+ ip_dst_net_unknown => {
9294+ DLT => ' EN10MB' ,
9295+ expr => " ip dst net ${nonexistent} " ,
9296+ errstr => " unknown network '${nonexistent} '" ,
9297+ },
9298+ net_unknown => {
9299+ DLT => ' EN10MB' ,
9300+ expr => " net ${nonexistent} " ,
9301+ errstr => " unknown network '${nonexistent} '" ,
9302+ },
9303+ src_net_unknown => {
9304+ DLT => ' EN10MB' ,
9305+ expr => " src net ${nonexistent} " ,
9306+ errstr => " unknown network '${nonexistent} '" ,
9307+ },
9308+ dst_net_unknown => {
9309+ DLT => ' EN10MB' ,
9310+ expr => " dst net ${nonexistent} " ,
9311+ errstr => " unknown network '${nonexistent} '" ,
9312+ },
9313+ src_or_dst_net_unknown => {
9314+ DLT => ' EN10MB' ,
9315+ expr => " src or dst net ${nonexistent} " ,
9316+ errstr => " unknown network '${nonexistent} '" ,
9317+ },
91399318 ip6_net_prefix => {
91409319 skip => skip_config_undef (' INET6' ),
91419320 DLT => ' RAW' ,
0 commit comments