2 * Copyright (c) 2008, 2009, 2010 Nicira Networks.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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".
26 * Netlink is not suitable for use in physical networks of heterogeneous
27 * machines because host byte order is used throughout. */
37 /* Netlink sockets. */
39 int nl_sock_create(int protocol, int multicast_group,
40 size_t so_sndbuf, size_t so_rcvbuf,
42 void nl_sock_destroy(struct nl_sock *);
44 int nl_sock_send(struct nl_sock *, const struct ofpbuf *, bool wait);
45 int nl_sock_sendv(struct nl_sock *sock, const struct iovec iov[], size_t n_iov,
47 int nl_sock_recv(struct nl_sock *, struct ofpbuf **, bool wait);
48 int nl_sock_transact(struct nl_sock *, const struct ofpbuf *request,
49 struct ofpbuf **reply);
51 void nl_sock_wait(const struct nl_sock *, short int events);
55 struct nl_sock *sock; /* Socket being dumped. */
56 uint32_t seq; /* Expected nlmsg_seq for replies. */
57 struct ofpbuf *buffer; /* Receive buffer currently being iterated. */
58 int status; /* 0=OK, EOF=done, or positive errno value. */
61 void nl_dump_start(struct nl_dump *, struct nl_sock *,
62 const struct ofpbuf *request);
63 bool nl_dump_next(struct nl_dump *, struct ofpbuf *reply);
64 int nl_dump_done(struct nl_dump *);
66 /* Netlink messages. */
68 /* Accessing headers and data. */
69 struct nlmsghdr *nl_msg_nlmsghdr(const struct ofpbuf *);
70 struct genlmsghdr *nl_msg_genlmsghdr(const struct ofpbuf *);
71 bool nl_msg_nlmsgerr(const struct ofpbuf *, int *error);
72 void nl_msg_reserve(struct ofpbuf *, size_t);
74 /* Appending headers and raw data. */
75 void nl_msg_put_nlmsghdr(struct ofpbuf *, size_t expected_payload,
76 uint32_t type, uint32_t flags);
77 void nl_msg_put_genlmsghdr(struct ofpbuf *, size_t expected_payload,
78 int family, uint32_t flags,
79 uint8_t cmd, uint8_t version);
80 void nl_msg_put(struct ofpbuf *, const void *, size_t);
81 void *nl_msg_put_uninit(struct ofpbuf *, size_t);
83 /* Appending attributes. */
84 void *nl_msg_put_unspec_uninit(struct ofpbuf *, uint16_t type, size_t);
85 void nl_msg_put_unspec(struct ofpbuf *, uint16_t type, const void *, size_t);
86 void nl_msg_put_flag(struct ofpbuf *, uint16_t type);
87 void nl_msg_put_u8(struct ofpbuf *, uint16_t type, uint8_t value);
88 void nl_msg_put_u16(struct ofpbuf *, uint16_t type, uint16_t value);
89 void nl_msg_put_u32(struct ofpbuf *, uint16_t type, uint32_t value);
90 void nl_msg_put_u64(struct ofpbuf *, uint16_t type, uint64_t value);
91 void nl_msg_put_string(struct ofpbuf *, uint16_t type, const char *value);
93 size_t nl_msg_start_nested(struct ofpbuf *, uint16_t type);
94 void nl_msg_end_nested(struct ofpbuf *, size_t offset);
95 void nl_msg_put_nested(struct ofpbuf *, uint16_t type,
96 const void *data, size_t size);
98 /* Separating buffers into individual messages. */
99 struct nlmsghdr *nl_msg_next(struct ofpbuf *buffer, struct ofpbuf *msg);
101 /* Netlink attribute types. */
116 /* Netlink attribute parsing. */
117 const void *nl_attr_get(const struct nlattr *);
118 size_t nl_attr_get_size(const struct nlattr *);
119 const void *nl_attr_get_unspec(const struct nlattr *, size_t size);
120 bool nl_attr_get_flag(const struct nlattr *);
121 uint8_t nl_attr_get_u8(const struct nlattr *);
122 uint16_t nl_attr_get_u16(const struct nlattr *);
123 uint32_t nl_attr_get_u32(const struct nlattr *);
124 uint64_t nl_attr_get_u64(const struct nlattr *);
125 const char *nl_attr_get_string(const struct nlattr *);
126 void nl_attr_get_nested(const struct nlattr *, struct ofpbuf *);
128 /* Netlink attribute policy.
130 * Specifies how to parse a single attribute from a Netlink message payload.
134 enum nl_attr_type type;
135 size_t min_len, max_len;
139 bool nl_policy_parse(const struct ofpbuf *, size_t offset,
140 const struct nl_policy[],
141 struct nlattr *[], size_t n_attrs);
142 bool nl_parse_nested(const struct nlattr *, const struct nl_policy[],
143 struct nlattr *[], size_t n_attrs);
147 int nl_lookup_genl_family(const char *name, int *number);
149 #endif /* netlink.h */