Skip to content
Snippets Groups Projects
  1. May 25, 2020
  2. May 22, 2020
    • Alban Crequy's avatar
      tools: add filtering by mount namespace · 32ab8583
      Alban Crequy authored
      
      In previous patches, I added the option --cgroupmap to filter events
      belonging to a set of cgroup-v2. Although this approach works fine with
      systemd services and containers when cgroup-v2 is enabled, it does not
      work with containers when only cgroup-v1 is enabled because
      bpf_get_current_cgroup_id() only works with cgroup-v2. It also requires
      Linux 4.18 to get this bpf helper function.
      
      This patch adds an additional way to filter by containers, using mount
      namespaces.
      
      Note that this does not help with systemd services since they normally
      don't create a new mount namespace (unless you set some options like
      'ReadOnlyPaths=', see "man 5 systemd.exec").
      
      My goal with this patch is to filter Kubernetes pods, even on
      distributions with an older kernel (<4.18) or without cgroup-v2 enabled.
      
      - This is only implemented for tools that already support filtering by
        cgroup id (bindsnoop, capable, execsnoop, profile, tcpaccept, tcpconnect,
        tcptop and tcptracer).
      
      - I picked the mount namespace because the other namespaces could be
        disabled in Kubernetes (e.g. HostNetwork, HostPID, HostIPC).
      
      It can be tested by following the example in docs/special_filtering added
      in this commit, to avoid compiling locally the following command can be used
      
      ```
      sudo bpftool map create /sys/fs/bpf/mnt_ns_set type hash key 8 value 4 \
        entries 128 name mnt_ns_set flags 0
      docker run -ti --rm --privileged \
        -v /usr/src:/usr/src -v /lib/modules:/lib/modules \
        -v /sys/fs/bpf:/sys/fs/bpf --pid=host kinvolk/bcc:alban-containers-filters \
        /usr/share/bcc/tools/execsnoop --mntnsmap /sys/fs/bpf/mnt_ns_set
      
      ```
      
      Co-authored-by: default avatarAlban Crequy <alban@kinvolk.io>
      Co-authored-by: default avatarMauricio Vásquez <mauricio@kinvolk.io>
      32ab8583
  3. Feb 21, 2020
  4. Jan 09, 2020
  5. Apr 20, 2019
    • Gary Lin's avatar
      tools: don't mix print(end="") with printb() · 6c793317
      Gary Lin authored
      
      While mixing print(end="") with printb(), some messages may miss due to
      the underlying buffer handling in python 3.
      
      For example:
      
        # python3 opensnoop.py
        PID    COMM               FD ERR PATH
        /proc/18849/cmdline
        4109   tmux: server       67   0 /proc/18849/cmdline
        4109   tmux: server       67   0 /proc/18849/cmdline
        4109   tmux: server       67   0 /proc/18849/cmdline
      
      The PID, COMM, FD, and ERR are printed with print(end=""), and those of
      the first instance was eaten by printb() which outputs PATH.
      
      The following scripts mix print(end="") and printb() for the same line:
      
      tools/execsnoop.py
      tools/opensnoop.py
      tools/tcpaccept.py
      tools/tcpconnect.py
      
      Those scripts work fine with python 2 but some messages may miss while
      using python 3.
      
      This commit converts print(end="") to printb(nl="") to avoid the
      inconsistent outputs.
      
      Signed-off-by: default avatarGary Lin <glin@suse.com>
      6c793317
  6. Apr 10, 2019
  7. Apr 07, 2019
  8. Mar 08, 2019
    • Xiaozhou Liu's avatar
      enhance tools/tcpaccept (#2254) · 701bd73a
      Xiaozhou Liu authored
      - add option `-T': include time column on output (HH:MM:SS)
      - add option `-P PORT': only trace port(s) specified
      - add RPORT colume on output
      701bd73a
  9. Feb 26, 2019
  10. Feb 15, 2019
  11. Jan 16, 2019
  12. Jan 10, 2019
    • Yonghong Song's avatar
      fix several printb usage with python3 · ebe1951d
      Yonghong Song authored
      
      The following three tools are recently changed to use
      printb in order to flush out the result.
        opensnoop.py, tcpaccept.py, tcpconnect.py
      
      With python3, however, these tools have errors like below:
        TypeError: %b requires a bytes-like object, or an object that implements __bytes__, not 'str'
        Traceback (most recent call last):
          File "_ctypes/callbacks.c", line 234, in 'calling callback function'
          File "/usr/lib/python3.6/site-packages/bcc/table.py", line 572, in raw_cb_
            callback(cpu, data, size)
          File "../../tools/opensnoop.py", line 248, in print_event
            printb(b'%s' % event.fname.decode('utf-8', 'replace'))
      
      This patch fixed printb related issues for these three tools
      for python3. The python2 still works with the fix.
      
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      ebe1951d
  13. Jan 09, 2019
  14. Jan 04, 2019
  15. Jan 03, 2019
  16. Dec 19, 2018
  17. Oct 09, 2018
    • jeromemarchand's avatar
      Bytes/string encoding (#2004) · b96ebcd2
      jeromemarchand authored
      * tools: uses 'replace' error handler by default in decode()
      
      Tools might encouter characters from non utf-8 charset (e.g. a file
      name). When this happen, it's better to replace the unexpected
      character by a question mark than crash the tool when all we do is
      to print the string.
      
      * tools: fix a bytes/string issue in attach_perf_event()
      b96ebcd2
  18. Sep 11, 2018
  19. Aug 16, 2018
  20. Jul 01, 2018
  21. Jun 21, 2018
    • Joe Yin's avatar
      #1838 (#1842) · 365eade7
      Joe Yin authored
      implement tracepoint based probing for tcpaccept.py.
      365eade7
  22. Jun 18, 2018
  23. Jun 14, 2018
    • Paul Chaignon's avatar
      Recognize context member dereferences despite array accesses (#1828) · a9f96c02
      Paul Chaignon authored
      * Skip instead of bailing out if MemberExpr is not rewritable
      
      * Recognize context member dereferences despite array accesses
      
      For example, the rewriter should recognize, in the following, that
      prev is an external pointer retrieved from the context pointer,
      despite the access to the second element of the args array.
      
      struct task_struct *prev = (struct task_struct *)ctx->args[1];
      
      The same could be done for the translation of member dereferences to
      bpf_probe_read calls, but that would be a little bit more complex (to
      retrieve the correct base) and there's currently no tool that would
      benefit from it.
      
      * Test for the recognition of ext ptrs from context array
      
      * tools: remove unnecessary bpf_probe_read calls
      
      5d656bc7 made this calls unnecessary.
      a9f96c02
  24. Mar 02, 2018
  25. Feb 02, 2018
  26. Mar 26, 2017
    • Rafael F's avatar
      Python 3 compatibility fixes around string handling (#986) · 78948e4a
      Rafael F authored
      This fixes the bcc module and all the affected tools for issues related to string handling in Python 3. Specifically, when passing Python strings to C libraries they are encoded as ASCII, and when constructing Python strings from C strings, they are decoded first.
      78948e4a
  27. Jun 26, 2016
    • Mark Drayton's avatar
      IPv6 support for tcp* tools (#582) · 11de2985
      Mark Drayton authored
      * tcpretrans: support full IPv6 addresses, fix --lossprobe
      
      * tcpaccept: support full IPv6 addresses, fix timestamps
      
      * tcpconnect: support full IPv6 addresses, fix timestamps
      
      * tcpconnlat: support full IPv6 addresses, fix timestamps
      11de2985
  28. May 05, 2016
  29. Feb 15, 2016
  30. Jan 27, 2016
    • Brenden Blanco's avatar
      Updates to use cmake GLOB and libbcc.so.0 in python init · 5bd0eb21
      Brenden Blanco authored
      
      In order not to miss some files in the tools and examples source
      directories, use cmake file(GLOB) to collect relevant files. To ease the
      implementation, move all tools to be .py suffixed in the source, but
      sans-suffix in the installation (same as before)
      
      In addition, to prevent future API breakage confusion (though of course
      that may still happen), use CDLL("libbcc.so.0") in the bcc __init__.py.
      
      Fixes: #317
      Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
      5bd0eb21
  31. Jan 14, 2016
  32. Oct 13, 2015
Loading