compiler: add and use __hidden visbility

Closes: #3485. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 3a026996
...@@ -217,7 +217,6 @@ AM_CFLAGS = -DLXCROOTFSMOUNT=\"$(LXCROOTFSMOUNT)\" \ ...@@ -217,7 +217,6 @@ AM_CFLAGS = -DLXCROOTFSMOUNT=\"$(LXCROOTFSMOUNT)\" \
-I $(top_srcdir)/src/lxc \ -I $(top_srcdir)/src/lxc \
-I $(top_srcdir)/src/lxc/storage \ -I $(top_srcdir)/src/lxc/storage \
-I $(top_srcdir)/src/lxc/cgroups -I $(top_srcdir)/src/lxc/cgroups
if ENABLE_APPARMOR if ENABLE_APPARMOR
AM_CFLAGS += -DHAVE_APPARMOR AM_CFLAGS += -DHAVE_APPARMOR
endif endif
...@@ -409,6 +408,7 @@ lxc_user_nic_SOURCES = cmd/lxc_user_nic.c \ ...@@ -409,6 +408,7 @@ lxc_user_nic_SOURCES = cmd/lxc_user_nic.c \
log.c log.h \ log.c log.h \
memory_utils.h \ memory_utils.h \
network.c network.h \ network.c network.h \
nl.c nl.h \
parse.c parse.h \ parse.c parse.h \
process_utils.c process_utils.h \ process_utils.c process_utils.h \
syscall_numbers.h \ syscall_numbers.h \
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "log.h" #include "log.h"
#include "memory_utils.h" #include "memory_utils.h"
#include "network.h" #include "network.h"
#include "nl.h"
#include "parse.h" #include "parse.h"
#include "process_utils.h" #include "process_utils.h"
#include "string_utils.h" #include "string_utils.h"
......
...@@ -75,4 +75,8 @@ ...@@ -75,4 +75,8 @@
#endif #endif
#endif #endif
#ifndef __hidden
#define __hidden __attribute__((visibility("hidden")))
#endif
#endif /* __LXC_COMPILER_H */ #endif /* __LXC_COMPILER_H */
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
lxc_log_define(nl, lxc); lxc_log_define(nl, lxc);
size_t nlmsg_len(const struct nlmsg *nlmsg) static size_t nlmsg_len(const struct nlmsg *nlmsg)
{ {
return nlmsg->nlmsghdr->nlmsg_len - NLMSG_HDRLEN; return nlmsg->nlmsghdr->nlmsg_len - NLMSG_HDRLEN;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include "compiler.h"
#include "memory_utils.h" #include "memory_utils.h"
/* /*
...@@ -59,7 +60,7 @@ struct nlmsg { ...@@ -59,7 +60,7 @@ struct nlmsg {
* *
* Return 0 on success, < 0 otherwise * Return 0 on success, < 0 otherwise
*/ */
int netlink_open(struct nl_handler *handler, int protocol); __hidden extern int netlink_open(struct nl_handler *handler, int protocol);
/* /*
* netlink_close : close a netlink socket, after this call, * netlink_close : close a netlink socket, after this call,
...@@ -67,7 +68,7 @@ int netlink_open(struct nl_handler *handler, int protocol); ...@@ -67,7 +68,7 @@ int netlink_open(struct nl_handler *handler, int protocol);
* *
* @handler: a handler to the netlink socket * @handler: a handler to the netlink socket
*/ */
void netlink_close(struct nl_handler *handler); __hidden extern void netlink_close(struct nl_handler *handler);
define_cleanup_function(struct nl_handler *, netlink_close); define_cleanup_function(struct nl_handler *, netlink_close);
/* /*
...@@ -80,8 +81,8 @@ define_cleanup_function(struct nl_handler *, netlink_close); ...@@ -80,8 +81,8 @@ define_cleanup_function(struct nl_handler *, netlink_close);
* *
* Returns 0 on success, < 0 otherwise * Returns 0 on success, < 0 otherwise
*/ */
int netlink_rcv(struct nl_handler *handler, struct nlmsg *nlmsg); __hidden extern int netlink_rcv(struct nl_handler *handler, struct nlmsg *nlmsg);
int __netlink_recv(struct nl_handler *handler, struct nlmsghdr *nlmsg); __hidden extern int __netlink_recv(struct nl_handler *handler, struct nlmsghdr *nlmsg);
/* /*
* netlink_send: send a netlink message to the kernel. It is up * netlink_send: send a netlink message to the kernel. It is up
...@@ -92,8 +93,8 @@ int __netlink_recv(struct nl_handler *handler, struct nlmsghdr *nlmsg); ...@@ -92,8 +93,8 @@ int __netlink_recv(struct nl_handler *handler, struct nlmsghdr *nlmsg);
* *
* Returns 0 on success, < 0 otherwise * Returns 0 on success, < 0 otherwise
*/ */
int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg); __hidden extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg);
int __netlink_send(struct nl_handler *handler, struct nlmsghdr *nlmsg); __hidden extern int __netlink_send(struct nl_handler *handler, struct nlmsghdr *nlmsg);
/* /*
* netlink_transaction: send a request to the kernel and read the response. * netlink_transaction: send a request to the kernel and read the response.
...@@ -106,10 +107,10 @@ int __netlink_send(struct nl_handler *handler, struct nlmsghdr *nlmsg); ...@@ -106,10 +107,10 @@ int __netlink_send(struct nl_handler *handler, struct nlmsghdr *nlmsg);
* *
* Returns 0 on success, < 0 otherwise * Returns 0 on success, < 0 otherwise
*/ */
int netlink_transaction(struct nl_handler *handler, __hidden extern int netlink_transaction(struct nl_handler *handler, struct nlmsg *request,
struct nlmsg *request, struct nlmsg *answer); struct nlmsg *answer);
int __netlink_transaction(struct nl_handler *handler, struct nlmsghdr *request, __hidden extern int __netlink_transaction(struct nl_handler *handler, struct nlmsghdr *request,
struct nlmsghdr *answer); struct nlmsghdr *answer);
/* /*
* nla_put_string: copy a null terminated string to a netlink message * nla_put_string: copy a null terminated string to a netlink message
...@@ -121,7 +122,7 @@ int __netlink_transaction(struct nl_handler *handler, struct nlmsghdr *request, ...@@ -121,7 +122,7 @@ int __netlink_transaction(struct nl_handler *handler, struct nlmsghdr *request,
* *
* Returns 0 on success, < 0 otherwise * Returns 0 on success, < 0 otherwise
*/ */
int nla_put_string(struct nlmsg *nlmsg, int attr, const char *string); __hidden int nla_put_string(struct nlmsg *nlmsg, int attr, const char *string);
/* /*
* nla_put_buffer: copy a buffer with a specified size to a netlink * nla_put_buffer: copy a buffer with a specified size to a netlink
...@@ -178,7 +179,7 @@ int nla_put_attr(struct nlmsg *nlmsg, int attr); ...@@ -178,7 +179,7 @@ int nla_put_attr(struct nlmsg *nlmsg, int attr);
* Returns current nested pointer to be reused * Returns current nested pointer to be reused
* to nla_end_nested. * to nla_end_nested.
*/ */
struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr); __hidden extern struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr);
/* /*
* nla_end_nested: end the nesting attribute * nla_end_nested: end the nesting attribute
...@@ -188,7 +189,7 @@ struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr); ...@@ -188,7 +189,7 @@ struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr);
* *
* Returns the current * Returns the current
*/ */
void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr); __hidden extern void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr);
/* /*
* nlmsg_allocate : allocate a netlink message. The netlink format message * nlmsg_allocate : allocate a netlink message. The netlink format message
...@@ -205,7 +206,7 @@ void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr); ...@@ -205,7 +206,7 @@ void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr);
* *
* Returns a pointer to the newly allocated netlink message, NULL otherwise * Returns a pointer to the newly allocated netlink message, NULL otherwise
*/ */
struct nlmsg *nlmsg_alloc(size_t size); __hidden extern struct nlmsg *nlmsg_alloc(size_t size);
/* /*
* nlmsg_alloc_reserve: like nlmsg_alloc(), but reserve the whole payload * nlmsg_alloc_reserve: like nlmsg_alloc(), but reserve the whole payload
...@@ -214,7 +215,7 @@ struct nlmsg *nlmsg_alloc(size_t size); ...@@ -214,7 +215,7 @@ struct nlmsg *nlmsg_alloc(size_t size);
* *
* @size: the capacity of the payload to be allocated. * @size: the capacity of the payload to be allocated.
*/ */
struct nlmsg *nlmsg_alloc_reserve(size_t size); __hidden extern struct nlmsg *nlmsg_alloc_reserve(size_t size);
/* /*
* Reserve room for additional data at the tail of a netlink message * Reserve room for additional data at the tail of a netlink message
...@@ -224,14 +225,14 @@ struct nlmsg *nlmsg_alloc_reserve(size_t size); ...@@ -224,14 +225,14 @@ struct nlmsg *nlmsg_alloc_reserve(size_t size);
* *
* Returns a pointer to newly reserved room or NULL * Returns a pointer to newly reserved room or NULL
*/ */
void *nlmsg_reserve(struct nlmsg *nlmsg, size_t len); __hidden extern void *nlmsg_reserve(struct nlmsg *nlmsg, size_t len);
/* /*
* nlmsg_free : free a previously allocate message * nlmsg_free : free a previously allocate message
* *
* @nlmsg: the netlink message to be freed * @nlmsg: the netlink message to be freed
*/ */
void nlmsg_free(struct nlmsg *nlmsg); __hidden extern void nlmsg_free(struct nlmsg *nlmsg);
define_cleanup_function(struct nlmsg *, nlmsg_free); define_cleanup_function(struct nlmsg *, nlmsg_free);
/* /*
...@@ -241,9 +242,9 @@ define_cleanup_function(struct nlmsg *, nlmsg_free); ...@@ -241,9 +242,9 @@ define_cleanup_function(struct nlmsg *, nlmsg_free);
* *
* Returns a pointer to the netlink data or NULL if there is no data * Returns a pointer to the netlink data or NULL if there is no data
*/ */
void *nlmsg_data(struct nlmsg *nlmsg); __hidden extern void *nlmsg_data(struct nlmsg *nlmsg);
extern int addattr(struct nlmsghdr *n, size_t maxlen, int type, __hidden extern int addattr(struct nlmsghdr *n, size_t maxlen, int type,
const void *data, size_t alen); const void *data, size_t alen);
#endif #endif
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#include "nl.h" #include "nl.h"
#include "rtnl.h" #include "rtnl.h"
extern int rtnetlink_open(struct rtnl_handler *handler) int rtnetlink_open(struct rtnl_handler *handler)
{ {
return netlink_open(&handler->nlh, NETLINK_ROUTE); return netlink_open(&handler->nlh, NETLINK_ROUTE);
} }
extern void rtnetlink_close(struct rtnl_handler *handler) void rtnetlink_close(struct rtnl_handler *handler)
{ {
netlink_close(&handler->nlh); netlink_close(&handler->nlh);
} }
...@@ -29,20 +29,19 @@ extern void rtnetlink_close(struct rtnl_handler *handler) ...@@ -29,20 +29,19 @@ extern void rtnetlink_close(struct rtnl_handler *handler)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align" #pragma GCC diagnostic ignored "-Wcast-align"
extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg) int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg)
{ {
return netlink_rcv(&handler->nlh, (struct nlmsg *)&rtnlmsg->nlmsghdr); return netlink_rcv(&handler->nlh, (struct nlmsg *)&rtnlmsg->nlmsghdr);
} }
extern int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg) int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg)
{ {
return netlink_send(&handler->nlh, (struct nlmsg *)&rtnlmsg->nlmsghdr); return netlink_send(&handler->nlh, (struct nlmsg *)&rtnlmsg->nlmsghdr);
} }
extern int rtnetlink_transaction(struct rtnl_handler *handler, int rtnetlink_transaction(struct rtnl_handler *handler, struct rtnlmsg *request,
struct rtnlmsg *request, struct rtnlmsg *answer)
struct rtnlmsg *answer)
{ {
return netlink_transaction(&handler->nlh, return netlink_transaction(&handler->nlh,
(struct nlmsg *)&request->nlmsghdr, (struct nlmsg *)&request->nlmsghdr,
...@@ -51,7 +50,7 @@ extern int rtnetlink_transaction(struct rtnl_handler *handler, ...@@ -51,7 +50,7 @@ extern int rtnetlink_transaction(struct rtnl_handler *handler,
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
extern struct rtnlmsg *rtnlmsg_alloc(size_t size) struct rtnlmsg *rtnlmsg_alloc(size_t size)
{ {
/* /*
size_t len; size_t len;
...@@ -63,4 +62,4 @@ extern struct rtnlmsg *rtnlmsg_alloc(size_t size) ...@@ -63,4 +62,4 @@ extern struct rtnlmsg *rtnlmsg_alloc(size_t size)
return NULL; return NULL;
} }
extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg) { free(rtnlmsg); } void rtnlmsg_free(struct rtnlmsg *rtnlmsg) { free(rtnlmsg); }
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#ifndef __LXC_RTNL_H #ifndef __LXC_RTNL_H
#define __LXC_RTNL_H #define __LXC_RTNL_H
#include <compiler.h>
/* /*
* Use this as a good size to allocate route netlink messages * Use this as a good size to allocate route netlink messages
*/ */
...@@ -38,14 +40,14 @@ struct rtnlmsg { ...@@ -38,14 +40,14 @@ struct rtnlmsg {
* *
* Returns 0 on success, < 0 otherwise * Returns 0 on success, < 0 otherwise
*/ */
extern int rtnetlink_open(struct rtnl_handler *handler); __hidden extern int rtnetlink_open(struct rtnl_handler *handler);
/* /*
* genetlink_close : close a route netlink socket * genetlink_close : close a route netlink socket
* *
* @handler: the handler of the socket to be closed * @handler: the handler of the socket to be closed
*/ */
extern void rtnetlink_close(struct rtnl_handler *handler); __hidden extern void rtnetlink_close(struct rtnl_handler *handler);
/* /*
* rtnetlink_rcv : receive a route netlink socket, it is up * rtnetlink_rcv : receive a route netlink socket, it is up
...@@ -56,7 +58,7 @@ extern void rtnetlink_close(struct rtnl_handler *handler); ...@@ -56,7 +58,7 @@ extern void rtnetlink_close(struct rtnl_handler *handler);
* *
* Returns 0 on success, < 0 otherwise * Returns 0 on success, < 0 otherwise
*/ */
extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg); __hidden extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);
/* /*
* rtnetlink_send : send a route netlink socket, it is up * rtnetlink_send : send a route netlink socket, it is up
...@@ -67,12 +69,11 @@ extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg); ...@@ -67,12 +69,11 @@ extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);
* *
* Returns 0 on success, < 0 otherwise * Returns 0 on success, < 0 otherwise
*/ */
extern int rtnetlink_send(struct rtnl_handler *handler, __hidden extern int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);
struct rtnlmsg *rtnlmsg);
struct genlmsg *genlmsg_alloc(size_t size); __hidden struct genlmsg *genlmsg_alloc(size_t size);
extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg); __hidden extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg);
/* /*
* rtnetlink_transaction : send and receive a route netlink message in one shot * rtnetlink_transaction : send and receive a route netlink message in one shot
...@@ -83,8 +84,9 @@ extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg); ...@@ -83,8 +84,9 @@ extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg);
* *
* Returns 0 on success, < 0 otherwise * Returns 0 on success, < 0 otherwise
*/ */
extern int rtnetlink_transaction(struct rtnl_handler *handler, __hidden extern int rtnetlink_transaction(struct rtnl_handler *handler, struct rtnlmsg *request,
struct rtnlmsg *request, struct rtnlmsg *answer);
struct rtnlmsg *answer);
__hidden struct rtnlmsg *rtnlmsg_alloc(size_t size);
#endif /* __LXC_RTNL_H */ #endif /* __LXC_RTNL_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment