diff options
author | Jouke Witteveen <j.witteveen@gmail.com> | 2014-02-27 13:43:22 +0100 |
---|---|---|
committer | Jouke Witteveen <j.witteveen@gmail.com> | 2014-02-27 13:48:49 +0100 |
commit | 03afcdce237b2dc52a6c1fea72b715cf6c34bf05 (patch) | |
tree | 90f98f8f08a748dea06f479d88fa91938015b645 /src/lib | |
parent | bcca0a027786c0d23f3f70c9f21b3332f41786e1 (diff) | |
download | netctl-03afcdce237b2dc52a6c1fea72b715cf6c34bf05.tar.gz netctl-03afcdce237b2dc52a6c1fea72b715cf6c34bf05.tar.xz |
Uniform adding and deleting of interfaces
The main benefit is the possibility to use interface hooks for links
that are created at runtime.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/connections/bond | 5 | ||||
-rw-r--r-- | src/lib/connections/bridge | 5 | ||||
-rw-r--r-- | src/lib/connections/dummy | 6 | ||||
-rw-r--r-- | src/lib/connections/vlan | 4 | ||||
-rwxr-xr-x | src/lib/network | 21 |
5 files changed, 29 insertions, 12 deletions
diff --git a/src/lib/connections/bond b/src/lib/connections/bond index c22fc82..9cc8b96 100644 --- a/src/lib/connections/bond +++ b/src/lib/connections/bond @@ -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" } diff --git a/src/lib/connections/bridge b/src/lib/connections/bridge index 94a4802..b358e01 100644 --- a/src/lib/connections/bridge +++ b/src/lib/connections/bridge @@ -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" } diff --git a/src/lib/connections/dummy b/src/lib/connections/dummy index 879fc92..5a12d1e 100644 --- a/src/lib/connections/dummy +++ b/src/lib/connections/dummy @@ -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" } diff --git a/src/lib/connections/vlan b/src/lib/connections/vlan index e9ab08b..b34a67e 100644 --- a/src/lib/connections/vlan +++ b/src/lib/connections/vlan @@ -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" } diff --git a/src/lib/network b/src/lib/network index 7dfe0b5..b91b5e8 100755 --- a/src/lib/network +++ b/src/lib/network @@ -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() { |