]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/networking/functions.network
36541eb13792d0ab55ab52a9acfa7f12e62ea34f
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.
67 boot_mesg
-n "Starting dhcpcd on the ${device} interface..."
69 # Check if a dhcpcd is already running.
70 local pid
="$(dhcpcd_get_pid "${device}")"
72 if dhcpcd_is_running
"${pid}"; then
73 boot_mesg
"dhcpcd already running!" ${WARNING}
78 # Check if a DHCP hostname has been set.
79 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
80 dhcp_start
+=( "-h" "${RED_DHCP_HOSTNAME}" )
83 # Tell dhcpcd to use the configured MTU
84 if [ -n "${RED_DHCP_FORCE_MTU}" ]; then
85 dhcp_start
+=( "--static" "mtu=${RED_DHCP_FORCE_MTU}" )
88 # Append any further command line options
92 /sbin
/dhcpcd
"${dhcp_start[@]}" ${device} >/dev
/null
2>&1
95 if [ "${ret}" -eq 0 ]; then
96 .
/var
/ipfire
/dhcpc
/dhcpcd-
"${device}".info
98 if [ $ip_address ]; then
101 boot_mesg
" DHCP Assigned Settings for ${device}:"
103 boot_mesg
" IP Address: $ip_address"
106 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
107 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
111 boot_mesg
" Subnet Mask: $subnet_mask"
113 boot_mesg
" Default Gateway: $routers"
115 boot_mesg
" DNS Server: $domain_name_servers"
120 boot_mesg
"DHCP for ${device} still running..."
131 # This function stops a previously started dhcpcd on a given device.
135 local leaseinfo
="/var/ipfire/dhcpc/dhcpcd-${device}.info"
137 boot_mesg
-n "Stopping dhcpcd on the ${device} interface..."
139 # Check if a dhcpcd is running.
140 local pid
="$(dhcpcd_get_pid "${device}")"
142 if ! dhcpcd_is_running
"${pid}"; then
143 boot_mesg
" Not running." ${WARNING}
149 /sbin
/dhcpcd
${dhcp_stop} ${device} &> /dev
/null
152 # Wait until dhcpd has stopped.
153 while [ -d "/proc/${pid}" ]; do
155 # repeat stop if dhcp was still running
156 /sbin
/dhcpcd
${dhcp_stop} ${device} &> /dev
/null
159 # Display console message, depended on the exit code
160 # of the stopped dhcpcd.
161 if [ "${ret}" -eq 0 ]; then
164 elif [ "${ret}" -eq 1 ]; then
165 boot_mesg
"failed to stop dhcpcd!" ${WARNING}
180 for path
in /dev
/cdc-
*; do
181 if [ -c "${path}" ]; then
182 _intf
="$(qmi_find_interface "${path}")"
184 # Check if the interface matches
185 if [ "${intf}" = "${_intf}" ]; then
196 qmi_find_interface
() {
199 qmicli
--device="${device}" --device-open-proxy --get-wwan-iface
202 qmi_enable_rawip_mode
() {
205 # Shut down the device first
206 ip link
set "${intf}" down
&>/dev
/null
208 echo "Y" > "/sys/class/net/${intf}/qmi/raw_ip"
211 qmi_configure_apn
() {
217 local username
="${4}"
218 local password
="${5}"
221 # We only support IPv4 right now
226 if [ -n "${apn}" ]; then
227 args
+=( "apn=${apn}" )
233 args
+=( "auth=${auth}" )
238 if [ -n "${username}" ]; then
239 args
+=( "username=${username}" )
243 if [ -n "${password}" ]; then
244 args
+=( "password=${password}" )
250 for arg
in ${args[@]}; do
251 if [ -n "${_args}" ]; then
254 _args
="${_args}${arg}"
257 qmicli
--device="${device}" --device-open-proxy \
258 --wds-start-network="${_args}" \
259 --client-no-release-cid &>/dev
/null
265 qmicli
--device="${device}" --device-open-proxy \
266 --wds-reset &>/dev
/null
269 # Assigns a "static" MAC address
270 qmi_assign_address
() {
274 local device
="$(qmi_find_device "${intf}")"
278 # Generate a "random" MAC address using the device number
279 printf -v address
"02:ff:ff:ff:ff:%02x" "${device:12}"
281 # Change the MAC address
282 ip link
set "${intf}" address
"${address}"