]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/initscripts/networking/functions.network
dhcpcd: 10-mtu break if carrier was lost
[people/pmueller/ipfire-2.x.git] / src / initscripts / networking / functions.network
CommitLineData
71ea0d68
SS
1#!/bin/sh
2#
3########################################################################
4# Begin
5#
6# Description : A collection of functions for the IPFire network scripts
7#
8# Authors : IPFire Development Team <developers@ipfire.org>
9#
10# Version : 01.00
11#
12# Notes :
13#
14########################################################################
15
16. /etc/sysconfig/rc
17. $rc_functions
18
19
20eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
21eval $(/usr/local/bin/readhash /var/ipfire/dns/settings)
22
23dhcpcd_get_pid() {
24 # This function returns the pid of a dhcpcd by a given
25 # network device, if a pidfile exists.
26
27 local device="$1"
28 local pidfile="/var/run/dhcpcd-${device}.pid"
29
30 # Check if a pid file exists.
31 if [ -f "${pidfile}" ] ; then
32
33 # Get the pid from the file.
34 local pid="$(<"${pidfile}")"
35
36 echo "${pid}"
37 fi
38}
39
40dhcpcd_is_running() {
41 # This functions checks if a dhcpcd is running by a given pid.
42
43 local pid="$1"
44
45 # Check if a dhcpcd is running.
46 if [ -n "${pid}" -a -d "/proc/${pid}" ]; then
47 # Return "0" (True) if a dhcpcd is running.
48 return 0
49 fi
50
51 # Return 1 (False) no dhcpcd is running.
52 return 1
53}
54
55dhcpcd_start() {
56 # This function will start a dhcpcd on a speciefied device.
57
58 local device="$1"
59 local dhcp_start=""
60
61 boot_mesg -n "Starting dhcpcd on the ${device} interface..."
62
63 # Check if a dhcpcd is already running.
64 local pid="$(dhcpcd_get_pid "${device}")"
65
66 if dhcpcd_is_running "${pid}"; then
67 boot_mesg "dhcpcd already running!" ${WARNING}
68 echo_warning
69 exit 2
70 fi
71
72 # Check if a DHCP hostname has been set.
73 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
74 dhcp_start+="-h ${RED_DHCP_HOSTNAME}"
75 fi
76
77 # Start dhcpcd.
2e28ecea 78 /sbin/dhcpcd ${dhcp_start} ${device} >/dev/null 2>&1
71ea0d68
SS
79 ret="$?"
80
81 if [ "${ret}" -eq 0 ]; then
82 . /var/ipfire/dhcpc/dhcpcd-"${device}".info
71ea0d68 83
f938083f
AF
84 if [ $ip_address ]; then
85 echo ""
86 echo_ok
87 boot_mesg " DHCP Assigned Settings for ${device}:"
71ea0d68 88 boot_mesg_flush
f938083f
AF
89 boot_mesg " IP Address: $ip_address"
90 boot_mesg_flush
91
92 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
93 boot_mesg " Hostname: $RED_DHCP_HOSTNAME"
94 boot_mesg_flush
95 fi
71ea0d68 96
f938083f
AF
97 boot_mesg " Subnet Mask: $subnet_mask"
98 boot_mesg_flush
99 boot_mesg " Default Gateway: $routers"
100 boot_mesg_flush
101 boot_mesg " DNS Server: $domain_name_servers"
102 boot_mesg_flush
103 else
104 echo ""
105 echo_ok
106 boot_mesg "DHCP for ${device} still running..."
107 boot_mesg_flush
108 fi
71ea0d68
SS
109 else
110 echo ""
111 $(exit "${ret}")
112 evaluate_retval
113 fi
114}
115
116dhcpcd_stop() {
117 # This function stops a previously started dhcpcd on a given device.
118
119 local device="$1"
120 local dhcp_stop="-k"
121 local leaseinfo="/var/ipfire/dhcpc/dhcpcd-${device}.info"
122
123 boot_mesg -n "Stopping dhcpcd on the ${device} interface..."
124
125 # Check if a dhcpcd is running.
126 local pid="$(dhcpcd_get_pid "${device}")"
127
128 if ! dhcpcd_is_running "${pid}"; then
02d67e75 129 boot_mesg " Not running." ${WARNING}
71ea0d68
SS
130 echo_warning
131 exit 1
132 fi
133
d43bb759 134 # Stop dhcpcd.
2e28ecea 135 /sbin/dhcpcd ${dhcp_stop} ${device} &> /dev/null
d43bb759
AF
136 ret="$?"
137
138 # Wait until dhcpd has stopped.
139 while [ -d "/proc/${pid}" ]; do
140 sleep 1
141 done
142
143 # Display console message, depended on the exit code
144 # of the stopped dhcpcd.
145 if [ "${ret}" -eq 0 ]; then
146 boot_mesg
147 echo_ok
148 elif [ "${ret}" -eq 1 ]; then
149 boot_mesg "failed to stop dhcpcd!" ${WARNING}
150 echo_warning
151 else
152 boot_mesg
153 echo_failure
71ea0d68
SS
154 fi
155}