Files
xdp-project-bpf-examples/pkt-loop-filter/get-bond-active.c
Toke Høiland-Jørgensen 032d9cde85 pkt-loop-filter: Add get-bond-active utility
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>
2022-06-29 16:58:34 +02:00

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;
}