mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
Add a small utility that uses a kprobe to extract the currently active slave ifindex from a bond interface. This value is normally only exported to userspace for bond types where it can be explicitly set, but the bond driver has an internal notion of an active interface regardless of the bond type. We can extract this value with a kprobe by attaching to a function in the bond driver and triggering an operation that causes this function to be called. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#ifndef BPF_DEFS_H
|
|
#define BPF_DEFS_H
|
|
|
|
/* cookie for init ns; hoping this is stable */
|
|
#define INIT_NS 1
|
|
|
|
/* partial structs for reading bond parameters.
|
|
*
|
|
* These are deliberately *not* declared with the preserve_access_index, as
|
|
* we'll read them with plan BPF_PROBE_READ() below; this is to make sure they
|
|
* work even without module BTF, and the fields we need are only the first ones
|
|
* of each struct which have been stable for a long time.
|
|
*/
|
|
struct slave {
|
|
struct net_device *dev; /* first - useful for panic debug */
|
|
};
|
|
|
|
struct bonding {
|
|
struct net_device *dev; /* first - useful for panic debug */
|
|
struct slave *curr_active_slave;
|
|
};
|
|
|
|
/* local partial kernel struct definitions with just the members we need */
|
|
struct net {
|
|
__u64 net_cookie;
|
|
} __attribute__((preserve_access_index));
|
|
|
|
struct net_device {
|
|
int ifindex;
|
|
struct {
|
|
struct net *net;
|
|
} nd_net;
|
|
} __attribute__((preserve_access_index));
|
|
|
|
struct netdev_notifier_info {
|
|
struct net_device *dev;
|
|
} __attribute__((preserve_access_index));
|
|
|
|
#endif
|