]> git.pld-linux.org Git - packages/systemd.git/blob - udev-net.helper
- s/daemon/hotplug (from hotplug)
[packages/systemd.git] / udev-net.helper
1 #!/bin/sh
2 #
3 # Kernel NET hotplug params include:
4 #       
5 #       ACTION=%s [register or unregister]
6 #       INTERFACE=%s
7
8 . /etc/sysconfig/network-scripts/functions.network
9
10 mesg() {
11     /usr/bin/logger -t $(basename $0)"[$$]" "$@"
12 }
13
14 debug_mesg() {
15     :
16 }
17
18 # returns true if device is either wireless, usbnet or is named eth* and supports ethtool
19 ethernet_check() {
20     [ -d /sys/class/net/$1/wireless/ ] && return 0
21     [[ "$1" == bnep* ]] && return 0
22     # eagle-usb/firewire create a fake ethX interface
23     if [ -x /usr/sbin/ethtool ] && ! /usr/sbin/ethtool $1 > /dev/null 2>&1;
24         then return 1;
25     fi
26     return 0;
27 }
28
29 if [ "$INTERFACE" = "" ]; then
30     mesg Bad NET invocation: \$INTERFACE is not set
31     exit 1
32 fi
33
34 export IN_HOTPLUG=1
35
36 case $ACTION in
37 add|register)
38     case $INTERFACE in
39         # interfaces that are registered after being "up" (?)
40         ppp*|ippp*|isdn*|plip*|lo*|irda*|dummy*|ipsec*|tun*|tap*)
41             debug_mesg assuming $INTERFACE is already up
42             exit 0
43             ;;
44         # interfaces that are registered then brought up
45         *)
46             # NOTE:  network configuration relies on administered state,
47             # we can't do much here without distro-specific knowledge
48             # such as whether/how to invoke DHCP, set up bridging, etc.
49
50             # Run ifrename as needed - Jean II
51             # Remap interface names based on MAC address. This workaround
52             # the dreaded configuration problem "all my cards are 'eth0'"...
53             # This needs to be done before ifup otherwise ifup will get
54             # confused by the name changed and because iface need to be
55             # down to change its name.
56             if [ -x /sbin/ifrename ] && [ -r /etc/iftab ]; then
57                 debug_mesg invoke ifrename for $INTERFACE
58                 NEWNAME=`/sbin/ifrename -i $INTERFACE`
59                 if [ -n "$NEWNAME" ]; then
60                     debug_mesg iface $INTERFACE is remapped to $NEWNAME
61                     INTERFACE=$NEWNAME
62                 fi;
63             fi
64
65             # conform to network service (AUTOMATIC_IFCFG)
66             [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
67
68             # don't do anything for non ethernet devices
69             ethernet_check $INTERFACE || exit 0;
70
71             # automatically create an interface file
72             CFG=/etc/sysconfig/network-scripts/ifcfg-$INTERFACE
73             if [ "$AUTOMATIC_IFCFG" != no -a ! -r $CFG ]; then
74                 debug_mesg creating config file for $INTERFACE
75                 cat > $CFG <<EOF
76 DEVICE=$INTERFACE
77 BOOTPROTO=dhcp
78 ONBOOT=yes
79 EOF
80             fi
81
82             if [ ! -f /var/lock/subsys/network ] || [ ! -r $CFG ]; then
83                 # Don't do anything if the network is stopped or interface isn't configured
84                 exit 0
85             fi
86
87             if [ -x /sbin/ifup ]; then
88                 debug_mesg invoke ifup $INTERFACE
89                 exec /sbin/ifup $INTERFACE hotplug
90             fi
91             ;;
92     esac
93     mesg $1 $ACTION event not handled
94     ;;
95
96 remove|unregister)
97     case $INTERFACE in
98         # interfaces that are unregistered after being "down" (?)
99         ppp*|ippp*|isdn*|plip*|lo*|irda*|dummy*|ipsec*|tun*|tap*)
100             debug_mesg assuming $INTERFACE is already down
101             exit 0
102             ;;
103         *)
104             if [ -x /sbin/ifdown ]; then
105                 debug_mesg invoke ifdown $INTERFACE
106                 exec /sbin/ifdown $INTERFACE daemon
107             fi
108             ;;
109     esac
110     mesg $1 $ACTION event not handled
111     ;;
112
113 *)
114     debug_mesg NET $ACTION event for $INTERFACE not supported
115     exit 1 ;;
116
117 esac
This page took 0.04824 seconds and 4 git commands to generate.