]> git.ipfire.org Git - network.git/blob - src/hooks/configs/ipv4-dhcp
39e03127920771ba9e582b884d0b24b8df2ca076
[network.git] / src / hooks / configs / ipv4-dhcp
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
24 HOOK_CONFIG_SETTINGS="HOOK DELAY"
25
26 # Default settings.
27 DELAY=0
28
29 hook_check_config_settings() {
30 assert isset DELAY
31 assert isinteger DELAY
32 }
33
34 hook_new() {
35 local zone="${1}"
36 shift
37
38 if zone_config_hook_is_configured ${zone} "ipv4-dhcp"; then
39 log ERROR "You can configure the ipv4-dhcp hook only once for a zone"
40 return ${EXIT_ERROR}
41 fi
42
43 while [ $# -gt 0 ]; do
44 case "${1}" in
45 --delay=*)
46 DELAY="$(cli_get_val "${1}")"
47 ;;
48 esac
49 shift
50 done
51
52 zone_config_settings_write "${zone}" "${HOOK}"
53
54 exit ${EXIT_OK}
55 }
56
57 hook_up() {
58 local zone=${1}
59 local config=${2}
60 shift 2
61
62 if ! device_exists ${zone}; then
63 error "Zone '${zone}' doesn't exist."
64 exit ${EXIT_ERROR}
65 fi
66
67 # Start dhclient for IPv4 on this zone.
68 dhclient_start ${zone} ipv4
69
70 exit ${EXIT_OK}
71 }
72
73 hook_down() {
74 local zone=${1}
75 local config=${2}
76 shift 2
77
78 if ! device_exists ${zone}; then
79 error "Zone '${zone}' doesn't exist."
80 exit ${EXIT_ERROR}
81 fi
82
83 # Stop dhclient for IPv4 on this zone.
84 dhclient_stop ${zone} ipv4
85
86 exit ${EXIT_OK}
87 }
88
89 hook_status() {
90 local zone=${1}
91 local config=${2}
92 shift 2
93
94 if ! device_exists ${zone}; then
95 error "Zone '${zone}' doesn't exist."
96 exit ${EXIT_ERROR}
97 fi
98
99 zone_config_settings_read "${zone}" "${config}"
100
101 local status
102 if dhclient_status ${zone} ipv4; then
103 status="${MSG_HOOK_UP}"
104 else
105 status="${MSG_HOOK_DOWN}"
106 fi
107 cli_statusline 3 "${HOOK}" "${status}"
108
109 cli_print_fmt1 3 "IPv4 address" "$(db_get "${zone}/ipv4/local-ip-address")"
110 local gateway="$(db_get "${zone}/ipv4/remote-ip-address")"
111 if isset gateway; then
112 cli_print_fmt1 3 "Gateway" "${gateway}"
113 cli_space
114 fi
115 local dns_servers="$(db_get "${zone}/ipv4/domain-name-servers")"
116 if isset dns_servers; then
117 cli_print_fmt1 3 "DNS-Servers" "${dns_servers}"
118 cli_space
119 fi
120
121 exit ${EXIT_OK}
122 }