Support defining the default callback handler with an environment variable
This commit is contained in:
parent
3c56ed5787
commit
680c54fd46
2 changed files with 22 additions and 30 deletions
22
lib/socket.c
22
lib/socket.c
|
@ -96,6 +96,26 @@
|
|||
#include <netlink/msg.h>
|
||||
#include <netlink/attr.h>
|
||||
|
||||
static int default_cb = NL_CB_DEFAULT;
|
||||
|
||||
static void __init init_default_cb(void)
|
||||
{
|
||||
char *nlcb;
|
||||
|
||||
if ((nlcb = getenv("NLCB"))) {
|
||||
if (!strcasecmp(nlcb, "default"))
|
||||
default_cb = NL_CB_DEFAULT;
|
||||
else if (!strcasecmp(nlcb, "verbose"))
|
||||
default_cb = NL_CB_VERBOSE;
|
||||
else if (!strcasecmp(nlcb, "debug"))
|
||||
default_cb = NL_CB_DEBUG;
|
||||
else {
|
||||
fprintf(stderr, "Unknown value for NLCB, valid values: "
|
||||
"{default | verbose | debug}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t used_ports_map[32];
|
||||
|
||||
static uint32_t generate_local_port(void)
|
||||
|
@ -175,7 +195,7 @@ struct nl_handle *nl_handle_alloc(void)
|
|||
{
|
||||
struct nl_cb *cb;
|
||||
|
||||
cb = nl_cb_alloc(NL_CB_DEFAULT);
|
||||
cb = nl_cb_alloc(default_cb);
|
||||
if (!cb) {
|
||||
nl_errno(ENOMEM);
|
||||
return NULL;
|
||||
|
|
30
src/utils.c
30
src/utils.c
|
@ -13,37 +13,9 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
static struct nl_cb *nltool_cb;
|
||||
|
||||
int nltool_init(int argc, char *argv[])
|
||||
{
|
||||
char *nlcb = getenv("NLCB");
|
||||
int cbset = NL_CB_VERBOSE;
|
||||
|
||||
if (nlcb) {
|
||||
if (!strcasecmp(nlcb, "default"))
|
||||
cbset = NL_CB_DEFAULT;
|
||||
else if (!strcasecmp(nlcb, "verbose"))
|
||||
cbset = NL_CB_VERBOSE;
|
||||
else if (!strcasecmp(nlcb, "debug"))
|
||||
cbset = NL_CB_DEBUG;
|
||||
else {
|
||||
fprintf(stderr, "Unknown value for NLCB, valid values: "
|
||||
"{default | verbose | debug}\n");
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
|
||||
nltool_cb = nl_cb_alloc(cbset);
|
||||
if (nltool_cb == NULL) {
|
||||
fprintf(stderr, "Cannot allocate callback handle\n");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
errout:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int nltool_connect(struct nl_handle *nlh, int protocol)
|
||||
|
@ -60,7 +32,7 @@ int nltool_connect(struct nl_handle *nlh, int protocol)
|
|||
|
||||
struct nl_handle *nltool_alloc_handle(void)
|
||||
{
|
||||
return nl_handle_alloc_cb(nltool_cb);
|
||||
return nl_handle_alloc();
|
||||
}
|
||||
|
||||
struct nl_addr *nltool_addr_parse(const char *str)
|
||||
|
|
Loading…
Add table
Reference in a new issue