]> git.ipfire.org Git - people/stevee/network.git/blame - src/functions/functions.pppoe-server
Local zones must be named net0, net1, ...
[people/stevee/network.git] / src / functions / functions.pppoe-server
CommitLineData
999d659b
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2012 IPFire Network Development Team #
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
fa19a5ae
SS
22pppoe_server_init() {
23 # Load the pppoe kernel module
24 module_load "pppoe"
25}
26
1c6a4e30 27pppoe_server_start() {
999d659b
MT
28 local zone=${1}
29 assert isset zone
30
fa19a5ae
SS
31 # Initialise the system for this
32 pppoe_server_init
33
1d08b9b3 34 service_start "pppoe-server@${zone}.service"
999d659b
MT
35}
36
1c6a4e30 37pppoe_server_stop() {
999d659b
MT
38 local zone=${1}
39 assert isset zone
40
1d08b9b3 41 service_stop "pppoe-server@${zone}.service"
999d659b
MT
42}
43
1c6a4e30 44pppoe_server_status() {
999d659b
MT
45 local zone=${1}
46 assert isset zone
47
1d08b9b3 48 service_status "pppoe-server@${zone}.service"
999d659b
MT
49}
50
1c6a4e30 51pppoe_server_options() {
999d659b
MT
52 local file=${1}
53 assert isset file
54
55 local zone=${2}
56 assert isset zone
57
58 shift 2
59
60 local auth="false"
61 local default_asyncmap="true"
62 local dns_servers
63 local lcp_echo_failure=5
64 local lcp_echo_interval=60
65 local proxyarp="true"
66 local required_auths
67 local value
68
69 while [ $# -gt 0 ]; do
70 case "${1}" in
71 --auth=*)
72 auth=$(cli_get_val ${1})
73 ;;
74 --default-asyncmap=*)
75 default_asyncmap=$(cli_get_val ${1})
76 ;;
77 --dns-server=*)
78 dns_servers="${dns_servers} $(cli_get_val ${1})"
79 ;;
80 --lcp-echo-failure=*)
81 lcp_echo_failure=$(cli_get_val ${1})
82 assert isinteger ${lcp_echo_failure}
83 ;;
84 --lcp-echo-interval=*)
85 lcp_echo_interval=$(cli_get_val ${1})
86 assert isinteger ${lcp_echo_interval}
87 ;;
88 --proxyarp=*)
89 proxyarp=$(cli_get_val ${1})
90 ;;
91 --require-auth=*)
92 required_auths="${required_auths} $(cli_get_val ${1})"
93 ;;
94 esac
95 shift
96 done
97
98 mkdir -p $(dirname ${file}) 2>/dev/null
99 config_header "pppoe-server options configuration file" > ${file}
100
101 # Authentication
102 (
103 print "# Authentication"
104 if enabled auth; then
105 print "auth"
106 else
107 print "noauth"
108 fi
109 print
110 ) >> ${file}
111
112 # If there are only a number of auth algorithms allowed, we
113 # define them here.
114 if isset required_auths; then
115 print "# Required authentication methods" >> ${file}
116 local method
117 for method in ${required_auths}; do
118 print "require-${method}"
119 done >> ${file}
120 print >> ${file}
121 fi
122
123 # DNS servers
124 if isset dns_servers; then
125 print "# DNS servers" >> ${file}
126 local server
127 for server in ${dns_servers}; do
128 print "ms-dns ${server}"
129 done >> ${file}
130 print >> ${file}
131 fi
132
133 # Default asyncmap
134 if enabled default_asyncmap; then
135 (
136 print "# Default asyncmap"
137 print "default-asyncmap"
138 print
139 ) >> ${file}
140 fi
141
142 # LCP settings.
143 (
144 print "# LCP settings"
145 print "lcp-echo-failure ${lcp_echo_failure}"
146 print "lcp-echo-interval ${lcp_echo_interval}"
147 print
148 ) >> ${file}
149
150 # Proxy ARP
151 (
152 print "# Proxy ARP"
153 if enabled proxyarp; then
154 print "proxyarp"
155 else
156 print "noproxyarp"
157 fi
158 print
159 ) >> ${file}
160
161 # Default options, we always set.
162 (
163 print "debug"
164 print "nodefaultroute"
165 print "noipdefault"
166 print "noipx"
167 ) >> ${file}
168
169 return ${EXIT_OK}
170}
171
1c6a4e30 172pppoe_server_poolfile() {
999d659b
MT
173 local file=${1}
174 assert isset file
175
176 local subnet=${2}
177 assert isset subnet
178
179 config_header "PPPoE server IP address pool file" > ${file}
180
181 # The network address will be the gateway address.
182 local netaddr=$(ipv4_get_network ${subnet})
183
184 local addr
185 for addr in $(ipv4_range_explicit ${subnet}); do
186 [ "${addr}" = "${netaddr}" ] && continue
187 print "${addr}"
188 done >> ${file}
189
190 return ${EXIT_OK}
191}