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 service_start
"pppd@${interface}"
31 function pppd_stop
() {
33 assert isset interface
35 service_stop
"pppd@${interface}"
38 function pppd_status
() {
40 assert isset interface
42 service_status
"pppd@${interface}"
45 function ppp_common_ip_pre_up
() {
49 if ! zone_exists
${zone}; then
50 error
"Zone '${zone}' does not exist."
54 routing_db_from_ppp
${zone} ipv4
56 # Request firewall reload
57 event_emit firewall-reload
62 function ppp_common_ip_up
() {
66 if ! zone_exists
${zone}; then
67 error
"Zone '${zone}' does not exist."
71 routing_db_set
${zone} ipv4 active
1
72 routing_update
${zone} ipv4
74 # Emit interface-up event
75 event_interface_up
${zone}
80 function ppp_common_ip_down
() {
84 if ! zone_exists
${zone}; then
85 error
"Zone '${zone}' does not exist."
89 # Remove the information about this zone from the routing database
90 # and update the routing table.
91 routing_db_remove
${zone} ipv4
92 routing_update
${zone} ipv4
94 # Save accounting information
95 ppp_accounting
${zone}
97 # Emit interface-up event
98 event_interface_down
${zone}
103 function ppp_common_ipv6_up
() {
107 if ! zone_exists
${zone}; then
108 error
"Zone '${zone}' does not exist."
112 # Add information about this zone to the routing database.
113 routing_db_from_ppp
${zone} ipv6
115 routing_db_set
${zone} ipv6 active
1
116 routing_update
${zone} ipv6
118 # Emit interface-up event
119 event_interface_up
${zone}
124 function ppp_common_ipv6_down
() {
128 if ! zone_exists
${zone}; then
129 error
"Zone '${zone}' does not exist."
133 # Remove the information about this zone from the routing database
134 # and update the routing table.
135 routing_db_remove
${zone} ipv6
136 routing_update
${zone} ipv6
138 # Save accounting information
139 ppp_accounting
${zone}
141 # Emit interface-up event
142 event_interface_down
${zone}
147 function ppp_secret
() {
154 # Updateing secret file
156 while read user a secret
; do
157 if [ "'${USER}'" != "${user}" ]; then
158 echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp
160 done < ${PPP_SECRETS}
161 echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp
162 cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS}
163 rm -f ${PPP_SECRETS}.tmp
166 function ppp_accounting() {
170 db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
171 --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
174 function pppd_exec() {
175 log DEBUG "Running pppd with parameters '$@
'."
180 function pppd_write_config() {
181 local file=${1}; shift
188 local plugin plugin_options
191 while [ $# -gt 0 ]; do
194 auth=$(cli_get_val ${1})
196 # The name of the created ppp interface.
198 interface=$(cli_get_val ${1})
200 # Maximum Transmission Unit
202 mtu=$(cli_get_val ${1})
204 # Maximum Receive Unit
206 mru=$(cli_get_val ${1})
209 plugin=$(cli_get_val ${1})
212 plugin_options=$(cli_get_val ${1})
215 user=$(cli_get_val ${1})
218 log WARNING "Unhandled argument: ${1}"
224 if [ -z "${interface}" ]; then
225 log ERROR "You need to set the interface name: ${interface}"
228 linkname=${interface}
231 if ! isoneof ${auth} ${PPP_SUPPORTED_AUTH_METHODS}; then
232 log ERROR "Unsupported auth method: ${auth}"
237 # Write the configuration header.
238 mkdir -p $(dirname ${file}) 2>/dev/null
239 config_header "PPP daemon configuration file" > ${file}
241 # At first, set the name of the link.
242 print "name ${linkname}\nlinkname ${linkname}\n" >> ${file}
244 # Configure the interface name.
245 print "# Interface name\nifname ${interface}\n" >> ${file}
248 if isset plugin; then
250 print "# Plugin settings"
251 print "plugin ${plugin} ${plugin_options}"
256 # User authentication
259 print "# User authentication"
264 print "require-${auth}"
272 isset mru || mru=${mtu}
275 print "# MTU/MRU settings"
282 # Add the default settings.
284 print "# Disable the compression"
285 print "noccp noaccomp nodeflate nopcomp novj novjccomp nobsdcomp nomppe"
287 print "noipdefault nodetach debug"