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