2010-01-25 17:11:17 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright (C) 2006 OpenWrt.org
|
|
|
|
# Copyright (C) 2010 Vertical Communications
|
|
|
|
|
2016-08-12 14:47:25 +00:00
|
|
|
preinit_ip_config() {
|
2016-07-28 22:23:55 +00:00
|
|
|
local netdev vid
|
2016-08-12 14:47:25 +00:00
|
|
|
|
2016-07-28 22:23:55 +00:00
|
|
|
netdev=${1%\.*}
|
|
|
|
vid=${1#*\.}
|
|
|
|
|
|
|
|
if [ "$vid" = "$netdev" ]; then
|
|
|
|
vid=
|
|
|
|
fi
|
|
|
|
|
|
|
|
grep -q "$netdev" /proc/net/dev || return
|
|
|
|
|
|
|
|
if [ -n "$vid" ]; then
|
|
|
|
ip link add link $netdev name $1 type vlan id $vid
|
|
|
|
fi
|
|
|
|
|
|
|
|
ip link set dev $netdev up
|
2016-08-12 14:47:25 +00:00
|
|
|
ip -4 address add $pi_ip/$pi_netmask broadcast $pi_broadcast dev $1
|
|
|
|
}
|
|
|
|
|
2016-07-28 22:25:09 +00:00
|
|
|
preinit_config_switch() {
|
|
|
|
local role roles ports device enable reset
|
|
|
|
|
|
|
|
local name=$1
|
|
|
|
local lan_if=$2
|
|
|
|
|
|
|
|
json_select switch
|
|
|
|
json_select $name
|
|
|
|
|
|
|
|
json_get_vars enable reset
|
|
|
|
|
|
|
|
if json_is_a roles array; then
|
|
|
|
json_get_keys roles roles
|
|
|
|
json_select roles
|
|
|
|
|
|
|
|
for role in $roles; do
|
|
|
|
json_select "$role"
|
|
|
|
json_get_vars ports device
|
|
|
|
json_select ..
|
|
|
|
|
|
|
|
if [ "$device" = "$lan_if" ]; then
|
|
|
|
swconfig dev $name set reset $reset
|
|
|
|
swconfig dev $name set enable_vlan $enable
|
|
|
|
swconfig dev $name vlan $role set ports "$ports"
|
|
|
|
swconfig dev $name set apply
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
json_select ..
|
|
|
|
fi
|
|
|
|
|
|
|
|
json_select ..
|
|
|
|
json_select ..
|
|
|
|
}
|
|
|
|
|
2016-07-28 20:58:59 +00:00
|
|
|
preinit_config_board() {
|
|
|
|
/bin/board_detect /tmp/board.json
|
|
|
|
|
|
|
|
[ -f "/tmp/board.json" ] || return
|
|
|
|
|
|
|
|
. /usr/share/libubox/jshn.sh
|
|
|
|
|
|
|
|
json_init
|
|
|
|
json_load "$(cat /tmp/board.json)"
|
|
|
|
|
|
|
|
json_select network
|
|
|
|
json_select "lan"
|
|
|
|
json_get_vars ifname
|
|
|
|
json_select ..
|
|
|
|
json_select ..
|
|
|
|
|
|
|
|
[ -n "$ifname" ] || return
|
|
|
|
|
|
|
|
# only use the first one
|
|
|
|
ifname=${ifname%% *}
|
|
|
|
|
2016-07-28 22:25:09 +00:00
|
|
|
if [ -x /sbin/swconfig ]; then
|
|
|
|
# configure the switch, if present
|
|
|
|
|
|
|
|
json_get_keys keys switch
|
|
|
|
for key in $keys; do
|
|
|
|
preinit_config_switch $key $ifname
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# trim any vlan ids
|
|
|
|
ifname=${ifname%\.*}
|
|
|
|
fi
|
2016-07-28 20:58:59 +00:00
|
|
|
|
|
|
|
preinit_ip_config $ifname
|
|
|
|
}
|
|
|
|
|
2010-01-25 17:11:17 +00:00
|
|
|
preinit_ip() {
|
2013-12-09 11:30:14 +00:00
|
|
|
# if the preinit interface isn't specified and ifname is set in
|
|
|
|
# preinit.arch use that interface
|
|
|
|
if [ -z "$pi_ifname" ]; then
|
|
|
|
pi_ifname=$ifname
|
|
|
|
fi
|
|
|
|
|
2016-08-12 14:47:25 +00:00
|
|
|
if [ -n "$pi_ifname" ]; then
|
|
|
|
preinit_ip_config $pi_ifname
|
2016-07-28 20:58:59 +00:00
|
|
|
elif [ -d "/etc/board.d/" ]; then
|
|
|
|
preinit_config_board
|
2016-08-12 14:47:25 +00:00
|
|
|
fi
|
2010-01-25 17:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
preinit_ip_deconfig() {
|
2013-12-09 11:30:14 +00:00
|
|
|
[ -n "$pi_ifname" ] && grep -q "$pi_ifname" /proc/net/dev && {
|
2016-07-28 22:23:55 +00:00
|
|
|
local netdev vid
|
|
|
|
|
|
|
|
netdev=${pi_ifname%\.*}
|
|
|
|
vid=${pi_ifname#*\.}
|
|
|
|
|
|
|
|
if [ "$vid" = "$netdev" ]; then
|
|
|
|
vid=
|
|
|
|
fi
|
|
|
|
|
2015-09-08 17:44:13 +00:00
|
|
|
ip -4 address flush dev $pi_ifname
|
2016-07-28 22:23:55 +00:00
|
|
|
ip link set dev $netdev down
|
|
|
|
|
|
|
|
if [ -n "$vid" ]; then
|
|
|
|
ip link delete $pi_ifname
|
|
|
|
fi
|
2013-12-09 11:30:14 +00:00
|
|
|
}
|
2010-01-25 17:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
preinit_net_echo() {
|
2010-02-01 00:32:46 +00:00
|
|
|
[ -n "$pi_ifname" ] && grep -q "$pi_ifname" /proc/net/dev && {
|
2013-12-09 11:30:14 +00:00
|
|
|
{
|
2010-01-25 17:11:17 +00:00
|
|
|
[ "$pi_preinit_net_messages" = "y" ] || {
|
2013-12-09 11:30:14 +00:00
|
|
|
[ "$pi_failsafe_net_message" = "true" ] &&
|
|
|
|
[ "$pi_preinit_no_failsafe_netmsg" != "y" ]
|
|
|
|
}
|
2010-01-25 17:11:17 +00:00
|
|
|
} && netmsg $pi_broadcast "$1"
|
2013-12-09 11:30:14 +00:00
|
|
|
}
|
2010-01-25 17:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
preinit_echo() {
|
2013-12-09 11:30:14 +00:00
|
|
|
preinit_net_echo $1
|
|
|
|
echo $1
|
2010-01-25 17:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pi_indicate_preinit() {
|
2016-03-24 21:40:13 +00:00
|
|
|
preinit_net_echo "Doing Lede Preinit\n"
|
2014-12-15 10:37:00 +00:00
|
|
|
set_state preinit
|
2010-01-25 17:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
boot_hook_add preinit_main preinit_ip
|
|
|
|
boot_hook_add preinit_main pi_indicate_preinit
|