-void
-lnet_print_range_exprs(cfs_list_t *exprs)
-{
- cfs_list_t *e;
- lnet_range_expr_t *lre;
-
- cfs_list_for_each(e, exprs) {
- lre = cfs_list_entry(exprs->next, lnet_range_expr_t, lre_list);
-
- CDEBUG(D_WARNING, "%d-%d/%d\n",
- lre->lre_min, lre->lre_max, lre->lre_stride);
- }
-
- CDEBUG(D_WARNING, "%d allocated\n", lnet_re_alloc);
-}
-
-int
-lnet_new_range_expr(cfs_list_t *exprs, int min, int max, int stride)
-{
- lnet_range_expr_t *lre;
-
- CDEBUG(D_NET, "%d-%d/%d\n", min, max, stride);
-
- if (min < 0 || min > 255 || min > max || stride < 0)
- return -EINVAL;
-
- LIBCFS_ALLOC(lre, sizeof(*lre));
- if (lre == NULL)
- return -ENOMEM;
-
- lnet_re_alloc++;
-
- lre->lre_min = min;
- lre->lre_max = max;
- lre->lre_stride = stride;
-
- cfs_list_add(&lre->lre_list, exprs);
- return 0;
-}
-
-void
-lnet_destroy_range_exprs(cfs_list_t *exprs)
-{
- lnet_range_expr_t *lre;
-
- while (!cfs_list_empty(exprs)) {
- lre = cfs_list_entry(exprs->next, lnet_range_expr_t, lre_list);
-
- cfs_list_del(&lre->lre_list);
- LIBCFS_FREE(lre, sizeof(*lre));
- lnet_re_alloc--;
- }
-}
-
-int
-lnet_parse_range_expr(cfs_list_t *exprs, char *str)
-{
- int nob = strlen(str);
- char *sep;
- int n;
- int x;
- int y;
- int z;
- int rc;
-
- if (nob == 0)
- return -EINVAL;
-
- if (!strcmp(str, "*")) /* match all */
- return lnet_new_range_expr(exprs, 0, 255, 1);
-
- n = nob;
- if (sscanf(str, "%u%n", &x, &n) >= 1 && n == nob) {
- /* simple number */
- return lnet_new_range_expr(exprs, x, x, 1);
- }
-
- /* Has to be an expansion */
- if (!(str[0] == '[' && nob > 2 && str[nob-1] == ']'))
- return -EINVAL;
-
- nob -= 2;
- str++;
- str[nob] = 0;
-
- do {
- /* Comma separated list of expressions... */
- sep = strchr(str, ',');
- if (sep != NULL)
- *sep++ = 0;
-
- nob = strlen(str);
- n = nob;
- if (sscanf(str, "%u%n", &x, &n) >= 1 && n == nob) {
- /* simple number */
- rc = lnet_new_range_expr(exprs, x, x, 1);
- if (rc != 0)
- return rc;
-
- continue;
- }
-
- n = nob;
- if (sscanf(str, "%u-%u%n", &x, &y, &n) >= 2 && n == nob) {
- /* simple range */
- rc = lnet_new_range_expr(exprs, x, y, 1);
- if (rc != 0)
- return rc;
- continue;
- }
-
- n = nob;
- if (sscanf(str, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob) {
- /* strided range */
- rc = lnet_new_range_expr(exprs, x, y, z);
- if (rc != 0)
- return rc;
- continue;
- }
-
- return -EINVAL;
-
- } while ((str = sep) != NULL);
-
- return 0;
-}
-