]> git.proxmox.com Git - mirror_ovs.git/blob - lib/netlink-socket.h
9d288bdd1fee15006e19e8500bb3550509a96e48
[mirror_ovs.git] / lib / netlink-socket.h
1 /*
2 * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef NETLINK_SOCKET_H
18 #define NETLINK_SOCKET_H 1
19
20 /* Netlink socket definitions.
21 *
22 * Netlink is a datagram-based network protocol primarily for communication
23 * between user processes and the kernel, and mainly on Linux. Netlink is
24 * specified in RFC 3549, "Linux Netlink as an IP Services Protocol".
25 *
26 * Netlink is not suitable for use in physical networks of heterogeneous
27 * machines because host byte order is used throughout.
28 *
29 * This header file defines functions for working with Netlink sockets, which
30 * are Linux-specific. For Netlink protocol definitions, see
31 * netlink-protocol.h. For helper functions for working with Netlink messages,
32 * see netlink.h.
33 */
34
35 #include <stdbool.h>
36 #include <stddef.h>
37 #include <stdint.h>
38
39 struct ofpbuf;
40 struct nl_sock;
41
42 #ifndef HAVE_NETLINK
43 #error "netlink-socket.h is only for hosts that support Netlink sockets"
44 #endif
45
46 /* Netlink sockets. */
47 int nl_sock_create(int protocol, struct nl_sock **);
48 int nl_sock_clone(const struct nl_sock *, struct nl_sock **);
49 void nl_sock_destroy(struct nl_sock *);
50
51 int nl_sock_join_mcgroup(struct nl_sock *, unsigned int multicast_group);
52 int nl_sock_leave_mcgroup(struct nl_sock *, unsigned int multicast_group);
53
54 int nl_sock_send(struct nl_sock *, const struct ofpbuf *, bool wait);
55 int nl_sock_recv(struct nl_sock *, struct ofpbuf **, bool wait);
56 int nl_sock_transact(struct nl_sock *, const struct ofpbuf *request,
57 struct ofpbuf **reply);
58
59 int nl_sock_drain(struct nl_sock *);
60
61 void nl_sock_wait(const struct nl_sock *, short int events);
62 int nl_sock_fd(const struct nl_sock *);
63
64 uint32_t nl_sock_pid(const struct nl_sock *);
65
66 /* Batching transactions. */
67 struct nl_transaction {
68 /* Filled in by client. */
69 struct ofpbuf *request; /* Request to send. */
70
71 /* Filled in by nl_sock_transact_batch(). */
72 struct ofpbuf *reply; /* Reply (NULL if reply was an error code). */
73 int error; /* Positive errno value, 0 if no error. */
74 };
75
76 void nl_sock_transact_multiple(struct nl_sock *,
77 struct nl_transaction **, size_t n);
78
79 /* Table dumping. */
80 struct nl_dump {
81 struct nl_sock *sock; /* Socket being dumped. */
82 uint32_t seq; /* Expected nlmsg_seq for replies. */
83 struct ofpbuf *buffer; /* Receive buffer currently being iterated. */
84 int status; /* 0=OK, EOF=done, or positive errno value. */
85 };
86
87 void nl_dump_start(struct nl_dump *, struct nl_sock *,
88 const struct ofpbuf *request);
89 bool nl_dump_next(struct nl_dump *, struct ofpbuf *reply);
90 int nl_dump_done(struct nl_dump *);
91
92 /* Miscellaneous */
93 int nl_lookup_genl_family(const char *name, int *number);
94 int nl_lookup_genl_mcgroup(const char *family_name, const char *group_name,
95 unsigned int *multicast_group,
96 unsigned int fallback);
97
98 #endif /* netlink-socket.h */