]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/networking/dhcpcd.exe
Merge branch 'master' into next
[ipfire-2.x.git] / src / initscripts / networking / dhcpcd.exe
1 ########################################################################
2 # Begin
3 #
4 # Description : DHCP Client Script
5 #
6 # Authors : Arne Fitzenreiter - arne_f@ipfire.org
7 #
8 # Version : 02.00
9 #
10 # Notes :
11 #
12 ########################################################################
13
14 . /etc/sysconfig/rc
15 . $rc_functions
16
17
18 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
19 eval $(/usr/local/bin/readhash /var/ipfire/dns/settings)
20
21 dhcpcd_up()
22 {
23 set | grep "^new_" | sed "s|^new_||g" | \
24 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
25
26 #Check if this was the Red device...
27 if [ ! "$interface" == "$RED_DEV" ]; then
28 exit 0;
29 fi
30
31 # Only if RED_TYPE=DHCP update /var/ipfire/red
32 if [ "$RED_TYPE" == "DHCP" ]; then
33
34 #Check if we have to restart the services at update
35 [ ! -e "/var/ipfire/red/active" ] && update=1;
36 if [ "$old_domain_name_service" != "$new_domain_name_service" ]; then
37 update=1;
38 fi
39 if [ "$old_ip_address" != "$new_ip_address" ]; then
40 update=1;
41 fi
42 if [ "$old_routers" != "$new_routers" ]; then
43 update=1;
44 fi
45
46 #Get DNS from dhcp
47 if [ -n "$DNS0" ] && [ -n "$DNS1" ]; then
48 logger -p local0.info -t dhcpcd.exe[$$] "Overwritting DNS-Server addresses with ${DNS0},${DNS1}"
49 echo -n ${DNS0} > /var/ipfire/red/dns1
50 echo -n ${DNS1} > /var/ipfire/red/dns2
51 else
52 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var/ipfire/red/dns1
53 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var/ipfire/red/dns2
54 fi
55
56 #Get IP Address
57 echo -n "$new_ip_address" > /var/ipfire/red/local-ipaddress
58
59 #Get default gateway
60 grep -v -E "\<gateway\>" /etc/hosts > /tmp/hosts
61 echo "$new_routers gateway" >> /tmp/hosts
62 mv /tmp/hosts /etc/hosts
63
64 fi
65 if [ $update ]; then
66 [ -e "/var/ipfire/red/active" ] || touch /var/ipfire/red/active
67 echo -n "$new_routers" > /var/ipfire/red/remote-ipaddress
68 logger -p local0.info -t dhcpcd.exe[$$] "$interface has been (re)configured with IP=$new_ip_address"
69 run_subdir ${rc_base}/init.d/networking/red.up/
70 touch /var/ipfire/red/active
71 fi
72 }
73
74 dhcpcd_down()
75 {
76 set | grep "^new_" | sed "s|^new_||g" | \
77 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
78
79 # Only if RED_TYPE=DHCP update /var/ipfire/red
80 if [ "$RED_TYPE" == "DHCP" ]; then
81 logger -p local0.info -t dhcpcd.exe[$$] "${interface} has been brought down"
82 rm -f /var/ipfire/red/active
83 run_subdir ${rc_base}/init.d/networking/red.down/
84 fi
85 }
86
87 case "$reason" in
88 BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) dhcpcd_up;;
89 PREINIT|EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) dhcpcd_down;;
90 esac