Commit 03afcdce authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

Uniform adding and deleting of interfaces

The main benefit is the possibility to use interface hooks for links
that are created at runtime.
parent bcca0a02
......@@ -10,7 +10,7 @@ bond_up() {
report_error "Interface '$Interface' already exists"
return 1
else
ip link add name "$Interface" type bond
interface_add bond "$Interface"
fi
bring_interface_up "$Interface"
......@@ -28,8 +28,7 @@ bond_down() {
done
ip_unset
bring_interface_down "$Interface"
ip link delete "$Interface"
interface_delete "$Interface"
}
......
......@@ -11,7 +11,7 @@ bridge_up() {
return 1
fi
else
ip link add name "$Interface" type bridge
interface_add bridge "$Interface"
fi
for member in "${BindsToInterfaces[@]}"; do
......@@ -34,8 +34,7 @@ bridge_down() {
done
ip_unset
bring_interface_down "$Interface"
ip link delete "$Interface" type bridge
interface_delete "$Interface"
}
......
......@@ -10,16 +10,14 @@ dummy_up() {
return 1
fi
ip link add "$Interface" type dummy
interface_add dummy "$Interface"
bring_interface_up "$Interface"
ip_set
}
dummy_down() {
ip_unset
bring_interface_down "$Interface"
ip link del "$Interface"
interface_delete "$Interface"
}
......
......@@ -12,7 +12,7 @@ vlan_up() {
return 1
else
bring_interface_up "$BindsToInterfaces"
ip link add link "$BindsToInterfaces" name "$Interface" type vlan id "$VLANID"
interface_add vlan "$Interface" "$BindsToInterfaces" id "$VLANID"
fi
ethernet_up
......@@ -20,7 +20,7 @@ vlan_up() {
vlan_down() {
ethernet_down
ip link delete "$Interface"
interface_delete "$Interface"
}
......
......@@ -10,6 +10,27 @@ is_interface() {
[[ -d "/sys/class/net/${1%%:?*}" ]]
}
## Add an interface
# $1: interface type
# $2: interface name
# $3: interface link (optional)
# $4...: additional arguments
interface_add() {
local type="$1" name="$2" link="$3"
shift 3
ip link add ${link:+link "$link"} name "$name" type "$type" "$@"
if [[ -x "$PROFILE_DIR/interfaces/$name" ]]; then
source "$PROFILE_DIR/interfaces/$name"
fi
}
## Delete an interface
# $1: interface name
interface_delete() {
bring_interface_down "$1"
ip link delete "$1"
}
## Check if an interface is up
# $1: interface name
interface_is_up() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment