]>
git.proxmox.com Git - mirror_ovs.git/blob - lib/netlink.h
2 * Copyright (c) 2008, 2009 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
);
53 /* Netlink messages. */
55 /* Accessing headers and data. */
56 struct nlmsghdr
*nl_msg_nlmsghdr(const struct ofpbuf
*);
57 struct genlmsghdr
*nl_msg_genlmsghdr(const struct ofpbuf
*);
58 bool nl_msg_nlmsgerr(const struct ofpbuf
*, int *error
);
59 void nl_msg_reserve(struct ofpbuf
*, size_t);
61 /* Appending headers and raw data. */
62 void nl_msg_put_nlmsghdr(struct ofpbuf
*, struct nl_sock
*,
63 size_t expected_payload
,
64 uint32_t type
, uint32_t flags
);
65 void nl_msg_put_genlmsghdr(struct ofpbuf
*, struct nl_sock
*,
66 size_t expected_payload
, int family
, uint32_t flags
,
67 uint8_t cmd
, uint8_t version
);
68 void nl_msg_put(struct ofpbuf
*, const void *, size_t);
69 void *nl_msg_put_uninit(struct ofpbuf
*, size_t);
71 /* Appending attributes. */
72 void *nl_msg_put_unspec_uninit(struct ofpbuf
*, uint16_t type
, size_t);
73 void nl_msg_put_unspec(struct ofpbuf
*, uint16_t type
, const void *, size_t);
74 void nl_msg_put_flag(struct ofpbuf
*, uint16_t type
);
75 void nl_msg_put_u8(struct ofpbuf
*, uint16_t type
, uint8_t value
);
76 void nl_msg_put_u16(struct ofpbuf
*, uint16_t type
, uint16_t value
);
77 void nl_msg_put_u32(struct ofpbuf
*, uint16_t type
, uint32_t value
);
78 void nl_msg_put_u64(struct ofpbuf
*, uint16_t type
, uint64_t value
);
79 void nl_msg_put_string(struct ofpbuf
*, uint16_t type
, const char *value
);
80 void nl_msg_put_nested(struct ofpbuf
*, uint16_t type
, struct ofpbuf
*);
82 /* Netlink attribute types. */
97 /* Netlink attribute parsing. */
98 const void *nl_attr_get(const struct nlattr
*);
99 size_t nl_attr_get_size(const struct nlattr
*);
100 const void *nl_attr_get_unspec(const struct nlattr
*, size_t size
);
101 bool nl_attr_get_flag(const struct nlattr
*);
102 uint8_t nl_attr_get_u8(const struct nlattr
*);
103 uint16_t nl_attr_get_u16(const struct nlattr
*);
104 uint32_t nl_attr_get_u32(const struct nlattr
*);
105 uint64_t nl_attr_get_u64(const struct nlattr
*);
106 const char *nl_attr_get_string(const struct nlattr
*);
108 /* Netlink attribute policy.
110 * Specifies how to parse a single attribute from a Netlink message payload.
114 enum nl_attr_type type
;
115 size_t min_len
, max_len
;
119 bool nl_policy_parse(const struct ofpbuf
*, size_t offset
,
120 const struct nl_policy
[],
121 struct nlattr
*[], size_t n_attrs
);
125 int nl_lookup_genl_family(const char *name
, int *number
);
127 #endif /* netlink.h */