-
Notifications
You must be signed in to change notification settings - Fork 54
Add DSCP class-name keyword support #492
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 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 |
|---|---|---|
|
|
@@ -737,22 +737,30 @@ static int _bf_parse_dscp(enum bf_matcher_type type, enum bf_matcher_op op, | |
| assert(payload); | ||
| assert(raw_payload); | ||
|
|
||
| if (!bf_dscp_class_from_str(raw_payload, (uint8_t *)payload)) | ||
| return 0; | ||
|
|
||
| if (!_bf_strtoul(raw_payload, &value) && value <= BF_DSCP_MAX) { | ||
| *(uint8_t *)payload = (uint8_t)value; | ||
| return 0; | ||
| } | ||
|
|
||
| return bf_err_r( | ||
| -EINVAL, | ||
| "\"%s %s\" expects a DSCP value (0-63) in decimal or hexadecimal notation, not '%s'", | ||
| "\"%s %s\" expects a DSCP value (0-63, decimal/hex) or class name, not '%s'", | ||
| bf_matcher_type_to_str(type), bf_matcher_op_to_str(op), raw_payload); | ||
| } | ||
|
|
||
| static void _bf_print_dscp(const void *payload) | ||
| { | ||
| assert(payload); | ||
|
|
||
| (void)fprintf(stdout, "%" PRIu8, *(uint8_t *)payload); | ||
| const char *name = bf_dscp_class_to_str(*(uint8_t *)payload); | ||
|
|
||
| if (name) | ||
| (void)fprintf(stdout, "%s", name); | ||
| else | ||
| (void)fprintf(stdout, "%" PRIu8, *(uint8_t *)payload); | ||
| } | ||
|
|
||
| static int _bf_parse_icmpv6_type(enum bf_matcher_type type, | ||
|
|
@@ -1665,6 +1673,51 @@ int bf_ipproto_from_str(const char *str, uint8_t *ipproto) | |
| return -EINVAL; | ||
| } | ||
|
|
||
| /* DSCP class name to codepoint mapping, based on iptables | ||
| * dscp_helper.c and http://www.iana.org/assignments/dscp-registry. | ||
|
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. Claude: nit: The IANA link uses plain HTTP. Consider updating to |
||
| * BE is an alias for CS0. */ | ||
| static const struct | ||
| { | ||
| const char *name; | ||
| uint8_t dscp; | ||
| } _bf_dscp_classes[] = { | ||
| {"cs0", 0}, {"cs1", 8}, {"cs2", 16}, {"cs3", 24}, {"cs4", 32}, | ||
| {"cs5", 40}, {"cs6", 48}, {"cs7", 56}, {"af11", 10}, {"af12", 12}, | ||
| {"af13", 14}, {"af21", 18}, {"af22", 20}, {"af23", 22}, {"af31", 26}, | ||
| {"af32", 28}, {"af33", 30}, {"af41", 34}, {"af42", 36}, {"af43", 38}, | ||
| {"ef", 46}, | ||
| }; | ||
|
|
||
| const char *bf_dscp_class_to_str(uint8_t dscp) | ||
| { | ||
| for (size_t i = 0; i < ARRAY_SIZE(_bf_dscp_classes); ++i) { | ||
| if (_bf_dscp_classes[i].dscp == dscp) | ||
| return _bf_dscp_classes[i].name; | ||
| } | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| int bf_dscp_class_from_str(const char *str, uint8_t *dscp) | ||
| { | ||
| assert(str); | ||
| assert(dscp); | ||
|
|
||
| if (bf_streq_i(str, "be")) { | ||
|
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. Claude: suggestion: The |
||
| *dscp = 0; | ||
| return 0; | ||
| } | ||
|
|
||
| for (size_t i = 0; i < ARRAY_SIZE(_bf_dscp_classes); ++i) { | ||
| if (bf_streq_i(str, _bf_dscp_classes[i].name)) { | ||
| *dscp = _bf_dscp_classes[i].dscp; | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| return -EINVAL; | ||
| } | ||
|
|
||
| #define ICMP_ROUTERADVERT 9 | ||
| #define ICMP_ROUTERSOLICIT 10 | ||
|
|
||
|
|
||
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.
Claude: nit: Other
_bf_parse_*functions passpayloaddirectly to their corresponding*_from_strcall without a cast (e.g.bf_icmp_type_from_str(raw_payload, payload),bf_ipproto_from_str(raw_payload, payload)). The explicit(uint8_t *)cast is safe but unnecessary in C (void *converts implicitly) and inconsistent with the existing pattern.