1#!/bin/sh 2# 3# Copyright (C) 2011 OpenWrt.org 4# 5 6. /lib/functions/uci-defaults.sh 7 8board_config_update 9 10board=$(cat /proc/device-tree/compatible | tr '\0' '\t' | cut -f 1) 11case "$board" in 12asus,rt-ac87u) 13 ifname=eth1 14 ;; 15dlink,dir-885l | \ 16netgear,r7900 | \ 17netgear,r8000 | \ 18netgear,r8500) 19 20 ifname=eth2 21 ;; 22*) 23 ifname=eth0 24 ;; 25esac 26 27# Workaround for devices using eth2 connected to (CPU) switch port 8 28case "$board" in 29dlink,dir-885l | \ 30netgear,r7900 | \ 31netgear,r8000 | \ 32netgear,r8500) 33 ifname=eth0 34 ucidef_add_switch "switch0" \ 35 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5t@$ifname" 36 board_config_flush 37 exit 0 38 ;; 39esac 40 41# NVRAM entries may contain unsorted ports, e.g. Netgear R6250 uses 42# vlan1ports=3 2 1 0 5* 43# vlan2ports=4 5u 44# and early Netgear R8000 was using 45# vlan1ports=3 2 1 0 5 7 8* 46vlan1ports="$(echo $(nvram get vlan1ports | tr " " "\n" | sort))" 47vlan2ports="$(echo $(nvram get vlan2ports | tr " " "\n" | sort))" 48if echo "$vlan1ports" | egrep -q "^1 2 3 4 5" && \ 49 echo "$vlan2ports" | egrep -q "^0 5"; then 50 ucidef_add_switch "switch0" \ 51 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5t@$ifname" 52elif echo "$vlan1ports" | egrep -q "^1 2 3 5 7" && \ 53 echo "$vlan2ports" | egrep -q "^0 7"; then 54 ucidef_add_switch "switch0" \ 55 "1:lan" "2:lan" "3:lan" "5:lan" "0:wan" "7t@$ifname" 56elif echo "$vlan1ports" | egrep -q "^0 1 2 3 5 7 8" && \ 57 echo "$vlan2ports" | egrep -q "^4 8"; then 58 ucidef_add_switch "switch0" \ 59 "0:lan" "1:lan" "2:lan" "3:lan" "5:lan" "7:lan" "4:wan" "8t@$ifname" 60else 61 ucidef_add_switch "switch0" \ 62 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5t@$ifname" 63fi 64 65board_config_flush 66 67exit 0 68