]>
Commit | Line | Data |
---|---|---|
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 |
22 | pppoe_server_init() { |
23 | # Load the pppoe kernel module | |
24 | module_load "pppoe" | |
25 | } | |
26 | ||
1c6a4e30 | 27 | pppoe_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 | 37 | pppoe_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 | 44 | pppoe_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 | 51 | pppoe_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 | |
8efbf77e | 63 | local ipv6="true" |
999d659b MT |
64 | local lcp_echo_failure=5 |
65 | local lcp_echo_interval=60 | |
66 | local proxyarp="true" | |
67 | local required_auths | |
68 | local value | |
69 | ||
70 | while [ $# -gt 0 ]; do | |
71 | case "${1}" in | |
72 | --auth=*) | |
2212045f | 73 | auth=$(cli_get_val "${1}") |
999d659b MT |
74 | ;; |
75 | --default-asyncmap=*) | |
2212045f | 76 | default_asyncmap=$(cli_get_val "${1}") |
999d659b | 77 | ;; |
8efbf77e SS |
78 | --disable-ipv6) |
79 | ipv6="false" | |
80 | ;; | |
70c971ce | 81 | --dns-servers=*) |
2212045f | 82 | dns_servers="$(cli_get_val "${1}")" |
999d659b MT |
83 | ;; |
84 | --lcp-echo-failure=*) | |
2212045f | 85 | lcp_echo_failure=$(cli_get_val "${1}") |
999d659b MT |
86 | assert isinteger ${lcp_echo_failure} |
87 | ;; | |
88 | --lcp-echo-interval=*) | |
2212045f | 89 | lcp_echo_interval=$(cli_get_val "${1}") |
999d659b MT |
90 | assert isinteger ${lcp_echo_interval} |
91 | ;; | |
92 | --proxyarp=*) | |
2212045f | 93 | proxyarp=$(cli_get_val "${1}") |
999d659b MT |
94 | ;; |
95 | --require-auth=*) | |
2212045f | 96 | required_auths="${required_auths} $(cli_get_val "${1}")" |
999d659b MT |
97 | ;; |
98 | esac | |
99 | shift | |
100 | done | |
101 | ||
102 | mkdir -p $(dirname ${file}) 2>/dev/null | |
103 | config_header "pppoe-server options configuration file" > ${file} | |
104 | ||
105 | # Authentication | |
106 | ( | |
107 | print "# Authentication" | |
108 | if enabled auth; then | |
109 | print "auth" | |
110 | else | |
111 | print "noauth" | |
112 | fi | |
113 | ||
114 | ) >> ${file} | |
115 | ||
116 | # If there are only a number of auth algorithms allowed, we | |
117 | # define them here. | |
118 | if isset required_auths; then | |
119 | print "# Required authentication methods" >> ${file} | |
120 | local method | |
121 | for method in ${required_auths}; do | |
122 | print "require-${method}" | |
123 | done >> ${file} | |
124 | print >> ${file} | |
125 | fi | |
126 | ||
8efbf77e SS |
127 | # IPv6 |
128 | if enabled ipv6; then | |
129 | # Generate a random gateway address | |
130 | local gw_addr="::$(random 4):$(random 4)" | |
131 | ( | |
132 | print "# IPv6" | |
133 | print "ipv6 ${gw_addr}" | |
134 | ||
135 | ) >> ${file} | |
136 | fi | |
137 | ||
999d659b MT |
138 | # DNS servers |
139 | if isset dns_servers; then | |
140 | print "# DNS servers" >> ${file} | |
141 | local server | |
142 | for server in ${dns_servers}; do | |
143 | print "ms-dns ${server}" | |
144 | done >> ${file} | |
145 | print >> ${file} | |
146 | fi | |
147 | ||
148 | # Default asyncmap | |
149 | if enabled default_asyncmap; then | |
150 | ( | |
151 | print "# Default asyncmap" | |
152 | print "default-asyncmap" | |
153 | ||
154 | ) >> ${file} | |
155 | fi | |
156 | ||
157 | # LCP settings. | |
158 | ( | |
159 | print "# LCP settings" | |
160 | print "lcp-echo-failure ${lcp_echo_failure}" | |
161 | print "lcp-echo-interval ${lcp_echo_interval}" | |
162 | ||
163 | ) >> ${file} | |
164 | ||
165 | # Proxy ARP | |
166 | ( | |
167 | print "# Proxy ARP" | |
168 | if enabled proxyarp; then | |
169 | print "proxyarp" | |
170 | else | |
171 | print "noproxyarp" | |
172 | fi | |
173 | ||
174 | ) >> ${file} | |
175 | ||
176 | # Default options, we always set. | |
177 | ( | |
178 | print "debug" | |
179 | print "nodefaultroute" | |
180 | print "noipdefault" | |
181 | print "noipx" | |
182 | ) >> ${file} | |
183 | ||
184 | return ${EXIT_OK} | |
185 | } | |
186 | ||
1c6a4e30 | 187 | pppoe_server_poolfile() { |
999d659b MT |
188 | local file=${1} |
189 | assert isset file | |
190 | ||
191 | local subnet=${2} | |
192 | assert isset subnet | |
193 | ||
194 | config_header "PPPoE server IP address pool file" > ${file} | |
195 | ||
196 | # The network address will be the gateway address. | |
197 | local netaddr=$(ipv4_get_network ${subnet}) | |
198 | ||
199 | local addr | |
200 | for addr in $(ipv4_range_explicit ${subnet}); do | |
201 | [ "${addr}" = "${netaddr}" ] && continue | |
202 | print "${addr}" | |
203 | done >> ${file} | |
204 | ||
205 | return ${EXIT_OK} | |
206 | } |