From ff2336e226e3aa31c0a2573e333df3d4bf95cddb Mon Sep 17 00:00:00 2001 From: adrien gaultier Date: Wed, 9 Oct 2024 17:21:19 +0200 Subject: [PATCH] add blocklist maps display just show_active_maps --- Justfile | 10 ++++++++++ showmaps.py | 9 +++++++++ 2 files changed, 19 insertions(+) create mode 100644 showmaps.py diff --git a/Justfile b/Justfile index f808523..c035e45 100644 --- a/Justfile +++ b/Justfile @@ -33,3 +33,13 @@ build: # Profile profile: CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --root --bin oryx + +show_active_maps: + @for MAPTYPE in BLOCKLIST_IPV4 BLOCKLIST_IPV6;do \ + map_ids=$(bpftool map show | grep "$MAPTYPE" | cut -f1 -d":" ); \ + for map_id in $map_ids;do \ + echo "$MAPTYPE($map_id)";\ + bpftool map dump id $map_id -j | jq "." | python3 showmaps.py 2>/dev/null || echo "\tempty";\ + done ;\ + done + diff --git a/showmaps.py b/showmaps.py new file mode 100644 index 0000000..c18123d --- /dev/null +++ b/showmaps.py @@ -0,0 +1,9 @@ +import sys,json; +rules=json.loads(sys.stdin.read()) +for rule in rules: + k = '.'.join([str(int(x,16)) for x in rule['key']]) + chunks =[rule['value'][idx: idx+2] for idx in range(0,len(rule['value']),2)] + ports = [int(f"{chunk[1]}{chunk[0]}".replace("0x",""),16) for chunk in chunks] + v = "[{}, ...]".format(', '.join([str(k) for k in ports if k!=0])) if not all(map(lambda x: x==0,ports)) else '*' + print(f"\t{k} : {v}") +