Project:
IPFire
Code Location:
git://git.ipfire.org/network.gitmaster
/
functions.dhclient
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2012 IPFire Network Development Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <http://www.gnu.org/licenses/>. # # # ############################################################################### dhclient_start() { local interface=${1} local proto=${2} assert isset interface assert device_exists ${interface} local service=$(dhclient_proto2service ${proto} ${interface}) service_start ${service} } dhclient_stop() { local interface=${1} local proto=${2} local service=$(dhclient_proto2service ${proto} ${interface}) service_stop ${service} } dhclient_status() { local interface=${1} local proto=${2} local service=$(dhclient_proto2service ${proto} ${interface}) service_status ${service} } dhclient_proto2service() { local proto=${1} assert isset proto local interface=${2} assert isset interface local service case "${proto}" in ipv4) service="dhclient4@${interface}.service" ;; ipv6) service="dhclient6@${interface}.service" ;; *) return ${EXIT_ERROR} ;; esac assert isset service echo "${service}" return ${EXIT_OK} } dhclient_write_config() { local interface=${1} local file=${2} shift 2 assert isset interface assert isset file local hostname=${HOSTNAME%%.*} local prefix_delegation="false" local vendor=$(distro_get_pretty_name) while [ $# -gt 0 ]; do case "${1}" in --hostname=*) hostname=$(cli_get_val ${1}) ;; --prefix-delegation=*) prefix_delegation="$(cli_get_bool "${1}")" ;; --vendor=*) vendor=$(cli_get_val ${1}) ;; *) log WARNING $"Unknown configuration option passed: ${1}." ;; esac shift done # Clear configuration file (if any). mkdir -p $(dirname ${file}) 2>/dev/null : > ${file} # Print the header. ( echo "#" echo "# This is a dhclient daemon configuration file for ${interface}." echo "# THIS FILE IS AUTOMATICALLY GENERATED AND WILL OVERWRITE" echo "# ANY CUSTOM CHANGES!" echo "#" echo "# $(date -u)" echo "#" echo ) >>${file} # Global options. echo "send vendor-class-identifier \"${vendor}\";" >>${file} echo # Interface options. ( echo "interface \"${interface}\" {" if isset hostname; then echo " send host-name \"${hostname}\";" print fi # Prefix delegation (IPv6). if enabled prefix_delegation; then print " # Prefix delegation" print " also request dhcp6.ia-pd 1;" print " send dhcp6.ia-na 1;" print fi echo "}" ) >>${file} return ${EXIT_OK} }
