]> git.bitcoin.ninja Git - flowspec-xdp/commitdiff
Total across loaded interfaces
authorMatt Corallo <git@bluematt.me>
Mon, 5 Apr 2021 16:29:15 +0000 (12:29 -0400)
committerMatt Corallo <git@bluematt.me>
Mon, 5 Apr 2021 16:39:08 +0000 (12:39 -0400)
dropcount.sh

index 4d5a74e2651284cb37fde23053c3c6a5dc26025d..2620b5dd6f836ec25d6a7ad4b0e959e462e367c9 100755 (executable)
@@ -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
+}