2006-07-30 03:09:09 +00:00
|
|
|
#!/bin/sh
|
2011-11-08 22:47:54 +00:00
|
|
|
# Copyright (C) 2006-2011 OpenWrt.org
|
2006-07-30 03:09:09 +00:00
|
|
|
|
|
|
|
# DEBUG="echo"
|
|
|
|
|
2010-11-30 00:46:21 +00:00
|
|
|
do_sysctl() {
|
|
|
|
[ -n "$2" ] && \
|
|
|
|
sysctl -n -e -w "$1=$2" >/dev/null || \
|
|
|
|
sysctl -n -e "$1"
|
|
|
|
}
|
|
|
|
|
2011-07-17 17:10:30 +00:00
|
|
|
map_sysctls() {
|
|
|
|
local cfg="$1"
|
|
|
|
local ifn="$2"
|
|
|
|
|
|
|
|
local fam
|
|
|
|
for fam in ipv4 ipv6; do
|
|
|
|
if [ -d /proc/sys/net/$fam ]; then
|
|
|
|
local key
|
|
|
|
for key in /proc/sys/net/$fam/*/$ifn/*; do
|
|
|
|
local val
|
|
|
|
config_get val "$cfg" "${fam}_${key##*/}"
|
|
|
|
[ -n "$val" ] && echo -n "$val" > "$key"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2006-07-30 03:09:09 +00:00
|
|
|
find_config() {
|
2006-08-27 10:05:58 +00:00
|
|
|
local iftype device iface ifaces ifn
|
2006-07-30 03:09:09 +00:00
|
|
|
for ifn in $interfaces; do
|
2006-07-30 13:21:18 +00:00
|
|
|
config_get iftype "$ifn" type
|
2006-07-30 03:09:09 +00:00
|
|
|
config_get iface "$ifn" ifname
|
2006-08-27 10:05:58 +00:00
|
|
|
case "$iftype" in
|
|
|
|
bridge) config_get ifaces "$ifn" ifnames;;
|
|
|
|
esac
|
2006-08-04 09:50:11 +00:00
|
|
|
config_get device "$ifn" device
|
2006-08-27 10:05:58 +00:00
|
|
|
for ifc in $device $iface $ifaces; do
|
2007-06-15 16:07:09 +00:00
|
|
|
[ ."$ifc" = ."$1" ] && {
|
2006-07-30 03:09:09 +00:00
|
|
|
echo "$ifn"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
scan_interfaces() {
|
2009-08-07 00:08:06 +00:00
|
|
|
local cfgfile="${1:-network}"
|
2006-07-30 03:09:09 +00:00
|
|
|
interfaces=
|
|
|
|
config_cb() {
|
2006-11-03 21:57:35 +00:00
|
|
|
case "$1" in
|
|
|
|
interface)
|
|
|
|
config_set "$2" auto 1
|
|
|
|
;;
|
|
|
|
esac
|
2009-08-07 00:08:06 +00:00
|
|
|
local iftype ifname device proto
|
2006-07-30 13:21:18 +00:00
|
|
|
config_get iftype "$CONFIG_SECTION" TYPE
|
|
|
|
case "$iftype" in
|
2006-07-30 03:09:09 +00:00
|
|
|
interface)
|
|
|
|
append interfaces "$CONFIG_SECTION"
|
2009-08-07 00:08:06 +00:00
|
|
|
config_get proto "$CONFIG_SECTION" proto
|
2006-08-27 11:11:55 +00:00
|
|
|
config_get iftype "$CONFIG_SECTION" type
|
2006-10-09 12:35:31 +00:00
|
|
|
config_get ifname "$CONFIG_SECTION" ifname
|
2009-08-07 00:08:06 +00:00
|
|
|
config_get device "$CONFIG_SECTION" device "$ifname"
|
|
|
|
config_set "$CONFIG_SECTION" device "$device"
|
2006-08-24 13:46:47 +00:00
|
|
|
case "$iftype" in
|
|
|
|
bridge)
|
2009-08-07 00:08:06 +00:00
|
|
|
config_set "$CONFIG_SECTION" ifnames "$device"
|
2006-08-24 13:46:47 +00:00
|
|
|
config_set "$CONFIG_SECTION" ifname br-"$CONFIG_SECTION"
|
|
|
|
;;
|
|
|
|
esac
|
2006-08-23 18:47:31 +00:00
|
|
|
( type "scan_$proto" ) >/dev/null 2>/dev/null && eval "scan_$proto '$CONFIG_SECTION'"
|
2006-07-30 03:09:09 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
2009-08-07 00:08:06 +00:00
|
|
|
config_load "${cfgfile}"
|
2006-07-30 03:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
add_vlan() {
|
|
|
|
local vif="${1%\.*}"
|
2009-08-04 00:06:47 +00:00
|
|
|
|
2006-07-30 03:09:09 +00:00
|
|
|
[ "$1" = "$vif" ] || ifconfig "$1" >/dev/null 2>/dev/null || {
|
|
|
|
ifconfig "$vif" up 2>/dev/null >/dev/null || add_vlan "$vif"
|
|
|
|
$DEBUG vconfig add "$vif" "${1##*\.}"
|
2008-08-01 03:01:25 +00:00
|
|
|
return 0
|
2006-07-30 03:09:09 +00:00
|
|
|
}
|
2008-08-01 03:01:25 +00:00
|
|
|
return 1
|
2006-07-30 03:09:09 +00:00
|
|
|
}
|
|
|
|
|
2010-05-07 01:17:47 +00:00
|
|
|
# add dns entries if they are not in resolv.conf yet
|
|
|
|
add_dns() {
|
|
|
|
local cfg="$1"; shift
|
|
|
|
|
2010-05-30 18:23:43 +00:00
|
|
|
remove_dns "$cfg"
|
|
|
|
|
|
|
|
# We may be called by pppd's ip-up which has a nonstandard umask set.
|
|
|
|
# Create an empty file here and force its permission to 0644, otherwise
|
|
|
|
# dnsmasq will not be able to re-read the resolv.conf.auto .
|
|
|
|
[ ! -f /tmp/resolv.conf.auto ] && {
|
|
|
|
touch /tmp/resolv.conf.auto
|
|
|
|
chmod 0644 /tmp/resolv.conf.auto
|
|
|
|
}
|
|
|
|
|
2010-05-07 01:17:47 +00:00
|
|
|
local dns
|
|
|
|
local add
|
|
|
|
for dns in "$@"; do
|
2011-09-23 08:35:50 +00:00
|
|
|
grep -qsE "^nameserver ${dns//./\\.}$" /tmp/resolv.conf.auto || {
|
2010-05-07 01:17:47 +00:00
|
|
|
add="${add:+$add }$dns"
|
|
|
|
echo "nameserver $dns" >> /tmp/resolv.conf.auto
|
|
|
|
}
|
|
|
|
done
|
|
|
|
|
2010-05-30 18:23:43 +00:00
|
|
|
[ -n "$cfg" ] && {
|
2011-07-15 14:57:44 +00:00
|
|
|
uci_toggle_state network "$cfg" dns "$add"
|
|
|
|
uci_toggle_state network "$cfg" resolv_dns "$add"
|
2010-05-30 18:23:43 +00:00
|
|
|
}
|
2010-05-07 01:17:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# remove dns entries of the given iface
|
|
|
|
remove_dns() {
|
|
|
|
local cfg="$1"
|
|
|
|
|
2010-05-30 18:23:43 +00:00
|
|
|
[ -n "$cfg" ] && {
|
|
|
|
[ -f /tmp/resolv.conf.auto ] && {
|
|
|
|
local dns=$(uci_get_state network "$cfg" resolv_dns)
|
|
|
|
for dns in $dns; do
|
2011-09-23 08:35:50 +00:00
|
|
|
sed -i -e "/^nameserver ${dns//./\\.}$/d" /tmp/resolv.conf.auto
|
2010-05-30 18:23:43 +00:00
|
|
|
done
|
|
|
|
}
|
2010-05-07 01:17:47 +00:00
|
|
|
|
2010-05-30 18:23:43 +00:00
|
|
|
uci_revert_state network "$cfg" dns
|
|
|
|
uci_revert_state network "$cfg" resolv_dns
|
|
|
|
}
|
2010-05-07 01:17:47 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 05:22:02 +00:00
|
|
|
# sort the device list, drop duplicates
|
|
|
|
sort_list() {
|
|
|
|
local arg="$*"
|
|
|
|
(
|
|
|
|
for item in $arg; do
|
|
|
|
echo "$item"
|
|
|
|
done
|
|
|
|
) | sort -u
|
|
|
|
}
|
|
|
|
|
2011-11-04 01:05:12 +00:00
|
|
|
prepare_interface_bridge() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2007-02-25 12:52:02 +00:00
|
|
|
# Create the interface, if necessary.
|
|
|
|
# Return status 0 indicates that the setup_interface() call should continue
|
|
|
|
# Return status 1 means that everything is set up already.
|
|
|
|
|
|
|
|
prepare_interface() {
|
2006-07-30 03:09:09 +00:00
|
|
|
local iface="$1"
|
|
|
|
local config="$2"
|
2011-09-24 20:34:17 +00:00
|
|
|
local macaddr="$3"
|
2006-07-30 03:09:09 +00:00
|
|
|
|
2007-02-25 12:52:02 +00:00
|
|
|
# if we're called for the bridge interface itself, don't bother trying
|
|
|
|
# to create any interfaces here. The scripts have already done that, otherwise
|
|
|
|
# the bridge interface wouldn't exist.
|
2007-11-30 09:43:05 +00:00
|
|
|
[ "br-$config" = "$iface" -o -e "$iface" ] && return 0;
|
2009-08-04 00:06:47 +00:00
|
|
|
|
2006-10-15 15:50:02 +00:00
|
|
|
ifconfig "$iface" 2>/dev/null >/dev/null && {
|
2009-08-07 00:08:06 +00:00
|
|
|
local proto
|
2009-06-01 18:07:44 +00:00
|
|
|
config_get proto "$config" proto
|
|
|
|
|
|
|
|
# make sure the interface is removed from any existing bridge and deconfigured,
|
|
|
|
# (deconfigured only if the interface is not set to proto=none)
|
2006-10-15 15:50:02 +00:00
|
|
|
unbridge "$iface"
|
2009-03-25 19:13:15 +00:00
|
|
|
|
2011-09-24 20:34:17 +00:00
|
|
|
local mtu macaddr txqueuelen
|
|
|
|
config_get mtu "$config" mtu
|
|
|
|
[ -n "$macaddr" ] || config_get macaddr "$config" macaddr
|
|
|
|
config_get txqueuelen "$config" txqueuelen
|
|
|
|
[ -n "$macaddr" ] && $DEBUG ifconfig "$iface" down
|
|
|
|
$DEBUG ifconfig "$iface" ${macaddr:+hw ether "$macaddr"} ${mtu:+mtu $mtu} ${txqueuelen:+txqueuelen $txqueuelen} up
|
|
|
|
|
|
|
|
[ "$proto" = none ] || ifconfig "$iface" 0.0.0.0
|
2011-07-17 17:10:30 +00:00
|
|
|
|
|
|
|
# Apply sysctl settings
|
|
|
|
map_sysctls "$config" "$iface"
|
2006-10-15 15:50:02 +00:00
|
|
|
}
|
|
|
|
|
2006-07-30 03:09:09 +00:00
|
|
|
# Setup VLAN interfaces
|
2008-08-01 03:01:25 +00:00
|
|
|
add_vlan "$iface" && return 1
|
2007-04-02 09:41:56 +00:00
|
|
|
ifconfig "$iface" 2>/dev/null >/dev/null || return 0
|
2006-07-30 03:09:09 +00:00
|
|
|
|
|
|
|
# Setup bridging
|
2009-08-07 00:08:06 +00:00
|
|
|
local iftype
|
2007-02-25 12:52:02 +00:00
|
|
|
config_get iftype "$config" type
|
2006-07-30 03:09:09 +00:00
|
|
|
case "$iftype" in
|
|
|
|
bridge)
|
2010-05-27 14:04:28 +00:00
|
|
|
local macaddr
|
|
|
|
config_get macaddr "$config" macaddr
|
2007-01-20 15:28:47 +00:00
|
|
|
[ -x /usr/sbin/brctl ] && {
|
|
|
|
ifconfig "br-$config" 2>/dev/null >/dev/null && {
|
2009-08-07 00:08:06 +00:00
|
|
|
local newdevs devices
|
2008-07-30 05:22:02 +00:00
|
|
|
config_get devices "$config" device
|
|
|
|
for dev in $(sort_list "$devices" "$iface"); do
|
|
|
|
append newdevs "$dev"
|
|
|
|
done
|
2011-07-15 14:57:44 +00:00
|
|
|
uci_toggle_state network "$config" device "$newdevs"
|
2009-09-16 14:21:19 +00:00
|
|
|
$DEBUG ifconfig "$iface" 0.0.0.0
|
2011-02-11 00:39:11 +00:00
|
|
|
$DEBUG do_sysctl "net.ipv6.conf.$iface.disable_ipv6" 1
|
2007-01-20 15:28:47 +00:00
|
|
|
$DEBUG brctl addif "br-$config" "$iface"
|
2007-02-25 12:52:02 +00:00
|
|
|
# Bridge existed already. No further processing necesary
|
2007-01-20 15:28:47 +00:00
|
|
|
} || {
|
2011-10-11 13:43:08 +00:00
|
|
|
local stp igmp_snooping
|
2009-08-07 00:08:06 +00:00
|
|
|
config_get_bool stp "$config" stp 0
|
2011-10-11 13:43:08 +00:00
|
|
|
config_get_bool igmp_snooping "$config" igmp_snooping 1
|
2007-01-20 15:28:47 +00:00
|
|
|
$DEBUG brctl addbr "br-$config"
|
|
|
|
$DEBUG brctl setfd "br-$config" 0
|
2009-09-16 14:21:19 +00:00
|
|
|
$DEBUG ifconfig "$iface" 0.0.0.0
|
2011-02-11 00:39:11 +00:00
|
|
|
$DEBUG do_sysctl "net.ipv6.conf.$iface.disable_ipv6" 1
|
2007-01-20 15:28:47 +00:00
|
|
|
$DEBUG brctl addif "br-$config" "$iface"
|
2009-08-07 00:08:06 +00:00
|
|
|
$DEBUG brctl stp "br-$config" $stp
|
2011-05-24 09:31:37 +00:00
|
|
|
[ -z "$macaddr" ] && macaddr="$(cat /sys/class/net/$iface/address)"
|
2011-10-11 13:43:08 +00:00
|
|
|
echo $igmp_snooping > /sys/devices/virtual/net/br-$config/bridge/multicast_snooping 2>/dev/null
|
2011-05-24 09:31:37 +00:00
|
|
|
$DEBUG ifconfig "br-$config" hw ether $macaddr up
|
2007-02-25 12:52:02 +00:00
|
|
|
# Creating the bridge here will have triggered a hotplug event, which will
|
|
|
|
# result in another setup_interface() call, so we simply stop processing
|
|
|
|
# the current event at this point.
|
2007-01-20 15:28:47 +00:00
|
|
|
}
|
2010-05-27 14:04:28 +00:00
|
|
|
ifconfig "$iface" ${macaddr:+hw ether "${macaddr}"} up 2>/dev/null >/dev/null
|
2007-02-25 12:52:02 +00:00
|
|
|
return 1
|
2006-07-30 03:09:09 +00:00
|
|
|
}
|
|
|
|
;;
|
|
|
|
esac
|
2007-02-25 12:52:02 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2008-04-02 21:27:28 +00:00
|
|
|
set_interface_ifname() {
|
|
|
|
local config="$1"
|
|
|
|
local ifname="$2"
|
|
|
|
|
2009-08-07 00:08:06 +00:00
|
|
|
local device
|
2008-04-02 21:27:28 +00:00
|
|
|
config_get device "$1" device
|
2011-07-15 14:57:44 +00:00
|
|
|
uci_toggle_state network "$config" ifname "$ifname"
|
|
|
|
uci_toggle_state network "$config" device "$device"
|
2008-04-02 21:27:28 +00:00
|
|
|
}
|
|
|
|
|
2008-08-20 11:17:40 +00:00
|
|
|
setup_interface_none() {
|
2008-08-20 11:45:23 +00:00
|
|
|
env -i ACTION="ifup" INTERFACE="$2" DEVICE="$1" PROTO=none /sbin/hotplug-call "iface" &
|
2008-08-20 11:17:40 +00:00
|
|
|
}
|
|
|
|
|
2008-08-07 15:28:48 +00:00
|
|
|
setup_interface_static() {
|
|
|
|
local iface="$1"
|
|
|
|
local config="$2"
|
|
|
|
|
2011-09-14 13:37:40 +00:00
|
|
|
local ipaddr netmask ip6addr
|
2008-08-07 15:28:48 +00:00
|
|
|
config_get ipaddr "$config" ipaddr
|
|
|
|
config_get netmask "$config" netmask
|
2011-09-14 13:37:40 +00:00
|
|
|
config_get ip6addr "$config" ip6addr
|
2008-08-07 15:28:48 +00:00
|
|
|
[ -z "$ipaddr" -o -z "$netmask" ] && [ -z "$ip6addr" ] && return 1
|
2009-08-04 00:06:47 +00:00
|
|
|
|
2010-11-17 19:11:50 +00:00
|
|
|
local gateway ip6gw dns bcast metric
|
2008-08-07 15:28:48 +00:00
|
|
|
config_get gateway "$config" gateway
|
|
|
|
config_get ip6gw "$config" ip6gw
|
|
|
|
config_get dns "$config" dns
|
|
|
|
config_get bcast "$config" broadcast
|
2010-11-17 19:11:50 +00:00
|
|
|
config_get metric "$config" metric
|
2009-08-04 00:06:47 +00:00
|
|
|
|
2011-09-14 13:37:40 +00:00
|
|
|
case "$ip6addr" in
|
|
|
|
*/*) ;;
|
|
|
|
*:*) ip6addr="$ip6addr/64" ;;
|
|
|
|
esac
|
|
|
|
|
2008-08-07 15:28:48 +00:00
|
|
|
[ -z "$ipaddr" ] || $DEBUG ifconfig "$iface" "$ipaddr" netmask "$netmask" broadcast "${bcast:-+}"
|
2011-09-14 13:37:44 +00:00
|
|
|
[ -z "$ip6addr" ] || $DEBUG ifconfig "${iface%:*}" add "$ip6addr"
|
2010-11-17 19:11:50 +00:00
|
|
|
[ -z "$gateway" ] || $DEBUG route add default gw "$gateway" ${metric:+metric $metric} dev "$iface"
|
2011-09-14 13:37:44 +00:00
|
|
|
[ -z "$ip6gw" ] || $DEBUG route -A inet6 add default gw "$ip6gw" ${metric:+metric $metric} dev "${iface%:*}"
|
2010-05-30 18:23:43 +00:00
|
|
|
[ -z "$dns" ] || add_dns "$config" $dns
|
2008-08-07 15:28:48 +00:00
|
|
|
|
2009-08-04 00:06:47 +00:00
|
|
|
config_get type "$config" TYPE
|
2009-04-13 00:43:23 +00:00
|
|
|
[ "$type" = "alias" ] && return 0
|
|
|
|
|
2008-08-07 15:28:48 +00:00
|
|
|
env -i ACTION="ifup" INTERFACE="$config" DEVICE="$iface" PROTO=static /sbin/hotplug-call "iface" &
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_interface_alias() {
|
|
|
|
local config="$1"
|
|
|
|
local parent="$2"
|
|
|
|
local iface="$3"
|
|
|
|
|
2009-08-07 00:08:06 +00:00
|
|
|
local cfg
|
2008-08-07 15:28:48 +00:00
|
|
|
config_get cfg "$config" interface
|
|
|
|
[ "$parent" == "$cfg" ] || return 0
|
|
|
|
|
2010-06-02 00:22:13 +00:00
|
|
|
# parent device and ifname
|
|
|
|
local p_device p_type
|
|
|
|
config_get p_device "$cfg" device
|
|
|
|
config_get p_type "$cfg" type
|
|
|
|
|
|
|
|
# select alias ifname
|
|
|
|
local layer use_iface
|
|
|
|
config_get layer "$config" layer 2
|
|
|
|
case "$layer:$p_type" in
|
|
|
|
# layer 3: e.g. pppoe-wan or pptp-vpn
|
|
|
|
3:*) use_iface="$iface" ;;
|
|
|
|
|
|
|
|
# layer 2 and parent is bridge: e.g. br-wan
|
|
|
|
2:bridge) use_iface="br-$cfg" ;;
|
|
|
|
|
|
|
|
# layer 1: e.g. eth0 or ath0
|
|
|
|
*) use_iface="$p_device" ;;
|
|
|
|
esac
|
|
|
|
|
2008-08-07 15:28:48 +00:00
|
|
|
# alias counter
|
2009-08-07 00:08:06 +00:00
|
|
|
local ctr
|
|
|
|
config_get ctr "$parent" alias_count 0
|
2008-08-07 15:28:48 +00:00
|
|
|
ctr="$(($ctr + 1))"
|
|
|
|
config_set "$parent" alias_count "$ctr"
|
|
|
|
|
|
|
|
# alias list
|
2009-08-07 00:08:06 +00:00
|
|
|
local list
|
2008-08-07 15:28:48 +00:00
|
|
|
config_get list "$parent" aliases
|
|
|
|
append list "$config"
|
|
|
|
config_set "$parent" aliases "$list"
|
|
|
|
|
2010-06-02 00:22:13 +00:00
|
|
|
use_iface="$use_iface:$ctr"
|
|
|
|
set_interface_ifname "$config" "$use_iface"
|
2009-08-07 00:08:06 +00:00
|
|
|
|
|
|
|
local proto
|
|
|
|
config_get proto "$config" proto "static"
|
|
|
|
case "${proto}" in
|
2008-08-07 15:28:48 +00:00
|
|
|
static)
|
2010-06-02 00:22:13 +00:00
|
|
|
setup_interface_static "$use_iface" "$config"
|
2008-08-07 15:28:48 +00:00
|
|
|
;;
|
2009-08-04 00:06:47 +00:00
|
|
|
*)
|
2008-08-07 15:28:48 +00:00
|
|
|
echo "Unsupported type '$proto' for alias config '$config'"
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2007-02-25 12:52:02 +00:00
|
|
|
setup_interface() {
|
2010-06-01 21:43:52 +00:00
|
|
|
local iface="$1"
|
2007-02-25 12:52:02 +00:00
|
|
|
local config="$2"
|
2009-08-07 00:08:06 +00:00
|
|
|
local proto="$3"
|
2009-03-25 19:13:15 +00:00
|
|
|
local vifmac="$4"
|
2007-02-25 12:52:02 +00:00
|
|
|
|
|
|
|
[ -n "$config" ] || {
|
2010-06-01 21:43:52 +00:00
|
|
|
config=$(find_config "$iface")
|
2007-02-25 12:52:02 +00:00
|
|
|
[ "$?" = 0 ] || return 1
|
|
|
|
}
|
2009-08-04 00:06:47 +00:00
|
|
|
|
2010-06-01 21:43:52 +00:00
|
|
|
prepare_interface "$iface" "$config" "$vifmac" || return 0
|
2009-08-04 00:06:47 +00:00
|
|
|
|
2010-06-01 21:43:52 +00:00
|
|
|
[ "$iface" = "br-$config" ] && {
|
2009-08-04 00:06:47 +00:00
|
|
|
# need to bring up the bridge and wait a second for
|
2007-02-25 12:52:02 +00:00
|
|
|
# it to switch to the 'forwarding' state, otherwise
|
|
|
|
# it will lose its routes...
|
2010-06-01 21:43:52 +00:00
|
|
|
ifconfig "$iface" up
|
2007-02-25 12:52:02 +00:00
|
|
|
sleep 1
|
|
|
|
}
|
2009-08-04 00:06:47 +00:00
|
|
|
|
2006-07-30 03:09:09 +00:00
|
|
|
# Interface settings
|
2010-06-01 21:43:52 +00:00
|
|
|
set_interface_ifname "$config" "$iface"
|
2006-07-30 03:09:09 +00:00
|
|
|
|
2009-08-07 00:08:06 +00:00
|
|
|
[ -n "$proto" ] || config_get proto "$config" proto
|
2006-07-30 03:09:09 +00:00
|
|
|
case "$proto" in
|
|
|
|
static)
|
2010-06-01 21:43:52 +00:00
|
|
|
setup_interface_static "$iface" "$config"
|
2006-07-30 03:09:09 +00:00
|
|
|
;;
|
|
|
|
dhcp)
|
2010-09-19 15:13:06 +00:00
|
|
|
# kill running udhcpc instance
|
2010-06-01 21:43:52 +00:00
|
|
|
local pidfile="/var/run/dhcp-${iface}.pid"
|
2011-11-08 22:47:54 +00:00
|
|
|
|
|
|
|
SERVICE_PID_FILE="$pidfile" \
|
2011-11-11 13:23:29 +00:00
|
|
|
service_stop /sbin/udhcpc
|
2010-09-19 15:13:06 +00:00
|
|
|
|
2010-12-22 07:20:24 +00:00
|
|
|
local ipaddr netmask hostname proto1 clientid vendorid broadcast reqopts
|
2010-09-19 15:13:06 +00:00
|
|
|
config_get ipaddr "$config" ipaddr
|
|
|
|
config_get netmask "$config" netmask
|
|
|
|
config_get hostname "$config" hostname
|
|
|
|
config_get proto1 "$config" proto
|
|
|
|
config_get clientid "$config" clientid
|
2010-10-06 21:21:28 +00:00
|
|
|
config_get vendorid "$config" vendorid
|
2010-09-19 15:13:06 +00:00
|
|
|
config_get_bool broadcast "$config" broadcast 0
|
2010-12-22 07:20:24 +00:00
|
|
|
config_get reqopts "$config" reqopts
|
2010-09-19 15:13:06 +00:00
|
|
|
|
|
|
|
[ -z "$ipaddr" ] || \
|
|
|
|
$DEBUG ifconfig "$iface" "$ipaddr" ${netmask:+netmask "$netmask"}
|
|
|
|
|
2011-01-29 13:45:16 +00:00
|
|
|
# additional request options
|
2011-11-11 13:23:29 +00:00
|
|
|
local opt dhcpopts daemonize
|
2011-01-29 13:45:16 +00:00
|
|
|
for opt in $reqopts; do
|
2011-01-29 17:06:07 +00:00
|
|
|
append dhcpopts "-O $opt"
|
2011-01-29 13:45:16 +00:00
|
|
|
done
|
|
|
|
|
2010-09-19 15:13:06 +00:00
|
|
|
# don't stay running in background if dhcp is not the main proto on the interface (e.g. when using pptp)
|
2011-11-11 13:23:29 +00:00
|
|
|
[ "$proto1" != "$proto" ] && {
|
|
|
|
append dhcpopts "-n -q"
|
|
|
|
} || {
|
|
|
|
append dhcpopts "-O rootpath -R"
|
|
|
|
daemonize=1
|
|
|
|
}
|
2010-09-19 15:13:06 +00:00
|
|
|
[ "$broadcast" = 1 ] && broadcast="-O broadcast" || broadcast=
|
|
|
|
|
2011-11-11 13:23:29 +00:00
|
|
|
SERVICE_DAEMONIZE=$daemonize \
|
2011-11-08 22:47:54 +00:00
|
|
|
SERVICE_PID_FILE="$pidfile" \
|
|
|
|
service_start /sbin/udhcpc -t 0 -i "$iface" \
|
2010-09-19 15:13:06 +00:00
|
|
|
${ipaddr:+-r $ipaddr} \
|
|
|
|
${hostname:+-H $hostname} \
|
|
|
|
${clientid:+-c $clientid} \
|
2010-10-06 21:21:28 +00:00
|
|
|
${vendorid:+-V $vendorid} \
|
2010-09-19 15:13:06 +00:00
|
|
|
-b -p "$pidfile" $broadcast \
|
2011-01-29 13:45:16 +00:00
|
|
|
${dhcpopts}
|
2006-07-30 03:09:09 +00:00
|
|
|
;;
|
2008-08-20 11:17:40 +00:00
|
|
|
none)
|
2010-06-01 21:43:52 +00:00
|
|
|
setup_interface_none "$iface" "$config"
|
2008-08-20 11:17:40 +00:00
|
|
|
;;
|
2006-07-30 03:09:09 +00:00
|
|
|
*)
|
|
|
|
if ( eval "type setup_interface_$proto" ) >/dev/null 2>/dev/null; then
|
2010-06-01 21:43:52 +00:00
|
|
|
eval "setup_interface_$proto '$iface' '$config' '$proto'"
|
2006-07-30 03:09:09 +00:00
|
|
|
else
|
|
|
|
echo "Interface type $proto not supported."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2010-02-12 02:06:57 +00:00
|
|
|
stop_interface_dhcp() {
|
|
|
|
local config="$1"
|
2010-05-05 23:24:11 +00:00
|
|
|
|
2010-05-30 18:23:43 +00:00
|
|
|
local ifname
|
2010-05-06 01:14:24 +00:00
|
|
|
config_get ifname "$config" ifname
|
2010-05-05 23:24:11 +00:00
|
|
|
|
2010-05-06 01:14:24 +00:00
|
|
|
local lock="/var/lock/dhcp-${ifname}"
|
2010-05-05 23:24:11 +00:00
|
|
|
[ -f "$lock" ] && lock -u "$lock"
|
|
|
|
|
2010-05-30 18:23:43 +00:00
|
|
|
remove_dns "$config"
|
|
|
|
|
2011-11-08 22:47:54 +00:00
|
|
|
SERVICE_PID_FILE="/var/run/dhcp-${ifname}.pid" \
|
|
|
|
service_stop /sbin/udhcpc
|
2010-05-05 23:24:11 +00:00
|
|
|
|
2010-02-12 02:06:57 +00:00
|
|
|
uci -P /var/state revert "network.$config"
|
|
|
|
}
|
|
|
|
|
2006-10-15 15:50:02 +00:00
|
|
|
unbridge() {
|
|
|
|
local dev="$1"
|
|
|
|
local brdev
|
2009-08-04 00:06:47 +00:00
|
|
|
|
2007-02-27 23:34:14 +00:00
|
|
|
[ -x /usr/sbin/brctl ] || return 0
|
2010-03-14 21:10:07 +00:00
|
|
|
brctl show 2>/dev/null | grep "$dev" >/dev/null && {
|
2006-10-15 15:50:02 +00:00
|
|
|
# interface is still part of a bridge, correct that
|
|
|
|
|
|
|
|
for brdev in $(brctl show | awk '$2 ~ /^[0-9].*\./ { print $1 }'); do
|
|
|
|
brctl delif "$brdev" "$dev" 2>/dev/null >/dev/null
|
2011-02-12 16:14:15 +00:00
|
|
|
do_sysctl "net.ipv6.conf.$dev.disable_ipv6" 0
|
2006-10-15 15:50:02 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
}
|