1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright (c) 2010, Keith Wiles <keith.wiles@windriver.com>
15 #include <rte_string_fns.h>
16 #include "cmdline_parse.h"
17 #include "cmdline_parse_portlist.h"
19 struct cmdline_token_ops cmdline_token_portlist_ops
= {
20 .parse
= cmdline_parse_portlist
,
21 .complete_get_nb
= NULL
,
22 .complete_get_elt
= NULL
,
23 .get_help
= cmdline_get_help_portlist
,
27 parse_set_list(cmdline_portlist_t
*pl
, size_t low
, size_t high
)
30 pl
->map
|= (1 << low
++);
31 } while (low
<= high
);
35 parse_ports(cmdline_portlist_t
*pl
, const char *str
)
38 const char *first
, *last
;
41 for (first
= str
, last
= first
;
42 first
!= NULL
&& last
!= NULL
;
45 last
= strchr(first
, ',');
48 ps
= strtoul(first
, &end
, 10);
49 if (errno
!= 0 || end
== first
||
50 (end
[0] != '-' && end
[0] != 0 && end
!= last
))
53 /* Support for N-M portlist format */
57 pe
= strtoul(first
, &end
, 10);
58 if (errno
!= 0 || end
== first
||
59 (end
[0] != 0 && end
!= last
))
65 if (ps
> pe
|| pe
>= sizeof (pl
->map
) * 8)
68 parse_set_list(pl
, ps
, pe
);
75 cmdline_parse_portlist(__rte_unused cmdline_parse_token_hdr_t
*tk
,
76 const char *buf
, void *res
, unsigned ressize
)
78 unsigned int token_len
= 0;
79 char portlist_str
[PORTLIST_TOKEN_SIZE
+1];
80 cmdline_portlist_t
*pl
;
85 if (res
&& ressize
< sizeof(cmdline_portlist_t
))
90 while (!cmdline_isendoftoken(buf
[token_len
]) &&
91 (token_len
< PORTLIST_TOKEN_SIZE
))
94 if (token_len
>= PORTLIST_TOKEN_SIZE
)
97 strlcpy(portlist_str
, buf
, token_len
+ 1);
101 if (strcmp("all", portlist_str
) == 0)
102 pl
->map
= UINT32_MAX
;
103 else if (parse_ports(pl
, portlist_str
) != 0)
111 cmdline_get_help_portlist(__rte_unused cmdline_parse_token_hdr_t
*tk
,
112 char *dstbuf
, unsigned int size
)
115 ret
= snprintf(dstbuf
, size
, "range of ports as 3,4-6,8-19,20");