> Application is accepting routes for port ID up to UINT8_MAX
> for LPM amd EM routes on parsing the given rule file, but only
> up to 32 ports can be enabled as per the variable enabled_port_mask
> which is defined as uint32_t.
> 
> This patch restricts the rules parsing code to accept routes for
> port ID up to 31 only to avoid any unnecessary maintenance of rules
> which will never be used.

If we want to add this extra check, probably better to do it in setup_lpm().
Where we already check that port is enabled, and If not, then this route rule 
will be skipped:

        /* populate the LPM table */
        for (i = 0; i < route_num_v4; i++) {
                struct in_addr in;

                /* skip unused ports */
                if ((1 << route_base_v4[i].if_out &
                                enabled_port_mask) == 0)
                        continue;

Same for EM.
Another question here - why we just silently skip the rule with invalid port?
Probably need to fail with error... that what ACL code-path does.

> Fixes: e7e6dd643092 ("examples/l3fwd: support config file for EM")
> Fixes: 52def963fc1c ("examples/l3fwd: support config file for LPM/FIB")
> Cc: sean.morris...@intel.com
> Cc: sta...@dpdk.org
> 
> Signed-off-by: Gagandeep Singh <g.si...@nxp.com>
> ---
>  examples/l3fwd/em_route_parse.c  | 6 ++++--
>  examples/l3fwd/lpm_route_parse.c | 6 ++++--
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/examples/l3fwd/em_route_parse.c b/examples/l3fwd/em_route_parse.c
> index 8b534de5f1..65c71cd1ba 100644
> --- a/examples/l3fwd/em_route_parse.c
> +++ b/examples/l3fwd/em_route_parse.c
> @@ -65,7 +65,8 @@ em_parse_v6_rule(char *str, struct em_rule *v)
>       /* protocol. */
>       GET_CB_FIELD(in[CB_FLD_PROTO], v->v6_key.proto, 0, UINT8_MAX, 0);
>       /* out interface. */
> -     GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> +     GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> +                     (sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> 
>       return 0;
>  }
> @@ -102,7 +103,8 @@ em_parse_v4_rule(char *str, struct em_rule *v)
>       /* protocol. */
>       GET_CB_FIELD(in[CB_FLD_PROTO], v->v4_key.proto, 0, UINT8_MAX, 0);
>       /* out interface. */
> -     GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> +     GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> +                     (sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> 
>       return 0;
>  }
> diff --git a/examples/l3fwd/lpm_route_parse.c 
> b/examples/l3fwd/lpm_route_parse.c
> index f27b66e838..357c12d9fe 100644
> --- a/examples/l3fwd/lpm_route_parse.c
> +++ b/examples/l3fwd/lpm_route_parse.c
> @@ -110,7 +110,8 @@ lpm_parse_v6_rule(char *str, struct lpm_route_rule *v)
> 
>       rc = lpm_parse_v6_net(in[CB_FLD_DST_ADDR], v->ip_32, &v->depth);
> 
> -     GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> +     GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> +                     (sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> 
>       return rc;
>  }
> @@ -132,7 +133,8 @@ lpm_parse_v4_rule(char *str, struct lpm_route_rule *v)
> 
>       rc = parse_ipv4_addr_mask(in[CB_FLD_DST_ADDR], &v->ip, &v->depth);
> 
> -     GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0, UINT8_MAX, 0);
> +     GET_CB_FIELD(in[CB_FLD_IF_OUT], v->if_out, 0,
> +                     (sizeof(enabled_port_mask) * CHAR_BIT) - 1, 0);
> 
>       return rc;
>  }
> --
> 2.25.1

Reply via email to