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