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() { ...@@ -10,7 +10,7 @@ bond_up() {
report_error "Interface '$Interface' already exists" report_error "Interface '$Interface' already exists"
return 1 return 1
else else
ip link add name "$Interface" type bond interface_add bond "$Interface"
fi fi
bring_interface_up "$Interface" bring_interface_up "$Interface"
...@@ -28,8 +28,7 @@ bond_down() { ...@@ -28,8 +28,7 @@ bond_down() {
done done
ip_unset ip_unset
bring_interface_down "$Interface" interface_delete "$Interface"
ip link delete "$Interface"
} }
......
...@@ -11,7 +11,7 @@ bridge_up() { ...@@ -11,7 +11,7 @@ bridge_up() {
return 1 return 1
fi fi
else else
ip link add name "$Interface" type bridge interface_add bridge "$Interface"
fi fi
for member in "${BindsToInterfaces[@]}"; do for member in "${BindsToInterfaces[@]}"; do
...@@ -34,8 +34,7 @@ bridge_down() { ...@@ -34,8 +34,7 @@ bridge_down() {
done done
ip_unset ip_unset
bring_interface_down "$Interface" interface_delete "$Interface"
ip link delete "$Interface" type bridge
} }
......
...@@ -10,16 +10,14 @@ dummy_up() { ...@@ -10,16 +10,14 @@ dummy_up() {
return 1 return 1
fi fi
ip link add "$Interface" type dummy interface_add dummy "$Interface"
bring_interface_up "$Interface" bring_interface_up "$Interface"
ip_set ip_set
} }
dummy_down() { dummy_down() {
ip_unset ip_unset
bring_interface_down "$Interface" interface_delete "$Interface"
ip link del "$Interface"
} }
......
...@@ -12,7 +12,7 @@ vlan_up() { ...@@ -12,7 +12,7 @@ vlan_up() {
return 1 return 1
else else
bring_interface_up "$BindsToInterfaces" bring_interface_up "$BindsToInterfaces"
ip link add link "$BindsToInterfaces" name "$Interface" type vlan id "$VLANID" interface_add vlan "$Interface" "$BindsToInterfaces" id "$VLANID"
fi fi
ethernet_up ethernet_up
...@@ -20,7 +20,7 @@ vlan_up() { ...@@ -20,7 +20,7 @@ vlan_up() {
vlan_down() { vlan_down() {
ethernet_down ethernet_down
ip link delete "$Interface" interface_delete "$Interface"
} }
......
...@@ -10,6 +10,27 @@ is_interface() { ...@@ -10,6 +10,27 @@ is_interface() {
[[ -d "/sys/class/net/${1%%:?*}" ]] [[ -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 ## Check if an interface is up
# $1: interface name # $1: interface name
interface_is_up() { 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