aboutsummaryrefslogtreecommitdiff
path: root/extra/ifalive.8
blob: 95637329ca0f088e15ddd12cfae1b4313a09a608 (plain)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
.\" This file is part of jumper -*- nroff -*-
.\" Copyright (C) 2017 Sergey Poznyakoff
.\"
.\" Jumper is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation; either version 3, or (at your option)
.\" any later version.
.\"
.\" Jumper is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with jumper.  If not, see <http://www.gnu.org/licenses/>.
.TH IFALIVE 1 "April 7, 2017" "JUMPER" "Jumper User Reference"
.SH NAME
ifalive \- check network interface activity
.SH SYNOPSIS
.nh
.na
\fBifalive\fR \fB\-i\fR [\fB\-dnp\fR] \fIIFACE\fR [\fIPID\fR]
.PP
\fBifalive\fR [\fB\-c\fR] [\fB\-dn\fR] [\fB\-s\fR \fISIG\fR] \fIPID\fR
[\fIEXPR\fR...]
.PP
\fBifalive \-r\fR [\fB\-dnp\fR] [\fIPID\fR]
.PP
.B ifalive \-h
.ad
.hy
.SH DESCRIPTION
Given the network interface name and the PID of the program that
controls it, \fBifalive\fR checks if the interface is "\fIalive\fR",
and if not, terminates the program.
.PP
It is designed as an ancillary utility for
.BR jumper (8),
to help automatically shut down inactive interfaces.
.PP
The program runs in three different operation modes, selected by the
options
.BR \-i,
.BR \-c,
and
.BR \-r .
.SS Initialization
The \fB\-i\fR option requests \fIinitialization mode\fR.  In this
mode, \fIifalive\fR remembers information about the network interface,
and the PID of the corresponding process that controls it.
.PP
If the \fIPID\fR argument is not given, the program assumes the PID of its
parent process.  The \fB\-p\fR option, if used, instructs the program
to use PID of the parent process of the originally obtained PID.  For
example,
.RS
.nf
.B ifalive -i -p tun0 1822
.fi
.RE
means that interface \fBtun0\fR is controlled by the parent of PID
1822, whereas
.RS
.nf
.B ifalive -i -p tun0
.fi
.RE
means that it is controlled by the grand-parent of \fBifalive\fR
itself.  This option can be used multiple times to move up the process
ancestor tree.  For example,
.RS
.nf
.B ifalive -i -ppp tun0 1822
.fi
.RE
means use grand-grand-parent of PID 1822.
.PP
The information is stored in a disk file
\fB/var/run/ifalive/\fIPID\fR.  This file will then be used to store
intermediate information about the state of the interface.
.PP
The initialization is normally performed right after the corresponding
interface is started.  For example, supposing the interface is
controlled by
.BR vpnc (8),
the following line should appear in the
.B  /etc/vpnc/vpnc-script-post-connect-action
file:
.sp
.RS
.nf
.B /usr/libexec/ifalive -i -pp $TUNDEV
.fi
.RE
.SS Periodic checking
This is the main (and the default) operation mode.  It is requested by
the \fB\-c\fR option, or by the absence of the mode specifying
option.  The \fIPID\fR argument is required.  The tool will first look
up the interface name corresponding to that \fIPID\fR, and will
evaluate the expression \fIEXPR\fR to check if the interface is
active.  In the absence of \fIEXPR\fR, the default expression is
evaluated.  See the section
.BR EXPRESSION ,
for the description.
.PP
If the expression evaluates to \fBtrue\fR, the utility will update the
interface statistics in its spool file, and will exit.  Otherwise, it
will terminate the controlling program by sending the \fBSIGTERM\fR
signal to \fIPID\fR.
.PP
The check mode is normally run periodically in a \fBHEARTBEAT\fR
event:
.sp
.RS
.nf
onevent HEARTBEAT {
    command "/usr/libexec/ifalive -c $pid";
}
.fi
.RE
.PP
.SS Cleanup
The cleanup mode is requested by the \fB\-r\fR command line option.
In this mode, \fBifalive\fR removes the state file for the given
\fIPID\fR.  The actual PID is computed as described in subsection
.BR Initialization ,
above.
.PP
This mode should be run when the interface goes down.  For example, if
the interface is controlled by \fBvpnc\fR, the following line should
appear in the file
.BR /etc/vpnc/vpnc-script-post-disconnect-action :
.sp
.RS
.nf
.B /usr/libexec/ifalive -r -pp 
.fi
.RE
.SH EXPRESSION
The expression operates on two variables: the previous interface state
\fBa\fR, and its current state, \fBb\fR.  Both variables have a number
of numeric attributes, which are accessed as \fB\fIX\fB.\fIattr\fR,
where \fIX\fR stands for the variable and \fIattr\fR for the attribute
name.  The following attributes are defined:
.TP
.B rx_bytes
Number of bytes received.
.TP
.B rx_packets
Number of network packets received.
.TP
.B rx_errors
Number of errors while receiving.
.TP
.B rx_dropped
Number of dropped incoming (received) packets.
.TP
.B rx_fifo_errors
Number of FIFO errors on incoming packets.
.TP
.B rx_frame_errors
Number of received frame errors.
.TP
.B rx_compressed
Number of received compressed format packets.
.TP
.B rx_multicast
Number of received multicast packets.
.TP
.B tx_bytes
Number of bytes transmitted.
.TP
.B tx_packets
Number of network packets transmitted.
.TP
.B tx_errors
Number of transmit errors.
.TP
.B tx_dropped
Number of dropped transmit packets.
.TP
.B tx_fifo_errors
Number of FIFO errors on transmit.
.TP
.B collisions
Number of collisions.
.TP
.B tx_carrier_errors
Number of carrier errors.
.TP
.B tx_compressed
Number of transmitted compressed format packets.
.PP
The usual arithmetical operations (\fB+\fR, \fB\-\fR,
\fB*\fR, \fB/\fR) are allowed over these values and integer numeric
constants.  The results can be compared using the operators:
\fB==\fR (or \fB==\fR), \fB!=\fR, \fB<\fR, \fB<=\fR, \fB>\fR,
\fB>=\fR.  The comparisons can be combined using boolean operations
\fBor\fR and \fBand\fR.  Logical values are negated using \fB!\fR.
The following table lists the operators in order of their precedence.
Operators down the table are executed prior to those located above.
Operators on the same line are executed left to right.
.PP
.sp
.nf
.ta 8n
	\fBor\fR
	\fBand\fR
	\fB=\fR, \fB==\fR, \fB!=\fR
	\fB<\fR, \fB<=\fR, \fB>\fR, \fB>=\fR
	\fB+\fR, \fB\-\fR
	\fB*\fR, \fB/\fR
	unary \fB!\fR, unary \fB\-\fR
.fi
.PP
Braces can be used to control the precedence.
.PP
The default expression is:
.PP
.RS
.nf
.B a.rx_bytes != b.rx_bytes and a.tx_bytes != b.tx_bytes
.fi
.RE
.PP
It means that interface is considered alive if some bytes were
transmitted or received over it since the last check.
.SH OPTIONS
.SS Actions
.TP
.B \-i
Initializes the state file.
.TP
.B \-c
Checks the state of the link (the default).
.TP
.B \-r
Removes the state file for \fIPID\fR
.TP
.B \-h
Displays a help summary.
.SS Modifiers
.TP
.B \-d
Enable debug output.
.TP
.B \-n
Dry-run mode: print everything, do nothing.
.TP
.B \-p
Use parent of \fIPID\fR (grand-parent for \fB\-pp\fR, etc.)
.TP
\fB\-s\fR \fISIG\fR
Terminate idle process with signal \fISIG\fR, instead of the default
\fBSIGTERM\fR.
.SH FILES
.TP
.B /proc/net/dev
Network interface statistics.
.TP
.B /var/run/ifalive
Directory where interface state files are stored.  Files are named by
the corresponding PID.
.SH BUGS
The program is Linux-specific.
.SH "SEE ALSO"
.BR jumper (8),
.SH AUTHORS
Sergey Poznyakoff
.SH "BUG REPORTS"
Report bugs to <bug\-jumper@gnu.org.ua>.
.SH COPYRIGHT
Copyright \(co 2017 Sergey Poznyakoff
.br
.na
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
.br
.ad
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
.\" Local variables:
.\" eval: (add-hook 'write-file-hooks 'time-stamp)
.\" time-stamp-start: ".TH [A-Z_][A-Z0-9_.\\-]* [0-9] \""
.\" time-stamp-format: "%:B %:d, %:y"
.\" time-stamp-end: "\""
.\" time-stamp-line-limit: 20
.\" end:

Return to:

Send suggestions and report system problems to the System administrator.