• Daniel Borkmann's avatar
    bpf: add sample usages for persistent maps/progs · 42984d7c
    Daniel Borkmann authored
    This patch adds a couple of stand-alone examples on how BPF_OBJ_PIN
    and BPF_OBJ_GET commands can be used.
    
    Example with maps:
    
      # ./fds_example -F /sys/fs/bpf/m -P -m -k 1 -v 42
      bpf: map fd:3 (Success)
      bpf: pin ret:(0,Success)
      bpf: fd:3 u->(1:42) ret:(0,Success)
      # ./fds_example -F /sys/fs/bpf/m -G -m -k 1
      bpf: get fd:3 (Success)
      bpf: fd:3 l->(1):42 ret:(0,Success)
      # ./fds_example -F /sys/fs/bpf/m -G -m -k 1 -v 24
      bpf: get fd:3 (Success)
      bpf: fd:3 u->(1:24) ret:(0,Success)
      # ./fds_example -F /sys/fs/bpf/m -G -m -k 1
      bpf: get fd:3 (Success)
      bpf: fd:3 l->(1):24 ret:(0,Success)
    
      # ./fds_example -F /sys/fs/bpf/m2 -P -m
      bpf: map fd:3 (Success)
      bpf: pin ret:(0,Success)
      # ./fds_example -F /sys/fs/bpf/m2 -G -m -k 1
      bpf: get fd:3 (Success)
      bpf: fd:3 l->(1):0 ret:(0,Success)
      # ./fds_example -F /sys/fs/bpf/m2 -G -m
      bpf: get fd:3 (Success)
    
    Example with progs:
    
      # ./fds_example -F /sys/fs/bpf/p -P -p
      bpf: prog fd:3 (Success)
      bpf: pin ret:(0,Success)
      bpf sock:4 <- fd:3 attached ret:(0,Success)
      # ./fds_example -F /sys/fs/bpf/p -G -p
      bpf: get fd:3 (Success)
      bpf: sock:4 <- fd:3 attached ret:(0,Success)
    
      # ./fds_example -F /sys/fs/bpf/p2 -P -p -o ./sockex1_kern.o
      bpf: prog fd:5 (Success)
      bpf: pin ret:(0,Success)
      bpf: sock:3 <- fd:5 attached ret:(0,Success)
      # ./fds_example -F /sys/fs/bpf/p2 -G -p
      bpf: get fd:3 (Success)
      bpf: sock:4 <- fd:3 attached ret:(0,Success)
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    42984d7c
libbpf.c 3.38 KB