mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
traffic-pacing-edt: implement option for --remove
Need quick way to remove before testing on production. Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
This commit is contained in:
@@ -42,6 +42,7 @@ static const struct option long_options[] = {
|
|||||||
{"dev", required_argument, NULL, 'd' },
|
{"dev", required_argument, NULL, 'd' },
|
||||||
{"qsize", required_argument, NULL, 'q' },
|
{"qsize", required_argument, NULL, 'q' },
|
||||||
{"force", no_argument, NULL, 'F' },
|
{"force", no_argument, NULL, 'F' },
|
||||||
|
{"remove", no_argument, NULL, 'r' },
|
||||||
{0, 0, NULL, 0 }
|
{0, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -125,7 +126,21 @@ int do_xdp_attach(int ifindex, struct bpf_program *prog, __u32 xdp_flags)
|
|||||||
|
|
||||||
err = bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags);
|
err = bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags);
|
||||||
if (err) {
|
if (err) {
|
||||||
fprintf(stderr, "link set xdp fd failed (err:%d)\n", err);
|
fprintf(stderr, "%s(): link set xdp fd failed (err:%d)\n",
|
||||||
|
__func__, err);
|
||||||
|
return EXIT_FAIL_XDP;
|
||||||
|
}
|
||||||
|
return EXIT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_xdp_detach(int ifindex, __u32 xdp_flags)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = bpf_set_link_xdp_fd(ifindex, -1, xdp_flags);
|
||||||
|
if (err) {
|
||||||
|
fprintf(stderr, "%s(): link set xdp fd failed (err:%d)\n",
|
||||||
|
__func__, err);
|
||||||
return EXIT_FAIL_XDP;
|
return EXIT_FAIL_XDP;
|
||||||
}
|
}
|
||||||
return EXIT_OK;
|
return EXIT_OK;
|
||||||
@@ -134,6 +149,7 @@ int do_xdp_attach(int ifindex, struct bpf_program *prog, __u32 xdp_flags)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
|
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
|
||||||
|
bool do_detach = false;
|
||||||
int opt, longindex = 0;
|
int opt, longindex = 0;
|
||||||
__u32 cfg_qsize = 512;
|
__u32 cfg_qsize = 512;
|
||||||
char buf[100];
|
char buf[100];
|
||||||
@@ -145,6 +161,9 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
int n_cpus = get_nprocs_conf();
|
int n_cpus = get_nprocs_conf();
|
||||||
|
|
||||||
|
/* Always use XDP native driver mode */
|
||||||
|
xdp_flags |= XDP_FLAGS_DRV_MODE;
|
||||||
|
|
||||||
obj = bpf_object__open_file("xdp_cpumap_qinq.o", NULL);
|
obj = bpf_object__open_file("xdp_cpumap_qinq.o", NULL);
|
||||||
err = libbpf_get_error(obj);
|
err = libbpf_get_error(obj);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -179,6 +198,9 @@ int main(int argc, char **argv)
|
|||||||
case 'F':
|
case 'F':
|
||||||
xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST;
|
xdp_flags &= ~XDP_FLAGS_UPDATE_IF_NOEXIST;
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
do_detach = true;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
error:
|
error:
|
||||||
default:
|
default:
|
||||||
@@ -193,13 +215,14 @@ int main(int argc, char **argv)
|
|||||||
return EXIT_FAIL_OPTION;
|
return EXIT_FAIL_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (do_detach)
|
||||||
|
return do_xdp_detach(ifindex, xdp_flags);
|
||||||
|
|
||||||
if (setrlimit(RLIMIT_MEMLOCK, &r)) {
|
if (setrlimit(RLIMIT_MEMLOCK, &r)) {
|
||||||
perror("setrlimit(RLIMIT_MEMLOCK)");
|
perror("setrlimit(RLIMIT_MEMLOCK)");
|
||||||
return EXIT_FAIL_MEM;
|
return EXIT_FAIL_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Always use XDP native driver mode */
|
|
||||||
xdp_flags |= XDP_FLAGS_DRV_MODE;
|
|
||||||
|
|
||||||
obj = do_load_bpf_obj(obj);
|
obj = do_load_bpf_obj(obj);
|
||||||
if (!obj)
|
if (!obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user