drgn/tests
Peilin Ye 557b8152cc helpers: Add netdev_get_by_name()
Add a helper to get the network device ("struct net_device *") given an
interface name.  As an example:

    >>> netdev = netdev_get_by_name(prog["init_net"], "lo")
    >>> netdev.ifindex.value_()
    1

Or pass a "Program" as the first argument, and let the helper find in
the initial network namespace (i.e. "init_net"):

    >>> netdev = netdev_get_by_index(prog, "dummy0")
    >>> netdev.ifindex.value_()
    2

Also add a test for this new helper to tests/helpers/linux/test_net.py.

This helper simply does a linear search over the name hash table of the
network namespace, since implementing hashing in drgn is non-trivial.
It is obviously slower than net/core/dev.c:netdev_name_node_lookup() in
the kernel, but still useful.

Linux kernel commit ff92741270bf ("net: introduce name_node struct to be
used in hashlist") introduced struct netdev_name_node for name lookups.
Start by assuming that the kernel has this commit, and fall back to the
old path if that fails.

Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
2021-08-11 20:23:39 -07:00
..
helpers helpers: Add netdev_get_by_name() 2021-08-11 20:23:39 -07:00
__init__.py Fix some flake8 errors 2021-08-11 14:52:44 -07:00
assembler.py libdrgn: binary_buffer: handle non-canonical LEB128 numbers 2021-06-30 21:39:31 -07:00
dwarf.py Track byte order in scalar types instead of objects 2021-02-19 21:41:29 -08:00
dwarfwriter.py libdrgn: dwarf_index: handle DW_FORM_block 2021-06-30 01:34:52 -07:00
elf.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
elfwriter.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
libdrgn.py Fix some flake8 errors 2021-08-11 14:52:44 -07:00
test_docs.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_dwarf.py Fix some flake8 errors 2021-08-11 14:52:44 -07:00
test_language_c.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_lexer.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_object.py Fix some flake8 errors 2021-08-11 14:52:44 -07:00
test_path.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_platform.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_program.py libdrgn: make addresses wrap around when reading memory 2021-06-03 17:49:29 -07:00
test_python.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_serialize.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00
test_type.py Fix some flake8 errors 2021-08-11 14:52:44 -07:00
test_util.py Use GPL-3.0-or-later license identifier instead of GPL-3.0+ 2021-04-03 01:10:35 -07:00