]>
git.ipfire.org Git - people/arne_f/network.git/blob - hooks/zones/bridge.configs/ipv4-static
9ea7288d133dc246097cf0dd18136e358286f159
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
22 .
/lib
/network
/header-config
24 HOOK_SETTINGS
="HOOK ADDRESS PREFIX GATEWAY"
28 assert isinteger PREFIX
30 if [ ${PREFIX} -gt 30 ]; then
31 error
"PREFIX is greater than 30."
40 while [ $# -gt 0 ]; do
43 ADDRESS
=${1#--address=}
46 NETMASK
=${1#--netmask=}
52 GATEWAY
=${1#--gateway=}
58 if [ -z "${PREFIX}" -a -n "${NETMASK}" ]; then
59 PREFIX
=$
(ipv4_mask_to_cidr
${NETMASK})
62 # XXX maybe we can add some hashing to identify a configuration again
63 config_write $
(zone_dir
${zone})/configs/${HOOK}.$(uuid) ${HOOK_SETTINGS}
73 if ! device_exists
${zone}; then
74 error
"Zone '${zone}' doesn't exist."
78 config_read $
(zone_dir
${zone})/configs
/${config}
80 if ! zone_has_ipv4
${zone} ${ADDRESS}/${PREFIX}; then
81 ip addr add
${ADDRESS}/${PREFIX} dev ${zone}
83 warning
"Do not set IPv4 address '${ADDRESS}/${PREFIX}' because it was already configured on zone '${zone}'."
86 if zone_is_nonlocal
${zone} && [ -n "${GATEWAY}" ]; then
98 if ! device_exists
${zone}; then
99 error
"Zone '${zone}' doesn't exist."
103 config_read $
(zone_dir
${zone})/configs
/${config}
105 if zone_has_ipv4
${zone} ${ADDRESS}/${PREFIX}; then
106 ip addr del
${ADDRESS}/${PREFIX} dev ${zone}
117 if ! device_exists
${zone}; then
118 error
"Zone '${zone}' doesn't exist."
122 config_read $
(zone_dir
${zone})/configs
/${config}
124 printf " %10s - " "${HOOK}"
125 if zone_has_ipv4
${zone} ${ADDRESS}/${PREFIX}; then
126 echo -ne "${COLOUR_ENABLED}ENABLED ${COLOUR_NORMAL}"
128 echo -ne "${COLOUR_DISABLED}DISABLED${COLOUR_NORMAL}"
130 echo " - ${ADDRESS}/${PREFIX}"
132 if [ -n "${GATEWAY}" ]; then
133 echo " Gateway: ${GATEWAY}"
139 function ipv4_mask_to_cidr
() {
143 for field
in $
(tr '.' ' ' <<<${1}); do
144 mask
=$
(( $
(( ${mask} << 8 )) | ${field} ))
148 local x=$(( 128 << 24 )) # 0x80000000
150 while [ $(( ${x} & ${mask} )) -ne 0 ]; do
151 [ ${mask} -eq ${x} ] && mask=0 || mask=$(( ${mask} << 1 ))
152 cidr=$((${cidr} + 1))
155 if [ $(( ${mask} & 2147483647 )) -ne 0 ]; then # 2147483647 = 0x7fffffff
156 echo "Invalid net mask: $1" >&2