]> git.ipfire.org Git - people/stevee/network.git/blame - functions.ppp
Reduce startup time by letting systemd create our files in /run.
[people/stevee/network.git] / functions.ppp
CommitLineData
5b20e43a
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
1848564d 5# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
5b20e43a
MT
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
c7ad7801
MT
22function ppp_common_ip_pre_up() {
23 local zone=${1}
24 shift
25
26 if ! zone_exists ${zone}; then
27 error "Zone '${zone}' does not exist."
28 return ${EXIT_ERROR}
29 fi
30
2c973348 31 routing_db_from_ppp ${zone} ipv4
ff8ec5ef 32
c7ad7801
MT
33 # Request firewall reload
34 event_firewall_reload
35
36 return ${EXIT_OK}
37}
38
39function ppp_common_ip_up() {
40 local zone=${1}
41 shift
42
43 if ! zone_exists ${zone}; then
44 error "Zone '${zone}' does not exist."
45 return ${EXIT_ERROR}
46 fi
47
2c973348
MT
48 routing_db_set ${zone} ipv4 active 1
49 routing_update ${zone} ipv4
ff8ec5ef 50
c7ad7801
MT
51 # Emit interface-up event
52 event_interface_up ${zone}
53
54 return ${EXIT_OK}
55}
56
57function ppp_common_ip_down() {
58 local zone=${1}
59 shift
60
61 if ! zone_exists ${zone}; then
62 error "Zone '${zone}' does not exist."
63 return ${EXIT_ERROR}
64 fi
65
201b7dff
MT
66 # Remove the information about this zone from the routing database
67 # and update the routing table.
68 routing_db_remove ${zone} ipv4
69 routing_update ${zone} ipv4
70
71 # Save accounting information
72 ppp_accounting ${zone}
73
74 # Emit interface-up event
75 event_interface_down ${zone}
76
77 return ${EXIT_OK}
78}
79
80function ppp_common_ipv6_up() {
81 local zone=${1}
82 shift
83
84 if ! zone_exists ${zone}; then
85 error "Zone '${zone}' does not exist."
86 return ${EXIT_ERROR}
87 fi
88
89 # Add information about this zone to the routing database.
90 routing_db_from_ppp ${zone} ipv6
91
92 routing_db_set ${zone} ipv6 active 1
93 routing_update ${zone} ipv6
94
95 # Emit interface-up event
96 event_interface_up ${zone}
97
98 return ${EXIT_OK}
99}
100
101function ppp_common_ipv6_down() {
102 local zone=${1}
103 shift
104
105 if ! zone_exists ${zone}; then
106 error "Zone '${zone}' does not exist."
107 return ${EXIT_ERROR}
108 fi
109
110 # Remove the information about this zone from the routing database
111 # and update the routing table.
112 routing_db_remove ${zone} ipv6
113 routing_update ${zone} ipv6
114
059469a8
MT
115 # Save accounting information
116 ppp_accounting ${zone}
117
c7ad7801
MT
118 # Emit interface-up event
119 event_interface_down ${zone}
120
121 return ${EXIT_OK}
122}
123
5b20e43a
MT
124function ppp_secret() {
125 local USER=${1}
126 local SECRET=${2}
127 local a
128 local secret
129 local user
130
131 # Updateing secret file
132 > ${PPP_SECRETS}.tmp
133 while read user a secret; do
134 if [ "'${USER}'" != "${user}" ]; then
135 echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp
136 fi
137 done < ${PPP_SECRETS}
138 echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp
139 cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS}
140 rm -f ${PPP_SECRETS}.tmp
141}
142
059469a8
MT
143function ppp_accounting() {
144 local zone=${1}
145 shift
5b20e43a 146
059469a8
MT
147 db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
148 --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
5b20e43a 149}
711ffac1
MT
150
151function pppd_exec() {
711ffac1
MT
152 log DEBUG "Running pppd with parameters '$@'."
153
154 pppd $@ > /dev/null
155}