]> git.ipfire.org Git - people/stevee/network.git/blob - src/functions/functions.dhclient
hostapd: Enable WMM by default.
[people/stevee/network.git] / src / functions / functions.dhclient
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
29 local service=$(dhclient_proto2service ${proto} ${interface})
30 service_start ${service}
31 }
32
33 dhclient_stop() {
34 local interface=${1}
35 local proto=${2}
36
37 local service=$(dhclient_proto2service ${proto} ${interface})
38 service_stop ${service}
39 }
40
41 dhclient_status() {
42 local interface=${1}
43 local proto=${2}
44
45 local service=$(dhclient_proto2service ${proto} ${interface})
46 service_status ${service}
47 }
48
49 dhclient_proto2service() {
50 local proto=${1}
51 assert isset proto
52
53 local interface=${2}
54 assert isset interface
55
56 local service
57
58 case "${proto}" in
59 ipv4)
60 service="dhclient4@${interface}.service"
61 ;;
62 ipv6)
63 service="dhclient6@${interface}.service"
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%%.*}
85 local prefix_delegation="false"
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 ;;
93 --prefix-delegation=*)
94 prefix_delegation="$(cli_get_bool "${1}")"
95 ;;
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}\";"
131 print
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 print
140 fi
141
142 echo "}"
143 ) >>${file}
144
145 return ${EXIT_OK}
146 }