[dpdk-dev,v2] examples/ip_pipeline: check VLAN and MPLS params

Message ID 1483912549-170299-1-git-send-email-anand.b.jyoti@intel.com (mailing list archive)
State Accepted, archived
Headers

Checks

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

Commit Message

Jyoti, Anand B Jan. 8, 2017, 9:55 p.m. UTC
  This commit add to CLI command check for the following errors
1. SVLAN and CVLAN IDs greater than 12 bits
2. MPLS ID greater than 20 bits
3. max number of supported MPLS labels to avoid array overflow

It prevents running CLI commands with invalid parameters.

Signed-off-by: Anand B Jyoti <anand.b.jyoti@intel.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 examples/ip_pipeline/pipeline/pipeline_routing.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
  

Comments

Thomas Monjalon Jan. 17, 2017, 5:27 p.m. UTC | #1
2017-01-09 03:25, Jyoti, Anand B:
> This commit add to CLI command check for the following errors
> 1. SVLAN and CVLAN IDs greater than 12 bits
> 2. MPLS ID greater than 20 bits
> 3. max number of supported MPLS labels to avoid array overflow
> 
> It prevents running CLI commands with invalid parameters.
> 
> Signed-off-by: Anand B Jyoti <anand.b.jyoti@intel.com>
> Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>

Applied, thanks
  

Patch

diff --git a/examples/ip_pipeline/pipeline/pipeline_routing.c b/examples/ip_pipeline/pipeline/pipeline_routing.c
index 3aadbf9..3deaff9 100644
--- a/examples/ip_pipeline/pipeline/pipeline_routing.c
+++ b/examples/ip_pipeline/pipeline/pipeline_routing.c
@@ -494,6 +494,26 @@  app_pipeline_routing_add_route(struct app_params *app,
 		/* data */
 		if (data->port_id >= p->n_ports_out)
 			return -1;
+
+		/* Valid range of VLAN tags 12 bits */
+		if (data->flags & PIPELINE_ROUTING_ROUTE_QINQ)
+			if ((data->l2.qinq.svlan & 0xF000) ||
+					(data->l2.qinq.cvlan & 0xF000))
+				return -1;
+
+		/* Max number of MPLS labels supported */
+		if (data->flags & PIPELINE_ROUTING_ROUTE_MPLS) {
+			uint32_t i;
+
+			if (data->l2.mpls.n_labels >
+					PIPELINE_ROUTING_MPLS_LABELS_MAX)
+				return -1;
+
+			/* Max MPLS label value 20 bits */
+			for (i = 0; i < data->l2.mpls.n_labels; i++)
+				if (data->l2.mpls.labels[i] & 0xFFF00000)
+					return -1;
+		}
 	}
 	break;