]> git.bitcoin.ninja Git - flowspec-xdp/commitdiff
Support multi-if map dump and fix last element print
authorMatt Corallo <git@bluematt.me>
Sun, 4 Apr 2021 17:30:31 +0000 (13:30 -0400)
committerMatt Corallo <git@bluematt.me>
Sun, 4 Apr 2021 18:38:32 +0000 (14:38 -0400)
dropcount.sh

index 3cfc4ab922c4bba79a3074104aa34a7560ffaf38..9864be80aa1be6a68eaa0ba71a8ff7eb040d4a29 100755 (executable)
@@ -1,29 +1,37 @@
-#!/bin/sh
-KEY=""
+#!/bin/bash
+function PRINTCNT() {
+if [ "$KEY" != "" ]; then
+       if [ "$KEY" = "0x00000000" ]; then
+               echo "Invalid packet length: $CNT"
+       elif [ "$KEY" = "0x00000001" ]; then
+               echo "Invalid VLAN tag: $CNT"
+       elif [ "$KEY" = "0x00000002" ]; then
+               echo "Invalid/rejected IHL IPv4 field: $CNT"
+       elif [ "$KEY" = "0x00000003" ]; then
+               echo "Rejected IPv6 fragments: $CNT"
+       else
+               echo "$KEY: $CNT"
+       fi
+fi
 CNT=0
-bpftool map dump id "$(bpftool map show | grep drop_cnt_map | awk '{ print $1 }' | tr -d ':')" | 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 "*) ;;
-               *)
-                       if [ "$KEY" != "" ]; then
-                               if [ "$KEY" = "0x00000000" ]; then
-                                       echo "Invalid packet length: $CNT"
-                               elif [ "$KEY" = "0x00000001" ]; then
-                                       echo "Invalid VLAN tag: $CNT"
-                               elif [ "$KEY" = "0x00000002" ]; then
-                                       echo "Invalid/rejected IHL IPv4 field: $CNT"
-                               elif [ "$KEY" = "0x00000003" ]; then
-                                       echo "Rejected IPv6 fragments: $CNT"
-                               else
-                                       echo "$KEY: $CNT"
-                               fi
-                       fi
-                       KEY=$(echo "$LINE" | awk '{ print "0x" $4 $3 $2 $1 }')
-                       CNT=0
-                       ;;
-       esac
+}
+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=$(echo "$LINE" | awk '{ print "0x" $4 $3 $2 $1 }')
+                                       ;;
+                       esac
+               done
+               PRINTCNT
+       }
 done