// SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2017-18 David Ahern <dsahern@gmail.com> * * 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. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*/
staticint do_attach(int idx, int prog_fd, int map_fd, constchar *name)
{ int err;
err = bpf_xdp_attach(idx, prog_fd, xdp_flags, NULL); if (err < 0) {
printf("ERROR: failed to attach program to %s\n", name); return err;
}
/* Adding ifindex as a possible egress TX port */
err = bpf_map_update_elem(map_fd, &idx, &idx, 0); if (err)
printf("ERROR: failed using device %s as TX-port\n", name);
err = bpf_object__load(obj); if (err) {
printf("Does kernel support devmap lookup?\n"); /* If not, the error message will be: * "cannot pass map_type 14 into func bpf_map_lookup_elem#1"
*/ return1;
}
bpf_object__for_each_program(pos, obj) {
sec_name = bpf_program__section_name(pos); if (sec_name && !strcmp(sec_name, prog_name)) {
prog = pos; break;
}
}
prog_fd = bpf_program__fd(prog); if (prog_fd < 0) {
printf("program not found: %s\n", strerror(prog_fd)); return1;
}
map_fd = bpf_map__fd(bpf_object__find_map_by_name(obj, "xdp_tx_ports")); if (map_fd < 0) {
printf("map not found: %s\n", strerror(map_fd)); return1;
}
}
for (i = optind; i < argc; ++i) {
idx = if_nametoindex(argv[i]); if (!idx)
idx = strtoul(argv[i], NULL, 0);
if (!idx) {
fprintf(stderr, "Invalid arg\n"); return1;
} if (!attach) {
err = do_detach(idx, argv[i], prog_name); if (err)
ret = err;
} else {
err = do_attach(idx, prog_fd, map_fd, argv[i]); if (err)
ret = err;
}
}
return ret;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-07)
¤
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.