]> git.ipfire.org Git - people/stevee/network.git/blame - src/hooks/ports/dummy
network fix parameter passing when using ""
[people/stevee/network.git] / src / hooks / ports / dummy
CommitLineData
bd86d39f
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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. /usr/lib/network/header-port
23
24HOOK_SETTINGS="HOOK ADDRESS"
25
1c6a4e30 26hook_check_settings() {
bd86d39f
MT
27 assert ismac ADDRESS
28}
29
cd6d94b5 30hook_parse_cmdline() {
bd86d39f
MT
31 while [ $# -gt 0 ]; do
32 case "${1}" in
33 --address=*)
2212045f 34 ADDRESS=$(cli_get_val "${1}")
bd86d39f
MT
35 ;;
36 *)
37 warning "Unknown argument '${1}'"
38 ;;
39 esac
40 shift
41 done
42
cd6d94b5
MT
43 if isset ADDRESS; then
44 if ! ismac ADDRESS; then
45 error "Invalid MAC address given: ${ADDRESS}"
46 return ${EXIT_ERROR}
47 fi
48
49 # Generate a random but static MAC address if none was set
50 else
bd86d39f
MT
51 ADDRESS=$(mac_generate)
52 fi
cd6d94b5
MT
53}
54
55hook_new() {
2212045f 56 if ! hook_parse_cmdline "$@"; then
cd6d94b5
MT
57 return ${EXIT_ERROR}
58 fi
bd86d39f
MT
59
60 local port=$(port_find_free ${DUMMY_PORT_PATTERN})
61 assert isset port
62
e9df08ad 63 if port_settings_write "${port}" ${HOOK_SETTINGS}; then
bd86d39f
MT
64 log INFO "New dummy port '${port}' has been created"
65 fi
66
67 exit ${EXIT_OK}
68}
69
1c6a4e30 70hook_create() {
1ba6a2bb 71 local port="${1}"
bd86d39f
MT
72 assert isset port
73
1ba6a2bb 74 # Read configuration
e9df08ad 75 port_settings_read "${port}" ${HOOK_SETTINGS}
bd86d39f 76
1ba6a2bb
MT
77 # Create the dummy device
78 dummy_create "${port}" "${ADDRESS}"
79
80 exit ${EXIT_OK}
81}
82
1c6a4e30 83hook_remove() {
1ba6a2bb
MT
84 local port="${1}"
85 assert isset port
86
87 # Remove the dummy device
88 dummy_remove "${port}"
89}
90
1c6a4e30 91hook_up() {
1ba6a2bb
MT
92 local port="${1}"
93 assert isset port
bd86d39f 94
8ed44a23
MT
95 # Bring up the port.
96 device_set_up ${port}
97
bd86d39f
MT
98 exit ${EXIT_OK}
99}
100
1c6a4e30 101hook_down() {
1ba6a2bb 102 local port="${1}"
bd86d39f
MT
103 assert isset port
104
8ed44a23
MT
105 # Tear down the port.
106 device_set_down ${port}
107
bd86d39f
MT
108 exit ${EXIT_OK}
109}
110
1c6a4e30 111hook_hotplug_rename() {
bd86d39f
MT
112 local port=${1}
113 assert isset port
114
115 local device=${2}
116 assert isset device
117
e9df08ad 118 port_settings_read "${port}" ${HOOK_SETTINGS}
bd86d39f
MT
119
120 if [ "${ADDRESS}" = "$(device_get_address ${device})" ]; then
121 log DEBUG "Device '${device}' equals port '${port}'."
122 exit ${EXIT_OK}
123 fi
124
125 log DEBUG "Device '${device}' does not equal port '${port}'."
126 exit ${EXIT_ERROR}
127}