]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/initscripts/init.d/networking/dhcpcd.exe
Merge branch 'next' of ssh://git.ipfire.org/pub/git/ipfire-2.x into next
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / 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 #Force MTU option for KabelDeutschland because this ISP
35 #set the MTU to 576 instead of the supportet 1500
36 if [ $RED_DHCP_FORCE_MTU -ge 576 ]; then
37 logger -p local0.info -t dhcpcd.exe[$$] "Force mtu to $RED_DHCP_FORCE_MTU"
38 ip link set $interface mtu $RED_DHCP_FORCE_MTU
39 fi
40
41 #Check if we have to restart the services at update
42 [ ! -e "/var/ipfire/red/active" ] && update=1;
43 if [ "$old_domain_name_service" != "$new_domain_name_service" ]; then
44 update=1;
45 fi
46 if [ "$old_ip_address" != "$new_ip_address" ]; then
47 update=1;
48 fi
49 if [ "$old_routers" != "$new_routers" ]; then
50 update=1;
51 fi
52
53 #Get DNS from dhcp
54 if [ -n "$DNS0" ] && [ -n "$DNS1" ]; then
55 logger -p local0.info -t dhcpcd.exe[$$] "Overwritting DNS-Server addresses with ${DNS0},${DNS1}"
56 echo -n ${DNS0} > /var/ipfire/red/dns1
57 echo -n ${DNS1} > /var/ipfire/red/dns2
58 else
59 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var/ipfire/red/dns1
60 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var/ipfire/red/dns2
61 fi
62
63 #Get IP Address
64 echo -n "$new_ip_address" > /var/ipfire/red/local-ipaddress
65
66 #Get default gateway
67 grep -v -E "\<gateway\>" /etc/hosts > /tmp/hosts
68 echo "$new_routers gateway" >> /tmp/hosts
69 mv /tmp/hosts /etc/hosts
70
71 fi
72 if [ $update ]; then
73 [ -e "/var/ipfire/red/active" ] || touch /var/ipfire/red/active
74 echo -n "$new_routers" > /var/ipfire/red/remote-ipaddress
75 logger -p local0.info -t dhcpcd.exe[$$] "$interface has been (re)configured with IP=$new_ip_address"
76 run_subdir ${rc_base}/init.d/networking/red.up/
77 touch /var/ipfire/red/active
78 fi
79 }
80
81 dhcpcd_down()
82 {
83 set | grep "^new_" | sed "s|^new_||g" | \
84 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
85
86 # Only if RED_TYPE=DHCP update /var/ipfire/red
87 if [ "$RED_TYPE" == "DHCP" ]; then
88 logger -p local0.info -t dhcpcd.exe[$$] "${interface} has been brought down"
89 rm -f /var/ipfire/red/active
90 run_subdir ${rc_base}/init.d/networking/red.down/
91 fi
92 }
93
94 case "$reason" in
95 BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) dhcpcd_up;;
96 PREINIT|EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) dhcpcd_down;;
97 esac