mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-10-06 08:45:57 +00:00

This little dance of mnl_socket_open(), option setting, and bind, is the same regardless of tool. Extract into a new module that should hold helpers for working with libmnl, mnl_util.c. Signed-off-by: Petr Machata <me@pmachata.org> Signed-off-by: David Ahern <dsahern@gmail.com>
31 lines
554 B
C
31 lines
554 B
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* mnl_utils.c Helpers for working with libmnl.
|
|
*/
|
|
|
|
#include <libmnl/libmnl.h>
|
|
|
|
#include "mnl_utils.h"
|
|
|
|
struct mnl_socket *mnlu_socket_open(int bus)
|
|
{
|
|
struct mnl_socket *nl;
|
|
int one = 1;
|
|
|
|
nl = mnl_socket_open(bus);
|
|
if (nl == NULL)
|
|
return NULL;
|
|
|
|
mnl_socket_setsockopt(nl, NETLINK_CAP_ACK, &one, sizeof(one));
|
|
mnl_socket_setsockopt(nl, NETLINK_EXT_ACK, &one, sizeof(one));
|
|
|
|
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0)
|
|
goto err_bind;
|
|
|
|
return nl;
|
|
|
|
err_bind:
|
|
mnl_socket_close(nl);
|
|
return NULL;
|
|
}
|