]> git.ipfire.org Git - people/stevee/network.git/blob - functions.dhclient
firewall: Re-unity firewall6/4 configuration again.
[people/stevee/network.git] / 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 vendor=$(distro_get_pretty_name)
86
87 while [ $# -gt 0 ]; do
88 case "${1}" in
89 --hostname=*)
90 hostname=$(cli_get_val ${1})
91 ;;
92 --vendor=*)
93 vendor=$(cli_get_val ${1})
94 ;;
95 *)
96 log WARNING $"Unknown configuration option passed: ${1}."
97 ;;
98 esac
99 shift
100 done
101
102 # Clear configuration file (if any).
103 mkdir -p $(dirname ${file}) 2>/dev/null
104 : > ${file}
105
106 # Print the header.
107 ( echo "#"
108 echo "# This is a dhclient daemon configuration file for ${interface}."
109 echo "# THIS FILE IS AUTOMATICALLY GENERATED AND WILL OVERWRITE"
110 echo "# ANY CUSTOM CHANGES!"
111 echo "#"
112 echo "# $(date -u)"
113 echo "#"
114 echo
115 ) >>${file}
116
117 # Global options.
118 echo "send vendor-class-identifier \"${vendor}\";" >>${file}
119 echo
120
121 # Interface options.
122 (
123 echo "interface \"${interface}\" {"
124
125 if isset hostname; then
126 echo " send host-name \"${hostname}\";"
127 fi
128
129 echo "}"
130 ) >>${file}
131
132 return ${EXIT_OK}
133 }