-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gluon-statistics-mcast: adding initial package #2367
Open
T-X
wants to merge
4
commits into
freifunk-gluon:main
Choose a base branch
from
T-X:pr-gluon-statistics-mcast
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# SPDX-License-Identifier: MIT | ||
# Copyright (C) 2022 Linus Lüssing <linus.luessing@c0d3.blue> | ||
|
||
include $(TOPDIR)/rules.mk | ||
|
||
PKG_NAME:=bpfcountd | ||
PKG_RELEASE:=1 | ||
|
||
PKG_SOURCE_PROTO:=git | ||
PKG_SOURCE_DATE:=2021-06-26 | ||
PKG_SOURCE_URL=https://github.com/lemoer/bpfcountd.git | ||
PKG_SOURCE_VERSION:=8b1aeb18d686815f93e2bfe976e536c5699d6371 | ||
PKG_MIRROR_HASH:=e6e7adcc11c0fd33c6d3ac31423d3288812270944c2f31d9610ac8c3173a8c5f | ||
|
||
PKG_MAINTAINER:=Linus Lüssing <linus.luessing@c0d3.blue> | ||
PKG_LICENSE:=MIT | ||
PKG_LICENSE_FILES:=LICENSE | ||
|
||
include $(INCLUDE_DIR)/package.mk | ||
|
||
define Package/bpfcountd | ||
SECTION:=net | ||
CATEGORY:=Network | ||
TITLE:=Berkeley Packet Filter Counting Daemon | ||
DEPENDS:=+libpcap | ||
endef | ||
|
||
define Package/bpfcountd/description | ||
bpfcountd was created to obtain packet statistics in larger networks | ||
without stressing the cpu resources. bpfcountd will count the amount | ||
of packages and bytes over time (for each defined rule). The rules | ||
are defined using the tcpdump filter syntax (bpf). The collected | ||
data is provided on a unix socket in plaintext. | ||
endef | ||
|
||
define Package/bpfcountd/install | ||
$(INSTALL_DIR) $(1)/usr/sbin | ||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bpfcountd $(1)/usr/sbin/ | ||
$(CP) ./files/* $(1)/ | ||
endef | ||
|
||
$(eval $(call BuildPackage,bpfcountd)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
arp;arp | ||
icmp6;icmp6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
config bpfcountd 'eth0_in' | ||
option ifname 'eth0' | ||
option prefilter 'inbound' | ||
option filterfile '/etc/bpfcountd.filters' | ||
option buffersize '2097152' | ||
option disabled '1' | ||
|
||
config bpfcountd 'eth0_out' | ||
option ifname 'eth0' | ||
option prefilter 'outbound' | ||
option filterfile '/etc/bpfcountd.filters' | ||
option buffersize '2097152' | ||
option disabled '1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/bin/sh /etc/rc.common | ||
# SPDX-License-Identifier: MIT | ||
# Copyright (C) 2022 Linus Lüssing <linus.luessing@c0d3.blue> | ||
|
||
USE_PROCD=1 | ||
START=20 | ||
STOP=90 | ||
|
||
UNIXSOCKDIR=/var/run/bpfcountd | ||
|
||
bpfcountd_start() { | ||
local cfg="$1" | ||
local disabled | ||
|
||
local ifname | ||
local prefilter | ||
local filterfile | ||
local buffersize | ||
|
||
config_get_bool disabled "$cfg" disabled 0 | ||
[ "$disabled" -gt 0 ] && return 0 | ||
|
||
mkdir -p "$UNIXSOCKDIR" | ||
|
||
config_get ifname "$cfg" "ifname" | ||
config_get prefilter "$cfg" "prefilter" | ||
config_get filterfile "$cfg" "filterfile" | ||
config_get buffersize "$cfg" "buffersize" | ||
|
||
[ -z "$ifname" ] && { | ||
echo "Error: no ifname specified for $cfg" >&2 | ||
return 0 | ||
} | ||
[ -z "$filterfile" ] && { | ||
echo "Error: no filterfile specified for $cfg" >&2 | ||
return 0 | ||
} | ||
|
||
procd_open_instance "$cfg" | ||
|
||
procd_set_param command /usr/sbin/bpfcountd | ||
procd_append_param command -i "$ifname" | ||
procd_append_param command -f "$filterfile" | ||
procd_append_param command -u $UNIXSOCKDIR/"$cfg".sock | ||
[ -n "$prefilter" ] && procd_append_param command -F "$prefilter" | ||
[ -n "$buffersize" ] && procd_append_param command -b "$buffersize" | ||
|
||
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} | ||
|
||
procd_set_param stderr 1 | ||
procd_close_instance | ||
} | ||
|
||
start_service() { | ||
local cfg="$1" | ||
local instance_found=0 | ||
|
||
. /lib/functions/network.sh | ||
|
||
config_cb() { | ||
local type="$1" | ||
local name="$2" | ||
if [ "$type" = "bpfcountd" ]; then | ||
if [ -n "$cfg" -a "$cfg" = "$name" ]; then | ||
instance_found=1 | ||
fi | ||
fi | ||
} | ||
|
||
config_load bpfcountd | ||
|
||
if [ -n "$cfg" ]; then | ||
[ "$instance_found" -gt 0 ] || return | ||
bpfcountd_start "$cfg" | ||
else | ||
config_foreach bpfcountd_start bpfcountd | ||
fi | ||
} | ||
|
||
stop_service() { | ||
local cfg="$1" | ||
|
||
if [ -n "$cfg" ]; then | ||
rm $UNIXSOCKDIR/$cfg.sock | ||
else | ||
rm $UNIXSOCKDIR/*.sock | ||
fi | ||
} | ||
|
||
service_triggers() { | ||
procd_add_reload_trigger bpfcountd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
include $(TOPDIR)/rules.mk | ||
|
||
PKG_NAME:=gluon-statistics-mcast | ||
PKG_VERSION:=1 | ||
|
||
include ../gluon.mk | ||
|
||
define Package/gluon-statistics-mcast | ||
TITLE:=Gluon Statistics for Multicast Traffic | ||
DEPENDS:= +bpfcountd +libgluonutil | ||
endef | ||
|
||
define Package/gluon-statistics-mcast/description | ||
This package collects disected statistics on multicast | ||
and management traffic and provides them via respondd in | ||
"statistics-extended". Such information can be helpful | ||
for further development and comparison of mesh routing | ||
protocols and troubleshooting network issues. | ||
|
||
The statistics gathered disect into batman-adv | ||
packets as well. Statistics are collected both on client | ||
bridge ports and br-client as well as mesh interfaces. | ||
|
||
This introduces a performance penalty but tries to | ||
keep the impact on unicast traffic small. | ||
|
||
Note that respondd replies are rather large | ||
(several UDP datagrams, even when LZMA compressed). | ||
Therefore you might want to use slower intervals for | ||
querying respondd "statistics-extended". | ||
endef | ||
|
||
$(eval $(call BuildPackageGluon,gluon-statistics-mcast)) |
68 changes: 68 additions & 0 deletions
68
package/gluon-statistics-mcast/files/etc/hotplug.d/iface/40-bpfcountd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,68 @@ | ||||||||||||||||||||||||||||||||||
case "$INTERFACE" in | ||||||||||||||||||||||||||||||||||
"client"|\ | ||||||||||||||||||||||||||||||||||
"mmfd") | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
*) | ||||||||||||||||||||||||||||||||||
exit 0 | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
Comment on lines
+2
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
esac | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
BPFCOUNTD_RUN="/var/run/bpfcountd" | ||||||||||||||||||||||||||||||||||
mkdir -p "${BPFCOUNTD_RUN}/gluon-ifaces" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
get_ifup_ifaces() { | ||||||||||||||||||||||||||||||||||
local ifaces="$DEVICE" | ||||||||||||||||||||||||||||||||||
local brports | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if [ -d "/sys/class/net/$DEVICE/bridge/" ]; then | ||||||||||||||||||||||||||||||||||
brports="$(ls "/sys/class/net/$DEVICE/brif/")" | ||||||||||||||||||||||||||||||||||
[ -n "$brports" ] && ifaces="$(echo -e "${brports}\n${ifaces}")" | ||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
echo "$ifaces" | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
get_ifdown_ifaces() { | ||||||||||||||||||||||||||||||||||
cat "${BPFCOUNTD_RUN}/gluon-ifaces/$INTERFACE" | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
bpfcountd_start() { | ||||||||||||||||||||||||||||||||||
local ifaces="$(get_ifup_ifaces)" | ||||||||||||||||||||||||||||||||||
local iface | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
[ -z "$ifaces" ] && return | ||||||||||||||||||||||||||||||||||
[ -f "${BPFCOUNTD_RUN}/gluon-ifaces/$INTERFACE" ] && return | ||||||||||||||||||||||||||||||||||
echo "$ifaces" > "${BPFCOUNTD_RUN}/gluon-ifaces/$INTERFACE" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
for iface in $ifaces; do | ||||||||||||||||||||||||||||||||||
IFNAME="$iface" /lib/gluon/core/mesh/setup.d/40-bpfcountd "clients" | ||||||||||||||||||||||||||||||||||
done | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
bpfcountd_stop() { | ||||||||||||||||||||||||||||||||||
local ifaces="$(get_ifdown_ifaces)" | ||||||||||||||||||||||||||||||||||
local iface | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
[ -z "$ifaces" ] && return | ||||||||||||||||||||||||||||||||||
rm "${BPFCOUNTD_RUN}/gluon-ifaces/$INTERFACE" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
for iface in $ifaces; do | ||||||||||||||||||||||||||||||||||
IFNAME="$iface" /lib/gluon/core/mesh/teardown.d/40-bpfcountd | ||||||||||||||||||||||||||||||||||
done | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# synchronize reads+writes to /var/run/gluon-ifaces/$INTERFACE | ||||||||||||||||||||||||||||||||||
lock /var/lock/gluon_bpfcountd_ifaces.lock | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
case "$ACTION" in | ||||||||||||||||||||||||||||||||||
"ifup") | ||||||||||||||||||||||||||||||||||
bpfcountd_start | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
"ifdown") | ||||||||||||||||||||||||||||||||||
bpfcountd_stop | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
*) | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
Comment on lines
+58
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
esac | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
lock -u /var/lock/gluon_bpfcountd_ifaces.lock |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this package to OpenWrt packages (I See that LICENCE identifies is missing).