1. 14 Jul, 2018 6 commits
    • Andrey Ignatov's avatar
      bpf: Sync bpf.h to tools/ · 060a7fcc
      Andrey Ignatov authored
      Sync BPF_SOCK_OPS_TCP_LISTEN_CB related UAPI changes to tools/.
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      060a7fcc
    • Andrey Ignatov's avatar
      bpf: Add BPF_SOCK_OPS_TCP_LISTEN_CB · f333ee0c
      Andrey Ignatov authored
      Add new TCP-BPF callback that is called on listen(2) right after socket
      transition to TCP_LISTEN state.
      
      It fills the gap for listening sockets in TCP-BPF. For example BPF
      program can set BPF_SOCK_OPS_STATE_CB_FLAG when socket becomes listening
      and track later transition from TCP_LISTEN to TCP_CLOSE with
      BPF_SOCK_OPS_STATE_CB callback.
      
      Before there was no way to do it with TCP-BPF and other options were
      much harder to work with. E.g. socket state tracking can be done with
      tracepoints (either raw or regular) but they can't be attached to cgroup
      and their lifetime has to be managed separately.
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      f333ee0c
    • Okash Khawaja's avatar
      bpf: btf: print map dump and lookup with btf info · 2d3feca8
      Okash Khawaja authored
      This patch augments the output of bpftool's map dump and map lookup
      commands to print data along side btf info, if the correspondin btf
      info is available. The outputs for each of  map dump and map lookup
      commands are augmented in two ways:
      
      1. when neither of -j and -p are supplied, btf-ful map data is printed
      whose aim is human readability. This means no commitments for json- or
      backward- compatibility.
      
      2. when either -j or -p are supplied, a new json object named
      "formatted" is added for each key-value pair. This object contains the
      same data as the key-value pair, but with btf info. "formatted" object
      promises json- and backward- compatibility. Below is a sample output.
      
      $ bpftool map dump -p id 8
      [{
              "key": ["0x0f","0x00","0x00","0x00"
              ],
              "value": ["0x03", "0x00", "0x00", "0x00", ...
              ],
              "formatted": {
                      "key": 15,
                      "value": {
                              "int_field":  3,
                              ...
                      }
              }
      }
      ]
      
      This patch calls btf_dumper introduced in previous patch to accomplish
      the above. Indeed, btf-ful info is only displayed if btf data for the
      given map is available. Otherwise existing output is displayed as-is.
      Signed-off-by: default avatarOkash Khawaja <osk@fb.com>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      2d3feca8
    • Okash Khawaja's avatar
      bpf: btf: add btf print functionality · b12d6ec0
      Okash Khawaja authored
      This consumes functionality exported in the previous patch. It does the
      main job of printing with BTF data. This is used in the following patch
      to provide a more readable output of a map's dump. It relies on
      json_writer to do json printing. Below is sample output where map keys
      are ints and values are of type struct A:
      
      typedef int int_type;
      enum E {
              E0,
              E1,
      };
      
      struct B {
              int x;
              int y;
      };
      
      struct A {
              int m;
              unsigned long long n;
              char o;
              int p[8];
              int q[4][8];
              enum E r;
              void *s;
              struct B t;
              const int u;
              int_type v;
              unsigned int w1: 3;
              unsigned int w2: 3;
      };
      
      $ sudo bpftool map dump id 14
      [{
              "key": 0,
              "value": {
                  "m": 1,
                  "n": 2,
                  "o": "c",
                  "p": [15,16,17,18,15,16,17,18
                  ],
                  "q": [[25,26,27,28,25,26,27,28
                      ],[35,36,37,38,35,36,37,38
                      ],[45,46,47,48,45,46,47,48
                      ],[55,56,57,58,55,56,57,58
                      ]
                  ],
                  "r": 1,
                  "s": 0x7ffd80531cf8,
                  "t": {
                      "x": 5,
                      "y": 10
                  },
                  "u": 100,
                  "v": 20,
                  "w1": 0x7,
                  "w2": 0x3
              }
          }
      ]
      
      This patch uses json's {} and [] to imply struct/union and array. More
      explicit information can be added later. For example, a command line
      option can be introduced to print whether a key or value is struct
      or union, name of a struct etc. This will however come at the expense
      of duplicating info when, for example, printing an array of structs.
      enums are printed as ints without their names.
      Signed-off-by: default avatarOkash Khawaja <osk@fb.com>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      b12d6ec0
    • Okash Khawaja's avatar
      bpf: btf: export btf types and name by offset from lib · 92b57121
      Okash Khawaja authored
      This patch introduces btf__resolve_type() function and exports two
      existing functions from libbpf. btf__resolve_type follows modifier
      types like const and typedef until it hits a type which actually takes
      up memory, and then returns it. This function follows similar pattern
      to btf__resolve_size but instead of computing size, it just returns
      the type.
      
      These  functions will be used in the followig patch which parses
      information inside array of `struct btf_type *`. btf_name_by_offset is
      used for printing variable names.
      Signed-off-by: default avatarOkash Khawaja <osk@fb.com>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Acked-by: default avatarSong Liu <songliubraving@fb.com>
      Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      92b57121
    • Jakub Kicinski's avatar
      tools: include reallocarray feature test in FEATURE_TESTS_BASIC · db42a21a
      Jakub Kicinski authored
      perf propagates its feature check results to libbpf.  This means
      features for which perf probes must be a superset of libbpf's
      required features.  perf depends on FEATURE_TESTS_BASIC for its list
      of features.
      
      commit 531b014e ("tools: bpf: make use of reallocarray") added
      reallocarray use to libbpf, make perf also perform the reallocarray
      feature check.
      
      Fixes: 531b014e ("tools: bpf: make use of reallocarray")
      Reported-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      db42a21a
  2. 13 Jul, 2018 14 commits
  3. 12 Jul, 2018 19 commits
  4. 11 Jul, 2018 1 commit
    • Daniel Borkmann's avatar
      Merge branch 'bpf-bpftool-improved-prog-load' · 671dffa7
      Daniel Borkmann authored
      Jakub Kicinski says:
      
      ====================
      This series starts with two minor clean ups to test_offload.py
      selftest script.
      
      The next 11 patches extend the abilities of bpftool prog load
      beyond the simple cgroup use cases.  Three new parameters are
      added:
      
       - type - allows specifying program type, independent of how
         code sections are named;
       - map  - allows reusing existing maps, instead of creating a new
         map on every program load;
       - dev  - offload/binding to a device.
      
      A number of changes to libbpf is required to accomplish the task.
      The section - program type logic mapping is exposed.  We should
      probably aim to use the libbpf program section naming everywhere.
      For reuse of maps we need to allow users to set FD for bpf map
      object in libbpf.
      
      Examples
      
      Load program my_xdp.o and pin it as /sys/fs/bpf/my_xdp, for xdp
      program type:
      
      $ bpftool prog load my_xdp.o /sys/fs/bpf/my_xdp \
        type xdp
      
      As above but for offload:
      
      $ bpftool prog load my_xdp.o /sys/fs/bpf/my_xdp \
        type xdp \
        dev netdevsim0
      
      Load program my_maps.o, but for the first map reuse map id 17,
      and for the map called "other_map" reuse pinned map /sys/fs/bpf/map0:
      
      $ bpftool prog load my_maps.o /sys/fs/bpf/prog \
        map idx 0 id 17 \
        map name other_map pinned /sys/fs/bpf/map0
      
      v3:
       - fix return codes in patch 5;
       - rename libbpf_prog_type_by_string() -> libbpf_prog_type_by_name();
       - fold file path into xattr in patch 8;
       - add patch 10;
       - use dup3() in patch 12;
       - depend on fd value in patch 12;
       - close old fd in patch 12.
      v2:
       - add compat for reallocarray().
      ====================
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      671dffa7