Denys Vlasenko | 6cf7f01 | 2009-11-06 04:04:19 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Denys Vlasenko | 002bdc3 | 2009-11-09 11:04:54 +0100 | [diff] [blame] | 3 | #exec >/dev/null |
Denys Vlasenko | 6cf7f01 | 2009-11-06 04:04:19 +0100 | [diff] [blame] | 4 | exec 2>&1 |
| 5 | exec </dev/null |
| 6 | |
| 7 | pwd="$PWD" |
| 8 | |
| 9 | if="${PWD##*/ifplugd_}" |
| 10 | |
Denys Vlasenko | 4f8ecf2 | 2015-10-24 14:55:33 +0200 | [diff] [blame] | 11 | echo "* Upping iface $if" |
| 12 | ip link set dev "$if" up |
| 13 | |
Denys Vlasenko | bf40f56 | 2009-11-07 17:54:44 +0100 | [diff] [blame] | 14 | echo "* Starting ifplugd on $if [$$]" |
Denys Vlasenko | 6cf7f01 | 2009-11-06 04:04:19 +0100 | [diff] [blame] | 15 | exec \ |
| 16 | env - PATH="$PATH" \ |
| 17 | softlimit \ |
| 18 | setuidgid root \ |
Denys Vlasenko | 0d79d77 | 2018-03-30 20:02:33 +0200 | [diff] [blame^] | 19 | ifplugd -aqlns -t3 -u8 -d8 -i "$if" -r "$pwd/ifplugd_handler" |
Denys Vlasenko | 6cf7f01 | 2009-11-06 04:04:19 +0100 | [diff] [blame] | 20 | |
Denys Vlasenko | 002bdc3 | 2009-11-09 11:04:54 +0100 | [diff] [blame] | 21 | # We use -t3 to wake ifplugd up less often. |
| 22 | # If after three tests (3*3=9 > 8) link state seen to be different, |
| 23 | # the handler will be called. |
| 24 | # IOW: short link losses will be ignored, longer ones |
| 25 | # will trigger DHCP reconfiguration and such (see handler code). |
Denys Vlasenko | bf40f56 | 2009-11-07 17:54:44 +0100 | [diff] [blame] | 26 | |
Denys Vlasenko | 0d79d77 | 2018-03-30 20:02:33 +0200 | [diff] [blame^] | 27 | # -l makes ifplugd run either "up" or "down" script on startup. |
| 28 | # For example, if wired eth cable is unplugged, this stops dhcp service |
| 29 | # from pointlessly trying to get a lease. |
| 30 | # -q means that stopping monitoring does not stop dhcp/zcip/etc: |
| 31 | # presumably, admin decided to control them manually. |
| 32 | |
Denys Vlasenko | d892f71 | 2018-03-30 11:14:46 +0200 | [diff] [blame] | 33 | #-a Don't up interface automatically |
| 34 | #-p Don't run "up" script on startup |
| 35 | #-q Don't run "down" script on exit |
| 36 | #-l Always run script on startup |
Denys Vlasenko | bf40f56 | 2009-11-07 17:54:44 +0100 | [diff] [blame] | 37 | #-n Do not daemonize |
| 38 | #-s Do not log to syslog |
Denys Vlasenko | 6cf7f01 | 2009-11-06 04:04:19 +0100 | [diff] [blame] | 39 | #-t SECS Poll time in seconds |
| 40 | #-u SECS Delay before running script after link up |
| 41 | #-d SECS Delay after link down |
Denys Vlasenko | bf40f56 | 2009-11-07 17:54:44 +0100 | [diff] [blame] | 42 | #-i IFACE Interface |
Denys Vlasenko | bf40f56 | 2009-11-07 17:54:44 +0100 | [diff] [blame] | 43 | #-M Monitor creation/destruction of interface (otherwise it must exist) |
Denys Vlasenko | d892f71 | 2018-03-30 11:14:46 +0200 | [diff] [blame] | 44 | #-r PROG Script to run |
Denys Vlasenko | bf40f56 | 2009-11-07 17:54:44 +0100 | [diff] [blame] | 45 | #-x ARG Extra argument for script |
Denys Vlasenko | d892f71 | 2018-03-30 11:14:46 +0200 | [diff] [blame] | 46 | #-I Don't exit on nonzero exit code from script |
| 47 | #-f/-F Treat link detection error as link down/link up (otherwise exit on error) |
Denys Vlasenko | 6cf7f01 | 2009-11-06 04:04:19 +0100 | [diff] [blame] | 48 | #-m MODE API mode (mii, priv, ethtool, wlan, auto) |
Denys Vlasenko | d892f71 | 2018-03-30 11:14:46 +0200 | [diff] [blame] | 49 | #-k Kill running daemon |