]> git.proxmox.com Git - mirror_iproute2.git/blame - lib/mnl_utils.c
lib: Extract from devlink/mnlg a helper, mnlu_socket_open()
[mirror_iproute2.git] / lib / mnl_utils.c
CommitLineData
72858c7b
PM
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * mnl_utils.c Helpers for working with libmnl.
4 */
5
6#include <libmnl/libmnl.h>
7
8#include "mnl_utils.h"
9
10struct mnl_socket *mnlu_socket_open(int bus)
11{
12 struct mnl_socket *nl;
13 int one = 1;
14
15 nl = mnl_socket_open(bus);
16 if (nl == NULL)
17 return NULL;
18
19 mnl_socket_setsockopt(nl, NETLINK_CAP_ACK, &one, sizeof(one));
20 mnl_socket_setsockopt(nl, NETLINK_EXT_ACK, &one, sizeof(one));
21
22 if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0)
23 goto err_bind;
24
25 return nl;
26
27err_bind:
28 mnl_socket_close(nl);
29 return NULL;
30}