1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
4 * We are making the OpenFlow specification and associated documentation
5 * (Software) available for public use and benefit with the expectation
6 * that others will use, modify and enhance the Software and contribute
7 * those enhancements back to the community. However, since we would
8 * like to make the Software available for broadest use, with as few
9 * restrictions as possible permission is hereby granted, free of
10 * charge, to any person obtaining a copy of this Software to deal in
11 * the Software under the copyrights without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * The name and trademarks of copyright holder(s) may NOT be used in
30 * advertising or publicity pertaining to the Software or any
31 * derivatives without specific, written prior permission.
39 * Netlink is a datagram-based network protocol primarily for communication
40 * between user processes and the kernel, and mainly on Linux. Netlink is
41 * specified in RFC 3549, "Linux Netlink as an IP Services Protocol".
43 * Netlink is not suitable for use in physical networks of heterogeneous
44 * machines because host byte order is used throughout. */
54 /* Netlink sockets. */
56 int nl_sock_create(int protocol, int multicast_group,
57 size_t so_sndbuf, size_t so_rcvbuf,
59 void nl_sock_destroy(struct nl_sock *);
61 int nl_sock_send(struct nl_sock *, const struct ofpbuf *, bool wait);
62 int nl_sock_sendv(struct nl_sock *sock, const struct iovec iov[], size_t n_iov,
64 int nl_sock_recv(struct nl_sock *, struct ofpbuf **, bool wait);
65 int nl_sock_transact(struct nl_sock *, const struct ofpbuf *request,
66 struct ofpbuf **reply);
68 int nl_sock_fd(const struct nl_sock *);
70 /* Netlink messages. */
72 /* Accessing headers and data. */
73 struct nlmsghdr *nl_msg_nlmsghdr(const struct ofpbuf *);
74 struct genlmsghdr *nl_msg_genlmsghdr(const struct ofpbuf *);
75 bool nl_msg_nlmsgerr(const struct ofpbuf *, int *error);
76 void nl_msg_reserve(struct ofpbuf *, size_t);
78 /* Appending headers and raw data. */
79 void nl_msg_put_nlmsghdr(struct ofpbuf *, struct nl_sock *,
80 size_t expected_payload,
81 uint32_t type, uint32_t flags);
82 void nl_msg_put_genlmsghdr(struct ofpbuf *, struct nl_sock *,
83 size_t expected_payload, int family, uint32_t flags,
84 uint8_t cmd, uint8_t version);
85 void nl_msg_put(struct ofpbuf *, const void *, size_t);
86 void *nl_msg_put_uninit(struct ofpbuf *, size_t);
88 /* Appending attributes. */
89 void *nl_msg_put_unspec_uninit(struct ofpbuf *, uint16_t type, size_t);
90 void nl_msg_put_unspec(struct ofpbuf *, uint16_t type, const void *, size_t);
91 void nl_msg_put_flag(struct ofpbuf *, uint16_t type);
92 void nl_msg_put_u8(struct ofpbuf *, uint16_t type, uint8_t value);
93 void nl_msg_put_u16(struct ofpbuf *, uint16_t type, uint16_t value);
94 void nl_msg_put_u32(struct ofpbuf *, uint16_t type, uint32_t value);
95 void nl_msg_put_u64(struct ofpbuf *, uint16_t type, uint64_t value);
96 void nl_msg_put_string(struct ofpbuf *, uint16_t type, const char *value);
97 void nl_msg_put_nested(struct ofpbuf *, uint16_t type, struct ofpbuf *);
99 /* Netlink attribute types. */
114 /* Netlink attribute parsing. */
115 const void* nl_attr_get(const struct nlattr *);
116 size_t nl_attr_get_size(const struct nlattr *);
117 const void* nl_attr_get_unspec(const struct nlattr *, size_t size);
118 bool nl_attr_get_flag(const struct nlattr *);
119 uint8_t nl_attr_get_u8(const struct nlattr *);
120 uint16_t nl_attr_get_u16(const struct nlattr *);
121 uint32_t nl_attr_get_u32(const struct nlattr *);
122 uint64_t nl_attr_get_u64(const struct nlattr *);
123 const char *nl_attr_get_string(const struct nlattr *);
125 /* Netlink attribute policy.
127 * Specifies how to parse a single attribute from a Netlink message payload.
129 * See Nl_policy for example.
133 enum nl_attr_type type;
134 size_t min_len, max_len;
138 bool nl_policy_parse(const struct ofpbuf *, const struct nl_policy[],
139 struct nlattr *[], size_t n_attrs);
143 int nl_lookup_genl_family(const char *name, int *number);
145 #endif /* netlink.h */