diff options
author | Matias Elo <matias.elo@nokia.com> | 2020-11-11 16:03:44 +0200 |
---|---|---|
committer | Petri Savolainen <petri.savolainen@nokia.com> | 2020-11-13 16:39:08 +0200 |
commit | 9adf28c6387587a1106032868f4efb0d93cb83b6 (patch) | |
tree | 842dbc1df91e584140ead503935ded78248e3b50 /example | |
parent | 5ff2bcc89e3434237924a80d3bbd85caab70c06b (diff) |
example: cls: add support for ODP_PMR_DMAC
Add support for destination MAC address PMR term.
Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
Diffstat (limited to 'example')
-rw-r--r-- | example/classifier/odp_classifier.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c index f7d10a812..ef7b829e1 100644 --- a/example/classifier/odp_classifier.c +++ b/example/classifier/odp_classifier.c @@ -1,5 +1,5 @@ /* Copyright (c) 2015-2018, Linaro Limited - * Copyright (c) 2019, Nokia + * Copyright (c) 2019-2020, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -800,6 +800,9 @@ static int convert_str_to_pmr_enum(char *token, odp_cls_pmr_term_t *term) } else if (strcasecmp(token, "ODP_PMR_SIP_ADDR") == 0) { *term = ODP_PMR_SIP_ADDR; return 0; + } else if (strcasecmp(token, "ODP_PMR_DMAC") == 0) { + *term = ODP_PMR_DMAC; + return 0; } else if (strcasecmp(token, "ODP_PMR_CUSTOM_FRAME") == 0) { *term = ODP_PMR_CUSTOM_FRAME; return 0; @@ -814,10 +817,11 @@ static int convert_str_to_pmr_enum(char *token, odp_cls_pmr_term_t *term) static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) { int policy_count; - char *token, *cos0, *cos1; + char *token, *cos0, *cos1, *cur_char; size_t len; odp_cls_pmr_term_t term; global_statistics *stats; + odph_ethaddr_t mac; char *pmr_str; uint32_t offset, ip_addr, u32; unsigned long int value, mask; @@ -911,6 +915,34 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) stats[policy_count].rule.val_sz = 4; break; + case ODP_PMR_DMAC: + /* :<MAC addr>:<mask> */ + token = strtok(NULL, ":"); + strncpy(stats[policy_count].value, token, + DISPLAY_STRING_LEN - 1); + + /* Replace hyphens in the MAC string with colons to be compatible with + * odph_eth_addr_parse(). */ + cur_char = token; + while ((cur_char = strchr(cur_char, '-')) != NULL) + *cur_char++ = ':'; + + if (odph_eth_addr_parse(&mac, token)) { + ODPH_ERR("Invalid MAC address. Use format 11-22-33-44-55-66.\n"); + exit(EXIT_FAILURE); + } + + memcpy(stats[policy_count].rule.value_be, mac.addr, ODPH_ETHADDR_LEN); + stats[policy_count].rule.val_sz = 6; + + token = strtok(NULL, ":"); + strncpy(stats[policy_count].mask, token, DISPLAY_STRING_LEN - 1); + mask_sz = parse_custom(token, stats[policy_count].rule.mask_be, ODPH_ETHADDR_LEN); + if (mask_sz != ODPH_ETHADDR_LEN) { + ODPH_ERR("Invalid mask. Provide mask without 0x prefix.\n"); + return -1; + } + break; case ODP_PMR_CUSTOM_FRAME: /* Fall through */ case ODP_PMR_CUSTOM_L3: |