]>
Commit | Line | Data |
---|---|---|
e9ea243e MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2012 IPFire Network Development Team # | |
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 | dhclient_start() { | |
23 | local interface=${1} | |
24 | local proto=${2} | |
25 | ||
26 | assert isset interface | |
27 | assert device_exists ${interface} | |
28 | ||
1d08b9b3 MT |
29 | local service=$(dhclient_proto2service ${proto} ${interface}) |
30 | service_start ${service} | |
e9ea243e MT |
31 | } |
32 | ||
33 | dhclient_stop() { | |
34 | local interface=${1} | |
35 | local proto=${2} | |
36 | ||
1d08b9b3 MT |
37 | local service=$(dhclient_proto2service ${proto} ${interface}) |
38 | service_stop ${service} | |
e9ea243e MT |
39 | } |
40 | ||
8e3508ac MT |
41 | dhclient_status() { |
42 | local interface=${1} | |
43 | local proto=${2} | |
44 | ||
1d08b9b3 MT |
45 | local service=$(dhclient_proto2service ${proto} ${interface}) |
46 | service_status ${service} | |
8e3508ac MT |
47 | } |
48 | ||
e9ea243e MT |
49 | dhclient_proto2service() { |
50 | local proto=${1} | |
51 | assert isset proto | |
52 | ||
1d08b9b3 MT |
53 | local interface=${2} |
54 | assert isset interface | |
55 | ||
e9ea243e MT |
56 | local service |
57 | ||
58 | case "${proto}" in | |
59 | ipv4) | |
1d08b9b3 | 60 | service="dhclient4@${interface}.service" |
e9ea243e MT |
61 | ;; |
62 | ipv6) | |
1d08b9b3 | 63 | service="dhclient6@${interface}.service" |
e9ea243e MT |
64 | ;; |
65 | *) | |
66 | return ${EXIT_ERROR} | |
67 | ;; | |
68 | esac | |
69 | ||
70 | assert isset service | |
71 | ||
72 | echo "${service}" | |
73 | return ${EXIT_OK} | |
74 | } | |
75 | ||
76 | dhclient_write_config() { | |
77 | local interface=${1} | |
78 | local file=${2} | |
79 | shift 2 | |
80 | ||
81 | assert isset interface | |
82 | assert isset file | |
83 | ||
84 | local hostname=${HOSTNAME%%.*} | |
08e40c8c | 85 | local prefix_delegation="false" |
e9ea243e MT |
86 | local vendor=$(distro_get_pretty_name) |
87 | ||
88 | while [ $# -gt 0 ]; do | |
89 | case "${1}" in | |
90 | --hostname=*) | |
91 | hostname=$(cli_get_val ${1}) | |
92 | ;; | |
08e40c8c MT |
93 | --prefix-delegation=*) |
94 | prefix_delegation="$(cli_get_bool "${1}")" | |
95 | ;; | |
e9ea243e MT |
96 | --vendor=*) |
97 | vendor=$(cli_get_val ${1}) | |
98 | ;; | |
99 | *) | |
100 | log WARNING $"Unknown configuration option passed: ${1}." | |
101 | ;; | |
102 | esac | |
103 | shift | |
104 | done | |
105 | ||
106 | # Clear configuration file (if any). | |
107 | mkdir -p $(dirname ${file}) 2>/dev/null | |
108 | : > ${file} | |
109 | ||
110 | # Print the header. | |
111 | ( echo "#" | |
112 | echo "# This is a dhclient daemon configuration file for ${interface}." | |
113 | echo "# THIS FILE IS AUTOMATICALLY GENERATED AND WILL OVERWRITE" | |
114 | echo "# ANY CUSTOM CHANGES!" | |
115 | echo "#" | |
116 | echo "# $(date -u)" | |
117 | echo "#" | |
118 | echo | |
119 | ) >>${file} | |
120 | ||
121 | # Global options. | |
122 | echo "send vendor-class-identifier \"${vendor}\";" >>${file} | |
123 | echo | |
124 | ||
125 | # Interface options. | |
126 | ( | |
127 | echo "interface \"${interface}\" {" | |
128 | ||
129 | if isset hostname; then | |
130 | echo " send host-name \"${hostname}\";" | |
08e40c8c MT |
131 | |
132 | fi | |
133 | ||
134 | # Prefix delegation (IPv6). | |
135 | if enabled prefix_delegation; then | |
136 | print " # Prefix delegation" | |
137 | print " also request dhcp6.ia-pd 1;" | |
138 | print " send dhcp6.ia-na 1;" | |
139 | ||
e9ea243e MT |
140 | fi |
141 | ||
142 | echo "}" | |
143 | ) >>${file} | |
144 | ||
145 | return ${EXIT_OK} | |
146 | } |