aboutsummaryrefslogtreecommitdiffstats
path: root/lib/librte_eal/common/rte_option.c
blob: 02d59a869542ab3c33ca84ffff2604ae58290a1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2018 Intel Corporation.
 */

#include <unistd.h>
#include <string.h>

#include <rte_eal.h>
#include <rte_option.h>

#include "eal_private.h"

TAILQ_HEAD(rte_option_list, rte_option);

struct rte_option_list rte_option_list =
	TAILQ_HEAD_INITIALIZER(rte_option_list);

static struct rte_option *option;

int
rte_option_parse(const char *opt)
{
	/* Check if the option is registered */
	TAILQ_FOREACH(option, &rte_option_list, next) {
		if (strcmp(opt, option->opt_str) == 0) {
			option->enabled = 1;
			return 0;
		}
	}

	return -1;
}

void __rte_experimental
rte_option_register(struct rte_option *opt)
{
	TAILQ_FOREACH(option, &rte_option_list, next) {
		if (strcmp(opt->opt_str, option->opt_str) == 0)
			RTE_LOG(INFO, EAL, "Option %s has already been registered.",
					opt->opt_str);
			return;
	}

	TAILQ_INSERT_HEAD(&rte_option_list, opt, next);
}

void
rte_option_init(void)
{
	TAILQ_FOREACH(option, &rte_option_list, next) {
		if (option->enabled)
			option->cb();
	}
}