2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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 ###############################################################################
22 PPP_SUPPORTED_AUTH_METHODS
="chap pap"
24 function pppd_start
() {
26 assert isset interface
28 # This will block until the connection has been established or
30 service_start
"pppd@${interface}"
32 # Get the exit code of the ppp daemon and figure out
34 local ret
=$
(service_get_exitcode
"pppd@${interface}")
40 error
"pppd crashed for an unknown reason"
43 error
"pppd: Configuration error"
46 error
"pppd terminated"
49 error
"pppd: Authentication failed"
52 error
"pppd: Unhandled exit code: ${ret}"
59 function pppd_stop
() {
61 assert isset interface
63 service_stop
"pppd@${interface}"
66 function pppd_status
() {
68 assert isset interface
70 service_status
"pppd@${interface}"
73 function ppp_common_ip_pre_up
() {
77 if ! zone_exists
${zone}; then
78 error
"Zone '${zone}' does not exist."
82 routing_db_from_ppp
${zone} ipv4
84 # Request firewall reload
85 event_emit firewall-reload
90 function ppp_common_ip_up
() {
94 if ! zone_exists
${zone}; then
95 error
"Zone '${zone}' does not exist."
99 routing_db_set
${zone} ipv4 active
1
100 routing_update
${zone} ipv4
101 routing_default_update
103 # Emit interface-up event
104 event_interface_up
${zone}
109 function ppp_common_ip_down
() {
113 if ! zone_exists
${zone}; then
114 error
"Zone '${zone}' does not exist."
118 # Remove the information about this zone from the routing database
119 # and update the routing table.
120 routing_db_remove
${zone} ipv4
121 routing_update
${zone} ipv4
122 routing_default_update
124 # Save accounting information
125 ppp_accounting
${zone}
127 # Emit interface-up event
128 event_interface_down
${zone}
133 function ppp_common_ipv6_up
() {
137 if ! zone_exists
${zone}; then
138 error
"Zone '${zone}' does not exist."
142 # Add information about this zone to the routing database.
143 routing_db_from_ppp
${zone} ipv6
145 routing_db_set
${zone} ipv6 active
1
146 routing_update
${zone} ipv6
147 routing_default_update
149 # Emit interface-up event
150 event_interface_up
${zone}
155 function ppp_common_ipv6_down
() {
159 if ! zone_exists
${zone}; then
160 error
"Zone '${zone}' does not exist."
164 # Remove the information about this zone from the routing database
165 # and update the routing table.
166 routing_db_remove
${zone} ipv6
167 routing_update
${zone} ipv6
168 routing_default_update
170 # Save accounting information
171 ppp_accounting
${zone}
173 # Emit interface-up event
174 event_interface_down
${zone}
179 function ppp_secret
() {
186 # Updateing secret file
188 while read user a secret
; do
189 if [ "'${USER}'" != "${user}" ]; then
190 echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp
192 done < ${PPP_SECRETS}
193 echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp
194 cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS}
195 rm -f ${PPP_SECRETS}.tmp
198 function ppp_accounting() {
202 db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
203 --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
206 function pppd_exec() {
207 log DEBUG "Running pppd with parameters '$@
'."
212 function pppd_write_config() {
213 local file=${1}; shift
217 local default_asyncmap="true"
219 local lcp_echo_failure=3
220 local lcp_echo_interval=20
223 local plugin plugin_options
227 while [ $# -gt 0 ]; do
230 auth=$(cli_get_val ${1})
232 # Enable or disable the use of the default asyncmap.
233 --default-asyncmap=*)
234 value=$(cli_get_val ${1})
235 if enabled value; then
236 default_asyncmap="true"
238 default_asyncmap="false"
241 # The name of the created ppp interface.
243 interface=$(cli_get_val ${1})
246 --lcr-echo-failure=*)
247 lcr_echo_failure=$(cli_get_val ${1})
249 if ! isinteger ${lcr_echo_failure}; then
250 error "--lcr-echo-failure= requires a number"
255 --lcr-echo-interval=*)
256 lcr_echo_interval=$(cli_get_val ${1})
258 if ! isinteger ${lcr_echo_failure}; then
259 error "--lcr-echo-interval= requires a number"
263 # Maximum Transmission Unit
265 mtu=$(cli_get_val ${1})
267 # Maximum Receive Unit
269 mru=$(cli_get_val ${1})
272 plugin=$(cli_get_val ${1})
275 plugin_options=$(cli_get_val ${1})
278 user=$(cli_get_val ${1})
281 log WARNING "Unhandled argument: ${1}"
287 if [ -z "${interface}" ]; then
288 log ERROR "You need to set the interface name: ${interface}"
291 linkname="${interface}"
294 if ! isoneof ${auth} ${PPP_SUPPORTED_AUTH_METHODS}; then
295 log ERROR "Unsupported auth method: ${auth}"
300 # Write the configuration header.
301 mkdir -p $(dirname ${file}) 2>/dev/null
302 config_header "PPP daemon configuration file" > ${file}
304 # At first, set the name of the link.
305 print "linkname ${linkname}\n" >> ${file}
307 # Configure the interface name.
308 print "# Interface name\nifname ${interface}\n" >> ${file}
311 if isset plugin; then
313 print "# Plugin settings"
314 print "plugin ${plugin} ${plugin_options}"
319 # User authentication
322 print "# User authentication"
327 print "require-${auth}"
335 isset mru || mru=${mtu}
338 print "# MTU/MRU settings"
346 if enabled default_asyncmap; then
348 print "# Use the default asyncmap."
349 print "default-asyncmap"
356 print "# LCP settings"
357 print "lcp-echo-failure ${lcp_echo_failure}"
358 print "lcp-echo-interval ${lcp_echo_interval}"
362 # Add the default settings.
364 print "# Disable the compression"
365 print "noccp noaccomp nodeflate nopcomp novj novjccomp nobsdcomp nomppe"
367 print "noipdefault updetach debug"