-
Notifications
You must be signed in to change notification settings - Fork 26
[RFC] infra: add iface mirror node #559
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: main
Are you sure you want to change the base?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ src += files( | |
| 'lacp.c', | ||
| 'loopback.c', | ||
| 'mempool.c', | ||
| 'mirror.c', | ||
| 'netlink.c', | ||
| 'nexthop.c', | ||
| 'port.c', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright (c) 2026 Christophe Fontaine | ||
|
|
||
| #include <gr_iface.h> | ||
| #include <gr_infra.h> | ||
| #include <gr_log.h> | ||
|
|
||
| #include <rte_bpf.h> | ||
| #include <rte_malloc.h> | ||
|
|
||
| #include <pcap.h> | ||
| #include <string.h> | ||
|
|
||
| int iface_mirror_filter_compile(const char *expr, struct rte_bpf **out) { | ||
|
Collaborator
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. What do you think of changing the signature to: struct rte_bpf *iface_mirror_filter_compile(const char *expr);And relying on |
||
| struct bpf_program fcode; | ||
| struct rte_bpf_prm *prm; | ||
| struct rte_bpf *bpf; | ||
| pcap_t *pcap; | ||
|
|
||
| *out = NULL; | ||
|
|
||
| if (expr == NULL || expr[0] == '\0') | ||
| return 0; | ||
|
Comment on lines
+136
to
+137
Collaborator
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. Probably worth returning EINVAL here. |
||
|
|
||
| pcap = pcap_open_dead(DLT_EN10MB, 262144); | ||
|
Collaborator
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 am not familiar with libpcap, could you add a comment explaining what are these arguments? Especially the |
||
| if (pcap == NULL) { | ||
| LOG(ERR, "pcap_open_dead failed"); | ||
| return errno_set(EINVAL); | ||
| } | ||
|
|
||
| if (pcap_compile(pcap, &fcode, expr, 1, PCAP_NETMASK_UNKNOWN) != 0) { | ||
| LOG(ERR, "mirror filter \"%s\": %s", expr, pcap_geterr(pcap)); | ||
| pcap_close(pcap); | ||
| return errno_set(EINVAL); | ||
| } | ||
|
|
||
| prm = rte_bpf_convert(&fcode); | ||
| pcap_freecode(&fcode); | ||
| pcap_close(pcap); | ||
|
|
||
| if (prm == NULL) { | ||
| LOG(ERR, "rte_bpf_convert \"%s\": %s", expr, rte_strerror(rte_errno)); | ||
| return -rte_errno; | ||
| } | ||
|
|
||
| bpf = rte_bpf_load(prm); | ||
| rte_free(prm); | ||
|
|
||
| if (bpf == NULL) { | ||
| LOG(ERR, "rte_bpf_load \"%s\": %s", expr, rte_strerror(rte_errno)); | ||
| return -rte_errno; | ||
| } | ||
|
|
||
| *out = bpf; | ||
| return 0; | ||
| } | ||
|
|
||
| void iface_mirror_filter_destroy(struct rte_bpf *bpf) { | ||
| if (bpf != NULL) | ||
| rte_bpf_destroy(bpf); | ||
| } | ||
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.
Can you move this field to
gr_ifacenext todescription[256]? And only store a strdup'd() copy in the control plane structure like it is done for name and description.