File: ipaddr.exp

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (138 lines) | stat: -rw-r--r-- 3,554 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
set TEST_NAME_BASE "ipaddr"
if {![installtest_p]} { untested $TEST_NAME_BASE; return }

# nc server management variables
set IPV4_ONLY -1
set nc_pipe 0

# Start an 'nc' server.  To start an IPv4 server, pass 1 as the
# argument.  To start an IPv6 server, pass 0 as the argument.
proc start_nc_server { IPV4 } {
    global TEST_NAME IPV4_ONLY nc_pipe
    if {$IPV4_ONLY < 0} {
	# First, does 'nc' exist on this system?
	if {[catch { exec which nc } res]} {
	    fail "$TEST_NAME find 'nc'"
	    return -1
	}
	pass "$TEST_NAME find 'nc'"

	# Older versions of 'nc' (on RHEL4 for instance) don't support
	# IPv6. Does this 'nc' support IPv6?
	set IPV4_ONLY 0
	if {[catch { exec sh -c "nc -h 2>&1 | grep -qi IPv6" } res]} {
	    # If we're here, 'nc' doesn't support IPv6.  So, it
	    # supports IPv4 only.
	    set IPV4_ONLY 1
	}
    }

    # Figure out the 'nc' command line.
    if {$IPV4} {
	if {$IPV4_ONLY} {
	    set nc_cmd "| nc -l localhost -p 8079"
	} else {
	    set nc_cmd "| nc -l -4 localhost 8079"
	}
    } else {
	if {$IPV4_ONLY} {
	    untested "$TEST_NAME starting IPv6 nc server"
	    return -1
	}
	set nc_cmd "| nc -l -6 localhost6 8079"
    }

    # Actually start the 'nc' server.
    verbose -log "starting $nc_cmd"
    if {[catch {open $nc_cmd} nc_pipe]} {
	verbose -log "nc command failed: $fl"
	fail "$TEST_NAME nc server start"
	return -1
    }

    pass "$TEST_NAME nc server start"
    return 0
}

# Stop the nc server.
proc stop_nc_server {} {
    global TEST_NAME nc_pipe

    kill -INT [pid $nc_pipe] 5
    catch { close $nc_pipe } res
    pass "$TEST_NAME nc server stop"
    return
}

# "load" generation function for stap_run.  It runs a client version
# of 'nc' and sends some IPv4 data through it.
proc run_ipv4_client {} {
    global srcdir subdir
    global IPV4_ONLY

    catch {
        exec bash -c "cat $srcdir/$subdir/ipaddr.txt > /dev/tcp/127.0.0.1/8079"
    }
    return 0
}

# "load" generation function for stap_run.  It runs a client version
# of 'nc' and sends some IPv6 data through it.
proc run_ipv6_client {} {
    global srcdir subdir
    global IPV4_ONLY

    if {$IPV4_ONLY} {
	verbose -log "error: nc only supports IPv4"
	return 1
    }
    catch {
        exec bash -c "cat $srcdir/$subdir/ipaddr.txt > /dev/tcp/::1/8079"
    }
    return 0
}

# Start the 1st IPv4 test
set TEST_NAME "${TEST_NAME_BASE}_IPv4_recvmsg"
if {[start_nc_server 1]} {
    # If we couldn't start the server, we're done.
    return
}
set script_output "packets = \[0-9\]+\r\naddress errors = 0\r\nbad family errors = 0\r\n"
stap_run $TEST_NAME run_ipv4_client $script_output $srcdir/$subdir/ipaddr1.stp

# Stop/cleanup the IPv4 server.
stop_nc_server

# Start the 2nd IPv4 test
set TEST_NAME "${TEST_NAME_BASE}_IPv4_receive"
if {[start_nc_server 1]} {
    # If we couldn't start the server, we're done.
    return
}
stap_run $TEST_NAME run_ipv4_client $script_output $srcdir/$subdir/ipaddr2.stp

# Stop/cleanup the IPv4 server
stop_nc_server

# Start the 1st IPv6 test
set TEST_NAME "${TEST_NAME_BASE}_IPv6_recvmsg"
if {[start_nc_server 0]} {
    # If we couldn't start the server, we're done.
    return
}
stap_run $TEST_NAME run_ipv6_client $script_output $srcdir/$subdir/ipaddr1.stp

# Stop/cleanup the IPv6 server.
stop_nc_server

# Start the 2nd IPv6 test
set TEST_NAME "${TEST_NAME_BASE}_IPv6_receive"
if {[start_nc_server 0]} {
    # If we couldn't start the server, we're done.
    return
}
stap_run $TEST_NAME run_ipv6_client $script_output $srcdir/$subdir/ipaddr2.stp

# Stop/cleanup the IPv6 server.
stop_nc_server