From: Matt Corallo Date: Sun, 4 Apr 2021 17:30:31 +0000 (-0400) Subject: Support multi-if map dump and fix last element print X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=6f38d6623c3282c8f93dedd1b6419946da1311dc;p=flowspec-xdp Support multi-if map dump and fix last element print --- diff --git a/dropcount.sh b/dropcount.sh index 3cfc4ab..9864be8 100755 --- a/dropcount.sh +++ b/dropcount.sh @@ -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