-
Notifications
You must be signed in to change notification settings - Fork 11
/
otherhost.py
executable file
·35 lines (25 loc) · 993 Bytes
/
otherhost.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env drgn
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: © 2023 Georg Sauthoff <[email protected]>
# hlist_for_each_entry(), netdev_get_by_name(), ...
from drgn.helpers.linux import *
import drgn.helpers.linux.net
# cf. dev_get_stats() in net/core/dev.c:
# https://elixir.bootlin.com/linux/v6.2.15/source/net/core/dev.c#L10431
def rx_otherhost_dropped(dev):
r = 0
for i in for_each_present_cpu(prog):
r += per_cpu_ptr(dev.core_stats, i).rx_otherhost_dropped.value_()
return r
def for_each_netdev(prog):
net = prog['init_net']
for i in range(drgn.helpers.linux.net._NETDEV_HASHENTRIES):
h = net.dev_index_head[i]
for d in hlist_for_each_entry("struct net_device", h, "index_hlist"):
yield d
for d in for_each_netdev(prog):
name = d.name.string_().decode()
x = rx_otherhost_dropped(d)
print(f'{name:15} {x}')
# d = netdev_get_by_name(prog, 'enp4s0u2u1u2')
# print(rx_otherhost_dropped(d))