-
Notifications
You must be signed in to change notification settings - Fork 52
[0/3] Enable flavor specific matching #456
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
Merged
qdeslandes
merged 2 commits into
facebook:main
from
yaakov-stein:enable_flavor_specific_matching
Mar 12, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0-only */ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
yaakov-stein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
|
|
||
| #include "cgen/matcher/packet.h" | ||
|
|
||
| #include <errno.h> | ||
|
|
||
| #include <bpfilter/helper.h> | ||
| #include <bpfilter/logger.h> | ||
| #include <bpfilter/matcher.h> | ||
|
|
||
| #include "cgen/matcher/icmp.h" | ||
| #include "cgen/matcher/ip4.h" | ||
| #include "cgen/matcher/ip6.h" | ||
| #include "cgen/matcher/meta.h" | ||
| #include "cgen/matcher/set.h" | ||
| #include "cgen/matcher/tcp.h" | ||
| #include "cgen/matcher/udp.h" | ||
| #include "cgen/program.h" | ||
|
|
||
| int bf_matcher_generate_packet(struct bf_program *program, | ||
| const struct bf_matcher *matcher) | ||
| { | ||
| assert(program); | ||
| assert(matcher); | ||
|
|
||
| switch (bf_matcher_get_type(matcher)) { | ||
| case BF_MATCHER_META_IFACE: | ||
| case BF_MATCHER_META_L3_PROTO: | ||
| case BF_MATCHER_META_L4_PROTO: | ||
| case BF_MATCHER_META_PROBABILITY: | ||
| case BF_MATCHER_META_SPORT: | ||
| case BF_MATCHER_META_DPORT: | ||
| case BF_MATCHER_META_FLOW_PROBABILITY: | ||
| return bf_matcher_generate_meta(program, matcher); | ||
| case BF_MATCHER_META_MARK: | ||
| case BF_MATCHER_META_FLOW_HASH: | ||
| return bf_err_r(-ENOTSUP, | ||
| "matcher '%s' is not supported by this flavor", | ||
| bf_matcher_type_to_str(bf_matcher_get_type(matcher))); | ||
| case BF_MATCHER_IP4_SADDR: | ||
| case BF_MATCHER_IP4_SNET: | ||
yaakov-stein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| case BF_MATCHER_IP4_DADDR: | ||
| case BF_MATCHER_IP4_DNET: | ||
| case BF_MATCHER_IP4_PROTO: | ||
| case BF_MATCHER_IP4_DSCP: | ||
| return bf_matcher_generate_ip4(program, matcher); | ||
| case BF_MATCHER_IP6_SADDR: | ||
| case BF_MATCHER_IP6_SNET: | ||
| case BF_MATCHER_IP6_DADDR: | ||
| case BF_MATCHER_IP6_DNET: | ||
| case BF_MATCHER_IP6_NEXTHDR: | ||
| case BF_MATCHER_IP6_DSCP: | ||
| return bf_matcher_generate_ip6(program, matcher); | ||
| case BF_MATCHER_TCP_SPORT: | ||
| case BF_MATCHER_TCP_DPORT: | ||
| case BF_MATCHER_TCP_FLAGS: | ||
| return bf_matcher_generate_tcp(program, matcher); | ||
| case BF_MATCHER_UDP_SPORT: | ||
| case BF_MATCHER_UDP_DPORT: | ||
| return bf_matcher_generate_udp(program, matcher); | ||
| case BF_MATCHER_ICMP_TYPE: | ||
| case BF_MATCHER_ICMP_CODE: | ||
| case BF_MATCHER_ICMPV6_TYPE: | ||
| case BF_MATCHER_ICMPV6_CODE: | ||
| return bf_matcher_generate_icmp(program, matcher); | ||
| case BF_MATCHER_SET: | ||
| return bf_matcher_generate_set(program, matcher); | ||
| default: | ||
| return bf_err_r(-EINVAL, "unknown matcher type %d", | ||
| bf_matcher_get_type(matcher)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0-only */ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
yaakov-stein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| struct bf_matcher; | ||
| struct bf_program; | ||
|
|
||
| /** | ||
| * @brief Generate bytecode for a packet-based matcher. | ||
| * | ||
| * Dispatches to the appropriate matcher codegen function based on the matcher | ||
| * type. Handles all matchers that operate on packet headers or metadata common | ||
| * to all packet-based flavors. | ||
| * | ||
| * `BF_MATCHER_META_MARK` and `BF_MATCHER_META_FLOW_HASH` are not supported | ||
| * by this function and return `-ENOTSUP`, as they require flavor-specific | ||
| * context access. | ||
| * | ||
| * @param program Program being generated. Can't be NULL. | ||
| * @param matcher Matcher to generate code for. Can't be NULL. | ||
| * @return 0 on success, negative errno on error. | ||
| */ | ||
| int bf_matcher_generate_packet(struct bf_program *program, | ||
| const struct bf_matcher *matcher); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Drive-by fix here and same thing in
nf.c