improve error handling in nft_mnl_connect()

This commit is contained in:
Thomas Bernard 2020-06-07 19:57:29 +02:00
parent ed48113355
commit 7245a68e5c
1 changed files with 11 additions and 11 deletions

View File

@ -84,24 +84,24 @@ static uint32_t rule_list_redirect_validate = RULE_CACHE_INVALID;
static uint32_t rule_list_peer_validate = RULE_CACHE_INVALID; static uint32_t rule_list_peer_validate = RULE_CACHE_INVALID;
/*
* return : 0 for OK, -1 for error
*/
int int
nft_mnl_connect(void) nft_mnl_connect(void)
{ {
int result = 0;
mnl_sock = mnl_socket_open(NETLINK_NETFILTER); mnl_sock = mnl_socket_open(NETLINK_NETFILTER);
if (mnl_sock == NULL) { if (mnl_sock == NULL) {
log_error("mnl_socket_open() FAILED: %m"); log_error("mnl_socket_open() FAILED: %m");
result = errno; return -1;
} else {
if (mnl_socket_bind(mnl_sock, 0, MNL_SOCKET_AUTOPID) < 0) {
log_error("mnl_socket_bind() FAILED: %m");
result = errno;
} else {
mnl_portid = mnl_socket_get_portid(mnl_sock);
}
} }
return result; if (mnl_socket_bind(mnl_sock, 0, MNL_SOCKET_AUTOPID) < 0) {
log_error("mnl_socket_bind() FAILED: %m");
return -1;
}
mnl_portid = mnl_socket_get_portid(mnl_sock);
syslog(LOG_INFO, "mnl_socket bound, port_id=%u", mnl_portid);
return 0;
} }
void void