/* SPDX-License-Identifier: GPL-2.0 * Copyright (c) 2018 Facebook * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation.
*/ #include <linux/bpf.h> #include <linux/if_link.h> #include <assert.h> #include <errno.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <net/if.h> #include <arpa/inet.h> #include <netinet/ether.h> #include <unistd.h> #include <time.h> #include <bpf/bpf.h> #include <bpf/libbpf.h>
if (ifindex > -1) { if (bpf_xdp_query_id(ifindex, xdp_flags, &curr_prog_id)) {
printf("bpf_xdp_query_id failed\n"); exit(1);
} if (prog_id == curr_prog_id)
bpf_xdp_detach(ifindex, xdp_flags, NULL); elseif (!curr_prog_id)
printf("couldn't find a prog id on a given iface\n"); else
printf("program on interface changed, not removing\n");
} exit(0);
}
/* simple "icmp packet too big sent" counter
*/ staticvoid poll_stats(unsignedint map_fd, unsignedint kill_after_s)
{
time_t started_at = time(NULL);
__u64 value = 0; int key = 0;
while (!kill_after_s || time(NULL) - started_at <= kill_after_s) {
sleep(STATS_INTERVAL_S);
/* static global var 'max_pcktsz' is accessible from .data section */ if (max_pckt_size) {
map_fd = bpf_object__find_map_fd_by_name(obj, "xdp_adju.data"); if (map_fd < 0) {
printf("finding a max_pcktsz map in obj file failed\n"); return 1;
}
bpf_map_update_elem(map_fd, &key, &max_pckt_size, BPF_ANY);
}
/* fetch icmpcnt map */
map_fd = bpf_object__find_map_fd_by_name(obj, "icmpcnt"); if (map_fd < 0) {
printf("finding a icmpcnt map in obj file failed\n"); return 1;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.