| 104 | } |
| 105 | |
| 106 | static int |
| 107 | l2fwd_parse_port_pair_config(const char *q_arg, struct l2fwd_resources *rsrc) |
| 108 | { |
| 109 | enum fieldnames { |
| 110 | FLD_PORT1 = 0, |
| 111 | FLD_PORT2, |
| 112 | _NUM_FLD |
| 113 | }; |
| 114 | const char *p, *p0 = q_arg; |
| 115 | uint16_t int_fld[_NUM_FLD]; |
| 116 | char *str_fld[_NUM_FLD]; |
| 117 | uint16_t port_pair = 0; |
| 118 | unsigned int size; |
| 119 | char s[256]; |
| 120 | char *end; |
| 121 | int i; |
| 122 | |
| 123 | while ((p = strchr(p0, '(')) != NULL) { |
| 124 | ++p; |
| 125 | p0 = strchr(p, ')'); |
| 126 | if (p0 == NULL) |
| 127 | return -1; |
| 128 | |
| 129 | size = p0 - p; |
| 130 | if (size >= sizeof(s)) |
| 131 | return -1; |
| 132 | |
| 133 | memcpy(s, p, size); |
| 134 | if (rte_strsplit(s, sizeof(s), str_fld, |
| 135 | _NUM_FLD, ',') != _NUM_FLD) |
| 136 | return -1; |
| 137 | |
| 138 | for (i = 0; i < _NUM_FLD; i++) { |
| 139 | errno = 0; |
| 140 | int_fld[i] = strtoul(str_fld[i], &end, 0); |
| 141 | if (errno != 0 || end == str_fld[i] || |
| 142 | int_fld[i] >= RTE_MAX_ETHPORTS) |
| 143 | return -1; |
| 144 | } |
| 145 | |
| 146 | if (port_pair >= RTE_MAX_ETHPORTS / 2) { |
| 147 | printf("exceeded max number of port pair params: Current %d Max = %d\n", |
| 148 | port_pair, RTE_MAX_ETHPORTS / 2); |
| 149 | return -1; |
| 150 | } |
| 151 | |
| 152 | if ((rsrc->dst_ports[int_fld[FLD_PORT1]] != UINT32_MAX) || |
| 153 | (rsrc->dst_ports[int_fld[FLD_PORT2]] != UINT32_MAX)) { |
| 154 | printf("Duplicate port pair (%d,%d) config\n", |
| 155 | int_fld[FLD_PORT1], int_fld[FLD_PORT2]); |
| 156 | return -1; |
| 157 | } |
| 158 | |
| 159 | rsrc->dst_ports[int_fld[FLD_PORT1]] = int_fld[FLD_PORT2]; |
| 160 | rsrc->dst_ports[int_fld[FLD_PORT2]] = int_fld[FLD_PORT1]; |
| 161 | |
| 162 | port_pair++; |
| 163 | } |
no test coverage detected