Commit Graph

6 Commits

Author SHA1 Message Date
Andrey Ignatov
98d2aba95c examples/tcp_sock: Fix missed import
In the previous commit used import was removed by mistake. Restore them.

Fixes: 7dd1853 ("examples: Switch tcp_sock to cgroup helpers")
2020-01-29 01:05:37 -08:00
Andrey Ignatov
7dd18535e1 examples: Switch tcp_sock to cgroup helpers
Use cgroup helpers instead of working with socket cgroup manually.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-14 16:03:20 -08:00
Omar Sandoval
7356816f61 helpers: get rid of get_tcp_states()
After thinking about this some more, I decided that although it makes
sense for scripts to convert a type to an IntEnum class, I'd prefer that
the helpers take and return drgn Objects rather than these classes.
2020-01-14 14:25:32 -08:00
Omar Sandoval
660276a0b8 Format Python code with Black
I'm not a fan of 100% of the Black coding style, but I've spent too much
time manually formatting Python code, so let's just pull the trigger.
2020-01-14 11:51:58 -08:00
Omar Sandoval
bb7a8eedcf helpers: add sk_tcpstate
Although it doesn't correspond to a Linux kernel function, it is more
convenient than open-coding it everywhere, especially since the leading
__ causes Python to mangle the name if it's inside of a class.
2020-01-02 19:43:57 -05:00
Andrey Ignatov
7a36136417 examples: Add tcp_sock.py
Add example script that goes over all TCP sockets and for every socket
prints:
- TCP state;
- IP:port pair;
- cgroup v2 path.

The script shows basic operations with sockets including getting `struct
sock`, `struct inet_sock`, socket fields and cgroup v2 of socket.

It provides output similar to `ss -nt` or `ss -lnt`:

  % sudo python36 -m drgn examples/linux/tcp_sock.py | shuf -n 5
  TIME_WAIT                                       [::1]:2560                                      [::1]:44041
  ESTABLISHED                                     [::1]:54178                                     [::1]:11101  system.slice/async-distillery-server.service
  LISTEN                                           [::]:3201                                       [::]:0      system.slice/fbflow.service
  ESTABLISHED           [2401:db00:21:718a:face:0:31:0]:2406            [2401:db00:12:a106:face:0:1e:0]:46306  system.slice/configerator_proxy2.service
  LISTEN                                        0.0.0.0:11150                                   0.0.0.0:0      system.slice/system-mcrouter.slice/mcrouter@tao.service

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-02 19:43:57 -05:00