From: Matt Corallo Date: Mon, 5 Apr 2021 16:29:15 +0000 (-0400) Subject: Total across loaded interfaces X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=d05d679fa4de0002100a7cd806897a2d97d19b5f;p=flowspec-xdp Total across loaded interfaces --- diff --git a/dropcount.sh b/dropcount.sh index 4d5a74e..2620b5d 100755 --- a/dropcount.sh +++ b/dropcount.sh @@ -16,23 +16,30 @@ if [ "$KEY" != "" ]; then fi CNT=0 } -bpftool map show | grep drop_cnt_map | awk '{ print $1 }' | tr -d ':' | while read IF; do - bpftool map dump id "$IF" | { - KEY="" - CNT=0 - while read LINE; do - case "$LINE" in - "key:") ;; - "value"*) - CNT=$(( $CNT + $(echo "$LINE" | awk '{ print "0x" $11 $10 $9 $8 $7 $6 $5 $4 }') )) - ;; - "Found "*) ;; - *) - PRINTCNT - KEY=$((16#$(echo "$LINE" | awk '{ print $4 $3 $2 $1 }'))) - ;; - esac - done +MAP_CONTENTS="$(bpftool map show | grep drop_cnt_map | awk '{ print $1 }' | tr -d ':' | while read IF; do + bpftool map dump id "$IF" +done)" +echo "$MAP_CONTENTS" | { + declare -a COUNTS + KEY="" + while read LINE; do + case "$LINE" in + "key:") ;; + "value"*) + COUNTS["$KEY"]=$(( ${COUNTS["$KEY"]} + $(echo "$LINE" | awk '{ print "0x" $11 $10 $9 $8 $7 $6 $5 $4 }') )) + ;; + "Found "*) ;; + *) + KEY=$((16#$(echo "$LINE" | awk '{ print $4 $3 $2 $1 }'))) + if [ "$COUNTS["$KEY"]" = "" ]; then + COUNTS["$KEY"]=0 + fi + ;; + esac + done + for C in "${!COUNTS[@]}"; do + KEY=$C + CNT="${COUNTS["$KEY"]}" PRINTCNT - } -done + done +}