#!/bin/sh /etc/rc.common
# Copyright (C) 2017 lean <coolsnowwolf@gmail.com>

START=99

start()
{
	rfc=4096
	cc=$(grep -c processor /proc/cpuinfo)
	rsfe=$(echo $cc*$rfc | bc)
	sysctl -w net.core.rps_sock_flow_entries=$rsfe >/dev/null
	for fileRps in $(ls /sys/class/net/eth*/queues/rx-*/rps_cpus)
	do
		echo $cc > $fileRps
	done
	
	for fileRfc in $(ls /sys/class/net/eth*/queues/rx-*/rps_flow_cnt)
	do
		echo $rfc > $fileRfc
	done
	
	uci set network.@globals[0].packet_steering=1
	uci commit network
	
	a=$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq)
	b=$(echo -n ' : ')
	c=$(cat /proc/cpuinfo | grep 'core id' | sort -u | wc -l)
	d=$(echo -n ' Core ')
	e=$(cat /proc/cpuinfo | grep 'processor' | wc -l)
	f=$(echo -n ' Thread ')
	g=$(dmesg | grep 'DMI:' | awk -F ',' '{print $1$2 }' | awk -F ':' '{print $2 }')
	h=${g}' '${b}${c}${d}${e}${f}

	mkdir -p /tmp/sysinfo
	echo $h > /tmp/sysinfo/model

	a=$(ip address | grep ^[0-9] | awk -F: '{print $2}' | sed "s/ //g" | grep '^[e]' | grep -v "@" | grep -v "\.")
	b=$(echo "$a" | wc -l)
	for i in $(seq 1 $b)
	do
		c=$(echo "$a" | sed -n ${i}p)
		ethtool -K $c rx-checksum on >/dev/null 2>&1
		ethtool -K $c tx-checksum-ip-generic on >/dev/null 2>&1 || (
		ethtool -K $c tx-checksum-ipv4 on >/dev/null 2>&1
		ethtool -K $c tx-checksum-ipv6 on >/dev/null 2>&1)
		ethtool -K $c tx-scatter-gather on >/dev/null 2>&1
		ethtool -K $c gso on >/dev/null 2>&1
		ethtool -K $c tso on >/dev/null 2>&1
		ethtool -K $c ufo on >/dev/null 2>&1
	done

	[ -f /etc/index.htm ] && mv /etc/index.htm /usr/lib/lua/luci/view/admin_status/index.htm
}
