]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/networking/functions.network
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
25 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
26 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/dns
/settings
)
29 # This function returns the pid of a dhcpcd by a given
30 # network device, if a pidfile exists.
33 local pidfile
="/var/run/dhcpcd/${device}.pid"
35 # Check if a pid file exists.
36 if [ -f "${pidfile}" ] ; then
38 # Get the pid from the file.
39 local pid
="$(<"${pidfile}")"
46 # This functions checks if a dhcpcd is running by a given pid.
50 # Check if a dhcpcd is running.
51 if [ -n "${pid}" -a -d "/proc/${pid}" ]; then
52 # Return "0" (True) if a dhcpcd is running.
56 # Return 1 (False) no dhcpcd is running.
61 # This function will start a dhcpcd on a speciefied device.
66 boot_mesg
-n "Starting dhcpcd on the ${device} interface..."
68 # Check if a dhcpcd is already running.
69 local pid
="$(dhcpcd_get_pid "${device}")"
71 if dhcpcd_is_running
"${pid}"; then
72 boot_mesg
"dhcpcd already running!" ${WARNING}
77 # Check if a DHCP hostname has been set.
78 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
79 dhcp_start
+=( "-h" "${RED_DHCP_HOSTNAME}" )
82 # Tell dhcpcd to use the configured MTU
83 if [ -n "${RED_DHCP_FORCE_MTU}" ]; then
84 dhcp_start
+=( "--static" "mtu=${RED_DHCP_FORCE_MTU}" )
88 /sbin
/dhcpcd
"${dhcp_start[@]}" ${device} >/dev
/null
2>&1
91 if [ "${ret}" -eq 0 ]; then
92 .
/var
/ipfire
/dhcpc
/dhcpcd-
"${device}".info
94 if [ $ip_address ]; then
97 boot_mesg
" DHCP Assigned Settings for ${device}:"
99 boot_mesg
" IP Address: $ip_address"
102 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
103 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
107 boot_mesg
" Subnet Mask: $subnet_mask"
109 boot_mesg
" Default Gateway: $routers"
111 boot_mesg
" DNS Server: $domain_name_servers"
116 boot_mesg
"DHCP for ${device} still running..."
127 # This function stops a previously started dhcpcd on a given device.
131 local leaseinfo
="/var/ipfire/dhcpc/dhcpcd-${device}.info"
133 boot_mesg
-n "Stopping dhcpcd on the ${device} interface..."
135 # Check if a dhcpcd is running.
136 local pid
="$(dhcpcd_get_pid "${device}")"
138 if ! dhcpcd_is_running
"${pid}"; then
139 boot_mesg
" Not running." ${WARNING}
145 /sbin
/dhcpcd
${dhcp_stop} ${device} &> /dev
/null
148 # Wait until dhcpd has stopped.
149 while [ -d "/proc/${pid}" ]; do
151 # repeat stop if dhcp was still running
152 /sbin
/dhcpcd
${dhcp_stop} ${device} &> /dev
/null
155 # Display console message, depended on the exit code
156 # of the stopped dhcpcd.
157 if [ "${ret}" -eq 0 ]; then
160 elif [ "${ret}" -eq 1 ]; then
161 boot_mesg
"failed to stop dhcpcd!" ${WARNING}