summaryrefslogtreecommitdiffstats
path: root/include/libmnl/libmnl.h
diff options
context:
space:
mode:
authorCristian Rodríguez <cristian.rodriguez@opensuse.org>2010-11-15 20:31:25 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2010-11-15 20:31:25 +0100
commit37dac00e2ad6445f496e68fcf815723432ecb5a8 (patch)
tree9c97e3f99a1663970c578ad879903ced82277415 /include/libmnl/libmnl.h
parent485d30a8a89e7500b0df4291fa4dfc33b894998c (diff)
src: implement both GCC visibility support and export script
Read "How to write shared libraries" from Ulrich Drepper for more information on this patch. Specifically section 2.2: Export control and section 3: Maintaining APIs and ABIs. Signed-off-by: Cristian Rodríguez <cristian.rodriguez@opensuse.org> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include/libmnl/libmnl.h')
-rw-r--r--include/libmnl/libmnl.h104
1 files changed, 55 insertions, 49 deletions
diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
index c4806d5..d2fc2d4 100644
--- a/include/libmnl/libmnl.h
+++ b/include/libmnl/libmnl.h
@@ -13,6 +13,12 @@
extern "C" {
#endif
+#if defined(HAVE_VISIBILITY) && defined(BUILDING_MNL)
+#define MNL_API extern __attribute__ ((visibility("default")))
+#else
+#define MNL_API extern
+#endif
+
/*
* Netlink socket API
*/
@@ -22,15 +28,15 @@ extern "C" {
struct mnl_socket;
-extern struct mnl_socket *mnl_socket_open(int type);
-extern int mnl_socket_bind(struct mnl_socket *nl, unsigned int groups, pid_t pid);
-extern int mnl_socket_close(struct mnl_socket *nl);
-extern int mnl_socket_get_fd(const struct mnl_socket *nl);
-extern unsigned int mnl_socket_get_portid(const struct mnl_socket *nl);
-extern int mnl_socket_sendto(const struct mnl_socket *nl, const void *req, size_t siz);
-extern int mnl_socket_recvfrom(const struct mnl_socket *nl, void *buf, size_t siz);
-extern int mnl_socket_setsockopt(const struct mnl_socket *nl, int type, void *buf, socklen_t len);
-extern int mnl_socket_getsockopt(const struct mnl_socket *nl, int type, void *buf, socklen_t *len);
+MNL_API struct mnl_socket *mnl_socket_open(int type);
+MNL_API int mnl_socket_bind(struct mnl_socket *nl, unsigned int groups, pid_t pid);
+MNL_API int mnl_socket_close(struct mnl_socket *nl);
+MNL_API int mnl_socket_get_fd(const struct mnl_socket *nl);
+MNL_API unsigned int mnl_socket_get_portid(const struct mnl_socket *nl);
+MNL_API int mnl_socket_sendto(const struct mnl_socket *nl, const void *req, size_t siz);
+MNL_API int mnl_socket_recvfrom(const struct mnl_socket *nl, void *buf, size_t siz);
+MNL_API int mnl_socket_setsockopt(const struct mnl_socket *nl, int type, void *buf, socklen_t len);
+MNL_API int mnl_socket_getsockopt(const struct mnl_socket *nl, int type, void *buf, socklen_t *len);
/*
* Netlink message API
@@ -40,31 +46,31 @@ extern int mnl_socket_getsockopt(const struct mnl_socket *nl, int type, void *bu
#define MNL_ALIGN(len) (((len)+MNL_ALIGNTO-1) & ~(MNL_ALIGNTO-1))
#define MNL_NLMSG_HDRLEN MNL_ALIGN(sizeof(struct nlmsghdr))
-extern size_t mnl_nlmsg_size(size_t len);
-extern size_t mnl_nlmsg_total_size(size_t len);
-extern size_t mnl_nlmsg_get_payload_len(const struct nlmsghdr *nlh);
+MNL_API size_t mnl_nlmsg_size(size_t len);
+MNL_API size_t mnl_nlmsg_total_size(size_t len);
+MNL_API size_t mnl_nlmsg_get_payload_len(const struct nlmsghdr *nlh);
/* Netlink message header builder */
-extern struct nlmsghdr *mnl_nlmsg_put_header(void *buf);
-extern void *mnl_nlmsg_put_extra_header(struct nlmsghdr *nlh, size_t size);
+MNL_API struct nlmsghdr *mnl_nlmsg_put_header(void *buf);
+MNL_API void *mnl_nlmsg_put_extra_header(struct nlmsghdr *nlh, size_t size);
/* Netlink message iterators */
-extern bool mnl_nlmsg_ok(const struct nlmsghdr *nlh, int len);
-extern struct nlmsghdr *mnl_nlmsg_next(const struct nlmsghdr *nlh, int *len);
+MNL_API bool mnl_nlmsg_ok(const struct nlmsghdr *nlh, int len);
+MNL_API struct nlmsghdr *mnl_nlmsg_next(const struct nlmsghdr *nlh, int *len);
/* Netlink sequence tracking */
-extern bool mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq);
+MNL_API bool mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq);
/* Netlink portID checking */
-extern bool mnl_nlmsg_portid_ok(const struct nlmsghdr *nlh, unsigned int portid);
+MNL_API bool mnl_nlmsg_portid_ok(const struct nlmsghdr *nlh, unsigned int portid);
/* Netlink message getters */
-extern void *mnl_nlmsg_get_payload(const struct nlmsghdr *nlh);
-extern void *mnl_nlmsg_get_payload_offset(const struct nlmsghdr *nlh, size_t offset);
-extern void *mnl_nlmsg_get_payload_tail(const struct nlmsghdr *nlh);
+MNL_API void *mnl_nlmsg_get_payload(const struct nlmsghdr *nlh);
+MNL_API void *mnl_nlmsg_get_payload_offset(const struct nlmsghdr *nlh, size_t offset);
+MNL_API void *mnl_nlmsg_get_payload_tail(const struct nlmsghdr *nlh);
/* Netlink message printer */
-extern void mnl_nlmsg_fprintf(FILE *fd, const void *data, size_t datalen, size_t extra_header_size);
+MNL_API void mnl_nlmsg_fprintf(FILE *fd, const void *data, size_t datalen, size_t extra_header_size);
/*
* Netlink attributes API
@@ -72,31 +78,31 @@ extern void mnl_nlmsg_fprintf(FILE *fd, const void *data, size_t datalen, size_t
#define MNL_ATTR_HDRLEN MNL_ALIGN(sizeof(struct nlattr))
/* TLV attribute getters */
-extern uint16_t mnl_attr_get_type(const struct nlattr *attr);
-extern uint16_t mnl_attr_get_len(const struct nlattr *attr);
-extern uint16_t mnl_attr_get_payload_len(const struct nlattr *attr);
-extern void *mnl_attr_get_payload(const struct nlattr *attr);
-extern uint8_t mnl_attr_get_u8(const struct nlattr *attr);
-extern uint16_t mnl_attr_get_u16(const struct nlattr *attr);
-extern uint32_t mnl_attr_get_u32(const struct nlattr *attr);
-extern uint64_t mnl_attr_get_u64(const struct nlattr *attr);
-extern const char *mnl_attr_get_str(const struct nlattr *attr);
+MNL_API uint16_t mnl_attr_get_type(const struct nlattr *attr);
+MNL_API uint16_t mnl_attr_get_len(const struct nlattr *attr);
+MNL_API uint16_t mnl_attr_get_payload_len(const struct nlattr *attr);
+MNL_API void *mnl_attr_get_payload(const struct nlattr *attr);
+MNL_API uint8_t mnl_attr_get_u8(const struct nlattr *attr);
+MNL_API uint16_t mnl_attr_get_u16(const struct nlattr *attr);
+MNL_API uint32_t mnl_attr_get_u32(const struct nlattr *attr);
+MNL_API uint64_t mnl_attr_get_u64(const struct nlattr *attr);
+MNL_API const char *mnl_attr_get_str(const struct nlattr *attr);
/* TLV attribute putters */
-extern void mnl_attr_put(struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data);
-extern void mnl_attr_put_u8(struct nlmsghdr *nlh, uint16_t type, uint8_t data);
-extern void mnl_attr_put_u16(struct nlmsghdr *nlh, uint16_t type, uint16_t data);
-extern void mnl_attr_put_u32(struct nlmsghdr *nlh, uint16_t type, uint32_t data);
-extern void mnl_attr_put_u64(struct nlmsghdr *nlh, uint16_t type, uint64_t data);
-extern void mnl_attr_put_str(struct nlmsghdr *nlh, uint16_t type, const char *data);
-extern void mnl_attr_put_strz(struct nlmsghdr *nlh, uint16_t type, const char *data);
+MNL_API void mnl_attr_put(struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data);
+MNL_API void mnl_attr_put_u8(struct nlmsghdr *nlh, uint16_t type, uint8_t data);
+MNL_API void mnl_attr_put_u16(struct nlmsghdr *nlh, uint16_t type, uint16_t data);
+MNL_API void mnl_attr_put_u32(struct nlmsghdr *nlh, uint16_t type, uint32_t data);
+MNL_API void mnl_attr_put_u64(struct nlmsghdr *nlh, uint16_t type, uint64_t data);
+MNL_API void mnl_attr_put_str(struct nlmsghdr *nlh, uint16_t type, const char *data);
+MNL_API void mnl_attr_put_strz(struct nlmsghdr *nlh, uint16_t type, const char *data);
/* TLV attribute nesting */
-extern struct nlattr *mnl_attr_nest_start(struct nlmsghdr *nlh, uint16_t type);
-extern void mnl_attr_nest_end(struct nlmsghdr *nlh, struct nlattr *start);
+MNL_API struct nlattr *mnl_attr_nest_start(struct nlmsghdr *nlh, uint16_t type);
+MNL_API void mnl_attr_nest_end(struct nlmsghdr *nlh, struct nlattr *start);
/* TLV validation */
-extern int mnl_attr_type_valid(const struct nlattr *attr, uint16_t maxtype);
+MNL_API int mnl_attr_type_valid(const struct nlattr *attr, uint16_t maxtype);
enum mnl_attr_data_type {
MNL_TYPE_UNSPEC,
@@ -114,12 +120,12 @@ enum mnl_attr_data_type {
MNL_TYPE_MAX,
};
-extern int mnl_attr_validate(const struct nlattr *attr, enum mnl_attr_data_type type);
-extern int mnl_attr_validate2(const struct nlattr *attr, enum mnl_attr_data_type type, size_t len);
+MNL_API int mnl_attr_validate(const struct nlattr *attr, enum mnl_attr_data_type type);
+MNL_API int mnl_attr_validate2(const struct nlattr *attr, enum mnl_attr_data_type type, size_t len);
/* TLV iterators */
-extern bool mnl_attr_ok(const struct nlattr *attr, int len);
-extern struct nlattr *mnl_attr_next(const struct nlattr *attr, int *len);
+MNL_API bool mnl_attr_ok(const struct nlattr *attr, int len);
+MNL_API struct nlattr *mnl_attr_next(const struct nlattr *attr, int *len);
#define mnl_attr_for_each(attr, nlh, offset) \
int __len__ = mnl_nlmsg_get_payload_len(nlh); \
@@ -136,8 +142,8 @@ extern struct nlattr *mnl_attr_next(const struct nlattr *attr, int *len);
/* TLV callback-based attribute parsers */
typedef int (*mnl_attr_cb_t)(const struct nlattr *attr, void *data);
-extern int mnl_attr_parse(const struct nlmsghdr *nlh, unsigned int offset, mnl_attr_cb_t cb, void *data);
-extern int mnl_attr_parse_nested(const struct nlattr *attr, mnl_attr_cb_t cb, void *data);
+MNL_API int mnl_attr_parse(const struct nlmsghdr *nlh, unsigned int offset, mnl_attr_cb_t cb, void *data);
+MNL_API int mnl_attr_parse_nested(const struct nlattr *attr, mnl_attr_cb_t cb, void *data);
/*
* callback API
@@ -148,10 +154,10 @@ extern int mnl_attr_parse_nested(const struct nlattr *attr, mnl_attr_cb_t cb, vo
typedef int (*mnl_cb_t)(const struct nlmsghdr *nlh, void *data);
-extern int mnl_cb_run(const void *buf, size_t numbytes, unsigned int seq,
+MNL_API int mnl_cb_run(const void *buf, size_t numbytes, unsigned int seq,
unsigned int portid, mnl_cb_t cb_data, void *data);
-extern int mnl_cb_run2(const void *buf, size_t numbytes, unsigned int seq,
+MNL_API int mnl_cb_run2(const void *buf, size_t numbytes, unsigned int seq,
unsigned int portid, mnl_cb_t cb_data, void *data,
mnl_cb_t *cb_ctl_array, unsigned int cb_ctl_array_len);