]>
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 | ||
f94b87ab | 24 | HOOK_SETTINGS="HOOK 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 | ||
1c6a4e30 | 40 | hook_check() { |
999d659b MT |
41 | assert isset MTU |
42 | assert isset SUBNET | |
f94b87ab | 43 | assert isset MAX_SESSIONS |
999d659b MT |
44 | } |
45 | ||
1c6a4e30 | 46 | hook_create() { |
999d659b MT |
47 | local zone=${1} |
48 | shift | |
49 | ||
50 | while [ $# -gt 0 ]; do | |
51 | case "${1}" in | |
f94b87ab MT |
52 | --max-sessions=*) |
53 | MAX_SESSIONS=$(cli_get_val ${1}) | |
54 | ;; | |
999d659b MT |
55 | --mtu=*) |
56 | MTU=$(cli_get_val ${1}) | |
57 | ;; | |
58 | --service-name=*) | |
59 | SERVICE_NAME=$(cli_get_val ${1}) | |
60 | ;; | |
61 | --subnet=*) | |
62 | SUBNET=$(cli_get_val ${1}) | |
63 | ;; | |
64 | esac | |
65 | shift | |
66 | done | |
67 | ||
e9df08ad | 68 | zone_config_settings_write "${zone}" "${HOOK}" ${HOOK_SETTINGS} |
999d659b MT |
69 | |
70 | exit ${EXIT_OK} | |
71 | } | |
72 | ||
1c6a4e30 | 73 | hook_up() { |
999d659b MT |
74 | local zone=${1} |
75 | local config=${2} | |
76 | shift 2 | |
77 | ||
78 | # Start the PPPoE server. | |
79 | pppoe_server_start ${zone} | |
80 | ||
81 | exit ${EXIT_OK} | |
82 | } | |
83 | ||
1c6a4e30 | 84 | hook_down() { |
999d659b MT |
85 | local zone=${1} |
86 | local config=${2} | |
87 | shift 2 | |
88 | ||
89 | if ! device_exists ${zone}; then | |
90 | error "Zone '${zone}' doesn't exist." | |
91 | exit ${EXIT_ERROR} | |
92 | fi | |
93 | ||
94 | # Stop the PPPoE server. | |
95 | pppoe_server_stop ${zone} | |
96 | ||
97 | exit ${EXIT_OK} | |
98 | } | |
99 | ||
1c6a4e30 | 100 | hook_status() { |
999d659b MT |
101 | local zone=${1} |
102 | local config=${2} | |
103 | shift 2 | |
104 | ||
105 | if ! device_exists ${zone}; then | |
106 | error "Zone '${zone}' doesn't exist." | |
107 | exit ${EXIT_ERROR} | |
108 | fi | |
e9df08ad MT |
109 | |
110 | zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS} | |
999d659b MT |
111 | |
112 | local status | |
113 | if pppoe_server_status ${zone}; then | |
114 | status="${MSG_HOOK_UP}" | |
115 | else | |
116 | status="${MSG_HOOK_DOWN}" | |
117 | fi | |
118 | cli_statusline 3 "PPPoE server" "${status}" | |
119 | ||
9689be27 MT |
120 | local gateway=$(ipv4_get_network ${SUBNET}) |
121 | cli_print_fmt1 3 "Gateway" "${gateway}" | |
122 | ||
123 | local start_address=$(ipv4_encode ${gateway}) | |
124 | start_address=$(( ${start_address} + 1 )) | |
125 | start_address=$(ipv4_decode ${start_address}) | |
126 | local end_address=$(ipv4_get_broadcast ${SUBNET}) | |
127 | ||
128 | cli_print_fmt1 3 "Client range" \ | |
129 | "${start_address}-${end_address}" | |
130 | cli_space | |
131 | ||
f94b87ab MT |
132 | local max_sessions=${MAX_SESSIONS} |
133 | if [ "${max_sessions}" = "0" ]; then | |
134 | max_sessions="unlimited" | |
135 | fi | |
136 | cli_print_fmt1 3 "${max_sessions} session(s) per MAC" | |
137 | cli_space | |
138 | ||
999d659b MT |
139 | exit ${EXIT_OK} |
140 | } |