diff --git a/fping/Makefile b/fping/Makefile deleted file mode 100644 index b0f3ae722..000000000 --- a/fping/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -# -# Copyright (C) 2016 Nikil Mehta -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# - -include $(TOPDIR)/rules.mk - -PKG_NAME:=fping -PKG_VERSION:=4.0 -PKG_RELEASE:=2 - -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=http://fping.org/dist/ -PKG_HASH:=67eb4152b98ad34f99d2eec4e1098a0bb52caf13c0c89cd147349d08190fe8ce - -PKG_MAINTAINER:=Nikil Mehta -PKG_LICENSE:=BSD-4-Clause -PKG_LICENSE_FILES:=COPYING - -PKG_INSTALL:=1 - -include $(INCLUDE_DIR)/package.mk - -define Package/fping - SECTION:=net - CATEGORY:=Network - TITLE:=sends ICMP ECHO_REQUEST packets to network hosts - URL:=http://fping.org/ -endef - - -define Package/fping/description - fping is a ping like program which uses the Internet Control Message Protocol - (ICMP) echo request to determine if a target host is responding. fping - differs from ping in that you can specify any number of targets on the command - line, or specify a file containing the lists of targets to ping. Instead of - sending to one target until it times out or replies, fping will send out a - ping packet and move on to the next target in a round-robin fashion. -endef - -CONFIGURE_ARGS+= \ - --enable-ipv4 \ - --enable-ipv6 - -TARGET_CFLAGS += -std=gnu99 - -define Package/fping/install - $(INSTALL_DIR) $(1)/usr/bin - $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/fping $(1)/usr/bin/ -endef - -$(eval $(call BuildPackage,fping)) diff --git a/icgroupd/Makefile b/icgroupd/Makefile deleted file mode 100644 index 7d24d2fda..000000000 --- a/icgroupd/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -# -# Copyright (C) 2019 iopsys Software Solutions AB -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# - -include $(TOPDIR)/rules.mk - -PKG_NAME:=icgroupd -PKG_VERSION:=1.0 -PKG_RELEASE:=0 - -PKG_LICENSE:=GPL-2.0 -PKG_LICENSE_FILES:= - -PKG_MAINTAINER:=Inteno Broadband AB - -include $(INCLUDE_DIR)/package.mk - -define Package/icgroupd - SECTION:=base - CATEGORY:=Base system - TITLE:=Inteno cgroup daemon - DEPENDS:=+uci +busybox -endef - -define Package/icgroupd/description - This package contains Intenos cgroup daemon and associated - configuration and startup scripts. -endef - -define Build/Compile - true -endef - -define Package/icgroupd/install - $(INSTALL_DIR) $(1)/sbin $(1)/etc/init.d $(1)/etc/config - - $(INSTALL_CONF) ./files/cgroups.config $(1)/etc/config/cgroups - $(INSTALL_BIN) ./files/cgroups.init $(1)/etc/init.d/cgroups - $(INSTALL_BIN) ./files/cgroupd $(1)/sbin/ -endef - -$(eval $(call BuildPackage,icgroupd)) - diff --git a/icgroupd/files/cgroupd b/icgroupd/files/cgroupd deleted file mode 100755 index 90da0e95d..000000000 --- a/icgroupd/files/cgroupd +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh - -CGBASEDIR=$1 -CGCONFIG=$2 -[ -n "$CGBASEDIR" -a -n "$CGCONFIG" ] || exit 1 - -[ -r /lib/functions.sh ] || exit 1 -. /lib/functions.sh - -CGPROCMAP=/tmp/cgprocmap -CGPERIOD=3s - -DBGLOG=/tmp/cgroupd.log -DEBUG=0 - - -add_to_procmap () { - local name_grp=$1 - local name grp - - name=$(echo $name_grp |awk -F= '{print $1}') - grp=$(echo $name_grp |awk -F= '{print $2}') - - echo "($name) $grp" >> $CGPROCMAP -} - -# Read configuration file and create process:group look-up table -# in /tmp file -read_config () { - local enab - - config_load $CGCONFIG - - config_get enab cgroups enabled "1" - [ $enab -eq 0 ] && exit 1 - - config_get CGDEFGROUP cgroups defgroup "_undef_" - [ "$CGDEFGROUP" == "_undef_" ] && exit 1 - [ "$DEBUG" == "1" ] && echo "default $CGDEFGROUP" >> $DBGLOG - - echo -n '' > $CGPROCMAP - config_list_foreach procmap procmap add_to_procmap - [ "$DEBUG" == "1" ] && cat $CGPROCMAP >> $DBGLOG -} - -# Move all process except init from cgroup root to cgroups according -# to /tmp look-up table -move_wild_procs () { - local wild_procs=$(cat $CGBASEDIR/cgroup.procs) - local pid name grp - - for pid in $wild_procs; do - - [ $pid -eq 1 ] && continue - if [ -d /proc/$pid ]; then - - name=$(awk '{print $2}' /proc/$pid/stat) - grp=$(awk "\$1==\"$name\" {print \$2}" $CGPROCMAP) - - [ "$grp" == "." ] && continue - [ -n "$grp" ] || grp=$CGDEFGROUP - - [ "$DEBUG" == "1" ] && \ - echo "Moving proc $pid $name to $grp" >> $DBGLOG - echo $pid > $CGBASEDIR/$grp/cgroup.procs - fi - done -} - - -[ "$DEBUG" == "1" ] && echo "$0 started $(date)" >> $DBGLOG -read_config -while true; do - move_wild_procs - sleep $CGPERIOD -done diff --git a/icgroupd/files/cgroups.config b/icgroupd/files/cgroups.config deleted file mode 100644 index 36d736b79..000000000 --- a/icgroupd/files/cgroups.config +++ /dev/null @@ -1,48 +0,0 @@ -config cgroups cgroups - option enabled 1 - option defgroup iopsys/normal - -config cgroup _root_ -# list option cpu.rt_runtime_us=50000 - list option memory.move_charge_at_immigrate=1 - -config cgroup iopsys - list option cpu.shares=4096 -# list option cpu.rt_runtime_us=40000 - list option memory.limit_in_bytes=-1 - list option memory.move_charge_at_immigrate=1 - -config cgroup iopsys_normal - list option cpu.shares=1024 -# list option cpu.rt_runtime_us=10000 - list option memory.limit_in_bytes=-1 - list option memory.move_charge_at_immigrate=1 - -config cgroup iopsys_high - list option cpu.shares=4096 -# list option cpu.rt_runtime_us=30000 - list option memory.limit_in_bytes=-1 - list option memory.move_charge_at_immigrate=1 - -config cgroup 3prt - list option cpu.shares=1024 -# list option cpu.rt_runtime_us=10000 - list option memory.limit_in_bytes=75M - list option memory.move_charge_at_immigrate=1 - -config cgroup 3prt_normal - list option cpu.shares=1024 -# list option cpu.rt_runtime_us=2500 - list option memory.limit_in_bytes=75M - list option memory.move_charge_at_immigrate=1 - -config cgroup 3prt_high - list option cpu.shares=4096 -# list option cpu.rt_runtime_us=7500 - list option memory.limit_in_bytes=75M - list option memory.move_charge_at_immigrate=1 - -config procmap procmap - list procmap kthreadd=. - list procmap minidlna=3prt/normal - diff --git a/icgroupd/files/cgroups.init b/icgroupd/files/cgroups.init deleted file mode 100755 index 7834e2b30..000000000 --- a/icgroupd/files/cgroups.init +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/sh /etc/rc.common - -START=01 -USE_PROCD=1 -PROCD_DEBUG=1 -NAME=cgroupd - -CGBASEDIR=/sys/fs/cgroup -CGCONFIG="cgroups" - -DBGLOG=/tmp/cginit.log -DEBUG=0 - - -cgroupinit_set_knob_value () { - local knob_val=$1 - local dir=$2 - local knob val - - knob=$(echo $knob_val |awk -F= '{print $1}') - val=$(echo $knob_val |awk -F= '{print $2}') - /bin/echo $val > $CGBASEDIR/$dir/$knob - [ "$DEBUG" == "1" ] && \ - echo "/bin/echo $val > $CGBASEDIR/$dir/$knob (ret=$?)" >> $DBGLOG -} - -cgroupinit_create_group () { - local cgrp=$1 - local dir - - [ "$DEBUG" == "1" ] && echo "Create group $cgrp:" >> $DBGLOG - if [ "$cgrp" == "_root_" ]; then - dir=. - else - dir=$(echo $cgrp |tr '_' '/') - - if [ ! -d $CGBASEDIR/$dir ]; then - mkdir $CGBASEDIR/$dir - [ "$DEBUG" == "1" ] && \ - echo "mkdir $CGBASEDIR/$dir (ret=$?)" >> $DBGLOG - fi - fi - - config_list_foreach $cgrp option cgroupinit_set_knob_value $dir -} - -cgroupinit_configure_cgroups () { - local enab defgrp - - [ "$DEBUG" == "1" ] && echo "$0 started $(date)" >> $DBGLOG - config_load $CGCONFIG - - config_get enab cgroups enabled "1" - [ $enab -eq 0 ] && return 1 - - config_get defgrp cgroups defgroup "_undef_" - [ "$defgrp" == "_undef_" ] && return 1 - - if ! grep -q " $CGBASEDIR cgroup " /proc/mounts; then - mount -t cgroup -o nodev,noexec,nosuid cgroup $CGBASEDIR - [ $? -eq 0 ] || return 1 - fi - - config_foreach cgroupinit_create_group cgroup - return 0 -} - -start_service () { - cgroupinit_configure_cgroups - [ $? -eq 0 ] || return - - procd_open_instance - procd_set_param command /sbin/cgroupd $CGBASEDIR $CGCONFIG - procd_set_param respawn - procd_close_instance -} - -stop_service () { - local cgdir procs prc - - for cgdir in $(find $CGBASEDIR -type d -mindepth 1 -depth); do - procs=$(cat $cgdir/cgroup.procs) - for prc in $procs; do - echo $prc > $CGBASEDIR/cgroup.procs - done - rmdir $cgdir - done -} - -service_triggers() { - procd_add_reload_trigger $CGCONFIG -} - diff --git a/ifbt/Makefile b/ifbt/Makefile deleted file mode 100644 index 0d90bf5b1..000000000 --- a/ifbt/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -# -# Copyright (C) 2018 iopsys Software Solutions AB -# - -include $(TOPDIR)/rules.mk -include $(INCLUDE_DIR)/kernel.mk - -PKG_NAME:=ifbt -PKG_VERSION:=0.3 - -PKG_SOURCE_VERSION:=c9a7db18b15a59b03b756d00a0a630e98d9541c5 -PKG_SOURCE_PROTO:=git -PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/ifbt.git - -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz -PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) -PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) - -PKG_LICENSE:=BSD-3-Clause -PKG_LICENSE_FILES:=README - -include $(INCLUDE_DIR)/package.mk - -ifeq ($(CONFIG_TARGET_iopsys_brcm63xx_mips),y) -TARGET_PLATFORM:=-DIOPSYS_BROADCOM -else ifeq ($(CONFIG_TARGET_iopsys_brcm63xx_arm),y) -TARGET_PLATFORM:=-DIOPSYS_BROADCOM -else ifeq ($(CONFIG_TARGET_iopsys_linksys),y) -TARGET_PLATFORM:=-DIOPSYS_MARVELL -else ifeq ($(CONFIG_TARGET_intel_mips),y) -TARGET_PLATFORM:=-DIOPSYS_INTEL -else ifeq ($(CONFIG_TARGET_iopsys_ramips),y) -TARGET_PLATFORM:=-DIOPSYS_MEDIATEK -else -$(info (UNEXPECTED CONFIG TARGET)) -endif - -export TARGET_PLATFORM - -define Package/ifbt - CATEGORY:=Utilities - DEPENDS:=+libuci +libubox +libubus +libblobmsg-json +libjson-c +libwifi +libjson-c - TITLE:=Fast BSS Transition -endef - -define Package/ifbt/description - ifbt is Iopsys application for fast BSS transition -endef - -define Package/ifbt/install - $(INSTALL_DIR) $(1)/sbin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/ifbt $(1)/sbin/ -endef - -$(eval $(call BuildPackage,ifbt)) diff --git a/libcgroup/Makefile b/libcgroup/Makefile deleted file mode 100644 index 82c2400ab..000000000 --- a/libcgroup/Makefile +++ /dev/null @@ -1,105 +0,0 @@ -# -# Copyright (C) 2016 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:=libcgroup -PKG_VERSION:=0.41 -PKG_RELEASE:=1 - -PKG_LICENSE:=LGPL-2.1 -PKG_LICENSE_FILES:=COPYING - -PKG_SOURCE_VERSION:=2186c97f60df7efe86ddadd5e3d9d36dd4923b98 - -PKG_SOURCE_URL:=git://git.code.sf.net/p/libcg/libcg -PKG_SOURCE_PROTO:=git -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)+git$(PKG_SOURCE_VERSION).tar.gz -PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) - -#PKG_BUILD_PARALLEL:=1 -PKG_FIXUP:=autoreconf - -# run install target when cross compiling. basically, make install DESTDIR=$(PKG_INSTALL_DIR) -# this way we don't need to pick out the resulting files from the build dir. -PKG_INSTALL:=1 - -include $(INCLUDE_DIR)/package.mk - -define Package/libcgroup - SECTION:=libs - CATEGORY:=Libraries - DEPENDS:=+libpthread - TITLE:=Control group configuration library - URL:=https://sourceforge.net/p/libcg/ -endef - -define Package/libcgroup/description - Control groups, a new kernel feature in Linux 2.6.24 provides a file system - interface to manipulate and control the details on task grouping including - creation of new task groups (control groups), permission handling and task - assignment. -endef - -define Package/libcgroup-daemon - SECTION:=base - CATEGORY:=Base system - DEPENDS:=+libcgroup +librt - TITLE:=Control group management daemon - URL:=https://sourceforge.net/p/libcg/ -endef - -define Package/libcgroup-utils - SECTION:=utils - CATEGORY:=Utilities - DEPENDS:=+libcgroup - TITLE:=Control group configuration utilities - URL:=https://sourceforge.net/p/libcg/ -endef - -#define Package/libcgroup/conffiles -# /etc/config/cgroups -#endef - -CONFIGURE_ARGS += \ - --disable-bindings \ - --disable-pam \ - --enable-static \ - -define Build/InstallDev - $(INSTALL_DIR) $(1)/usr/include/libcgroup - $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/include/*.h $(1)/usr/include/ - $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/include/libcgroup/*.h $(1)/usr/include/libcgroup/ - - $(INSTALL_DIR) $(1)/usr/lib $(1)/usr/lib/pkgconfig - $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libcgroup.* $(1)/usr/lib/ - $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libcgroup.pc $(1)/usr/lib/pkgconfig/ -endef - -define Package/libcgroup/install - $(INSTALL_DIR) $(1)/usr/lib - $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libcgroup.so* $(1)/usr/lib/ -endef - -define Package/libcgroup-daemon/install - $(INSTALL_DIR) $(1)/usr/sbin - $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/* $(1)/usr/sbin - - # move to its own package? - $(INSTALL_DIR) $(1)/etc/config $(1)/etc/init.d - $(INSTALL_CONF) ./files/cgroups.config $(1)/etc/config/cgroups - $(INSTALL_BIN) ./files/cgroups.init $(1)/etc/init.d/cgroups -endef - -define Package/libcgroup-utils/install - $(INSTALL_DIR) $(1)/usr/bin - $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/* $(1)/usr/bin -endef - -#$(eval $(call BuildPackage,libcgroup)) -#$(eval $(call BuildPackage,libcgroup-daemon)) -#$(eval $(call BuildPackage,libcgroup-utils)) diff --git a/libcgroup/files/cgroups.config b/libcgroup/files/cgroups.config deleted file mode 100644 index 896f32a26..000000000 --- a/libcgroup/files/cgroups.config +++ /dev/null @@ -1,40 +0,0 @@ -config cgroups cgroups - option enabled 1 - option defgroup iopsys/normal - -config cgroup _root_ - list option memory.move_charge_at_immigrate=1 - -config cgroup iopsys - list option cpu.shares=4096 - list option memory.limit_in_bytes=-1 - list option memory.move_charge_at_immigrate=1 - -config cgroup iopsys_normal - list option cpu.shares=1024 - list option memory.limit_in_bytes=-1 - list option memory.move_charge_at_immigrate=1 - -config cgroup iopsys_high - list option cpu.shares=4096 - list option memory.limit_in_bytes=-1 - list option memory.move_charge_at_immigrate=1 - -config cgroup 3prt - list option cpu.shares=1024 - list option memory.limit_in_bytes=75M - list option memory.move_charge_at_immigrate=1 - -config cgroup 3prt_normal - list option cpu.shares=1024 - list option memory.limit_in_bytes=75M - list option memory.move_charge_at_immigrate=1 - -config cgroup 3prt_high - list option cpu.shares=4096 - list option memory.limit_in_bytes=75M - list option memory.move_charge_at_immigrate=1 - -config procmap procmap - list procmap minidlna=3prt/normal - diff --git a/libcgroup/files/cgroups.init b/libcgroup/files/cgroups.init deleted file mode 100755 index 283b00977..000000000 --- a/libcgroup/files/cgroups.init +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/sh /etc/rc.common - -START=01 -USE_PROCD=1 -#PROCD_DEBUG=1 -NAME=cgrulesengd - -CGBASEDIR=/sys/fs/cgroup -CGCONFIG="cgroups" - -CGRULESCONF=/tmp/cgrules.conf -CGCONFIGCONF=/tmp/cgconfig.conf - - -cgroupinit_add_knob_val_to_list () { -CG_KNOB_VAL_LIST="$CG_KNOB_VAL_LIST -$1" -} - -cgroupinit_create_group () { - local cgrp=$1 - local dir curr - - if [ "$cgrp" == "_root_" ]; then - dir=. - else - dir=$(echo $cgrp |tr '_' '/') - fi - - echo -e "group $dir {" >> $CGCONFIGCONF - - CG_KNOB_VAL_LIST= - config_list_foreach $cgrp option cgroupinit_add_knob_val_to_list - CG_KNOB_VAL_LIST=$(echo "$CG_KNOB_VAL_LIST" |sort) - curr="_none_" - - for knob_val in $CG_KNOB_VAL_LIST ; do - local ctrlr knob val - - knob=$(echo $knob_val |awk -F= '{print $1}') - ctrlr=$(echo $knob |awk -F. '{print $1}') - val=$(echo $knob_val |awk -F= '{print $2}') - - if [ "$curr" != "$ctrlr" ]; then - [ "$curr" == "_none_" ] || echo -e "\t}" >> $CGCONFIGCONF - curr=$ctrlr - echo -e "\t$curr {" >> $CGCONFIGCONF - fi - - echo -e "\t\t$knob = \"$val\";" >> $CGCONFIGCONF - done - - [ "$curr" == "_none_" ] || echo -e "\t}" >> $CGCONFIGCONF - echo -e "}\n" >> $CGCONFIGCONF -} - -cgroupinit_add_to_rules () { - local name_grp=$1 - local name grp - - name=$(echo $name_grp |awk -F= '{print $1}') - grp=$(echo $name_grp |awk -F= '{print $2}') - - echo -e "*:$name\t*\t$grp" >> $CGRULESCONF -} - -cgroupinit_generate_config () { - local enab defgrp - - config_load $CGCONFIG - - config_get enab cgroups enabled "1" - [ $enab -eq 0 ] && return 1 - - config_get defgrp cgroups defgroup "_undef_" - [ "$defgrp" == "_undef_" ] && return 1 - - # mount here instead of in cgconfigparser to get all options right - # mounting without any controllers listed means mount all available - if ! grep -q " $CGBASEDIR cgroup " /proc/mounts; then - mount -t cgroup -o nodev,noexec,nosuid cgroup $CGBASEDIR - [ $? -eq 0 ] || return 1 - fi - - echo -n '' > $CGCONFIGCONF - config_foreach cgroupinit_create_group cgroup - - echo -n '' > $CGRULESCONF - config_list_foreach procmap procmap cgroupinit_add_to_rules - echo -e "*\t*\t$defgrp" >> $CGRULESCONF - - return 0 -} - -# cgrulesengd has hardcoded paths for configuration files -# use symlinks to point to generated config files -cgroupinit_cgrulesengd_fixup () { - [ -r /etc/cgrules.conf ] || ln -s $CGRULESCONF /etc/cgrules.conf - [ -r /etc/cgconfig.conf ] || ln -s $CGCONFIGCONF /etc/cgconfig.conf - [ -d /etc/cgconfig.d ] || mkdir /etc/cgconfig.d -} - -start_service () { - cgroupinit_generate_config - [ $? -eq 0 ] || return - - cgroupinit_cgrulesengd_fixup - /usr/sbin/cgconfigparser -l $CGCONFIGCONF || return - - procd_open_instance - procd_set_param command /usr/sbin/cgrulesengd --nodaemon --syslog - procd_set_param respawn - procd_close_instance -} - -stop_service () { - /usr/sbin/cgclear -} - -service_triggers() { - procd_add_reload_trigger $CGCONFIG -} - diff --git a/logrotate/Makefile b/logrotate/Makefile deleted file mode 100644 index 6b3f79e16..000000000 --- a/logrotate/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -# -# Copyright (C) 2006 OpenWrt.org -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# -# $Id$ - -include $(TOPDIR)/rules.mk - -PKG_NAME:=logrotate -PKG_VERSION:=3.7.1 -PKG_RELEASE:=1 - -PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).orig.tar.gz -PKG_SOURCE_URL:=http://ftp.de.debian.org/debian/pool/main/l/logrotate -PKG_MD5SUM:=552639142e163745f6bcd4f1f3816d8a -PKG_CAT:=zcat - -PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) - -PKG_LICENSE:=GPLv2 -PKG_LICENSE_FILES:=COPYING - -include $(INCLUDE_DIR)/package.mk - -define Package/logrotate - SECTION:=utils - CATEGORY:=Utilities - DEPENDS:=+libpopt - TITLE:=rotates, compresses, and mails system logs -endef - -define Build/Compile - $(call Build/Compile/Default, \ - RPM_OPT_FLAGS="$(TARGET_CFLAGS) $(EXTRA_CPPFLAGS)" \ - LDFLAGS="$(EXTRA_LDFLAGS)" \ - logrotate \ - ) -endef - -define Package/logrotate/install - $(INSTALL_DIR) $(1)/usr/sbin - $(CP) ${PKG_BUILD_DIR}/logrotate $(1)/usr/sbin/ - $(INSTALL_DIR) $(1)/etc - $(CP) ./files/logrotate.conf $(1)/etc/ - $(INSTALL_DIR) $(1)/etc/logrotate.d -endef - -$(eval $(call BuildPackage,logrotate)) diff --git a/logrotate/files/logrotate.conf b/logrotate/files/logrotate.conf deleted file mode 100644 index 9a91db94f..000000000 --- a/logrotate/files/logrotate.conf +++ /dev/null @@ -1,30 +0,0 @@ -# rotate log files weekly -weekly -#daily - -# keep 4 weeks worth of backlogs -rotate 4 - -# create new (empty) log files after rotating old ones -create - -notifempty -nomail -#olddir /var/log/backup/ -missingok -#dateext - -# uncomment this if you want your log files compressed -#compress - -# packages can drop log rotation information into this directory -include /etc/logrotate.d - -# no packages own lastlog or wtmp -- we'll rotate them here -#/var/log/wtmp { -# monthly -# create 0664 root utmp -# rotate 1 -#} - -# system-specific logs may be also be configured here. diff --git a/logrotate/patches/01-dateext_maxage.patch b/logrotate/patches/01-dateext_maxage.patch deleted file mode 100644 index 1623b4bf1..000000000 --- a/logrotate/patches/01-dateext_maxage.patch +++ /dev/null @@ -1,433 +0,0 @@ -diff -u -ruN logrotate-3.7.1.orig/config.c logrotate-3.7.1/config.c ---- logrotate-3.7.1.orig/config.c 2003-08-07 07:13:14.000000000 -0400 -+++ logrotate-3.7.1/config.c 2005-05-24 12:21:09.000000000 -0400 -@@ -511,6 +511,14 @@ - newlog->flags &= ~LOG_FLAG_IFEMPTY; - - *endtag = oldchar, start = endtag; -+ } else if (!strcmp(start, "dateext")) { -+ newlog->flags |= LOG_FLAG_DATEEXT; -+ -+ *endtag = oldchar, start = endtag; -+ } else if (!strcmp(start, "nodateext")) { -+ newlog->flags &= ~LOG_FLAG_DATEEXT; -+ -+ *endtag = oldchar, start = endtag; - } else if (!strcmp(start, "noolddir")) { - newlog->oldDir = NULL; - -@@ -670,6 +678,21 @@ - } - *endtag = oldchar, start = endtag; - } -+ } else if (!strcmp(start, "maxage")) { -+ *endtag = oldchar, start = endtag; -+ -+ if (!isolateValue(configFile, lineNum, "maxage count", &start, -+ &endtag)) { -+ oldchar = *endtag, *endtag = '\0'; -+ -+ newlog->rotateAge = strtoul(start, &chptr, 0); -+ if (*chptr || newlog->rotateAge < 0) { -+ message(MESS_ERROR, "%s:%d bad maximum age '%s'\n", -+ configFile, lineNum, start); -+ return 1; -+ } -+ *endtag = oldchar, start = endtag; -+ } - } else if (!strcmp(start, "errors")) { - message(MESS_DEBUG, "%s: %d: the errors directive is deprecated and no longer used.\n", - configFile, lineNum); -diff -u -ruN logrotate-3.7.1.orig/logrotate.8 logrotate-3.7.1/logrotate.8 ---- logrotate-3.7.1.orig/logrotate.8 2003-08-07 07:13:14.000000000 -0400 -+++ logrotate-3.7.1/logrotate.8 2005-05-24 12:21:09.000000000 -0400 -@@ -200,6 +200,11 @@ - Log files are rotated every day. - - .TP -+\fBdateext\fR -+Archive old versions of log files adding a daily extension like YYYYMMDD -+instead of simply adding a number. -+ -+.TP - \fBdelaycompress\fR - Postpone compression of the previous log file to the next rotation cycle. - This has only effect when used in combination with \fBcompress\fR. -@@ -246,6 +251,12 @@ - instead of the just-rotated file (this is the default). - - .TP -+\fBmaxage\fR \fIcount\fR -+Remove rotated logs older than days. The age is only checked -+if the logfile is to be rotated. The files are mailed to the -+configured address if \fBmaillast\fR and \fBmail\fR are configured. -+ -+.TP - \fBmissingok\fR - If the log file is missing, go on to the next one without issuing an error - message. See also \fBnomissingok\fR. -diff -u -ruN logrotate-3.7.1.orig/logrotate.c logrotate-3.7.1/logrotate.c ---- logrotate-3.7.1.orig/logrotate.c 2004-10-19 17:41:24.000000000 -0400 -+++ logrotate-3.7.1/logrotate.c 2005-05-24 12:21:09.000000000 -0400 -@@ -11,6 +11,7 @@ - #include - #include - #include -+#include - - #ifdef WITH_SELINUX - #include -@@ -22,6 +23,10 @@ - #include "log.h" - #include "logrotate.h" - -+#if !defined(GLOB_ABORTED) && defined(GLOB_ABEND) -+#define GLOB_ABORTED GLOB_ABEND -+#endif -+ - typedef struct { - char * fn; - struct tm lastRotated; /* only tm.mon, tm_mday, tm_year are good! */ -@@ -42,6 +47,14 @@ - char * mailCommand = DEFAULT_MAIL_COMMAND; - time_t nowSecs = 0; - -+static int globerr(const char * pathname, int theerr) { -+ message(MESS_ERROR, "error accessing %s: %s\n", pathname, -+ strerror(theerr)); -+ -+ /* We want the glob operation to continue, so return 0 */ -+ return 1; -+} -+ - static logState * findState(const char * fn, struct stateSet * sip) { - int i; - logState * states = sip->states; -@@ -49,9 +62,11 @@ - struct tm now = *localtime(&nowSecs); - time_t lr_time; - -+ /* find the filename fn in the statesPtr list */ - for (i = 0; i < numStates; i++) - if (!strcmp(fn, states[i].fn)) break; - -+ /* not in statesPtr list, so add new entry */ - if (i == numStates) { - i = numStates++; - states = realloc(states, sizeof(*states) * numStates); -@@ -121,6 +136,17 @@ - return rc; - } - -+static int removeLogFile(char * name) { -+ message(MESS_DEBUG, "removing old log %s\n", name); -+ -+ if (!debug && unlink(name)) { -+ message(MESS_ERROR, "Failed to remove old log %s: %s\n", -+ name, strerror(errno)); -+ return 1; -+ } -+ return 0; -+} -+ - static int compressLogFile(char * name, logInfo * log, struct stat *sb) { - char * compressedName; - const char ** fullCommand; -@@ -265,6 +291,25 @@ - return rc; - } - -+static int mailLogWrapper (char * mailFilename, char * mailCommand, int logNum, logInfo * log) { -+ /* if the log is compressed (and we're not mailing a -+ * file whose compression has been delayed), we need -+ * to uncompress it */ -+ if ((log->flags & LOG_FLAG_COMPRESS) && -+ !((log->flags & LOG_FLAG_DELAYCOMPRESS) && -+ (log->flags & LOG_FLAG_MAILFIRST))) { -+ if (mailLog(mailFilename, mailCommand, -+ log->uncompress_prog, log->logAddress, -+ log->files[logNum])) -+ return 1; -+ } else { -+ if (mailLog(mailFilename, mailCommand, NULL, -+ log->logAddress, mailFilename)) -+ return 1; -+ } -+ return 0; -+} -+ - static int copyTruncate(char * currLog, char * saveLog, struct stat * sb, int flags) { - char buf[BUFSIZ]; - int fdcurr = -1, fdsave = -1; -@@ -479,6 +524,9 @@ - char * baseName; - char * dirName; - char * firstRotated; -+ char * glob_pattern; -+ glob_t globResult; -+ int rc; - size_t alloc_size; - int rotateCount = log->rotateCount ? log->rotateCount : 1; - int logStart = (log->logStart == -1) ? 1 : log->logStart; -@@ -509,7 +557,7 @@ - - alloc_size = strlen(dirName) + strlen(baseName) + - strlen(log->files[logNum]) + strlen(fileext) + -- strlen(compext) + 10; -+ strlen(compext) + 18; - - oldName = alloca(alloc_size); - newName = alloca(alloc_size); -@@ -531,16 +579,116 @@ - /* First compress the previous log when necessary */ - if (log->flags & LOG_FLAG_COMPRESS && - log->flags & LOG_FLAG_DELAYCOMPRESS) { -- struct stat sbprev; -- -- sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext); -- if (stat(oldName, &sbprev)) { -- message(MESS_DEBUG, "previous log %s does not exist\n", -- oldName); -- } else { -- hasErrors = compressLogFile(oldName, log, &sbprev); -+ if (log->flags & LOG_FLAG_DATEEXT) { -+ /* glob for uncompressed files with our pattern */ -+ glob_pattern = malloc(strlen(dirName) + strlen(baseName) -+ + strlen(fileext) + 44 ); -+ sprintf(glob_pattern, -+ "%s/%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%s", -+ dirName, baseName, fileext); -+ rc = glob(glob_pattern, 0, globerr, &globResult); -+ if (!rc && globResult.gl_pathc > 0) { -+ for (i = 0; i < globResult.gl_pathc && !hasErrors; i++) { -+ struct stat sbprev; -+ sprintf(oldName,"%s",(globResult.gl_pathv)[i]); -+ if (stat(oldName, &sbprev)) { -+ message(MESS_DEBUG, "previous log %s does not exist\n", oldName); -+ } else { -+ hasErrors = compressLogFile(oldName, log, &sbprev); -+ } -+ } -+ } else { -+ message (MESS_DEBUG, "glob finding logs to compress failed\n"); -+ /* fallback to old behaviour */ -+ sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext); -+ } -+ globfree(&globResult); -+ free(glob_pattern); -+ } else { -+ struct stat sbprev; -+ -+ sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext); -+ if (stat(oldName, &sbprev)) { -+ message(MESS_DEBUG, "previous log %s does not exist\n", -+ oldName); -+ } else { -+ hasErrors = compressLogFile(oldName, log, &sbprev); -+ } - } - } -+ -+ firstRotated = alloca(strlen(dirName) + strlen(baseName) + -+ strlen(fileext) + strlen(compext) + 30); -+ -+ if(log->flags & LOG_FLAG_DATEEXT) { -+ /* glob for compressed files with our pattern -+ * and compress ext */ -+ glob_pattern = malloc(strlen(dirName)+strlen(baseName) -+ +strlen(fileext)+strlen(compext)+44); -+ sprintf(glob_pattern, -+ "%s/%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%s%s", -+ dirName, baseName, fileext, compext); -+ rc = glob(glob_pattern, 0, globerr, &globResult); -+ if (!rc) { -+ /* search for files to drop, if we find one remember it, -+ * if we find another one mail and remove the first and -+ * remember the second and so on */ -+ struct stat fst_buf; -+ int mail_out = -1; -+ /* remove the first (n - rotateCount) matches -+ * no real rotation needed, since the files have -+ * the date in their name */ -+ for (i = 0; i < globResult.gl_pathc; i++) { -+ if( !stat((globResult.gl_pathv)[i],&fst_buf) ) { -+ if ((i <= ((int)globResult.gl_pathc - rotateCount)) -+ || ((log->rotateAge > 0) -+ && (((nowSecs - fst_buf.st_mtime)/60/60/24) -+ > log->rotateAge))) { -+ if ( mail_out != -1 ) { -+ if (!hasErrors && log->logAddress) { -+ char * mailFilename = (globResult.gl_pathv)[mail_out]; -+ hasErrors = mailLogWrapper(mailFilename, mailCommand, logNum, log); -+ if (!hasErrors) -+ hasErrors = removeLogFile(mailFilename); -+ } -+ } -+ mail_out = i; -+ } -+ } -+ } -+ if ( mail_out != -1 ) { -+ /* oldName is oldest Backup found (for unlink later) */ -+ sprintf(oldName, "%s", (globResult.gl_pathv)[mail_out]); -+ strcpy(disposeName, oldName); -+ } else -+ disposeName = NULL; -+ } else { -+ message (MESS_DEBUG, "glob finding old rotated logs failed\n"); -+ disposeName = NULL; -+ } -+ /* firstRotated is most recently created/compressed rotated log */ -+ sprintf(firstRotated, "%s/%s-%04d%02d%02d%s%s", -+ dirName, baseName, now.tm_year+1900, -+ now.tm_mon+1, now.tm_mday, fileext, compext); -+ globfree(&globResult); -+ free(glob_pattern); -+ } else { -+ if ( log->rotateAge ) { -+ struct stat fst_buf; -+ for (i=1; i <= rotateCount; i++) { -+ sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName, -+ rotateCount + 1, fileext, compext); -+ if(!stat(oldName,&fst_buf) -+ && (((nowSecs - fst_buf.st_mtime)/60/60/24) -+ > log->rotateAge)) { -+ char * mailFilename = (globResult.gl_pathv)[i]; -+ if (!hasErrors && log->logAddress) -+ hasErrors = mailLogWrapper(mailFilename, mailCommand, logNum, log); -+ if (!hasErrors) -+ hasErrors = removeLogFile(mailFilename); -+ } -+ } -+ } - - sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName, - logStart + rotateCount, fileext, compext); -@@ -548,8 +696,6 @@ - - strcpy(disposeName, oldName); - -- firstRotated = alloca(strlen(dirName) + strlen(baseName) + -- strlen(fileext) + strlen(compext) + 30); - sprintf(firstRotated, "%s/%s.%d%s%s", dirName, baseName, - logStart, fileext, - (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext); -@@ -600,12 +746,27 @@ - } - } - } -- -+ } /* !LOG_FLAG_DATEEXT */ -+ - finalName = oldName; -- -- /* note: the gzip extension is *not* used here! */ -- sprintf(finalName, "%s/%s.%d%s", dirName, baseName, logStart, fileext); -- -+ -+ if(log->flags & LOG_FLAG_DATEEXT) { -+ char * destFile = alloca(strlen(dirName) + strlen(baseName) + -+ strlen(fileext) + strlen(compext) + 30); -+ struct stat fst_buf; -+ sprintf(finalName, "%s/%s-%04d%02d%02d%s", -+ dirName, baseName, now.tm_year+1900, -+ now.tm_mon+1, now.tm_mday, fileext); -+ sprintf(destFile, "%s%s", finalName, compext); -+ if(!stat(destFile,&fst_buf)) { -+ message (MESS_DEBUG, "destination %s already exists, skipping rotation\n", firstRotated); -+ hasErrors = 1; -+ } -+ } else { -+ /* note: the gzip extension is *not* used here! */ -+ sprintf(finalName, "%s/%s.%d%s", dirName, baseName, logStart, fileext); -+ } -+ - /* if the last rotation doesn't exist, that's okay */ - if (!debug && access(disposeName, F_OK)) { - message(MESS_DEBUG, "log %s doesn't exist -- won't try to " -@@ -613,9 +774,6 @@ - disposeName = NULL; - } - -- free(dirName); -- free(baseName); -- - if (!hasErrors) { - if (log->pre && !(log->flags & LOG_FLAG_SHAREDSCRIPTS)) { - message(MESS_DEBUG, "running prerotate script\n"); -@@ -722,33 +880,12 @@ - else - mailFilename = disposeName; - -- if (mailFilename) { -- /* if the log is compressed (and we're not mailing a -- file whose compression has been delayed), we need -- to uncompress it */ -- if ((log->flags & LOG_FLAG_COMPRESS) && -- !((log->flags & LOG_FLAG_DELAYCOMPRESS) && -- (log->flags & LOG_FLAG_MAILFIRST))) { -- if (mailLog(mailFilename, mailCommand, -- log->uncompress_prog, log->logAddress, -- log->files[logNum])) -- hasErrors = 1; -- } else { -- if (mailLog(mailFilename, mailCommand, NULL, -- log->logAddress, mailFilename)) -- hasErrors = 1; -- } -- } -+ if (mailFilename) -+ hasErrors = mailLogWrapper(mailFilename, mailCommand, logNum, log); - } - - if (!hasErrors && disposeName) { -- message(MESS_DEBUG, "removing old log %s\n", disposeName); -- -- if (!debug && unlink(disposeName)) { -- message(MESS_ERROR, "Failed to remove old log %s: %s\n", -- disposeName, strerror(errno)); -- hasErrors = 1; -- } -+ hasErrors = removeLogFile(disposeName); - } - } - -@@ -761,6 +898,8 @@ - } - } - #endif -+ free(dirName); -+ free(baseName); - return hasErrors; - } - -@@ -1047,7 +1186,9 @@ - - int main(int argc, const char ** argv) { - logInfo defConfig = { NULL, NULL, 0, NULL, ROT_SIZE, -- /* threshHold */ 1024 * 1024, 0, -+ /* threshHold */ 1024 * 1024, -+ /* rotateCount */ 0, -+ /* rotateAge */ 0, - /* log start */ -1, - /* pre, post */ NULL, NULL, - /* first, last */ NULL, NULL, -diff -u -ruN logrotate-3.7.1.orig/logrotate.h logrotate-3.7.1/logrotate.h ---- logrotate-3.7.1.orig/logrotate.h 2003-08-07 07:13:14.000000000 -0400 -+++ logrotate-3.7.1/logrotate.h 2005-05-24 12:21:09.000000000 -0400 -@@ -15,6 +15,7 @@ - #define LOG_FLAG_MAILFIRST (1 << 6) - #define LOG_FLAG_SHAREDSCRIPTS (1 << 7) - #define LOG_FLAG_COPY (1 << 8) -+#define LOG_FLAG_DATEEXT (1 << 9) - - #define NO_FORCE_ROTATE 0 - #define FORCE_ROTATE 1 -@@ -34,6 +35,7 @@ - enum { ROT_DAYS, ROT_WEEKLY, ROT_MONTHLY, ROT_SIZE, ROT_FORCE } criterium; - unsigned int threshhold; - int rotateCount; -+ int rotateAge; - int logStart; - char * pre, * post, * first, * last; - char * logAddress; diff --git a/logrotate/patches/02-datehack.patch b/logrotate/patches/02-datehack.patch deleted file mode 100644 index 69121aafa..000000000 --- a/logrotate/patches/02-datehack.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff -u -ruN logrotate-3.7.1.orig/logrotate.c logrotate-3.7.1/logrotate.c ---- logrotate-3.7.1.orig/logrotate.c 2004-10-19 17:41:24.000000000 -0400 -+++ logrotate-3.7.1/logrotate.c 2005-05-24 12:12:26.000000000 -0400 -@@ -1002,7 +1002,7 @@ - } - - /* Hack to hide earlier bug */ -- if ((year != 1900) && (year < 1996 || year > 2100)) { -+ if ((year != 1900) && (year < 1970 || year > 2100)) { - message(MESS_ERROR, "bad year %d for file %s in state file %s\n", - year, argv[0], stateFilename); - fclose(f); diff --git a/logrotate/patches/03-ignore_hidden.patch b/logrotate/patches/03-ignore_hidden.patch deleted file mode 100644 index 390de7537..000000000 --- a/logrotate/patches/03-ignore_hidden.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- logrotate-3.7/config.c.orig 2005-04-26 22:57:53.000000000 -0400 -+++ logrotate-3.7/config.c 2005-04-26 22:59:36.000000000 -0400 -@@ -142,6 +142,11 @@ - (!fname[1] || (fname[1] == '.' && !fname[2]))) - return 0; - -+ /* Don't include 'hidden' files either; this breaks Gentoo -+ portage config file management http://bugs.gentoo.org/87683 */ -+ if (fname[0] == '.') -+ return 0; -+ - /* Check if fname is ending in a taboo-extension; if so, return - false */ - for (i = 0; i < tabooCount; i++) { diff --git a/logrotate/patches/04-no_tmpdir.patch b/logrotate/patches/04-no_tmpdir.patch deleted file mode 100644 index fb95f1ee3..000000000 --- a/logrotate/patches/04-no_tmpdir.patch +++ /dev/null @@ -1,54 +0,0 @@ -diff -u -ruN logrotate-3.7.1-cur/logrotate.c logrotate-3.7.1/logrotate.c ---- logrotate-3.7.1-cur/logrotate.c 2005-05-25 18:20:41.000000000 -0400 -+++ logrotate-3.7.1/logrotate.c 2005-05-25 18:21:10.000000000 -0400 -@@ -90,10 +90,7 @@ - } - - static int runScript(char * logfn, char * script) { -- int fd; -- char *filespec; - int rc; -- char buf[256]; - - if (debug) { - message(MESS_DEBUG, "running script with arg %s: \"%s\"\n", -@@ -101,38 +98,12 @@ - return 0; - } - -- filespec = buf; -- snprintf(buf, sizeof(buf), "%s/logrotate.XXXXXX", getenv("TMPDIR") ?: "/tmp"); -- fd = -1; -- if (!filespec || (fd = mkstemp(filespec)) < 0 || fchmod(fd, 0700)) { -- message(MESS_DEBUG, "error creating %s: %s\n", filespec, -- strerror(errno)); -- if (fd >= 0) { -- close(fd); -- unlink(filespec); -- } -- return -1; -- } -- -- if (write(fd, "#!/bin/sh\n\n", 11) != 11 || -- write(fd, script, strlen(script)) != strlen(script)) { -- message(MESS_DEBUG, "error writing %s\n", filespec); -- close(fd); -- unlink(filespec); -- return -1; -- } -- -- close(fd); -- - if (!fork()) { -- execlp(filespec, filespec, logfn, NULL); -+ execl("/bin/sh", "sh", "-c", script, NULL); - exit(1); - } - - wait(&rc); -- -- unlink(filespec); -- - return rc; - } - diff --git a/logrotate/patches/05-taboo_to_debug.patch b/logrotate/patches/05-taboo_to_debug.patch deleted file mode 100644 index 2e07188f5..000000000 --- a/logrotate/patches/05-taboo_to_debug.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff -u -ruN logrotate-3.7.1.orig/config.c logrotate-3.7.1/config.c ---- logrotate-3.7.1.orig/config.c 2003-08-07 07:13:14.000000000 -0400 -+++ logrotate-3.7.1/config.c 2005-05-24 12:13:41.000000000 -0400 -@@ -147,7 +147,7 @@ - for (i = 0; i < tabooCount; i++) { - if (!strcmp(fname + strlen(fname) - strlen(tabooExts[i]), - tabooExts[i])) { -- message(MESS_ERROR, "Ignoring %s, because of %s " -+ message(MESS_DEBUG, "Ignoring %s, because of %s " - "ending\n", fname, tabooExts[i]); - - return 0; diff --git a/logrotate/patches/06-weekly.patch b/logrotate/patches/06-weekly.patch deleted file mode 100644 index 8a371e8e0..000000000 --- a/logrotate/patches/06-weekly.patch +++ /dev/null @@ -1,22 +0,0 @@ ---- logrotate-3.7.1-old/logrotate.c 2004-10-19 23:41:24.000000000 +0200 -+++ logrotate-3.7.1-new/logrotate.c 2005-10-02 17:29:22.380767321 +0200 -@@ -424,12 +424,15 @@ int findNeedRotating(logInfo * log, int - switch (log->criterium) { - case ROT_WEEKLY: - /* rotate if: -- 1) the current weekday is before the weekday of the -- last rotation -+ 1) the day of the week is the same as the day of the week of -+ the previous rotation but not the same day of the year -+ this will rotate it on the same day every week, but not -+ twice a day. - 2) more then a week has passed since the last - rotation */ -- state->doRotate = ((now.tm_wday < state->lastRotated.tm_wday) || -- ((mktime(&now) - mktime(&state->lastRotated)) > -+ state->doRotate = ((now.tm_wday == state->lastRotated.tm_wday && -+ now.tm_yday != state->lastRotated.tm_yday) || -+ ((mktime(&now) - mktime(&state->lastRotated)) > - (7 * 24 * 3600))); - break; - case ROT_MONTHLY: diff --git a/multiwan/Makefile b/multiwan/Makefile deleted file mode 100644 index feccd5ca0..000000000 --- a/multiwan/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# -# Copyright (C) 2010-2012 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:=multiwan -PKG_VERSION:=1.0.22 -PKG_RELEASE:=2 - -PKG_LICENSE:=GPLv2 - -include $(INCLUDE_DIR)/package.mk - -define Package/multiwan - SECTION:=net - CATEGORY:=Network - DEPENDS:=+ip +iptables +kmod-ipt-conntrack +iptables-mod-conntrack-extra +iptables-mod-ipopt - TITLE:=Simple multi WAN configuration - URL:=ftp://ftp.netlab7.com/ - MAINTAINER:=Craig M. Coffee -endef - -define Package/multiwan/description -An agent script that makes Multi-WAN configuration simple, -easy and manageable. Complete with load balancing, failover and an easy -to manage traffic ruleset. -endef - -define Package/multiwan/conffiles -/etc/config/multiwan -endef - -define Build/Compile -endef - -define Package/multiwan/install - $(CP) ./files/* $(1) -endef - -define Package/multiwan/postinst -[ -n "$${IPKG_INSTROOT}" ] || /etc/init.d/multiwan enable -exit 0 -endef - -$(eval $(call BuildPackage,multiwan)) diff --git a/multiwan/files/etc/config/multiwan b/multiwan/files/etc/config/multiwan deleted file mode 100644 index 09d988f16..000000000 --- a/multiwan/files/etc/config/multiwan +++ /dev/null @@ -1,57 +0,0 @@ - -config 'multiwan' 'config' - # REMOVE THIS LINE OR PUT TO 1 TO ENABLE MULTIWAN - option 'enabled' '0' - - option 'default_route' 'balancer' - # health_monitor below is defaulted to parallel, and can be set to - # serial to save system resources. - # option 'health_monitor' 'serial' - # option 'debug' '1' - -config 'interface' 'wan' - option 'weight' '10' - option 'health_interval' '10' - option 'icmp_hosts' 'dns' - # icmp_count is defaulted to 1, and can be increased to reduce - # false positives. - # option 'icmp_count' '3' - option 'timeout' '3' - option 'health_fail_retries' '3' - option 'health_recovery_retries' '5' - option 'failover_to' 'wwan' - option 'dns' 'auto' - -config 'interface' 'wwan' - option 'weight' '10' - option 'health_interval' '10' - option 'icmp_hosts' 'gateway' - option 'timeout' '3' - option 'health_fail_retries' '3' - option 'health_recovery_retries' '5' - option 'failover_to' 'balancer' - option 'dns' '208.67.222.222 208.67.220.220' - -#config 'mwanfw' -# option 'src' '192.168.1.0/24' -# option 'dst' 'ftp.netlab7.com' -# option 'proto' 'tcp' -# option 'ports' '21' -# option 'wanrule' 'wan2' - -# VoIP traffic goes through wan -# config 'mwanfw' - # option 'src' '192.168.1.0/24' - # option 'proto' 'udp' - # option 'port_type' 'source-ports' - # option 'ports' '5060,16384:16482' - # option 'wanrule' 'wan' - -#config 'mwanfw' -# option 'src' '192.168.0.3' -# option 'proto' 'icmp' -# option 'wanrule' 'balancer' - -#config 'mwanfw' -# option 'dst' 'www.whatismyip.com' -# option 'wanrule' 'fastbalancer' diff --git a/multiwan/files/etc/init.d/multiwan b/multiwan/files/etc/init.d/multiwan deleted file mode 100755 index 368075714..000000000 --- a/multiwan/files/etc/init.d/multiwan +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh /etc/rc.common -START=99 -EXTRA_COMMANDS="single" -USE_PROCD=1 - -start_service () { - /usr/bin/multiwan agent & -} - -stop_service () { - sh /usr/bin/multiwan stop -} - -reload_service () { - /usr/bin/multiwan restart & -} - -single () { - /usr/bin/multiwan single & -} - -service_triggers() { - procd_add_reload_trigger multiwan -} - diff --git a/multiwan/files/usr/bin/multiwan b/multiwan/files/usr/bin/multiwan deleted file mode 100755 index 281d8f4bc..000000000 --- a/multiwan/files/usr/bin/multiwan +++ /dev/null @@ -1,1119 +0,0 @@ -#!/bin/sh - -. /lib/functions.sh -. /lib/functions/network.sh - -silencer() { - if [ -z "$debug" -o "$debug" == "0" ]; then - $* > /dev/null 2>&1 - else - $* - fi -} - -mwnote() { - logger ${debug:+-s} -p 5 -t multiwan "$1" -} - -failover() { - local failchk=$(query_config failchk $2) - local recvrychk=$(query_config recvrychk $2) - - local wanid=$(query_config wanid $2) - local failover_to=$(uci_get_state multiwan ${2} failover_to) - local failover_to_wanid=$(query_config wanid $failover_to) - - local existing_failover=$(iptables -n -L FW${wanid}MARK -t mangle | echo $(($(wc -l) - 2))) - - add() { - - wan_fail_map=$(echo $wan_fail_map | sed -e "s/\(^\|.*\]\)${1}\[${failchk}\]/\1/g") - wan_fail_map="$wan_fail_map${1}[x]" - wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/\(^\|.*\]\)${1}\[${recvrychk}\]/\1/g") - update_cache - - if [ "$existing_failover" == "2" ]; then - if [ "$failover_to" != "balancer" -a "$failover_to" != "fastbalancer" -a "$failover_to" != "disable" -a "$failover_to_wanid" != "$wanid" ]; then - iptables -I FW${wanid}MARK 2 -t mangle -j FW${failover_to_wanid}MARK - elif [ "$failover_to" == "balancer" ]; then - iptables -I FW${wanid}MARK 2 -t mangle -j LoadBalancer - elif [ "$failover_to" == "fastbalancer" ]; then - iptables -I FW${wanid}MARK 2 -t mangle -j FastBalancer - fi - fi - mwnote "$1 has failed and is currently offline." - } - - del() { - - wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/\(^\|.*\]\)${1}\[${recvrychk}\]/\1/g") - wan_fail_map=$(echo $wan_fail_map | sed -e "s/\(^\|.*\]\)${1}\[${failchk}\]/\1/g") - update_cache - - if [ "$existing_failover" == "3" ]; then - iptables -D FW${wanid}MARK 2 -t mangle - fi - mwnote "$1 has recovered and is back online!" - } - - case $1 in - add) add $2;; - del) del $2;; - esac -} - -fail_wan() { - local new_fail_count - - local health_fail_retries=$(uci_get_state multiwan ${1} health_fail_retries) - local weight=$(uci_get_state multiwan ${1} weight) - - local failchk=$(query_config failchk $1) - local recvrychk=$(query_config recvrychk $1) - wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/\(^\|.*\]\)${1}\[${recvrychk}\]/\1/g") - - if [ -z "$failchk" ]; then - failchk=1 - wan_fail_map="$wan_fail_map${1}[1]" - fi - - if [ "$failchk" != "x" ]; then - new_fail_count=$(($failchk + 1)) - if [ "$new_fail_count" -lt "$health_fail_retries" ]; then - wan_fail_map=$(echo $wan_fail_map | sed -e "s/\(^\|.*\]\)${1}\[${failchk}\]/\1${1}\[${new_fail_count}\]/g") - else - failover add $1 - refresh_dns - if [ "$weight" != "disable" ]; then - refresh_loadbalancer - fi - fi - fi - update_cache -} - -recover_wan() { - local new_fail_count - - local health_recovery_retries=$(uci_get_state multiwan ${1} health_recovery_retries) - local weight=$(uci_get_state multiwan ${1} weight) - - local failchk=$(query_config failchk $1) - local recvrychk=$(query_config recvrychk $1) - local wanid=$(query_config wanid $1) - - if [ ! -z "$failchk" -a "$failchk" != "x" ]; then - wan_fail_map=$(echo $wan_fail_map | sed -e "s/\(^\|.*\]\)${1}\[${failchk}\]/\1/g") - update_cache - fi - - if [ "$failchk" == "x" ]; then - if [ -z "$recvrychk" ]; then - wan_recovery_map="$wan_recovery_map${1}[1]" - update_cache - if [ "$health_recovery_retries" == "1" ]; then - recover_wan $1 - fi - else - new_recovery_count=$(($recvrychk + 1)) - if [ "$new_recovery_count" -lt "$health_recovery_retries" ]; then - wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/\(^\|.*\]\)${1}\[${recvrychk}\]/\1${1}\[${new_recovery_count}\]/g") - update_cache - else - failover del $1 - refresh_dns - if [ "$weight" != "disable" ]; then - refresh_loadbalancer - fi - fi - fi - fi -} - -acquire_wan_data() { - local check_old_map - local get_wanid - local old_ifname - local old_ipaddr - local old_gateway - - local ifname ipaddr gateway - network_flush_cache - network_get_device ifname ${1} || ifname=x - network_get_ipaddr ipaddr ${1} || ipaddr=x - network_get_gateway gateway ${1} || gateway=x - - check_old_map=$(echo $wan_id_map 2>&1 | grep -o -e "^$1\[" -e "\]$1\[") - - if [ -z $check_old_map ]; then - wancount=$(($wancount + 1)) - if [ $wancount -gt 20 ]; then - wancount=20 - return - fi - wan_if_map="$wan_if_map${1}[${ifname}]" - wan_id_map="$wan_id_map${1}[${wancount}]" - wan_gw_map="$wan_gw_map${1}[${gateway}]" - wan_ip_map="$wan_ip_map${1}[${ipaddr}]" - else - old_ipaddr=$(query_config ipaddr $1) - old_gateway=$(query_config gateway $1) - old_ifname=$(query_config ifname $1) - get_wanid=$(query_config wanid $1) - - wan_if_map=$(echo $wan_if_map | sed -e "s/\(^\|.*\]\)${1}\[${old_ifname}\]/\1${1}\[${ifname}\]/g") - wan_ip_map=$(echo $wan_ip_map | sed -e "s/\(^\|.*\]\)${1}\[${old_ipaddr}\]/\1${1}\[${ipaddr}\]/g") - wan_gw_map=$(echo $wan_gw_map | sed -e "s/\(^\|.*\]\)${1}\[${old_gateway}\]/\1${1}\[${gateway}\]/g") - - if [ "$old_ifname" != "$ifname" ]; then - iptables -D MultiWanPreHandler -t mangle -i $old_$ifname -m state --state NEW -j FW${get_wanid}MARK - iptables -A MultiWanPreHandler -t mangle -i $ifname -m state --state NEW -j FW${get_wanid}MARK - iptables -D MultiWanPostHandler -t mangle -o $old_$ifname -m mark --mark 0x1 -j FW${get_wanid}MARK - iptables -A MultiWanPostHandler -t mangle -o $ifname -m mark --mark 0x1 -j FW${get_wanid}MARK - fi - - if [ "$ifname" != "x" -a "$ipaddr" != "x" -a "$gateway" != "x" ]; then - failover del $1 - iprules_config $get_wanid - else - failover add $1 - fi - - refresh_routes - refresh_loadbalancer - refresh_dns - update_cache - fi -} - -update_cache() { - if [ ! -d /tmp/.mwan ]; then - mkdir /tmp/.mwan > /dev/null 2>&1 - fi - - rm /tmp/.mwan/cache > /dev/null 2>&1 - touch /tmp/.mwan/cache - - echo "# Automatically Generated by Multi-WAN Agent Script. Do not modify or remove. #" > /tmp/.mwan/cache - echo "wan_id_map=\"$wan_id_map\"" >> /tmp/.mwan/cache - echo "wan_if_map=\"$wan_if_map\"" >> /tmp/.mwan/cache - echo "wan_ip_map=\"$wan_ip_map\"" >> /tmp/.mwan/cache - echo "wan_gw_map=\"$wan_gw_map\"" >> /tmp/.mwan/cache - echo "wan_fail_map=\"$wan_fail_map\"" >> /tmp/.mwan/cache - echo "wan_recovery_map=\"$wan_recovery_map\"" >> /tmp/.mwan/cache - echo "wan_monitor_map=\"$wan_monitor_map\"" >> /tmp/.mwan/cache -} - -query_config() { - case $1 in - ifname) echo $wan_if_map | grep -o -e "^$2\[\w*.*\]" -e "\]$2\[\w*.*\]" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}';; - ipaddr) echo $wan_ip_map | grep -o -e "^$2\[\w*.*\]" -e "\]$2\[\w*.*\]" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}';; - gateway) echo $wan_gw_map | grep -o -e "^$2\[\w*.*\]" -e "\]$2\[\w*.*\]" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}';; - wanid) echo $wan_id_map | grep -o -e "^$2\[\w*.*\]" -e "\]$2\[\w*.*\]" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}';; - failchk) echo $wan_fail_map | grep -o -e "^$2\[\w*.*\]" -e "\]$2\[\w*.*\]" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}';; - recvrychk) echo $wan_recovery_map | grep -o -e "^$2\[\w*.*\]" -e "\]$2\[\w*.*\]" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}';; - monitor) echo $wan_monitor_map | grep -o -e "^$2\[\w*.*\]" -e "\]$2\[\w*.*\]" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}';; - group) echo $wan_id_map | grep -o "\w*\[$2\]" | awk -F "[" '{print $1}';; - esac -} - -mwan_kill() { - local otherpids=$(ps 2>&1 | grep 'multiwan agent' | grep -v $$ | awk '{print $1}') - [ -n "$otherpids" ] && kill $otherpids > /dev/null 2>&1 - sleep 2 -} - -# For system shutdownl: stop -# A plain stop will leave network in a limp state, without wan access -# stop single: restore to a single wan -# stop restart: restart multiple wan's -stop() { - mwan_kill - flush $1 - - if [ "$1" == "single" ]; then - # ifup is quite expensive--do it only when single wan is requested - echo "## Refreshing Interfaces ##" - local i=0 - while [ $((i++)) -lt $wancount ]; do - local group=$(query_config group $i) - ifup $group >&- 2>&- && sleep 1 - done - - echo "## Unloaded, updating syslog and exiting. ##" - mwnote "Succesfully Unloaded on $(exec date -R)." - rm -fr /tmp/.mwan >&- 2>&- - fi - ip route flush cache - - if [ "$1" == "restart" ]; then - echo "## Restarting Multi-WAN. ##" - mwnote "Reinitializing Multi-WAN Configuration." - rm -fr /tmp/.mwan >&- 2>&- - /etc/init.d/multiwan start >&- 2>&- - fi - - exit -} - -clear_rules() { - local restore_single=$1 - local group - - iptables -t mangle -D PREROUTING -j MultiWan - iptables -t mangle -D FORWARD -j MultiWan - iptables -t mangle -D OUTPUT -j MultiWan - iptables -t mangle -D POSTROUTING -j MultiWan - iptables -t mangle -F MultiWan - iptables -t mangle -X MultiWan - iptables -t mangle -F MultiWanRules - iptables -t mangle -X MultiWanRules - iptables -t mangle -F MultiWanDNS - iptables -t mangle -X MultiWanDNS - iptables -t mangle -F MultiWanPreHandler - iptables -t mangle -X MultiWanPreHandler - iptables -t mangle -F MultiWanPostHandler - iptables -t mangle -X MultiWanPostHandler - iptables -t mangle -F LoadBalancer - iptables -t mangle -X LoadBalancer - iptables -t mangle -F FastBalancer - iptables -t mangle -X FastBalancer - iptables -t mangle -F MultiWanLoadBalancer - iptables -t mangle -X MultiWanLoadBalancer - - local i=0 - while [ $((i++)) -lt $wancount ]; do - iptables -t mangle -F FW${i}MARK - iptables -t mangle -X FW${i}MARK - done - - if [ ! -z "$CHKFORQOS" ]; then - iptables -t mangle -F PREROUTING - iptables -t mangle -F FORWARD - iptables -t mangle -F OUTPUT - iptables -t mangle -F POSTROUTING - iptables -t mangle -F MultiWanQoS - iptables -t mangle -X MultiWanQoS - - i=0 - while [ $((i++)) -lt $wancount ]; do - group=$(query_config group $i) - iptables -t mangle -F qos_${group} - iptables -t mangle -F qos_${group}_ct - iptables -t mangle -X qos_${group} - iptables -t mangle -X qos_${group}_ct - done - fi - - [ "$restore_single" == 'single' ] && - /etc/init.d/qos restart > /dev/null 2>&1 -} - -qos_init() { - local ifname - local queue_count - local get_wan_tc - local get_wan_iptables - local add_qos_iptables - local add_qos_tc - local execute - local iprule - local qos_if_test - - ifname=$(query_config ifname $1) - - if [ "$ifname" == "x" ]; then - return - fi - - qos_if_test=$(echo $qos_if_done | grep $ifname.) - - if [ ! -z "$qos_if_test" ]; then - return - fi - - qos_if_done=$(echo ${qos_if_done}.${ifname}) - - queue_count=$(tc filter list dev $ifname | tail -n 1 | awk -F " " '{print $10}' | sed "s/0x//g") - - if [ -z "$queue_count" ]; then - return - fi - - queue_count=$(($queue_count + 1)) - - iptables -t mangle -N qos_${1} - iptables -t mangle -N qos_${1}_ct - - get_wan_tc=$(tc filter list dev $ifname | grep "0x" | sed -e "s/filter /tc filter add dev $ifname /g" -e "s/pref/prio/g" -e "s/fw//g") - get_wan_iptables=$(iptables-save | egrep '(-A Default )|(-A Default_ct )' | grep -v "MultiWanQoS" | sed -e "s/Default /qos_${1} /g" -e "s/Default_ct /qos_${1}_ct /g" -e "s/-A/iptables -t mangle -A/g") - - - local i=0 - while [ $i -lt $queue_count ]; do - echo "s/\(0x$i \|0x$i\/0xffffffff\)/0x$(($2 * 10 + $i)) /g" >> /tmp/.mwan/qos.$1.sedfilter - i=$(($i + 1)) - done - - add_qos_iptables=$(echo "$get_wan_iptables" | sed -f /tmp/.mwan/qos.$1.sedfilter) - echo "$add_qos_iptables" | while read execute; do ${execute}; done - - rm /tmp/.mwan/qos.$1.sedfilter - i=1 - while [ $i -lt $queue_count ]; do - echo "s/0x$i /0x${2}${i} fw /g" >> /tmp/.mwan/qos.$1.sedfilter - i=$(($i + 1)) - done - - add_qos_tc=$(echo "$get_wan_tc" | sed -f /tmp/.mwan/qos.$1.sedfilter) - echo "$add_qos_tc" | while read execute; do ${execute}; done - rm /tmp/.mwan/qos.$1.sedfilter - - i=0 - while [ $i -lt $queue_count ]; do - if [ $i -lt $(($queue_count - 1)) ]; then - ip rule add fwmark 0x$(($2 * 10 + $i + 1)) table $(($2 + 170)) prio $(( $2 * 10 + $i + 2)) - fi - iptables -t mangle -A MultiWanQoS -m mark --mark 0x$(($2 * 10 + $i)) -j qos_${1} - i=$(($i + 1)) - done -} - -mwanrule() { - local src - local dst - local ports - local proto - local wanrule - - config_get src $1 src - config_get dst $1 dst - config_get port_type $1 port_type 'dports' - config_get ports $1 ports - config_get proto $1 proto - config_get wanrule $1 wanrule - - if [ -z "$wanrule" ]; then - return - fi - - if [ "$wanrule" != "balancer" -a "$wanrule" != "fastbalancer" ]; then - wanrule=$(query_config wanid ${wanrule}) - wanrule="FW${wanrule}MARK" - elif [ "$wanrule" == "balancer" ]; then - wanrule="LoadBalancer" - elif [ "$wanrule" == "fastbalancer" ]; then - wanrule="FastBalancer" - fi - if [ "$dst" == "all" ]; then - dst=$NULL - fi - if [ "$proto" == "all" ]; then - proto=$NULL - fi - if [ "$ports" == "all" ]; then - ports=$NULL - fi - add_rule() { - if [ "$proto" == "icmp" ]; then - ports=$NULL - fi - if [ "$src" == "all" ]; then - src=$NULL - fi - iptables -t mangle -A MultiWanRules ${src:+-s $src} ${dst:+-d $dst} \ - -m mark --mark 0x0 ${proto:+-p $proto -m $proto} \ - ${ports:+-m multiport --$port_type $ports} \ - -j $wanrule - } - if [ -z "$proto" -a ! -z "$ports" ]; then - proto=tcp - add_rule - proto=udp - add_rule - return - fi - add_rule -} - - -get_dns_servers() { - local group=$1 - local groups=$1 - local dns="" - local dnss="" - local aliases="" - local g - - aliases="$(uci show network| grep =\'@$group\')" - - for g in $aliases ; do - g=${g#*.}; g=${g%%.*} - [ "$(uci -q get network.$g)" == "interface" ] || continue - groups="$groups $g" - done - - groups="$(echo $groups | tr ' ' '\n' | sort -u | tr '\n' ' ')" - - for group in $groups ; do - network_get_dnsserver dns ${group} - dnss="$dnss $dns" - done - - echo $dnss -} - - -refresh_dns() { - local dns - local group - local ipaddr - local gateway - local ifname - local failchk - local compile_dns - local dns_server - - network_flush_cache - - iptables -F MultiWanDNS -t mangle - - rm /tmp/resolv.conf.auto - touch /tmp/resolv.conf.auto - - echo "## Refreshing DNS Resolution and Tables ##" - - local i=0 - while [ $((i++)) -lt $wancount ]; do - group=$(query_config group $i) - gateway=$(query_config gateway $group) - ipaddr=$(query_config ipaddr $group) - ifname=$(query_config ifname $group) - failchk=$(query_config failchk $group) - - dns=$(uci_get_state multiwan ${group} dns 'auto') - [ "$dns" == "auto" ] && dns=$(get_dns_servers $group) - dns=$(echo $dns | sed -e "s/\,/ /g" | sed -e "s/ /\n/g") - - if [ ! -z "$dns" -a "$failchk" != "x" -a "$ipaddr" != "x" -a "$gateway" != "x" -a "$ifname" != "x" ]; then - echo "$dns" | while read dns_server; do - iptables -t mangle -A MultiWanDNS -d $dns_server -p tcp --dport 53 -j FW${i}MARK - iptables -t mangle -A MultiWanDNS -d $dns_server -p udp --dport 53 -j FW${i}MARK - - compile_dns="nameserver $dns_server" - echo "$compile_dns" >> /tmp/resolv.conf.auto - done - fi - done - - last_resolv_update=$(ls -l -e /tmp/resolv.conf.auto | awk -F " " '{print $5, $9}') -} - -iptables_init() { - echo "## IPTables Rule Initialization ##" - local iprule - local group - local ifname - local execute - local IMQ_NFO - local default_route_id - local i - - if [ ! -z "$CHKFORQOS" ]; then - echo "## QoS Initialization ##" - - /etc/init.d/qos restart > /dev/null 2>&1 - - IMQ_NFO=$(iptables -n -L PREROUTING -t mangle -v | grep IMQ | awk -F " " '{print $6,$12}') - - iptables -t mangle -F PREROUTING - iptables -t mangle -F FORWARD - iptables -t mangle -F POSTROUTING - iptables -t mangle -F OUTPUT - - echo "$IMQ_NFO" | while read execute; do - iptables -t mangle -A PREROUTING -i $(echo $execute | awk -F " " '{print $1}') -j IMQ --todev $(echo $execute | awk -F " " '{print $2}') - done - - iptables -t mangle -N MultiWanQoS - - i=0 - while [ $((i++)) -lt $wancount ]; do - qos_init $(query_config group $i) $i - done - - fi - - iptables -t mangle -N MultiWan - iptables -t mangle -N LoadBalancer - iptables -t mangle -N FastBalancer - iptables -t mangle -N MultiWanRules - iptables -t mangle -N MultiWanDNS - iptables -t mangle -N MultiWanPreHandler - iptables -t mangle -N MultiWanPostHandler - iptables -t mangle -N MultiWanLoadBalancer - - echo "## Creating FW Rules ##" - i=0 - while [ $((i++)) -lt $wancount ]; do - iprule=$(($i * 10)) - iptables -t mangle -N FW${i}MARK - iptables -t mangle -A FW${i}MARK -j MARK --set-mark 0x${iprule} - iptables -t mangle -A FW${i}MARK -j CONNMARK --save-mark - done - - iptables -t mangle -A LoadBalancer -j MARK --set-mark 0x1 - iptables -t mangle -A LoadBalancer -j CONNMARK --save-mark - - if [ -z "$CHKFORMODULE" ]; then - iptables -t mangle -A FastBalancer -j MARK --set-mark 0x2 - iptables -t mangle -A FastBalancer -j CONNMARK --save-mark - else - mwnote "Performance load balancer(fastbalanacer) is unavailable due to current kernel limitations." - iptables -t mangle -A FastBalancer -j MARK --set-mark 0x1 - iptables -t mangle -A FastBalancer -j CONNMARK --save-mark - fi - - iptables -t mangle -A MultiWan -j CONNMARK --restore-mark - iptables -t mangle -A MultiWan -j MultiWanPreHandler - iptables -t mangle -A MultiWan -j MultiWanRules - iptables -t mangle -A MultiWan -j MultiWanLoadBalancer - iptables -t mangle -A MultiWan -j MultiWanDNS - iptables -t mangle -A MultiWan -j MultiWanPostHandler - - iptables -t mangle -I PREROUTING -j MultiWan - iptables -t mangle -I FORWARD -j MultiWan - iptables -t mangle -I OUTPUT -j MultiWan - iptables -t mangle -I POSTROUTING -j MultiWan - - - refresh_dns - - config_load "multiwan" - config_foreach mwanrule mwanfw - - if [ "$default_route" != "balancer" -a "$default_route" != "fastbalancer" ]; then - default_route_id=$(query_config wanid $default_route) - iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j FW${default_route_id}MARK - elif [ "$default_route" == "fastbalancer" ]; then - iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j FastBalancer - else - iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j LoadBalancer - fi - - i=0 - while [ $((i++)) -lt $wancount ]; do - group=$(query_config group $i) - ifname=$(query_config ifname $group) - iptables -t mangle -A MultiWanPreHandler -i $ifname -m state --state NEW -j FW${i}MARK - iptables -t mangle -A MultiWanPostHandler -o $ifname -m mark --mark 0x1 -j FW${i}MARK - done - - if [ ! -z "$CHKFORQOS" ]; then - iptables -t mangle -A MultiWan -j MultiWanQoS - fi -} - -refresh_loadbalancer() { - local group - local gateway - local ifname - local failchk - local weight - local nexthop - local pre_nexthop_chk - local rand_probability - - echo "## Refreshing Load Balancer ##" - - ip rule del prio 9 > /dev/null 2>&1 - ip route flush table 170 > /dev/null 2>&1 - - for TABLE in 170; do - ip route | grep -Ev ^default | while read ROUTE; do - ip route add table $TABLE to $ROUTE - done - done - - iptables -F MultiWanLoadBalancer -t mangle - - local total_weight=0 - - local i=0 - while [ $((i++)) -lt $wancount ]; do - group=$(query_config group $i) - failchk=$(query_config failchk $group) - gateway=$(query_config gateway $group) - ifname=$(query_config ifname $group) - weight=$(uci_get_state multiwan ${group} weight) - if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then - total_weight=$(($total_weight + $weight)) - fi - done - - i=0 - while [ $((i++)) -lt $wancount ]; do - group=$(query_config group $i) - failchk=$(query_config failchk $group) - gateway=$(query_config gateway $group) - ifname=$(query_config ifname $group) - - weight=$(uci_get_state multiwan ${group} weight) - - if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then - nexthop="$nexthop nexthop via $gateway dev $ifname weight $weight" - - rand_probability=$(($weight * 100 / $total_weight)) - total_weight=$(($total_weight - $weight)) - - if [ $rand_probability -lt 10 ]; then - rand_probability="0.0${rand_probability}" - elif [ $rand_probability -lt 100 ]; then - rand_probability="0.${rand_probability}" - else - rand_probability="1.0" - fi - - if [ -z "$CHKFORMODULE" ]; then - iptables -A MultiWanLoadBalancer -t mangle -m mark --mark 0x2 -m statistic --mode random --probability $rand_probability -j FW${i}MARK - fi - fi - - done - - pre_nexthop_chk=$(echo $nexthop | awk -F "nexthop" '{print NF-1}') - if [ "$pre_nexthop_chk" == "1" ]; then - ip route add default via $(echo $nexthop | awk -F " " '{print $3}') dev $(echo $nexthop | awk -F " " '{print $5}') proto static table 170 - elif [ "$pre_nexthop_chk" -gt "1" ]; then - ip route add proto static table 170 default scope global $nexthop - fi - - ip rule add fwmark 0x1 table 170 prio 9 - ip route flush cache -} - -refresh_routes() { - local iprule - local gateway - local group - local ifname - local ipaddr - - echo "## Refreshing Routing Tables ##" - - local i=0 - while [ $((i++)) -lt $wancount ]; do - group=$(query_config group $i) - gateway=$(query_config gateway $group) - ifname=$(query_config ifname $group) - ipaddr=$(query_config ipaddr $group) - ip route flush table $(($i + 170)) > /dev/null 2>&1 - - TABLE=$(($i + 170)) - ip route | grep -Ev ^default | while read ROUTE; do - ip route add table $TABLE to $ROUTE - done - - if [ "$gateway" != "x" -a "$ipaddr" != "x" -a "$ifname" != "x" ]; then - ip route add default via $gateway table $(($i + 170)) src $ipaddr proto static - route add default gw $gateway > /dev/null 2>&1 - fi - done - - ip route flush cache -} - -iprules_config() { - local iprule - local group - local gateway - local ipaddr - - group=$(query_config group $1) - gateway=$(query_config gateway $group) - ipaddr=$(query_config ipaddr $group) - - CHKIPROUTE=$(grep MWAN${1} /etc/iproute2/rt_tables) - if [ -z "$CHKIPROUTE" ]; then - echo "$(($1 + 170)) MWAN${1}" >> /etc/iproute2/rt_tables - fi - - ip rule del prio $(($1 * 10)) > /dev/null 2>&1 - ip rule del prio $(($1 * 10 + 1)) > /dev/null 2>&1 - - if [ "$gateway" != "x" -a "$ipaddr" != "x" ]; then - ip rule add from $ipaddr table $(($1 + 170)) prio $(($1 * 10)) - ip rule add fwmark 0x$(($1 * 10)) table $(($1 + 170)) prio $(($1 * 10 + 1)) - fi -} - -flush() { - local restore_single=$1 - echo "## Flushing IP Rules & Routes ##" - - ip rule flush > /dev/null 2>&1 - ip rule add lookup 128 prio 0 > /dev/null 2>&1 - ip rule add lookup local prio 1 > /dev/null 2>&1 - ip rule add lookup main prio 32766 > /dev/null 2>&1 - ip rule add lookup default prio 32767 > /dev/null 2>&1 - - ip route flush table 170 > /dev/null - - local i=0 - while [ $((i++)) -lt $wancount ]; do - ip route del default > /dev/null 2>&1 - ip route flush table $(($i + 170)) > /dev/null 2>&1 - done - - echo "## Clearing Rules ##" - clear_rules $restore_single > /dev/null 2>&1 - - rm $jobfile > /dev/null 2>&1 -} - -main_init() { - local RP_PATH IFACE - local group - local health_interval - - echo "## Main Initialization ##" - - mkdir /tmp/.mwan > /dev/null 2>&1 - - mwan_kill - flush - - echo "## IP Rules Initialization ##" - - CHKIPROUTE=$(grep LoadBalancer /etc/iproute2/rt_tables) - if [ -z "$CHKIPROUTE" ]; then - echo "#" >> /etc/iproute2/rt_tables - echo "170 LoadBalancer" >> /etc/iproute2/rt_tables - fi - - local i=0 - while [ $((i++)) -lt $wancount ]; do - iprules_config $i - done - - refresh_routes - iptables_init - - refresh_loadbalancer - - RP_PATH=/proc/sys/net/ipv4/conf - for IFACE in $(ls $RP_PATH); do - echo 0 > $RP_PATH/$IFACE/rp_filter - done - mwnote "Succesfully Initialized on $(date -R)." - fail_start_check - - while :; do - schedule_tasks - do_tasks - done -} - -if_rx_bytes() { - local up=0 - local rx_bytes=0 - json_load "$(devstatus $1)" - json_get_var up up - if [ "$up" == "1" ]; then - json_select statistics - json_get_var rx_bytes rx_bytes - json_select .. - fi - json_close_object - echo "$rx_bytes" -} - -dhcp_renew() { - local pid=$(ps -w | grep udhcpc | grep "$1.pid" | awk '{print$1}') - [ -n "$pid" ] && kill -SIGUSR1 $pid -} - -monitor_wan() { - local ifname ipaddr gateway icmp_hosts_acquire icmp_test_host - local check_test - - . /tmp/.mwan/cache - - local health_method=$(uci_get_state multiwan ${1} health_method "ping") - local timeout=$(uci_get_state multiwan ${1} timeout) - local icmp_hosts=$(uci_get_state multiwan ${1} icmp_hosts) - local icmp_count=$(uci_get_state multiwan ${1} icmp_count '1') - local health_interval=$(uci_get_state multiwan ${1} health_interval) - local ifname_cur=$(query_config ifname $1) - local ipaddr_cur=$(query_config ipaddr $1) - local gateway_cur=$(query_config gateway $1) - local old_rx_bytes="0" - local new_rx_bytes="$(if_rx_bytes $ifname_cur)" - - while :; do - [ "${health_monitor%.*}" = 'parallel' ] && sleep $health_interval - - network_flush_cache - network_get_device ifname ${1} || ifname=x - network_get_ipaddr ipaddr ${1} || ipaddr=x - network_get_gateway gateway ${1} || gateway=x - - if [ "$ifname_cur" != "$ifname" -o "$ipaddr_cur" != "$ipaddr" -o "$gateway_cur" != "$gateway" ]; then - add_task "$1" acquire - if [ "${health_monitor%.*}" = 'parallel' ]; then - exit - else - return - fi - else - [ "$gateway" != "x" ] && ! ip route | grep -o $gateway >&- 2>&- && - add_task route refresh - fi - - if [ "$health_method" == "stats" ] && [ "$ifname" != "x" -a "$ipaddr" != "x" -a "$gateway" != "x" ]; then - new_rx_bytes="$(if_rx_bytes $ifname)" - if [ "$new_rx_bytes" == "0" ]; then - add_task "$1" fail - elif [ "$new_rx_bytes" == "$old_rx_bytes" ]; then - dhcp_renew $ifname - new_rx_bytes="$(if_rx_bytes $ifname)" - network_get_ipaddr ipaddr ${1} || ipaddr=x - network_get_gateway gateway ${1} || gateway=x - if [ "$ipaddr" = "x" -o "$gateway" = "x" ]; then - add_task "$1" fail - elif [ "$new_rx_bytes" == "$old_rx_bytes" ]; then - add_task "$1" fail - elif [ "$new_rx_bytes" != "0" ]; then - old_rx_bytes=$new_rx_bytes - add_task "$1" pass - fi - else - old_rx_bytes=$new_rx_bytes - add_task "$1" pass - fi - elif [ "$health_method" == "ping" ] && [ "$icmp_hosts" != "disable" -a "$ifname" != "x" -a "$ipaddr" != "x" -a "$gateway" != "x" ]; then - - if [ "$icmp_hosts" == "gateway" -o -z "$icmp_hosts" ]; then - icmp_hosts_acquire=$gateway - elif [ "$icmp_hosts" == "dns" ]; then - icmp_hosts_acquire=$(uci_get_state multiwan $1 dns 'auto') - [ "$icmp_hosts_acquire" == "auto" ] && - network_get_dnsserver icmp_hosts_acquire $1 - else - icmp_hosts_acquire=$icmp_hosts - fi - - icmp_hosts=$(echo $icmp_hosts_acquire | sed -e "s/\,/ /g" | sed -e "s/ /\n/g") - - ping_test() { - echo "$icmp_hosts" | while read icmp_test_host; do - ping -c "$icmp_count" -W $timeout -I $ifname $icmp_test_host 2>&1 | grep -o "round-trip" - done - } - - check_test=$(ping_test) - - if [ -z "$check_test" ]; then - add_task "$1" fail - else - add_task "$1" pass - fi - - elif [ "$icmp_hosts" == "disable" ]; then - add_task "$1" pass - fi - - [ "$health_monitor" = 'serial' ] && { - wan_monitor_map=$(echo $wan_monitor_map | sed -e "s/\(^\|.*\]\)${1}\[\w*\]/\1${1}\[$(date +%s)\]/g") - update_cache - break - } - done -} - -# Add a task to the $jobfile while ensuring -# no duplicate tasks for the specified group -add_task() { - local group=$1 - local task=$2 - grep -o "$group.$task" $jobfile >&- 2>&- || echo "$group.$task" >> $jobfile -} - -# For health_monitor "parallel", start a background monitor for each group. -# For health_monitor "serial", queue monitor tasks for do_tasks. -schedule_tasks() { - local group health_interval monitored_last_at current_time diff delay - local i=0 - - get_health_interval() { - group=$(query_config group $1) - health_interval=$(uci_get_state multiwan ${group} health_interval 'disable') - [ "$health_interval" = "disable" ] && health_interval=0 - } - - [ "$health_monitor" = 'parallel' ] && { - while [ $((i++)) -lt $wancount ]; do - get_health_interval $i - if [ "$health_interval" -gt 0 ]; then - monitor_wan $group & - sleep 1 - fi - done - echo "## Started background monitor_wan ##" - health_monitor="parallel.started" - } - - [ "$health_monitor" = 'serial' ] && { - local monitor_disabled=1 - - until [ -f $jobfile ]; do - current_time=$(date +%s) - delay=$max_interval - i=0 - - while [ $((i++)) -lt $wancount ]; do - get_health_interval $i - if [ "$health_interval" -gt 0 ]; then - monitor_disabled=0 - - monitored_last=$(query_config monitor $group) - [ -z "$monitored_last" ] && { - monitored_last=$current_time - wan_monitor_map="${wan_monitor_map}${group}[$monitored_last]" - update_cache - } - - will_monitor_at=$(($monitored_last + $health_interval)) - diff=$(($will_monitor_at - $current_time)) - [ $diff -le 0 ] && add_task "$group" 'monitor' - - delay=$(($delay > $diff ? $diff : $delay)) - fi - done - - [ "$monitor_disabled" -eq 1 ] && { - # Although health monitors are disabled, still - # need to check up on iptables rules in do_tasks - sleep "$iptables_interval" - break - } - [ $delay -gt 0 ] && sleep $delay - done - } -} - -rule_counter=0 -# Process each task in the $jobfile in FIFO order -do_tasks() { - local check_iptables - local queued_task - local current_resolv_file - - while :; do - - . /tmp/.mwan/cache - - if [ "$((++rule_counter))" -eq 5 -o "$health_monitor" = 'serial' ]; then - - check_iptables=$(iptables -n -L MultiWan -t mangle | grep "references" | awk -F "(" '{print $2}' | cut -d " " -f 1) - - if [ -z "$check_iptables" -o "$check_iptables" -lt 4 ]; then - mwnote "Netfilter rules appear to of been altered." - /etc/init.d/multiwan restart - exit - fi - - current_resolv_file=$(ls -l -e /tmp/resolv.conf.auto | awk -F " " '{print $5, $9}') - - if [ "$last_resolv_update" != "$current_resolv_file" ]; then - refresh_dns - fi - - rule_counter=0 - fi - - if [ -f $jobfile ]; then - - mv $jobfile $jobfile.work - - while read LINE; do - - execute_task() { - case $2 in - fail) fail_wan $1;; - pass) recover_wan $1;; - acquire) - acquire_wan_data $1 - [ "${health_monitor%.*}" = 'parallel' ] && { - monitor_wan $1 & - echo "## Started background monitor_wan ##" - } - ;; - monitor) monitor_wan $1;; - refresh) refresh_routes;; - *) echo "## Unknown task command: $2 ##";; - esac - } - - queued_task=$(echo $LINE | awk -F "." '{print $1,$2}') - execute_task $queued_task - done < $jobfile.work - - rm $jobfile.work - fi - - if [ "$health_monitor" = 'serial' ]; then - break - else - sleep 1 - fi - done -} - -fail_start_check(){ - local ipaddr - local gateway - local ifname - local group - - local i=0 - while [ $((i++)) -lt $wancount ]; do - group=$(query_config group $i) - ifname=$(query_config ifname $group) - ipaddr=$(query_config ipaddr $group) - gateway=$(query_config gateway $group) - - if [ "$ifname" == "x" -o "$ipaddr" == "x" -o "$gateway" == "x" ]; then - failover add $group - fi - done -} - -wancount=0 -max_interval=$(((1<<31) - 1)) - -config_load "multiwan" -config_get_bool enabled config enabled '1' -[ "$enabled" -gt 0 ] || exit -config_get default_route config default_route -config_get health_monitor config health_monitor -config_get iptables_interval config iptables_interval '30' -config_get debug config debug - -[ "$health_monitor" = 'serial' ] || health_monitor='parallel' - -config_foreach acquire_wan_data interface - -update_cache - -CHKFORQOS=$(iptables -n -L Default -t mangle 2>&1 | grep "Chain Default") -CHKFORMODULE=$(iptables -m statistic 2>&1 | grep -o "File not found") - -jobfile="/tmp/.mwan/jobqueue" - -case $1 in - agent) silencer main_init;; - stop) silencer stop;; - restart) silencer stop restart;; - single) silencer stop single;; -esac diff --git a/tptest/Makefile b/tptest/Makefile deleted file mode 100644 index 3917e5194..000000000 --- a/tptest/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -include $(TOPDIR)/rules.mk - -PKG_NAME:=tptest -PKG_VERSION:=1.3 -PKG_RELEASE:=0 - -PKG_SOURCE_VERSION:=10685ce4c31a5b6bf582be19f4333aed273a54bf -PKG_SOURCE_PROTO:=git -PKG_SOURCE_URL:=https://dev.iopsys.eu/fork/tptest.git - -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)-$(PKG_SOURCE_VERSION).tar.gz -PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) -PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) -PKG_LICENSE:=LGPL-2.1-only -PKG_LICENSE_FILES:=LICENSE -include $(INCLUDE_DIR)/package.mk - -TARGET_LDFLAGS+= \ - -Wl,-rpath-link=$(STAGING_DIR)/usr/lib \ - -Wl,-rpath-link=$(STAGING_DIR)/lib - -TARGET_CFLAGS+= \ - -DUNIX -DLINUX - -MAKE_OPTS:= \ - ARCH="$(LINUX_KARCH)" \ - CROSS_COMPILE="$(TARGET_CROSS)" \ - SUBDIRS="$(PKG_BUILD_DIR)" \ - -define Package/tptest - CATEGORY:=Utilities - TITLE:=TPTEST speed test utility -endef - -define Package/tptest/description - TPTEST speed test utility -endef - -define Build/Compile - $(MAKE) -C $(PKG_BUILD_DIR) \ - $(TARGET_CONFIGURE_OPTS) LINUX_DIR=$(LINUX_DIR) MAKE_OPTS=$(MAKE_OPTS) LDFLAGS="$(TARGET_LDFLAGS)" CFLAGS="$(TARGET_CFLAGS) -I$(LINUX_DIR)/include -I$(STAGING_DIR)/usr/include" -endef - -define Package/tptest/install - $(CP) ./files/* $(1)/ - $(INSTALL_DIR) $(1)/usr/sbin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/tptest $(1)/usr/sbin/ - $(INSTALL_DIR) $(1)/etc/config -endef - -$(eval $(call BuildPackage,tptest)) diff --git a/tptest/files/etc/config/speedtest b/tptest/files/etc/config/speedtest deleted file mode 100644 index 95734a433..000000000 --- a/tptest/files/etc/config/speedtest +++ /dev/null @@ -1,5 +0,0 @@ - -config testserver '1' - option server 'referens.sth.ip-performance.se' - option port '1641' -