+static int
+l2fwd_parse_port_pair_config(const char *q_arg, struct l2fwd_resources *rsrc)
+{
+ enum fieldnames {
+ FLD_PORT1 = 0,
+ FLD_PORT2,
+ _NUM_FLD
+ };
+ const char *p, *p0 = q_arg;
+ uint16_t int_fld[_NUM_FLD];
+ char *str_fld[_NUM_FLD];
+ uint16_t port_pair = 0;
+ unsigned int size;
+ char s[256];
+ char *end;
+ int i;
+
+ while ((p = strchr(p0, '(')) != NULL) {
+ ++p;
+ p0 = strchr(p, ')');
+ if (p0 == NULL)
+ return -1;
+
+ size = p0 - p;
+ if (size >= sizeof(s))
+ return -1;
+
+ memcpy(s, p, size);
+ if (rte_strsplit(s, sizeof(s), str_fld,
+ _NUM_FLD, ',') != _NUM_FLD)
+ return -1;
+
+ for (i = 0; i < _NUM_FLD; i++) {
+ errno = 0;
+ int_fld[i] = strtoul(str_fld[i], &end, 0);
+ if (errno != 0 || end == str_fld[i] ||
+ int_fld[i] >= RTE_MAX_ETHPORTS)
+ return -1;
+ }
+
+ if (port_pair >= RTE_MAX_ETHPORTS / 2) {
+ printf("exceeded max number of port pair params: Current %d Max = %d\n",
+ port_pair, RTE_MAX_ETHPORTS / 2);
+ return -1;
+ }
+
+ if ((rsrc->dst_ports[int_fld[FLD_PORT1]] != UINT32_MAX) ||
+ (rsrc->dst_ports[int_fld[FLD_PORT2]] != UINT32_MAX)) {
+ printf("Duplicate port pair (%d,%d) config\n",
+ int_fld[FLD_PORT1], int_fld[FLD_PORT2]);
+ return -1;
+ }
+
+ rsrc->dst_ports[int_fld[FLD_PORT1]] = int_fld[FLD_PORT2];
+ rsrc->dst_ports[int_fld[FLD_PORT2]] = int_fld[FLD_PORT1];
+
+ port_pair++;
+ }
+
+ rsrc->port_pairs = true;
+
+ return 0;
+}
+