aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/config
diff options
context:
space:
mode:
authorJames <>2015-11-04 11:49:21 +0000
committerJames <>2015-11-04 11:49:21 +0000
commit716ca530e1c4515d8683c9d5be3d56b301758b66 (patch)
tree700eb5bcc1a462a5f21dcec15ce7c97ecfefa772 /package/network/config
downloadtrunk-47381-716ca530e1c4515d8683c9d5be3d56b301758b66.tar.gz
trunk-47381-716ca530e1c4515d8683c9d5be3d56b301758b66.tar.bz2
trunk-47381-716ca530e1c4515d8683c9d5be3d56b301758b66.zip
trunk-47381HEADmaster
Diffstat (limited to 'package/network/config')
-rw-r--r--package/network/config/firewall/Makefile59
-rw-r--r--package/network/config/firewall/files/firewall.config194
-rw-r--r--package/network/config/firewall/files/firewall.hotplug11
-rwxr-xr-xpackage/network/config/firewall/files/firewall.init61
-rw-r--r--package/network/config/firewall/files/firewall.user7
-rw-r--r--package/network/config/gre/Makefile65
-rwxr-xr-xpackage/network/config/gre/files/gre.sh237
-rw-r--r--package/network/config/ipip/Makefile40
-rwxr-xr-xpackage/network/config/ipip/files/ipip.sh80
-rw-r--r--package/network/config/ltq-adsl-app/Makefile84
-rw-r--r--package/network/config/ltq-adsl-app/files/dsl_control59
-rw-r--r--package/network/config/ltq-adsl-app/patches/010-eglibc_compile_fix.patch23
-rw-r--r--package/network/config/ltq-vdsl-app/Makefile78
-rw-r--r--package/network/config/ltq-vdsl-app/files/dsl_control91
-rw-r--r--package/network/config/ltq-vdsl-app/patches/100-compat.patch22
-rw-r--r--package/network/config/ltq-vdsl-app/patches/101-musl.patch10
-rw-r--r--package/network/config/netifd/Makefile46
-rw-r--r--package/network/config/netifd/files/etc/hotplug.d/iface/00-netstate7
-rwxr-xr-xpackage/network/config/netifd/files/etc/init.d/network151
-rwxr-xr-xpackage/network/config/netifd/files/lib/netifd/dhcp.script102
-rwxr-xr-xpackage/network/config/netifd/files/lib/netifd/proto/dhcp.sh74
-rwxr-xr-xpackage/network/config/netifd/files/lib/network/config.sh79
-rwxr-xr-xpackage/network/config/netifd/files/sbin/devstatus12
l---------package/network/config/netifd/files/sbin/ifdown1
-rwxr-xr-xpackage/network/config/netifd/files/sbin/ifstatus13
-rwxr-xr-xpackage/network/config/netifd/files/sbin/ifup79
-rwxr-xr-xpackage/network/config/netifd/files/usr/share/udhcpc/default.script57
-rw-r--r--package/network/config/qos-scripts/Makefile52
-rw-r--r--package/network/config/qos-scripts/files/etc/config/qos68
-rwxr-xr-xpackage/network/config/qos-scripts/files/etc/hotplug.d/iface/10-qos2
-rwxr-xr-xpackage/network/config/qos-scripts/files/etc/init.d/qos28
-rwxr-xr-xpackage/network/config/qos-scripts/files/usr/bin/qos-start4
-rwxr-xr-xpackage/network/config/qos-scripts/files/usr/bin/qos-stat67
-rwxr-xr-xpackage/network/config/qos-scripts/files/usr/bin/qos-stop6
-rwxr-xr-xpackage/network/config/qos-scripts/files/usr/lib/qos/generate.sh499
-rw-r--r--package/network/config/qos-scripts/files/usr/lib/qos/tcrules.awk106
-rw-r--r--package/network/config/soloscli/Makefile45
-rw-r--r--package/network/config/soloscli/files/etc/hotplug.d/atm/15-solos-init26
-rw-r--r--package/network/config/soloscli/files/etc/uci-default/solos15
-rw-r--r--package/network/config/soloscli/files/solos-log-stats19
-rw-r--r--package/network/config/soloscli/patches/001-no-driver.patch11
-rw-r--r--package/network/config/soloscli/patches/002-cflags.patch12
-rw-r--r--package/network/config/swconfig/Makefile60
-rw-r--r--package/network/config/swconfig/files/switch.sh15
-rw-r--r--package/network/config/swconfig/src/Makefile15
-rw-r--r--package/network/config/swconfig/src/cli.c354
-rw-r--r--package/network/config/swconfig/src/swlib.c801
-rw-r--r--package/network/config/swconfig/src/swlib.h252
-rw-r--r--package/network/config/swconfig/src/uci.c246
49 files changed, 4445 insertions, 0 deletions
diff --git a/package/network/config/firewall/Makefile b/package/network/config/firewall/Makefile
new file mode 100644
index 0000000..15cfa31
--- /dev/null
+++ b/package/network/config/firewall/Makefile
@@ -0,0 +1,59 @@
+#
+# Copyright (C) 2013-2015 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=firewall
+PKG_VERSION:=2015-07-27
+PKG_RELEASE:=$(PKG_SOURCE_VERSION)
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=git://nbd.name/firewall3.git
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
+PKG_SOURCE_VERSION:=980b7859bbd1db1e5e46422fccccbce38f9809ab
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
+PKG_MAINTAINER:=Jo-Philipp Wich <jow@openwrt.org>
+PKG_LICENSE:=ISC
+
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+define Package/firewall
+ SECTION:=net
+ CATEGORY:=Base system
+ TITLE:=OpenWrt C Firewall
+ DEPENDS:=+libubox +libubus +libuci +libip4tc +IPV6:libip6tc +libxtables +kmod-ipt-core +kmod-ipt-conntrack +kmod-ipt-nat
+endef
+
+define Package/firewall/description
+ This package provides a config-compatible C implementation of the UCI firewall.
+endef
+
+define Package/firewall/conffiles
+/etc/config/firewall
+/etc/firewall.user
+endef
+
+TARGET_CFLAGS += -ffunction-sections -fdata-sections
+TARGET_LDFLAGS += -Wl,--gc-sections
+CMAKE_OPTIONS += $(if $(CONFIG_IPV6),,-DDISABLE_IPV6=1)
+
+define Package/firewall/install
+ $(INSTALL_DIR) $(1)/sbin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/firewall3 $(1)/sbin/fw3
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/firewall.init $(1)/etc/init.d/firewall
+ $(INSTALL_DIR) $(1)/etc/hotplug.d/iface
+ $(INSTALL_DATA) ./files/firewall.hotplug $(1)/etc/hotplug.d/iface/20-firewall
+ $(INSTALL_DIR) $(1)/etc/config/
+ $(INSTALL_DATA) ./files/firewall.config $(1)/etc/config/firewall
+ $(INSTALL_DIR) $(1)/etc/
+ $(INSTALL_DATA) ./files/firewall.user $(1)/etc/firewall.user
+endef
+
+$(eval $(call BuildPackage,firewall))
diff --git a/package/network/config/firewall/files/firewall.config b/package/network/config/firewall/files/firewall.config
new file mode 100644
index 0000000..749dbec
--- /dev/null
+++ b/package/network/config/firewall/files/firewall.config
@@ -0,0 +1,194 @@
+config defaults
+ option syn_flood 1
+ option input ACCEPT
+ option output ACCEPT
+ option forward REJECT
+# Uncomment this line to disable ipv6 rules
+# option disable_ipv6 1
+
+config zone
+ option name lan
+ list network 'lan'
+ option input ACCEPT
+ option output ACCEPT
+ option forward ACCEPT
+
+config zone
+ option name wan
+ list network 'wan'
+ list network 'wan6'
+ option input REJECT
+ option output ACCEPT
+ option forward REJECT
+ option masq 1
+ option mtu_fix 1
+
+config forwarding
+ option src lan
+ option dest wan
+
+# We need to accept udp packets on port 68,
+# see https://dev.openwrt.org/ticket/4108
+config rule
+ option name Allow-DHCP-Renew
+ option src wan
+ option proto udp
+ option dest_port 68
+ option target ACCEPT
+ option family ipv4
+
+# Allow IPv4 ping
+config rule
+ option name Allow-Ping
+ option src wan
+ option proto icmp
+ option icmp_type echo-request
+ option family ipv4
+ option target ACCEPT
+
+config rule
+ option name Allow-IGMP
+ option src wan
+ option proto igmp
+ option family ipv4
+ option target ACCEPT
+
+# Allow DHCPv6 replies
+# see https://dev.openwrt.org/ticket/10381
+config rule
+ option name Allow-DHCPv6
+ option src wan
+ option proto udp
+ option src_ip fc00::/6
+ option dest_ip fc00::/6
+ option dest_port 546
+ option family ipv6
+ option target ACCEPT
+
+config rule
+ option name Allow-MLD
+ option src wan
+ option proto icmp
+ option src_ip fe80::/10
+ list icmp_type '130/0'
+ list icmp_type '131/0'
+ list icmp_type '132/0'
+ list icmp_type '143/0'
+ option family ipv6
+ option target ACCEPT
+
+# Allow essential incoming IPv6 ICMP traffic
+config rule
+ option name Allow-ICMPv6-Input
+ option src wan
+ option proto icmp
+ list icmp_type echo-request
+ list icmp_type echo-reply
+ list icmp_type destination-unreachable
+ list icmp_type packet-too-big
+ list icmp_type time-exceeded
+ list icmp_type bad-header
+ list icmp_type unknown-header-type
+ list icmp_type router-solicitation
+ list icmp_type neighbour-solicitation
+ list icmp_type router-advertisement
+ list icmp_type neighbour-advertisement
+ option limit 1000/sec
+ option family ipv6
+ option target ACCEPT
+
+# Allow essential forwarded IPv6 ICMP traffic
+config rule
+ option name Allow-ICMPv6-Forward
+ option src wan
+ option dest *
+ option proto icmp
+ list icmp_type echo-request
+ list icmp_type echo-reply
+ list icmp_type destination-unreachable
+ list icmp_type packet-too-big
+ list icmp_type time-exceeded
+ list icmp_type bad-header
+ list icmp_type unknown-header-type
+ option limit 1000/sec
+ option family ipv6
+ option target ACCEPT
+
+# include a file with users custom iptables rules
+config include
+ option path /etc/firewall.user
+
+
+### EXAMPLE CONFIG SECTIONS
+# do not allow a specific ip to access wan
+#config rule
+# option src lan
+# option src_ip 192.168.45.2
+# option dest wan
+# option proto tcp
+# option target REJECT
+
+# block a specific mac on wan
+#config rule
+# option dest wan
+# option src_mac 00:11:22:33:44:66
+# option target REJECT
+
+# block incoming ICMP traffic on a zone
+#config rule
+# option src lan
+# option proto ICMP
+# option target DROP
+
+# port redirect port coming in on wan to lan
+#config redirect
+# option src wan
+# option src_dport 80
+# option dest lan
+# option dest_ip 192.168.16.235
+# option dest_port 80
+# option proto tcp
+
+# port redirect of remapped ssh port (22001) on wan
+#config redirect
+# option src wan
+# option src_dport 22001
+# option dest lan
+# option dest_port 22
+# option proto tcp
+
+# allow IPsec/ESP and ISAKMP passthrough
+config rule
+ option src wan
+ option dest lan
+ option proto esp
+ option target ACCEPT
+
+config rule
+ option src wan
+ option dest lan
+ option dest_port 500
+ option proto udp
+ option target ACCEPT
+
+### FULL CONFIG SECTIONS
+#config rule
+# option src lan
+# option src_ip 192.168.45.2
+# option src_mac 00:11:22:33:44:55
+# option src_port 80
+# option dest wan
+# option dest_ip 194.25.2.129
+# option dest_port 120
+# option proto tcp
+# option target REJECT
+
+#config redirect
+# option src lan
+# option src_ip 192.168.45.2
+# option src_mac 00:11:22:33:44:55
+# option src_port 1024
+# option src_dport 80
+# option dest_ip 194.25.2.129
+# option dest_port 120
+# option proto tcp
diff --git a/package/network/config/firewall/files/firewall.hotplug b/package/network/config/firewall/files/firewall.hotplug
new file mode 100644
index 0000000..f1eab00
--- /dev/null
+++ b/package/network/config/firewall/files/firewall.hotplug
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+[ "$ACTION" = ifup -o "$ACTION" = ifupdate ] || exit 0
+[ "$ACTION" = ifupdate -a -z "$IFUPDATE_ADDRESSES" -a -z "$IFUPDATE_DATA" ] && exit 0
+
+/etc/init.d/firewall enabled || exit 0
+
+fw3 -q network "$INTERFACE" >/dev/null || exit 0
+
+logger -t firewall "Reloading firewall due to $ACTION of $INTERFACE ($DEVICE)"
+fw3 -q reload
diff --git a/package/network/config/firewall/files/firewall.init b/package/network/config/firewall/files/firewall.init
new file mode 100755
index 0000000..ee3ed1a
--- /dev/null
+++ b/package/network/config/firewall/files/firewall.init
@@ -0,0 +1,61 @@
+#!/bin/sh /etc/rc.common
+
+START=19
+USE_PROCD=1
+QUIET=""
+
+validate_firewall_redirect()
+{
+ uci_validate_section firewall redirect "${1}" \
+ 'proto:or(uinteger, string)' \
+ 'src:string' \
+ 'src_ip:cidr' \
+ 'src_dport:or(port, portrange)' \
+ 'dest:string' \
+ 'dest_ip:cidr' \
+ 'dest_port:or(port, portrange)' \
+ 'target:or("SNAT", "DNAT")'
+}
+
+validate_firewall_rule()
+{
+ uci_validate_section firewall rule "${1}" \
+ 'proto:or(uinteger, string)' \
+ 'src:string' \
+ 'dest:string' \
+ 'src_port:or(port, portrange)' \
+ 'dest_port:or(port, portrange)' \
+ 'target:string'
+}
+
+service_triggers() {
+ procd_add_reload_trigger firewall
+
+ procd_open_validate
+ validate_firewall_redirect
+ validate_firewall_rule
+ procd_close_validate
+}
+
+restart() {
+ fw3 restart
+}
+
+start_service() {
+ fw3 ${QUIET} start
+}
+
+stop_service() {
+ fw3 flush
+}
+
+reload_service() {
+ fw3 reload
+}
+
+boot() {
+ # Be silent on boot, firewall might be started by hotplug already,
+ # so don't complain in syslog.
+ QUIET=-q
+ start
+}
diff --git a/package/network/config/firewall/files/firewall.user b/package/network/config/firewall/files/firewall.user
new file mode 100644
index 0000000..6f79906
--- /dev/null
+++ b/package/network/config/firewall/files/firewall.user
@@ -0,0 +1,7 @@
+# This file is interpreted as shell script.
+# Put your custom iptables rules here, they will
+# be executed with each firewall (re-)start.
+
+# Internal uci firewall chains are flushed and recreated on reload, so
+# put custom rules into the root chains e.g. INPUT or FORWARD or into the
+# special user chains, e.g. input_wan_rule or postrouting_lan_rule.
diff --git a/package/network/config/gre/Makefile b/package/network/config/gre/Makefile
new file mode 100644
index 0000000..49e7d19
--- /dev/null
+++ b/package/network/config/gre/Makefile
@@ -0,0 +1,65 @@
+#
+# Copyright (C) 2014 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=gre
+PKG_VERSION:=1
+PKG_RELEASE:=3
+PKG_LICENSE:=GPL-2.0
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/gre/Default
+ SECTION:=net
+ CATEGORY:=Network
+ MAINTAINER:=Hans Dedecker <dedeckeh@gmail.com>
+endef
+
+define Package/gre
+$(call Package/gre/Default)
+ TITLE:=Generic Routing Encapsulation config support
+endef
+
+define Package/gre/description
+ Generic Routing Encapsulation config support (IPv4 and IPv6) in /etc/config/network.
+endef
+
+define Package/grev4
+$(call Package/gre/Default)
+ TITLE:=Generic Routing Encapsulation (IPv4) config support
+ DEPENDS:=@(PACKAGE_gre) +kmod-gre
+endef
+
+define Package/grev4/description
+ Generic Routing Encapsulation config support (IPv4) in /etc/config/network.
+endef
+
+define Package/grev6
+$(call Package/gre/Default)
+ TITLE:=Generic Routing Encapsulation (IPv6) config support
+ DEPENDS:=@(PACKAGE_gre) @IPV6 +kmod-ip6-gre
+endef
+
+define Package/grev6/description
+ Generic Routing Encapsulation config support (IPv6) in /etc/config/network.
+endef
+
+define Build/Compile
+endef
+
+define Build/Configure
+endef
+
+define Package/gre/install
+ $(INSTALL_DIR) $(1)/lib/netifd/proto
+ $(INSTALL_BIN) ./files/gre.sh $(1)/lib/netifd/proto/gre.sh
+endef
+
+$(eval $(call BuildPackage,gre))
+$(eval $(call BuildPackage,grev4))
+$(eval $(call BuildPackage,grev6))
diff --git a/package/network/config/gre/files/gre.sh b/package/network/config/gre/files/gre.sh
new file mode 100755
index 0000000..4483a08
--- /dev/null
+++ b/package/network/config/gre/files/gre.sh
@@ -0,0 +1,237 @@
+#!/bin/sh
+
+[ -n "$INCLUDE_ONLY" ] || {
+ . /lib/functions.sh
+ . /lib/functions/network.sh
+ . ../netifd-proto.sh
+ init_proto "$@"
+}
+
+gre_generic_setup() {
+ local cfg="$1"
+ local mode="$2"
+ local local="$3"
+ local remote="$4"
+ local link="$5"
+ local mtu ttl tos zone ikey okey icsum ocsum iseqno oseqno
+ json_get_vars mtu ttl tos zone ikey okey icsum ocsum iseqno oseqno
+
+ [ -z "$zone" ] && zone="wan"
+
+ proto_init_update "$link" 1
+
+ proto_add_tunnel
+ json_add_string mode "$mode"
+ json_add_int mtu "${mtu:-1280}"
+ [ -n "$df" ] && json_add_boolean df "$df"
+ json_add_int ttl "${ttl:-64}"
+ [ -n "$tos" ] && json_add_string tos "$tos"
+ json_add_string local "$local"
+ json_add_string remote "$remote"
+ [ -n "$tunlink" ] && json_add_string link "$tunlink"
+ json_add_string info "${ikey:-0},${okey:-0},${icsum:-0},${ocsum:-0},${iseqno:-0},${oseqno:-0}"
+ proto_close_tunnel
+
+ proto_add_data
+ [ -n "$zone" ] && json_add_string zone "$zone"
+ proto_close_data
+
+ proto_send_update "$cfg"
+}
+
+gre_setup() {
+ local cfg="$1"
+ local mode="$2"
+
+ local ipaddr peeraddr
+ json_get_vars df ipaddr peeraddr tunlink
+
+ [ -z "$peeraddr" ] && {
+ proto_notify_error "$cfg" "MISSING_ADDRESS"
+ proto_block_restart "$cfg"
+ exit
+ }
+
+ ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
+
+ [ -z "$ipaddr" ] && {
+ local wanif="$tunlink"
+ if [ -z $wanif ] && ! network_find_wan wanif; then
+ proto_notify_error "$cfg" "NO_WAN_LINK"
+ exit
+ fi
+
+ if ! network_get_ipaddr ipaddr "$wanif"; then
+ proto_notify_error "$cfg" "NO_WAN_LINK"
+ exit
+ fi
+ }
+
+ [ -z "$df" ] && df="1"
+
+ gre_generic_setup $cfg $mode $ipaddr $peeraddr "gre-$cfg"
+}
+
+proto_gre_setup() {
+ local cfg="$1"
+
+ gre_setup $cfg "greip"
+}
+
+proto_gretap_setup() {
+ local cfg="$1"
+
+ local network
+ json_get_vars network
+
+ gre_setup $cfg "gretapip"
+
+ json_init
+ json_add_string name "gre-$cfg"
+ json_add_boolean link-ext 0
+ json_close_object
+
+ for i in $network; do
+ ubus call network.interface."$i" add_device "$(json_dump)"
+ done
+}
+
+grev6_setup() {
+ local cfg="$1"
+ local mode="$2"
+
+ local ip6addr peer6addr weakif
+ json_get_vars ip6addr peer6addr tunlink weakif
+
+ [ -z "$peer6addr" ] && {
+ proto_notify_error "$cfg" "MISSING_ADDRESS"
+ proto_block_restart "$cfg"
+ exit
+ }
+
+ ( proto_add_host_dependency "$cfg" "$peer6addr" "$tunlink" )
+
+ [ -z "$ip6addr" ] && {
+ local wanif="$tunlink"
+ if [ -z $wanif ] && ! network_find_wan6 wanif; then
+ proto_notify_error "$cfg" "NO_WAN_LINK"
+ exit
+ fi
+
+ if ! network_get_ipaddr6 ip6addr "$wanif"; then
+ [ -z "$weakif" ] && weakif="lan"
+ if ! network_get_ipaddr6 ip6addr "$weakif"; then
+ proto_notify_error "$cfg" "NO_WAN_LINK"
+ exit
+ fi
+ fi
+ }
+
+ gre_generic_setup $cfg $mode $ip6addr $peer6addr "grev6-$cfg"
+}
+
+proto_grev6_setup() {
+ local cfg="$1"
+
+ grev6_setup $cfg "greip6"
+}
+
+proto_grev6tap_setup() {
+ local cfg="$1"
+
+ local network
+ json_get_vars network
+
+ grev6_setup $cfg "gretapip6"
+
+ json_init
+ json_add_string name "grev6-$cfg"
+ json_add_boolean link-ext 0
+ json_close_object
+
+ for i in $network; do
+ ubus call network.interface."$i" add_device "$(json_dump)"
+ done
+}
+
+gretap_generic_teardown() {
+ local network
+ json_get_vars network
+
+ json_init
+ json_add_string name "$1"
+ json_add_boolean link-ext 0
+ json_close_object
+
+ for i in $network; do
+ ubus call network.interface."$i" remove_device "$(json_dump)"
+ done
+}
+
+proto_gre_teardown() {
+ local cfg="$1"
+}
+
+proto_gretap_teardown() {
+ local cfg="$1"
+
+ gretap_generic_teardown "gre-$cfg"
+}
+
+proto_grev6_teardown() {
+ local cfg="$1"
+}
+
+proto_grev6tap_teardown() {
+ local cfg="$1"
+
+ gretap_generic_teardown "grev6-$cfg"
+}
+
+gre_generic_init_config() {
+ no_device=1
+ available=1
+
+ proto_config_add_int "mtu"
+ proto_config_add_int "ttl"
+ proto_config_add_string "tos"
+ proto_config_add_string "tunlink"
+ proto_config_add_string "zone"
+ proto_config_add_int "ikey"
+ proto_config_add_int "okey"
+ proto_config_add_boolean "icsum"
+ proto_config_add_boolean "ocsum"
+ proto_config_add_boolean "iseqno"
+ proto_config_add_boolean "oseqno"
+}
+
+proto_gre_init_config() {
+ gre_generic_init_config
+ proto_config_add_string "ipaddr"
+ proto_config_add_string "peeraddr"
+ proto_config_add_boolean "df"
+}
+
+proto_gretap_init_config() {
+ proto_gre_init_config
+ proto_config_add_string "network"
+}
+
+proto_grev6_init_config() {
+ gre_generic_init_config
+ proto_config_add_string "ip6addr"
+ proto_config_add_string "peer6addr"
+ proto_config_add_string "weakif"
+}
+
+proto_grev6tap_init_config() {
+ proto_grev6_init_config
+ proto_config_add_string "network"
+}
+
+[ -n "$INCLUDE_ONLY" ] || {
+ [ -f /lib/modules/$(uname -r)/gre.ko ] && add_protocol gre
+ [ -f /lib/modules/$(uname -r)/gre.ko ] && add_protocol gretap
+ [ -f /lib/modules/$(uname -r)/ip6_gre.ko ] && add_protocol grev6
+ [ -f /lib/modules/$(uname -r)/ip6_gre.ko ] && add_protocol grev6tap
+}
diff --git a/package/network/config/ipip/Makefile b/package/network/config/ipip/Makefile
new file mode 100644
index 0000000..5aa722d
--- /dev/null
+++ b/package/network/config/ipip/Makefile
@@ -0,0 +1,40 @@
+#
+# Copyright (C) 2014 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=ipip
+PKG_VERSION:=1
+PKG_RELEASE:=1
+PKG_LICENSE:=GPL-2.0
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/ipip
+ SECTION:=net
+ CATEGORY:=Network
+ MAINTAINER:=Hans Dedecker <dedeckeh@gmail.com>
+ TITLE:=IP in IP Tunnel config support
+ DEPENDS:= +kmod-ipip
+endef
+
+define Package/ipip/description
+ IP in IP Tunnel config support in /etc/config/network.
+endef
+
+define Build/Compile
+endef
+
+define Build/Configure
+endef
+
+define Package/ipip/install
+ $(INSTALL_DIR) $(1)/lib/netifd/proto
+ $(INSTALL_BIN) ./files/ipip.sh $(1)/lib/netifd/proto/ipip.sh
+endef
+
+$(eval $(call BuildPackage,ipip))
diff --git a/package/network/config/ipip/files/ipip.sh b/package/network/config/ipip/files/ipip.sh
new file mode 100755
index 0000000..51c503f
--- /dev/null
+++ b/package/network/config/ipip/files/ipip.sh
@@ -0,0 +1,80 @@
+#!/bin/sh
+
+[ -n "$INCLUDE_ONLY" ] || {
+ . /lib/functions.sh
+ . /lib/functions/network.sh
+ . ../netifd-proto.sh
+ init_proto "$@"
+}
+
+proto_ipip_setup() {
+ local cfg="$1"
+
+ local df ipaddr peeraddr tunlink ttl tos zone mtu
+ json_get_vars df ipaddr peeraddr tunlink ttl tos zone mtu
+
+ [ -z "$peeraddr" ] && {
+ proto_notify_error "$cfg" "MISSING_ADDRESS"
+ proto_block_restart "$cfg"
+ return
+ }
+
+ ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )
+
+ [ -z "$ipaddr" ] && {
+ local wanif="$tunlink"
+ if [ -z $wanif ] && ! network_find_wan wanif; then
+ proto_notify_error "$cfg" "NO_WAN_LINK"
+ return
+ fi
+
+ if ! network_get_ipaddr ipaddr "$wanif"; then
+ proto_notify_error "$cfg" "NO_WAN_LINK"
+ return
+ fi
+ }
+
+ [ -z "$zone" ] && zone="wan"
+
+ proto_init_update "ipip-$cfg" 1
+
+ proto_add_tunnel
+ json_add_string mode "ipip"
+ json_add_int mtu "${mtu:-1280}"
+ json_add_int ttl "${ttl:-64}"
+ [ -n "$tos" ] && json_add_string tos "$tos"
+ json_add_string local "$ipaddr"
+ json_add_string remote "$peeraddr"
+ [ -n "$tunlink" ] && json_add_string link "$tunlink"
+ json_add_boolean df "${df:-1}"
+
+ proto_close_tunnel
+
+ proto_add_data
+ [ -n "$zone" ] && json_add_string zone "$zone"
+ proto_close_data
+
+ proto_send_update "$cfg"
+}
+
+proto_ipip_teardown() {
+ local cfg="$1"
+}
+
+proto_ipip_init_config() {
+ no_device=1
+ available=1
+
+ proto_config_add_int "mtu"
+ proto_config_add_int "ttl"
+ proto_config_add_string "tos"
+ proto_config_add_string "tunlink"
+ proto_config_add_string "zone"
+ proto_config_add_string "ipaddr"
+ proto_config_add_string "peeraddr"
+ proto_config_add_boolean "df"
+}
+
+[ -n "$INCLUDE_ONLY" ] || {
+ add_protocol ipip
+}
diff --git a/package/network/config/ltq-adsl-app/Makefile b/package/network/config/ltq-adsl-app/Makefile
new file mode 100644
index 0000000..9670119
--- /dev/null
+++ b/package/network/config/ltq-adsl-app/Makefile
@@ -0,0 +1,84 @@
+#
+# Copyright (C) 2011-2012 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+include $(INCLUDE_DIR)/kernel.mk
+
+PKG_NAME:=dsl_cpe_control_danube
+PKG_VERSION:=3.24.4.4
+PKG_RELEASE:=2
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_BUILD_DIR:=$(BUILD_DIR)/dsl_cpe_control-$(PKG_VERSION)
+PKG_SOURCE_URL:=http://mirror2.openwrt.org/sources/
+PKG_MD5SUM:=ee315306626b68794d3d3636dabfe161
+PKG_MAINTAINER:=John Crispin <blogic@openwrt.org>
+PKG_LICENSE:=BSD-3-Clause
+
+PKG_FIXUP:=autoreconf
+
+PKG_CONFIG_DEPENDS:=\
+ CONFIG_LTQ_DSL_ENABLE_SOAP \
+ CONFIG_LTQ_DSL_ENABLE_DSL_EVENT_POLLING
+
+PKG_BUILD_DEPENDS:=TARGET_lantiq_xway:kmod-ltq-adsl-danube TARGET_lantiq_ase:kmod-ltq-adsl-ase
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/ltq-adsl-app
+ SECTION:=net
+ CATEGORY:=Network
+ TITLE:=Lantiq DSL userland tool
+ URL:=http://www.lantiq.com/
+ DEPENDS:=@(TARGET_lantiq_xway||TARGET_lantiq_ase) +libpthread
+ MENU:=1
+endef
+
+define Package/ltq-adsl-app/description
+ Infineon DSL CPE API for Amazon SE, Danube and Vinax.
+endef
+
+LTQ_DSL_MAX_DEVICE=1
+LTQ_DSL_LINES_PER_DEVICE=1
+LTQ_DSL_CHANNELS_PER_LINE=1
+
+CONFIGURE_ARGS += \
+ --with-max-device="$(LTQ_DSL_MAX_DEVICE)" \
+ --with-lines-per-device="$(LTQ_DSL_LINES_PER_DEVICE)" \
+ --with-channels-per-line="$(LTQ_DSL_CHANNELS_PER_LINE)" \
+ --enable-danube \
+ --enable-driver-include="-I$(STAGING_DIR)/usr/include/adsl/" \
+ --enable-debug-prints \
+ --enable-add-appl-cflags="-DMAX_CLI_PIPES=2" \
+ --enable-cli-support \
+ --enable-cmv-scripts \
+ --enable-debug-tool-interface \
+ --enable-adsl-led \
+ --enable-dsl-ceoc \
+ --enable-script-notification \
+ --enable-dsl-pm \
+ --enable-dsl-pm-total \
+ --enable-dsl-pm-history \
+ --enable-dsl-pm-showtime \
+ --enable-dsl-pm-channel-counters \
+ --enable-dsl-pm-datapath-counters \
+ --enable-dsl-pm-line-counters \
+ --enable-dsl-pm-channel-thresholds \
+ --enable-dsl-pm-datapath-thresholds \
+ --enable-dsl-pm-line-thresholds \
+ --enable-dsl-pm-optional-parameters
+
+TARGET_CFLAGS += -I$(LINUX_DIR)/include
+
+define Package/ltq-adsl-app/install
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/dsl_control $(1)/etc/init.d/
+
+ $(INSTALL_DIR) $(1)/sbin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/dsl_cpe_control $(1)/sbin
+endef
+
+$(eval $(call BuildPackage,ltq-adsl-app))
diff --git a/package/network/config/ltq-adsl-app/files/dsl_control b/package/network/config/ltq-adsl-app/files/dsl_control
new file mode 100644
index 0000000..cece347
--- /dev/null
+++ b/package/network/config/ltq-adsl-app/files/dsl_control
@@ -0,0 +1,59 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2012 OpenWrt.org
+
+START=99
+
+EXTRA_COMMANDS="status lucistat"
+EXTRA_HELP=" status Get DSL status information
+ lucistat Get status information if lua friendly format"
+
+SERVICE_DAEMONIZE=1
+SERVICE_WRITE_PID=1
+
+[ -f /lib/functions/lantiq_dsl.sh ] && . /lib/functions/lantiq_dsl.sh
+
+annex_b=10_00_10_00_00_04_00_00
+annex_bdmt=10_00_00_00_00_00_00_00
+annex_b2=00_00_10_00_00_00_00_00
+annex_b2p=00_00_00_00_00_04_00_00
+annex_a=04_01_04_00_00_01_00_00
+annex_at1=01_00_00_00_00_00_00_00
+annex_alite=00_01_00_00_00_00_00_00
+annex_admt=04_00_00_00_00_00_00_00
+annex_a2=00_00_04_00_00_00_00_00
+annex_a2p=00_00_00_00_00_01_00_00
+annex_l=00_00_00_00_04_00_00_00
+annex_m=00_00_00_00_40_00_04_00
+annex_m2=00_00_00_00_40_00_00_00
+annex_m2p=00_00_00_00_00_00_04_00
+
+start() {
+ local annex
+ local firmware
+ local xtu
+ config_load network
+ config_get annex dsl annex
+ config_get firmware dsl firmware
+
+ eval "xtu=\"\${annex_$annex}\""
+
+ [ -z "${firmware}" ] &&
+ firmware=/lib/firmware/adsl.bin
+ [ -f "${firmware}" ] || {
+ echo failed to find $firmware
+ return 1
+ }
+
+ service_start /sbin/dsl_cpe_control -i${xtu} \
+ -n /sbin/dsl_notify.sh \
+ -f ${firmware}
+}
+
+stop() {
+ DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
+ DSL_INTERFACE_STATUS="DOWN" \
+ /sbin/dsl_notify.sh
+
+ service_stop /sbin/dsl_cpe_control
+}
+
diff --git a/package/network/config/ltq-adsl-app/patches/010-eglibc_compile_fix.patch b/package/network/config/ltq-adsl-app/patches/010-eglibc_compile_fix.patch
new file mode 100644
index 0000000..268f868
--- /dev/null
+++ b/package/network/config/ltq-adsl-app/patches/010-eglibc_compile_fix.patch
@@ -0,0 +1,23 @@
+--- a/configure.in
++++ b/configure.in
+@@ -29,6 +29,8 @@ AC_C_VOLATILE
+ #AC_FUNC_STRTOD
+ #AC_CHECK_FUNCS([ftime gethostbyname gettimeofday localtime_r memset select socket strchr strerror strstr strtoull])
+
++AC_SEARCH_LIBS([clock_gettime],[rt])
++
+ #
+ # save the configure arguments
+ #
+--- a/src/dsl_cpe_linux.h
++++ b/src/dsl_cpe_linux.h
+@@ -45,7 +45,8 @@
+ #include <arpa/inet.h>
+ #include <sys/socket.h> /* socket */
+ #include <sys/sem.h> /* semget */
+-#include <semaphore.h> /* sem_t */
++#include <semaphore.h> /* sem_t */
++#include <limits.h>
+
+ #ifdef DSL_DEBUG_TOOL_INTERFACE
+ #include <sys/socket.h>
diff --git a/package/network/config/ltq-vdsl-app/Makefile b/package/network/config/ltq-vdsl-app/Makefile
new file mode 100644
index 0000000..061a966
--- /dev/null
+++ b/package/network/config/ltq-vdsl-app/Makefile
@@ -0,0 +1,78 @@
+# Copyright (C) 2010 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+
+include $(TOPDIR)/rules.mk
+include $(INCLUDE_DIR)/kernel.mk
+
+PKG_NAME:=ltq-vdsl-app
+PKG_VERSION:=4.16.2.4
+PKG_RELEASE:=1
+PKG_BASE_NAME:=dsl_cpe_control_vrx
+PKG_SOURCE:=$(PKG_BASE_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://github.com/xdarklight/$(PKG_BASE_NAME)/archive/v$(PKG_VERSION)
+PKG_MD5SUM:=487925ef5327ea38c544035b388de8bb
+PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_BASE_NAME)-$(PKG_VERSION)
+PKG_LICENSE:=BSD-2-Clause
+
+PKG_BUILD_DEPENDS:=kmod-ltq-vdsl-vr9
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/ltq-vdsl-app
+ SECTION:=net
+ CATEGORY:=Network
+ TITLE:=Lantiq VDSL userland tool
+ URL:=http://www.lantiq.com/
+ DEPENDS:=@TARGET_lantiq_xrx200 +libpthread +librt
+endef
+
+define Package/ltq-vdsl-app/description
+ Userland tool needed to control Lantiq VDSL CPE
+endef
+
+CONFIGURE_ARGS += \
+ --with-max-device="1" \
+ --with-lines-per-device="1" \
+ --with-channels-per-line="1" \
+ --enable-vrx \
+ --enable-driver-include="-I$(STAGING_DIR)/usr/include/drv_vdsl_cpe_api" \
+ --enable-device-driver-include="-I$(STAGING_DIR)/usr/include/vdsl/" \
+ --enable-add-appl-cflags="-DMAX_CLI_PIPES=2" \
+ --enable-ifxos \
+ --enable-ifxos-include="-I$(STAGING_DIR)/usr/include/ifxos" \
+ --enable-ifxos-library="-I$(STAGING_DIR)/usr/lib" \
+ --disable-dsl-ceoc \
+ --enable-dsl-pm-total \
+ --enable-dsl-pm-showtime \
+ --enable-dsl-pm-line-counters \
+ --enable-dsl-pm-line-failure-counters \
+ --enable-dsl-pm-datapath-counters \
+ --enable-dsl-pm-datapath-failure-counters \
+ --enable-deprecated \
+ --disable-soap-support \
+ --enable-dsl-bonding=no \
+ --enable-debug-prints=err \
+ --disable-dti
+
+ifeq ($(CONFIG_IFX_CLI),y)
+CONFIGURE_ARGS += \
+ --enable-cli-support
+endif
+
+CONFIGURE_ARGS += --enable-model=full
+#CONFIGURE_ARGS += --enable-model=lite
+#CONFIGURE_ARGS += --enable-model=footprint
+#CONFIGURE_ARGS += --enable-model=typical
+#CONFIGURE_ARGS += --enable-model=debug
+
+define Package/ltq-vdsl-app/install
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/dsl_control $(1)/etc/init.d/
+
+ $(INSTALL_DIR) $(1)/sbin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/dsl_cpe_control $(1)/sbin/vdsl_cpe_control
+endef
+
+$(eval $(call BuildPackage,ltq-vdsl-app))
diff --git a/package/network/config/ltq-vdsl-app/files/dsl_control b/package/network/config/ltq-vdsl-app/files/dsl_control
new file mode 100644
index 0000000..394e1c0
--- /dev/null
+++ b/package/network/config/ltq-vdsl-app/files/dsl_control
@@ -0,0 +1,91 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2012 OpenWrt.org
+
+# needs to start before the atm layer which starts at 50
+START=48
+
+EXTRA_COMMANDS="status lucistat"
+EXTRA_HELP=" status Get DSL status information
+ lucistat Get status information if lua friendly format"
+
+SERVICE_DAEMONIZE=1
+SERVICE_WRITE_PID=1
+
+[ -f /lib/functions/lantiq_dsl.sh ] && . /lib/functions/lantiq_dsl.sh
+
+# G.992.1 Annex A
+# G.992.2 Annex A
+# G.992.3 Annex A
+# G.992.4 Annex A
+# G.992.5 Annex A
+# G.993.2 Annex A/B/C
+xtse_adsl_a="04 01 04 01 00 01 00 00"
+
+# G.992.1 Annex B
+# G.992.3 Annex B
+# G.992.5 Annex B
+# G.993.2 Annex A/B/C
+xtse_adsl_b="10 00 10 00 00 04 00 00"
+
+# G.992.1 Annex B
+# G.992.3 Annex B
+# G.992.3 Annex J
+# G.992.5 Annex B
+# G.992.5 Annex J
+# G.993.2 Annex A/B/C
+xtse_adsl_j="10 00 10 40 00 04 01 00"
+
+xtse_vdsl="00 00 00 00 00 00 00 07"
+
+start() {
+ local annex
+ local firmware
+ local xtse
+ local xtse_adsl
+ local mode
+
+ config_load network
+ config_get annex dsl annex
+ config_get firmware dsl firmware
+ config_get xfer_mode dsl xfer_mode
+
+ [ -z "${xfer_mode}" ] && xfer_mode=ptm
+
+ case "${xfer_mode}" in
+ atm)
+ insmod ltq_atm_vr9
+ mode=1
+ ;;
+ *)
+ insmod ltq_ptm_vr9
+ mode=2
+ ;;
+ esac
+
+ eval "xtse_adsl=\"\${xtse_adsl_$annex}\""
+ if [ "${xtse_adsl}" ]; then
+ xtse=$xtse_adsl
+ else
+ xtse=$xtse_vdsl
+ fi
+
+ [ -z "${firmware}" ] && firmware=/lib/firmware/vdsl.bin
+ [ -f "${firmware}" ] || {
+ echo failed to find $firmware
+ return 1
+ }
+
+ service_start /sbin/vdsl_cpe_control \
+ -i `echo $xtse | sed "s/ /_/g"` \
+ -n /sbin/dsl_notify.sh \
+ -f ${firmware} \
+ -M ${mode}
+}
+
+stop() {
+ DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
+ DSL_INTERFACE_STATUS="DOWN" \
+ /sbin/dsl_notify.sh
+
+ service_stop /sbin/vdsl_cpe_control
+}
diff --git a/package/network/config/ltq-vdsl-app/patches/100-compat.patch b/package/network/config/ltq-vdsl-app/patches/100-compat.patch
new file mode 100644
index 0000000..eeedc54
--- /dev/null
+++ b/package/network/config/ltq-vdsl-app/patches/100-compat.patch
@@ -0,0 +1,22 @@
+--- a/src/dsl_cpe_init_cfg.c
++++ b/src/dsl_cpe_init_cfg.c
+@@ -38,7 +38,7 @@ DSL_InitData_t gInitCfgData =
+ DSL_DEV_HS_TONE_GROUP_CLEANED, \
+ DSL_DEV_HS_TONE_GROUP_CLEANED, \
+ DSL_DEV_HS_TONE_GROUP_CLEANED, \
+- 0x1E116000, 0x37, -1),
++ 0x1E116000, 0x3f, -1),
+ DSL_CPE_SIC_SET(DSL_TC_ATM, DSL_EMF_TC_CLEANED, DSL_EMF_TC_CLEANED, DSL_SYSTEMIF_MII, \
+ DSL_TC_EFM, DSL_EMF_TC_CLEANED, DSL_EMF_TC_CLEANED, DSL_SYSTEMIF_MII),
+ }
+--- a/src/dsl_cpe_control.c
++++ b/src/dsl_cpe_control.c
+@@ -6856,7 +6856,7 @@ DSL_int_t dsl_cpe_daemon (
+ for (nDevice = 0; nDevice < DSL_CPE_MAX_DSL_ENTITIES; nDevice++)
+ {
+ #if defined(INCLUDE_DSL_CPE_API_VRX)
+- sprintf (device, "%s/%d", DSL_CPE_DEVICE_NAME, nDevice);
++ sprintf (device, "%s%d", DSL_CPE_DEVICE_NAME, nDevice);
+ #else
+ sprintf (device, "%s", DSL_CPE_DEVICE_NAME);
+ #endif /* defined(INCLUDE_DSL_CPE_API_VRX)*/
diff --git a/package/network/config/ltq-vdsl-app/patches/101-musl.patch b/package/network/config/ltq-vdsl-app/patches/101-musl.patch
new file mode 100644
index 0000000..9982426
--- /dev/null
+++ b/package/network/config/ltq-vdsl-app/patches/101-musl.patch
@@ -0,0 +1,10 @@
+--- a/src/dsl_cpe_control.c
++++ b/src/dsl_cpe_control.c
+@@ -12,6 +12,7 @@
+ /*
+ Includes
+ */
++#include <limits.h>
+ #include "dsl_cpe_control.h"
+ #include "dsl_cpe_cli.h"
+ #include "dsl_cpe_cli_console.h"
diff --git a/package/network/config/netifd/Makefile b/package/network/config/netifd/Makefile
new file mode 100644
index 0000000..beacd50
--- /dev/null
+++ b/package/network/config/netifd/Makefile
@@ -0,0 +1,46 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=netifd
+PKG_VERSION:=2015-09-27
+PKG_RELEASE=$(PKG_SOURCE_VERSION)
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=http://git.openwrt.org/project/netifd.git
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
+PKG_SOURCE_VERSION:=509ffb22475ebdd5291d510a098f996473951344
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
+PKG_MAINTAINER:=Felix Fietkau <nbd@openwrt.org>
+# PKG_MIRROR_MD5SUM:=
+# CMAKE_INSTALL:=1
+
+PKG_LICENSE:=GPL-2.0
+PKG_LICENSE_FILES:=
+
+PKG_BUILD_PARALLEL:=1
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+define Package/netifd
+ SECTION:=base
+ CATEGORY:=Base system
+ DEPENDS:=+libuci +libnl-tiny +libubus +ubus +ubusd +jshn +libubox
+ TITLE:=OpenWrt Network Interface Configuration Daemon
+endef
+
+TARGET_CFLAGS += \
+ -I$(STAGING_DIR)/usr/include/libnl-tiny \
+ -I$(STAGING_DIR)/usr/include
+
+CMAKE_OPTIONS += \
+ -DLIBNL_LIBS=-lnl-tiny \
+ -DDEBUG=1
+
+define Package/netifd/install
+ $(INSTALL_DIR) $(1)/sbin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/netifd $(1)/sbin/
+ $(CP) ./files/* $(1)/
+ $(CP) $(PKG_BUILD_DIR)/scripts/* $(1)/lib/netifd/
+endef
+
+$(eval $(call BuildPackage,netifd))
diff --git a/package/network/config/netifd/files/etc/hotplug.d/iface/00-netstate b/package/network/config/netifd/files/etc/hotplug.d/iface/00-netstate
new file mode 100644
index 0000000..023025c
--- /dev/null
+++ b/package/network/config/netifd/files/etc/hotplug.d/iface/00-netstate
@@ -0,0 +1,7 @@
+[ ifup = "$ACTION" ] && {
+ uci_toggle_state network "$INTERFACE" up 1
+ [ -n "$DEVICE" ] && {
+ uci_toggle_state network "$INTERFACE" device "$(uci -q get network.$INTERFACE.ifname)"
+ uci_toggle_state network "$INTERFACE" ifname "$DEVICE"
+ }
+}
diff --git a/package/network/config/netifd/files/etc/init.d/network b/package/network/config/netifd/files/etc/init.d/network
new file mode 100755
index 0000000..bdadbbc
--- /dev/null
+++ b/package/network/config/netifd/files/etc/init.d/network
@@ -0,0 +1,151 @@
+#!/bin/sh /etc/rc.common
+
+START=20
+STOP=90
+
+USE_PROCD=1
+
+init_switch() {
+ setup_switch() { return 0; }
+
+ include /lib/network
+ setup_switch
+}
+
+start_service() {
+ init_switch
+
+ procd_open_instance
+ procd_set_param command /sbin/netifd
+ procd_set_param respawn
+ procd_set_param watch network.interface
+ [ -e /proc/sys/kernel/core_pattern ] && {
+ procd_set_param limits core="unlimited"
+ }
+ procd_close_instance
+}
+
+reload_service() {
+ init_switch
+ ubus call network reload
+ /sbin/wifi reload_legacy
+}
+
+stop() {
+ /sbin/wifi down
+ procd_kill network ''
+}
+
+service_running() {
+ ubus -t 30 wait_for network.interface
+ /sbin/wifi reload_legacy
+}
+
+validate_atm_bridge_section()
+{
+ uci_validate_section network "atm-bridge" "${1}" \
+ 'unit:uinteger:0' \
+ 'vci:range(32, 65535):35' \
+ 'vpi:range(0, 255):8' \
+ 'atmdev:uinteger:0' \
+ 'encaps:or("llc", "vc"):llc' \
+ 'payload:or("bridged", "routed"):bridged'
+}
+
+validate_route_section()
+{
+ uci_validate_section network route "${1}" \
+ 'interface:string' \
+ 'target:cidr4' \
+ 'netmask:netmask4' \
+ 'gateway:ip4addr' \
+ 'metric:uinteger' \
+ 'mtu:uinteger' \
+ 'table:or(range(0,65535),string)'
+}
+
+validate_route6_section()
+{
+ uci_validate_section network route6 "${1}" \
+ 'interface:string' \
+ 'target:cidr6' \
+ 'gateway:ip6addr' \
+ 'metric:uinteger' \
+ 'mtu:uinteger' \
+ 'table:or(range(0,65535),string)'
+}
+
+validate_rule_section()
+{
+ uci_validate_section network rule "${1}" \
+ 'in:string' \
+ 'out:string' \
+ 'src:cidr4' \
+ 'dest:cidr4' \
+ 'tos:range(0,31)' \
+ 'mark:string' \
+ 'invert:bool' \
+ 'lookup:or(range(0,65535),string)' \
+ 'goto:range(0,65535)' \
+ 'action:or("prohibit", "unreachable", "blackhole", "throw")'
+}
+
+validate_rule6_section()
+{
+ uci_validate_section network rule6 "${1}" \
+ 'in:string' \
+ 'out:string' \
+ 'src:cidr6' \
+ 'dest:cidr6' \
+ 'tos:range(0,31)' \
+ 'mark:string' \
+ 'invert:bool' \
+ 'lookup:or(range(0,65535),string)' \
+ 'goto:range(0,65535)' \
+ 'action:or("prohibit", "unreachable", "blackhole", "throw")'
+}
+
+validate_switch_section()
+{
+ uci_validate_section network switch "${1}" \
+ 'name:string' \
+ 'enable:bool' \
+ 'enable_vlan:bool' \
+ 'reset:bool'
+}
+
+validate_switch_vlan()
+{
+ uci_validate_section network switch_vlan "${1}" \
+ 'device:string' \
+ 'vlan:uinteger' \
+ 'ports:list(ports)'
+}
+
+service_triggers()
+{
+ procd_add_reload_trigger network wireless
+
+ procd_open_validate
+ validate_atm_bridge_section
+ validate_route_section
+ validate_route6_section
+ validate_rule_section
+ validate_rule6_section
+ validate_switch_section
+ validate_switch_vlan
+ procd_close_validate
+}
+
+restart() {
+ ifdown -a
+ sleep 1
+ trap '' TERM
+ stop "$@"
+ start "$@"
+}
+
+shutdown() {
+ ifdown -a
+ sleep 1
+}
diff --git a/package/network/config/netifd/files/lib/netifd/dhcp.script b/package/network/config/netifd/files/lib/netifd/dhcp.script
new file mode 100755
index 0000000..b3a61e2
--- /dev/null
+++ b/package/network/config/netifd/files/lib/netifd/dhcp.script
@@ -0,0 +1,102 @@
+#!/bin/sh
+[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
+
+. /lib/functions.sh
+. /lib/netifd/netifd-proto.sh
+
+set_classless_routes() {
+ local max=128
+ while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
+ proto_add_ipv4_route "${1%%/*}" "${1##*/}" "$2" "$ip"
+ max=$(($max-1))
+ shift 2
+ done
+}
+
+setup_interface () {
+ proto_init_update "*" 1
+ proto_add_ipv4_address "$ip" "${subnet:-255.255.255.0}"
+ # TODO: apply $broadcast
+
+ for i in $router; do
+ proto_add_ipv4_route "$i" 32 "" "$ip"
+ proto_add_ipv4_route 0.0.0.0 0 "$i" "$ip"
+
+ for r in $CUSTOMROUTES; do
+ proto_add_ipv4_route "${r%%/*}" "${r##*/}" "$i" "$ip"
+ done
+ done
+
+ # CIDR STATIC ROUTES (rfc3442)
+ [ -n "$staticroutes" ] && set_classless_routes $staticroutes
+ [ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
+
+ for dns in $dns; do
+ proto_add_dns_server "$dns"
+ done
+ for domain in $domain; do
+ proto_add_dns_search "$domain"
+ done
+
+ proto_add_data
+ [ -n "$ZONE" ] && json_add_string zone "$ZONE"
+ [ -n "$ntpsrv" ] && json_add_string ntpserver "$ntpsrv"
+ [ -n "$timesvr" ] && json_add_string timeserver "$timesvr"
+ [ -n "$hostname" ] && json_add_string hostname "$hostname"
+ [ -n "$message" ] && json_add_string message "$message"
+ [ -n "$timezone" ] && json_add_int timezone "$timezone"
+ [ -n "$lease" ] && json_add_int leasetime "$lease"
+ proto_close_data
+
+ proto_send_update "$INTERFACE"
+
+
+ if [ "$IFACE6RD" != 0 -a -n "$ip6rd" ]; then
+ local v4mask="${ip6rd%% *}"
+ ip6rd="${ip6rd#* }"
+ local ip6rdprefixlen="${ip6rd%% *}"
+ ip6rd="${ip6rd#* }"
+ local ip6rdprefix="${ip6rd%% *}"
+ ip6rd="${ip6rd#* }"
+ local ip6rdbr="${ip6rd%% *}"
+
+ [ -n "$ZONE" ] || ZONE=$(fw3 -q network $INTERFACE)
+ [ -z "$IFACE6RD" -o "$IFACE6RD" = 1 ] && IFACE6RD=${INTERFACE}_6
+
+ json_init
+ json_add_string name "$IFACE6RD"
+ json_add_string ifname "@$INTERFACE"
+ json_add_string proto "6rd"
+ json_add_string peeraddr "$ip6rdbr"
+ json_add_int ip4prefixlen "$v4mask"
+ json_add_string ip6prefix "$ip6rdprefix"
+ json_add_int ip6prefixlen "$ip6rdprefixlen"
+ json_add_string tunlink "$INTERFACE"
+ [ -n "$IFACE6RD_DELEGATE" ] && json_add_boolean delegate "$IFACE6RD_DELEGATE"
+ [ -n "$ZONE6RD" ] || ZONE6RD=$ZONE
+ [ -n "$ZONE6RD" ] && json_add_string zone "$ZONE6RD"
+ [ -n "$MTU6RD" ] && json_add_string mtu "$MTU6RD"
+ json_close_object
+
+ ubus call network add_dynamic "$(json_dump)"
+ fi
+}
+
+deconfig_interface() {
+ proto_init_update "*" 0
+ proto_send_update "$INTERFACE"
+}
+
+case "$1" in
+ deconfig)
+ deconfig_interface
+ ;;
+ renew|bound)
+ setup_interface
+ ;;
+esac
+
+# user rules
+[ -f /etc/udhcpc.user ] && . /etc/udhcpc.user "$@"
+
+exit 0
diff --git a/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh b/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh
new file mode 100755
index 0000000..0e88af9
--- /dev/null
+++ b/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. ../netifd-proto.sh
+init_proto "$@"
+
+proto_dhcp_init_config() {
+ renew_handler=1
+
+ proto_config_add_string 'ipaddr:ipaddr'
+ proto_config_add_string 'hostname:hostname'
+ proto_config_add_string clientid
+ proto_config_add_string vendorid
+ proto_config_add_boolean 'broadcast:bool'
+ proto_config_add_string 'reqopts:list(string)'
+ proto_config_add_string iface6rd
+ proto_config_add_string sendopts
+ proto_config_add_boolean delegate
+ proto_config_add_string zone6rd
+ proto_config_add_string zone
+ proto_config_add_string mtu6rd
+ proto_config_add_string customroutes
+}
+
+proto_dhcp_setup() {
+ local config="$1"
+ local iface="$2"
+
+ local ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes
+ json_get_vars ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes
+
+ local opt dhcpopts
+ for opt in $reqopts; do
+ append dhcpopts "-O $opt"
+ done
+
+ for opt in $sendopts; do
+ append dhcpopts "-x $opt"
+ done
+
+ [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
+ [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" || clientid="-C"
+ [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
+ [ "$iface6rd" != 0 -a -f /lib/netifd/proto/6rd.sh ] && append dhcpopts "-O 212"
+ [ -n "$zone6rd" ] && proto_export "ZONE6RD=$zone6rd"
+ [ -n "$zone" ] && proto_export "ZONE=$zone"
+ [ -n "$mtu6rd" ] && proto_export "MTU6RD=$mtu6rd"
+ [ -n "$customroutes" ] && proto_export "CUSTOMROUTES=$customroutes"
+ [ "$delegate" = "0" ] && proto_export "IFACE6RD_DELEGATE=0"
+
+ proto_export "INTERFACE=$config"
+ proto_run_command "$config" udhcpc \
+ -p /var/run/udhcpc-$iface.pid \
+ -s /lib/netifd/dhcp.script \
+ -f -t 0 -i "$iface" \
+ ${ipaddr:+-r $ipaddr} \
+ ${hostname:+-H $hostname} \
+ ${vendorid:+-V $vendorid} \
+ $clientid $broadcast $dhcpopts
+}
+
+proto_dhcp_renew() {
+ local interface="$1"
+ # SIGUSR1 forces udhcpc to renew its lease
+ local sigusr1="$(kill -l SIGUSR1)"
+ [ -n "$sigusr1" ] && proto_kill_command "$interface" $sigusr1
+}
+
+proto_dhcp_teardown() {
+ local interface="$1"
+ proto_kill_command "$interface"
+}
+
+add_protocol dhcp
diff --git a/package/network/config/netifd/files/lib/network/config.sh b/package/network/config/netifd/files/lib/network/config.sh
new file mode 100755
index 0000000..9128971
--- /dev/null
+++ b/package/network/config/netifd/files/lib/network/config.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+# Copyright (C) 2011 OpenWrt.org
+
+. /usr/share/libubox/jshn.sh
+
+find_config() {
+ local device="$1"
+ local ifdev ifl3dev ifobj
+ for ifobj in `ubus list network.interface.\*`; do
+ interface="${ifobj##network.interface.}"
+ (
+ json_load "$(ifstatus $interface)"
+ json_get_var ifdev device
+ json_get_var ifl3dev l3_device
+ if [[ "$device" = "$ifdev" ]] || [[ "$device" = "$ifl3dev" ]]; then
+ echo "$interface"
+ exit 0
+ else
+ exit 1
+ fi
+ ) && return
+ done
+}
+
+unbridge() {
+ return
+}
+
+ubus_call() {
+ json_init
+ local _data="$(ubus -S call "$1" "$2")"
+ [ -z "$_data" ] && return 1
+ json_load "$_data"
+ return 0
+}
+
+
+fixup_interface() {
+ local config="$1"
+ local ifname type device l3dev
+
+ config_get type "$config" type
+ config_get ifname "$config" ifname
+ config_get device "$config" device "$ifname"
+ [ "bridge" = "$type" ] && ifname="br-$config"
+ config_set "$config" device "$ifname"
+ ubus_call "network.interface.$config" status || return 0
+ json_get_var l3dev l3_device
+ [ -n "$l3dev" ] && ifname="$l3dev"
+ json_init
+ config_set "$config" ifname "$ifname"
+ config_set "$config" device "$device"
+}
+
+scan_interfaces() {
+ config_load network
+ config_foreach fixup_interface interface
+}
+
+prepare_interface_bridge() {
+ local config="$1"
+
+ [ -n "$config" ] || return 0
+ ubus call network.interface."$config" prepare
+}
+
+setup_interface() {
+ local iface="$1"
+ local config="$2"
+
+ [ -n "$config" ] || return 0
+ ubus call network.interface."$config" add_device "{ \"name\": \"$iface\" }"
+}
+
+do_sysctl() {
+ [ -n "$2" ] && \
+ sysctl -n -e -w "$1=$2" >/dev/null || \
+ sysctl -n -e "$1"
+}
diff --git a/package/network/config/netifd/files/sbin/devstatus b/package/network/config/netifd/files/sbin/devstatus
new file mode 100755
index 0000000..3c35b26
--- /dev/null
+++ b/package/network/config/netifd/files/sbin/devstatus
@@ -0,0 +1,12 @@
+#!/bin/sh
+. /usr/share/libubox/jshn.sh
+DEVICE="$1"
+
+[ -n "$DEVICE" ] || {
+ echo "Usage: $0 <device>"
+ exit 1
+}
+
+json_init
+json_add_string name "$DEVICE"
+ubus call network.device status "$(json_dump)"
diff --git a/package/network/config/netifd/files/sbin/ifdown b/package/network/config/netifd/files/sbin/ifdown
new file mode 120000
index 0000000..a0e5c17
--- /dev/null
+++ b/package/network/config/netifd/files/sbin/ifdown
@@ -0,0 +1 @@
+ifup \ No newline at end of file
diff --git a/package/network/config/netifd/files/sbin/ifstatus b/package/network/config/netifd/files/sbin/ifstatus
new file mode 100755
index 0000000..8a951e6
--- /dev/null
+++ b/package/network/config/netifd/files/sbin/ifstatus
@@ -0,0 +1,13 @@
+#!/bin/sh
+INTERFACE="$1"
+
+[ -n "$INTERFACE" ] || {
+ echo "Usage: $0 <interface>"
+ exit 1
+}
+
+ubus -S list "network.interface.$INTERFACE" >/dev/null || {
+ echo "Interface $INTERFACE not found"
+ exit 1
+}
+ubus call network.interface status "{ \"interface\" : \"$INTERFACE\" }"
diff --git a/package/network/config/netifd/files/sbin/ifup b/package/network/config/netifd/files/sbin/ifup
new file mode 100755
index 0000000..af3aaa8
--- /dev/null
+++ b/package/network/config/netifd/files/sbin/ifup
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+ifup_all=
+setup_wifi=
+
+if_call() {
+ local interface="$1"
+ for mode in $modes; do
+ ubus call network.interface $mode "{ \"interface\" : \"$interface\" }"
+ done
+}
+
+case "$0" in
+ *ifdown) modes=down;;
+ *ifup)
+ modes="down up"
+ setup_wifi=1
+ ;;
+ *) echo "Invalid command: $0";;
+esac
+
+while :; do
+ case "$1" in
+ -a)
+ ifup_all=1
+ shift
+ ;;
+ -w)
+ setup_wifi=
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
+
+[ "$modes" = "down up" ] && ubus call network reload
+if [ -n "$ifup_all" ]; then
+ for interface in `ubus -S list 'network.interface.*'`; do
+ if_call "${interface##network.interface.}"
+ done
+ [ -n "$setup_wifi" ] && /sbin/wifi up
+ exit
+else
+ ubus -S list "network.interface.$1" > /dev/null || {
+ echo "Interface $1 not found"
+ exit
+ }
+ if_call "$1"
+fi
+
+if [ -n "$setup_wifi" ] && grep -sq config /etc/config/wireless; then
+ . /lib/functions.sh
+
+ find_related_radios() {
+ local wdev wnet
+ config_get wdev "$1" device
+ config_get wnet "$1" network
+
+ if [ -n "$wdev" ]; then
+ for wnet in $wnet; do
+ if [ "$wnet" = "$network" ]; then
+ append radio_devs "$wdev" "$N"
+ fi
+ done
+ fi
+ }
+
+ local radio_devs
+ local network="$1"
+ config_load wireless
+ config_foreach find_related_radios wifi-iface
+
+ local dev
+ for dev in $(echo "$radio_devs" | sort -u); do
+ /sbin/wifi up "$dev"
+ done
+fi
diff --git a/package/network/config/netifd/files/usr/share/udhcpc/default.script b/package/network/config/netifd/files/usr/share/udhcpc/default.script
new file mode 100755
index 0000000..ac765a6
--- /dev/null
+++ b/package/network/config/netifd/files/usr/share/udhcpc/default.script
@@ -0,0 +1,57 @@
+#!/bin/sh
+[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
+
+set_classless_routes() {
+ local max=128
+ local type
+ while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
+ [ ${1##*/} -eq 32 ] && type=host || type=net
+ echo "udhcpc: adding route for $type $1 via $2"
+ route add -$type "$1" gw "$2" dev "$interface"
+ max=$(($max-1))
+ shift 2
+ done
+}
+
+setup_interface() {
+ echo "udhcpc: ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}"
+ ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}
+
+ [ -n "$router" ] && [ "$router" != "0.0.0.0" ] && [ "$router" != "255.255.255.255" ] && {
+ echo "udhcpc: setting default routers: $router"
+
+ local valid_gw=""
+ for i in $router ; do
+ route add default gw $i dev $interface
+ valid_gw="${valid_gw:+$valid_gw|}$i"
+ done
+
+ eval $(route -n | awk '
+ /^0.0.0.0\W{9}('$valid_gw')\W/ {next}
+ /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}
+ ')
+ }
+
+ # CIDR STATIC ROUTES (rfc3442)
+ [ -n "$staticroutes" ] && set_classless_routes $staticroutes
+ [ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
+}
+
+
+applied=
+case "$1" in
+ deconfig)
+ ifconfig "$interface" 0.0.0.0
+ ;;
+ renew)
+ setup_interface update
+ ;;
+ bound)
+ setup_interface ifup
+ ;;
+esac
+
+# user rules
+[ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
+
+exit 0
diff --git a/package/network/config/qos-scripts/Makefile b/package/network/config/qos-scripts/Makefile
new file mode 100644
index 0000000..9118c00
--- /dev/null
+++ b/package/network/config/qos-scripts/Makefile
@@ -0,0 +1,52 @@
+#
+# Copyright (C) 2006-2015 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=qos-scripts
+PKG_VERSION:=1.2.1
+PKG_RELEASE:=7
+
+PKG_MAINTAINER:=Felix Fietkau <nbd@openwrt.org>
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/qos-scripts
+ SECTION:=utils
+ CATEGORY:=Base system
+ DEPENDS:=+tc +kmod-sched-core +kmod-sched-connmark +kmod-ifb +iptables +iptables-mod-ipopt +iptables-mod-conntrack-extra
+ TITLE:=QoS scripts
+ PKGARCH:=all
+endef
+
+define Package/qos-scripts/description
+ A set of scripts that abstract QoS configuration into a simple
+ configuration file supporting stanzas that specify any number of QoS
+ entries.
+endef
+
+define Package/qos-scripts/conffiles
+/etc/config/qos
+endef
+
+define Build/Prepare
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+define Package/qos-scripts/install
+ $(INSTALL_DIR) $(1)
+ $(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,qos-scripts))
diff --git a/package/network/config/qos-scripts/files/etc/config/qos b/package/network/config/qos-scripts/files/etc/config/qos
new file mode 100644
index 0000000..44e988a
--- /dev/null
+++ b/package/network/config/qos-scripts/files/etc/config/qos
@@ -0,0 +1,68 @@
+# QoS configuration for OpenWrt
+
+# INTERFACES:
+config interface wan
+ option classgroup "Default"
+ option enabled 0
+ option upload 128
+ option download 1024
+
+# RULES:
+config classify
+ option target "Priority"
+ option ports "22,53"
+ option comment "ssh, dns"
+config classify
+ option target "Normal"
+ option proto "tcp"
+ option ports "20,21,25,80,110,443,993,995"
+ option comment "ftp, smtp, http(s), imap"
+config classify
+ option target "Express"
+ option ports "5190"
+ option comment "AOL, iChat, ICQ"
+config default
+ option target "Express"
+ option proto "udp"
+ option pktsize "-500"
+config reclassify
+ option target "Priority"
+ option proto "icmp"
+config default
+ option target "Bulk"
+ option portrange "1024-65535"
+
+
+# Don't change the stuff below unless you
+# really know what it means :)
+
+config classgroup "Default"
+ option classes "Priority Express Normal Bulk"
+ option default "Normal"
+
+
+config class "Priority"
+ option packetsize 400
+ option avgrate 10
+ option priority 20
+config class "Priority_down"
+ option packetsize 1000
+ option avgrate 10
+
+
+config class "Express"
+ option packetsize 1000
+ option avgrate 50
+ option priority 10
+
+config class "Normal"
+ option packetsize 1500
+ option packetdelay 100
+ option avgrate 10
+ option priority 5
+config class "Normal_down"
+ option avgrate 20
+
+config class "Bulk"
+ option avgrate 1
+ option packetdelay 200
diff --git a/package/network/config/qos-scripts/files/etc/hotplug.d/iface/10-qos b/package/network/config/qos-scripts/files/etc/hotplug.d/iface/10-qos
new file mode 100755
index 0000000..0ced29a
--- /dev/null
+++ b/package/network/config/qos-scripts/files/etc/hotplug.d/iface/10-qos
@@ -0,0 +1,2 @@
+#!/bin/sh
+[ "$ACTION" = ifup ] && /etc/init.d/qos enabled && /usr/lib/qos/generate.sh interface "$INTERFACE" | sh
diff --git a/package/network/config/qos-scripts/files/etc/init.d/qos b/package/network/config/qos-scripts/files/etc/init.d/qos
new file mode 100755
index 0000000..712d906
--- /dev/null
+++ b/package/network/config/qos-scripts/files/etc/init.d/qos
@@ -0,0 +1,28 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006 OpenWrt.org
+
+START=50
+USE_PROCD=1
+
+validate_qos_section()
+{
+ uci_validate_section qos interface "${1}" \
+ 'enabled:bool' \
+ 'upload:uinteger' \
+ 'download:uinteger'
+}
+
+service_triggers()
+{
+ procd_add_reload_trigger "qos"
+ procd_add_validation validate_qos_section
+ qos-start
+}
+
+start_service() {
+ qos-start
+}
+
+reload_service() {
+ qos-start
+}
diff --git a/package/network/config/qos-scripts/files/usr/bin/qos-start b/package/network/config/qos-scripts/files/usr/bin/qos-start
new file mode 100755
index 0000000..261ffb4
--- /dev/null
+++ b/package/network/config/qos-scripts/files/usr/bin/qos-start
@@ -0,0 +1,4 @@
+#!/bin/sh
+qos-stop
+/usr/lib/qos/generate.sh all | sh
+
diff --git a/package/network/config/qos-scripts/files/usr/bin/qos-stat b/package/network/config/qos-scripts/files/usr/bin/qos-stat
new file mode 100755
index 0000000..cbbf8e8
--- /dev/null
+++ b/package/network/config/qos-scripts/files/usr/bin/qos-stat
@@ -0,0 +1,67 @@
+#!/bin/sh
+# Copyright (C) 2011 OpenWrt.org
+
+. /lib/functions.sh
+
+include /lib/network
+
+get_ifname() {
+ local interface="$1"
+ local cfgt
+
+ scan_interfaces
+ config_get cfgt "$interface" TYPE
+ [ "$cfgt" = "interface" ] && config_get "$interface" ifname
+}
+
+config_cb() {
+ config_get TYPE "$CONFIG_SECTION" TYPE
+ [ "interface" = "$TYPE" ] && {
+ config_get device "$CONFIG_SECTION" ifname
+ [ -z "$device" ] && device="$(get_ifname ${CONFIG_SECTION})"
+ config_set "$CONFIG_SECTION" device "$device"
+ }
+}
+
+config_load qos
+
+print_comments() {
+ echo ''
+ echo '# Interface: '"$1"
+ echo '# Direction: '"$2"
+ echo '# Stats: '"$3"
+ echo ''
+}
+
+get_device() {
+ ( config_load network; scan_interfaces; config_get "$1" ifname )
+}
+
+interface_stats() {
+ local interface="$1"
+ local device
+
+ device="$(get_device "$interface")"
+ [ -z "$device" ] && config_get device "$interface" device
+ config_get_bool enabled "$interface" enabled 1
+ [ -z "$device" -o 1 -ne "$enabled" ] && {
+ return 1
+ }
+ config_get_bool halfduplex "$interface" halfduplex 0
+
+ if [ 1 -ne "$halfduplex" ]; then
+ unset halfduplex
+ print_comments "$interface" "Egress" "Start"
+ tc -s class show dev "$device"
+ print_comments "$interface" "Egress" "End"
+ id="root"
+ else
+ id=""
+ fi
+
+ print_comments "$interface" "Ingress${halfduplex:+/Egress}" "Start"
+ tc -s class show dev "$(tc filter show dev $device $id | grep mirred | sed -e 's,.*\(ifb.*\)).*,\1,')"
+ print_comments "$interface" "Ingress${halfduplex:+/Egress}" "End"
+}
+
+[ -z "$1" ] && config_foreach interface_stats interface || interface_stats "$1"
diff --git a/package/network/config/qos-scripts/files/usr/bin/qos-stop b/package/network/config/qos-scripts/files/usr/bin/qos-stop
new file mode 100755
index 0000000..7f654d8
--- /dev/null
+++ b/package/network/config/qos-scripts/files/usr/bin/qos-stop
@@ -0,0 +1,6 @@
+#!/bin/sh
+for iface in $(tc qdisc show | grep -E '(hfsc|ingress)' | awk '{print $5}'); do
+ tc qdisc del dev "$iface" ingress 2>&- >&-
+ tc qdisc del dev "$iface" root 2>&- >&-
+done
+/usr/lib/qos/generate.sh firewall stop | sh
diff --git a/package/network/config/qos-scripts/files/usr/lib/qos/generate.sh b/package/network/config/qos-scripts/files/usr/lib/qos/generate.sh
new file mode 100755
index 0000000..01f9b6b
--- /dev/null
+++ b/package/network/config/qos-scripts/files/usr/lib/qos/generate.sh
@@ -0,0 +1,499 @@
+#!/bin/sh
+[ -e /lib/functions.sh ] && . /lib/functions.sh || . ./functions.sh
+[ -x /sbin/modprobe ] && {
+ insmod="modprobe"
+ rmmod="$insmod -r"
+} || {
+ insmod="insmod"
+ rmmod="rmmod"
+}
+
+add_insmod() {
+ eval "export isset=\${insmod_$1}"
+ case "$isset" in
+ 1) ;;
+ *) {
+ [ "$2" ] && append INSMOD "$rmmod $1 >&- 2>&-" "$N"
+ append INSMOD "$insmod $* >&- 2>&-" "$N"; export insmod_$1=1
+ };;
+ esac
+}
+
+[ -e /etc/config/network ] && {
+ # only try to parse network config on openwrt
+
+ find_ifname() {(
+ reset_cb
+ include /lib/network
+ scan_interfaces
+ config_get "$1" ifname
+ )}
+} || {
+ find_ifname() {
+ echo "Interface not found."
+ exit 1
+ }
+}
+
+parse_matching_rule() {
+ local var="$1"
+ local section="$2"
+ local options="$3"
+ local prefix="$4"
+ local suffix="$5"
+ local proto="$6"
+ local mport=""
+ local ports=""
+
+ append "$var" "$prefix" "$N"
+ for option in $options; do
+ case "$option" in
+ proto) config_get value "$section" proto; proto="${proto:-$value}";;
+ esac
+ done
+ config_get type "$section" TYPE
+ case "$type" in
+ classify) unset pkt; append "$var" "-m mark --mark 0/0x0f";;
+ default) pkt=1; append "$var" "-m mark --mark 0/0xf0";;
+ reclassify) pkt=1;;
+ esac
+ append "$var" "${proto:+-p $proto}"
+ for option in $options; do
+ config_get value "$section" "$option"
+
+ case "$pkt:$option" in
+ *:srchost)
+ append "$var" "-s $value"
+ ;;
+ *:dsthost)
+ append "$var" "-d $value"
+ ;;
+ *:ports|*:srcports|*:dstports)
+ value="$(echo "$value" | sed -e 's,-,:,g')"
+ lproto=${lproto:-tcp}
+ case "$proto" in
+ ""|tcp|udp) append "$var" "-m ${proto:-tcp -p tcp} -m multiport";;
+ *) unset "$var"; return 0;;
+ esac
+ case "$option" in
+ ports)
+ config_set "$section" srcports ""
+ config_set "$section" dstports ""
+ config_set "$section" portrange ""
+ append "$var" "--ports $value"
+ ;;
+ srcports)
+ config_set "$section" ports ""
+ config_set "$section" dstports ""
+ config_set "$section" portrange ""
+ append "$var" "--sports $value"
+ ;;
+ dstports)
+ config_set "$section" ports ""
+ config_set "$section" srcports ""
+ config_set "$section" portrange ""
+ append "$var" "--dports $value"
+ ;;
+ esac
+ ports=1
+ ;;
+ *:portrange)
+ config_set "$section" ports ""
+ config_set "$section" srcports ""
+ config_set "$section" dstports ""
+ value="$(echo "$value" | sed -e 's,-,:,g')"
+ case "$proto" in
+ ""|tcp|udp) append "$var" "-m ${proto:-tcp -p tcp} --sport $value --dport $value";;
+ *) unset "$var"; return 0;;
+ esac
+ ports=1
+ ;;
+ *:connbytes)
+ value="$(echo "$value" | sed -e 's,-,:,g')"
+ add_insmod xt_connbytes
+ append "$var" "-m connbytes --connbytes $value --connbytes-dir both --connbytes-mode bytes"
+ ;;
+ *:comment)
+ add_insmod xt_comment
+ append "$var" "-m comment --comment '$value'"
+ ;;
+ *:tos)
+ add_insmod xt_dscp
+ case "$value" in
+ !*) append "$var" "-m tos ! --tos $value";;
+ *) append "$var" "-m tos --tos $value"
+ esac
+ ;;
+ *:dscp)
+ add_insmod xt_dscp
+ dscp_option="--dscp"
+ [ -z "${value%%[EBCA]*}" ] && dscp_option="--dscp-class"
+ case "$value" in
+ !*) append "$var" "-m dscp ! $dscp_option $value";;
+ *) append "$var" "-m dscp $dscp_option $value"
+ esac
+ ;;
+ *:direction)
+ value="$(echo "$value" | sed -e 's,-,:,g')"
+ if [ "$value" = "out" ]; then
+ append "$var" "-o $device"
+ elif [ "$value" = "in" ]; then
+ append "$var" "-i $device"
+ fi
+ ;;
+ 1:pktsize)
+ value="$(echo "$value" | sed -e 's,-,:,g')"
+ add_insmod xt_length
+ append "$var" "-m length --length $value"
+ ;;
+ 1:limit)
+ add_insmod xt_limit
+ append "$var" "-m limit --limit $value"
+ ;;
+ 1:tcpflags)
+ case "$proto" in
+ tcp) append "$var" "-m tcp --tcp-flags ALL $value";;
+ *) unset $var; return 0;;
+ esac
+ ;;
+ 1:mark)
+ config_get class "${value##!}" classnr
+ [ -z "$class" ] && continue;
+ case "$value" in
+ !*) append "$var" "-m mark ! --mark $class/0x0f";;
+ *) append "$var" "-m mark --mark $class/0x0f";;
+ esac
+ ;;
+ 1:TOS)
+ add_insmod xt_DSCP
+ config_get TOS "$rule" 'TOS'
+ suffix="-j TOS --set-tos "${TOS:-"Normal-Service"}
+ ;;
+ 1:DSCP)
+ add_insmod xt_DSCP
+ config_get DSCP "$rule" 'DSCP'
+ [ -z "${DSCP%%[EBCA]*}" ] && set_value="--set-dscp-class $DSCP" \
+ || set_value="--set-dscp $DSCP"
+ suffix="-j DSCP $set_value"
+ ;;
+ esac
+ done
+ append "$var" "$suffix"
+ case "$ports:$proto" in
+ 1:) parse_matching_rule "$var" "$section" "$options" "$prefix" "$suffix" "udp";;
+ esac
+}
+
+config_cb() {
+ option_cb() {
+ return 0
+ }
+
+ # Section start
+ case "$1" in
+ interface)
+ config_set "$2" "classgroup" "Default"
+ config_set "$2" "upload" "128"
+ ;;
+ classify|default|reclassify)
+ option_cb() {
+ append options "$1"
+ }
+ ;;
+ esac
+
+ # Section end
+ config_get TYPE "$CONFIG_SECTION" TYPE
+ case "$TYPE" in
+ interface)
+ config_get_bool enabled "$CONFIG_SECTION" enabled 1
+ [ 1 -eq "$enabled" ] || return 0
+ config_get classgroup "$CONFIG_SECTION" classgroup
+ config_set "$CONFIG_SECTION" ifbdev "$C"
+ C=$(($C+1))
+ append INTERFACES "$CONFIG_SECTION"
+ config_set "$classgroup" enabled 1
+ config_get device "$CONFIG_SECTION" device
+ [ -z "$device" ] && {
+ device="$(find_ifname ${CONFIG_SECTION})"
+ config_set "$CONFIG_SECTION" device "${device:-eth0}"
+ }
+ ;;
+ classgroup) append CG "$CONFIG_SECTION";;
+ classify|default|reclassify)
+ case "$TYPE" in
+ classify) var="ctrules";;
+ *) var="rules";;
+ esac
+ config_get target "$CONFIG_SECTION" target
+ config_set "$CONFIG_SECTION" options "$options"
+ append "$var" "$CONFIG_SECTION"
+ unset options
+ ;;
+ esac
+}
+
+
+enum_classes() {
+ local c="0"
+ config_get classes "$1" classes
+ config_get default "$1" default
+ for class in $classes; do
+ c="$(($c + 1))"
+ config_set "${class}" classnr $c
+ case "$class" in
+ $default) class_default=$c;;
+ esac
+ done
+ class_default="${class_default:-$c}"
+}
+
+cls_var() {
+ local varname="$1"
+ local class="$2"
+ local name="$3"
+ local type="$4"
+ local default="$5"
+ local tmp tmp1 tmp2
+ config_get tmp1 "$class" "$name"
+ config_get tmp2 "${class}_${type}" "$name"
+ tmp="${tmp2:-$tmp1}"
+ tmp="${tmp:-$tmp2}"
+ export ${varname}="${tmp:-$default}"
+}
+
+tcrules() {
+ _dir=/usr/lib/qos
+ [ -e $_dir/tcrules.awk ] || _dir=.
+ echo "$cstr" | awk \
+ -v device="$dev" \
+ -v linespeed="$rate" \
+ -v direction="$dir" \
+ -f $_dir/tcrules.awk
+}
+
+start_interface() {
+ local iface="$1"
+ local num_ifb="$2"
+ config_get device "$iface" device
+ config_get_bool enabled "$iface" enabled 1
+ [ -z "$device" -o 1 -ne "$enabled" ] && {
+ return 1
+ }
+ config_get upload "$iface" upload
+ config_get_bool halfduplex "$iface" halfduplex
+ config_get download "$iface" download
+ config_get classgroup "$iface" classgroup
+ config_get_bool overhead "$iface" overhead 0
+
+ download="${download:-${halfduplex:+$upload}}"
+ enum_classes "$classgroup"
+ for dir in ${halfduplex:-up} ${download:+down}; do
+ case "$dir" in
+ up)
+ [ "$overhead" = 1 ] && upload=$(($upload * 98 / 100 - (15 * 128 / $upload)))
+ dev="$device"
+ rate="$upload"
+ dl_mode=""
+ prefix="cls"
+ ;;
+ down)
+ [ "$(ls -d /proc/sys/net/ipv4/conf/ifb* 2>&- | wc -l)" -ne "$num_ifb" ] && add_insmod ifb numifbs="$num_ifb"
+ config_get ifbdev "$iface" ifbdev
+ [ "$overhead" = 1 ] && download=$(($download * 98 / 100 - (80 * 1024 / $download)))
+ dev="ifb$ifbdev"
+ rate="$download"
+ dl_mode=1
+ prefix="d_cls"
+ ;;
+ *) continue;;
+ esac
+ cstr=
+ for class in $classes; do
+ cls_var pktsize "$class" packetsize $dir 1500
+ cls_var pktdelay "$class" packetdelay $dir 0
+ cls_var maxrate "$class" limitrate $dir 100
+ cls_var prio "$class" priority $dir 1
+ cls_var avgrate "$class" avgrate $dir 0
+ cls_var qdisc "$class" qdisc $dir ""
+ cls_var filter "$class" filter $dir ""
+ config_get classnr "$class" classnr
+ append cstr "$classnr:$prio:$avgrate:$pktsize:$pktdelay:$maxrate:$qdisc:$filter" "$N"
+ done
+ append ${prefix}q "$(tcrules)" "$N"
+ export dev_${dir}="ifconfig $dev up txqueuelen 5 >&- 2>&-
+tc qdisc del dev $dev root >&- 2>&-
+tc qdisc add dev $dev root handle 1: hfsc default ${class_default}0
+tc class add dev $dev parent 1: classid 1:1 hfsc sc rate ${rate}kbit ul rate ${rate}kbit"
+ done
+ [ -n "$download" ] && {
+ add_insmod cls_u32
+ add_insmod em_u32
+ add_insmod act_connmark
+ add_insmod act_mirred
+ add_insmod sch_ingress
+ }
+ if [ -n "$halfduplex" ]; then
+ export dev_up="tc qdisc del dev $device root >&- 2>&-
+tc qdisc add dev $device root handle 1: hfsc
+tc filter add dev $device parent 1: protocol ip prio 10 u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb$ifbdev"
+ elif [ -n "$download" ]; then
+ append dev_${dir} "tc qdisc del dev $device ingress >&- 2>&-
+tc qdisc add dev $device ingress
+tc filter add dev $device parent ffff: protocol ip prio 1 u32 match u32 0 0 flowid 1:1 action connmark action mirred egress redirect dev ifb$ifbdev" "$N"
+ fi
+ add_insmod cls_fw
+ add_insmod sch_hfsc
+ add_insmod sch_fq_codel
+
+ cat <<EOF
+${INSMOD:+$INSMOD$N}${dev_up:+$dev_up
+$clsq
+}${ifbdev:+$dev_down
+$d_clsq
+$d_clsl
+$d_clsf
+}
+EOF
+ unset INSMOD clsq clsf clsl d_clsq d_clsl d_clsf dev_up dev_down
+}
+
+start_interfaces() {
+ local C="$1"
+ for iface in $INTERFACES; do
+ start_interface "$iface" "$C"
+ done
+}
+
+add_rules() {
+ local var="$1"
+ local rules="$2"
+ local prefix="$3"
+
+ for rule in $rules; do
+ unset iptrule
+ config_get target "$rule" target
+ config_get target "$target" classnr
+ config_get options "$rule" options
+
+ ## If we want to override the TOS field, let's clear the DSCP field first.
+ [ ! -z "$(echo $options | grep 'TOS')" ] && {
+ s_options=${options%%TOS}
+ add_insmod xt_DSCP
+ parse_matching_rule iptrule "$rule" "$s_options" "$prefix" "-j DSCP --set-dscp 0"
+ append "$var" "$iptrule" "$N"
+ unset iptrule
+ }
+
+ target=$(($target | ($target << 4)))
+ parse_matching_rule iptrule "$rule" "$options" "$prefix" "-j MARK --set-mark $target/0xff"
+ append "$var" "$iptrule" "$N"
+ done
+}
+
+start_cg() {
+ local cg="$1"
+ local iptrules
+ local pktrules
+ local sizerules
+ enum_classes "$cg"
+ add_rules iptrules "$ctrules" "iptables -t mangle -A qos_${cg}_ct"
+ config_get classes "$cg" classes
+ for class in $classes; do
+ config_get mark "$class" classnr
+ config_get maxsize "$class" maxsize
+ [ -z "$maxsize" -o -z "$mark" ] || {
+ add_insmod xt_length
+ append pktrules "iptables -t mangle -A qos_${cg} -m mark --mark $mark/0x0f -m length --length $maxsize: -j MARK --set-mark 0/0xff" "$N"
+ }
+ done
+ add_rules pktrules "$rules" "iptables -t mangle -A qos_${cg}"
+ for iface in $INTERFACES; do
+ config_get classgroup "$iface" classgroup
+ config_get device "$iface" device
+ config_get ifbdev "$iface" ifbdev
+ config_get upload "$iface" upload
+ config_get download "$iface" download
+ config_get halfduplex "$iface" halfduplex
+ download="${download:-${halfduplex:+$upload}}"
+ append up "iptables -t mangle -A OUTPUT -o $device -j qos_${cg}" "$N"
+ append up "iptables -t mangle -A FORWARD -o $device -j qos_${cg}" "$N"
+ done
+ cat <<EOF
+$INSMOD
+iptables -t mangle -N qos_${cg} >&- 2>&-
+iptables -t mangle -N qos_${cg}_ct >&- 2>&-
+${iptrules:+${iptrules}${N}iptables -t mangle -A qos_${cg}_ct -j CONNMARK --save-mark --mask 0xff}
+iptables -t mangle -A qos_${cg} -j CONNMARK --restore-mark --mask 0x0f
+iptables -t mangle -A qos_${cg} -m mark --mark 0/0x0f -j qos_${cg}_ct
+$pktrules
+${iptrules:+${iptrules}${N}iptables -t mangle -A qos_${cg} -j CONNMARK --save-mark --mask 0xf0}
+$up$N${down:+${down}$N}
+EOF
+ unset INSMOD
+}
+
+start_firewall() {
+ add_insmod xt_multiport
+ add_insmod xt_CONNMARK
+ stop_firewall
+ for group in $CG; do
+ start_cg $group
+ done
+}
+
+stop_firewall() {
+ # Builds up a list of iptables commands to flush the qos_* chains,
+ # remove rules referring to them, then delete them
+
+ # Print rules in the mangle table, like iptables-save
+ iptables -t mangle -S |
+ # Find rules for the qos_* chains
+ grep '^-N qos_\|-j qos_' |
+ # Exclude rules in qos_* chains (inter-qos_* refs)
+ grep -v '^-A qos_' |
+ # Replace -N with -X and hold, with -F and print
+ # Replace -A with -D
+ # Print held lines at the end (note leading newline)
+ sed -e '/^-N/{s/^-N/-X/;H;s/^-X/-F/}' \
+ -e 's/^-A/-D/' \
+ -e '${p;g}' |
+ # Make into proper iptables calls
+ # Note: awkward in previous call due to hold space usage
+ sed -n -e 's/^./iptables -t mangle &/p'
+}
+
+C="0"
+INTERFACES=""
+[ -e ./qos.conf ] && {
+ . ./qos.conf
+ config_cb
+} || config_load qos
+
+C="0"
+for iface in $INTERFACES; do
+ export C="$(($C + 1))"
+done
+
+case "$1" in
+ all)
+ start_interfaces "$C"
+ start_firewall
+ ;;
+ interface)
+ start_interface "$2" "$C"
+ ;;
+ interfaces)
+ start_interfaces
+ ;;
+ firewall)
+ case "$2" in
+ stop)
+ stop_firewall
+ ;;
+ start|"")
+ start_firewall
+ ;;
+ esac
+ ;;
+esac
diff --git a/package/network/config/qos-scripts/files/usr/lib/qos/tcrules.awk b/package/network/config/qos-scripts/files/usr/lib/qos/tcrules.awk
new file mode 100644
index 0000000..12f94a6
--- /dev/null
+++ b/package/network/config/qos-scripts/files/usr/lib/qos/tcrules.awk
@@ -0,0 +1,106 @@
+BEGIN {
+ dmax=100
+ if (!(linespeed > 0)) linespeed = 128
+ FS=":"
+ n = 0
+}
+
+($1 != "") {
+ n++
+ class[n] = $1
+ prio[n] = $2
+ avgrate[n] = ($3 * linespeed / 100)
+ pktsize[n] = $4
+ delay[n] = $5
+ maxrate[n] = ($6 * linespeed / 100)
+ qdisc[n] = $7
+ filter[n] = $8
+}
+
+END {
+ allocated = 0
+ maxdelay = 0
+
+ for (i = 1; i <= n; i++) {
+ # set defaults
+ if (!(pktsize[i] > 0)) pktsize[i] = 1500
+ if (!(prio[i] > 0)) prio[i] = 1
+
+ allocated += avgrate[i]
+ sum_prio += prio[i]
+ if ((avgrate[i] > 0) && !(delay[i] > 0)) {
+ sum_rtprio += prio[i]
+ }
+ }
+
+ # allocation of m1 in rt classes:
+ # sum(d * m1) must not exceed dmax * (linespeed - allocated)
+ dmax = 0
+ for (i = 1; i <= n; i++) {
+ if (avgrate[i] > 0) {
+ rtm2[i] = avgrate[i]
+ if (delay[i] > 0) {
+ d[i] = delay[i]
+ } else {
+ d[i] = 2 * pktsize[i] * 1000 / (linespeed * 1024)
+ if (d[i] > dmax) dmax = d[i]
+ }
+ }
+ }
+
+ ds_avail = dmax * (linespeed - allocated)
+ for (i = 1; i <= n; i++) {
+ lsm1[i] = 0
+ rtm1[i] = 0
+ lsm2[i] = linespeed * prio[i] / sum_prio
+ if ((avgrate[i] > 0) && (d[i] > 0)) {
+ if (!(delay[i] > 0)) {
+ ds = ds_avail * prio[i] / sum_rtprio
+ ds_avail -= ds
+ rtm1[i] = rtm2[i] + ds/d[i]
+ }
+ lsm1[i] = rtm1[i]
+ }
+ else {
+ d[i] = 0
+ }
+ }
+
+ # main qdisc
+ for (i = 1; i <= n; i++) {
+ printf "tc class add dev "device" parent 1:1 classid 1:"class[i]"0 hfsc"
+ if (rtm1[i] > 0) {
+ printf " rt m1 " int(rtm1[i]) "kbit d " int(d[i] * 1000) "us m2 " int(rtm2[i])"kbit"
+ }
+ printf " ls m1 " int(lsm1[i]) "kbit d " int(d[i] * 1000) "us m2 " int(lsm2[i]) "kbit"
+ print " ul rate " int(maxrate[i]) "kbit"
+ }
+
+ # leaf qdisc
+ avpkt = 1200
+ for (i = 1; i <= n; i++) {
+ print "tc qdisc add dev "device" parent 1:"class[i]"0 handle "class[i]"00: fq_codel limit 800 quantum 300 noecn"
+ }
+
+ # filter rule
+ for (i = 1; i <= n; i++) {
+ filter_cmd = "tc filter add dev "device" parent 1: prio %d protocol ip handle %s fw flowid 1:%d0\n";
+ if (direction == "up") {
+ filter_1 = sprintf("0x%x0/0xf0", class[i])
+ filter_2 = sprintf("0x0%x/0x0f", class[i])
+ } else {
+ filter_1 = sprintf("0x0%x/0x0f", class[i])
+ filter_2 = sprintf("0x%x0/0xf0", class[i])
+ }
+
+ printf filter_cmd, class[i] * 2, filter_1, class[i]
+ printf filter_cmd, class[i] * 2 + 1, filter_2, class[i]
+
+ filterc=1
+ if (filter[i] != "") {
+ print " tc filter add dev "device" parent "class[i]"00: handle "filterc"0 "filter[i]
+ filterc=filterc+1
+ }
+ }
+}
+
diff --git a/package/network/config/soloscli/Makefile b/package/network/config/soloscli/Makefile
new file mode 100644
index 0000000..12bc15e
--- /dev/null
+++ b/package/network/config/soloscli/Makefile
@@ -0,0 +1,45 @@
+#
+# Copyright (C) 2006-2014 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=soloscli
+PKG_VERSION:=1.04
+PKG_RELEASE:=1
+
+PKG_SOURCE:=solos-pci-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=@SF/openadsl
+PKG_MD5SUM:=c398866de3c059b14eb953c89d698124
+PKG_LICENSE:=GPL-2.0
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/solos-pci-$(PKG_VERSION)
+PKG_BUILD_PARALLEL:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/soloscli
+ SECTION:=net
+ CATEGORY:=Network
+ TITLE:=Configuration utility for Solos ADSL2+ modems
+ DEPENDS:=+kmod-solos-pci
+ URL:=http://sourceforge.net/projects/openadsl
+endef
+
+define Package/soloscli/description
+ This package contains the soloscli utility
+ for interrogating Traverse Technologies' Solos ADSL2+ modems.
+endef
+
+define Package/soloscli/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/soloscli/soloscli $(1)/usr/bin/
+ $(INSTALL_BIN) ./files/solos-log-stats $(1)/usr/bin/
+ $(INSTALL_DIR) $(1)/etc/hotplug.d/atm
+ $(INSTALL_DATA) ./files/etc/hotplug.d/atm/15-solos-init $(1)/etc/hotplug.d/atm/
+endef
+
+$(eval $(call BuildPackage,soloscli))
diff --git a/package/network/config/soloscli/files/etc/hotplug.d/atm/15-solos-init b/package/network/config/soloscli/files/etc/hotplug.d/atm/15-solos-init
new file mode 100644
index 0000000..36d13ea
--- /dev/null
+++ b/package/network/config/soloscli/files/etc/hotplug.d/atm/15-solos-init
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+dialog() {
+ local tag="$(echo "$1" | cut -d= -f1)"
+ local value="$(echo "$1" | cut -d= -f2-)"
+ local response
+
+ response="$(soloscli -s "$port" "$tag" "$value")"
+ [ $? -ne 0 ] && {
+ logger "soloscli($port): $tag '$value' returns $response"
+ }
+}
+
+if [ "$ACTION" = "add" ]; then
+ include /lib/network
+ scan_interfaces
+
+ case $DEVICENAME in
+ solos-pci[0-3])
+ port="${DEVICENAME#solos-pci}"
+ device="solos${port}"
+
+ config_list_foreach wan "$device" dialog
+ ;;
+ esac
+fi
diff --git a/package/network/config/soloscli/files/etc/uci-default/solos b/package/network/config/soloscli/files/etc/uci-default/solos
new file mode 100644
index 0000000..7f69da6
--- /dev/null
+++ b/package/network/config/soloscli/files/etc/uci-default/solos
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+uci batch <<__EOF__
+
+delete network.wan.solos0
+
+add_list network.wan.solos0="ActivateLine=Abort"
+add_list network.wan.solos0="Retrain=EnableAll"
+add_list network.wan.solos0="DetectNoise=Enable"
+add_list network.wan.solos0="BisMCapability=Disable"
+add_list network.wan.solos0="BisACapability=Disable"
+add_list network.wan.solos0="ActivateLine=Start"
+
+commit network
+__EOF__
diff --git a/package/network/config/soloscli/files/solos-log-stats b/package/network/config/soloscli/files/solos-log-stats
new file mode 100644
index 0000000..2b75ee3
--- /dev/null
+++ b/package/network/config/soloscli/files/solos-log-stats
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+cd /sys/class/atm/ || exit 1
+
+for PORT in solos-pci* ; do
+
+ RXRATE=`cat $PORT/parameters/RxBitRate`
+ TXRATE=`cat $PORT/parameters/TxBitRate`
+ RXSNR=`cat $PORT/parameters/LocalSNRMargin | sed "s/ dB//"`
+ TXSNR=`cat $PORT/parameters/RemoteSNRMargin | sed "s/ dB//"`
+ RXERR=`cat $PORT/parameters/RSUnCorrectedErrorsDn`
+ TXERR=`cat $PORT/parameters/RSUnCorrectedErrorsUp`
+ RXFEC=`cat $PORT/parameters/RSCorrectedErrorsDn`
+ TXFEC=`cat $PORT/parameters/RSCorrectedErrorsUp`
+
+ echo "$RXRATE $RXSNR $RXERR $RXFEC / $TXRATE $TXSNR $TXERR $TXFEC" |
+ logger -t $PORT
+done
+
diff --git a/package/network/config/soloscli/patches/001-no-driver.patch b/package/network/config/soloscli/patches/001-no-driver.patch
new file mode 100644
index 0000000..95588aa
--- /dev/null
+++ b/package/network/config/soloscli/patches/001-no-driver.patch
@@ -0,0 +1,11 @@
+--- a/Makefile
++++ b/Makefile
+@@ -11,7 +11,7 @@ else
+ KDIR ?= /lib/modules/$(shell uname -r)/build
+ PWD := $(shell pwd)
+
+-all: soloscli driver
++all: soloscli
+
+ soloscli: soloscli/soloscli
+
diff --git a/package/network/config/soloscli/patches/002-cflags.patch b/package/network/config/soloscli/patches/002-cflags.patch
new file mode 100644
index 0000000..a7d6a86
--- /dev/null
+++ b/package/network/config/soloscli/patches/002-cflags.patch
@@ -0,0 +1,12 @@
+--- a/soloscli/Makefile
++++ b/soloscli/Makefile
+@@ -4,9 +4,6 @@
+ # Last Mod: 2009-06-16
+ #
+
+-CC=gcc
+-CFLAGS=-Wall
+-
+ soloscli: soloscli.c soloscli.h
+
+ clean:
diff --git a/package/network/config/swconfig/Makefile b/package/network/config/swconfig/Makefile
new file mode 100644
index 0000000..b62b059
--- /dev/null
+++ b/package/network/config/swconfig/Makefile
@@ -0,0 +1,60 @@
+#
+# Copyright (C) 2008-2010 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=swconfig
+PKG_RELEASE:=10
+
+PKG_MAINTAINER:=Felix Fietkau <nbd@openwrt.org>
+PKG_LICENSE:=GPL-2.0
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/kernel.mk
+
+define Package/swconfig
+ SECTION:=base
+ CATEGORY:=Base system
+ DEPENDS:=+libuci +libnl-tiny
+ TITLE:=Switch configuration utility
+endef
+
+TARGET_CPPFLAGS := \
+ -D_GNU_SOURCE \
+ -I$(STAGING_DIR)/usr/include/libnl-tiny \
+ -I$(PKG_BUILD_DIR) \
+ $(TARGET_CPPFLAGS) \
+ -I$(LINUX_DIR)/user_headers/include
+
+define Build/Prepare
+ mkdir -p $(PKG_BUILD_DIR)
+ $(CP) ./src/* $(PKG_BUILD_DIR)/
+endef
+
+define Build/Compile
+ CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" \
+ $(MAKE) -C $(PKG_BUILD_DIR) \
+ $(TARGET_CONFIGURE_OPTS) \
+ LIBS="$(TARGET_LDFLAGS) -lnl-tiny -lm -luci"
+endef
+
+define Build/InstallDev
+ $(INSTALL_DIR) $(1)/usr/include
+ $(CP) $(PKG_BUILD_DIR)/swlib.h $(1)/usr/include/
+
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(CP) $(PKG_BUILD_DIR)/libsw.so $(1)/usr/lib/
+endef
+
+define Package/swconfig/install
+ $(INSTALL_DIR) $(1)/sbin $(1)/lib/network
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/swconfig $(1)/sbin/swconfig
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/libsw.so $(1)/lib
+ $(INSTALL_DATA) ./files/switch.sh $(1)/lib/network/
+endef
+
+$(eval $(call BuildPackage,swconfig))
diff --git a/package/network/config/swconfig/files/switch.sh b/package/network/config/swconfig/files/switch.sh
new file mode 100644
index 0000000..74d2590
--- /dev/null
+++ b/package/network/config/swconfig/files/switch.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+setup_switch_dev() {
+ local name
+ config_get name "$1" name
+ name="${name:-$1}"
+ [ -d "/sys/class/net/$name" ] && ip link set dev "$name" up
+ swconfig dev "$name" load network
+}
+
+setup_switch() {
+ config_load network
+ config_foreach setup_switch_dev switch
+}
diff --git a/package/network/config/swconfig/src/Makefile b/package/network/config/swconfig/src/Makefile
new file mode 100644
index 0000000..1176bf0
--- /dev/null
+++ b/package/network/config/swconfig/src/Makefile
@@ -0,0 +1,15 @@
+ifndef CFLAGS
+CFLAGS = -O2 -g -I ../src
+endif
+LIBS=-lnl -lnl-genl
+
+all: swconfig
+
+%.o: %.c
+ $(CC) $(CFLAGS) -fPIC -c -o $@ $^
+
+libsw.so: swlib.o
+ $(CC) $(CFLAGS) -fPIC -shared -o $@ swlib.o
+
+swconfig: libsw.so cli.o uci.o
+ $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) -L./ -lsw
diff --git a/package/network/config/swconfig/src/cli.c b/package/network/config/swconfig/src/cli.c
new file mode 100644
index 0000000..d472086
--- /dev/null
+++ b/package/network/config/swconfig/src/cli.c
@@ -0,0 +1,354 @@
+/*
+ * swconfig.c: Switch configuration utility
+ *
+ * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2010 Martin Mares <mj@ucw.cz>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundatio.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <stdint.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <uci.h>
+
+#include <linux/types.h>
+#include <linux/netlink.h>
+#include <linux/genetlink.h>
+#include <netlink/netlink.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+#include <linux/switch.h>
+#include "swlib.h"
+
+enum {
+ CMD_NONE,
+ CMD_GET,
+ CMD_SET,
+ CMD_LOAD,
+ CMD_HELP,
+ CMD_SHOW,
+ CMD_PORTMAP,
+};
+
+static void
+print_attrs(const struct switch_attr *attr)
+{
+ int i = 0;
+ while (attr) {
+ const char *type;
+ switch(attr->type) {
+ case SWITCH_TYPE_INT:
+ type = "int";
+ break;
+ case SWITCH_TYPE_STRING:
+ type = "string";
+ break;
+ case SWITCH_TYPE_PORTS:
+ type = "ports";
+ break;
+ case SWITCH_TYPE_NOVAL:
+ type = "none";
+ break;
+ default:
+ type = "unknown";
+ break;
+ }
+ printf("\tAttribute %d (%s): %s (%s)\n", ++i, type, attr->name, attr->description);
+ attr = attr->next;
+ }
+}
+
+static void
+list_attributes(struct switch_dev *dev)
+{
+ printf("%s: %s(%s), ports: %d (cpu @ %d), vlans: %d\n", dev->dev_name, dev->alias, dev->name, dev->ports, dev->cpu_port, dev->vlans);
+ printf(" --switch\n");
+ print_attrs(dev->ops);
+ printf(" --vlan\n");
+ print_attrs(dev->vlan_ops);
+ printf(" --port\n");
+ print_attrs(dev->port_ops);
+}
+
+static void
+print_attr_val(const struct switch_attr *attr, const struct switch_val *val)
+{
+ int i;
+
+ switch (attr->type) {
+ case SWITCH_TYPE_INT:
+ printf("%d", val->value.i);
+ break;
+ case SWITCH_TYPE_STRING:
+ printf("%s", val->value.s);
+ break;
+ case SWITCH_TYPE_PORTS:
+ for(i = 0; i < val->len; i++) {
+ printf("%d%s ",
+ val->value.ports[i].id,
+ (val->value.ports[i].flags &
+ SWLIB_PORT_FLAG_TAGGED) ? "t" : "");
+ }
+ break;
+ default:
+ printf("?unknown-type?");
+ }
+}
+
+static void
+show_attrs(struct switch_dev *dev, struct switch_attr *attr, struct switch_val *val)
+{
+ while (attr) {
+ if (attr->type != SWITCH_TYPE_NOVAL) {
+ printf("\t%s: ", attr->name);
+ if (swlib_get_attr(dev, attr, val) < 0)
+ printf("???");
+ else
+ print_attr_val(attr, val);
+ putchar('\n');
+ }
+ attr = attr->next;
+ }
+}
+
+static void
+show_global(struct switch_dev *dev)
+{
+ struct switch_val val;
+
+ printf("Global attributes:\n");
+ show_attrs(dev, dev->ops, &val);
+}
+
+static void
+show_port(struct switch_dev *dev, int port)
+{
+ struct switch_val val;
+
+ printf("Port %d:\n", port);
+ val.port_vlan = port;
+ show_attrs(dev, dev->port_ops, &val);
+}
+
+static void
+show_vlan(struct switch_dev *dev, int vlan, bool all)
+{
+ struct switch_val val;
+ struct switch_attr *attr;
+
+ val.port_vlan = vlan;
+
+ if (all) {
+ attr = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_VLAN, "ports");
+ if (swlib_get_attr(dev, attr, &val) < 0)
+ return;
+
+ if (!val.len)
+ return;
+ }
+
+ printf("VLAN %d:\n", vlan);
+ show_attrs(dev, dev->vlan_ops, &val);
+}
+
+static void
+print_usage(void)
+{
+ printf("swconfig list\n");
+ printf("swconfig dev <dev> [port <port>|vlan <vlan>] (help|set <key> <value>|get <key>|load <config>|show)\n");
+ exit(1);
+}
+
+static void
+swconfig_load_uci(struct switch_dev *dev, const char *name)
+{
+ struct uci_context *ctx;
+ struct uci_package *p = NULL;
+ int ret = -1;
+
+ ctx = uci_alloc_context();
+ if (!ctx)
+ return;
+
+ uci_load(ctx, name, &p);
+ if (!p) {
+ uci_perror(ctx, "Failed to load config file: ");
+ goto out;
+ }
+
+ ret = swlib_apply_from_uci(dev, p);
+ if (ret < 0)
+ fprintf(stderr, "Failed to apply configuration for switch '%s'\n", dev->dev_name);
+
+out:
+ uci_free_context(ctx);
+ exit(ret);
+}
+
+int main(int argc, char **argv)
+{
+ int retval = 0;
+ struct switch_dev *dev;
+ struct switch_attr *a;
+ struct switch_val val;
+ int i;
+
+ int cmd = CMD_NONE;
+ char *cdev = NULL;
+ int cport = -1;
+ int cvlan = -1;
+ char *ckey = NULL;
+ char *cvalue = NULL;
+ char *csegment = NULL;
+
+ if((argc == 2) && !strcmp(argv[1], "list")) {
+ swlib_list();
+ return 0;
+ }
+
+ if(argc < 4)
+ print_usage();
+
+ if(strcmp(argv[1], "dev"))
+ print_usage();
+
+ cdev = argv[2];
+
+ for(i = 3; i < argc; i++)
+ {
+ char *arg = argv[i];
+ if (cmd != CMD_NONE) {
+ print_usage();
+ } else if (!strcmp(arg, "port") && i+1 < argc) {
+ cport = atoi(argv[++i]);
+ } else if (!strcmp(arg, "vlan") && i+1 < argc) {
+ cvlan = atoi(argv[++i]);
+ } else if (!strcmp(arg, "help")) {
+ cmd = CMD_HELP;
+ } else if (!strcmp(arg, "set") && i+1 < argc) {
+ cmd = CMD_SET;
+ ckey = argv[++i];
+ if (i+1 < argc)
+ cvalue = argv[++i];
+ } else if (!strcmp(arg, "get") && i+1 < argc) {
+ cmd = CMD_GET;
+ ckey = argv[++i];
+ } else if (!strcmp(arg, "load") && i+1 < argc) {
+ if ((cport >= 0) || (cvlan >= 0))
+ print_usage();
+ cmd = CMD_LOAD;
+ ckey = argv[++i];
+ } else if (!strcmp(arg, "portmap")) {
+ if (i + 1 < argc)
+ csegment = argv[++i];
+ cmd = CMD_PORTMAP;
+ } else if (!strcmp(arg, "show")) {
+ cmd = CMD_SHOW;
+ } else {
+ print_usage();
+ }
+ }
+
+ if (cmd == CMD_NONE)
+ print_usage();
+ if (cport > -1 && cvlan > -1)
+ print_usage();
+
+ dev = swlib_connect(cdev);
+ if (!dev) {
+ fprintf(stderr, "Failed to connect to the switch. Use the \"list\" command to see which switches are available.\n");
+ return 1;
+ }
+
+ swlib_scan(dev);
+
+ if (cmd == CMD_GET || cmd == CMD_SET) {
+ if(cport > -1)
+ a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_PORT, ckey);
+ else if(cvlan > -1)
+ a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_VLAN, ckey);
+ else
+ a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_GLOBAL, ckey);
+
+ if(!a)
+ {
+ fprintf(stderr, "Unknown attribute \"%s\"\n", ckey);
+ retval = -1;
+ goto out;
+ }
+ }
+
+ switch(cmd)
+ {
+ case CMD_SET:
+ if ((a->type != SWITCH_TYPE_NOVAL) &&
+ (cvalue == NULL))
+ print_usage();
+
+ if(cvlan > -1)
+ cport = cvlan;
+
+ if(swlib_set_attr_string(dev, a, cport, cvalue) < 0)
+ {
+ fprintf(stderr, "failed\n");
+ retval = -1;
+ goto out;
+ }
+ break;
+ case CMD_GET:
+ if(cvlan > -1)
+ val.port_vlan = cvlan;
+ if(cport > -1)
+ val.port_vlan = cport;
+ if(swlib_get_attr(dev, a, &val) < 0)
+ {
+ fprintf(stderr, "failed\n");
+ retval = -1;
+ goto out;
+ }
+ print_attr_val(a, &val);
+ putchar('\n');
+ break;
+ case CMD_LOAD:
+ swconfig_load_uci(dev, ckey);
+ break;
+ case CMD_HELP:
+ list_attributes(dev);
+ break;
+ case CMD_PORTMAP:
+ swlib_print_portmap(dev, csegment);
+ break;
+ case CMD_SHOW:
+ if (cport >= 0 || cvlan >= 0) {
+ if (cport >= 0)
+ show_port(dev, cport);
+ else
+ show_vlan(dev, cvlan, false);
+ } else {
+ show_global(dev);
+ for (i=0; i < dev->ports; i++)
+ show_port(dev, i);
+ for (i=0; i < dev->vlans; i++)
+ show_vlan(dev, i, true);
+ }
+ break;
+ }
+
+out:
+ swlib_free_all(dev);
+ return retval;
+}
diff --git a/package/network/config/swconfig/src/swlib.c b/package/network/config/swconfig/src/swlib.c
new file mode 100644
index 0000000..0dbace5
--- /dev/null
+++ b/package/network/config/swconfig/src/swlib.c
@@ -0,0 +1,801 @@
+/*
+ * swlib.c: Switch configuration API (user space part)
+ *
+ * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <stdint.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <linux/switch.h>
+#include "swlib.h"
+#include <netlink/netlink.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+
+//#define DEBUG 1
+#ifdef DEBUG
+#define DPRINTF(fmt, ...) fprintf(stderr, "%s(%d): " fmt, __func__, __LINE__, ##__VA_ARGS__)
+#else
+#define DPRINTF(fmt, ...) do {} while (0)
+#endif
+
+static struct nl_sock *handle;
+static struct nl_cache *cache;
+static struct genl_family *family;
+static struct nlattr *tb[SWITCH_ATTR_MAX + 1];
+static int refcount = 0;
+
+static struct nla_policy port_policy[SWITCH_ATTR_MAX] = {
+ [SWITCH_PORT_ID] = { .type = NLA_U32 },
+ [SWITCH_PORT_FLAG_TAGGED] = { .type = NLA_FLAG },
+};
+
+static struct nla_policy portmap_policy[SWITCH_PORTMAP_MAX] = {
+ [SWITCH_PORTMAP_SEGMENT] = { .type = NLA_STRING },
+ [SWITCH_PORTMAP_VIRT] = { .type = NLA_U32 },
+};
+
+static inline void *
+swlib_alloc(size_t size)
+{
+ void *ptr;
+
+ ptr = malloc(size);
+ if (!ptr)
+ goto done;
+ memset(ptr, 0, size);
+
+done:
+ return ptr;
+}
+
+static int
+wait_handler(struct nl_msg *msg, void *arg)
+{
+ int *finished = arg;
+
+ *finished = 1;
+ return NL_STOP;
+}
+
+/* helper function for performing netlink requests */
+static int
+swlib_call(int cmd, int (*call)(struct nl_msg *, void *),
+ int (*data)(struct nl_msg *, void *), void *arg)
+{
+ struct nl_msg *msg;
+ struct nl_cb *cb = NULL;
+ int finished;
+ int flags = 0;
+ int err;
+
+ msg = nlmsg_alloc();
+ if (!msg) {
+ fprintf(stderr, "Out of memory!\n");
+ exit(1);
+ }
+
+ if (!data)
+ flags |= NLM_F_DUMP;
+
+ genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, genl_family_get_id(family), 0, flags, cmd, 0);
+ if (data) {
+ if (data(msg, arg) < 0)
+ goto nla_put_failure;
+ }
+
+ cb = nl_cb_alloc(NL_CB_CUSTOM);
+ if (!cb) {
+ fprintf(stderr, "nl_cb_alloc failed.\n");
+ exit(1);
+ }
+
+ err = nl_send_auto_complete(handle, msg);
+ if (err < 0) {
+ fprintf(stderr, "nl_send_auto_complete failed: %d\n", err);
+ goto out;
+ }
+
+ finished = 0;
+
+ if (call)
+ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, call, arg);
+
+ if (data)
+ nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, wait_handler, &finished);
+ else
+ nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, wait_handler, &finished);
+
+ err = nl_recvmsgs(handle, cb);
+ if (err < 0) {
+ goto out;
+ }
+
+ if (!finished)
+ err = nl_wait_for_ack(handle);
+
+out:
+ if (cb)
+ nl_cb_put(cb);
+nla_put_failure:
+ nlmsg_free(msg);
+ return err;
+}
+
+static int
+send_attr(struct nl_msg *msg, void *arg)
+{
+ struct switch_val *val = arg;
+ struct switch_attr *attr = val->attr;
+
+ NLA_PUT_U32(msg, SWITCH_ATTR_ID, attr->dev->id);
+ NLA_PUT_U32(msg, SWITCH_ATTR_OP_ID, attr->id);
+ switch(attr->atype) {
+ case SWLIB_ATTR_GROUP_PORT:
+ NLA_PUT_U32(msg, SWITCH_ATTR_OP_PORT, val->port_vlan);
+ break;
+ case SWLIB_ATTR_GROUP_VLAN:
+ NLA_PUT_U32(msg, SWITCH_ATTR_OP_VLAN, val->port_vlan);
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+
+nla_put_failure:
+ return -1;
+}
+
+static int
+store_port_val(struct nl_msg *msg, struct nlattr *nla, struct switch_val *val)
+{
+ struct nlattr *p;
+ int ports = val->attr->dev->ports;
+ int err = 0;
+ int remaining;
+
+ if (!val->value.ports)
+ val->value.ports = malloc(sizeof(struct switch_port) * ports);
+
+ nla_for_each_nested(p, nla, remaining) {
+ struct nlattr *tb[SWITCH_PORT_ATTR_MAX+1];
+ struct switch_port *port;
+
+ if (val->len >= ports)
+ break;
+
+ err = nla_parse_nested(tb, SWITCH_PORT_ATTR_MAX, p, port_policy);
+ if (err < 0)
+ goto out;
+
+ if (!tb[SWITCH_PORT_ID])
+ continue;
+
+ port = &val->value.ports[val->len];
+ port->id = nla_get_u32(tb[SWITCH_PORT_ID]);
+ port->flags = 0;
+ if (tb[SWITCH_PORT_FLAG_TAGGED])
+ port->flags |= SWLIB_PORT_FLAG_TAGGED;
+
+ val->len++;
+ }
+
+out:
+ return err;
+}
+
+static int
+store_val(struct nl_msg *msg, void *arg)
+{
+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+ struct switch_val *val = arg;
+
+ if (!val)
+ goto error;
+
+ if (nla_parse(tb, SWITCH_ATTR_MAX - 1, genlmsg_attrdata(gnlh, 0),
+ genlmsg_attrlen(gnlh, 0), NULL) < 0) {
+ goto error;
+ }
+
+ if (tb[SWITCH_ATTR_OP_VALUE_INT])
+ val->value.i = nla_get_u32(tb[SWITCH_ATTR_OP_VALUE_INT]);
+ else if (tb[SWITCH_ATTR_OP_VALUE_STR])
+ val->value.s = strdup(nla_get_string(tb[SWITCH_ATTR_OP_VALUE_STR]));
+ else if (tb[SWITCH_ATTR_OP_VALUE_PORTS])
+ val->err = store_port_val(msg, tb[SWITCH_ATTR_OP_VALUE_PORTS], val);
+
+ val->err = 0;
+ return 0;
+
+error:
+ return NL_SKIP;
+}
+
+int
+swlib_get_attr(struct switch_dev *dev, struct switch_attr *attr, struct switch_val *val)
+{
+ int cmd;
+ int err;
+
+ switch(attr->atype) {
+ case SWLIB_ATTR_GROUP_GLOBAL:
+ cmd = SWITCH_CMD_GET_GLOBAL;
+ break;
+ case SWLIB_ATTR_GROUP_PORT:
+ cmd = SWITCH_CMD_GET_PORT;
+ break;
+ case SWLIB_ATTR_GROUP_VLAN:
+ cmd = SWITCH_CMD_GET_VLAN;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ memset(&val->value, 0, sizeof(val->value));
+ val->len = 0;
+ val->attr = attr;
+ val->err = -EINVAL;
+ err = swlib_call(cmd, store_val, send_attr, val);
+ if (!err)
+ err = val->err;
+
+ return err;
+}
+
+static int
+send_attr_ports(struct nl_msg *msg, struct switch_val *val)
+{
+ struct nlattr *n;
+ int i;
+
+ /* TODO implement multipart? */
+ if (val->len == 0)
+ goto done;
+ n = nla_nest_start(msg, SWITCH_ATTR_OP_VALUE_PORTS);
+ if (!n)
+ goto nla_put_failure;
+ for (i = 0; i < val->len; i++) {
+ struct switch_port *port = &val->value.ports[i];
+ struct nlattr *np;
+
+ np = nla_nest_start(msg, SWITCH_ATTR_PORT);
+ if (!np)
+ goto nla_put_failure;
+
+ NLA_PUT_U32(msg, SWITCH_PORT_ID, port->id);
+ if (port->flags & SWLIB_PORT_FLAG_TAGGED)
+ NLA_PUT_FLAG(msg, SWITCH_PORT_FLAG_TAGGED);
+
+ nla_nest_end(msg, np);
+ }
+ nla_nest_end(msg, n);
+done:
+ return 0;
+
+nla_put_failure:
+ return -1;
+}
+
+static int
+send_attr_val(struct nl_msg *msg, void *arg)
+{
+ struct switch_val *val = arg;
+ struct switch_attr *attr = val->attr;
+
+ if (send_attr(msg, arg))
+ goto nla_put_failure;
+
+ switch(attr->type) {
+ case SWITCH_TYPE_NOVAL:
+ break;
+ case SWITCH_TYPE_INT:
+ NLA_PUT_U32(msg, SWITCH_ATTR_OP_VALUE_INT, val->value.i);
+ break;
+ case SWITCH_TYPE_STRING:
+ if (!val->value.s)
+ goto nla_put_failure;
+ NLA_PUT_STRING(msg, SWITCH_ATTR_OP_VALUE_STR, val->value.s);
+ break;
+ case SWITCH_TYPE_PORTS:
+ if (send_attr_ports(msg, val) < 0)
+ goto nla_put_failure;
+ break;
+ default:
+ goto nla_put_failure;
+ }
+ return 0;
+
+nla_put_failure:
+ return -1;
+}
+
+int
+swlib_set_attr(struct switch_dev *dev, struct switch_attr *attr, struct switch_val *val)
+{
+ int cmd;
+
+ switch(attr->atype) {
+ case SWLIB_ATTR_GROUP_GLOBAL:
+ cmd = SWITCH_CMD_SET_GLOBAL;
+ break;
+ case SWLIB_ATTR_GROUP_PORT:
+ cmd = SWITCH_CMD_SET_PORT;
+ break;
+ case SWLIB_ATTR_GROUP_VLAN:
+ cmd = SWITCH_CMD_SET_VLAN;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ val->attr = attr;
+ return swlib_call(cmd, NULL, send_attr_val, val);
+}
+
+int swlib_set_attr_string(struct switch_dev *dev, struct switch_attr *a, int port_vlan, const char *str)
+{
+ struct switch_port *ports;
+ struct switch_val val;
+ char *ptr;
+
+ memset(&val, 0, sizeof(val));
+ val.port_vlan = port_vlan;
+ switch(a->type) {
+ case SWITCH_TYPE_INT:
+ val.value.i = atoi(str);
+ break;
+ case SWITCH_TYPE_STRING:
+ val.value.s = (char *)str;
+ break;
+ case SWITCH_TYPE_PORTS:
+ ports = alloca(sizeof(struct switch_port) * dev->ports);
+ memset(ports, 0, sizeof(struct switch_port) * dev->ports);
+ val.len = 0;
+ ptr = (char *)str;
+ while(ptr && *ptr)
+ {
+ while(*ptr && isspace(*ptr))
+ ptr++;
+
+ if (!*ptr)
+ break;
+
+ if (!isdigit(*ptr))
+ return -1;
+
+ if (val.len >= dev->ports)
+ return -1;
+
+ ports[val.len].flags = 0;
+ ports[val.len].id = strtoul(ptr, &ptr, 10);
+ while(*ptr && !isspace(*ptr)) {
+ if (*ptr == 't')
+ ports[val.len].flags |= SWLIB_PORT_FLAG_TAGGED;
+ else
+ return -1;
+
+ ptr++;
+ }
+ if (*ptr)
+ ptr++;
+ val.len++;
+ }
+ val.value.ports = ports;
+ break;
+ case SWITCH_TYPE_NOVAL:
+ if (str && !strcmp(str, "0"))
+ return 0;
+
+ break;
+ default:
+ return -1;
+ }
+ return swlib_set_attr(dev, a, &val);
+}
+
+
+struct attrlist_arg {
+ int id;
+ int atype;
+ struct switch_dev *dev;
+ struct switch_attr *prev;
+ struct switch_attr **head;
+};
+
+static int
+add_id(struct nl_msg *msg, void *arg)
+{
+ struct attrlist_arg *l = arg;
+
+ NLA_PUT_U32(msg, SWITCH_ATTR_ID, l->id);
+
+ return 0;
+nla_put_failure:
+ return -1;
+}
+
+static int
+add_attr(struct nl_msg *msg, void *ptr)
+{
+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+ struct attrlist_arg *arg = ptr;
+ struct switch_attr *new;
+
+ if (nla_parse(tb, SWITCH_ATTR_MAX - 1, genlmsg_attrdata(gnlh, 0),
+ genlmsg_attrlen(gnlh, 0), NULL) < 0)
+ goto done;
+
+ new = swlib_alloc(sizeof(struct switch_attr));
+ if (!new)
+ goto done;
+
+ new->dev = arg->dev;
+ new->atype = arg->atype;
+ if (arg->prev) {
+ arg->prev->next = new;
+ } else {
+ arg->prev = *arg->head;
+ }
+ *arg->head = new;
+ arg->head = &new->next;
+
+ if (tb[SWITCH_ATTR_OP_ID])
+ new->id = nla_get_u32(tb[SWITCH_ATTR_OP_ID]);
+ if (tb[SWITCH_ATTR_OP_TYPE])
+ new->type = nla_get_u32(tb[SWITCH_ATTR_OP_TYPE]);
+ if (tb[SWITCH_ATTR_OP_NAME])
+ new->name = strdup(nla_get_string(tb[SWITCH_ATTR_OP_NAME]));
+ if (tb[SWITCH_ATTR_OP_DESCRIPTION])
+ new->description = strdup(nla_get_string(tb[SWITCH_ATTR_OP_DESCRIPTION]));
+
+done:
+ return NL_SKIP;
+}
+
+int
+swlib_scan(struct switch_dev *dev)
+{
+ struct attrlist_arg arg;
+
+ if (dev->ops || dev->port_ops || dev->vlan_ops)
+ return 0;
+
+ arg.atype = SWLIB_ATTR_GROUP_GLOBAL;
+ arg.dev = dev;
+ arg.id = dev->id;
+ arg.prev = NULL;
+ arg.head = &dev->ops;
+ swlib_call(SWITCH_CMD_LIST_GLOBAL, add_attr, add_id, &arg);
+
+ arg.atype = SWLIB_ATTR_GROUP_PORT;
+ arg.prev = NULL;
+ arg.head = &dev->port_ops;
+ swlib_call(SWITCH_CMD_LIST_PORT, add_attr, add_id, &arg);
+
+ arg.atype = SWLIB_ATTR_GROUP_VLAN;
+ arg.prev = NULL;
+ arg.head = &dev->vlan_ops;
+ swlib_call(SWITCH_CMD_LIST_VLAN, add_attr, add_id, &arg);
+
+ return 0;
+}
+
+struct switch_attr *swlib_lookup_attr(struct switch_dev *dev,
+ enum swlib_attr_group atype, const char *name)
+{
+ struct switch_attr *head;
+
+ if (!name || !dev)
+ return NULL;
+
+ switch(atype) {
+ case SWLIB_ATTR_GROUP_GLOBAL:
+ head = dev->ops;
+ break;
+ case SWLIB_ATTR_GROUP_PORT:
+ head = dev->port_ops;
+ break;
+ case SWLIB_ATTR_GROUP_VLAN:
+ head = dev->vlan_ops;
+ break;
+ }
+ while(head) {
+ if (!strcmp(name, head->name))
+ return head;
+ head = head->next;
+ }
+
+ return NULL;
+}
+
+static void
+swlib_priv_free(void)
+{
+ if (family)
+ nl_object_put((struct nl_object*)family);
+ if (cache)
+ nl_cache_free(cache);
+ if (handle)
+ nl_socket_free(handle);
+ family = NULL;
+ handle = NULL;
+ cache = NULL;
+}
+
+static int
+swlib_priv_init(void)
+{
+ int ret;
+
+ handle = nl_socket_alloc();
+ if (!handle) {
+ DPRINTF("Failed to create handle\n");
+ goto err;
+ }
+
+ if (genl_connect(handle)) {
+ DPRINTF("Failed to connect to generic netlink\n");
+ goto err;
+ }
+
+ ret = genl_ctrl_alloc_cache(handle, &cache);
+ if (ret < 0) {
+ DPRINTF("Failed to allocate netlink cache\n");
+ goto err;
+ }
+
+ family = genl_ctrl_search_by_name(cache, "switch");
+ if (!family) {
+ DPRINTF("Switch API not present\n");
+ goto err;
+ }
+ return 0;
+
+err:
+ swlib_priv_free();
+ return -EINVAL;
+}
+
+struct swlib_scan_arg {
+ const char *name;
+ struct switch_dev *head;
+ struct switch_dev *ptr;
+};
+
+static int
+add_port_map(struct switch_dev *dev, struct nlattr *nla)
+{
+ struct nlattr *p;
+ int err = 0, idx = 0;
+ int remaining;
+
+ dev->maps = malloc(sizeof(struct switch_portmap) * dev->ports);
+ if (!dev->maps)
+ return -1;
+ memset(dev->maps, 0, sizeof(struct switch_portmap) * dev->ports);
+
+ nla_for_each_nested(p, nla, remaining) {
+ struct nlattr *tb[SWITCH_PORTMAP_MAX+1];
+
+ if (idx >= dev->ports)
+ continue;
+
+ err = nla_parse_nested(tb, SWITCH_PORTMAP_MAX, p, portmap_policy);
+ if (err < 0)
+ continue;
+
+
+ if (tb[SWITCH_PORTMAP_SEGMENT] && tb[SWITCH_PORTMAP_VIRT]) {
+ dev->maps[idx].segment = strdup(nla_get_string(tb[SWITCH_PORTMAP_SEGMENT]));
+ dev->maps[idx].virt = nla_get_u32(tb[SWITCH_PORTMAP_VIRT]);
+ }
+ idx++;
+ }
+
+out:
+ return err;
+}
+
+
+static int
+add_switch(struct nl_msg *msg, void *arg)
+{
+ struct swlib_scan_arg *sa = arg;
+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+ struct switch_dev *dev;
+ const char *name;
+ const char *alias;
+
+ if (nla_parse(tb, SWITCH_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL) < 0)
+ goto done;
+
+ if (!tb[SWITCH_ATTR_DEV_NAME])
+ goto done;
+
+ name = nla_get_string(tb[SWITCH_ATTR_DEV_NAME]);
+ alias = nla_get_string(tb[SWITCH_ATTR_ALIAS]);
+
+ if (sa->name && (strcmp(name, sa->name) != 0) && (strcmp(alias, sa->name) != 0))
+ goto done;
+
+ dev = swlib_alloc(sizeof(struct switch_dev));
+ if (!dev)
+ goto done;
+
+ strncpy(dev->dev_name, name, IFNAMSIZ - 1);
+ dev->alias = strdup(alias);
+ if (tb[SWITCH_ATTR_ID])
+ dev->id = nla_get_u32(tb[SWITCH_ATTR_ID]);
+ if (tb[SWITCH_ATTR_NAME])
+ dev->name = strdup(nla_get_string(tb[SWITCH_ATTR_NAME]));
+ if (tb[SWITCH_ATTR_PORTS])
+ dev->ports = nla_get_u32(tb[SWITCH_ATTR_PORTS]);
+ if (tb[SWITCH_ATTR_VLANS])
+ dev->vlans = nla_get_u32(tb[SWITCH_ATTR_VLANS]);
+ if (tb[SWITCH_ATTR_CPU_PORT])
+ dev->cpu_port = nla_get_u32(tb[SWITCH_ATTR_CPU_PORT]);
+ if (tb[SWITCH_ATTR_PORTMAP])
+ add_port_map(dev, tb[SWITCH_ATTR_PORTMAP]);
+
+ if (!sa->head) {
+ sa->head = dev;
+ sa->ptr = dev;
+ } else {
+ sa->ptr->next = dev;
+ sa->ptr = dev;
+ }
+
+ refcount++;
+done:
+ return NL_SKIP;
+}
+
+static int
+list_switch(struct nl_msg *msg, void *arg)
+{
+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+
+ if (nla_parse(tb, SWITCH_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL) < 0)
+ goto done;
+
+ if (!tb[SWITCH_ATTR_DEV_NAME] || !tb[SWITCH_ATTR_NAME])
+ goto done;
+
+ printf("Found: %s - %s\n", nla_get_string(tb[SWITCH_ATTR_DEV_NAME]),
+ nla_get_string(tb[SWITCH_ATTR_ALIAS]));
+
+done:
+ return NL_SKIP;
+}
+
+void
+swlib_list(void)
+{
+ if (swlib_priv_init() < 0)
+ return;
+ swlib_call(SWITCH_CMD_GET_SWITCH, list_switch, NULL, NULL);
+ swlib_priv_free();
+}
+
+void
+swlib_print_portmap(struct switch_dev *dev, char *segment)
+{
+ int i;
+
+ if (segment) {
+ if (!strcmp(segment, "cpu")) {
+ printf("%d ", dev->cpu_port);
+ } else if (!strcmp(segment, "disabled")) {
+ for (i = 0; i < dev->ports; i++)
+ if (!dev->maps[i].segment)
+ printf("%d ", i);
+ } else for (i = 0; i < dev->ports; i++) {
+ if (dev->maps[i].segment && !strcmp(dev->maps[i].segment, segment))
+ printf("%d ", i);
+ }
+ } else {
+ printf("%s - %s\n", dev->dev_name, dev->name);
+ for (i = 0; i < dev->ports; i++)
+ if (i == dev->cpu_port)
+ printf("port%d:\tcpu\n", i);
+ else if (dev->maps[i].segment)
+ printf("port%d:\t%s.%d\n", i, dev->maps[i].segment, dev->maps[i].virt);
+ else
+ printf("port%d:\tdisabled\n", i);
+ }
+}
+
+struct switch_dev *
+swlib_connect(const char *name)
+{
+ struct swlib_scan_arg arg;
+
+ if (!refcount) {
+ if (swlib_priv_init() < 0)
+ return NULL;
+ };
+
+ arg.head = NULL;
+ arg.ptr = NULL;
+ arg.name = name;
+ swlib_call(SWITCH_CMD_GET_SWITCH, add_switch, NULL, &arg);
+
+ if (!refcount)
+ swlib_priv_free();
+
+ return arg.head;
+}
+
+static void
+swlib_free_attributes(struct switch_attr **head)
+{
+ struct switch_attr *a = *head;
+ struct switch_attr *next;
+
+ while (a) {
+ next = a->next;
+ free(a->name);
+ free(a->description);
+ free(a);
+ a = next;
+ }
+ *head = NULL;
+}
+
+static void
+swlib_free_port_map(struct switch_dev *dev)
+{
+ int i;
+
+ if (!dev || !dev->maps)
+ return;
+
+ for (i = 0; i < dev->ports; i++)
+ free(dev->maps[i].segment);
+ free(dev->maps);
+}
+
+void
+swlib_free(struct switch_dev *dev)
+{
+ swlib_free_attributes(&dev->ops);
+ swlib_free_attributes(&dev->port_ops);
+ swlib_free_attributes(&dev->vlan_ops);
+ swlib_free_port_map(dev);
+ free(dev->name);
+ free(dev->alias);
+ free(dev);
+
+ if (--refcount == 0)
+ swlib_priv_free();
+}
+
+void
+swlib_free_all(struct switch_dev *dev)
+{
+ struct switch_dev *p;
+
+ while (dev) {
+ p = dev->next;
+ swlib_free(dev);
+ dev = p;
+ }
+}
diff --git a/package/network/config/swconfig/src/swlib.h b/package/network/config/swconfig/src/swlib.h
new file mode 100644
index 0000000..7edece3
--- /dev/null
+++ b/package/network/config/swconfig/src/swlib.h
@@ -0,0 +1,252 @@
+/*
+ * swlib.h: Switch configuration API (user space part)
+ *
+ * Copyright (C) 2008-2009 Felix Fietkau <nbd@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+
+Usage of the library functions:
+
+ The main datastructure for a switch is the struct switch_device
+ To get started, you first need to use switch_connect() to probe
+ for switches and allocate an instance of this struct.
+
+ There are two possible usage modes:
+ dev = switch_connect("eth0");
+ - this call will look for a switch registered for the linux device
+ "eth0" and only allocate a switch_device for this particular switch.
+
+ dev = switch_connect(NULL)
+ - this will return one switch_device struct for each available
+ switch. The switch_device structs are chained with by ->next pointer
+
+ Then to query a switch for all available attributes, use:
+ swlib_scan(dev);
+
+ All allocated datastructures for the switch_device struct can be freed with
+ swlib_free(dev);
+ or
+ swlib_free_all(dev);
+
+ The latter traverses a whole chain of switch_device structs and frees them all
+
+ Switch attributes (struct switch_attr) are divided into three groups:
+ dev->ops:
+ - global settings
+ dev->port_ops:
+ - per-port settings
+ dev->vlan_ops:
+ - per-vlan settings
+
+ switch_lookup_attr() is a small helper function to locate attributes
+ by name.
+
+ switch_set_attr() and switch_get_attr() can alter or request the values
+ of attributes.
+
+Usage of the switch_attr struct:
+
+ ->atype: attribute group, one of:
+ - SWLIB_ATTR_GROUP_GLOBAL
+ - SWLIB_ATTR_GROUP_VLAN
+ - SWLIB_ATTR_GROUP_PORT
+
+ ->id: identifier for the attribute
+
+ ->type: data type, one of:
+ - SWITCH_TYPE_INT
+ - SWITCH_TYPE_STRING
+ - SWITCH_TYPE_PORT
+
+ ->name: short name of the attribute
+ ->description: longer description
+ ->next: pointer to the next attribute of the current group
+
+
+Usage of the switch_val struct:
+
+ When setting attributes, following members of the struct switch_val need
+ to be set up:
+
+ ->len (for attr->type == SWITCH_TYPE_PORT)
+ ->port_vlan:
+ - port number (for attr->atype == SWLIB_ATTR_GROUP_PORT), or:
+ - vlan number (for attr->atype == SWLIB_ATTR_GROUP_VLAN)
+ ->value.i (for attr->type == SWITCH_TYPE_INT)
+ ->value.s (for attr->type == SWITCH_TYPE_STRING)
+ - owned by the caller, not stored in the library internally
+ ->value.ports (for attr->type == SWITCH_TYPE_PORT)
+ - must point to an array of at lest val->len * sizeof(struct switch_port)
+
+ When getting string attributes, val->value.s must be freed by the caller
+ When getting port list attributes, an internal static buffer is used,
+ which changes from call to call.
+
+ */
+
+#ifndef __SWLIB_H
+#define __SWLIB_H
+
+enum swlib_attr_group {
+ SWLIB_ATTR_GROUP_GLOBAL,
+ SWLIB_ATTR_GROUP_VLAN,
+ SWLIB_ATTR_GROUP_PORT,
+};
+
+enum swlib_port_flags {
+ SWLIB_PORT_FLAG_TAGGED = (1 << 0),
+};
+
+
+struct switch_dev;
+struct switch_attr;
+struct switch_port;
+struct switch_port_map;
+struct switch_val;
+struct uci_package;
+
+struct switch_dev {
+ int id;
+ char dev_name[IFNAMSIZ];
+ char *name;
+ char *alias;
+ int ports;
+ int vlans;
+ int cpu_port;
+ struct switch_attr *ops;
+ struct switch_attr *port_ops;
+ struct switch_attr *vlan_ops;
+ struct switch_portmap *maps;
+ struct switch_dev *next;
+ void *priv;
+};
+
+struct switch_val {
+ struct switch_attr *attr;
+ int len;
+ int err;
+ int port_vlan;
+ union {
+ char *s;
+ int i;
+ struct switch_port *ports;
+ } value;
+};
+
+struct switch_attr {
+ struct switch_dev *dev;
+ int atype;
+ int id;
+ int type;
+ char *name;
+ char *description;
+ struct switch_attr *next;
+};
+
+struct switch_port {
+ unsigned int id;
+ unsigned int flags;
+};
+
+struct switch_portmap {
+ unsigned int virt;
+ char *segment;
+};
+
+/**
+ * swlib_list: list all switches
+ */
+void swlib_list(void);
+
+/**
+ * swlib_print_portmap: get portmap
+ * @dev: switch device struct
+ */
+void swlib_print_portmap(struct switch_dev *dev, char *segment);
+
+/**
+ * swlib_connect: connect to the switch through netlink
+ * @name: name of the ethernet interface,
+ *
+ * if name is NULL, it connect and builds a chain of all switches
+ */
+struct switch_dev *swlib_connect(const char *name);
+
+/**
+ * swlib_free: free all dynamically allocated data for the switch connection
+ * @dev: switch device struct
+ *
+ * all members of a switch device chain (generated by swlib_connect(NULL))
+ * must be freed individually
+ */
+void swlib_free(struct switch_dev *dev);
+
+/**
+ * swlib_free_all: run swlib_free on all devices in the chain
+ * @dev: switch device struct
+ */
+void swlib_free_all(struct switch_dev *dev);
+
+/**
+ * swlib_scan: probe the switch driver for available commands/attributes
+ * @dev: switch device struct
+ */
+int swlib_scan(struct switch_dev *dev);
+
+/**
+ * swlib_lookup_attr: look up a switch attribute
+ * @dev: switch device struct
+ * @type: global, port or vlan
+ * @name: name of the attribute
+ */
+struct switch_attr *swlib_lookup_attr(struct switch_dev *dev,
+ enum swlib_attr_group atype, const char *name);
+
+/**
+ * swlib_set_attr: set the value for an attribute
+ * @dev: switch device struct
+ * @attr: switch attribute struct
+ * @val: attribute value pointer
+ * returns 0 on success
+ */
+int swlib_set_attr(struct switch_dev *dev, struct switch_attr *attr,
+ struct switch_val *val);
+
+/**
+ * swlib_set_attr_string: set the value for an attribute with type conversion
+ * @dev: switch device struct
+ * @attr: switch attribute struct
+ * @port_vlan: port or vlan (if applicable)
+ * @str: string value
+ * returns 0 on success
+ */
+int swlib_set_attr_string(struct switch_dev *dev, struct switch_attr *attr,
+ int port_vlan, const char *str);
+
+/**
+ * swlib_get_attr: get the value for an attribute
+ * @dev: switch device struct
+ * @attr: switch attribute struct
+ * @val: attribute value pointer
+ * returns 0 on success
+ * for string attributes, the result string must be freed by the caller
+ */
+int swlib_get_attr(struct switch_dev *dev, struct switch_attr *attr,
+ struct switch_val *val);
+
+/**
+ * swlib_apply_from_uci: set up the switch from a uci configuration
+ * @dev: switch device struct
+ * @p: uci package which contains the desired global config
+ */
+int swlib_apply_from_uci(struct switch_dev *dev, struct uci_package *p);
+
+#endif
diff --git a/package/network/config/swconfig/src/uci.c b/package/network/config/swconfig/src/uci.c
new file mode 100644
index 0000000..bbeeb03
--- /dev/null
+++ b/package/network/config/swconfig/src/uci.c
@@ -0,0 +1,246 @@
+/*
+ * uci.c: UCI binding for the switch configuration utility
+ *
+ * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundatio.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <stdint.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <uci.h>
+
+#include <linux/types.h>
+#include <linux/netlink.h>
+#include <linux/genetlink.h>
+#include <netlink/netlink.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+#include <linux/switch.h>
+#include "swlib.h"
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+#endif
+
+struct swlib_setting {
+ struct switch_attr *attr;
+ const char *name;
+ int port_vlan;
+ const char *val;
+ struct swlib_setting *next;
+};
+
+struct swlib_setting early_settings[] = {
+ { .name = "reset", .val = "1" },
+ { .name = "enable_vlan", .val = "1" },
+};
+
+static struct swlib_setting *settings;
+static struct swlib_setting **head;
+
+static bool swlib_match_name(struct switch_dev *dev, const char *name)
+{
+ return (strcmp(name, dev->dev_name) == 0 ||
+ strcmp(name, dev->alias) == 0);
+}
+
+static int
+swlib_map_settings(struct switch_dev *dev, int type, int port_vlan, struct uci_section *s)
+{
+ struct swlib_setting *setting;
+ struct switch_attr *attr;
+ struct uci_element *e;
+ struct uci_option *o;
+
+ uci_foreach_element(&s->options, e) {
+ o = uci_to_option(e);
+
+ if (o->type != UCI_TYPE_STRING)
+ continue;
+
+ if (!strcmp(e->name, "device"))
+ continue;
+
+ /* map early settings */
+ if (type == SWLIB_ATTR_GROUP_GLOBAL) {
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(early_settings); i++) {
+ if (strcmp(e->name, early_settings[i].name) != 0)
+ continue;
+
+ early_settings[i].val = o->v.string;
+ goto skip;
+ }
+ }
+
+ attr = swlib_lookup_attr(dev, type, e->name);
+ if (!attr)
+ continue;
+
+ setting = malloc(sizeof(struct swlib_setting));
+ memset(setting, 0, sizeof(struct swlib_setting));
+ setting->attr = attr;
+ setting->port_vlan = port_vlan;
+ setting->val = o->v.string;
+ *head = setting;
+ head = &setting->next;
+skip:
+ continue;
+ }
+}
+
+int swlib_apply_from_uci(struct switch_dev *dev, struct uci_package *p)
+{
+ struct switch_attr *attr;
+ struct uci_element *e;
+ struct uci_section *s;
+ struct uci_option *o;
+ struct uci_ptr ptr;
+ struct switch_val val;
+ int i;
+
+ settings = NULL;
+ head = &settings;
+
+ uci_foreach_element(&p->sections, e) {
+ struct uci_element *n;
+
+ s = uci_to_section(e);
+
+ if (strcmp(s->type, "switch") != 0)
+ continue;
+
+ uci_foreach_element(&s->options, n) {
+ struct uci_option *o = uci_to_option(n);
+
+ if (strcmp(n->name, "name") != 0)
+ continue;
+
+ if (o->type != UCI_TYPE_STRING)
+ continue;
+
+ if (swlib_match_name(dev, o->v.string))
+ goto found;
+
+ break;
+ }
+
+ if (!swlib_match_name(dev, e->name))
+ continue;
+
+ goto found;
+ }
+
+ /* not found */
+ return -1;
+
+found:
+ /* look up available early options, which need to be taken care
+ * of in the correct order */
+ for (i = 0; i < ARRAY_SIZE(early_settings); i++) {
+ early_settings[i].attr = swlib_lookup_attr(dev,
+ SWLIB_ATTR_GROUP_GLOBAL, early_settings[i].name);
+ }
+ swlib_map_settings(dev, SWLIB_ATTR_GROUP_GLOBAL, 0, s);
+
+ /* look for port or vlan sections */
+ uci_foreach_element(&p->sections, e) {
+ struct uci_element *os;
+ s = uci_to_section(e);
+
+ if (!strcmp(s->type, "switch_port")) {
+ char *devn, *port, *port_err = NULL;
+ int port_n;
+
+ uci_foreach_element(&s->options, os) {
+ o = uci_to_option(os);
+ if (o->type != UCI_TYPE_STRING)
+ continue;
+
+ if (!strcmp(os->name, "device")) {
+ devn = o->v.string;
+ if (!swlib_match_name(dev, devn))
+ devn = NULL;
+ } else if (!strcmp(os->name, "port")) {
+ port = o->v.string;
+ }
+ }
+ if (!devn || !port || !port[0])
+ continue;
+
+ port_n = strtoul(port, &port_err, 0);
+ if (port_err && port_err[0])
+ continue;
+
+ swlib_map_settings(dev, SWLIB_ATTR_GROUP_PORT, port_n, s);
+ } else if (!strcmp(s->type, "switch_vlan")) {
+ char *devn, *vlan, *vlan_err = NULL;
+ int vlan_n;
+
+ uci_foreach_element(&s->options, os) {
+ o = uci_to_option(os);
+ if (o->type != UCI_TYPE_STRING)
+ continue;
+
+ if (!strcmp(os->name, "device")) {
+ devn = o->v.string;
+ if (!swlib_match_name(dev, devn))
+ devn = NULL;
+ } else if (!strcmp(os->name, "vlan")) {
+ vlan = o->v.string;
+ }
+ }
+ if (!devn || !vlan || !vlan[0])
+ continue;
+
+ vlan_n = strtoul(vlan, &vlan_err, 0);
+ if (vlan_err && vlan_err[0])
+ continue;
+
+ swlib_map_settings(dev, SWLIB_ATTR_GROUP_VLAN, vlan_n, s);
+ }
+ }
+
+ for (i = 0; i < ARRAY_SIZE(early_settings); i++) {
+ struct swlib_setting *st = &early_settings[i];
+ if (!st->attr || !st->val)
+ continue;
+ swlib_set_attr_string(dev, st->attr, st->port_vlan, st->val);
+
+ }
+
+ while (settings) {
+ struct swlib_setting *st = settings;
+
+ swlib_set_attr_string(dev, st->attr, st->port_vlan, st->val);
+ st = st->next;
+ free(settings);
+ settings = st;
+ }
+
+ /* Apply the config */
+ attr = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_GLOBAL, "apply");
+ if (!attr)
+ return 0;
+
+ memset(&val, 0, sizeof(val));
+ swlib_set_attr(dev, attr, &val);
+
+ return 0;
+}