create_ap

create a nat-ed wifi ap
git clone git://git.2f30.org/create_ap.git
Log | Files | Refs | LICENSE

commit f06e24721a64dde389563fe4eadd4869be1f780a
parent 796c420589073ba7645d4d9b3dd433aa9463861a
Author: oblique <psyberbits@gmail.com>
Date:   Sun Feb 22 21:58:35 +0200

Use `ip' instead of `brctl'

This removes bridge-utils from dependencies.

Diffstat:
README.md | 3---
create_ap | 28++++++++++++++++++----------
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/README.md b/README.md @@ -23,9 +23,6 @@ * dnsmasq * iptables -### For 'Bridged' Internet sharing method -* bridge-utils - ## Installation ### Generic diff --git a/create_ap b/create_ap @@ -13,9 +13,6 @@ # dnsmasq # iptables -# dependencies for 'bridge' Internet sharing method -# bridge-utils - # make sure that all command outputs are in english # so we can parse them correctly @@ -115,7 +112,8 @@ is_wifi_interface() { } is_bridge_interface() { - brctl show | cut -f1 | grep -E "^$1\$" > /dev/null 2>&1 + [[ -z "$1" ]] && return 1 + [[ -d "/sys/class/net/${1}/bridge" ]] } get_phy_device() { @@ -462,8 +460,11 @@ _cleanup() { fi if ! is_bridge_interface $INTERNET_IFACE; then - ip link set down $BRIDGE_IFACE - brctl delbr $BRIDGE_IFACE + ip link set dev $BRIDGE_IFACE down + ip link set dev $INTERNET_IFACE down + ip link set dev $INTERNET_IFACE promisc off + ip link set dev $INTERNET_IFACE nomaster + ip link delete $BRIDGE_IFACE type bridge ip addr flush $INTERNET_IFACE ip link set dev $INTERNET_IFACE up @@ -479,11 +480,13 @@ _cleanup() { ip route flush dev $INTERNET_IFACE for x in "${ROUTE_ADDRS[@]}"; do + [[ -z "$x" ]] && continue [[ "$x" == default* ]] && continue ip route add $x dev $INTERNET_IFACE done for x in "${ROUTE_ADDRS[@]}"; do + [[ -z "$x" ]] && continue [[ "$x" != default* ]] && continue ip route add $x dev $INTERNET_IFACE done @@ -1040,7 +1043,7 @@ if [[ "$SHARE_METHOD" != "none" ]]; then # # 1) save the IPs and route table of INTERNET_IFACE # 2) if NetworkManager is running set INTERNET_IFACE as unmanaged - # 3) create BRIDGE_IFACE and add INTERNET_IFACE to it + # 3) create BRIDGE_IFACE and attach INTERNET_IFACE to it # 4) set the previously saved IPs and route table to BRIDGE_IFACE # # we need the above because BRIDGE_IFACE is the master interface from now on @@ -1060,11 +1063,16 @@ if [[ "$SHARE_METHOD" != "none" ]]; then networkmanager_wait_until_unmanaged $INTERNET_IFACE fi - brctl addbr $BRIDGE_IFACE || die - brctl setfd $BRIDGE_IFACE 0 - brctl addif $BRIDGE_IFACE $INTERNET_IFACE || die + # create bridge interface + ip link add name $BRIDGE_IFACE type bridge || die ip link set dev $BRIDGE_IFACE up || die + # set 0ms forward delay + echo 0 > /sys/class/net/$BRIDGE_IFACE/bridge/forward_delay + + # attach internet interface to bridge interface + ip link set dev $INTERNET_IFACE promisc on || die ip link set dev $INTERNET_IFACE up || die + ip link set dev $INTERNET_IFACE master $BRIDGE_IFACE || die ip addr flush $INTERNET_IFACE for x in "${IP_ADDRS[@]}"; do