-
Notifications
You must be signed in to change notification settings - Fork 8
n-acd: decide if ebpf is used at runtime #9
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: master
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
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,8 +208,6 @@ static int n_acd_probe_link(NAcdProbe *probe) { | |
* entry. | ||
*/ | ||
r = n_acd_ensure_bpf_map_space(probe->acd); | ||
if (r) | ||
return r; | ||
|
||
/* | ||
* Link entry into context, indexed by its IP. Note that we allow | ||
|
@@ -238,7 +236,7 @@ static int n_acd_probe_link(NAcdProbe *probe) { | |
/* | ||
* Add the ip address to the map, if it is not already there. | ||
*/ | ||
if (n_acd_probe_is_unique(probe)) { | ||
if (probe->acd->fd_bpf_map >= 0 && n_acd_probe_is_unique(probe)) { | ||
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. I think I would rather prefer for |
||
r = n_acd_bpf_map_add(probe->acd->fd_bpf_map, &probe->ip); | ||
if (r) { | ||
/* | ||
|
@@ -261,7 +259,7 @@ static void n_acd_probe_unlink(NAcdProbe *probe) { | |
* If this is the only probe for a given IP, remove the IP from the | ||
* kernel BPF map. | ||
*/ | ||
if (n_acd_probe_is_unique(probe)) { | ||
if (probe->acd->fd_bpf_map >= 0 && n_acd_probe_is_unique(probe)) { | ||
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 comment as above. I would rather make |
||
r = n_acd_bpf_map_remove(probe->acd->fd_bpf_map, &probe->ip); | ||
c_assert(r >= 0); | ||
--probe->acd->n_bpf_map; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,7 +296,7 @@ int n_acd_ensure_bpf_map_space(NAcd *acd) { | |
|
||
r = n_acd_bpf_compile(&fd_prog, fd_map, (struct ether_addr*) acd->mac); | ||
if (r) | ||
return r; | ||
fd_prog = -1; | ||
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 will suppress any real error from |
||
|
||
if (fd_prog >= 0) { | ||
r = setsockopt(acd->fd_socket, SOL_SOCKET, SO_ATTACH_BPF, &fd_prog, sizeof(fd_prog)); | ||
|
@@ -360,12 +360,12 @@ _c_public_ int n_acd_new(NAcd **acdp, NAcdConfig *config) { | |
acd->max_bpf_map = 8; | ||
|
||
r = n_acd_bpf_map_create(&acd->fd_bpf_map, acd->max_bpf_map); | ||
if (r) | ||
return r; | ||
|
||
r = n_acd_bpf_compile(&fd_bpf_prog, acd->fd_bpf_map, (struct ether_addr*) acd->mac); | ||
if (r) | ||
return r; | ||
if (acd->fd_bpf_map >= 0) { | ||
r = n_acd_bpf_compile(&fd_bpf_prog, acd->fd_bpf_map, (struct ether_addr*) acd->mac); | ||
if (r) | ||
fd_bpf_prog = -1; | ||
} | ||
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 as above, I think this should handle a possible fd_bpf_prog = -1;
r = n_acd_bpf_map_create(...);
if (!r)
r = n_acd_bpf_compile(...);
if (r && r != N_ACD_E_DENIED)
return r; |
||
|
||
r = n_acd_socket_new(&acd->fd_socket, fd_bpf_prog, config); | ||
if (r) | ||
|
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.
Please keep this error-handler there, otherwise we will suppress real errors from the bpf-helpers.