]> git.ipfire.org Git - people/ms/network.git/blame - src/hooks/configs/dhcp
Makefile: Fix typo in localstatedir
[people/ms/network.git] / src / hooks / configs / dhcp
CommitLineData
e9ea243e
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
f41fa3d7 22. /usr/lib/network/header-config
e9ea243e 23
636f1b96 24HOOK_SETTINGS=(
8ece5c30
MT
25 "IPV6"
26 "IPV4"
636f1b96 27)
e9ea243e 28
8ece5c30
MT
29DEFAULT_IPV6="on"
30DEFAULT_IPV4="on"
e9ea243e 31
b6d9bf2b 32hook_check_config_settings() {
8ece5c30
MT
33 assert isbool IPV6
34 assert isbool IPV4
e9ea243e
MT
35}
36
9353a4e4 37hook_parse_cmdline() {
320f1fda
JS
38 local id="${1}"
39 shift
40
e9ea243e
MT
41 while [ $# -gt 0 ]; do
42 case "${1}" in
e80eb686 43 --ipv6=*)
8ece5c30 44 IPV6="$(cli_get_bool "${1}")"
9353a4e4 45 ;;
e80eb686 46 --ipv4=*)
8ece5c30 47 IPV4="$(cli_get_bool "${1}")"
9353a4e4
JS
48 ;;
49 *)
50 warning "Ignoring unknown option '${1}'"
51 ;;
e9ea243e
MT
52 esac
53 shift
54 done
e36f775d
JS
55
56 # Check if the user disabled ipv6 and ipv4
8ece5c30
MT
57 if ! enabled IPV6 && ! enabled IPV4; then
58 error "You disabled IPv6 and IPv4. At least one must be enabled"
e36f775d
JS
59 return ${EXIT_ERROR}
60 fi
9353a4e4
JS
61}
62
1c6a4e30 63hook_up() {
e9ea243e
MT
64 local zone=${1}
65 local config=${2}
66 shift 2
67
68 if ! device_exists ${zone}; then
69 error "Zone '${zone}' doesn't exist."
70 exit ${EXIT_ERROR}
71 fi
72
9353a4e4
JS
73 zone_config_settings_read "${zone}" "${config}"
74
75 # Start dhclient for IPv6 on this zone if enabled.
8ece5c30 76 if enabled IPV6; then
9353a4e4
JS
77 dhclient_start ${zone} ipv6
78 fi
79
80 # Start dhclient for IPv4 on this zone if enabled.
8ece5c30 81 if enabled IPV4; then
9353a4e4
JS
82 dhclient_start ${zone} ipv4
83 fi
e9ea243e
MT
84
85 exit ${EXIT_OK}
86}
87
1c6a4e30 88hook_down() {
e9ea243e
MT
89 local zone=${1}
90 local config=${2}
91 shift 2
92
93 if ! device_exists ${zone}; then
94 error "Zone '${zone}' doesn't exist."
95 exit ${EXIT_ERROR}
96 fi
97
9353a4e4
JS
98 # Stop dhclient for IPv6 on this zone.
99 dhclient_stop ${zone} ipv6
100
e9ea243e
MT
101 # Stop dhclient for IPv4 on this zone.
102 dhclient_stop ${zone} ipv4
103
104 exit ${EXIT_OK}
105}
106
1c6a4e30 107hook_status() {
e9ea243e
MT
108 local zone=${1}
109 local config=${2}
110 shift 2
111
112 if ! device_exists ${zone}; then
113 error "Zone '${zone}' doesn't exist."
114 exit ${EXIT_ERROR}
115 fi
e9df08ad 116
b6d9bf2b 117 zone_config_settings_read "${zone}" "${config}"
e9ea243e 118
8e3508ac 119 local status
9353a4e4 120 if dhclient_status ${zone} ipv4 || dhclient_status ${zone} ipv6; then
8e3508ac 121 status="${MSG_HOOK_UP}"
e9ea243e 122 else
8e3508ac 123 status="${MSG_HOOK_DOWN}"
e9ea243e 124 fi
8e3508ac 125 cli_statusline 3 "${HOOK}" "${status}"
e9ea243e 126
9353a4e4
JS
127 cli_space
128
129 local proto
130 for proto in "IPv6" "IPv4"; do
131 local _proto=${proto,,}
132
133 cli_print_fmt1 3 "${proto}"
134
8ece5c30 135 if enabled "${proto^^}"; then
9353a4e4
JS
136 cli_print_fmt1 4 "Status" "enabled"
137
138 local address="$(db_get "${zone}/${_proto}/local-ip-address")"
139 if isset address; then
140 cli_print_fmt1 4 "Address" "${address}"
141 fi
142
143 local gateway="$(db_get "${zone}/${_proto}/remote-ip-address")"
144 if isset gateway; then
145 cli_print_fmt1 4 "Gateway" "${gateway}"
146 fi
147
148 local dns_servers="$(db_get "${zone}/${_proto}/domain-name-servers")"
149 if isset dns_servers; then
150 cli_print_fmt1 4 "DNS Servers" "${dns_servers}"
151 fi
152 else
153 cli_print_fmt1 4 "Status" "disabled"
154 fi
155
ffea9f57 156 cli_space
9353a4e4
JS
157
158 done
e9ea243e
MT
159
160 exit ${EXIT_OK}
161}