Skip to content

Commit

Permalink
add blocklist maps display
Browse files Browse the repository at this point in the history
just show_active_maps
  • Loading branch information
adgaultier committed Oct 9, 2024
1 parent d827a17 commit ff2336e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

9 changes: 9 additions & 0 deletions showmaps.py
Original file line number Diff line number Diff line change
@@ -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}")

0 comments on commit ff2336e

Please sign in to comment.