From cffc1cd77b99196f268935cf781e7059b28773bd Mon Sep 17 00:00:00 2001 From: Jan-Niklas Burfeind Date: Tue, 26 Oct 2021 13:25:03 +0200 Subject: [PATCH 01/20] scripts: eva_ramboot.py: remove unused import concludes: commit e7bc8984d9ca ("scripts: make eva_ramboot.py offset configurable") Signed-off-by: Jan-Niklas Burfeind --- scripts/flashing/eva_ramboot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/flashing/eva_ramboot.py b/scripts/flashing/eva_ramboot.py index b182f09d21..365fceecf6 100755 --- a/scripts/flashing/eva_ramboot.py +++ b/scripts/flashing/eva_ramboot.py @@ -3,7 +3,6 @@ import argparse from ftplib import FTP -from sys import argv from os import stat parser = argparse.ArgumentParser(description='Tool to boot AVM EVA ramdisk images.') From 8c4e41d26f1b02c4daeb77324b7a2d32926f3258 Mon Sep 17 00:00:00 2001 From: Sven Roederer Date: Fri, 16 Jul 2021 00:44:53 +0200 Subject: [PATCH 02/20] dropbear: add config options for agent-forwarding support * SSH agent forwarding might cause security issues, locally and on the jump machine (https://defn.io/2019/04/12/ssh-forwarding/). So allow to completely disabling it. * separate options for client and server * keep it enabled by default Signed-off-by: Sven Roederer --- package/network/services/dropbear/Config.in | 9 +++++++++ package/network/services/dropbear/Makefile | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/package/network/services/dropbear/Config.in b/package/network/services/dropbear/Config.in index 15000eff53..d4644fc88f 100644 --- a/package/network/services/dropbear/Config.in +++ b/package/network/services/dropbear/Config.in @@ -95,6 +95,11 @@ config DROPBEAR_DBCLIENT bool "Build dropbear with dbclient" default y +config DROPBEAR_DBCLIENT_AGENTFORWARD + bool "Enable agent forwarding in dbclient" + default y + depends on DROPBEAR_DBCLIENT + config DROPBEAR_SCP bool "Build dropbear with scp" default y @@ -109,4 +114,8 @@ config DROPBEAR_ASKPASS Increases binary size by about 0.1 kB (MIPS). +config DROPBEAR_AGENTFORWARD + bool "Enable agent forwarding" + default y + endmenu diff --git a/package/network/services/dropbear/Makefile b/package/network/services/dropbear/Makefile index 7fb4b7f123..d518de3f70 100644 --- a/package/network/services/dropbear/Makefile +++ b/package/network/services/dropbear/Makefile @@ -32,7 +32,8 @@ PKG_CONFIG_DEPENDS:= \ CONFIG_DROPBEAR_CURVE25519 CONFIG_DROPBEAR_ZLIB \ CONFIG_DROPBEAR_ED25519 CONFIG_DROPBEAR_CHACHA20POLY1305 \ CONFIG_DROPBEAR_UTMP CONFIG_DROPBEAR_PUTUTLINE \ - CONFIG_DROPBEAR_DBCLIENT CONFIG_DROPBEAR_SCP CONFIG_DROPBEAR_ASKPASS + CONFIG_DROPBEAR_DBCLIENT CONFIG_DROPBEAR_SCP CONFIG_DROPBEAR_ASKPASS \ + CONFIG_DROPBEAR_DBCLIENT_AGENTFORWARD CONFIG_DROPBEAR_AGENTFORWARD include $(INCLUDE_DIR)/package.mk @@ -135,6 +136,8 @@ DB_OPT_CONFIG = \ !!DROPBEAR_ECC_384|CONFIG_DROPBEAR_ECC_FULL|1|0 \ !!DROPBEAR_ECC_521|CONFIG_DROPBEAR_ECC_FULL|1|0 \ DROPBEAR_CLI_ASKPASS_HELPER|CONFIG_DROPBEAR_ASKPASS|1|0 \ + DROPBEAR_CLI_AGENTFWD|CONFIG_DROPBEAR_DBCLIENT_AGENTFORWARD|1|0 \ + DROPBEAR_SVR_AGENTFWD|CONFIG_DROPBEAR_AGENTFORWARD|1|0 \ TARGET_CFLAGS += -DARGTYPE=3 -ffunction-sections -fdata-sections -flto From e72185a4a1b2bb6874d1235a99e8ca6309043228 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 26 Sep 2021 17:58:59 -0400 Subject: [PATCH 03/20] scripts: fix various typos This only affects typos in comments or user-facing output. Signed-off-by: Josh Soref [only picks changes to scripts, drop "commandline" replacement, fix case for "arbitrary", improve commit message] Signed-off-by: Adrian Schmutzler --- scripts/checkpatch.pl | 2 +- scripts/dl_github_archive.py | 4 ++-- scripts/ext-toolchain.sh | 2 +- scripts/json_overview_image_info.py | 2 +- scripts/linksys-image.sh | 4 ++-- scripts/pad_image | 2 +- scripts/sign_images.sh | 4 ++-- scripts/size_compare.sh | 4 ++-- scripts/slugimage.pl | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 8ffc093548..aa8038529a 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4697,7 +4697,7 @@ sub process { ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) { ## ## # Remove any bracketed sections to ensure we do not -## # falsly report the parameters of functions. +## # falsely report the parameters of functions. ## my $ln = $line; ## while ($ln =~ s/\([^\(\)]*\)//g) { ## } diff --git a/scripts/dl_github_archive.py b/scripts/dl_github_archive.py index 59fd7067be..b992227dc9 100755 --- a/scripts/dl_github_archive.py +++ b/scripts/dl_github_archive.py @@ -207,7 +207,7 @@ class GitHubCommitTsCache(object): class DownloadGitHubTarball(object): - """Download and repack archive tarabll from GitHub. + """Download and repack archive tarball from GitHub. Compared with the method of packing after cloning the whole repo, this method is more friendly to users with fragile internet connection. @@ -220,7 +220,7 @@ class DownloadGitHubTarball(object): - GitHub archives do not contain source codes for submodules. - - GitHub archives seem to respect .gitattributes and ignore pathes with + - GitHub archives seem to respect .gitattributes and ignore paths with export-ignore attributes. For the first two issues, the method will fail loudly to allow fallback to diff --git a/scripts/ext-toolchain.sh b/scripts/ext-toolchain.sh index ee7d9532f5..4da287591a 100755 --- a/scripts/ext-toolchain.sh +++ b/scripts/ext-toolchain.sh @@ -569,7 +569,7 @@ while [ -n "$1" ]; do echo -e " Most commands also take a --cflags parameter which " >&2 echo -e " is used to specify C flags to be passed to the " >&2 echo -e " cross compiler when performing tests." >&2 - echo -e " This paremter may be repeated multiple times." >&2 + echo -e " This parameter may be repeated multiple times." >&2 exit 1 ;; diff --git a/scripts/json_overview_image_info.py b/scripts/json_overview_image_info.py index db47fd9e42..89b7d4fe20 100755 --- a/scripts/json_overview_image_info.py +++ b/scripts/json_overview_image_info.py @@ -7,7 +7,7 @@ from sys import argv import json if len(argv) != 2: - print("JSON info files script requires ouput file as argument") + print("JSON info files script requires output file as argument") exit(1) output_path = Path(argv[1]) diff --git a/scripts/linksys-image.sh b/scripts/linksys-image.sh index 36a676d964..c3baf44844 100755 --- a/scripts/linksys-image.sh +++ b/scripts/linksys-image.sh @@ -11,11 +11,11 @@ # This is appended to the factory image and is tested by the Linksys Upgrader - as observed in civic. # The footer is 256 bytes. The format is: # .LINKSYS. This is detected by the Linksys upgrader before continuing with upgrade. (9 bytes) -# The version number of upgrade. Not checked so use arbitary value (8 bytes) +# The version number of upgrade. Not checked so use arbitrary value (8 bytes) # Model of target device, padded (0x20) to (15 bytes) # CRC checksum of the image to flash (8 byte) # Padding (0x20) (7 bytes) -# Signature of signer. Not checked so use Arbitary value (16 bytes) +# Signature of signer. Not checked so use arbitrary value (16 bytes) # Padding (0x00) (192 bytes) # 0x0A (1 byte) diff --git a/scripts/pad_image b/scripts/pad_image index b1941a28d8..871063af34 100755 --- a/scripts/pad_image +++ b/scripts/pad_image @@ -2,7 +2,7 @@ function usage { echo "Usage: prepare_image image_type kernel_image rootfs_image header_size" - echo "Padd root and kernel image to the correct size and append the jffs2 start marker as needed" + echo "Pad root and kernel image to the correct size and append the jffs2 start marker as needed" exit 1 } diff --git a/scripts/sign_images.sh b/scripts/sign_images.sh index c41b21e091..f37c2f5016 100755 --- a/scripts/sign_images.sh +++ b/scripts/sign_images.sh @@ -3,12 +3,12 @@ # directory where search for images TOP_DIR="${TOP_DIR:-./bin/targets}" # key to sign images -BUILD_KEY="${BUILD_KEY:-key-build}" # TODO unifiy naming? +BUILD_KEY="${BUILD_KEY:-key-build}" # TODO unify naming? # remove other signatures (added e.g. by buildbot) REMOVE_OTER_SIGNATURES="${REMOVE_OTER_SIGNATURES:-1}" # find all sysupgrade images in TOP_DIR -# factory images don't need signatures as non OpenWrt system doen't check them anyway +# factory images don't need signatures as non OpenWrt system doesn't check them anyway for image in $(find $TOP_DIR -type f -name "*-sysupgrade.bin"); do # check if image actually support metadata if fwtool -i /dev/null "$image"; then diff --git a/scripts/size_compare.sh b/scripts/size_compare.sh index 8b047a451e..a5cc3337c7 100755 --- a/scripts/size_compare.sh +++ b/scripts/size_compare.sh @@ -7,9 +7,9 @@ ### ### The script compares locally compiled package with the package indexes ### available upstream. This way the storage impact of optimizations or -### feature modifiactions is easy to see. +### feature modifications is easy to see. ### -### If no environmental variables are set the scritp reads the current +### If no environmental variables are set the script reads the current ### .config file. The evaluated env variables are the following: ### ### TARGET SUBTARGET ARCH PACKAGES BIN_DIR BASE_URL CHECK_INSTALLED diff --git a/scripts/slugimage.pl b/scripts/slugimage.pl index 8c0654d4f6..366b239e96 100755 --- a/scripts/slugimage.pl +++ b/scripts/slugimage.pl @@ -772,7 +772,7 @@ sub writeOutFirmware { $_->{'name'}, $filename); } - # If the next parition is before the end of the current image, then rewind. + # If the next partition is before the end of the current image, then rewind. elsif ($_->{'offset'} < $end_point) { $debug and printf("Rewound %s before <%s> in \"%s\"\n", (($end_point - $_->{'offset'}) >= $block_size ? @@ -971,7 +971,7 @@ if (!GetOptions("d|debug" => \$debug, print " [-b|--redboot] Input/Output RedBoot filename\n"; print " [-s|--sysconf] Input/Output SysConf filename\n"; print " [-L|--loader] Second stage boot loader filename\n"; - print " [-k|--kernel] Input/Ouptut Kernel filename\n"; + print " [-k|--kernel] Input/Output Kernel filename\n"; print " [-r|--ramdisk] Input/Output Ramdisk filename(s)\n"; print " [-f|--fisdir] Input/Output FIS directory filename\n"; print " [-m|--microcode] Input/Output Microcode filename\n"; From 6bf810b1e1d947da969c01396b7f70e7b6b9f5cb Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 26 Sep 2021 17:58:59 -0400 Subject: [PATCH 04/20] build: fix various typos Fix typos in comment and user-facing help text. Signed-off-by: Josh Soref [split out config changes, adjust commit message] Signed-off-by: Adrian Schmutzler --- config/Config-kernel.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/Config-kernel.in b/config/Config-kernel.in index fd44ddb46b..b3f9cccd7e 100644 --- a/config/Config-kernel.in +++ b/config/Config-kernel.in @@ -887,7 +887,7 @@ config KERNEL_SQUASHFS_XATTR bool "Squashfs XATTR support" # -# compile optimiziation setting +# compile optimization setting # choice prompt "Compiler optimization level" From fa10ceb558aaf883b49eaa02ace996fa97cf228e Mon Sep 17 00:00:00 2001 From: Lucian Cristian Date: Tue, 31 Aug 2021 10:04:36 +0300 Subject: [PATCH 05/20] elfutils: enable host build frr 8.0 needs host libelf dev add option for host build tested on x86, ramips, kirkwood Signed-off-by: Lucian Cristian [changed commit author's email] Signed-off-by: Christian Lamparter --- package/libs/elfutils/Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/package/libs/elfutils/Makefile b/package/libs/elfutils/Makefile index d595e4caf2..b0c9b8bd8c 100644 --- a/package/libs/elfutils/Makefile +++ b/package/libs/elfutils/Makefile @@ -26,6 +26,7 @@ PKG_BUILD_DEPENDS:=!USE_GLIBC:argp-standalone include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/nls.mk +include $(INCLUDE_DIR)/host-build.mk define Package/elfutils/Default SECTION:=libs @@ -60,6 +61,12 @@ else CONFIGURE_ARGS += --disable-nls endif +HOST_CONFIGURE_ARGS += \ + --disable-debuginfod \ + --disable-libdebuginfod \ + --without-lzma \ + --without-zstd + CONFIGURE_ARGS += \ --program-prefix=eu- \ --disable-debuginfod \ @@ -97,6 +104,7 @@ define Package/libelf/install endef # these lines need to be ordered by dependency because of ABI versioning +$(eval $(call HostBuild)) $(eval $(call BuildPackage,libelf)) $(eval $(call BuildPackage,libdw)) $(eval $(call BuildPackage,libasm)) From ea4e37d662be7c60ae587c04953e604325219247 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Fri, 5 Nov 2021 14:53:44 +0800 Subject: [PATCH 06/20] autocore: fix read temp for x86 devices Signed-off-by: Tianling Shen --- package/emortal/autocore/files/generic/cpuinfo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/emortal/autocore/files/generic/cpuinfo b/package/emortal/autocore/files/generic/cpuinfo index 5bd86ae685..771b8444f6 100755 --- a/package/emortal/autocore/files/generic/cpuinfo +++ b/package/emortal/autocore/files/generic/cpuinfo @@ -27,9 +27,9 @@ if grep -q "bcm27xx" "/etc/openwrt_release"; then cpu_temp="$(vcgencmd measure_temp | awk -F '=' '{print $2}' | awk -F "'" '{print $1}')°C" elif grep -q "x86" "/etc/openwrt_release"; then # Intel - cpu_temp="$(sensors "coretemp-*" 2>"/dev/null" | grep "Package id 0" | head -n1 | awk '{print $4}' | tr -d "+")" + cpu_temp="$(sensors "coretemp-*" 2>"/dev/null" | grep -E "(Package id |Core )" | grep -Eo "\+[0-9]*" | head -n1 | tr -d "+")°C" # AMD - [ -z "${cpu_temp}" ] && cpu_temp="$(sensors "k10temp-*" 2>"/dev/null" | grep "Tdie" | head -n1 | awk '{print $2}' | tr -d "+")" + [ -z "${cpu_temp}" ] && cpu_temp="$(sensors "k*temp-*" 2>"/dev/null" | grep "Tdie" | head -n1 | awk '{print $2}' | tr -d "+")" else [ -e "/sys/class/thermal/thermal_zone0/temp" ] && \ cpu_temp="$(awk '{printf("%.1f°C", $0 / 1000)}' /sys/class/thermal/thermal_zone0/temp)" From 872fd346422940a83b3f93247d1ef6bb13327495 Mon Sep 17 00:00:00 2001 From: Dominick Grift Date: Fri, 22 Oct 2021 13:51:11 +0200 Subject: [PATCH 07/20] libsepol: update to version 3.3 Signed-off-by: Dominick Grift --- package/libs/libsepol/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/libs/libsepol/Makefile b/package/libs/libsepol/Makefile index c7950a9ba0..87f1ccd917 100644 --- a/package/libs/libsepol/Makefile +++ b/package/libs/libsepol/Makefile @@ -6,12 +6,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=libsepol -PKG_VERSION:=3.2 +PKG_VERSION:=3.3 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/3.2 -PKG_HASH:=dfc7f662af8000116e56a01de6a0394ed79be1b34b999e551346233c5dd19508 +PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/$(PKG_VERSION) +PKG_HASH:=2d97df3eb8466169b389c3660acbb90c54200ac96e452eca9f41a9639f4f238b PKG_MAINTAINER:=Thomas Petazzoni From d6a422da0044d1361f836553997aff5388bd954b Mon Sep 17 00:00:00 2001 From: Dominick Grift Date: Fri, 22 Oct 2021 13:51:12 +0200 Subject: [PATCH 08/20] libselinux: update to version 3.3 Signed-off-by: Dominick Grift --- package/libs/libselinux/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/libs/libselinux/Makefile b/package/libs/libselinux/Makefile index 0c5f9baceb..3969ef38d9 100644 --- a/package/libs/libselinux/Makefile +++ b/package/libs/libselinux/Makefile @@ -6,12 +6,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=libselinux -PKG_VERSION:=3.2 +PKG_VERSION:=3.3 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/3.2 -PKG_HASH:=df758ef1d9d4811051dd901ea6b029ae334ffd7c671c128beb16bce1e25ac161 +PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/$(PKG_VERSION) +PKG_HASH:=acfdee27633d2496508c28727c3d41d3748076f66d42fccde2e6b9f3463a7057 HOST_BUILD_DEPENDS:=libsepol/host pcre/host PKG_LICENSE:=libselinux-1.0 From 4ac1ede70c38a4047718ab98e55222d45abbd01f Mon Sep 17 00:00:00 2001 From: Dominick Grift Date: Fri, 22 Oct 2021 13:51:13 +0200 Subject: [PATCH 09/20] libsemanage: update to version 3.3 Signed-off-by: Dominick Grift --- package/libs/libsemanage/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package/libs/libsemanage/Makefile b/package/libs/libsemanage/Makefile index 2fde14c06c..8337b90bda 100644 --- a/package/libs/libsemanage/Makefile +++ b/package/libs/libsemanage/Makefile @@ -6,12 +6,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=libsemanage -PKG_VERSION:=3.2 -PKG_RELEASE:=2 +PKG_VERSION:=3.3 +PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/3.2 -PKG_HASH:=d722a55ca4fe2d4e2b30527720db657e6238b28079e69e2e4affeb8e733ee511 +PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/$(PKG_VERSION) +PKG_HASH:=84d0ec5afa34bbbb471f602d8c1bf317d12443d07852a34b60741d428d597ce8 PKG_MAINTAINER:=Thomas Petazzoni PKG_LICENSE:=LGPL-2.1 PKG_LICENSE_FILES:=COPYING From eb00300bebd63500b3e09ae44a2a66fd7893b4f0 Mon Sep 17 00:00:00 2001 From: Dominick Grift Date: Fri, 22 Oct 2021 13:51:14 +0200 Subject: [PATCH 10/20] checkpolicy: update to version 3.3 Signed-off-by: Dominick Grift --- package/utils/checkpolicy/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/utils/checkpolicy/Makefile b/package/utils/checkpolicy/Makefile index 206bf201c0..e9c10e293f 100644 --- a/package/utils/checkpolicy/Makefile +++ b/package/utils/checkpolicy/Makefile @@ -6,12 +6,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=checkpolicy -PKG_VERSION:=3.2 +PKG_VERSION:=3.3 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/3.2 -PKG_HASH:=9b1c81fa86fe3867842164448d90c8e7ea94b2987497809c65d4caa87a5c5bc8 +PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/$(PKG_VERSION) +PKG_HASH:=25c84edfa3a10ab8cb073b97bc55cb66377532d54a2723da9accdabd05431485 PKG_INSTALL:=1 PKG_BUILD_DEPENDS:=libselinux HOST_BUILD_DEPENDS:=libselinux/host From 522c0a0862e797282bdf865bb4231f540e63266d Mon Sep 17 00:00:00 2001 From: Dominick Grift Date: Fri, 22 Oct 2021 13:51:15 +0200 Subject: [PATCH 11/20] policycoreutils: update to version 3.3 Signed-off-by: Dominick Grift --- package/utils/policycoreutils/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/utils/policycoreutils/Makefile b/package/utils/policycoreutils/Makefile index 249c2afb94..f724deda97 100644 --- a/package/utils/policycoreutils/Makefile +++ b/package/utils/policycoreutils/Makefile @@ -6,12 +6,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=policycoreutils -PKG_VERSION:=3.2 +PKG_VERSION:=3.3 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/3.2 -PKG_HASH:=d1331c6fa766c547b071c491de90b9f343c8dbffdb119be8a5a7e491199b93a9 +PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/$(PKG_VERSION) +PKG_HASH:=4199040ced8a81f2ddd0522b4faf2aba62fc821473f4051dc8474fb1c4a01078 PKG_INSTALL:=1 HOST_BUILD_DEPENDS:=libsemanage/host gettext-full/host PKG_BUILD_DEPENDS:=BUSYBOX_CONFIG_PAM:libpam gettext-full/host From 94d29affa12e690a82a24172c8e368c054b7a2b3 Mon Sep 17 00:00:00 2001 From: Dominick Grift Date: Fri, 22 Oct 2021 13:51:16 +0200 Subject: [PATCH 12/20] secilc: update to version 3.3 Signed-off-by: Dominick Grift --- package/utils/secilc/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/utils/secilc/Makefile b/package/utils/secilc/Makefile index 7ed22615c0..6f059bfc81 100644 --- a/package/utils/secilc/Makefile +++ b/package/utils/secilc/Makefile @@ -6,12 +6,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=secilc -PKG_VERSION:=3.2 +PKG_VERSION:=3.3 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/3.2 -PKG_HASH:=5f6e6528a281b29ac5e558babffc3d8aab682fd8df8977daff5f266a50292cc3 +PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/$(PKG_VERSION) +PKG_HASH:=2c5e1a5d417baf1d2aa3eac294e12c3aac7184a5ef6a779dcbe469ed756e8651 HOST_BUILD_DEPENDS:=libsepol/host PKG_MAINTAINER:=Dominick Grift From 80196ba2a55abbf62505cde14df8f60db7f7860a Mon Sep 17 00:00:00 2001 From: Dominick Grift Date: Fri, 22 Oct 2021 19:42:40 +0200 Subject: [PATCH 13/20] selinux-policy: update to version 1.0 wifi: writes to terminal hotplugcall and sqm read class sysfile symlinks unbound and sqm related loose ends support/example: policycoreutils host-compile is required TODO: this was wrong and it is actually needed linguist detectable does not work this way linguist-detectable updates README adds workflows adds a note about persistent /var option project moved to https://github.com/DefenSec/selinux-policy Signed-off-by: Dominick Grift --- package/system/selinux-policy/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/system/selinux-policy/Makefile b/package/system/selinux-policy/Makefile index 219ebc7995..0b85920170 100644 --- a/package/system/selinux-policy/Makefile +++ b/package/system/selinux-policy/Makefile @@ -7,9 +7,9 @@ include $(TOPDIR)/rules.mk PKG_NAME:=selinux-policy PKG_SOURCE_PROTO:=git -PKG_SOURCE_URL:=https://git.defensec.nl/selinux-policy.git -PKG_VERSION:=0.9 -PKG_MIRROR_HASH:=f1a37a4fc104fbacde3012178fc117b473899360f26a8735156394288441d99c +PKG_SOURCE_URL:=https://github.com/DefenSec/selinux-policy +PKG_VERSION:=1.0 +PKG_MIRROR_HASH:=2358a064d1231d39e6292d646e1a38898d949b8bef6558ac1e0992d3b5bca33f PKG_SOURCE_VERSION:=v$(PKG_VERSION) PKG_BUILD_DEPENDS:=secilc/host policycoreutils/host From 87911b01c28ce5a11f78479cbb9702c663a60cd7 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Sat, 6 Nov 2021 23:28:48 +0800 Subject: [PATCH 14/20] default-settings: set lang to zh_CN for Chinese builds explicitly Signed-off-by: Tianling Shen --- .../emortal/default-settings/files/zzz-default-settings-chinese | 1 + 1 file changed, 1 insertion(+) diff --git a/package/emortal/default-settings/files/zzz-default-settings-chinese b/package/emortal/default-settings/files/zzz-default-settings-chinese index 30a9167bca..58ef48f177 100755 --- a/package/emortal/default-settings/files/zzz-default-settings-chinese +++ b/package/emortal/default-settings/files/zzz-default-settings-chinese @@ -1,6 +1,7 @@ #!/bin/sh uci -q batch <<-EOF + set luci.main.lang='zh_cn' set system.@system[0].timezone='CST-8' set system.@system[0].zonename='Asia/Shanghai' From 2463ef37d3f9f665a7eaffb7e050d1ef320168f6 Mon Sep 17 00:00:00 2001 From: Koen Vandeputte Date: Tue, 12 Oct 2021 11:02:30 +0200 Subject: [PATCH 15/20] ar71xx: mikrotik: rb91x: fix 10M ethernet link speed Extensive testing on the board showed that ethernet does not work when forced to 10Mbps. Trial-and-error revealed that the correct PLL value should be altered to 0x00001313 (iso 0x00001616) The change is done for this specific board only as I do not have other boards using this specific SoC. The board now works correctly in 1000, 100 and 10 Mode Signed-off-by: Koen Vandeputte (cherry picked from commit 5e8b9624f1791d193e8d5e007ce4c873454f014a) --- target/linux/ar71xx/files/arch/mips/ath79/mach-rb91x.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-rb91x.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-rb91x.c index e240c3ad43..458ae09f7d 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-rb91x.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-rb91x.c @@ -318,6 +318,7 @@ static void __init rb711gr100_setup(void) ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0); ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII; ath79_eth0_data.phy_mask = BIT(0); + ath79_eth0_pll_data.pll_10 = 0x00001313; ath79_eth0_pll_data.pll_1000 = 0x02000000; ath79_register_eth(0); From 58dbe18bebfa3fb39966e11e044b39883bdacac2 Mon Sep 17 00:00:00 2001 From: Alan Swanson Date: Fri, 1 Oct 2021 16:46:32 +0100 Subject: [PATCH 16/20] uboot-lantiq: fix sha1.h header clash when system libmd installed Backport of u-boot commit "includes: move openssl headers to include/u-boot" https://github.com/u-boot/u-boot/commit/2b9912e6a7df7b1f60beb7942bd0e6fa5f9d0167 Fixes: FS#3955 Signed-off-by: Alan Swanson (cherry picked from commit 8db641049292035604f0e1fb788608fdea879eca) --- .../patches/101-fix-crypt-header-clash.patch | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 package/boot/uboot-lantiq/patches/101-fix-crypt-header-clash.patch diff --git a/package/boot/uboot-lantiq/patches/101-fix-crypt-header-clash.patch b/package/boot/uboot-lantiq/patches/101-fix-crypt-header-clash.patch new file mode 100644 index 0000000000..fcb1a3d95b --- /dev/null +++ b/package/boot/uboot-lantiq/patches/101-fix-crypt-header-clash.patch @@ -0,0 +1,172 @@ +Fix header clash with system /usr/include/sha1.h and sha256.h when libmd +is installed. + +Backport of u-boot commit "includes: move openssl headers to include/u-boot" +https://github.com/u-boot/u-boot/commit/2b9912e6a7df7b1f60beb7942bd0e6fa5f9d0167 + +--- a/board/gdsys/p1022/controlcenterd-id.c ++++ b/board/gdsys/p1022/controlcenterd-id.c +@@ -30,7 +30,7 @@ + #include + #include + #include +-#include ++#include + #include + #include + #include +--- a/board/pcs440ep/pcs440ep.c ++++ b/board/pcs440ep/pcs440ep.c +@@ -13,7 +13,7 @@ + #include + #include + #include +-#include ++#include + #include + #include + #include +--- a/common/cmd_sha1sum.c ++++ b/common/cmd_sha1sum.c +@@ -11,7 +11,7 @@ + #include + #include + #include +-#include ++#include + + int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) + { +--- a/common/hash.c ++++ b/common/hash.c +@@ -14,8 +14,8 @@ + #include + #include + #include +-#include +-#include ++#include ++#include + #include + #include + +--- a/common/image-fit.c ++++ b/common/image-fit.c +@@ -21,7 +21,7 @@ DECLARE_GLOBAL_DATA_PTR; + #endif /* !USE_HOSTCC*/ + + #include +-#include ++#include + #include + #include + +--- a/common/image.c ++++ b/common/image.c +@@ -34,7 +34,7 @@ + #endif + + #include +-#include ++#include + #include + #include + +--- a/drivers/crypto/ace_sha.c ++++ b/drivers/crypto/ace_sha.c +@@ -5,8 +5,8 @@ + * SPDX-License-Identifier: GPL-2.0+ + */ + #include +-#include +-#include ++#include ++#include + #include + #include "ace_sha.h" + +--- /dev/null ++++ b/include/u-boot/sha1.h +@@ -0,0 +1 @@ ++#include "../sha1.h" +--- /dev/null ++++ b/include/u-boot/sha256.h +@@ -0,0 +1 @@ ++#include "../sha256.h" +--- a/lib/rsa/rsa-verify.c ++++ b/lib/rsa/rsa-verify.c +@@ -7,7 +7,7 @@ + #include + #include + #include +-#include ++#include + #include + #include + #include +--- a/lib/sha1.c ++++ b/lib/sha1.c +@@ -36,7 +36,7 @@ + #include + #endif /* USE_HOSTCC */ + #include +-#include "sha1.h" ++#include + + /* + * 32-bit integer manipulation macros (big endian) +--- a/lib/sha256.c ++++ b/lib/sha256.c +@@ -11,7 +11,7 @@ + #endif /* USE_HOSTCC */ + #include + #include +-#include ++#include + + /* + * 32-bit integer manipulation macros (big endian) +--- a/lib/tpm.c ++++ b/lib/tpm.c +@@ -7,7 +7,7 @@ + + #include + #include +-#include ++#include + #include + #include + +--- a/tools/imls/imls.c ++++ b/tools/imls/imls.c +@@ -24,7 +24,7 @@ + #include + #endif + +-#include ++#include + #include + #include + #include +--- a/tools/mkimage.h ++++ b/tools/mkimage.h +@@ -18,7 +18,7 @@ + #include + #include + #include +-#include ++#include + #include "fdt_host.h" + + #undef MKIMAGE_DEBUG +--- a/tools/ubsha1.c ++++ b/tools/ubsha1.c +@@ -13,7 +13,7 @@ + #include + #include + #include +-#include "sha1.h" ++#include + + int main (int argc, char **argv) + { From aa58b28e476e00a3747693f7edca17f4c797e8b0 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Tue, 26 Oct 2021 13:02:37 +0100 Subject: [PATCH 17/20] base-files, metadata: support additional group membership Some packages may require additional group membership for the system user added by that package. Allow defining additional groups as third member of the ':'-separated tuple, allowing to specify multiple ','-separated groups with optional GID. Example: USERID:=foouser=1000:foogroup=1000:addg1=1001,addg2=1002,addg3 Signed-off-by: Daniel Golle (cherry picked from commit b2aca61360c33ad3161f8ef35a1c28ebb2507600) --- package/base-files/files/lib/functions.sh | 23 ++++++++++++++++++++--- scripts/metadata.pm | 8 +++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index a8d340f32e..56fe8800f7 100644 --- a/package/base-files/files/lib/functions.sh +++ b/package/base-files/files/lib/functions.sh @@ -188,10 +188,10 @@ add_group_and_user() { if [ -n "$rusers" ]; then local tuple oIFS="$IFS" for tuple in $rusers; do - local uid gid uname gname + local uid gid uname gname addngroups addngroup addngname addngid IFS=":" - set -- $tuple; uname="$1"; gname="$2" + set -- $tuple; uname="$1"; gname="$2"; addngroups="$3" IFS="=" set -- $uname; uname="$1"; uid="$2" set -- $gname; gname="$1"; gid="$2" @@ -211,7 +211,24 @@ add_group_and_user() { group_add_user "$gname" "$uname" fi - unset uid gid uname gname + if [ -n "$uname" ] && [ -n "$addngroups" ]; then + oIFS="$IFS" + IFS="," + for addngroup in $addngroups ; do + IFS="=" + set -- $addngroup; addngname="$1"; addngid="$2" + if [ -n "$addngid" ]; then + group_exists "$addngname" || group_add "$addngname" "$addngid" + else + group_add_next "$addngname" + fi + + group_add_user "$addngname" "$uname" + done + IFS="$oIFS" + fi + + unset uid gid uname gname addngroups addngroup addngname addngid done fi } diff --git a/scripts/metadata.pm b/scripts/metadata.pm index a884f6f3d0..37df230bec 100644 --- a/scripts/metadata.pm +++ b/scripts/metadata.pm @@ -291,13 +291,19 @@ sub parse_package_metadata($) { my @ugspecs = split /\s+/, $1; for my $ugspec (@ugspecs) { - my @ugspec = split /:/, $ugspec, 2; + my @ugspec = split /:/, $ugspec, 3; if ($ugspec[0]) { parse_package_metadata_usergroup($src->{makefile}, "user", \%usernames, \%userids, $ugspec[0]) or return 0; } if ($ugspec[1]) { parse_package_metadata_usergroup($src->{makefile}, "group", \%groupnames, \%groupids, $ugspec[1]) or return 0; } + if ($ugspec[2]) { + my @addngroups = split /,/, $ugspec[2]; + for my $addngroup (@addngroups) { + parse_package_metadata_usergroup($src->{makefile}, "group", \%groupnames, \%groupids, $addngroup) or return 0; + } + } } }; } From 661f8b7cb6bd7063befb68a585768ed8cc4e084c Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Wed, 10 Nov 2021 19:50:47 +0800 Subject: [PATCH 18/20] autocore: fix read temp for x86 device Signed-off-by: Tianling Shen --- package/emortal/autocore/files/generic/cpuinfo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/emortal/autocore/files/generic/cpuinfo b/package/emortal/autocore/files/generic/cpuinfo index 771b8444f6..58d1de92d4 100755 --- a/package/emortal/autocore/files/generic/cpuinfo +++ b/package/emortal/autocore/files/generic/cpuinfo @@ -27,7 +27,7 @@ if grep -q "bcm27xx" "/etc/openwrt_release"; then cpu_temp="$(vcgencmd measure_temp | awk -F '=' '{print $2}' | awk -F "'" '{print $1}')°C" elif grep -q "x86" "/etc/openwrt_release"; then # Intel - cpu_temp="$(sensors "coretemp-*" 2>"/dev/null" | grep -E "(Package id |Core )" | grep -Eo "\+[0-9]*" | head -n1 | tr -d "+")°C" + cpu_temp="$(sensors "coretemp-*" 2>"/dev/null" | grep -E "(Package id |Core )" | grep -Eo "\+[0-9.]*°C" | head -n1 | tr -d "+")" # AMD [ -z "${cpu_temp}" ] && cpu_temp="$(sensors "k*temp-*" 2>"/dev/null" | grep "Tdie" | head -n1 | awk '{print $2}' | tr -d "+")" else From 418beef4bc39e36ed6378d8e6fd28e6ccd5ff358 Mon Sep 17 00:00:00 2001 From: AmadeusGhost <42570690+AmadeusGhost@users.noreply.github.com> Date: Wed, 3 Nov 2021 23:02:36 +0800 Subject: [PATCH 19/20] libiptbwctl: fixes build error Fixes: #505 --- package/emortal/libiptbwctl/Makefile | 38 +-- package/emortal/libiptbwctl/src/Makefile | 12 +- package/emortal/libiptbwctl/src/ipt_bwctl.c | 242 +++++++----------- package/emortal/libiptbwctl/src/ipt_bwctl.h | 18 +- .../emortal/libiptbwctl/src/utils/bw_get.c | 12 +- .../emortal/libiptbwctl/src/utils/bw_set.c | 21 +- 6 files changed, 127 insertions(+), 216 deletions(-) diff --git a/package/emortal/libiptbwctl/Makefile b/package/emortal/libiptbwctl/Makefile index 681e55d750..4981f55ed3 100644 --- a/package/emortal/libiptbwctl/Makefile +++ b/package/emortal/libiptbwctl/Makefile @@ -9,37 +9,26 @@ include $(TOPDIR)/rules.mk PKG_NAME:=libiptbwctl -PKG_VERSION:=$(GARGOYLE_VERSION) -ifeq ($(GARGOYLE_VERSION),) - PKG_VERSION:=1.0.0 -endif +PKG_VERSION:=1.0.0 PKG_RELEASE:=1 -PKG_BUILD_DIR:=$(BUILD_DIR)/libiptbwctl +PKG_MAINTAINER:=Eric Bishop include $(INCLUDE_DIR)/package.mk define Package/libiptbwctl - SECTION:=net - CATEGORY:=Network - DEPENDS:=+iptables-mod-bandwidth - TITLE:=IPT bandwidth control library - URL:=http://www.gargoyle-router.com - MAINTAINER:=Eric Bishop + SECTION:=libs + CATEGORY:=Libraries + SUBMENU:=Networking + DEPENDS:=+iptables-mod-bandwidth + TITLE:=IPT bandwidth control library + URL:=http://www.gargoyle-router.com endef - define Package/libiptbwctl/description IPT bandwidth control library endef - -define Build/Prepare - mkdir -p $(PKG_BUILD_DIR) - $(CP) ./src/* $(PKG_BUILD_DIR)/ -endef - - define Build/Configure endef @@ -51,13 +40,13 @@ define Build/Compile CFLAGS="$(TARGET_CFLAGS) -I $(STAGING_DIR)/usr/include" \ LDFLAGS="$(TARGET_LDFLAGS) -L $(STAGING_DIR)/usr/lib" \ all - + mkdir -p $(STAGING_DIR)/usr/include/ $(CP) $(PKG_BUILD_DIR)/*.h $(STAGING_DIR)/usr/include/ mkdir -p $(STAGING_DIR)/usr/lib $(CP) $(PKG_BUILD_DIR)/*.so* $(STAGING_DIR)/usr/lib/ - + $(MAKE) -C $(PKG_BUILD_DIR)/utils \ $(TARGET_CONFIGURE_OPTS) \ STAGING_DIR="$(STAGING_DIR)" \ @@ -66,11 +55,8 @@ define Build/Compile all endef - - define Package/libiptbwctl/install - $(INSTALL_DIR) $(1)/usr/lib - $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib $(CP) $(PKG_BUILD_DIR)/*.so* $(1)/usr/lib/ $(INSTALL_BIN) $(PKG_BUILD_DIR)/utils/bw_get $(1)/usr/bin/bw_get $(INSTALL_BIN) $(PKG_BUILD_DIR)/utils/bw_set $(1)/usr/bin/bw_set @@ -78,6 +64,4 @@ define Package/libiptbwctl/install $(INSTALL_BIN) $(PKG_BUILD_DIR)/utils/set_kernel_timezone $(1)/usr/bin/set_kernel_timezone endef - $(eval $(call BuildPackage,libiptbwctl)) - diff --git a/package/emortal/libiptbwctl/src/Makefile b/package/emortal/libiptbwctl/src/Makefile index 5306846620..42c308fc73 100644 --- a/package/emortal/libiptbwctl/src/Makefile +++ b/package/emortal/libiptbwctl/src/Makefile @@ -1,6 +1,5 @@ VERSION=1 - ifeq ($(CC),) CC=gcc endif @@ -17,8 +16,6 @@ ifeq ($(RANLIB),) RANLIB=ranlib endif - - OS=$(shell uname) ifeq ($(OS),Darwin) LINK=$(LD) @@ -35,22 +32,18 @@ endif CFLAGS:=$(CFLAGS) -Os WARNING_FLAGS=-Wall -Wstrict-prototypes - - all: libiptbwctl libiptbwctl: libiptbwctl.$(SHLIB_EXT) libiptbwctl.a - libiptbwctl.a: ipt_bwctl_static.o ipt_bwctl_safe_malloc_static.o if [ -e $@ ] ; then rm $@ ; fi $(AR) rc $@ $^ $(RANLIB) $@ - libiptbwctl.$(SHLIB_EXT) : ipt_bwctl_dyn.o ipt_bwctl_safe_malloc_dyn.o if [ -e libiptbwctl.$(SHLIB_EXT) ] ; then rm libiptbwctl.$(SHLIB_EXT)* ; fi - $(LINK) $(LDFLAGS) $(SHLIB_FLAGS) -o $(SHLIB_FILE) $^ -lc + $(LINK) $(LDFLAGS) $(SHLIB_FLAGS) -o $(SHLIB_FILE) $^ -lc ln -s $(SHLIB_FILE) libiptbwctl.$(SHLIB_EXT) %_dyn.o: %.c @@ -59,9 +52,6 @@ libiptbwctl.$(SHLIB_EXT) : ipt_bwctl_dyn.o ipt_bwctl_safe_malloc_dyn.o %_static.o: %.c $(CC) $(CFLAGS) $(WARNING_FLAGS) -o $@ -c $^ - - - clean: cd utils rm -rf bw_get bw_set *.a *.o *~ .*sw* diff --git a/package/emortal/libiptbwctl/src/ipt_bwctl.c b/package/emortal/libiptbwctl/src/ipt_bwctl.c index 27f33a2ab5..f4e2856cdc 100644 --- a/package/emortal/libiptbwctl/src/ipt_bwctl.c +++ b/package/emortal/libiptbwctl/src/ipt_bwctl.c @@ -18,25 +18,20 @@ * along with this program. If not, see . */ - #include "ipt_bwctl.h" #define malloc ipt_bwctl_safe_malloc #define strdup ipt_bwctl_safe_strdup - static int bandwidth_semaphore = -1; -union semun +union semun { - int val; // Value for SETVAL - struct semid_ds *buf; // Buffer for IPC_STAT, IPC_SET - unsigned short *array; // Array for GETALL, SETALL - struct seminfo *__buf; // Buffer for IPC_INFO (Linux specific) + int val; // Value for SETVAL + struct semid_ds *buf; // Buffer for IPC_STAT, IPC_SET + unsigned short *array; // Array for GETALL, SETALL + struct seminfo *__buf; // Buffer for IPC_INFO (Linux specific) }; - - - /* semaphore functions */ static int get_sem_val(int sid, int member); static int get_sem(int *sid, key_t key); @@ -47,65 +42,63 @@ static int unlock(void); /* needed to calculate history time intervals */ -static time_t get_next_node_start_time( time_t current_start_time, - time_t reset_interval, - time_t reset_time, +static time_t get_next_node_start_time( time_t current_start_time, + time_t reset_interval, + time_t reset_time, unsigned char is_constant_interval ); /* functions used to get data from kernel module */ -static void parse_returned_ip_data( void *out_data, - uint32_t* out_index, - unsigned char* in_buffer, - uint32_t* in_index, - unsigned char get_history, - time_t reset_interval, - time_t reset_time, +static void parse_returned_ip_data( void *out_data, + uint32_t* out_index, + unsigned char* in_buffer, + uint32_t* in_index, + unsigned char get_history, + time_t reset_interval, + time_t reset_time, unsigned char is_constant_interval ); -static int get_bandwidth_data( char* id, - unsigned char get_history, - char* ip, - unsigned long* num_ips, - void** data, +static int get_bandwidth_data( char* id, + unsigned char get_history, + char* ip, + unsigned long* num_ips, + void** data, unsigned long max_wait_milliseconds ); /* functions used to send/restore data to kernel module */ -static int set_ip_block( void* ip_block_data, - unsigned char is_history, - unsigned char* output_buffer, - uint32_t* current_output_index, +static int set_ip_block( void* ip_block_data, + unsigned char is_history, + unsigned char* output_buffer, + uint32_t* current_output_index, uint32_t output_buffer_length ); -static int set_bandwidth_data( char* id, - unsigned char zero_unset, - unsigned char set_history, - unsigned long num_ips, - time_t last_backup, - void* data, +static int set_bandwidth_data( char* id, + unsigned char zero_unset, + unsigned char set_history, + unsigned long num_ips, + time_t last_backup, + void* data, unsigned long max_wait_milliseconds ); /* utility i/o functions when saving/restoring data to/from file */ -static unsigned char* read_entire_file( FILE* in, - unsigned long read_block_size, +static unsigned char* read_entire_file( FILE* in, + unsigned long read_block_size, unsigned long *length ); -static char** split_on_separators( char* line, - char* separators, - int num_separators, - int max_pieces, - int include_remainder_at_max, +static char** split_on_separators( char* line, + char* separators, + int num_separators, + int max_pieces, + int include_remainder_at_max, unsigned long *pieces_read ); - - static int get_sem_val(int sid, int member) { int semval; @@ -119,12 +112,12 @@ static int get_sem(int *sid, key_t key) union semun semopts; int members = 1; - + int success = ((*sid = semget(key, members, IPC_CREAT|IPC_EXCL|0777))== -1) ? 0 : 1; if(success) { semopts.val = 1; - /* Initialize all members (could be done with SETALL) */ + /* Initialize all members (could be done with SETALL) */ for(cntr=0; cntrlast_end = ip_bw_data->last_end; history->history_bws = (uint64_t*)malloc( (history->num_nodes+1)*sizeof(uint64_t) ); - + /* read bws */ int node_index = 0; *in_index += 32; @@ -334,8 +322,7 @@ static void parse_returned_ip_data( void *out_data, (history->history_bws)[node_index] = ip_bw_data->ipbw_data[node_index]; } - - /* + /* * We now need to deal with DST * * The problem is that the kernel can't tell the difference @@ -344,7 +331,7 @@ static void parse_returned_ip_data( void *out_data, * shifts values in the bandwidth history to reflect the time * as it would be if the current offset from UTC had always been * in effect. So, we need to go backwards through the history and - * anytime we go from DST to non-DST (or visa-versa) implement a + * anytime we go from DST to non-DST (or visa-versa) implement a * shift so that returned times reflect reality. */ time_t now; @@ -357,10 +344,9 @@ static void parse_returned_ip_data( void *out_data, *out_index = *out_index + 1; } - static int get_bandwidth_data(char* id, unsigned char get_history, char* ip, unsigned long* num_ips, void** data, unsigned long max_wait_milliseconds) -{ - +{ + unsigned char buf[BANDWIDTH_QUERY_LENGTH]; memset(buf, '\0', BANDWIDTH_QUERY_LENGTH); int done = 0; @@ -369,7 +355,6 @@ static int get_bandwidth_data(char* id, unsigned char get_history, char* ip, uns *data = NULL; *num_ips = 0; - int got_lock = lock(max_wait_milliseconds); int sockfd = -1; if(got_lock) @@ -377,7 +362,6 @@ static int get_bandwidth_data(char* id, unsigned char get_history, char* ip, uns sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); } - uint32_t* request_ip = (uint32_t*)buf; uint32_t* request_index = (uint32_t*)(buf + 4); unsigned char* request_history =(unsigned char*)(buf + 8); @@ -393,6 +377,7 @@ static int get_bandwidth_data(char* id, unsigned char get_history, char* ip, uns inet_aton(ip, &addr); *request_ip = (uint32_t)addr.s_addr; } + *request_index = 0; *request_history = get_history; sprintf(request_id, "%s", id); @@ -419,7 +404,7 @@ static int get_bandwidth_data(char* id, unsigned char get_history, char* ip, uns time_t reset_interval = ip_bw_data->reset_interval; time_t reset_time = ip_bw_data->reset_time; unsigned char is_constant_interval = ip_bw_data->reset_is_constant_interval; - + if(!data_initialized) { *num_ips = total_ips; @@ -490,7 +475,6 @@ static int get_bandwidth_data(char* id, unsigned char get_history, char* ip, uns return got_lock && (error == 0); } - static int set_ip_block(void* ip_block_data, unsigned char is_history, unsigned char* output_buffer, uint32_t* current_output_index, uint32_t output_buffer_length) { if(is_history) @@ -501,15 +485,14 @@ static int set_ip_block(void* ip_block_data, unsigned char is_history, unsigned { return 1; } - + *( (uint32_t*)(output_buffer + *current_output_index) ) = history->ip; *current_output_index = *current_output_index + 4; *( (uint32_t*)(output_buffer + *current_output_index) ) = history->num_nodes; *current_output_index = *current_output_index + 4; - - /* + /* * We now need to deal with DST * * The problem is that the kernel module can't tell the difference @@ -517,9 +500,9 @@ static int set_ip_block(void* ip_block_data, unsigned char is_history, unsigned * time. Whenever the time offset from UTC shifts, the kernel module * shifts values in the bandwidth history to reflect the time * as it would be if the current offset from UTC had always been - * in effect. In order to keep all data in the kernel module + * in effect. In order to keep all data in the kernel module * consistent we need to make sure values we send kernel module - * are adjusted for current offset from UTC, not the real one, + * are adjusted for current offset from UTC, not the real one, * where the offset may be inconsistent because of DST. * * Also note we ignore all but the first, second and last values in the @@ -529,7 +512,7 @@ static int set_ip_block(void* ip_block_data, unsigned char is_history, unsigned * values are returned. However, when setting data, it's perfectly ok * to just have the three necessary values and set everything else to zero */ - time_t first_start = history->first_start; + time_t first_start = history->first_start; time_t first_end = history->first_end; time_t last_end = history->last_end; @@ -539,8 +522,8 @@ static int set_ip_block(void* ip_block_data, unsigned char is_history, unsigned first_start = first_start + (get_minutes_west(first_start)-current_minutes_west); first_end = first_end + (get_minutes_west(first_end)-current_minutes_west); last_end = last_end + (get_minutes_west(last_end)-current_minutes_west); - - + + *( (uint64_t*)(output_buffer + *current_output_index) ) = (uint64_t)first_start; *current_output_index = *current_output_index + 8; @@ -563,13 +546,12 @@ static int set_ip_block(void* ip_block_data, unsigned char is_history, unsigned { return 1; } - ip_bw* ib = (ip_bw*)ip_block_data; *( (uint32_t*)(output_buffer + *current_output_index) ) = ib->ip; *current_output_index = *current_output_index + 4; *( (uint64_t*)(output_buffer + *current_output_index) ) = ib->bw; - + /* struct in_addr addr; addr.s_addr = ib->ip; @@ -588,7 +570,6 @@ static int set_bandwidth_data(char* id, unsigned char zero_unset, unsigned char memset(buf, 0, BANDWIDTH_QUERY_LENGTH); int done = 0; - int got_lock = lock(max_wait_milliseconds); int sockfd = -1; if(got_lock) @@ -604,7 +585,6 @@ static int set_bandwidth_data(char* id, unsigned char zero_unset, unsigned char uint64_t* last_backup_time = (uint64_t*)(buf+14); unsigned char* set_id = (unsigned char*)(buf+22); - *total_ips = num_ips; *next_ip_index = 0; *num_ips_in_buffer = 0; @@ -685,13 +665,13 @@ static unsigned char* read_entire_file(FILE* in, unsigned long read_block_size, /* * line is the line to be parsed -- it is not modified in any way * max_pieces indicates number of pieces to return, if negative this is determined dynamically - * include_remainder_at_max indicates whether the last piece, when max pieces are reached, + * include_remainder_at_max indicates whether the last piece, when max pieces are reached, * should be what it would normally be (0) or the entire remainder of the line (1) * if max_pieces < 0 this parameter is ignored * * * returns all non-separator pieces in a line - * result is dynamically allocated, MUST be freed after call-- even if + * result is dynamically allocated, MUST be freed after call-- even if * line is empty (you still get a valid char** pointer to to a NULL char*) */ static char** split_on_separators(char* line, char* separators, int num_separators, int max_pieces, int include_remainder_at_max, unsigned long *pieces_read) @@ -727,7 +707,6 @@ static char** split_on_separators(char* line, char* separators, int num_separato split_index = 0; split[split_index] = NULL; - dup_line = strdup(line); start = dup_line; non_separator_found = 0; @@ -763,7 +742,7 @@ static char** split_on_separators(char* line, char* separators, int num_separato first_separator_index++; } } - + /* copy next piece to split array */ if(first_separator_index > 0) { @@ -784,7 +763,6 @@ static char** split_on_separators(char* line, char* separators, int num_separato *pieces_read = split_index; } - /* find next non-separator index, indicating start of next piece */ start = start+ first_separator_index; non_separator_found = 0; @@ -804,7 +782,7 @@ static char** split_on_separators(char* line, char* separators, int num_separato } } free(dup_line); - + } else { @@ -814,14 +792,13 @@ static char** split_on_separators(char* line, char* separators, int num_separato return split; } - time_t* get_interval_starts_for_history(ip_bw_history history) { time_t *start_times = NULL; if(history.num_nodes > 0) { start_times = (time_t*)malloc(history.num_nodes*sizeof(time_t)); - int node_index =0; + int node_index =0; time_t next_start = history.first_start; time_t next_end = get_next_node_start_time(next_start, history.reset_interval, history.reset_time, history.is_constant_interval); for(node_index=0; node_index < history.num_nodes; node_index++) @@ -834,8 +811,6 @@ time_t* get_interval_starts_for_history(ip_bw_history history) return start_times; } - - void free_ip_bw_histories(ip_bw_history* histories, int num_histories) { if(histories == NULL) @@ -853,31 +828,28 @@ void free_ip_bw_histories(ip_bw_history* histories, int num_histories) free(histories); } - - - - - int get_all_bandwidth_history_for_rule_id(char* id, unsigned long* num_ips, ip_bw_history** data, unsigned long max_wait_milliseconds) { return get_bandwidth_data(id, 1, "ALL", num_ips, (void*)data, max_wait_milliseconds); } + int get_ip_bandwidth_history_for_rule_id(char* id, char* ip, ip_bw_history** data, unsigned long max_wait_milliseconds) { unsigned long num_ips; return get_bandwidth_data(id, 1, ip, &num_ips, (void*)data, max_wait_milliseconds); } + int get_all_bandwidth_usage_for_rule_id(char* id, unsigned long* num_ips, ip_bw** data, unsigned long max_wait_milliseconds) { return get_bandwidth_data(id, 0, "ALL", num_ips, (void*)data, max_wait_milliseconds); } + int get_ip_bandwidth_usage_for_rule_id(char* id, char* ip, ip_bw** data, unsigned long max_wait_milliseconds) { unsigned long num_ips; return get_bandwidth_data(id, 0, ip, &num_ips, (void*)data, max_wait_milliseconds); } - int set_bandwidth_history_for_rule_id(char* id, unsigned char zero_unset, unsigned long num_ips, ip_bw_history* data, unsigned long max_wait_milliseconds) { return set_bandwidth_data(id, zero_unset, 1, num_ips, 0, data, max_wait_milliseconds); @@ -888,15 +860,10 @@ int set_bandwidth_usage_for_rule_id(char* id, unsigned char zero_unset, unsigned return set_bandwidth_data(id, zero_unset, 0, num_ips, last_backup, data, max_wait_milliseconds); } - - - - - /* save single id in ascii */ int save_usage_to_file(ip_bw* data, unsigned long num_ips, char* out_file_path) { - + int success = 0; FILE* out_file = fopen(out_file_path, "w"); if(out_file != NULL) @@ -904,8 +871,8 @@ int save_usage_to_file(ip_bw* data, unsigned long num_ips, char* out_file_path) //dump backup time time_t now; time(&now); - fprintf(out_file, "%-15ld\n", now); - + fprintf(out_file, "%-15lld\n", now); + //dump ips int out_index=0; for(out_index=0; out_index < num_ips; out_index++) @@ -928,7 +895,7 @@ int save_history_to_file(ip_bw_history* data, unsigned long num_ips, char* out_f FILE* out_file = fopen(out_file_path, "wb"); if(out_file != NULL) { - //dump number of ips & history interval parameter + //dump number of ips & history interval parameter //note that we assume interval is same for all histories //(which will be the case if they all come from the same rule id) fwrite((uint32_t*)(&num_ips), 4, 1, out_file); @@ -961,7 +928,7 @@ int save_history_to_file(ip_bw_history* data, unsigned long num_ips, char* out_f for(out_index=0; out_index < num_ips; out_index++) { ip_bw_history next = data[out_index]; - + fwrite( &(next.ip), 4, 1, out_file); fwrite( &(next.num_nodes), 4, 1, out_file); if(next.num_nodes == 0) @@ -986,7 +953,6 @@ int save_history_to_file(ip_bw_history* data, unsigned long num_ips, char* out_f bw_bits = bw_bits == 32 && (bw < INT32_MAX) ? 32 : 64; } - fwrite( &first_start, 8, 1, out_file); fwrite( &first_end, 8, 1, out_file); fwrite( &last_end, 8, 1, out_file); @@ -1013,7 +979,6 @@ int save_history_to_file(ip_bw_history* data, unsigned long num_ips, char* out_f return success; } - ip_bw* load_usage_from_file(char* in_file_path, unsigned long* num_ips, time_t* last_backup) { ip_bw* data = NULL; @@ -1040,7 +1005,7 @@ ip_bw* load_usage_from_file(char* in_file_path, unsigned long* num_ips, time_t* struct in_addr ipaddr; if(data_part_index == 0) { - sscanf(data_parts[data_part_index], "%ld", last_backup); + sscanf(data_parts[data_part_index], "%lld", last_backup); //printf("last_backup = %ld\n", *last_backup); data_part_index++; } @@ -1067,19 +1032,18 @@ ip_bw* load_usage_from_file(char* in_file_path, unsigned long* num_ips, time_t* *num_ips = *num_ips + 1; } } - + /* cleanup by freeing data_parts */ for(data_part_index = 0; data_part_index < num_data_parts; data_part_index++) { free(data_parts[data_part_index]); } - + free(data_parts); } return data; } - ip_bw_history* load_history_from_file(char* in_file_path, unsigned long* num_ips) { ip_bw_history* data = NULL; @@ -1090,7 +1054,7 @@ ip_bw_history* load_history_from_file(char* in_file_path, unsigned long* num_ips uint64_t reset_interval; uint64_t reset_time; unsigned char is_constant_interval; - + uint32_t nips = 0; fread(&nips, 4, 1, in_file); *num_ips = (unsigned long)nips; @@ -1109,7 +1073,7 @@ ip_bw_history* load_history_from_file(char* in_file_path, unsigned long* num_ips uint32_t ip; uint32_t num_nodes; - uint64_t first_start; + uint64_t first_start; uint64_t first_end; uint64_t last_end; unsigned char bw_bits; @@ -1159,7 +1123,6 @@ ip_bw_history* load_history_from_file(char* in_file_path, unsigned long* num_ips return data; } - void print_usage(FILE* out, ip_bw* usage, unsigned long num_ips) { unsigned long usage_index; @@ -1186,7 +1149,7 @@ void print_histories(FILE* out, char* id, ip_bw_history* histories, unsigned lon for(history_index=0; history_index < num_histories; history_index++) { ip_bw_history history = histories[history_index]; - + int history_initialized = 1; if( history.first_start == 0 && history.first_end == 0 && history.last_end == 0) { @@ -1198,7 +1161,6 @@ void print_histories(FILE* out, char* id, ip_bw_history* histories, unsigned lon char *ip_str = NULL; time_t *times = NULL; - if(history.ip != 0) { struct in_addr ipaddr; @@ -1209,8 +1171,7 @@ void print_histories(FILE* out, char* id, ip_bw_history* histories, unsigned lon { ip_str = strdup("COMBINED"); } - - + if(output_type == 'm' || output_type == 'h') { fprintf(out, "%s %-15s\n", id, ip_str); @@ -1218,9 +1179,9 @@ void print_histories(FILE* out, char* id, ip_bw_history* histories, unsigned lon if(output_type == 'm') { - printf("%ld\n", history.first_start); - printf("%ld\n", history.first_end); - printf("%ld\n", history.last_end); + printf("%lld\n", history.first_start); + printf("%lld\n", history.first_end); + printf("%lld\n", history.last_end); } else { @@ -1240,7 +1201,7 @@ void print_histories(FILE* out, char* id, ip_bw_history* histories, unsigned lon { time_t start = times[hindex]; time_t end = hindex+1 < history.num_nodes ? times[hindex+1] : 0 ; - + char* start_str = strdup(asctime(localtime(&start))); char* end_str = end == 0 ? strdup("(Now)") : strdup(asctime(localtime(&end))); char* nl = strchr(start_str, '\n'); @@ -1253,17 +1214,16 @@ void print_histories(FILE* out, char* id, ip_bw_history* histories, unsigned lon { *nl = '\0'; } - + if(output_type == 'h') { fprintf(out, "%lld\t%s\t%s\n", (unsigned long long int)bw, start_str, end_str); } else { - fprintf(out, "%s,%s,%ld,%ld,%lld\n", id, ip_str, start, end, (unsigned long long int)bw ); + fprintf(out, "%s,%s,%lld,%lld,%lld\n", id, ip_str, start, end, (unsigned long long int)bw); } - - + free(start_str); free(end_str); } @@ -1275,9 +1235,6 @@ void print_histories(FILE* out, char* id, ip_bw_history* histories, unsigned lon } } - - - void unlock_bandwidth_semaphore(void) { unlock(); @@ -1322,13 +1279,12 @@ int get_minutes_west(time_t now) utc_day = utc_day < tz_day - 1 ? tz_day + 1 : utc_day; tz_day = tz_day < utc_day - 1 ? utc_day + 1 : tz_day; - + minuteswest = (24*60*utc_day + 60*utc_hour + utc_minute) - (24*60*tz_day + 60*tz_hour + tz_minute) ; return minuteswest; } - void set_kernel_timezone(void) { time_t now; @@ -1342,8 +1298,8 @@ void set_kernel_timezone(void) /* Get tv to pass to settimeofday(2) to be sure we avoid hour-sized warp */ /* (see gettimeofday(2) man page, or /usr/src/linux/kernel/time.c) */ - syscall(SYS_gettimeofday, &tv, &old_tz); + gettimeofday(&tv, &old_tz); /* set timezone */ - syscall(SYS_settimeofday, &tv, &new_tz); + settimeofday(&tv, &new_tz); } diff --git a/package/emortal/libiptbwctl/src/ipt_bwctl.h b/package/emortal/libiptbwctl/src/ipt_bwctl.h index 5f70d9f8a2..04fd775496 100644 --- a/package/emortal/libiptbwctl/src/ipt_bwctl.h +++ b/package/emortal/libiptbwctl/src/ipt_bwctl.h @@ -32,16 +32,16 @@ #include #include #include -#include +#include #include #include + #define BANDWIDTH_QUERY_LENGTH 16384 /* socket id parameters (for userspace i/o) */ #define BANDWIDTH_SET 2048 #define BANDWIDTH_GET 2049 - /* max id length */ #define BANDWIDTH_MAX_ID_LENGTH 50 @@ -57,7 +57,6 @@ #define BANDWIDTH_MONTH 84 #define BANDWIDTH_NEVER 85 - #pragma pack(push, 1) typedef struct ip_bw_struct { @@ -87,7 +86,7 @@ typedef struct ip_bw_kernel_data_item_struct uint64_t ipbw_data[0]; }ip_bw_kernel_data_item; -typedef struct +typedef struct { uint8_t error; uint32_t ip_total; @@ -126,36 +125,25 @@ extern int get_ip_bandwidth_history_for_rule_id(char* id, char* ip, ip_bw_histor extern int get_all_bandwidth_usage_for_rule_id(char* id, unsigned long* num_ips, ip_bw** data, unsigned long max_wait_milliseconds); extern int get_ip_bandwidth_usage_for_rule_id(char* id, char* ip, ip_bw** data, unsigned long max_wait_milliseconds); - - extern int set_bandwidth_history_for_rule_id(char* id, unsigned char zero_unset, unsigned long num_ips, ip_bw_history* data, unsigned long max_wait_milliseconds); extern int set_bandwidth_usage_for_rule_id(char* id, unsigned char zero_unset, unsigned long num_ips, time_t last_backup, ip_bw* data, unsigned long max_wait_milliseconds); - - extern int save_usage_to_file(ip_bw* data, unsigned long num_ips, char* out_file_path); extern int save_history_to_file(ip_bw_history* data, unsigned long num_ips, char* out_file_path); - - extern ip_bw* load_usage_from_file(char* in_file_path, unsigned long* num_ips, time_t* last_backup); extern ip_bw_history* load_history_from_file(char* in_file_path, unsigned long* num_ips); extern void print_usage(FILE* out, ip_bw* usage, unsigned long num_ips); extern void print_histories(FILE* out, char* id, ip_bw_history* histories, unsigned long num_histories, char output_type); - - - extern void unlock_bandwidth_semaphore(void); extern void unlock_bandwidth_semaphore_on_exit(void); - /* sets kernel timezone minuteswest to match user timezone */ extern int get_minutes_west(time_t now); extern void set_kernel_timezone(void); - /* safe malloc & strdup functions used to handle malloc errors cleanly */ extern void* ipt_bwctl_safe_malloc(size_t size); extern char* ipt_bwctl_safe_strdup(const char* str); diff --git a/package/emortal/libiptbwctl/src/utils/bw_get.c b/package/emortal/libiptbwctl/src/utils/bw_get.c index b4df411fcf..73ede1d5fe 100644 --- a/package/emortal/libiptbwctl/src/utils/bw_get.c +++ b/package/emortal/libiptbwctl/src/utils/bw_get.c @@ -18,12 +18,10 @@ * along with this program. If not, see . */ - #include #define malloc ipt_bwctl_safe_malloc #define strdup ipt_bwctl_safe_strdup - int main(int argc, char **argv) { char *id = NULL; @@ -40,7 +38,7 @@ int main(int argc, char **argv) int c; struct in_addr read_addr; while((c = getopt(argc, argv, "i:I:a:A:f:F:tThHmMuU")) != -1) - { + { switch(c) { case 'i': @@ -96,16 +94,15 @@ int main(int argc, char **argv) } } - if(id == NULL) { fprintf(stderr, "ERROR: you must specify an id to query\n\n"); exit(0); } - - set_kernel_timezone(); + + set_kernel_timezone(); unlock_bandwidth_semaphore_on_exit(); - + if(get_history == 0) { if(address == NULL) @@ -136,7 +133,6 @@ int main(int argc, char **argv) exit(0); } - if(out_file_path != NULL) { if(get_history == 0) diff --git a/package/emortal/libiptbwctl/src/utils/bw_set.c b/package/emortal/libiptbwctl/src/utils/bw_set.c index 8d5f34876f..a5869dde6e 100644 --- a/package/emortal/libiptbwctl/src/utils/bw_set.c +++ b/package/emortal/libiptbwctl/src/utils/bw_set.c @@ -34,10 +34,9 @@ int main(int argc, char **argv) int last_backup_from_cl = 0; int is_history_file = 0; - int c; while((c = getopt(argc, argv, "i:I:b:B:f:F:UuHh")) != -1) - { + { switch(c) { case 'i': @@ -55,7 +54,7 @@ int main(int argc, char **argv) break; case 'b': case 'B': - if(sscanf(optarg, "%ld", &last_backup) == 0) + if(sscanf(optarg, "%lld", &last_backup) == 0) { fprintf(stderr, "ERROR: invalid backup time specified. Should be unix epoch seconds -- number of seconds since 1970 (UTC)\n"); exit(0); @@ -82,7 +81,6 @@ int main(int argc, char **argv) default: fprintf(stderr, "USAGE:\n\t%s -i [ID] -b [LAST_BACKUP_TIME] -f [IN_FILE_NAME] [ IP BANDWIDTH PAIRS, IF -f NOT SPECIFIED ]\n", argv[0]); exit(0); - } } @@ -91,14 +89,15 @@ int main(int argc, char **argv) fprintf(stderr, "ERROR: you must specify an id for which to set data\n\n"); exit(0); } + if(in_file_path == NULL && is_history_file) { fprintf(stderr, "ERROR: you need to specify file to load history from\n\t\t(history format is too complex to load from command line)\n"); } - set_kernel_timezone(); unlock_bandwidth_semaphore_on_exit(); + int query_succeeded = 0; if(in_file_path != NULL) { @@ -128,12 +127,11 @@ int main(int argc, char **argv) unsigned long num_data_parts; data_parts = argv+optind; num_data_parts = argc - optind; - - unsigned long num_ips = num_data_parts/2; - ip_bw* buffer = (ip_bw*)malloc(num_ips*sizeof(ip_bw)); + ip_bw* buffer = (ip_bw*)malloc(num_ips*sizeof(ip_bw)); unsigned long data_index = 0; unsigned long buffer_index = 0; + while(data_index < num_data_parts) { ip_bw next; @@ -141,10 +139,10 @@ int main(int argc, char **argv) int valid = inet_aton(data_parts[data_index], &ipaddr); if((!valid) && (!last_backup_from_cl)) { - sscanf(data_parts[data_index], "%ld", &last_backup); + sscanf(data_parts[data_index], "%lld", &last_backup); } data_index++; - + if(valid && data_index < num_data_parts) { next.ip = ipaddr.s_addr; @@ -166,7 +164,7 @@ int main(int argc, char **argv) num_ips = buffer_index; /* number that were successfully read */ query_succeeded = set_bandwidth_usage_for_rule_id(id, 1, num_ips, last_backup, buffer, 1000); } - + if(!query_succeeded) { fprintf(stderr, "ERROR: Could not set data. Please try again.\n\n"); @@ -183,4 +181,3 @@ int main(int argc, char **argv) return 0; } - From b613d40f8d4ce7a0ad0241afbbcee896e924a45a Mon Sep 17 00:00:00 2001 From: AmadeusGhost <42570690+AmadeusGhost@users.noreply.github.com> Date: Thu, 4 Nov 2021 23:15:14 +0800 Subject: [PATCH 20/20] gargoyle: cleanup build warning and makefile --- .../emortal/gargoyle-firewall-util/Makefile | 41 ++-- .../src/backup_quotas.c | 25 +-- .../src/delete_chain_from_table.c | 8 +- .../src/make_iptables_rules.c | 128 ++++-------- .../gargoyle-firewall-util/src/print_quotas.c | 43 ++-- .../src/restore_quotas.c | 123 +++++------ package/emortal/libericstools/Makefile | 31 +-- package/emortal/qos-gargoyle/Makefile | 30 +-- package/emortal/qos-gargoyle/src/Makefile | 4 +- package/emortal/qos-gargoyle/src/qosmon.c | 195 ++++++++---------- 10 files changed, 236 insertions(+), 392 deletions(-) diff --git a/package/emortal/gargoyle-firewall-util/Makefile b/package/emortal/gargoyle-firewall-util/Makefile index f3071ebb48..ada653677f 100644 --- a/package/emortal/gargoyle-firewall-util/Makefile +++ b/package/emortal/gargoyle-firewall-util/Makefile @@ -1,48 +1,38 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gargoyle-firewall-util -PKG_VERSION:=$(GARGOYLE_VERSION) -ifeq ($(GARGOYLE_VERSION),) - PKG_VERSION:=1.0.0 -endif +PKG_VERSION:=1.0.0 PKG_RELEASE:=1 -PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) +PKG_MAINTAINER:=Eric Bishop include $(INCLUDE_DIR)/package.mk define Package/gargoyle-firewall-util - SECTION:=net - CATEGORY:=Network - TITLE:=A couple of shell script routines for firewall initialization - DEPENDS:=+ebtables +libericstools +uci +libiptbwctl +iptables-mod-filter +iptables-mod-ipopt +iptables-mod-conntrack-extra +iptables-mod-nat-extra +iptables-mod-extra +iptables-mod-iprange +iptables-mod-bandwidth +iptables-mod-timerange +iptables-mod-weburl +kmod-gre +kmod-pptp +kmod-tun +kmod-nf-nathelper +kmod-nf-nathelper-extra - MAINTAINER:=Eric Bishop + SECTION:=net + CATEGORY:=Network + TITLE:=A couple of shell script routines for firewall initialization + DEPENDS:=+ebtables +libericstools +libiptbwctl +iptables-mod-filter +iptables-mod-ipopt \ + +iptables-mod-conntrack-extra +iptables-mod-nat-extra +iptables-mod-extra +iptables-mod-iprange \ + +iptables-mod-bandwidth +iptables-mod-timerange +iptables-mod-weburl +kmod-gre +kmod-nf-nathelper \ + +kmod-nf-nathelper-extra +kmod-pptp +kmod-tun +uci endef define Package/gargoyle-firewall-util/description - A couple of shell script routines for firewall initialization -endef - -define Build/Prepare - echo PACKAGE BUILD DIR = $(PACKAGE_BUILD_DIR) - mkdir -p $(PKG_BUILD_DIR) - $(CP) ./src/* $(PKG_BUILD_DIR)/ + A couple of shell script routines for firewall initialization endef define Build/Configure endef - define Build/Compile $(MAKE) -C $(PKG_BUILD_DIR) \ $(TARGET_CONFIGURE_OPTS) \ STAGING_DIR="$(STAGING_DIR)" \ CFLAGS="$(TARGET_CFLAGS) -I $(STAGING_DIR)/usr/include" \ - LDFLAGS="$(TARGET_LDFLAGS) -L $(STAGING_DIR)/usr/lib" + LDFLAGS="$(TARGET_LDFLAGS) -L $(STAGING_DIR)/usr/lib" endef - - define Package/gargoyle-firewall-util/postinst included=$$(cat $${IPKG_INSTROOT}/etc/config/firewall | grep 'gargoyle_additions.firewall' ) if [ -z "$$included" ] ; then printf "config include\n\toption type script\n\toption path /usr/lib/gargoyle_firewall_util/gargoyle_additions.firewall\n\toption family IPv4\n\toption reload 1\n\n" >> $${IPKG_INSTROOT}/etc/config/firewall ; fi @@ -54,19 +44,18 @@ define Package/gargoyle-firewall-util/install $(INSTALL_DIR) $(1)/usr/bin/ $(INSTALL_DIR) $(1)/etc/init.d/ $(INSTALL_DIR) $(1)/etc/ppp/ip-up.d/ - + $(INSTALL_BIN) $(PKG_BUILD_DIR)/make_iptables_rules $(1)/usr/bin/make_iptables_rules $(INSTALL_BIN) $(PKG_BUILD_DIR)/delete_chain_from_table $(1)/usr/bin/delete_chain_from_table $(INSTALL_BIN) $(PKG_BUILD_DIR)/backup_quotas $(1)/usr/bin/backup_quotas $(INSTALL_BIN) $(PKG_BUILD_DIR)/restore_quotas $(1)/usr/bin/restore_quotas $(INSTALL_BIN) $(PKG_BUILD_DIR)/print_quotas $(1)/usr/bin/print_quotas - + $(INSTALL_BIN) ./files/gargoyle_firewall_util.sh $(1)/usr/lib/gargoyle_firewall_util/gargoyle_firewall_util.sh - $(INSTALL_BIN) ./files/gargoyle_additions.firewall $(1)/usr/lib/gargoyle_firewall_util/gargoyle_additions.firewall + $(INSTALL_BIN) ./files/gargoyle_additions.firewall $(1)/usr/lib/gargoyle_firewall_util/gargoyle_additions.firewall $(INSTALL_BIN) ./files/gargoyle_firewall.hotplug $(1)/etc/hotplug.d/iface/21-gargoyle_firewall $(INSTALL_BIN) ./files/set_kernel_timezone.init $(1)/etc/init.d/set_kernel_timezone - $(INSTALL_BIN) ./files/modemaccess.pppoe $(1)/etc/ppp/ip-up.d/modemaccess.sh + $(INSTALL_BIN) ./files/modemaccess.pppoe $(1)/etc/ppp/ip-up.d/modemaccess.sh endef - $(eval $(call BuildPackage,gargoyle-firewall-util)) diff --git a/package/emortal/gargoyle-firewall-util/src/backup_quotas.c b/package/emortal/gargoyle-firewall-util/src/backup_quotas.c index 5d4e58aca8..999eb4fb44 100644 --- a/package/emortal/gargoyle-firewall-util/src/backup_quotas.c +++ b/package/emortal/gargoyle-firewall-util/src/backup_quotas.c @@ -18,7 +18,6 @@ * along with this program. If not, see . */ - #include #include #include @@ -35,13 +34,13 @@ void backup_quota(char* quota_id, char* quota_backup_dir); char* get_uci_option(struct uci_context* ctx,char* package_name, char* section_name, char* option_name); char* get_option_value_string(struct uci_option* uopt); - int main(void) { struct uci_context *ctx = uci_alloc_context(); list* quota_sections = get_all_sections_of_type(ctx, "firewall", "quota"); system("mkdir -p /usr/data/quotas"); unlock_bandwidth_semaphore_on_exit(); + while(quota_sections->length > 0) { char* next_quota = shift_list(quota_sections); @@ -59,10 +58,10 @@ int main(void) if(do_backup) { //do backup - + /* base id for quota is the ip associated with it*/ char* backup_id = get_uci_option(ctx, "firewall", next_quota, "id"); - char* ip = get_uci_option(ctx, "firewall", next_quota, "ip"); + char* ip = get_uci_option(ctx, "firewall", next_quota, "ip"); if(ip == NULL) { ip = strdup("ALL"); @@ -82,7 +81,6 @@ int main(void) backup_id = strdup(ip); } - char* types[] = { "ingress_limit", "egress_limit", "combined_limit" }; char* postfixes[] = { "_ingress", "_egress", "_combined" }; int type_index; @@ -92,7 +90,7 @@ int main(void) if(defined != NULL) { char* type_id = dynamic_strcat(2, backup_id, postfixes[type_index]); - + backup_quota(type_id, "/usr/data/quotas" ); free(type_id); @@ -105,7 +103,7 @@ int main(void) } free(next_quota); } - + unsigned long num; destroy_list(quota_sections, DESTROY_MODE_FREE_VALUES, &num); uci_free_context(ctx); @@ -136,8 +134,8 @@ list* get_all_sections_of_type(struct uci_context *ctx, char* package, char* sec void backup_quota(char* id, char* quota_backup_dir) { - /* if we ever bother to allow quotas to apply to subnets - * specified with '/', this may be necessary + /* if we ever bother to allow quotas to apply to subnets + * specified with '/', this may be necessary */ char* quota_file_name; if(strstr(id, "/") != NULL) @@ -150,7 +148,7 @@ void backup_quota(char* id, char* quota_backup_dir) } char* quota_file_path = dynamic_strcat(3, quota_backup_dir, "/quota_", quota_file_name); - + unsigned long num_ips; ip_bw *ip_buf = NULL; int query_succeeded = get_all_bandwidth_usage_for_rule_id(id, &num_ips, &ip_buf, 5000); @@ -160,7 +158,7 @@ void backup_quota(char* id, char* quota_backup_dir) free(ip_buf); } free(quota_file_path); - free(quota_file_name); + free(quota_file_name); } char* get_uci_option(struct uci_context* ctx, char* package_name, char* section_name, char* option_name) @@ -186,9 +184,6 @@ char* get_uci_option(struct uci_context* ctx, char* package_name, char* section_ return option_value; } - - - // this function dynamically allocates memory for // the option string, but since this program exits // almost immediately (after printing variable info) @@ -224,5 +219,3 @@ char* get_option_value_string(struct uci_option* uopt) return opt_str; } - - diff --git a/package/emortal/gargoyle-firewall-util/src/delete_chain_from_table.c b/package/emortal/gargoyle-firewall-util/src/delete_chain_from_table.c index b8f5548e19..e5265ff832 100644 --- a/package/emortal/gargoyle-firewall-util/src/delete_chain_from_table.c +++ b/package/emortal/gargoyle-firewall-util/src/delete_chain_from_table.c @@ -5,6 +5,7 @@ #include #include + #define malloc safe_malloc #define strdup safe_strdup @@ -24,13 +25,11 @@ int main(int argc, char **argv) unsigned long num_lines = 0; char** table_dump = get_shell_command_output_lines(command, &num_lines); free(command); - unsigned long line_index; char* current_chain = NULL; list* delete_commands = initialize_list(); - for(line_index=0; line_index < num_lines; line_index++) { char* line = table_dump[line_index]; @@ -42,7 +41,7 @@ int main(int argc, char **argv) if(current_chain != NULL) { free(current_chain); } current_chain = strdup(line_pieces[1]); } - else + else { unsigned long line_num; int read = sscanf(line_pieces[0], "%ld", &line_num); @@ -61,7 +60,7 @@ int main(int argc, char **argv) free_null_terminated_string_array(line_pieces); } free_null_terminated_string_array(table_dump); - + /* final two commands to flush chain being deleted and whack it */ unshift_list(delete_commands, dynamic_strcat(5, "iptables -t ", table, " -F ", delete_chain, " 2>/dev/null")); unshift_list(delete_commands, dynamic_strcat(5, "iptables -t ", table, " -X ", delete_chain, " 2>/dev/null")); @@ -76,4 +75,3 @@ int main(int argc, char **argv) return 0; } - diff --git a/package/emortal/gargoyle-firewall-util/src/make_iptables_rules.c b/package/emortal/gargoyle-firewall-util/src/make_iptables_rules.c index e85f227886..67809f206d 100644 --- a/package/emortal/gargoyle-firewall-util/src/make_iptables_rules.c +++ b/package/emortal/gargoyle-firewall-util/src/make_iptables_rules.c @@ -29,6 +29,7 @@ #include #include + #define malloc safe_malloc #define strdup safe_strdup @@ -114,17 +115,17 @@ int main(int argc, char **argv) if(def != NULL) { char** rules = compute_rules(def, table, chain, 0, target, target_options); - + int rindex = 0; for(rindex=0; rules[rindex] != NULL; rindex++) - { + { if(run_commands == 0) { printf("%s\n", rules[rindex]); } else { - system(rules[rindex]); + system(rules[rindex]); } } } @@ -140,18 +141,13 @@ int main(int argc, char **argv) } - - return 0; } - - - -/* +/* * Note we've currently maxed out out one whole byte of address space * in the connmark at this point. If we want to match in - * further dimensions, we will have to be greedy and take + * further dimensions, we will have to be greedy and take * even more address space */ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingress, char* target, char* target_options) @@ -163,7 +159,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr target = strdup(target); to_uppercase(target); - /* get timerange vars first */ char* active_hours = get_map_element(rule_def, "active_hours"); char* active_weekdays = get_map_element(rule_def, "active_weekdays"); @@ -174,7 +169,7 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr dcat_and_free(&single_check, &tmp, 1, 1); } else if(active_hours != NULL && active_weekdays != NULL) - { + { char* tmp = dynamic_strcat(5, " -m timerange --hours \"", active_hours, "\" --weekdays \"", active_weekdays, "\" " ); dcat_and_free(&single_check, &tmp, 1, 1); } @@ -189,7 +184,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr dcat_and_free(&single_check, &tmp, 1, 1); } - /* * layer7 && ipp2p can not be negated. To negate them * set a mark/connmark and negate that @@ -216,8 +210,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr dcat_and_free(&single_check, &tmp, 1, 1); } - - /* make sure proto is lower case */ char* proto = get_map_element(rule_def, "proto"); if(proto == NULL) @@ -236,19 +228,15 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr } int include_proto = strcmp(proto, "both") == 0 ? 0 : 1; - /* parse multi rules */ int mask_byte_index = 0; list* initial_mask_list = initialize_list(); list* final_mask_list = initialize_list(); - - - /* url matches are a bit of a special case, handle them first */ /* we have to save this mask_byte_index specially, because it must be set separately, so it only gets set if packet is http request */ int url_mask_byte_index = mask_byte_index; - + char* url_match_vars[] = { "url_contains", "url_regex", "url_exact", "url_domain_contains", "url_domain_regex", "url_domain_exact" }; char* url_neg_match_vars[] = { "not_url_contains", "not_url_regex", "not_url_exact", "not_url_domain_contains", "not_url_domain_regex", "not_url_domain_exact" }; char* url_prefixes1[] = { " -m weburl ", " -m weburl ", " -m weburl ", " -m weburl --domain_only ", " -m weburl --domain_only ", " -m weburl --domain_only " }; @@ -257,7 +245,7 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr int url_var_index=0; int url_rule_count=0; int url_is_negated=0; - + for(url_is_negated=0; url_is_negated < 2 && url_rule_count == 0; url_is_negated++) { char** url_vars = url_is_negated ? url_neg_match_vars : url_match_vars; @@ -272,7 +260,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr } } url_is_negated--; - proto = url_rule_count > 0 ? "tcp" : proto; int url_is_multi = url_rule_count <= 1 ? 0 : 1; @@ -294,7 +281,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr push_list(final_mask_list, (void*)&url_is_multi); mask_byte_index++; - /* mark matches */ char** mark_def = get_map_element(rule_def, "mark"); int mark_is_negated = mark_def == NULL ? 1 : 0; @@ -304,7 +290,7 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr int mark_is_multi = compute_multi_rules(mark_def, multi_rules, &single_check, mark_is_negated, rule_prefix, " -m mark ", " --mark ", mark_is_negated, 0, mask_byte_index, proto, include_proto, 0) == 2; push_list(initial_mask_list, (void*)&mark_is_negated); push_list(final_mask_list, (void*)&mark_is_multi); - mask_byte_index++; + mask_byte_index++; /* connmark matches */ char** connmark_def = get_map_element(rule_def, "connmark"); @@ -314,11 +300,10 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr int connmark_is_multi = compute_multi_rules(connmark_def, multi_rules, &single_check, 0, rule_prefix, " -m connmark ", " --mark ", connmark_is_negated, 0, mask_byte_index, proto, include_proto, 0) == 2; push_list(initial_mask_list, (void*)&connmark_is_negated); push_list(final_mask_list, (void*)&connmark_is_multi); - mask_byte_index++; - + mask_byte_index++; /* - * for ingress source = remote, destination = local + * for ingress source = remote, destination = local * for egress source = local, destination = remote * * addresses are a bit tricky, since we need to handle 3 different kinds of matches: ips, ip ranges and macs @@ -371,15 +356,13 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr } } } - + push_list(initial_mask_list, (void*)(addr_negated + addr_index)); push_list(final_mask_list, (void*)(is_multi == 1 ? &is_true : &is_false) ); mask_byte_index++; } } - - char** sport_def = get_map_element(rule_def, (is_ingress ? "remote_port" : "local_port")); int sport_is_negated = sport_def == NULL ? 1 : 0; sport_def = sport_def == NULL ? get_map_element(rule_def, (is_ingress ? "not_remote_port" : "not_local_port")) : sport_def; @@ -389,7 +372,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr push_list(final_mask_list, (void*)&sport_is_multi); mask_byte_index++; - char** dport_def = get_map_element(rule_def, (is_ingress ? "local_port" : "remote_port")); int dport_is_negated = dport_def == NULL ? 1 : 0; dport_def = dport_def == NULL ? get_map_element(rule_def, (is_ingress ? "not_local_port" : "not_remote_port")) : dport_def; @@ -401,8 +383,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr list* all_rules = initialize_list(); - - //if no target_options specified, make sure it's an empty string, not null target_options = (target_options == NULL) ? "" : target_options; //if target_options is empty and we're rejecting and proto is tcp, set options to --reject-with tcp-reset instead of default @@ -416,7 +396,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr compute_multi_rules(dummy_multi, multi_rules, &single_check, 1, rule_prefix, " ", "", 0, 0, mask_byte_index, proto, requires_proto, 0); mask_byte_index++; } - /* printf("final mask length = %ld\n", final_mask_list->length); @@ -445,7 +424,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr { *next_is_multi = 1; } - unsigned long next_mark_bit = 0x01000000 * (unsigned long)pow(2, next_mask_index) * (*next_is_multi); final_match = final_match + next_mark_bit; @@ -461,7 +439,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr /* else it's last single_check mark which is never initialized to one */ } - if(initial_main_mark > 0) { //set main_mark unconditionally @@ -476,7 +453,7 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr sprintf(mark, "0x%lX", initial_url_mark); push_list(all_rules, dynamic_strcat(5, rule_prefix, " -p tcp -m weburl --contains http -j CONNMARK --set-mark ", mark, "/", mark)); } - + //put all rules in place from multi_rules list while(multi_rules->length > 0) { @@ -488,7 +465,7 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr //if final mark matches perfectly with mask of 0xFF000000, jump to (REJECT/ACCEPT) target char final_match_str[12]; sprintf(final_match_str, "0x%lX", final_match); - + //if we're rejecting, no target options are specified, and no proto is specified add two rules: one for tcp with tcp-reject, and one for everything else if(safe_strcmp(target, "REJECT") == 0 && safe_strcmp(target_options, "") == 0 && safe_strcmp(proto, "both")) { @@ -507,7 +484,7 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr else { if( strcmp(proto, "both") == 0 ) - { + { if( dport_def == NULL && sport_def == NULL ) { if(safe_strcmp(target, "REJECT") == 0 && safe_strcmp(target_options, "") == 0 ) @@ -556,7 +533,6 @@ char** compute_rules(string_map *rule_def, char* table, char* chain, int is_ingr return block_rule_list; } - /* returns 0 if no rules found, 1 if one rule found AND included in single_check, otherwise 2 */ int compute_multi_rules(char** def, list* multi_rules, char** single_check, int never_single, char* rule_prefix, char* test_prefix1, char* test_prefix2, int is_negation1, int is_negation2, int mask_byte_index, char* proto, int requires_proto, int quoted_args) { @@ -568,7 +544,7 @@ int compute_multi_rules(char** def, list* multi_rules, char** single_check, int } if(def != NULL) { - int num_rules; + int num_rules; for(num_rules=0; def[num_rules] != NULL; num_rules++){} if(num_rules == 1 && !never_single) { @@ -584,7 +560,6 @@ int compute_multi_rules(char** def, list* multi_rules, char** single_check, int sprintf(mask_str, "0x%lX", mask); char* connmark_part = dynamic_strcat(4, " -j CONNMARK --set-mark ", (is_negation ? "0x0" : mask_str), "/", mask_str); - int rule_index =0; for(rule_index=0; def[rule_index] != NULL; rule_index++) { @@ -613,12 +588,6 @@ int compute_multi_rules(char** def, list* multi_rules, char** single_check, int return parse_type; } - - - - - - string_map* get_rule_definition(char* package, char* section) { string_map* definition = NULL; @@ -637,8 +606,8 @@ string_map* get_rule_definition(char* package, char* section) { struct uci_element *e; definition = initialize_string_map(1); - - uci_foreach_element(&s->options, e) + + uci_foreach_element(&s->options, e) { char* option_name = strdup(e->name); to_lowercase(option_name); @@ -651,7 +620,7 @@ string_map* get_rule_definition(char* package, char* section) } } uci_free_context(ctx); - + return definition; } @@ -661,15 +630,15 @@ int parse_option(char* option_name, char* option_value, string_map* definition) if( safe_strcmp(option_name, "proto") == 0 || safe_strcmp(option_name, "layer7") == 0 || safe_strcmp(option_name, "ipp2p") == 0 || - safe_strcmp(option_name, "max_pkt_size") == 0 || - safe_strcmp(option_name, "min_pkt_size") ==0 + safe_strcmp(option_name, "max_pkt_size") == 0 || + safe_strcmp(option_name, "min_pkt_size") ==0 ) { valid_option = 1; set_map_element(definition, option_name, strdup(option_value)); } - else if( safe_strcmp(option_name, "active_hours") == 0 || - safe_strcmp(option_name, "active_weekly_ranges") == 0 || + else if( safe_strcmp(option_name, "active_hours") == 0 || + safe_strcmp(option_name, "active_weekly_ranges") == 0 || safe_strcmp(option_name, "active_weekdays") == 0 ) { @@ -692,7 +661,7 @@ int parse_option(char* option_name, char* option_value, string_map* definition) else if( safe_strcmp(option_name, "remote_addr") == 0 || safe_strcmp(option_name, "local_addr") == 0 || safe_strcmp(option_name, "not_remote_addr") == 0 || - safe_strcmp(option_name, "not_local_addr") == 0 + safe_strcmp(option_name, "not_local_addr") == 0 ) { char*** parsed_addr = parse_ips_and_macs(option_value); @@ -709,7 +678,7 @@ int parse_option(char* option_name, char* option_value, string_map* definition) else if( safe_strcmp(option_name, "remote_port") == 0 || safe_strcmp(option_name, "local_port") == 0 || safe_strcmp(option_name, "not_remote_port") == 0 || - safe_strcmp(option_name, "not_local_port") == 0 + safe_strcmp(option_name, "not_local_port") == 0 ) { char** parsed_ports = parse_ports(option_value); @@ -730,13 +699,13 @@ int parse_option(char* option_name, char* option_value, string_map* definition) truncate_if_starts_with(option_name, "not_url_exact") || truncate_if_starts_with(option_name, "not_url_domain_contains") || truncate_if_starts_with(option_name, "not_url_domain_regex") || - truncate_if_starts_with(option_name, "not_url_domain_exact") + truncate_if_starts_with(option_name, "not_url_domain_exact") ) { /* * may be a quoted list of urls to block, so attempt to parse this * if no quotes found, match on unquoted expresssion - * we don't need to de-escape quotes because when we define rule, + * we don't need to de-escape quotes because when we define rule, * we call iptables from system, and through the shell, which will de-escape quotes for us */ list* parsed_quoted = parse_quoted_list(option_value, '\"', '\\', 0); @@ -759,7 +728,6 @@ int parse_option(char* option_name, char* option_value, string_map* definition) return valid_option; } - // this function dynamically allocates memory for // the option string, but since this program exits // almost immediately (after printing variable info) @@ -796,9 +764,6 @@ char* get_option_value_string(struct uci_option* uopt) return opt_str; } - - - char*** parse_ips_and_macs(char* addr_str) { unsigned long num_pieces; @@ -806,7 +771,7 @@ char*** parse_ips_and_macs(char* addr_str) list* ip_list = initialize_list(); list* ip_range_list = initialize_list(); list* mac_list = initialize_list(); - + int ip_part_index; for(ip_part_index=0; addr_parts[ip_part_index] != NULL; ip_part_index++) { @@ -828,7 +793,7 @@ char*** parse_ips_and_macs(char* addr_str) int end_ip[4]; int start_valid = sscanf(start, "%d.%d.%d.%d", start_ip, start_ip+1, start_ip+2, start_ip+3); int end_valid = sscanf(end, "%d.%d.%d.%d", end_ip, end_ip+1, end_ip+2, end_ip+3); - + if(start_valid == 4 && end_valid == 4) { //get_ip_range_strs(start_ip, end_ip, "", 4, ip_list); @@ -836,7 +801,7 @@ char*** parse_ips_and_macs(char* addr_str) } free(start); - free(end); + free(end); free(range_parts); //free(next_str); } @@ -851,7 +816,7 @@ char*** parse_ips_and_macs(char* addr_str) } } free(addr_parts); - + unsigned long num1, num2, num3; char*** return_value = (char***)malloc(3*sizeof(char**)); return_value[MATCH_IP_INDEX] = (char**)destroy_list(ip_list, DESTROY_MODE_RETURN_VALUES, &num1); @@ -869,8 +834,6 @@ char*** parse_ips_and_macs(char* addr_str) return return_value; } - - char** parse_ports(char* port_str) { unsigned long num_pieces; @@ -888,7 +851,6 @@ char** parse_ports(char* port_str) return ports; } - /* * parses a list of marks/connmarks * the max_mask parameter specfies a maximal mask that will be used @@ -896,8 +858,8 @@ char** parse_ports(char* port_str) * (by defining [mark]/[mask]) this is bitwise-anded with the maximum * mask to get the final mask. This is especially necessary for * connmarks, because the mechanism to handle negation when multiple - * test rules are needed uses the last (high) byte of the connmark - * address space, so this HAS to be masked out when matching + * test rules are needed uses the last (high) byte of the connmark + * address space, so this HAS to be masked out when matching * connmarks, using max_mask=0x00FFFFFF */ char** parse_marks(char* list_str, unsigned long max_mask) @@ -912,7 +874,7 @@ char** parse_marks(char* list_str, unsigned long max_mask) free(marks); marks = NULL; } - else + else { int mark_index; for(mark_index = 0; marks[mark_index] != NULL; mark_index++) @@ -928,9 +890,9 @@ char** parse_marks(char* list_str, unsigned long max_mask) unsigned long mask = 0xFFFFFFFF; mask_start++; sscanf(mask_start, "%lX", &mask); - + mask = mask & max_mask; - + *(mask_start) = '\0'; char new_mask_str[12]; sprintf(new_mask_str, "0x%lX", mask); @@ -950,14 +912,13 @@ char** parse_marks(char* list_str, unsigned long max_mask) return marks; } - -/* - * parses list of quoted strings, ignoring escaped quote characters that are not themselves escaped +/* + * parses list of quoted strings, ignoring escaped quote characters that are not themselves escaped * Note that we don't de-escape anything here. If necessary that should be done elsewhere. - */ + */ list* parse_quoted_list(char* list_str, char quote_char, char escape_char, char add_remainder_if_uneven_quotes) { - + long num_quotes = 0; long list_index = 0; char previous_is_quoted = 0; @@ -966,11 +927,11 @@ list* parse_quoted_list(char* list_str, char quote_char, char escape_char, char num_quotes = num_quotes + ( list_str[list_index] == quote_char && !previous_is_quoted ? 1 : 0); previous_is_quoted = list_str[list_index] == escape_char && !previous_is_quoted ? 1 : 0; } - + char** pieces = (char**)malloc( ((long)(num_quotes/2)+2) * sizeof(char*) ); long piece_index = 0; long next_start_index=-1; - previous_is_quoted = 0; + previous_is_quoted = 0; for(list_index=0; list_str[list_index] != '\0'; list_index++) { if( list_str[list_index] == quote_char && !previous_is_quoted ) @@ -1018,11 +979,10 @@ list* parse_quoted_list(char* list_str, char quote_char, char escape_char, char push_list(quoted_list, strdup(list_str)); } free(pieces);//but do free array of char* pointers, we don't need it anymore - + return quoted_list; } - int truncate_if_starts_with(char* test_str, char* prefix) { int prefix_length = strlen(prefix); diff --git a/package/emortal/gargoyle-firewall-util/src/print_quotas.c b/package/emortal/gargoyle-firewall-util/src/print_quotas.c index 3aad95eed3..9ca434470e 100644 --- a/package/emortal/gargoyle-firewall-util/src/print_quotas.c +++ b/package/emortal/gargoyle-firewall-util/src/print_quotas.c @@ -18,7 +18,6 @@ * along with this program. If not, see . */ - #include #include #include @@ -27,6 +26,7 @@ #include #include #include + #define malloc safe_malloc #define strdup safe_strdup @@ -35,7 +35,6 @@ void backup_quota(char* quota_id, char* quota_backup_dir); char* get_uci_option(struct uci_context* ctx,char* package_name, char* section_name, char* option_name); char* get_option_value_string(struct uci_option* uopt); - int main(void) { struct uci_context *ctx = uci_alloc_context(); @@ -44,18 +43,17 @@ int main(void) /* for each ip have uint64_t[6], */ string_map *id_ip_to_bandwidth = initialize_string_map(1); - string_map *id_ip_to_percents = initialize_string_map(1); + string_map *id_ip_to_percents = initialize_string_map(1); string_map *id_ip_to_limits = initialize_string_map(1); list *id_to_time = initialize_list(); while(quota_sections->length > 0) { char* next_quota = shift_list(quota_sections); - /* base id for quota is the ip associated with it*/ char *id = get_uci_option(ctx, "firewall", next_quota, "id"); - char* ip = get_uci_option(ctx, "firewall", next_quota, "ip"); + char* ip = get_uci_option(ctx, "firewall", next_quota, "ip"); if(ip == NULL) { ip = strdup("ALL"); @@ -75,10 +73,6 @@ int main(void) id = strdup(ip); } - - - - string_map* ip_to_bandwidth = get_string_map_element(id_ip_to_bandwidth, id); ip_to_bandwidth = ip_to_bandwidth == NULL ? initialize_string_map(1) : ip_to_bandwidth; set_string_map_element(id_ip_to_bandwidth, id, ip_to_bandwidth); @@ -104,7 +98,7 @@ int main(void) char* weekdays_var = is_off_peak ? offpeak_weekdays : onpeak_weekdays; char* weekly_ranges_var = is_off_peak ? offpeak_weekly_ranges : onpeak_weekly_ranges; char* active_var = is_off_peak ? strdup("except") : strdup("only"); - + if(weekly_ranges_var != NULL) { if(hours_var != NULL) { free(hours_var); hours_var=NULL; } @@ -114,7 +108,7 @@ int main(void) weekdays_var = weekdays_var == NULL ? strdup("") : weekdays_var; weekly_ranges_var = weekly_ranges_var == NULL ? strdup("") : weekly_ranges_var; push_list(id_to_time, dynamic_strcat(11, "quotaTimes[\"", id, "\"] = [\"", hours_var, "\", \"", weekdays_var, "\", \"", weekly_ranges_var ,"\", \"", active_var, "\"];")); - + free(hours_var); free(weekdays_var); free(weekly_ranges_var); @@ -127,8 +121,7 @@ int main(void) char* types[] = { "combined_limit", "ingress_limit", "egress_limit" }; char* postfixes[] = { "_combined", "_ingress", "_egress" }; - - + int type_index; for(type_index=0; type_index < 3; type_index++) { @@ -156,8 +149,7 @@ int main(void) addr.s_addr = next.ip; next_ip = strdup(inet_ntoa(addr)); } - - + uint64_t *bw_list = get_string_map_element(ip_to_bandwidth,next_ip); if(bw_list == NULL) { @@ -172,7 +164,7 @@ int main(void) } bw_list[type_index] = 1; bw_list[type_index+3] = next.bw; - + char bw_str[50]; sprintf(bw_str, "%lld", next.bw); double bw_percent; @@ -190,7 +182,7 @@ int main(void) { bw_percent = 100.0; } - + double* percent_list = get_string_map_element(ip_to_percents, next_ip); if(percent_list == NULL) { @@ -216,14 +208,12 @@ int main(void) } free(type_id); free(limit); - } } free(id); free(ip); free(next_quota); } - unsigned long num_ids; char** id_list = (char**)get_string_map_keys(id_ip_to_bandwidth, &num_ids); @@ -255,7 +245,7 @@ int main(void) } printf("];\n"); } - } + } printf("var quotaTimes = new Array();\n"); printf("var quotaUsed = new Array();\n"); @@ -275,12 +265,11 @@ int main(void) string_map* ip_to_bandwidth = get_string_map_element(id_ip_to_bandwidth, next_id); string_map* ip_to_percents = get_string_map_element(id_ip_to_percents, next_id); string_map* ip_to_limits = get_string_map_element(id_ip_to_limits, next_id); - + printf("quotaUsed[ \"%s\" ] = [];\n", next_id); printf("quotaPercents[ \"%s\" ] = [];\n", next_id); printf("quotaLimits[ \"%s\" ] = [];\n", next_id); - - + if(ip_to_bandwidth != NULL) { unsigned long num_ips; @@ -334,7 +323,6 @@ int main(void) } } - unsigned long num; destroy_list(quota_sections, DESTROY_MODE_FREE_VALUES, &num); uci_free_context(ctx); @@ -344,7 +332,6 @@ int main(void) list* get_all_sections_of_type(struct uci_context *ctx, char* package, char* section_type) { - struct uci_package *p = NULL; struct uci_element *e = NULL; @@ -363,7 +350,6 @@ list* get_all_sections_of_type(struct uci_context *ctx, char* package, char* sec return sections_of_type; } - char* get_uci_option(struct uci_context* ctx, char* package_name, char* section_name, char* option_name) { char* option_value = NULL; @@ -387,9 +373,6 @@ char* get_uci_option(struct uci_context* ctx, char* package_name, char* section_ return option_value; } - - - // this function dynamically allocates memory for // the option string, but since this program exits // almost immediately (after printing variable info) @@ -425,5 +408,3 @@ char* get_option_value_string(struct uci_option* uopt) return opt_str; } - - diff --git a/package/emortal/gargoyle-firewall-util/src/restore_quotas.c b/package/emortal/gargoyle-firewall-util/src/restore_quotas.c index 84a5c3a51f..fb0caabb11 100644 --- a/package/emortal/gargoyle-firewall-util/src/restore_quotas.c +++ b/package/emortal/gargoyle-firewall-util/src/restore_quotas.c @@ -1,4 +1,4 @@ -/* restore_quotas -- Used to initialize and restore bandwidth quotas based on UCI config files +/* restore_quotas -- Used to initialize and restore bandwidth quotas based on UCI config files * and any previously saved quota data in /usr/data/quotas * Originally designed for use with Gargoyle router firmware (gargoyle-router.com) * @@ -25,7 +25,6 @@ #include #include - #include #include #include @@ -33,6 +32,7 @@ #include #include #include + #define malloc safe_malloc #define strdup safe_strdup @@ -40,8 +40,6 @@ #define EGRESS_INDEX 1 #define COMBINED_INDEX 2 - - void restore_backup_for_id(char* id, char* quota_backup_dir, unsigned char is_individual_other, list* defined_ip_groups); uint32_t ip_to_host_int(char* ip_str); uint32_t* ip_range_to_host_ints(char* ip_str); @@ -64,7 +62,7 @@ int main(int argc, char** argv) char* death_mask = NULL; char* crontab_line = NULL; int ret; - + unsigned char full_qos_active = 0; char c; @@ -131,8 +129,6 @@ int main(int argc, char** argv) return 0; } - - struct uci_context *ctx = uci_alloc_context(); struct uci_ptr ptr; @@ -153,7 +149,6 @@ int main(int argc, char** argv) char* base_id = get_uci_option(ctx, "firewall", next_quota, "id"); char* exceeded_up_speed_str = get_uci_option(ctx, "firewall", next_quota, "exceeded_up_speed"); char* exceeded_down_speed_str = get_uci_option(ctx, "firewall", next_quota, "exceeded_down_speed"); - if(base_id != NULL) { @@ -175,7 +170,7 @@ int main(int argc, char** argv) if(oldval != NULL) { free(oldval); } oldval = set_long_map_element(down_speeds, down, strdup(exceeded_down_speed_str) ); if(oldval != NULL) { free(oldval); } - + } } } @@ -183,16 +178,16 @@ int main(int argc, char** argv) free(exceeded_up_speed_str); free(exceeded_down_speed_str); } + unsigned long num_destroyed; destroy_list(quota_sections, DESTROY_MODE_FREE_VALUES, &num_destroyed); quota_sections = quota_section_buf; - - /* initialize qos mark maps */ unsigned long mark_band = 2; int upload_shift = 0; int download_shift = 8; + while(up_speeds->num_elements > 0) { unsigned long mark = mark_band << upload_shift; @@ -204,6 +199,7 @@ int main(int argc, char** argv) free(next_up_speed); mark_band++; } + mark_band = 2; while(down_speeds->num_elements > 0) { @@ -217,15 +213,12 @@ int main(int argc, char** argv) mark_band++; } - - - /* initialize chains */ run_shell_command(dynamic_strcat(3, "iptables -t ", quota_table, " -N forward_quotas 2>/dev/null"), 1); run_shell_command(dynamic_strcat(3, "iptables -t ", quota_table, " -N egress_quotas 2>/dev/null"), 1); run_shell_command(dynamic_strcat(3, "iptables -t ", quota_table, " -N ingress_quotas 2>/dev/null"), 1); run_shell_command(dynamic_strcat(3, "iptables -t ", quota_table, " -N combined_quotas 2>/dev/null"), 1); - + run_shell_command("iptables -t nat -N quota_redirects 2>/dev/null", 0); run_shell_command("iptables -t nat -A quota_redirects -j CONNMARK --set-mark 0x0/0xFF000000 2>/dev/null", 0); run_shell_command("iptables -t nat -I zone_lan_prerouting -j quota_redirects 2>/dev/null", 0); @@ -235,7 +228,6 @@ int main(int argc, char** argv) run_shell_command(dynamic_strcat(6, "iptables -t ", quota_table, " -I INPUT 2 -i ", wan_if, no_death_mark_test, " -j combined_quotas 2>/dev/null"), 1); run_shell_command(dynamic_strcat(6, "iptables -t ", quota_table, " -I OUTPUT 1 -o ", wan_if, no_death_mark_test, " -j egress_quotas 2>/dev/null"), 1); run_shell_command(dynamic_strcat(6, "iptables -t ", quota_table, " -I OUTPUT 2 -o ", wan_if, no_death_mark_test, " -j combined_quotas 2>/dev/null"), 1); - run_shell_command(dynamic_strcat(3, "iptables -t ", quota_table, " -I FORWARD -j forward_quotas 2>/dev/null"), 1); run_shell_command(dynamic_strcat(6, "iptables -t ", quota_table, " -A forward_quotas -o ", wan_if, no_death_mark_test, " -j egress_quotas 2>/dev/null"), 1); @@ -283,7 +275,7 @@ int main(int argc, char** argv) } } free(quota_enabled_var); - + if(enabled) { char* ip = get_uci_option(ctx, "firewall", next_quota, "ip"); @@ -314,8 +306,7 @@ int main(int argc, char** argv) ip = dynamic_replace(ip, "- ", "-"); free(tmp_ip); } - - + if( (strcmp(ip, "ALL_OTHERS_COMBINED") == 0 || strcmp(ip, "ALL_OTHERS_INDIVIDUAL") == 0) && (!process_other_quota) ) { push_list(other_quota_section_names, strdup(next_quota)); @@ -328,7 +319,7 @@ int main(int argc, char** argv) /* this is an explicitly defined ip or ip range, so save it for later, to deal with individual other overlap problem */ push_list(defined_ip_groups, strdup(ip)); } - + /* compute proper base id for rule, adding variable to uci if necessary */ char* quota_base_id = get_uci_option(ctx, "firewall", next_quota, "id"); if(quota_base_id == NULL) @@ -338,7 +329,7 @@ int main(int argc, char** argv) char** split_ip = split_on_separators(ip, id_breaks, 3, -1, 0, &num_pieces); char* first_ip = dynamic_replace(split_ip[0], "/", "_"); free_null_terminated_string_array(split_ip); - + quota_base_id = strdup(first_ip); unsigned long next_postfix_count = 0; while( get_string_map_element(defined_base_ids, quota_base_id) != NULL) @@ -346,7 +337,7 @@ int main(int argc, char** argv) char next_postfix[20]; if(next_postfix_count > 25) { - sprintf(next_postfix, "_%c", ('A' + next_postfix_count)); + sprintf(next_postfix, "_%ld", ('A' + next_postfix_count)); } else { @@ -359,7 +350,7 @@ int main(int argc, char** argv) /* D for dummy place holder */ set_string_map_element(defined_base_ids, quota_base_id, strdup("D")); - + /* add id we've decided on to UCI */ char* var_set = dynamic_strcat(4, "firewall.", next_quota, ".id=", quota_base_id); if (uci_lookup_ptr(ctx, &ptr, var_set, true) == UCI_OK) @@ -375,7 +366,7 @@ int main(int argc, char** argv) do_restore = strcmp(ignore_backup, "1") == 0 ? 0 : 1; if(!do_restore) { - //remove variable from uci + //remove variable from uci char* var_name = dynamic_strcat(3, "firewall.", next_quota, ".ignore_backup_at_next_restore"); if (uci_lookup_ptr(ctx, &ptr, var_name, true) == UCI_OK) { @@ -385,15 +376,13 @@ int main(int argc, char** argv) } } free(ignore_backup); - - char* reset_interval = get_uci_option(ctx, "firewall", next_quota, "reset_interval"); char* reset = strdup(""); if(reset_interval != NULL) { char* reset_time = get_uci_option(ctx, "firewall", next_quota, "reset_time"); - + char* interval_option = strdup(" --reset_interval "); reset = dcat_and_free(&reset, &interval_option, 1, 1); reset = dcat_and_free(&reset, &reset_interval, 1, 1); @@ -404,9 +393,9 @@ int main(int argc, char** argv) reset = dcat_and_free(&reset, &reset_time, 1, 1); } } - - char* time_match_str = strdup(""); - + + char* time_match_str = strdup(""); + char* offpeak_hours = get_uci_option(ctx, "firewall", next_quota, "offpeak_hours"); char* offpeak_weekdays = get_uci_option(ctx, "firewall", next_quota, "offpeak_weekdays"); char* offpeak_weekly_ranges = get_uci_option(ctx, "firewall", next_quota, "offpeak_weekly_ranges"); @@ -415,7 +404,6 @@ int main(int argc, char** argv) char* onpeak_weekdays = get_uci_option(ctx, "firewall", next_quota, "onpeak_weekdays"); char* onpeak_weekly_ranges = get_uci_option(ctx, "firewall", next_quota, "onpeak_weekly_ranges"); - if(offpeak_hours != NULL || offpeak_weekdays != NULL || offpeak_weekly_ranges != NULL || onpeak_hours != NULL || onpeak_weekdays != NULL || onpeak_weekly_ranges != NULL) { unsigned char is_off_peak = (offpeak_hours != NULL || offpeak_weekdays != NULL || offpeak_weekly_ranges != NULL) ? 1 : 0; @@ -432,15 +420,15 @@ int main(int argc, char** argv) time_match_str = dcat_and_free(&time_match_str, &timerange_match, 1,1); if(hours_var != NULL && weekly_ranges_var == NULL) { - time_match_str = dcat_and_free(&time_match_str, &hour_match, 1, 1); - time_match_str = dcat_and_free(&time_match_str, &hours_var, 1, 1); - time_match_str = dcat_and_free(&time_match_str, "e_end, 1, 0); + time_match_str = dcat_and_free(&time_match_str, &hour_match, 1, 1); + time_match_str = dcat_and_free(&time_match_str, &hours_var, 1, 1); + time_match_str = dcat_and_free(&time_match_str, "e_end, 1, 0); } if(weekdays_var != NULL && weekly_ranges_var == NULL) { - time_match_str = dcat_and_free(&time_match_str, &weekday_match, 1, 1); + time_match_str = dcat_and_free(&time_match_str, &weekday_match, 1, 1); time_match_str = dcat_and_free(&time_match_str, &weekdays_var, 1, 1); - time_match_str = dcat_and_free(&time_match_str, "e_end, 1, 0); + time_match_str = dcat_and_free(&time_match_str, "e_end, 1, 0); } if(weekly_ranges_var != NULL) { @@ -450,11 +438,11 @@ int main(int argc, char** argv) } free(quote_end); } - + char* types[] = { "ingress_limit", "egress_limit", "combined_limit" }; char* postfixes[] = { "_ingress", "_egress", "_combined" }; char* chains[] = { "ingress_quotas", "egress_quotas", "combined_quotas" }; - + int type_index; for(type_index=0; type_index < 3; type_index++) { @@ -463,28 +451,28 @@ int main(int argc, char** argv) char* subnet_definition = strdup(""); char* limit = get_uci_option(ctx, "firewall", next_quota, types[type_index]); - + char* type_id = dynamic_strcat(2, quota_base_id, postfixes[type_index] ); - + char* up_qos_mark = get_string_map_element(upload_qos_marks, exceeded_up_speed_str); char* down_qos_mark = get_string_map_element(download_qos_marks, exceeded_down_speed_str); if(full_qos_active) { up_qos_mark = get_uci_option(ctx, "firewall", next_quota, "exceeded_up_class_mark"); down_qos_mark = get_uci_option(ctx, "firewall", next_quota, "exceeded_down_class_mark"); - } + } - /* + /* * need to do ip test even if limit is null, because ALL_OTHERS quotas should not apply when any of the three types of explicit limit is defined * and we therefore need to use this test to set mark indicating an explicit quota has been checked */ - char* ip_test = strdup(""); + char* ip_test = strdup(""); if( strcmp(ip, "ALL_OTHERS_COMBINED") != 0 && strcmp(ip, "ALL_OTHERS_INDIVIDUAL") != 0 && strcmp(ip, "ALL") != 0 ) { char* src_test = strstr(ip, "-") == NULL ? dynamic_strcat(3, " --src ", ip, " ") : dynamic_strcat(3, " -m iprange --src-range ", ip, " "); char* dst_test = strstr(ip, "-") == NULL ? dynamic_strcat(3, " --dst ", ip, " ") : dynamic_strcat(3, " -m iprange --dst-range ", ip, " "); - + if(strstr(ip, ",") != NULL || strstr(ip, " ") != NULL || strstr(ip, "\t") != NULL ) { char ip_breaks[] = { ',', ' ', '\t' }; @@ -560,14 +548,12 @@ int main(int argc, char** argv) { applies_to = strdup("individual_local"); } - + char *subnet_option = strdup(" --subnet "); subnet_definition = dcat_and_free(&subnet_definition, &subnet_option, 1, 1); subnet_definition = dcat_and_free(&subnet_definition, &local_subnet, 1, 0); } } - - if(up_qos_mark != NULL && down_qos_mark != NULL) { @@ -582,11 +568,11 @@ int main(int argc, char** argv) char* other_type_id = dynamic_strcat(2, quota_base_id, postfixes[other_type_index] ); if(type_index == EGRESS_INDEX) { - run_shell_command(dynamic_strcat(10, "iptables -t ", quota_table, " -A ", chains[type_index], ip_test, time_match_str, " -m bandwidth --id \"", other_type_id, "\" --bcheck_with_src_dst_swap ", set_egress_mark), 1); + run_shell_command(dynamic_strcat(10, "iptables -t ", quota_table, " -A ", chains[type_index], ip_test, time_match_str, " -m bandwidth --id \"", other_type_id, "\" --bcheck_with_src_dst_swap ", set_egress_mark), 1); } else { - run_shell_command(dynamic_strcat(10, "iptables -t ", quota_table, " -A ", chains[type_index], ip_test, time_match_str, " -m bandwidth --id \"", other_type_id, "\" --bcheck_with_src_dst_swap ", set_ingress_mark), 1); + run_shell_command(dynamic_strcat(10, "iptables -t ", quota_table, " -A ", chains[type_index], ip_test, time_match_str, " -m bandwidth --id \"", other_type_id, "\" --bcheck_with_src_dst_swap ", set_ingress_mark), 1); } free(other_type_id); } @@ -595,13 +581,13 @@ int main(int argc, char** argv) free(set_egress_mark); free(set_ingress_mark); } - + if(limit != NULL) { if(up_qos_mark != NULL && down_qos_mark != NULL) { char* set_egress_mark = dynamic_strcat(2, " -j MARK --set-mark ", up_qos_mark); - char* set_ingress_mark = dynamic_strcat(2, " -j MARK --set-mark ", down_qos_mark); + char* set_ingress_mark = dynamic_strcat(2, " -j MARK --set-mark ", down_qos_mark); if(strcmp(types[type_index], "egress_limit") == 0) { run_shell_command(dynamic_strcat(15, "iptables -t ", quota_table, " -A ", chains[type_index], ip_test, time_match_str, " -m bandwidth --id \"", type_id, "\" --type ", applies_to, subnet_definition, " --greater_than ", limit, reset, set_egress_mark), 1); @@ -624,7 +610,6 @@ int main(int argc, char** argv) //insert quota block rule run_shell_command(dynamic_strcat(15, "iptables -t ", quota_table, " -A ", chains[type_index], ip_test, time_match_str, " -m bandwidth --id \"", type_id, "\" --type ", applies_to, subnet_definition, " --greater_than ", limit, reset, set_death_mark), 1); - //insert redirect rule if(strcmp(ip, "ALL") == 0 || strcmp(ip, "ALL_OTHERS_INDIVIDUAL") == 0) { @@ -656,7 +641,6 @@ int main(int argc, char** argv) } } - //restore from backup if(do_restore) { @@ -670,7 +654,6 @@ int main(int argc, char** argv) run_shell_command(dynamic_strcat(5, "iptables -t ", quota_table, " -A ", chains[type_index], " -j CONNMARK --set-mark 0x0/0x0F000000 2>/dev/null"), 1); } - free(ip_test); free(applies_to); free(subnet_definition); @@ -693,7 +676,6 @@ int main(int argc, char** argv) free(exceeded_down_speed_str); } free(next_quota); - } run_shell_command("iptables -t nat -A quota_redirects -j CONNMARK --set-mark 0x0/0xFF000000 2>/dev/null", 0); @@ -804,17 +786,16 @@ void restore_backup_for_id(char* id, char* quota_backup_dir, unsigned char is_in ip_bw* ptr = loaded_backup_data + ip_index; push_list(ip_bw_list, ptr); } - + unsigned long num_groups = 0; char** group_strs = (char**)get_list_values(defined_ip_groups, &num_groups); unsigned long group_index; - + for(group_index = 0; group_index < num_groups; group_index++) { filter_group_from_list(&ip_bw_list, group_strs[group_index]); } - - + //rebuild the backup data array from the filtered list if(num_ips != ip_bw_list->length) { @@ -828,7 +809,7 @@ void restore_backup_for_id(char* id, char* quota_backup_dir, unsigned char is_in free(loaded_backup_data); loaded_backup_data = adj_backup; } - + destroy_list(ip_bw_list, DESTROY_MODE_IGNORE_VALUES, &num_groups); free(group_strs); //don't want to destroy values, they're still contained in list, so just destroy container array } @@ -871,7 +852,7 @@ list* filter_group_from_list(list** orig_ip_bw_list, char* ip_group_str) unsigned long num_groups = 0; char** split_group = split_on_separators(dyn_group_str, group_breaks, 3, -1, 0, &num_groups); unsigned long group_index; - + for(group_index = 0; group_index < num_groups; group_index++) { uint32_t* range = ip_range_to_host_ints( split_group[group_index] ); @@ -894,6 +875,7 @@ list* filter_group_from_list(list** orig_ip_bw_list, char* ip_group_str) destroy_list(*orig_ip_bw_list, DESTROY_MODE_IGNORE_VALUES, &num_destroyed); *orig_ip_bw_list = new_ip_bw_list; } + free_null_terminated_string_array(split_group); free(dyn_group_str); @@ -906,8 +888,7 @@ uint32_t* ip_range_to_host_ints(char* ip_str) uint32_t* ret_val = (uint32_t*)malloc(2*sizeof(uint32_t)); uint32_t start = 0; uint32_t end = 0; - - + unsigned long num_pieces = 0; char ip_breaks[] = "/-"; char** split_ip = split_on_separators(ip_str, ip_breaks, 2, -1, 0, &num_pieces); @@ -943,7 +924,6 @@ uint32_t* ip_range_to_host_ints(char* ip_str) return ret_val; } - uint32_t ip_to_host_int(char* ip_str) { struct in_addr inp; @@ -951,19 +931,17 @@ uint32_t ip_to_host_int(char* ip_str) return (uint32_t)ntohl(inp.s_addr); } - void delete_chain_from_table(char* table, char* delete_chain) { char *command = dynamic_strcat(3, "iptables -t ", table, " -L -n --line-numbers 2>/dev/null"); unsigned long num_lines = 0; char** table_dump = get_shell_command_output_lines(command, &num_lines ); - free(command); + free(command); unsigned long line_index; char* current_chain = NULL; list* delete_commands = initialize_list(); - for(line_index=0; line_index < num_lines; line_index++) { char* line = table_dump[line_index]; @@ -975,7 +953,7 @@ void delete_chain_from_table(char* table, char* delete_chain) if(current_chain != NULL) { free(current_chain); } current_chain = strdup(line_pieces[1]); } - else + else { unsigned long line_num; int read = sscanf(line_pieces[0], "%ld", &line_num); @@ -994,7 +972,7 @@ void delete_chain_from_table(char* table, char* delete_chain) free_null_terminated_string_array(line_pieces); } free_null_terminated_string_array(table_dump); - + /* final two commands to flush chain being deleted and whack it */ unshift_list(delete_commands, dynamic_strcat(5, "iptables -t ", table, " -F ", delete_chain, " 2>/dev/null")); unshift_list(delete_commands, dynamic_strcat(5, "iptables -t ", table, " -X ", delete_chain, " 2>/dev/null")); @@ -1005,7 +983,6 @@ void delete_chain_from_table(char* table, char* delete_chain) char *next_command = (char*)pop_list(delete_commands); run_shell_command(next_command, 1); } - } void run_shell_command(char* command, int free_command_str) @@ -1039,7 +1016,6 @@ list* get_all_sections_of_type(struct uci_context *ctx, char* package, char* sec return sections_of_type; } - char* get_uci_option(struct uci_context* ctx, char* package_name, char* section_name, char* option_name) { char* option_value = NULL; @@ -1063,9 +1039,6 @@ char* get_uci_option(struct uci_context* ctx, char* package_name, char* section_ return option_value; } - - - // this function dynamically allocates memory for // the option string, but since this program exits // almost immediately (after printing variable info) @@ -1101,5 +1074,3 @@ char* get_option_value_string(struct uci_option* uopt) return opt_str; } - - diff --git a/package/emortal/libericstools/Makefile b/package/emortal/libericstools/Makefile index 191db48e62..531fbda64e 100644 --- a/package/emortal/libericstools/Makefile +++ b/package/emortal/libericstools/Makefile @@ -1,44 +1,32 @@ -# +# # Copyright (C) 2006 OpenWrt.org # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # -# $Id: Makefile 9907 2007-12-25 01:59:55Z nbd $ include $(TOPDIR)/rules.mk PKG_NAME:=libericstools -PKG_VERSION:=$(GARGOYLE_VERSION) -ifeq ($(GARGOYLE_VERSION),) - PKG_VERSION:=1.0.0 -endif +PKG_VERSION:=1.0.0 PKG_RELEASE:=1 -PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) +PKG_MAINTAINER:=Eric Bishop include $(INCLUDE_DIR)/package.mk define Package/libericstools - SECTION:=libs - CATEGORY:=Libraries - TITLE:=Erics Tools - URL:=http://www.gargoyle-router.com - MAINTAINER:=Eric Bishop + SECTION:=libs + CATEGORY:=Libraries + TITLE:=Erics Tools + URL:=http://www.gargoyle-router.com endef - define Package/libericstools/description - A bunch of routines/utilities written by Eric Bishop, - a library primarily used in Gargoyle Web Interface for OpenWrt + A bunch of routines/utilities written by Eric Bishop, a library + primarily used in Gargoyle Web Interface for OpenWrt. endef -define Build/Prepare - mkdir -p $(PKG_BUILD_DIR) - $(CP) ./src/* $(PKG_BUILD_DIR) -endef - - define Build/Configure endef @@ -48,7 +36,6 @@ define Build/InstallDev mkdir -p $(STAGING_DIR)/usr/lib $(CP) $(PKG_BUILD_DIR)/*.so* $(STAGING_DIR)/usr/lib/ - endef define Package/libericstools/install diff --git a/package/emortal/qos-gargoyle/Makefile b/package/emortal/qos-gargoyle/Makefile index 2bedade23f..11f3796f72 100644 --- a/package/emortal/qos-gargoyle/Makefile +++ b/package/emortal/qos-gargoyle/Makefile @@ -1,35 +1,26 @@ include $(TOPDIR)/rules.mk PKG_NAME:=qos-gargoyle -PKG_VERSION:=$(GARGOYLE_VERSION) -ifeq ($(GARGOYLE_VERSION),) - PKG_VERSION:=1.0.0 -endif +PKG_VERSION:=1.0.0 PKG_RELEASE:=1 -PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) +PKG_MAINTAINER:=Eric Bishop include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/kernel.mk define Package/qos-gargoyle - SECTION:=net - CATEGORY:=Network - TITLE:=A set of QoS scripts designed for use with Gargoyle Web Interface - DEPENDS:=+tc +ip +kmod-sched +iptables-mod-filter +iptables-mod-ipopt +iptables-mod-imq +gargoyle-firewall-util - MAINTAINER:=Eric Bishop + SECTION:=net + CATEGORY:=Network + TITLE:=QoS scripts for Gargoyle Web Interface + DEPENDS:=+tc +ip +kmod-sched +iptables-mod-filter +iptables-mod-ipopt \ + +iptables-mod-imq +gargoyle-firewall-util endef define Package/qos-gargoyle/description - A set of QoS scripts designed for use with Gargoyle Web Interface + A set of QoS scripts designed for use with Gargoyle Web Interface endef -define Build/Prepare - mkdir -p $(PKG_BUILD_DIR) - $(CP) ./src/* $(PKG_BUILD_DIR)/ -endef - - define Build/Configure endef @@ -41,22 +32,19 @@ define Build/Compile LDFLAGS="$(TARGET_LDFLAGS) -L $(STAGING_DIR)/usr/lib" \ BUILD_DIR="$(KERNEL_BUILD_DIR)" \ all - - endef define Package/qos-gargoyle/install $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_DIR) $(1)/etc/hotplug.d/iface $(INSTALL_DIR) $(1)/etc/config - + $(INSTALL_BIN) ./files/qos_gargoyle.init $(1)/etc/init.d/qos_gargoyle $(INSTALL_BIN) ./files/qos_gargoyle.hotplug $(1)/etc/hotplug.d/iface/23-qos_gargoyle $(INSTALL_DATA) ./files/qos_gargoyle.conf $(1)/etc/config/qos_gargoyle $(INSTALL_DIR) $(1)/usr/sbin $(INSTALL_BIN) $(PKG_BUILD_DIR)/qosmon $(1)/usr/sbin/qosmon - endef define Package/qos-gargoyle/prerm diff --git a/package/emortal/qos-gargoyle/src/Makefile b/package/emortal/qos-gargoyle/src/Makefile index 88aca6022d..6b345bf7ae 100644 --- a/package/emortal/qos-gargoyle/src/Makefile +++ b/package/emortal/qos-gargoyle/src/Makefile @@ -8,13 +8,12 @@ TCDIR:=$(STAGING_DIR)/usr/lib/iproute2 LDLIBS += -lm - TCOBJS := $(TCDIR)/tc/tc_util.o TCOBJS += $(TCDIR)/tc/tc_core.o TCOBJS += $(TCDIR)/tc/q_hfsc.o TCOBJS += $(TCDIR)/lib/libnetlink.a TCOBJS += $(TCDIR)/lib/libutil.a -LDFLAGS += -Wl,-export-dynamic +LDFLAGS += -Wl,-export-dynamic all: qosmon @@ -33,4 +32,3 @@ uninstall: clean: rm -rf *.o *~ .*sw* qosmon - diff --git a/package/emortal/qos-gargoyle/src/qosmon.c b/package/emortal/qos-gargoyle/src/qosmon.c index 1d112c83d6..2cc3ca5e09 100644 --- a/package/emortal/qos-gargoyle/src/qosmon.c +++ b/package/emortal/qos-gargoyle/src/qosmon.c @@ -1,10 +1,10 @@ /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ -/* qosmon - An active QoS monitor for gargoyle routers. +/* qosmon - An active QoS monitor for gargoyle routers. * Created By Paul Bixel * http://www.gargoyle-router.com - * + * * Copyright © 2010 by Paul Bixel - * + * * This file is free software: you may copy, redistribute and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 2 of the License, or (at your @@ -18,7 +18,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * -*/ + */ + #define _GNU_SOURCE 1 #include #include @@ -47,7 +48,6 @@ #include #endif - #define MAXPACKET 100 /* max packet size */ #define BACKGROUND 3 /* Detact and run in the background */ #define ADDENTITLEMENT 4 @@ -58,7 +58,7 @@ //The number of arguments needed for two of our kernel calls changed //in iproute2 after v2.6.29 (not sure when). We will use the new define -//RTNL_FAMILY_MAX to tell us that we are linking against a version of iproute2 +//RTNL_FAMILY_MAX to tell us that we are linking against a version of iproute2 //after then and define dump_filter and talk accordingly. #ifdef RTNL_FAMILY_MAX #define dump_filter(a,b,c) rtnl_dump_filter(a,b,c) @@ -77,7 +77,6 @@ /* use_names is required when linking to tc_util.o */ bool use_names = false; - u_char packet[MAXPACKET]; int pingflags, options; @@ -94,7 +93,7 @@ int datalen=64-8; /* How much data */ const char usage[] = "Gargoyle active congestion controller version 2.4\n\n" -"Usage: qosmon [options] pingtime pingtarget bandwidth [pinglimit]\n" +"Usage: qosmon [options] pingtime pingtarget bandwidth [pinglimit]\n" " pingtime - The ping interval the monitor will use when active in ms.\n" " pingtarget - The URL or IP address of the target host for the monitor.\n" " bandwidth - The maximum download speed the WAN link will support in kbps.\n" @@ -114,7 +113,7 @@ uint16_t nreceived = 0; /* # of packets we got back */ // For our digital filters we use Y = Y(-1) + alpha * (X - Y(-1)) // where alpha = Sample_Period / (TC + Sample_Period) -int fil_triptime; //Filter ping times in uS +int fil_triptime; //Filter ping times in uS int alpha; //Actually alpha * 1000 int period; //PING period In milliseconds int rawfltime; //Trip time in milliseconds @@ -144,7 +143,7 @@ u_char firstflg=1; //First pass flag u_char DCA; //Number of download classes active u_char RTDCA; //Number of realtime download classes active u_char pingon=0; //Set to one when pinger becomes active. -int pinglimit=0; //MinRTT mode ping time. +int pinglimit=0; //MinRTT mode ping time. int pinglimit_cl=0; //Ping limit entered on the commandline. int plimit; //Currently enforce ping limit @@ -162,6 +161,7 @@ long int dbw_fil; //Filtered total download load (bps). #define QMON_REALTIME 3 #define QMON_IDLE 4 #define QMON_EXIT 5 + char *statename[]= {"CHECK","INIT","ACTIVE","MINRTT","IDLE","DISABLED"}; unsigned char qstate=QMON_CHK; @@ -169,8 +169,8 @@ u_short cnt_mismatch=0; u_short cnt_errorflg=0; u_short last_errorflg=0; -FILE *statusfd; //Filestream for updating our status to. -char sigterm=0; //Set when we get a signal to terminal +FILE *statusfd; //Filestream for updating our status to. +char sigterm=0; //Set when we get a signal to terminal int sel_err=0; //Last error code returned by select #define DAEMON_NAME "qosmon" @@ -210,8 +210,6 @@ double ceil(double x) return i; } - - /* * F I N I S H * @@ -265,7 +263,7 @@ int in_cksum(u_short *addr, int len) /* * P I N G E R - * + * * Compose and transmit an ICMP ECHO REQUEST packet. The IP packet * will be added on by the kernel. The ID field is our UNIX process ID, * and the sequence number is an ascending integer. The first 8 bytes @@ -298,15 +296,14 @@ void pinger(void) /* cc = sendto(s, msg, len, flags, to, tolen) */ i = sendto( s, outpack, cc, 0, (const struct sockaddr *) &whereto, sizeof(whereto) ); - -} +} /* * T V S U B - * + * * Subtract 2 timeval structs: out = out - in. - * + * * Out is assumed to be >= in. */ void tvsub(register struct timeval *out, register struct timeval *in) @@ -358,14 +355,14 @@ char pr_pack( void *buf, int cc, struct sockaddr_in *from ) //If it was not the packet we are looking for return now. if (icp->icmp_seq != ntransmitted) return 0; - + tp = (struct timeval *)&icp->icmp_data[0]; tvsub( &tv, tp ); triptime = tv.tv_sec*1000+(tv.tv_usec/1000); - + //We are now ready to update the filtered round trip time. //Check for some possible errors first. - if (triptime > period) triptime = period; + if (triptime > period) triptime = period; //If this was the most recent one we sent then update the rawfltime. rawfltime=triptime; @@ -375,7 +372,6 @@ char pr_pack( void *buf, int cc, struct sockaddr_in *from ) //return 1 if we got a valid time. return 1; - } //These variables referenced but not used by the tc code we link to. @@ -383,7 +379,6 @@ int filter_ifindex; int use_iec = 0; int resolve_hosts = 0; - int print_class(struct nlmsghdr *n, void *arg) { struct tcmsg *t = NLMSG_DATA(n); @@ -417,14 +412,14 @@ int print_class(struct nlmsghdr *n, void *arg) //We only deal with hfsc classes. if (strcmp((char*)RTA_DATA(tb[TCA_KIND]),"hfsc")) return 0; - + //Reject the root node if (t->tcm_parent == TC_H_ROOT) return 0; //A previous error backs us out. if (errorflg) return 0; - //If something has changed about the class structure or we reached the + //If something has changed about the class structure or we reached the //end of the array we need to reset and back out. if (classcnt >= STATCNT) { errorflg=1; @@ -441,12 +436,12 @@ int print_class(struct nlmsghdr *n, void *arg) errorflg=1; return 0; } - + //First time through so record the ID. if (firstflg) { - classptr->ID = leafid; - } - + classptr->ID = leafid; + } + //Pickup some hfsc basic stats if (tb[TCA_STATS2]) { @@ -476,7 +471,6 @@ int print_class(struct nlmsghdr *n, void *arg) sc = RTA_DATA(tbs[TCA_HFSC_FSC]); classptr->rtclass |= (sc && sc->m1); } - } } else { @@ -484,7 +478,6 @@ int print_class(struct nlmsghdr *n, void *arg) return 0; } - //Avoid a big jolt on the first pass. if (firstflg) { classptr->bytes = work; @@ -500,10 +493,10 @@ int print_class(struct nlmsghdr *n, void *arg) if (bperiodbytes)*8000/bperiod; //bps per second x 1000 here - //Convert back to bps as part of the filter calculation + //Convert back to bps as part of the filter calculation classptr->cbw_flt=(bw-classptr->cbw_flt)*BWTC/1000+classptr->cbw_flt; - //A class is considered active if its BW exceeds 4000bps + //A class is considered active if its BW exceeds 4000bps if ((leafid != -1) && (classptr->cbw_flt > 4000)) { DCA++;actflg=1; if (classptr->rtclass) RTDCA++; @@ -514,8 +507,7 @@ int print_class(struct nlmsghdr *n, void *arg) dbw_fil = 0; } else { dbw_fil += classptr->cbw_flt; - } - + } } classptr->bwtime=newtime.tv_nsec; @@ -559,7 +551,6 @@ int class_list(char *d) return 0; } - /* * tc_class_modify * @@ -604,7 +595,7 @@ int tc_class_modify(__u32 rate) return 1; } req.t.tcm_parent = handle; - + strcpy(k,"hsfc"); addattr_l(&req.n, sizeof(req), TCA_KIND, k, strlen(k)+1); @@ -624,7 +615,6 @@ int tc_class_modify(__u32 rate) tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail; } - //Communicate our change to the kernel. ll_init_map(&rth); @@ -633,7 +623,6 @@ int tc_class_modify(__u32 rate) return 1; } - if (talk(&rth, &req.n, NULL) < 0) return 2; @@ -647,7 +636,6 @@ int tc_class_modify(__u32 rate) */ void update_status( FILE* fd ) { - struct CLASS_STATS *cptr=dnstats; u_char i; char nstr[10]; @@ -655,7 +643,7 @@ void update_status( FILE* fd ) //Link load includes the ping traffic when the pinger is on. if (pingon) dbw = dbw_fil + 64 * 8 * 1000/period; - else dbw = dbw_fil; + else dbw = dbw_fil; //Update the status file. rewind(fd); @@ -675,8 +663,7 @@ void update_status( FILE* fd ) fprintf(fd,"RTT time limit: %d (ms) [%d/%d]\n",plimit/1000,pinglimit/1000,(pinglimit+135*pinglimit_cl/100)/1000); fprintf(fd,"Classes Active: %u\n",DCA); - fprintf(fd,"Errors: (mismatch,errors,last err,selerr): %u,%u,%u,%i\n", cnt_mismatch, cnt_errorflg,last_errorflg,sel_err); - + fprintf(fd,"Errors: (mismatch,errors,last err,selerr): %u,%u,%u,%i\n", cnt_mismatch, cnt_errorflg,last_errorflg,sel_err); i=0; while ((i++ID != 0)) { @@ -705,16 +692,16 @@ void update_status( FILE* fd ) printw("ping (%s/%d) DCA=%d, RTDCA=%d, plim=%d, plim2=%d, state=%s\n",nstr,fil_triptime/1000, DCA,RTDCA,pinglimit/1000,plimit/1000,statename[qstate]); - printw("Link Limit=%6d, Fair Limit=%6d, Current Load=%6d (kbps)\n", + printw("Link Limit=%6d, Fair Limit=%6d, Current Load=%6d (kbps)\n", dbw_ul/1000,new_dbw_ul/1000,dbw/1000); printw("Saved Active Limit=%6d, Saved Realtime Limit=%6d\n",saved_active_limit/1000,saved_realtime_limit/1000); - printw("pings sent=%d, pings received=%d\n", + printw("pings sent=%d, pings received=%d\n", ntransmitted,nreceived); - printw("Defined classes for %s\n",DEVICE); - printw("Errors: (mismatches,errors,last err,selerr): %u,%u,%u,%i\n", cnt_mismatch, cnt_errorflg,last_errorflg,sel_err); + printw("Defined classes for %s\n",DEVICE); + printw("Errors: (mismatches,errors,last err,selerr): %u,%u,%u,%i\n", cnt_mismatch, cnt_errorflg,last_errorflg,sel_err); cptr=dnstats; - i=0; + i=0; while ((i++ID != 0)) { printw("ID %4X, Active %u, Realtime %u. Backlog %u, BW (filtered kbps): %ld\n", (short unsigned) cptr->ID, @@ -737,7 +724,6 @@ void resetsig(int parm) resetbw=1; } - /* * M A I N */ @@ -750,7 +736,6 @@ int main(int argc, char *argv[]) struct protoent *proto; float err; - argc--, av++; while (argc > 0 && *av[0] == '-') { while (*++av[0]) switch (*av[0]) { @@ -826,9 +811,9 @@ int main(int argc, char *argv[]) // where alpha = Sample_Period / (TC + Sample_Period) // TC needs to be not less than 3 times the sample period - alpha = (period*1000. / (period*4 + period)); + alpha = (period*1000. / (period*4 + period)); - //Class bandwidth filter time constants + //Class bandwidth filter time constants BWTC= (period*1000. / (7500. + period)); //Check that we have access to tc functions. @@ -840,7 +825,7 @@ int main(int argc, char *argv[]) //Make sure the device is present and that we can scan it. classptr=dnstats; - errorflg=0; + errorflg=0; class_list(DEVICE); if (errorflg) { fprintf(stderr, "Cannot scan ingress device %s\n",DEVICE); @@ -850,7 +835,7 @@ int main(int argc, char *argv[]) //If running in the background fork() if (DEAMON) { - /* Ignore most signals in background */ + /* Ignore most signals in background */ signal( SIGINT, SIG_IGN ); signal( SIGQUIT, SIG_IGN ); signal( SIGCHLD, SIG_IGN ); @@ -891,14 +876,13 @@ int main(int argc, char *argv[]) statusfd = fopen("/tmp/qosmon.status","w"); s = socket(AF_INET, SOCK_RAW, proto->p_proto); - //Check that things opened correctly. if (DEAMON) { if (statusfd == NULL) { syslog( LOG_CRIT, "Cannot open /tmp/qosmon.status - %i",errno ); exit(EXIT_FAILURE); } - + if (s < 0) { syslog( LOG_CRIT, "Cannot open ping socket - %i",errno ); exit(EXIT_FAILURE); @@ -913,16 +897,16 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot open /tmp/qosmon.status - %i",errno ); exit(EXIT_FAILURE); } - + if (s < 0) { fprintf( stderr, "Cannot open ping socket - %i",errno ); exit(EXIT_FAILURE); } - //Ctrl-C terminates + //Ctrl-C terminates signal( SIGINT, (sighandler_t) finish ); - //Close terminal terminates + //Close terminal terminates signal( SIGHUP, (sighandler_t) finish ); setlinebuf( stdout ); @@ -957,27 +941,27 @@ int main(int argc, char *argv[]) //Send the next ping if (pingon) pinger(); - + //Wait for the pong(s). timeout.tv_sec = 0; timeout.tv_usec = period*1000; - + //Need a loop here to clean out any old pongs that show up. //select() returns 1 if there is data to read. // 0 if the time has expired. - // -1 if a signal arrived. + // -1 if a signal arrived. while (sel_err=select(s+1, &fdmask, NULL, NULL, &timeout)) { //Signal arrived, just loop and keep waiting. if (sel_err == -1) continue; - + //If we got here then data must be waiting, try to read the whole packet if ( (cc=recvfrom(s,packet,len,0,(struct sockaddr *) &from, &fromlen)) < 0) { continue; } - - //OK there is a whole packet, get it and record the triptime. - pr_pack( packet, cc, &from ); + + //OK there is a whole packet, get it and record the triptime. + pr_pack( packet, cc, &from ); } @@ -985,7 +969,7 @@ int main(int argc, char *argv[]) classptr=dnstats; cc=classcnt; classcnt=0; - errorflg=0; + errorflg=0; class_list(DEVICE); //If there was an error or the number of classes changed then reset everything @@ -996,11 +980,10 @@ int main(int argc, char *argv[]) firstflg=1; pingon=0; - qstate=QMON_CHK; + qstate=QMON_CHK; continue; } - //Initialize or reinitialize the fair linklimit. if (resetbw) { saved_realtime_limit=saved_active_limit=new_dbw_ul= DBW_UL * .9; @@ -1018,26 +1001,26 @@ int main(int argc, char *argv[]) //Update the filtered ping response time based on what happened. //If we are not pinging then no change in the filtered value. - if (pingon) + if (pingon) fil_triptime = ((rawfltime*1000 - fil_triptime)*alpha)/1000 + fil_triptime; //Run the state machine switch (qstate) { // Wait to see if the ping targer will respond at all before doing anything - case QMON_CHK: + case QMON_CHK: pingon=1; //If we get two pings go ahead and lower the link speed. if (nreceived >= 2) { - //If the pinglimit was entered on the command line - //without the add flag then go directly to the - //IDLE state otherwise automatically determine an appropriate + //If the pinglimit was entered on the command line + //without the add flag then go directly to the + //IDLE state otherwise automatically determine an appropriate //ping limit. if ((pinglimit) && !(pingflags & ADDENTITLEMENT)) { dbw_ul=0; //Forces an update in tc_class_modify() - tc_class_modify(new_dbw_ul); + tc_class_modify(new_dbw_ul); fil_triptime = rawfltime*1000; qstate=QMON_IDLE; } else { @@ -1045,8 +1028,8 @@ int main(int argc, char *argv[]) nreceived=0; qstate=QMON_INIT; } - } - break; + } + break; // Take a measurement of the practical ping time we can expect in an unsaturated // link. We do this by making pings and using the filter response after @@ -1058,7 +1041,7 @@ int main(int argc, char *argv[]) if (nreceived < (10000/period)+1) fil_triptime = rawfltime*1000; //After 15 seconds we have measured our ping response entitlement. - //Move on to the active state. + //Move on to the active state. if (nreceived > (15000/period)+1) { qstate=QMON_IDLE; tc_class_modify(new_dbw_ul); //Restore reasonable bandwidth @@ -1069,7 +1052,7 @@ int main(int argc, char *argv[]) //Add what the user specified to the 110% of the measure ping time. pinglimit += (fil_triptime*1.1); } else { - //Without the '-a' flag we just use 200% of measure ping time. + //Without the '-a' flag we just use 200% of measure ping time. //This works OK in my system but I have no evidence that it will work in other systems. pinglimit = fil_triptime*2.0; } @@ -1078,7 +1061,7 @@ int main(int argc, char *argv[]) if (pinglimit < 10000) pinglimit=10000; if (pinglimit > 800000) pinglimit=800000; - //Reasonable max ping. + //Reasonable max ping. rawfltime_max = 2*pinglimit; } break; @@ -1100,7 +1083,7 @@ int main(int argc, char *argv[]) if (dbw_fil < 0.12 * DBW_UL) break; // In the ACTIVE & REALTIME states we observe ping times as long as the - // link remains active. While we are observing we adjust the + // link remains active. While we are observing we adjust the // link upper limit speed to maintain the specified pinglimit. // If the amount of data we are recieving dies down we enter the WAIT state case QMON_ACTIVE: @@ -1113,9 +1096,9 @@ int main(int argc, char *argv[]) //The pinglimit we will use depends on if any realtime classes are active //or not. In realtime mode we only allow 'pinglimit' round trip times which - //makes our pings low but also lowers our throughput. The automatic measurement + //makes our pings low but also lowers our throughput. The automatic measurement //above set pinglimit to the average RTT of the ping assuming it has to wait on - //average for 2/3 of an single MTU sized packet to transmit. The means on + //average for 2/3 of an single MTU sized packet to transmit. The means on //average there is nothing in the buffer but a packet is transmitting. //When not in realtime mode the stradegy is that we allow enough packets in the queue @@ -1123,32 +1106,32 @@ int main(int argc, char *argv[]) //We are talking about a queue controlled by the ISP so we don't know much about it. //We make an assumption that the queue is long enough to allow full utilization of the link. - //This should be the case and often the queue is much longer than needed (bufferbloat). - //When not in realtime mode we can allow this buffer to fill but we don't want it to overflow + //This should be the case and often the queue is much longer than needed (bufferbloat). + //When not in realtime mode we can allow this buffer to fill but we don't want it to overflow //because it will then drop packets which will cause our QoS to breakdown. So we want it to fill //just enough to promote full link utilization. - //The classical optimum queue size would be equal to the bandwidth * RTT and the - //additional time it will take our ping to pass through such a queue turns out to be the RTT. - //But Barman et all, Globecomm2004 indicates that only 20-30% of this is really needed. + //The classical optimum queue size would be equal to the bandwidth * RTT and the + //additional time it will take our ping to pass through such a queue turns out to be the RTT. + //But Barman et all, Globecomm2004 indicates that only 20-30% of this is really needed. // - //When we measured an RTT above that it was to the ISPs gateway so we do not really know what the average + //When we measured an RTT above that it was to the ISPs gateway so we do not really know what the average //RTT time to other IPs on the internet. And since not all hosts respond the same anyway I doubt there //is consistant RTT that we could use. - // - //For ACTIVE mode on a 925kbps/450kbps link I measured the following + // + //For ACTIVE mode on a 925kbps/450kbps link I measured the following //relationship between ping limit and throughput with large packets downloading. // //Ping Limit Throughput Percent - // 612ms 918kbps 100 + // 612ms 918kbps 100 // 525ms 915kbps 99.6 // 437ms 898kbps 97.8 - // 350ms 875kbps 95.3 - // 262ms 862kbps 93.8 + // 350ms 875kbps 95.3 + // 262ms 862kbps 93.8 // 81ms 870kbps 94.7 // 60ms 680kbps 69.8 // 50ms 630kbps 68.6 - // 40ms 490kbps 53.3 + // 40ms 490kbps 53.3 // //The 1500 byte packet time is 1500*10/925kbps download and 1500*10/425kbps upload for a total //RTT of around 48ms. Idle ping times on this link are around 35ms. @@ -1199,7 +1182,7 @@ int main(int argc, char *argv[]) //Do not increase the bandwidth until we reach 85% of the current limit. if (dbw_fil < dbw_ul * 0.85) break; - //Increase slowly (0.4%/sec). err is negative here. + //Increase slowly (0.4%/sec). err is negative here. new_dbw_ul = new_dbw_ul * (1.0 - 0.004*err*(float)period/(float)plimit/1000.0); if (new_dbw_ul > DBW_UL) new_dbw_ul=DBW_UL; @@ -1208,9 +1191,9 @@ int main(int argc, char *argv[]) new_dbw_ul = new_dbw_ul * (1.0 - 0.004*err*(float)period/(float)plimit/1000.0); - //Dynamic range is 1/.15 or 6.67 : 1. + //Dynamic range is 1/.15 or 6.67 : 1. if (new_dbw_ul < DBW_UL*.15) new_dbw_ul=DBW_UL*.15; - } + } //Modify parent download limit as needed. tc_class_modify(new_dbw_ul); @@ -1219,38 +1202,34 @@ int main(int argc, char *argv[]) if (rawfltime_max > plimit) rawfltime_max -= 100; break; - - } update_status(statusfd); - //If we get here the first pass is over. + //If we get here the first pass is over. firstflg=0; - - } //Next ping + } //Next ping qstate=QMON_EXIT; //We got a signal to terminate so start by restoring the root TC class to //the original upper limit. tc_class_modify(DBW_UL); - + update_status(statusfd); //Write a message in the system log if (DEAMON) { syslog( LOG_NOTICE, "terminated sigterm=%i, sel_err=%i", sigterm, sel_err ); closelog(); - } + } #ifndef ONLYBG - else { + else { endwin(); fflush(stdout); } #endif } -