summaryrefslogtreecommitdiffstats
path: root/src/lib/connections/bridge
blob: 94a48026c5e4a890cde9dc9fc843818cbcf849c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Contributed by: Thomas Bächler <thomas@archlinux.org>

. "$SUBR_DIR/ip"

declare -ag BindsToInterfaces

bridge_up() {
    if is_interface "$Interface"; then
        if [[ ! -d "/sys/class/net/$Interface/brif" ]]; then
            report_error "Interface '$Interface' already exists and is not a bridge"
            return 1
        fi
    else
        ip link add name "$Interface" type bridge
    fi

    for member in "${BindsToInterfaces[@]}"; do
        ip link set dev "$member" promisc on up
        ip addr flush dev "$member" scope host &>/dev/null
        ip addr flush dev "$member" scope site &>/dev/null
        ip addr flush dev "$member" scope global &>/dev/null
        ip link set dev "$member" master "$Interface"
        is_yes "${SkipForwardingDelay:-no}" && bridge link set dev "$member" state 3
    done

    bring_interface_up "$Interface"
    ip_set
}

bridge_down() {
    for member in "${BindsToInterfaces[@]}"; do
        ip link set "$member" promisc off down
        ip link set dev "$member" nomaster
    done

    ip_unset
    bring_interface_down "$Interface"
    ip link delete "$Interface" type bridge
}


# vim: ft=sh ts=4 et sw=4: