]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blob - src/initscripts/networking/dhcpcd.exe
Merge branch 'master' into next
[people/mfischer/ipfire-2.x.git] / src / initscripts / networking / dhcpcd.exe
1 ###############################################################################
2 # #
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 ###############################################################################
20
21 . /etc/sysconfig/rc
22 . $rc_functions
23
24 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
25
26 dhcpcd_up()
27 {
28 set | grep "^new_" | sed "s|^new_||g" | \
29 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
30
31 #Check if this was the Red device...
32 if [ ! "$interface" == "$RED_DEV" ]; then
33 exit 0;
34 fi
35
36 # Only if RED_TYPE=DHCP update /var/ipfire/red
37 if [ "$RED_TYPE" == "DHCP" ]; then
38 # Check if we have to restart the services at update
39 [ ! -e "/var/ipfire/red/active" ] && update=1;
40 if [ "$old_domain_name_service" != "$new_domain_name_service" ]; then
41 update=1;
42 fi
43 if [ "$old_ip_address" != "$new_ip_address" ]; then
44 update=1;
45 fi
46 if [ "$old_routers" != "$new_routers" ]; then
47 update=1;
48 fi
49
50 # Get DNS from dhcp
51 /etc/rc.d/helper/getdnsfromdhcpc.pl 1 > /var/run/dns1
52 /etc/rc.d/helper/getdnsfromdhcpc.pl 2 > /var/run/dns2
53
54 #Get IP Address
55 echo -n "$new_ip_address" > /var/ipfire/red/local-ipaddress
56
57 #Get default gateway
58 grep -v -E "\<gateway\>" /etc/hosts > /tmp/hosts
59 echo "$new_routers gateway" >> /tmp/hosts
60 mv /tmp/hosts /etc/hosts
61
62 fi
63 if [ $update ]; then
64 [ -e "/var/ipfire/red/active" ] || touch /var/ipfire/red/active
65 echo -n "$new_routers" > /var/ipfire/red/remote-ipaddress
66 logger -p local0.info -t dhcpcd.exe[$$] "$interface has been (re)configured with IP=$new_ip_address"
67 run_subdir ${rc_base}/init.d/networking/red.up/
68 touch /var/ipfire/red/active
69 fi
70 }
71
72 dhcpcd_down()
73 {
74 set | grep "^new_" | sed "s|^new_||g" | \
75 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
76
77 # Remove DNS servers
78 rm -f /var/run/dns1 /var/run/dns2
79
80 # Only if RED_TYPE=DHCP update /var/ipfire/red
81 if [ "$RED_TYPE" == "DHCP" ]; then
82 rm -f /var/ipfire/red/active
83 if [ ! $reason == "PREINIT" ]; then
84 logger -p local0.info -t dhcpcd.exe[$$] "${interface} has been brought down ($reason)"
85 run_subdir ${rc_base}/init.d/networking/red.down/
86 fi
87 fi
88 }
89
90 case "$reason" in
91 BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) dhcpcd_up;;
92 PREINIT|EXPIRE|FAIL|IPV4LL|NAK|RELEASE|STOP) dhcpcd_down;;
93 esac