]>
Commit | Line | Data |
---|---|---|
999d659b MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # | |
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 | ||
22 | . /usr/lib/network/header-config | |
23 | ||
70c971ce | 24 | HOOK_CONFIG_SETTINGS="HOOK DNS_SERVERS MTU SERVICE_NAME SUBNET MAX_SESSIONS" |
999d659b MT |
25 | |
26 | # Maximum Transmission Unit. | |
27 | MTU=1492 | |
28 | ||
29 | # Service Name. | |
30 | SERVICE_NAME= | |
31 | ||
32 | # A subnet. Addresses from this subnet will be given to the remote hosts. | |
33 | # The net address will be the gateway address for the PPPoE server. | |
34 | SUBNET= | |
35 | ||
f94b87ab MT |
36 | # Defines the max. number of sessions per MAC address. |
37 | # 0 = unlimited. | |
38 | MAX_SESSIONS=0 | |
39 | ||
b6d9bf2b | 40 | hook_check_config_settings() { |
999d659b MT |
41 | assert isset MTU |
42 | assert isset SUBNET | |
f94b87ab | 43 | assert isset MAX_SESSIONS |
70c971ce SS |
44 | |
45 | local server | |
46 | for server in ${DNS_SERVERS}; do | |
47 | assert ipv4_is_valid "${server}" | |
48 | done | |
999d659b MT |
49 | } |
50 | ||
88b80413 | 51 | hook_parse_cmdline() { |
999d659b MT |
52 | while [ $# -gt 0 ]; do |
53 | case "${1}" in | |
70c971ce SS |
54 | --dns-server=*) |
55 | local dns_servers="$(cli_get_val "${1}")" | |
56 | ||
57 | local dns_server | |
58 | for dns_server in ${dns_servers}; do | |
59 | if ! ipv4_is_valid "${dns_server}"; then | |
60 | warning "Invalid IPv4 address: ${dns_server}. Skipped." | |
61 | continue | |
62 | fi | |
63 | ||
64 | list_append DNS_SERVERS "${dns_server}" | |
65 | done | |
66 | ;; | |
f94b87ab | 67 | --max-sessions=*) |
2212045f | 68 | MAX_SESSIONS=$(cli_get_val "${1}") |
370adaac JS |
69 | if ! isinteger ${MAX_SESSIONS} || ! [ ${MAX_SESSIONS} -ge 0 ]; then |
70 | error "Invalid value for '--max-session'. This value must be an integer greate or eqal zero." | |
71 | exit ${EXIT_ERROR} | |
72 | fi | |
f94b87ab | 73 | ;; |
999d659b | 74 | --mtu=*) |
2212045f | 75 | MTU=$(cli_get_val "${1}") |
370adaac JS |
76 | if ! mtu_is_valid "ipv4" ${MTU}; then |
77 | error "Invalid value for '--mtu'. Cannot be larger then 9000 or smaller than 576" | |
78 | exit ${EXIT_ERROR} | |
79 | fi | |
999d659b MT |
80 | ;; |
81 | --service-name=*) | |
2212045f | 82 | SERVICE_NAME=$(cli_get_val "${1}") |
999d659b MT |
83 | ;; |
84 | --subnet=*) | |
2212045f | 85 | SUBNET=$(cli_get_val "${1}") |
370adaac JS |
86 | if ! ipv4_net_is_valid "${SUBNET}"; then |
87 | error "Invalid IPv4 Subnet ${SUBNET}." | |
88 | exit ${EXIT_ERROR} | |
89 | fi | |
90 | ;; | |
91 | *) | |
92 | warning "Ignoring unknown option '${1}'" | |
999d659b MT |
93 | ;; |
94 | esac | |
95 | shift | |
96 | done | |
88b80413 JS |
97 | } |
98 | ||
99 | hook_new() { | |
100 | local zone=${1} | |
101 | shift | |
102 | ||
103 | if zone_config_hook_is_configured ${zone} "pppoe-server"; then | |
104 | log ERROR "You can configure the pppoe-server hook only once for a zone" | |
105 | return ${EXIT_ERROR} | |
106 | fi | |
107 | ||
2212045f | 108 | if ! hook_parse_cmdline "$@"; then |
88b80413 JS |
109 | # Return an error if the parsing of the cmd line fails |
110 | return ${EXIT_ERROR} | |
111 | fi | |
999d659b | 112 | |
b6d9bf2b | 113 | zone_config_settings_write "${zone}" "${HOOK}" |
999d659b MT |
114 | |
115 | exit ${EXIT_OK} | |
116 | } | |
117 | ||
1c6a4e30 | 118 | hook_up() { |
999d659b MT |
119 | local zone=${1} |
120 | local config=${2} | |
121 | shift 2 | |
122 | ||
123 | # Start the PPPoE server. | |
124 | pppoe_server_start ${zone} | |
125 | ||
126 | exit ${EXIT_OK} | |
127 | } | |
128 | ||
1c6a4e30 | 129 | hook_down() { |
999d659b MT |
130 | local zone=${1} |
131 | local config=${2} | |
132 | shift 2 | |
133 | ||
134 | if ! device_exists ${zone}; then | |
135 | error "Zone '${zone}' doesn't exist." | |
136 | exit ${EXIT_ERROR} | |
137 | fi | |
138 | ||
139 | # Stop the PPPoE server. | |
140 | pppoe_server_stop ${zone} | |
141 | ||
142 | exit ${EXIT_OK} | |
143 | } | |
144 | ||
1c6a4e30 | 145 | hook_status() { |
999d659b MT |
146 | local zone=${1} |
147 | local config=${2} | |
148 | shift 2 | |
149 | ||
150 | if ! device_exists ${zone}; then | |
151 | error "Zone '${zone}' doesn't exist." | |
152 | exit ${EXIT_ERROR} | |
153 | fi | |
e9df08ad | 154 | |
b6d9bf2b | 155 | zone_config_settings_read "${zone}" "${config}" |
999d659b MT |
156 | |
157 | local status | |
158 | if pppoe_server_status ${zone}; then | |
159 | status="${MSG_HOOK_UP}" | |
160 | else | |
161 | status="${MSG_HOOK_DOWN}" | |
162 | fi | |
163 | cli_statusline 3 "PPPoE server" "${status}" | |
164 | ||
9689be27 MT |
165 | local gateway=$(ipv4_get_network ${SUBNET}) |
166 | cli_print_fmt1 3 "Gateway" "${gateway}" | |
167 | ||
168 | local start_address=$(ipv4_encode ${gateway}) | |
169 | start_address=$(( ${start_address} + 1 )) | |
170 | start_address=$(ipv4_decode ${start_address}) | |
171 | local end_address=$(ipv4_get_broadcast ${SUBNET}) | |
172 | ||
173 | cli_print_fmt1 3 "Client range" \ | |
174 | "${start_address}-${end_address}" | |
175 | cli_space | |
176 | ||
f94b87ab MT |
177 | local max_sessions=${MAX_SESSIONS} |
178 | if [ "${max_sessions}" = "0" ]; then | |
179 | max_sessions="unlimited" | |
180 | fi | |
181 | cli_print_fmt1 3 "${max_sessions} session(s) per MAC" | |
182 | cli_space | |
183 | ||
999d659b MT |
184 | exit ${EXIT_OK} |
185 | } |