Skip to content

Commit

Permalink
gluon-statistics-mcast: adding initial package
Browse files Browse the repository at this point in the history
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".

Signed-off-by: Linus Lüssing <[email protected]>
  • Loading branch information
T-X committed Jan 9, 2022
1 parent c16eb43 commit 8e22b67
Show file tree
Hide file tree
Showing 7 changed files with 1,203 additions and 0 deletions.
33 changes: 33 additions & 0 deletions package/gluon-statistics-mcast/Makefile
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))
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[ "$INTERFACE" = "client" ] || exit 0

bpfcountd_start() {
local iface

for iface in /sys/class/net/$DEVICE/brif/*; do
IFNAME="${iface##*/}" /lib/gluon/core/mesh/setup.d/40-bpfcountd "clients"
done
IFNAME="$DEVICE" /lib/gluon/core/mesh/setup.d/40-bpfcountd "clients"
}

bpfcountd_stop() {
local iface

for iface in $(uci get network.client.ifname); do
IFNAME="$iface" /lib/gluon/core/mesh/teardown.d/40-bpfcountd
done
IFNAME="br-client" /lib/gluon/core/mesh/teardown.d/40-bpfcountd
}

case "$ACTION" in
"ifup")
bpfcountd_start
;;
"ifdown")
bpfcountd_stop
;;
*)
;;
esac
560 changes: 560 additions & 0 deletions package/gluon-statistics-mcast/files/lib/gluon/bpfcountd/mesh.filters

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh

[ -z "$IFNAME" ] && exit 0

if [ -z "$1" ]; then
SOCKETSSUB="mesh"
else
SOCKETSSUB="$1"
fi

. /lib/functions.sh

lock /var/lock/gluon_bpfcountd.lock

BPFCOUNTD_RUN="/var/run/bpfcountd"
mkdir -p "${BPFCOUNTD_RUN}/gluon-sockets/$SOCKETSSUB"

export UCI_CONFIG_DIR="${BPFCOUNTD_RUN}/gluon-config"
mkdir -p "${UCI_CONFIG_DIR}"
touch "${UCI_CONFIG_DIR}/bpfcountd"


# Skip anything which might be unicast payload to avoid
# a noticeable performance impact:
# -> a batadv unicast packet with an IP unicast destination in
# the inner ethernet header; all batadv unicast fragments
# Note: batadv unicast fragments might contain a multicast
# packet, too (though unlikely, usually they are smaller
# than MTU).

# All IP packets with a unicast destination, except
# ICMP or PIM (103)
PREFILTER_IP4_UC="(ip and not ip multicast and not igmp and not ip proto 103)"
PREFILTER_IP6_UC="(ip6 and not ip6 multicast and not ip6 proto 0 and not ip6 proto 103)"
PREFILTER_IP_UC="(${PREFILTER_IP4_UC} or ${PREFILTER_IP6_UC})"

PREFILTER_CLIENT="not ${PREFILTER_IP_UC}"
PREFILTER_MESH="not (batadv 15 unicast and ${PREFILTER_IP_UC}) and not batadv 15 unicast_frag"
PREFILTER="${PREFILTER_CLIENT} and ${PREFILTER_MESH}"

SECTION_IN="$(uci -c ${UCI_CONFIG_DIR} add bpfcountd bpfcountd)"
SECTION_OUT="$(uci -c ${UCI_CONFIG_DIR} add bpfcountd bpfcountd)"
uci -c "${UCI_CONFIG_DIR}" batch <<-EOF
set bpfcountd.${SECTION_IN}.ifname=${IFNAME}
set bpfcountd.${SECTION_IN}.prefilter="inbound and (${PREFILTER})"
set bpfcountd.${SECTION_IN}.filterfile='/lib/gluon/bpfcountd/mesh.filters'
set bpfcountd.${SECTION_IN}.disabled='0'
set bpfcountd.${SECTION_OUT}.ifname=${IFNAME}
set bpfcountd.${SECTION_OUT}.prefilter="outbound and (${PREFILTER})"
set bpfcountd.${SECTION_OUT}.filterfile='/lib/gluon/bpfcountd/mesh.filters'
set bpfcountd.${SECTION_OUT}.disabled='0'
commit bpfcountd
EOF

ln -s "../../bpfcountd.${IFNAME}.in.sock" "${BPFCOUNTD_RUN}/gluon-sockets/$SOCKETSSUB/bpfcountd.${IFNAME}.in.sock"
ln -s "../../bpfcountd.${IFNAME}.out.sock" "${BPFCOUNTD_RUN}/gluon-sockets/$SOCKETSSUB/bpfcountd.${IFNAME}.out.sock"

/etc/init.d/bpfcountd start "${IFNAME}.in" "${SECTION_IN}"
/etc/init.d/bpfcountd start "${IFNAME}.out" "${SECTION_OUT}"

lock -u /var/lock/gluon_bpfcountd.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

[ -z "$IFNAME" ] && exit 0

. /lib/functions.sh

BPFCOUNTD_RUN="/var/run/bpfcountd"

lock /var/lock/gluon_bpfcountd.lock
export UCI_CONFIG_DIR="${BPFCOUNTD_RUN}/gluon-config"


bpfcountd_uci_delete() {
local cfg="$1"
local uci_ifname

config_get uci_ifname "$cfg" ifname
[ "${uci_ifname}" = "$IFNAME" ] || return

uci -c "${UCI_CONFIG_DIR}" delete "bpfcountd.$cfg"
}

/etc/init.d/bpfcountd stop "$IFNAME.in"
/etc/init.d/bpfcountd stop "$IFNAME.out"

rm "${BPFCOUNTD_RUN}/gluon-sockets/"*"/bpfcountd.${IFNAME}.in.sock"
rm "${BPFCOUNTD_RUN}/gluon-sockets/"*"/bpfcountd.${IFNAME}.out.sock"

config_load bpfcountd
config_foreach bpfcountd_uci_delete bpfcountd
uci -c "${UCI_CONFIG_DIR}" commit bpfcountd

lock -u /var/lock/gluon_bpfcountd.lock
6 changes: 6 additions & 0 deletions package/gluon-statistics-mcast/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all: respondd.so

CFLAGS += -Wall

respondd.so: respondd.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -D_GNU_SOURCE -o $@ $^ $(LDLIBS) -lgluonutil -luci
Loading

0 comments on commit 8e22b67

Please sign in to comment.