summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-08-02 16:40:41 (GMT)
committerThomas Haller <thaller@redhat.com>2023-08-02 20:20:13 (GMT)
commit298c5dc6df6d47b1488b0025619f1932b3064477 (patch)
treef881456bfe735d2ba9d4b6e517b0981a124d25e9 /include
parent862eed54e3882c64a5017789229b6dc9337ace17 (diff)
downloadlibnl-298c5dc6df6d47b1488b0025619f1932b3064477.zip
libnl-298c5dc6df6d47b1488b0025619f1932b3064477.tar.gz
libnl-298c5dc6df6d47b1488b0025619f1932b3064477.tar.bz2
include: drop "netlink-private/netlink.h" and move declarations
Diffstat (limited to 'include')
-rw-r--r--include/base/nl-base-utils.h110
-rw-r--r--include/netlink-private/netlink.h220
-rw-r--r--include/nl-aux-core/nl-core.h16
-rw-r--r--include/nl-priv-dynamic-core/cache-api.h23
-rw-r--r--include/nl-priv-dynamic-core/nl-core.h42
5 files changed, 167 insertions, 244 deletions
diff --git a/include/base/nl-base-utils.h b/include/base/nl-base-utils.h
index e02b5f4..4e7ad7a 100644
--- a/include/base/nl-base-utils.h
+++ b/include/base/nl-base-utils.h
@@ -8,6 +8,9 @@
#include <byteswap.h>
#include <stdlib.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <inttypes.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
@@ -17,6 +20,12 @@
#include <netinet/in.h>
#include <arpa/inet.h>
+#ifndef DISABLE_PTHREADS
+#include <pthread.h>
+#endif
+
+/*****************************************************************************/
+
#if __BYTE_ORDER == __BIG_ENDIAN
#define ntohll(x) (x)
#elif __BYTE_ORDER == __LITTLE_ENDIAN
@@ -178,9 +187,14 @@
#define _NL_N_ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
+#define ARRAY_SIZE(arr) _NL_N_ELEMENTS(arr)
+
/*****************************************************************************/
-extern const char *nl_strerror_l(int err);
+/* This is also defined in stddef.h */
+#ifndef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER)
+#endif
/*****************************************************************************/
@@ -713,4 +727,98 @@ static inline char *_nl_inet_ntop_dup(int addr_family, const void *addr)
#define _nl_auto_free _nl_auto(_nl_auto_free_fcn)
_NL_AUTO_DEFINE_FCN_VOID0(void *, _nl_auto_free_fcn, free);
+/*****************************************************************************/
+
+#define NSEC_PER_SEC 1000000000L
+
+struct trans_tbl {
+ uint64_t i;
+ const char *a;
+};
+
+#define __ADD(id, name) \
+ { \
+ .i = id, .a = #name \
+ }
+
+#define BUG() \
+ do { \
+ fprintf(stderr, "BUG at file position %s:%d:%s\n", __FILE__, \
+ __LINE__, __func__); \
+ assert(0); \
+ } while (0)
+
+#define BUG_ON(condition) \
+ do { \
+ if (condition) \
+ BUG(); \
+ } while (0)
+
+#define APPBUG(msg) \
+ do { \
+ fprintf(stderr, "APPLICATION BUG: %s:%d:%s: %s\n", __FILE__, \
+ __LINE__, __func__, msg); \
+ assert(0); \
+ } while (0)
+
+/*****************************************************************************/
+
+#ifndef DISABLE_PTHREADS
+#define NL_LOCK(NAME) pthread_mutex_t(NAME) = PTHREAD_MUTEX_INITIALIZER
+#define NL_RW_LOCK(NAME) pthread_rwlock_t(NAME) = PTHREAD_RWLOCK_INITIALIZER
+
+static inline void nl_lock(pthread_mutex_t *lock)
+{
+ pthread_mutex_lock(lock);
+}
+
+static inline void nl_unlock(pthread_mutex_t *lock)
+{
+ pthread_mutex_unlock(lock);
+}
+
+static inline void nl_read_lock(pthread_rwlock_t *lock)
+{
+ pthread_rwlock_rdlock(lock);
+}
+
+static inline void nl_read_unlock(pthread_rwlock_t *lock)
+{
+ pthread_rwlock_unlock(lock);
+}
+
+static inline void nl_write_lock(pthread_rwlock_t *lock)
+{
+ pthread_rwlock_wrlock(lock);
+}
+
+static inline void nl_write_unlock(pthread_rwlock_t *lock)
+{
+ pthread_rwlock_unlock(lock);
+}
+
+#else
+#define NL_LOCK(NAME) int __unused_lock_##NAME __attribute__((unused))
+#define NL_RW_LOCK(NAME) int __unused_lock_##NAME __attribute__((unused))
+
+#define nl_lock(LOCK) \
+ do { \
+ } while (0)
+#define nl_unlock(LOCK) \
+ do { \
+ } while (0)
+#define nl_read_lock(LOCK) \
+ do { \
+ } while (0)
+#define nl_read_unlock(LOCK) \
+ do { \
+ } while (0)
+#define nl_write_lock(LOCK) \
+ do { \
+ } while (0)
+#define nl_write_unlock(LOCK) \
+ do { \
+ } while (0)
+#endif
+
#endif /* __NETLINK_BASE_NL_BASE_UTILS_H__ */
diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h
deleted file mode 100644
index cc67841..0000000
--- a/include/netlink-private/netlink.h
+++ /dev/null
@@ -1,220 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-only */
-/*
- * Copyright (c) 2003-2013 Thomas Graf <tgraf@suug.ch>
- */
-
-#ifndef NETLINK_LOCAL_H_
-#define NETLINK_LOCAL_H_
-
-#include "nl-default.h"
-
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <time.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <inttypes.h>
-#include <assert.h>
-#include <limits.h>
-#include <search.h>
-
-#include <arpa/inet.h>
-#include <netdb.h>
-
-#ifndef SOL_NETLINK
-#define SOL_NETLINK 270
-#endif
-
-#include <linux/types.h>
-
-/* local header copies */
-#include <linux/if.h>
-#include <linux/if_arp.h>
-#include <linux/if_ether.h>
-#include <linux/ethtool.h>
-#include <linux/pkt_sched.h>
-#include <linux/pkt_cls.h>
-#include <linux/gen_stats.h>
-#include <linux/atm.h>
-#include <linux/ip.h>
-#include <linux/ipv6.h>
-#include <linux/snmp.h>
-#include <linux/xfrm.h>
-
-#ifndef DISABLE_PTHREADS
-#include <pthread.h>
-#endif
-
-#include "base/nl-base-utils.h"
-
-#include <netlink/netlink.h>
-#include <netlink/handlers.h>
-#include <netlink/cache.h>
-#include <netlink/route/tc.h>
-
-#include "nl-priv-dynamic-core/cache-api.h"
-#include "nl-aux-core/nl-core.h"
-
-#define NSEC_PER_SEC 1000000000L
-
-struct trans_tbl {
- uint64_t i;
- const char *a;
-};
-
-#define __ADD(id, name) { .i = id, .a = #name }
-
-struct trans_list {
- int i;
- char *a;
- struct nl_list_head list;
-};
-
-#ifdef NL_DEBUG
-#define NL_DBG(LVL,FMT,ARG...) \
- do { \
- if (LVL <= nl_debug) { \
- int _errsv = errno; \
- fprintf(stderr, \
- "DBG<" #LVL ">%20s:%-4u %s: " FMT, \
- __FILE__, __LINE__, \
- __func__, ##ARG); \
- errno = _errsv; \
- } \
- } while (0)
-#else /* NL_DEBUG */
-#define NL_DBG(LVL,FMT,ARG...) do { } while(0)
-#endif /* NL_DEBUG */
-
-#define BUG() \
- do { \
- fprintf(stderr, "BUG at file position %s:%d:%s\n", \
- __FILE__, __LINE__, __func__); \
- assert(0); \
- } while (0)
-
-#define BUG_ON(condition) \
- do { \
- if (condition) \
- BUG(); \
- } while (0)
-
-
-#define APPBUG(msg) \
- do { \
- fprintf(stderr, "APPLICATION BUG: %s:%d:%s: %s\n", \
- __FILE__, __LINE__, __func__, msg); \
- assert(0); \
- } while(0)
-
-extern int __nl_read_num_str_file(const char *path,
- int (*cb)(long, const char *));
-
-extern int __trans_list_add(int, const char *, struct nl_list_head *);
-extern void __trans_list_clear(struct nl_list_head *);
-
-extern char *__type2str(int, char *, size_t, const struct trans_tbl *, size_t);
-extern int __str2type(const char *, const struct trans_tbl *, size_t);
-
-extern char *__list_type2str(int, char *, size_t, struct nl_list_head *);
-extern int __list_str2type(const char *, struct nl_list_head *);
-
-extern char *__flags2str(int, char *, size_t, const struct trans_tbl *, size_t);
-extern int __str2flags(const char *, const struct trans_tbl *, size_t);
-
-extern void dump_from_ops(struct nl_object *, struct nl_dump_params *);
-extern struct rtnl_link *link_lookup(struct nl_cache *cache, int ifindex);
-
-#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
-
-/* This is also defined in stddef.h */
-#ifndef offsetof
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
-extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
- struct nlmsghdr *, struct nl_parser_param *);
-
-
-#define GENL_FAMILY(id, name) \
- { \
- { id, NL_ACT_UNSPEC, name }, \
- END_OF_MSGTYPES_LIST, \
- }
-
-static inline int build_sysconf_path(char **strp, const char *filename)
-{
- char *sysconfdir;
-
- sysconfdir = getenv("NLSYSCONFDIR");
-
- if (!sysconfdir)
- sysconfdir = SYSCONFDIR;
-
- return asprintf(strp, "%s/%s", sysconfdir, filename);
-}
-
-#ifndef DISABLE_PTHREADS
-#define NL_LOCK(NAME) pthread_mutex_t (NAME) = PTHREAD_MUTEX_INITIALIZER
-#define NL_RW_LOCK(NAME) pthread_rwlock_t (NAME) = PTHREAD_RWLOCK_INITIALIZER
-
-static inline void nl_lock(pthread_mutex_t *lock)
-{
- pthread_mutex_lock(lock);
-}
-
-static inline void nl_unlock(pthread_mutex_t *lock)
-{
- pthread_mutex_unlock(lock);
-}
-
-static inline void nl_read_lock(pthread_rwlock_t *lock)
-{
- pthread_rwlock_rdlock(lock);
-}
-
-static inline void nl_read_unlock(pthread_rwlock_t *lock)
-{
- pthread_rwlock_unlock(lock);
-}
-
-static inline void nl_write_lock(pthread_rwlock_t *lock)
-{
- pthread_rwlock_wrlock(lock);
-}
-
-static inline void nl_write_unlock(pthread_rwlock_t *lock)
-{
- pthread_rwlock_unlock(lock);
-}
-
-#else
-#define NL_LOCK(NAME) int __unused_lock_ ##NAME __attribute__((unused))
-#define NL_RW_LOCK(NAME) int __unused_lock_ ##NAME __attribute__((unused))
-
-#define nl_lock(LOCK) do { } while(0)
-#define nl_unlock(LOCK) do { } while(0)
-#define nl_read_lock(LOCK) do { } while(0)
-#define nl_read_unlock(LOCK) do { } while(0)
-#define nl_write_lock(LOCK) do { } while(0)
-#define nl_write_unlock(LOCK) do { } while(0)
-#endif
-
-static inline int rtnl_tc_calc_txtime64(int bufsize, uint64_t rate)
-{
- return ((double) bufsize / (double) rate) * 1000000.0;
-}
-
-static inline int rtnl_tc_calc_bufsize64(int txtime, uint64_t rate)
-{
- return ((double) txtime * (double) rate) / 1000000.0;
-}
-
-#endif
diff --git a/include/nl-aux-core/nl-core.h b/include/nl-aux-core/nl-core.h
index 1a02aaa..c336e34 100644
--- a/include/nl-aux-core/nl-core.h
+++ b/include/nl-aux-core/nl-core.h
@@ -5,6 +5,22 @@
#include "base/nl-base-utils.h"
+#ifdef NL_DEBUG
+#define NL_DBG(LVL, FMT, ARG...) \
+ do { \
+ if (LVL <= nl_debug) { \
+ int _errsv = errno; \
+ fprintf(stderr, "DBG<" #LVL ">%20s:%-4u %s: " FMT, \
+ __FILE__, __LINE__, __func__, ##ARG); \
+ errno = _errsv; \
+ } \
+ } while (0)
+#else /* NL_DEBUG */
+#define NL_DBG(LVL, FMT, ARG...) \
+ do { \
+ } while (0)
+#endif /* NL_DEBUG */
+
struct nl_addr;
void nl_addr_put(struct nl_addr *);
#define _nl_auto_nl_addr _nl_auto(_nl_auto_nl_addr_fcn)
diff --git a/include/nl-priv-dynamic-core/cache-api.h b/include/nl-priv-dynamic-core/cache-api.h
index 38662b7..6491651 100644
--- a/include/nl-priv-dynamic-core/cache-api.h
+++ b/include/nl-priv-dynamic-core/cache-api.h
@@ -258,6 +258,29 @@ struct nl_cache_ops
/** @} */
+struct nl_cache {
+ struct nl_list_head c_items;
+ int c_nitems;
+ int c_iarg1;
+ int c_iarg2;
+ int c_refcnt;
+ unsigned int c_flags;
+ struct nl_hash_table *hashtable;
+ struct nl_cache_ops *c_ops;
+};
+
+static inline const char *nl_cache_name(struct nl_cache *cache)
+{
+ return cache->c_ops ? cache->c_ops->co_name : "unknown";
+}
+
+struct nl_cache_assoc {
+ struct nl_cache *ca_cache;
+ change_func_t ca_change;
+ change_func_v2_t ca_change_v2;
+ void *ca_change_data;
+};
+
#ifdef __cplusplus
}
#endif
diff --git a/include/nl-priv-dynamic-core/nl-core.h b/include/nl-priv-dynamic-core/nl-core.h
index d4866b2..d7bec85 100644
--- a/include/nl-priv-dynamic-core/nl-core.h
+++ b/include/nl-priv-dynamic-core/nl-core.h
@@ -32,29 +32,6 @@ static inline int wait_for_ack(struct nl_sock *sk)
return nl_wait_for_ack(sk);
}
-struct nl_cache {
- struct nl_list_head c_items;
- int c_nitems;
- int c_iarg1;
- int c_iarg2;
- int c_refcnt;
- unsigned int c_flags;
- struct nl_hash_table *hashtable;
- struct nl_cache_ops *c_ops;
-};
-
-static inline const char *nl_cache_name(struct nl_cache *cache)
-{
- return cache->c_ops ? cache->c_ops->co_name : "unknown";
-}
-
-struct nl_cache_assoc {
- struct nl_cache *ca_cache;
- change_func_t ca_change;
- change_func_v2_t ca_change_v2;
- void *ca_change_data;
-};
-
#define LOOSE_COMPARISON 1
#define ID_COMPARISON 2
@@ -87,4 +64,23 @@ struct nl_msg {
int nm_refcnt;
};
+/*****************************************************************************/
+
+extern const char *nl_strerror_l(int err);
+
+extern int __nl_read_num_str_file(const char *path,
+ int (*cb)(long, const char *));
+
+extern int __trans_list_add(int, const char *, struct nl_list_head *);
+extern void __trans_list_clear(struct nl_list_head *);
+
+extern char *__type2str(int, char *, size_t, const struct trans_tbl *, size_t);
+extern int __str2type(const char *, const struct trans_tbl *, size_t);
+
+extern char *__list_type2str(int, char *, size_t, struct nl_list_head *);
+extern int __list_str2type(const char *, struct nl_list_head *);
+
+extern char *__flags2str(int, char *, size_t, const struct trans_tbl *, size_t);
+extern int __str2flags(const char *, const struct trans_tbl *, size_t);
+
#endif /* __NL_SHARED_CORE_NL_CORE_H__ */