in port_management added a loop thats populate the ports config with sfpports from db

and added a function that sets the speed on the sfp from config on restart
This commit is contained in:
Reidar Cederqvist 2016-09-21 11:32:03 +02:00
parent a1a48a45c5
commit 192c397493

View file

@ -10,10 +10,10 @@ USE_PROCD=1
check_for_config(){
if [ -s "/etc/config/ports" ]
then
debug_print "file exists and has content"
then
debug_print "file exists and has content"
if uci -q get ports.@ethport[0] >/dev/null #are there any valid content then continue
then
then
return 0
else
rm -f /etc/config/ports
@ -21,7 +21,7 @@ check_for_config(){
fi
debug_print "ports config file doesn't exsist or is empty"
touch /etc/config/ports
local portnames="$(db get hw.board.ethernetPortNames)"
local fiberorder="$(db get hw.board.fiberPortOrder)"
local portorder="$(db get hw.board.ethernetPortOrder)"
for port in $portorder
do
@ -31,12 +31,20 @@ check_for_config(){
uci set ports.@ethport[-1].ifname=$port
uci set ports.@ethport[-1].speed='auto'
if [ "$(interfacename $port)" = "WAN" ]
then
then
uci set ports.@ethport[-1].pause=1
else
uci set ports.@ethport[-1].pause=0
fi
done
for fiber in $fiberorder; do
uci add ports sfpport
uci rename ports.@sfpport[-1]="$(fibername $fiber)"
uci set ports.@sfpport[-1].name="$(fibername $fiber)"
uci set ports.@sfpport[-1].ifname=$fiber
uci set ports.@sfpport[-1].speed='auto'
uci set ports.@sfpport[-1].pause=1
done
uci commit ports
[ $DEBUG ] && cat /etc/config/ports
}
@ -91,12 +99,12 @@ set_port_status() {
case "$status" in
disabled)
ethctl $port phy-power down
;;
;;
*)
if [ "$status" != "$curstatus" ]; then
case "$status" in
1000*)
portno=$(get_port_no $port)
local portno=$(get_port_no $port)
case "$status" in
1000FD) ethswctl -c phymode -p $portno -y 1000 -z 1 ;;
1000HD) ethswctl -c phymode -p $portno -y 1000 -z 0 ;;
@ -109,7 +117,7 @@ set_port_status() {
ethctl $port media-type $status
;;
*)
ethctl $port media-type advertise 1000FDAUTO
ethctl $port media-type advertise 1000FDAUTO
ethctl $port media-type auto
;;
esac
@ -120,15 +128,41 @@ set_port_status() {
esac
}
set_fiber_status() {
local port="$1"
local status="$2"
case "$status" in
disabled)
ethctl $port phy-power down
;;
100*FDAUTO|auto)
ethctl $port media-type sfp fiber $status
ethctl $port phy-power up
;;
esac
}
configure_ethports(){
local port ifname pause speed
name=$1
config_get speed $name speed
config_get speed $name speed
config_get ifname $name ifname
config_get pause $name pause
set_port_status $ifname $speed
set_port_pause $ifname $pause
}
configure_sfpports(){
local port ifname pause speed
name=$1
config_get speed $name speed
config_get ifname $name ifname
config_get pause $name pause
set_fiber_status $ifname $speed
set_port_pause $ifname $pause
}
#arg1: ethX
#arg2: 0 or 1
set_port_pause() {
@ -141,9 +175,10 @@ start_service() {
check_for_config
config_load ports
config_foreach configure_ethports ethport
config_foreach configure_sfpports sfpport
}
service_triggers() {
procd_add_reload_trigger ports
procd_add_reload_trigger ports
}