]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blame - src/initscripts/networking/dhcpcd.exe
Early spring clean: Remove trailing whitespaces, and correct licence headers
[people/mfischer/ipfire-2.x.git] / src / initscripts / networking / dhcpcd.exe
CommitLineData
66c36198
PM
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###############################################################################
1393a0c8 20
26617b09
AF
21. /etc/sysconfig/rc
22. $rc_functions
0e42072a 23
5ba06eb8 24eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
26617b09 25
21d1c72e 26dhcpcd_up()
26617b09
AF
27{
28 set | grep "^new_" | sed "s|^new_||g" | \
29 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
30
0c719f93
AF
31 #Check if this was the Red device...
32 if [ ! "$interface" == "$RED_DEV" ]; then
33 exit 0;
34 fi
35
5ba06eb8
AF
36 # Only if RED_TYPE=DHCP update /var/ipfire/red
37 if [ "$RED_TYPE" == "DHCP" ]; then
1434fa0d 38 # Check if we have to restart the services at update
44b2f168 39 [ ! -e "/var/ipfire/red/active" ] && update=1;
26617b09
AF
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
1434fa0d
MT
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
26617b09
AF
53
54 #Get IP Address
14e30bab 55 echo -n "$new_ip_address" > /var/ipfire/red/local-ipaddress
26617b09
AF
56
57 #Get default gateway
3d9d5884
AF
58 grep -v -E "\<gateway\>" /etc/hosts > /tmp/hosts
59 echo "$new_routers gateway" >> /tmp/hosts
26617b09
AF
60 mv /tmp/hosts /etc/hosts
61
62 fi
63 if [ $update ]; then
1393a0c8 64 [ -e "/var/ipfire/red/active" ] || touch /var/ipfire/red/active
14e30bab 65 echo -n "$new_routers" > /var/ipfire/red/remote-ipaddress
26617b09 66 logger -p local0.info -t dhcpcd.exe[$$] "$interface has been (re)configured with IP=$new_ip_address"
0e42072a 67 run_subdir ${rc_base}/init.d/networking/red.up/
26617b09
AF
68 touch /var/ipfire/red/active
69 fi
70}
71
21d1c72e 72dhcpcd_down()
26617b09 73{
21d1c72e
AF
74 set | grep "^new_" | sed "s|^new_||g" | \
75 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
5ba06eb8 76
1434fa0d
MT
77 # Remove DNS servers
78 rm -f /var/run/dns1 /var/run/dns2
79
5ba06eb8
AF
80 # Only if RED_TYPE=DHCP update /var/ipfire/red
81 if [ "$RED_TYPE" == "DHCP" ]; then
21d1c72e 82 rm -f /var/ipfire/red/active
455291f9 83 if [ ! $reason == "PREINIT" ]; then
bedfda83 84 logger -p local0.info -t dhcpcd.exe[$$] "${interface} has been brought down ($reason)"
455291f9
AF
85 run_subdir ${rc_base}/init.d/networking/red.down/
86 fi
21d1c72e 87 fi
26617b09 88}
1393a0c8 89
26617b09 90case "$reason" in
21d1c72e 91BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) dhcpcd_up;;
bedfda83 92PREINIT|EXPIRE|FAIL|IPV4LL|NAK|RELEASE|STOP) dhcpcd_down;;
26617b09 93esac