[dpdk-dev,v2] examples/l2fwd: check if user portmask is valid

Message ID 1517511522-16486-1-git-send-email-vipin.varghese@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Varghese, Vipin Feb. 1, 2018, 6:58 p.m. UTC
  User can pass portmask with any value, even invalid mask. The code
checks against actual portmask.

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
---

V2 Changes:
 - correct the spelling in comment - Vipin
---
 examples/l2fwd/main.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

De Lara Guarch, Pablo Feb. 6, 2018, 4:55 p.m. UTC | #1
> -----Original Message-----
> From: Varghese, Vipin
> Sent: Thursday, February 1, 2018 6:59 PM
> To: dev@dpdk.org
> Cc: stable@dpdk.org; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>; Richardson, Bruce
> <bruce.richardson@intel.com>; Varghese, Vipin
> <vipin.varghese@intel.com>
> Subject: [PATCH v2] examples/l2fwd: check if user portmask is valid
> 
> User can pass portmask with any value, even invalid mask. The code checks
> against actual portmask.
> 
> Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> ---
> 
> V2 Changes:
>  - correct the spelling in comment - Vipin

I think there is no need to CC stable here, so I will remove it from the list.

Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
  
Thomas Monjalon Feb. 6, 2018, 5:53 p.m. UTC | #2
> > User can pass portmask with any value, even invalid mask. The code checks
> > against actual portmask.
> > 
> > Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
> > ---
> > 
> > V2 Changes:
> >  - correct the spelling in comment - Vipin
> 
> I think there is no need to CC stable here, so I will remove it from the list.
> 
> Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>

Applied, thanks
  

Patch

diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
index 6c07ed4..e4a4a7c 100644
--- a/examples/l2fwd/main.c
+++ b/examples/l2fwd/main.c
@@ -549,6 +549,11 @@  enum {
 	if (nb_ports == 0)
 		rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
 
+	/* check port mask to possible port mask */
+	if (l2fwd_enabled_port_mask & ~((1 << nb_ports) - 1))
+		rte_exit(EXIT_FAILURE, "Invalid portmask; possible (0x%x)\n",
+			(1 << nb_ports) - 1);
+
 	/* reset l2fwd_dst_ports */
 	for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++)
 		l2fwd_dst_ports[portid] = 0;