Netzwerkscripts erweitert.
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / net / common / dhcpcd
1 #!/bin/sh
2 # Begin $network-devices/services/dhcpcd
3
4 # Based upon lfs-bootscripts-1.12 $network_devices/if{down,up}
5 # Rewritten by Nathan Coulson <nathan@linuxfromscratch.org>
6 # Adapted for dhcpcd by DJ Lucas <dj@lucasit.com>
7 # Made compatible for ipfire by Michael Tremer mitch@ipfire.org
8
9 . /etc/sysconfig/rc
10 . $rc_functions
11
12 PIDFILE="/var/run/dhcpcd-$1.pid"
13 LEASEINFO="/var/ipfire/dhcpc/dhcpcd-$1.info"
14
15 case "$2" in
16         up)
17                 boot_mesg -n "Starting dhcpcd on the $1 interface..."           
18                 echo -n "${1}" > /var/ipfire/red/iface
19
20                 # Test to see if there is a stale pid file
21                 if [ -f "$PIDFILE" ]
22                 then
23                         ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null
24                         if [ $? != 0 ]
25                         then
26                                 rm -f /var/run/dhcpcd-$1.pid > /dev/null
27                         else
28                                 boot_mesg "dhcpcd already running!" ${WARNING}
29                                 echo_warning
30                                 exit 2
31                         fi
32                 fi
33                 if [ "$NAME" == "red" ]; then
34                         /sbin/iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i ${1} -j ACCEPT
35                         /sbin/iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i ${1} -j ACCEPT
36                 fi
37                 
38                 DHCP_START="-N -R -L /var/ipfire/dhcpc "
39                 
40                 if [ -n "${DHCP_HOSTNAME}" ]; then
41                         DHCP_START+="-h ${DHCP_HOSTNAME} "
42           fi
43                 /sbin/dhcpcd $1 $DHCP_START >/dev/null 2>&1
44                 # Save the return value
45                 RET="$?"
46                 # Print the assigned settings if requested
47                 if [ "$RET" = "0" -a "$PRINTIP" = "yes" ]; then
48                         . /var/ipfire/dhcpc/dhcpcd-$1.info
49                         logger -t ipfire "DHCPCD Success"
50                         if [ "$PRINTALL" = "yes" ]; then
51                                 echo ""
52                                 echo_ok
53                                 boot_mesg "           DHCP Assigned Settings for ${1}:"
54                                 boot_mesg_flush
55                                 boot_mesg "           IP Address:      $IPADDR"
56                                 boot_mesg_flush
57                                 if [ -n "${DHCP_HOSTNAME}" ]; then
58                                         boot_mesg "           Hostname:        $DHCP_HOSTNAME"
59                                         boot_mesg_flush
60                                 fi
61                                 boot_mesg "           Subnet Mask:     $NETMASK"
62                                 boot_mesg_flush
63                                 boot_mesg "           Default Gateway: $GATEWAY"
64                                 boot_mesg_flush
65                                 boot_mesg "           DNS Server:      $DNS"
66                                 boot_mesg_flush
67                         else
68                                 boot_mesg " IP Addresss: ""$IPADDR"
69                                 echo_ok
70                         fi
71                         if [ "$DNS1" = "" ]; then
72                                 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var/ipfire/red/dns1
73                                 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var/ipfire/red/dns2
74                         else 
75                                 echo "$DNS1" > /var/ipfire/red/dns1
76                                 echo "$DNS2" > /var/ipfire/red/dns2
77                         fi
78                         . /var/ipfire/dhcpc/dhcpcd-${1}.info
79                         echo "$IPADDR"  > /var/ipfire/red/local-ipaddress
80                         echo "$GATEWAY" > /var/ipfire/red/remote-ipaddress
81                 else
82                         echo ""
83                         logger -t ipfire "DHCPCD Fail"
84                         $(exit "$RET")
85                         evaluate_retval
86                 fi
87         ;;
88
89         down)
90                 boot_mesg -n "Stopping dhcpcd on the $1 interface..."
91                 # Do nothing with the client daemon if we have an infinate 
92                 # lease time as the client exits when started in this case,
93                 # just echo OK.
94                 DHCP_STOP="-k"
95                 if [ -e $LEASEINFO ]
96                 then
97                         . $LEASEINFO
98
99                         if [ "$LEASETIME" = "4294967295" ]
100                         then
101                                 # do nothing, just echo ok
102                                 echo ""
103                                 echo_ok
104                         else
105                         if [ -n "$DHCP_STOP" ]
106                         then
107                                 /sbin/dhcpcd $1 $DHCP_STOP &> /dev/null
108                                 RET="$?"
109                                 if [ "$RET" -eq 0 ]; then
110                                         echo ""
111                                         echo_ok
112                                 elif [ "$RET" -eq 1 ]; then
113                                         boot_mesg "dhcpcd not running!" ${WARNING}
114                                         echo_warning
115                                 else
116                                         echo ""
117                                         echo_failure
118                                 fi
119                         else
120                                 echo ""
121                                 killproc dhcpcd
122                         fi
123                     fi
124                 else
125                         boot_mesg -n "LEASEINFO Test failed! - " ${WARNING}
126                         boot_mesg "dhcpcd is not running!" ${WARNING}
127                         echo_warning
128                         exit 1
129                 fi
130         ;;
131
132         *)
133                 echo "Usage: $0 [interface] {up|down}"
134                 exit 1
135         ;;
136 esac
137
138 # End $network_devices/services/dhcpcd