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>
40 lines
916 B
C
40 lines
916 B
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <net/if.h>
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <bpf/libbpf.h>
|
|
|
|
#include "bond-active.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int ifindex, active_ifindex;
|
|
const char *ifname;
|
|
|
|
if (argc < 2) {
|
|
fprintf(stderr, "Usage: %s <ifname>\n", argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
ifname = argv[1];
|
|
ifindex = if_nametoindex(ifname);
|
|
if (!ifindex) {
|
|
fprintf(stderr, "Couldn't find interface '%s'\n", ifname);
|
|
return 1;
|
|
}
|
|
|
|
active_ifindex = get_bond_active_ifindex(ifindex);
|
|
if (active_ifindex < 0)
|
|
return active_ifindex;
|
|
|
|
printf("Bond with ifindex %d has active ifindex: %d\n", ifindex, active_ifindex);
|
|
return 0;
|
|
}
|