1 /*
2 * Copyright (c) 2014, Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2017 Amazon.com, Inc. or its affiliates.
4 * All Rights reserved.
5 *
6 * Portions of this software copied from libfabric
7 * (https://github.com/ofiwg/libfabric)
8 *
9 * LICENSE_BEGIN
10 *
11 * BSD license:
12 *
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer.
20 *
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 *
39 * LICENSE_END
40 */
41
42 #ifndef LIBNL3_UTILS_H
43 #define LIBNL3_UTILS_H
44
45 #include <linux/netlink.h>
46 #include <linux/rtnetlink.h>
47 #include <netlink/netlink.h>
48 #include <netlink/route/rtnl.h>
49 #include <netlink/route/route.h>
50
51 typedef struct nl_sock NL_HANDLE;
52
53 #define NLMSG_SIZE(size) nlmsg_size(size)
54 #define NL_GETERROR(err) nl_geterror(err)
55 #define NL_HANDLE_ALLOC nl_socket_alloc
56 #define NL_HANDLE_FREE nl_socket_free
57 #define NL_DISABLE_SEQ_CHECK nl_socket_disable_seq_check
58 #define INC_CB_MSGCNT(arg)
59
60 /* err will be returned as -NLE_AGAIN */
61 /* if the socket times out */
62 #define NL_RECVMSGS(nlh, cb_arg, rc, err, out) \
63 do { \
64 err = nl_recvmsgs_default(nlh); \
65 if (err < 0) { \
66 opal_output(0, "Failed to receive netlink reply message, error %s\n", \
67 NL_GETERROR(err)); \
68 if (err == -NLE_AGAIN) \
69 err = rc; \
70 goto out; \
71 } \
72 } while (0)
73
74 struct opal_reachable_netlink_rt_cb_arg {
75 int oif;
76 int found;
77 int has_gateway;
78 int replied;
79 struct opal_reachable_netlink_sk *unlsk;
80 };
81
82 #endif /* LIBNL3_UTILS_H */