@@ -5,11 +5,13 @@ BEGIN {
55 $basedir = $0 ;
66 $basedir =~ s | (.*)/[^/]*| $1 | ;
77
8- $test_count = 38;
8+ $test_count_ipv4 = 34;
9+ $test_count_ipv6 = 4;
910
1011 $test_ipsec = 0;
1112 if ( system (" ip xfrm policy help 2>&1 | grep -q ctx" ) eq 0 ) {
12- $test_count += 8;
13+ $test_count_ipv4 += 4;
14+ $test_count_ipv6 += 4;
1315 $test_ipsec = 1;
1416 }
1517
@@ -23,10 +25,17 @@ BEGIN {
2325
2426 $rc = ` $basedir /../kvercmp $kvercur $kverminstream ` ;
2527 if ( $netlabelctl gt " 021" and $rc > 0 ) {
26- $test_count += 3;
28+ $test_count_ipv6 += 3;
2729 $test_calipso_stream = 1;
2830 }
2931
32+ $test_count = $test_count_ipv4 ;
33+ $test_ipv6 = 0;
34+ if ( system (" test -f /proc/net/if_inet6" ) eq 0 ) {
35+ $test_count += $test_count_ipv6 ;
36+ $test_ipv6 = 1;
37+ }
38+
3039 plan tests => $test_count ;
3140}
3241
@@ -298,16 +307,6 @@ if ($test_ipsec) {
298307" runcon -t test_inet_bad_client_t -- $basedir /client stream 127.0.0.1 65535 2>&1" ;
299308 ok( $result >> 8 eq 5 );
300309
301- # Verify that authorized client can communicate with the server.
302- $result =
303- system " runcon -t test_inet_client_t $basedir /client stream ::1 65535" ;
304- ok( $result eq 0 );
305-
306- # Verify that unauthorized client cannot communicate with the server.
307- $result = system
308- " runcon -t test_inet_bad_client_t -- $basedir /client stream ::1 65535 2>&1" ;
309- ok( $result >> 8 eq 5 );
310-
311310 # Kill the server.
312311 server_end($pid );
313312
@@ -325,24 +324,49 @@ if ($test_ipsec) {
325324" runcon -t test_inet_bad_client_t -- $basedir /client dgram 127.0.0.1 65535 2>&1" ;
326325 ok( $result >> 8 eq 8 );
327326
328- # Verify that unauthorized client cannot communicate with the server.
329- $result = system
330- " runcon -t test_inet_bad_client_t -- $basedir /client dgram ::1 65535 2>&1" ;
331- ok( $result >> 8 eq 8 );
332-
333327 # Kill the server.
334328 server_end($pid );
335329
330+ if ($test_ipv6 ) {
331+
332+ # Start the IPv6 stream server.
333+ $pid = server_start( " -t test_inet_server_t" , " -6 stream 65535" );
334+
335+ # Verify that authorized client can communicate with the server.
336+ $result = system
337+ " runcon -t test_inet_client_t $basedir /client stream ::1 65535" ;
338+ ok( $result eq 0 );
339+
340+ # Verify that unauthorized client cannot communicate with the server.
341+ $result = system
342+ " runcon -t test_inet_bad_client_t -- $basedir /client stream ::1 65535 2>&1" ;
343+ ok( $result >> 8 eq 5 );
344+
345+ # Kill the server.
346+ server_end($pid );
347+
348+ # Start the IPv6 dgram server.
349+ $pid = server_start( " -t test_inet_server_t" , " -6 dgram 65535" );
350+
351+ # Verify that unauthorized client cannot communicate with the server.
352+ $result = system
353+ " runcon -t test_inet_bad_client_t -- $basedir /client dgram ::1 65535 2>&1" ;
354+ ok( $result >> 8 eq 8 );
355+
356+ # Kill the server.
357+ server_end($pid );
358+
336359# Start the dgram server for IPSEC test using IPv6 but do not request peer context.
337- $pid = server_start( " -t test_inet_server_t" , " -n dgram 65535" );
360+ $pid = server_start( " -t test_inet_server_t" , " -6n dgram 65535" );
338361
339- # This test now passes.
340- $result = system
341- " runcon -t test_inet_client_t $basedir /client -e nopeer dgram ::1 65535" ;
342- ok( $result eq 0 );
362+ # This test now passes.
363+ $result = system
364+ " runcon -t test_inet_client_t $basedir /client -e nopeer dgram ::1 65535" ;
365+ ok( $result eq 0 );
343366
344- # Kill the server.
345- server_end($pid );
367+ # Kill the server.
368+ server_end($pid );
369+ }
346370
347371 # Flush IPSEC configuration.
348372 system " /bin/sh $basedir /ipsec-flush" ;
@@ -364,16 +388,6 @@ $result = system
364388" runcon -t test_inet_bad_client_t -- $basedir /client -e nopeer stream 127.0.0.1 65535 2>&1" ;
365389ok( $result >> 8 eq 5 );
366390
367- # Verify that authorized client can communicate with the server.
368- $result = system
369- " runcon -t test_inet_client_t -- $basedir /client -e nopeer stream ::1 65535" ;
370- ok( $result eq 0 );
371-
372- # Verify that unauthorized client cannot communicate with the server.
373- $result = system
374- " runcon -t test_inet_bad_client_t -- $basedir /client -e nopeer stream ::1 65535 2>&1" ;
375- ok( $result >> 8 eq 5 );
376-
377391# Kill the server.
378392server_end($pid );
379393
@@ -390,29 +404,55 @@ $result = system
390404" runcon -t test_inet_bad_client_t -- $basedir /client -e nopeer dgram 127.0.0.1 65535 2>&1" ;
391405ok( $result >> 8 eq 8 );
392406
393- # Verify that authorized client can communicate with the server.
394- $result = system
395- " runcon -t test_inet_client_t $basedir /client -e nopeer dgram ::1 65535" ;
396- ok( $result eq 0 );
407+ # Kill the server.
408+ server_end($pid );
397409
398- # Verify that unauthorized client cannot communicate with the server.
399- $result = system
410+ if ($test_ipv6 ) {
411+
412+ # Start the IPv6 stream server.
413+ $pid = server_start( " -t test_inet_server_t" , " -6n stream 65535" );
414+
415+ # Verify that authorized client can communicate with the server.
416+ $result = system
417+ " runcon -t test_inet_client_t -- $basedir /client -e nopeer stream ::1 65535" ;
418+ ok( $result eq 0 );
419+
420+ # Verify that unauthorized client cannot communicate with the server.
421+ $result = system
422+ " runcon -t test_inet_bad_client_t -- $basedir /client -e nopeer stream ::1 65535 2>&1" ;
423+ ok( $result >> 8 eq 5 );
424+
425+ # Kill the server.
426+ server_end($pid );
427+
428+ # Start the IPv6 dgram server.
429+ $pid = server_start( " -t test_inet_server_t" , " -6n dgram 65535" );
430+
431+ # Verify that authorized client can communicate with the server.
432+ $result = system
433+ " runcon -t test_inet_client_t $basedir /client -e nopeer dgram ::1 65535" ;
434+ ok( $result eq 0 );
435+
436+ # Verify that unauthorized client cannot communicate with the server.
437+ $result = system
400438" runcon -t test_inet_bad_client_t -- $basedir /client -e nopeer dgram ::1 65535 2>&1" ;
401- ok( $result >> 8 eq 8 );
439+ ok( $result >> 8 eq 8 );
402440
403- # Kill the server.
404- server_end($pid );
441+ # Kill the server.
442+ server_end($pid );
443+ }
405444
406445# Flush iptables configuration.
407446system " /bin/sh $basedir /iptables-flush" ;
408447
409- if ($ test_calipso_stream ) {
448+ if ( $test_ipv6 and $ test_calipso_stream ) {
410449
411450 # Load NetLabel configuration for CALIPSO/IPv6 labeling over loopback.
412451 system " /bin/sh $basedir /calipso-load" ;
413452
414453 # Start the stream server.
415- $pid = server_start( " -t test_inet_server_t -l s0:c0.c10" , " stream 65535" );
454+ $pid =
455+ server_start( " -t test_inet_server_t -l s0:c0.c10" , " -6 stream 65535" );
416456
417457 # Verify that authorized client can communicate with the server.
418458 $result = system
0 commit comments