Skip to content

Commit

Permalink
include: drop "netlink-private/netlink.h" and move declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
thom311 committed Aug 2, 2023
1 parent 30b3daa commit ebd66c5
Show file tree
Hide file tree
Showing 152 changed files with 345 additions and 517 deletions.
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ noinst_HEADERS = \
include/linux-private/linux/tc_ematch/tc_em_meta.h \
include/linux-private/linux/veth.h \
include/linux-private/linux/xfrm.h \
include/netlink-private/netlink.h \
include/nl-aux-core/nl-core.h \
include/nl-aux-route/nl-route.h \
include/nl-default.h \
Expand Down
110 changes: 109 additions & 1 deletion include/base/nl-base-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand Down Expand Up @@ -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

/*****************************************************************************/

Expand Down Expand Up @@ -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__ */
220 changes: 0 additions & 220 deletions include/netlink-private/netlink.h

This file was deleted.

16 changes: 16 additions & 0 deletions include/nl-aux-core/nl-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit ebd66c5

Please sign in to comment.