Skip to content

Commit

Permalink
feature: add XDP_FLAGS* in python lib (iovisor#3447)
Browse files Browse the repository at this point in the history
  add XDP_FLAG macros in python lib so macro names instead of numeric numbers can be used by tools.
  • Loading branch information
chenyuezhou authored May 24, 2021
1 parent f0a0dc7 commit 528be5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions examples/networking/xdp/xdp_drop_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def usage():
if len(sys.argv) == 3:
if "-S" in sys.argv:
# XDP_FLAGS_SKB_MODE
flags |= (1 << 1)
flags |= BPF.XDP_FLAGS_SKB_MODE
if "-H" in sys.argv:
# XDP_FLAGS_HW_MODE
maptype = "array"
offload_device = device
flags |= (1 << 3)
flags |= BPF.XDP_FLAGS_HW_MODE

mode = BPF.XDP
#mode = BPF.SCHED_CLS
Expand Down
2 changes: 1 addition & 1 deletion examples/networking/xdp/xdp_macswap_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def usage():
if len(sys.argv) == 3:
if "-S" in sys.argv:
# XDP_FLAGS_SKB_MODE
flags |= 2 << 0
flags |= BPF.XDP_FLAGS_SKB_MODE

if "-S" == sys.argv[1]:
device = sys.argv[2]
Expand Down
7 changes: 7 additions & 0 deletions src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ class BPF(object):
XDP_TX = 3
XDP_REDIRECT = 4

# from xdp_flags uapi/linux/if_link.h
XDP_FLAGS_UPDATE_IF_NOEXIST = (1 << 0)
XDP_FLAGS_SKB_MODE = (1 << 1)
XDP_FLAGS_DRV_MODE = (1 << 2)
XDP_FLAGS_HW_MODE = (1 << 3)
XDP_FLAGS_REPLACE = (1 << 4)

# from bpf_attach_type uapi/linux/bpf.h
TRACE_FENTRY = 24
TRACE_FEXIT = 25
Expand Down

0 comments on commit 528be5e

Please sign in to comment.