summaryrefslogtreecommitdiffstats
path: root/src/lib/connections/bridge
blob: 56e2c846ea964fcc788bfd27c527931754989bb6 (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
43
# Contributed by: Thomas Bächler <thomas@archlinux.org>

. "$SUBR_DIR/ip"

: ${BRCTL:=brctl}
declare -a 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
        $BRCTL addbr "$Interface"
    fi

    for member in "${BindsToInterfaces[@]}"; do
        ip link set "$member" promisc on up
        ip addr flush dev "$member"
        $BRCTL addif "$Interface" "$member"
    done
    # Set options
    [[ "$FwdDelay" ]] && $BRCTL setfd "$Interface" "$FwdDelay"
    [[ "$MaxAge" ]] && $BRCTL setmaxage "$Interface" "$MaxAge"

    bring_interface_up "$Interface"
    ip_set
}

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

    ip_unset
    bring_interface_down "$Interface"
    $BRCTL delbr "$Interface"
}


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