]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/networking/dhcpcd.exe
suricata: Change midstream policy to "pass-flow"
[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 . /etc/init.d/networking/functions.network
24
25 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
26
27 dhcpcd_up()
28 {
29 set | grep "^new_" | sed "s|^new_||g" | \
30 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
31
32 #Check if this was the Red device...
33 if [ ! "$interface" == "$RED_DEV" ]; then
34 exit 0;
35 fi
36
37 # Check if we have to restart the services at update
38 [ ! -e "/var/ipfire/red/active" ] && update=1;
39 if [ "$old_domain_name_service" != "$new_domain_name_service" ]; then
40 update=1;
41 fi
42 if [ "$old_ip_address" != "$new_ip_address" ]; then
43 update=1;
44 fi
45 if [ "$old_routers" != "$new_routers" ]; then
46 update=1;
47 fi
48
49 # Get DNS from dhcp
50 /etc/rc.d/helper/getdnsfromdhcpc.pl 1 > /var/run/dns1
51 /etc/rc.d/helper/getdnsfromdhcpc.pl 2 > /var/run/dns2
52
53 #Get IP Address
54 echo -n "$new_ip_address" > /var/ipfire/red/local-ipaddress
55
56 # Get default gateway
57 if [ -n "${new_routers}" ]; then
58 grep -v -E "\<gateway\>" /etc/hosts > /tmp/hosts
59 echo "$new_routers gateway" >> /tmp/hosts
60 mv /tmp/hosts /etc/hosts
61 fi
62
63 if [ $update ]; then
64 # Consider RED being active
65 touch /var/ipfire/red/active
66
67 if [ -n "${new_routers}" ]; then
68 echo -n "${new_routers}" > /var/ipfire/red/remote-ipaddress
69 fi
70
71 logger -p local0.info -t dhcpcd.exe[$$] "$interface has been (re)configured with IP=$new_ip_address"
72 run_subdir ${rc_base}/init.d/networking/red.up/
73 fi
74 }
75
76 dhcpcd_down()
77 {
78 set | grep "^new_" | sed "s|^new_||g" | \
79 sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
80
81 # Remove DNS servers
82 rm -f /var/run/dns1 /var/run/dns2
83
84 # Consider RED to be no longer active
85 rm -f /var/ipfire/red/active
86
87 if [ ! $reason == "PREINIT" ]; then
88 logger -p local0.info -t dhcpcd.exe[$$] "${interface} has been brought down ($reason)"
89 run_subdir ${rc_base}/init.d/networking/red.down/
90 fi
91
92 # Remove any configured IP address from the device
93 ip addr flush dev "${interface}" &>/dev/null
94
95 return 0
96 }
97
98 case "${reason}" in
99 BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC)
100 dhcpcd_up
101 ;;
102 PREINIT|EXPIRE|FAIL|IPV4LL|NAK|RELEASE|STOP)
103 dhcpcd_down
104 ;;
105 # Ignored events where we do not need to do anything
106 STOPPED|CARRIER|NOCARRIER)
107 ;;
108 *)
109 logger -p "local0.info" -t "dhcpcd.exe[$$]" "Unhandled DHCP event: ${reason}"
110 ;;
111 esac