-
Notifications
You must be signed in to change notification settings - Fork 187
xdp-forward-queueing: Update outstanding bytes #497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: xdp-forward-queueing
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| #include <stdio.h> | ||
| #include <errno.h> | ||
| #include <string.h> | ||
| #include <unistd.h> | ||
| #include <errno.h> | ||
|
|
||
| #include <bpf/libbpf.h> | ||
| #include <xdp/libxdp.h> | ||
|
|
@@ -140,7 +142,10 @@ static int do_load(const void *cfg, __unused const char *pin_root_path) | |
| { | ||
| struct xdp_program *xdp_prog = NULL, *init_prog = NULL; | ||
| DECLARE_LIBBPF_OPTS(xdp_program_opts, opts); | ||
| struct bpf_program *return_prog = NULL; | ||
| const struct load_opts *opt = cfg; | ||
| struct bpf_link *link = NULL; | ||
| char pin_link_path[PATH_MAX]; | ||
| struct xdp_forward *skel; | ||
| int ret = EXIT_FAILURE; | ||
| struct iface *iface; | ||
|
|
@@ -217,6 +222,34 @@ static int do_load(const void *cfg, __unused const char *pin_root_path) | |
| pr_info("Loaded on interface %s\n", iface->ifname); | ||
| } | ||
|
|
||
| /* Attach xdp_check_return to xdp_frame_return tracepoint and | ||
| * pin the link to pin_root_path/xdp_check_return. | ||
| */ | ||
|
|
||
| return_prog = bpf_object__find_program_by_name(skel->obj,"xdp_check_return"); | ||
| if (!return_prog) { | ||
| pr_warn("Failed to find xdp_check_return program\n"); | ||
| goto end_detach; | ||
| } | ||
|
|
||
| link = bpf_program__attach_raw_tracepoint(return_prog, "xdp_frame_return"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be possible to just call |
||
| if (libbpf_get_error((const void *) link)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be possible to just pass the pointers to |
||
| pr_warn("Couldn't attach to xdp_frame_return: %s\n", | ||
| strerror(libbpf_get_error((const void *) link))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...same here |
||
| goto end_detach; | ||
| } | ||
| skel->links.xdp_check_return = link; | ||
|
|
||
| snprintf(pin_link_path, sizeof(pin_link_path), "%s/%s", pin_root_path, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use the |
||
| "xdp_check_return"); | ||
| ret = bpf_link__pin(link, pin_link_path); | ||
| if (ret) { | ||
| pr_warn("Failed to pin link: %s\n", | ||
| strerror(errno)); | ||
| goto end_detach; | ||
| } | ||
| pr_info("Pinned xdp_check_return to %s\n", pin_link_path); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be |
||
|
|
||
| end_destroy: | ||
| xdp_forward__destroy(skel); | ||
| end: | ||
|
|
@@ -225,6 +258,10 @@ static int do_load(const void *cfg, __unused const char *pin_root_path) | |
| end_detach: | ||
| for (iface = opt->ifaces; iface; iface = iface->next) | ||
| xdp_program__detach(xdp_prog, iface->ifindex, opt->xdp_mode, 0); | ||
|
|
||
| bpf_link__unpin(link); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| bpf_link__destroy(link); | ||
|
|
||
| goto end_destroy; | ||
| } | ||
|
|
||
|
|
@@ -246,6 +283,8 @@ struct prog_option unload_options[] = { | |
| static int do_unload(const void *cfg, __unused const char *pin_root_path) | ||
| { | ||
| const struct unload_opts *opt = cfg; | ||
| struct bpf_link *link = NULL; | ||
| char pin_link_path[PATH_MAX]; | ||
| int ret = EXIT_SUCCESS; | ||
| struct iface *iface; | ||
|
|
||
|
|
@@ -258,6 +297,24 @@ static int do_unload(const void *cfg, __unused const char *pin_root_path) | |
| pr_info("Unloaded from interface %s\n", iface->ifname); | ||
| } | ||
|
|
||
| snprintf(pin_link_path, sizeof(pin_link_path), "%s/%s", pin_root_path, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above wrt using |
||
| "xdp_check_return"); | ||
|
|
||
| link = bpf_link__open(pin_link_path); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of going through this open/unpin/destroy dance, just unlink the pin file? |
||
| ret = bpf_link__unpin(link); | ||
| if(ret){ | ||
| pr_warn("Couldn't unpin link\n"); | ||
| } else { | ||
| pr_info("Unpinned link from %s\n", pin_link_path); | ||
| } | ||
|
|
||
| ret = bpf_link__destroy(link); | ||
| if(ret){ | ||
| pr_warn("Couldn't destroy link\n"); | ||
| } else { | ||
| pr_info("Destroyed link\n"); | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The program is available in the skeleton as skel->progs.xdp_check_return - no need to use
bpf_object__find_program_by_name()