From 9680f910f46b78d700ae66a16c08d8927dfc2199 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Thu, 24 Jan 2013 13:51:24 +0100 Subject: Move private header files to This clarifies the seperation between public and private header files. Signed-off-by: Thomas Graf --- include/Makefile.am | 17 +- include/netlink-generic.h | 20 - include/netlink-local.h | 257 --------- include/netlink-private/cache-api.h | 285 ++++++++++ include/netlink-private/genl.h | 20 + include/netlink-private/netlink.h | 257 +++++++++ include/netlink-private/object-api.h | 376 +++++++++++++ include/netlink-private/route/link/api.h | 153 ++++++ include/netlink-private/route/tc-api.h | 134 +++++ include/netlink-private/tc.h | 55 ++ include/netlink-private/types.h | 910 +++++++++++++++++++++++++++++++ include/netlink-tc.h | 55 -- include/netlink-types.h | 910 ------------------------------- include/netlink/cache-api.h | 285 ---------- include/netlink/object-api.h | 375 ------------- include/netlink/route/link/api.h | 153 ------ include/netlink/route/link/info-api.h | 20 - include/netlink/route/tc-api.h | 136 ----- include/netlink/route/tc.h | 2 + 19 files changed, 2200 insertions(+), 2220 deletions(-) delete mode 100644 include/netlink-generic.h delete mode 100644 include/netlink-local.h create mode 100644 include/netlink-private/cache-api.h create mode 100644 include/netlink-private/genl.h create mode 100644 include/netlink-private/netlink.h create mode 100644 include/netlink-private/object-api.h create mode 100644 include/netlink-private/route/link/api.h create mode 100644 include/netlink-private/route/tc-api.h create mode 100644 include/netlink-private/tc.h create mode 100644 include/netlink-private/types.h delete mode 100644 include/netlink-tc.h delete mode 100644 include/netlink-types.h delete mode 100644 include/netlink/cache-api.h delete mode 100644 include/netlink/object-api.h delete mode 100644 include/netlink/route/link/api.h delete mode 100644 include/netlink/route/link/info-api.h delete mode 100644 include/netlink/route/tc-api.h (limited to 'include') diff --git a/include/Makefile.am b/include/Makefile.am index 50d1e4e..50f96b7 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -116,12 +116,11 @@ noinst_HEADERS = \ linux/rtnetlink.h \ linux/snmp.h \ linux/tc_ematch/tc_em_meta.h \ - netlink-generic.h \ - netlink-local.h \ - netlink-tc.h \ - netlink-types.h \ - netlink/cache-api.h \ - netlink/object-api.h \ - netlink/route/link/api.h \ - netlink/route/link/info-api.h \ - netlink/route/tc-api.h + netlink-private/genl.h \ + netlink-private/netlink.h \ + netlink-private/tc.h \ + netlink-private/types.h \ + netlink-private/cache-api.h \ + netlink-private/object-api.h \ + netlink-private/route/link/api.h \ + netlink-private/route/tc-api.h diff --git a/include/netlink-generic.h b/include/netlink-generic.h deleted file mode 100644 index 10aa2f0..0000000 --- a/include/netlink-generic.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * netlink-generic.h Local Generic Netlink Interface - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * Copyright (c) 2003-2006 Thomas Graf - */ - -#ifndef NETLINK_GENL_PRIV_H_ -#define NETLINK_GENL_PRIV_H_ - -#include -#include - -#define GENL_HDRSIZE(hdrlen) (GENL_HDRLEN + (hdrlen)) - -#endif diff --git a/include/netlink-local.h b/include/netlink-local.h deleted file mode 100644 index c0915f8..0000000 --- a/include/netlink-local.h +++ /dev/null @@ -1,257 +0,0 @@ -/* - * netlink-local.h Local Netlink Interface - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * Copyright (c) 2003-2011 Thomas Graf - */ - -#ifndef NETLINK_LOCAL_H_ -#define NETLINK_LOCAL_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#ifndef SOL_NETLINK -#define SOL_NETLINK 270 -#endif - -#include - -/* local header copies */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef DISABLE_PTHREADS -#include -#endif - -#include -#include -#include -#include -#include -#include -#include - -struct trans_tbl { - int i; - const char *a; -}; - -#define __ADD(id, name) { .i = id, .a = #name }, - -struct trans_list { - int i; - char *a; - struct nl_list_head list; -}; - -#define NL_DEBUG 1 - -#define NL_DBG(LVL,FMT,ARG...) \ - do { \ - if (LVL <= nl_debug) \ - fprintf(stderr, "DBG<" #LVL ">: " FMT, ##ARG); \ - } while (0) - -#define BUG() \ - do { \ - NL_DBG(1, "BUG: %s:%d\n", \ - __FILE__, __LINE__); \ - assert(0); \ - } while (0) - -#define APPBUG(msg) \ - do { \ - NL_DBG(1, "APPLICATION BUG: %s:%d:%s: %s\n", \ - __FILE__, __LINE__, __PRETTY_FUNCTION__, 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 *); - -static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg) -{ - return cb->cb_set[type](msg, cb->cb_args[type]); -} - -#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 - -#define __init __attribute__ ((constructor)) -#define __exit __attribute__ ((destructor)) -#undef __deprecated -#define __deprecated __attribute__ ((deprecated)) - -#define min(x,y) ({ \ - typeof(x) _x = (x); \ - typeof(y) _y = (y); \ - (void) (&_x == &_y); \ - _x < _y ? _x : _y; }) - -#define max(x,y) ({ \ - typeof(x) _x = (x); \ - typeof(y) _y = (y); \ - (void) (&_x == &_y); \ - _x > _y ? _x : _y; }) - -#define min_t(type,x,y) \ - ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) -#define max_t(type,x,y) \ - ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) - -extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *, - struct nlmsghdr *, struct nl_parser_param *); - - -static inline void rtnl_copy_ratespec(struct rtnl_ratespec *dst, - struct tc_ratespec *src) -{ - dst->rs_cell_log = src->cell_log; - dst->rs_overhead = src->overhead; - dst->rs_cell_align = src->cell_align; - dst->rs_mpu = src->mpu; - dst->rs_rate = src->rate; -} - -static inline void rtnl_rcopy_ratespec(struct tc_ratespec *dst, - struct rtnl_ratespec *src) -{ - dst->cell_log = src->rs_cell_log; - dst->overhead = src->rs_overhead; - dst->cell_align = src->rs_cell_align; - dst->mpu = src->rs_mpu; - dst->rate = src->rs_rate; -} - -static inline char *nl_cache_name(struct nl_cache *cache) -{ - return cache->c_ops ? cache->c_ops->co_name : "unknown"; -} - -#define GENL_FAMILY(id, name) \ - { \ - { id, NL_ACT_UNSPEC, name }, \ - END_OF_MSGTYPES_LIST, \ - } - -static inline int wait_for_ack(struct nl_sock *sk) -{ - if (sk->s_flags & NL_NO_AUTO_ACK) - return 0; - else - return nl_wait_for_ack(sk); -} - -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 - -#endif diff --git a/include/netlink-private/cache-api.h b/include/netlink-private/cache-api.h new file mode 100644 index 0000000..5d9b0ad --- /dev/null +++ b/include/netlink-private/cache-api.h @@ -0,0 +1,285 @@ +/* + * netlink-private/cache-api.h Caching API + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2013 Thomas Graf + */ + +#ifndef NETLINK_CACHE_API_H_ +#define NETLINK_CACHE_API_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup cache + * @defgroup cache_api Cache Implementation + * @brief + * + * @par 1) Cache Definition + * @code + * struct nl_cache_ops my_cache_ops = { + * .co_name = "route/link", + * .co_protocol = NETLINK_ROUTE, + * .co_hdrsize = sizeof(struct ifinfomsg), + * .co_obj_ops = &my_obj_ops, + * }; + * @endcode + * + * @par 2) + * @code + * // The simplest way to fill a cache is by providing a request-update + * // function which must trigger a complete dump on the kernel-side of + * // whatever the cache covers. + * static int my_request_update(struct nl_cache *cache, + * struct nl_sock *socket) + * { + * // In this example, we request a full dump of the interface table + * return nl_rtgen_request(socket, RTM_GETLINK, AF_UNSPEC, NLM_F_DUMP); + * } + * + * // The resulting netlink messages sent back will be fed into a message + * // parser one at a time. The message parser has to extract all relevant + * // information from the message and create an object reflecting the + * // contents of the message and pass it on to the parser callback function + * // provide which will add the object to the cache. + * static int my_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who, + * struct nlmsghdr *nlh, struct nl_parser_param *pp) + * { + * struct my_obj *obj; + * + * obj = my_obj_alloc(); + * obj->ce_msgtype = nlh->nlmsg_type; + * + * // Parse the netlink message and continue creating the object. + * + * err = pp->pp_cb((struct nl_object *) obj, pp); + * if (err < 0) + * goto errout; + * } + * + * struct nl_cache_ops my_cache_ops = { + * ... + * .co_request_update = my_request_update, + * .co_msg_parser = my_msg_parser, + * }; + * @endcode + * + * @par 3) Notification based Updates + * @code + * // Caches can be kept up-to-date based on notifications if the kernel + * // sends out notifications whenever an object is added/removed/changed. + * // + * // It is trivial to support this, first a list of groups needs to be + * // defined which are required to join in order to receive all necessary + * // notifications. The groups are separated by address family to support + * // the common situation where a separate group is used for each address + * // family. If there is only one group, simply specify AF_UNSPEC. + * static struct nl_af_group addr_groups[] = { + * { AF_INET, RTNLGRP_IPV4_IFADDR }, + * { AF_INET6, RTNLGRP_IPV6_IFADDR }, + * { END_OF_GROUP_LIST }, + * }; + * + * // In order for the caching system to know the meaning of each message + * // type it requires a table which maps each supported message type to + * // a cache action, e.g. RTM_NEWADDR means address has been added or + * // updated, RTM_DELADDR means address has been removed. + * static struct nl_cache_ops rtnl_addr_ops = { + * ... + * .co_msgtypes = { + * { RTM_NEWADDR, NL_ACT_NEW, "new" }, + * { RTM_DELADDR, NL_ACT_DEL, "del" }, + * { RTM_GETADDR, NL_ACT_GET, "get" }, + * END_OF_MSGTYPES_LIST, + * }, + * .co_groups = addr_groups, + * }; + * + * // It is now possible to keep the cache up-to-date using the cache manager. + * @endcode + * @{ + */ + +enum { + NL_ACT_UNSPEC, + NL_ACT_NEW, + NL_ACT_DEL, + NL_ACT_GET, + NL_ACT_SET, + NL_ACT_CHANGE, + __NL_ACT_MAX, +}; + +#define NL_ACT_MAX (__NL_ACT_MAX - 1) + +#define END_OF_MSGTYPES_LIST { -1, -1, NULL } + +/** + * Message type to cache action association + */ +struct nl_msgtype +{ + /** Netlink message type */ + int mt_id; + + /** Cache action to take */ + int mt_act; + + /** Name of operation for human-readable printing */ + char * mt_name; +}; + +/** + * Address family to netlink group association + */ +struct nl_af_group +{ + /** Address family */ + int ag_family; + + /** Netlink group identifier */ + int ag_group; +}; + +#define END_OF_GROUP_LIST AF_UNSPEC, 0 + +/** + * Parser parameters + * + * This structure is used to configure what kind of parser to use + * when parsing netlink messages to create objects. + */ +struct nl_parser_param +{ + /** Function to parse netlink messages into objects */ + int (*pp_cb)(struct nl_object *, struct nl_parser_param *); + + /** Arbitary argument to be passed to the parser */ + void * pp_arg; +}; + +/** + * Cache Operations + * + * This structure defines the characterstics of a cache type. It contains + * pointers to functions which implement the specifics of the object type + * the cache can hold. + */ +struct nl_cache_ops +{ + /** Name of cache type (must be unique) */ + char * co_name; + + /** Size of family specific netlink header */ + int co_hdrsize; + + /** Netlink protocol */ + int co_protocol; + + /** cache object hash size **/ + int co_hash_size; + + /** cache flags */ + unsigned int co_flags; + + /** Reference counter */ + unsigned int co_refcnt; + + /** Group definition */ + struct nl_af_group * co_groups; + + /** + * Called whenever an update of the cache is required. Must send + * a request message to the kernel requesting a complete dump. + */ + int (*co_request_update)(struct nl_cache *, struct nl_sock *); + + /** + * Called whenever a message was received that needs to be parsed. + * Must parse the message and call the paser callback function + * (nl_parser_param) provided via the argument. + */ + int (*co_msg_parser)(struct nl_cache_ops *, struct sockaddr_nl *, + struct nlmsghdr *, struct nl_parser_param *); + + /** + * The function registered under this callback is called after a + * netlink notification associated with this cache type has been + * parsed into an object and is being considered for inclusio into + * the specified cache. + * + * The purpose of this function is to filter out notifications + * which should be ignored when updating caches. + * + * The function must return NL_SKIP to prevent the object from + * being included, or NL_OK to include it. + * + * @code + * int my_filter(struct nl_cache *cache, struct nl_object *obj) + * { + * if (reason_to_not_include_obj(obj)) + * return NL_SKIP; + * + * return NL_OK; + * } + * @endcode + */ + int (*co_event_filter)(struct nl_cache *, struct nl_object *obj); + + /** + * The function registered under this callback is called when an + * object formed from a notification event needs to be included in + * a cache. + * + * For each modified object, the change callback \c change_cb must + * be called with the \c data argument provided. + * + * If no function is registered, the function nl_cache_include() + * will be used for this purpose. + * + * @see nl_cache_include() + */ + int (*co_include_event)(struct nl_cache *cache, struct nl_object *obj, + change_func_t change_cb, void *data); + + void (*reserved_1)(void); + void (*reserved_2)(void); + void (*reserved_3)(void); + void (*reserved_4)(void); + void (*reserved_5)(void); + void (*reserved_6)(void); + void (*reserved_7)(void); + void (*reserved_8)(void); + + /** Object operations */ + struct nl_object_ops * co_obj_ops; + + /** Internal, do not touch! */ + struct nl_cache_ops *co_next; + + struct nl_cache *co_major_cache; + struct genl_ops * co_genl; + + /* Message type definition */ + struct nl_msgtype co_msgtypes[]; +}; + +extern void nl_cache_ops_get(struct nl_cache_ops *); +extern void nl_cache_ops_put(struct nl_cache_ops *); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/netlink-private/genl.h b/include/netlink-private/genl.h new file mode 100644 index 0000000..0aca6d7 --- /dev/null +++ b/include/netlink-private/genl.h @@ -0,0 +1,20 @@ +/* + * netlink-private/genl.h Local Generic Netlink Interface + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2013 Thomas Graf + */ + +#ifndef NETLINK_GENL_PRIV_H_ +#define NETLINK_GENL_PRIV_H_ + +#include +#include + +#define GENL_HDRSIZE(hdrlen) (GENL_HDRLEN + (hdrlen)) + +#endif diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h new file mode 100644 index 0000000..6ae6d17 --- /dev/null +++ b/include/netlink-private/netlink.h @@ -0,0 +1,257 @@ +/* + * netlink-private/netlink.h Local Netlink Interface + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2013 Thomas Graf + */ + +#ifndef NETLINK_LOCAL_H_ +#define NETLINK_LOCAL_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#ifndef SOL_NETLINK +#define SOL_NETLINK 270 +#endif + +#include + +/* local header copies */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef DISABLE_PTHREADS +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +struct trans_tbl { + int i; + const char *a; +}; + +#define __ADD(id, name) { .i = id, .a = #name }, + +struct trans_list { + int i; + char *a; + struct nl_list_head list; +}; + +#define NL_DEBUG 1 + +#define NL_DBG(LVL,FMT,ARG...) \ + do { \ + if (LVL <= nl_debug) \ + fprintf(stderr, "DBG<" #LVL ">: " FMT, ##ARG); \ + } while (0) + +#define BUG() \ + do { \ + NL_DBG(1, "BUG: %s:%d\n", \ + __FILE__, __LINE__); \ + assert(0); \ + } while (0) + +#define APPBUG(msg) \ + do { \ + NL_DBG(1, "APPLICATION BUG: %s:%d:%s: %s\n", \ + __FILE__, __LINE__, __PRETTY_FUNCTION__, 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 *); + +static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg) +{ + return cb->cb_set[type](msg, cb->cb_args[type]); +} + +#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 + +#define __init __attribute__ ((constructor)) +#define __exit __attribute__ ((destructor)) +#undef __deprecated +#define __deprecated __attribute__ ((deprecated)) + +#define min(x,y) ({ \ + typeof(x) _x = (x); \ + typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x < _y ? _x : _y; }) + +#define max(x,y) ({ \ + typeof(x) _x = (x); \ + typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x > _y ? _x : _y; }) + +#define min_t(type,x,y) \ + ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) +#define max_t(type,x,y) \ + ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) + +extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *, + struct nlmsghdr *, struct nl_parser_param *); + + +static inline void rtnl_copy_ratespec(struct rtnl_ratespec *dst, + struct tc_ratespec *src) +{ + dst->rs_cell_log = src->cell_log; + dst->rs_overhead = src->overhead; + dst->rs_cell_align = src->cell_align; + dst->rs_mpu = src->mpu; + dst->rs_rate = src->rate; +} + +static inline void rtnl_rcopy_ratespec(struct tc_ratespec *dst, + struct rtnl_ratespec *src) +{ + dst->cell_log = src->rs_cell_log; + dst->overhead = src->rs_overhead; + dst->cell_align = src->rs_cell_align; + dst->mpu = src->rs_mpu; + dst->rate = src->rs_rate; +} + +static inline char *nl_cache_name(struct nl_cache *cache) +{ + return cache->c_ops ? cache->c_ops->co_name : "unknown"; +} + +#define GENL_FAMILY(id, name) \ + { \ + { id, NL_ACT_UNSPEC, name }, \ + END_OF_MSGTYPES_LIST, \ + } + +static inline int wait_for_ack(struct nl_sock *sk) +{ + if (sk->s_flags & NL_NO_AUTO_ACK) + return 0; + else + return nl_wait_for_ack(sk); +} + +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 + +#endif diff --git a/include/netlink-private/object-api.h b/include/netlink-private/object-api.h new file mode 100644 index 0000000..f4fd71e --- /dev/null +++ b/include/netlink-private/object-api.h @@ -0,0 +1,376 @@ +/* + * netlink-private/object-api.c Object API + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2013 Thomas Graf + */ + +#ifndef NETLINK_OBJECT_API_H_ +#define NETLINK_OBJECT_API_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup object + * @defgroup object_api Object API + * @brief + * + * @par 1) Object Definition + * @code + * // Define your object starting with the common object header + * struct my_obj { + * NLHDR_COMMON + * int my_data; + * }; + * + * // Fill out the object operations structure + * struct nl_object_ops my_ops = { + * .oo_name = "my_obj", + * .oo_size = sizeof(struct my_obj), + * }; + * + * // At this point the object can be allocated, you may want to provide a + * // separate _alloc() function to ease allocting objects of this kind. + * struct nl_object *obj = nl_object_alloc(&my_ops); + * + * // And release it again... + * nl_object_put(obj); + * @endcode + * + * @par 2) Allocating additional data + * @code + * // You may require to allocate additional data and store it inside + * // object, f.e. assuming there is a field `ptr'. + * struct my_obj { + * NLHDR_COMMON + * void * ptr; + * }; + * + * // And at some point you may assign allocated data to this field: + * my_obj->ptr = calloc(1, ...); + * + * // In order to not introduce any memory leaks you have to release + * // this data again when the last reference is given back. + * static void my_obj_free_data(struct nl_object *obj) + * { + * struct my_obj *my_obj = nl_object_priv(obj); + * + * free(my_obj->ptr); + * } + * + * // Also when the object is cloned, you must ensure for your pointer + * // stay valid even if one of the clones is freed by either making + * // a clone as well or increase the reference count. + * static int my_obj_clone(struct nl_object *src, struct nl_object *dst) + * { + * struct my_obj *my_src = nl_object_priv(src); + * struct my_obj *my_dst = nl_object_priv(dst); + * + * if (src->ptr) { + * dst->ptr = calloc(1, ...); + * memcpy(dst->ptr, src->ptr, ...); + * } + * } + * + * struct nl_object_ops my_ops = { + * ... + * .oo_free_data = my_obj_free_data, + * .oo_clone = my_obj_clone, + * }; + * @endcode + * + * @par 3) Object Dumping + * @code + * static int my_obj_dump_detailed(struct nl_object *obj, + * struct nl_dump_params *params) + * { + * struct my_obj *my_obj = nl_object_priv(obj); + * + * // It is absolutely essential to use nl_dump() when printing + * // any text to make sure the dumping parameters are respected. + * nl_dump(params, "Obj Integer: %d\n", my_obj->my_int); + * + * // Before we can dump the next line, make sure to prefix + * // this line correctly. + * nl_new_line(params); + * + * // You may also split a line into multiple nl_dump() calls. + * nl_dump(params, "String: %s ", my_obj->my_string); + * nl_dump(params, "String-2: %s\n", my_obj->another_string); + * } + * + * struct nl_object_ops my_ops = { + * ... + * .oo_dump[NL_DUMP_FULL] = my_obj_dump_detailed, + * }; + * @endcode + * + * @par 4) Object Attributes + * @code + * // The concept of object attributes is optional but can ease the typical + * // case of objects that have optional attributes, e.g. a route may have a + * // nexthop assigned but it is not required to. + * + * // The first step to define your object specific bitmask listing all + * // attributes + * #define MY_ATTR_FOO (1<<0) + * #define MY_ATTR_BAR (1<<1) + * + * // When assigning an optional attribute to the object, make sure + * // to mark its availability. + * my_obj->foo = 123123; + * my_obj->ce_mask |= MY_ATTR_FOO; + * + * // At any time you may use this mask to check for the availability + * // of the attribute, e.g. while dumping + * if (my_obj->ce_mask & MY_ATTR_FOO) + * nl_dump(params, "foo %d ", my_obj->foo); + * + * // One of the big advantages of this concept is that it allows for + * // standardized comparisons which make it trivial for caches to + * // identify unique objects by use of unified comparison functions. + * // In order for it to work, your object implementation must provide + * // a comparison function and define a list of attributes which + * // combined together make an object unique. + * + * static int my_obj_compare(struct nl_object *_a, struct nl_object *_b, + * uint32_t attrs, int flags) + * { + * struct my_obj *a = nl_object_priv(_a): + * struct my_obj *b = nl_object_priv(_b): + * int diff = 0; + * + * // We help ourselves in defining our own DIFF macro which will + * // call ATTR_DIFF() on both objects which will make sure to only + * // compare the attributes if required. + * #define MY_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, MY_ATTR_##ATTR, a, b, EXPR) + * + * // Call our own diff macro for each attribute to build a bitmask + * // representing the attributes which mismatch. + * diff |= MY_DIFF(FOO, a->foo != b->foo) + * diff |= MY_DIFF(BAR, strcmp(a->bar, b->bar)) + * + * return diff; + * } + * + * // In order to identify identical objects with differing attributes + * // you must specify the attributes required to uniquely identify + * // your object. Make sure to not include too many attributes, this + * // list is used when caches look for an old version of an object. + * struct nl_object_ops my_ops = { + * ... + * .oo_id_attrs = MY_ATTR_FOO, + * .oo_compare = my_obj_compare, + * }; + * @endcode + * @{ + */ + +/** + * Common Object Header + * + * This macro must be included as first member in every object + * definition to allow objects to be cached. + */ +#define NLHDR_COMMON \ + int ce_refcnt; \ + struct nl_object_ops * ce_ops; \ + struct nl_cache * ce_cache; \ + struct nl_list_head ce_list; \ + int ce_msgtype; \ + int ce_flags; \ + uint32_t ce_mask; + +struct nl_object +{ + NLHDR_COMMON +}; + + +/** + * Return true if attribute is available in both objects + * @arg A an object + * @arg B another object + * @arg ATTR attribute bit + * + * @return True if the attribute is available, otherwise false is returned. + */ +#define AVAILABLE(A, B, ATTR) (((A)->ce_mask & (B)->ce_mask) & (ATTR)) + +/** + * Return true if attribute is available in only one of both objects + * @arg A an object + * @arg B another object + * @arg ATTR attribute bit + * + * @return True if the attribute is available in only one of both objects, + * otherwise false is returned. + */ +#define AVAILABLE_MISMATCH(A, B, ATTR) (((A)->ce_mask ^ (B)->ce_mask) & (ATTR)) + +/** + * Return true if attributes mismatch + * @arg A an object + * @arg B another object + * @arg ATTR attribute bit + * @arg EXPR Comparison expression + * + * This function will check if the attribute in question is available + * in both objects, if not this will count as a mismatch. + * + * If available the function will execute the expression which must + * return true if the attributes mismatch. + * + * @return True if the attribute mismatch, or false if they match. + */ +#define ATTR_MISMATCH(A, B, ATTR, EXPR) (AVAILABLE_MISMATCH(A, B, ATTR) || \ + (AVAILABLE(A, B, ATTR) && (EXPR))) + +/** + * Return attribute bit if attribute does not match + * @arg LIST list of attributes to be compared + * @arg ATTR attribute bit + * @arg A an object + * @arg B another object + * @arg EXPR Comparison expression + * + * This function will check if the attribute in question is available + * in both objects, if not this will count as a mismatch. + * + * If available the function will execute the expression which must + * return true if the attributes mismatch. + * + * In case the attributes mismatch, the attribute is returned, otherwise + * 0 is returned. + * + * @code + * diff |= ATTR_DIFF(attrs, MY_ATTR_FOO, a, b, a->foo != b->foo); + * @endcode + */ +#define ATTR_DIFF(LIST, ATTR, A, B, EXPR) \ +({ int diff = 0; \ + if (((LIST) & (ATTR)) && ATTR_MISMATCH(A, B, ATTR, EXPR)) \ + diff = ATTR; \ + diff; }) + +/** + * Object Operations + */ +struct nl_object_ops +{ + /** + * Unique name of object type + * + * Must be in the form family/name, e.g. "route/addr" + */ + char * oo_name; + + /** Size of object including its header */ + size_t oo_size; + + /* List of attributes needed to uniquely identify the object */ + uint32_t oo_id_attrs; + + /** + * Constructor function + * + * Will be called when a new object of this type is allocated. + * Can be used to initialize members such as lists etc. + */ + void (*oo_constructor)(struct nl_object *); + + /** + * Destructor function + * + * Will be called when an object is freed. Must free all + * resources which may have been allocated as part of this + * object. + */ + void (*oo_free_data)(struct nl_object *); + + /** + * Cloning function + * + * Will be called when an object needs to be cloned. Please + * note that the generic object code will make an exact + * copy of the object first, therefore you only need to take + * care of members which require reference counting etc. + * + * May return a negative error code to abort cloning. + */ + int (*oo_clone)(struct nl_object *, struct nl_object *); + + /** + * Dumping functions + * + * Will be called when an object is dumped. The implementations + * have to use nl_dump(), nl_dump_line(), and nl_new_line() to + * dump objects. + * + * The functions must return the number of lines printed. + */ + void (*oo_dump[NL_DUMP_MAX+1])(struct nl_object *, + struct nl_dump_params *); + + /** + * Comparison function + * + * Will be called when two objects of the same type are + * compared. It takes the two objects in question, an object + * specific bitmask defining which attributes should be + * compared and flags to control the behaviour. + * + * The function must return a bitmask with the relevant bit + * set for each attribute that mismatches. + */ + int (*oo_compare)(struct nl_object *, struct nl_object *, + uint32_t, int); + + + /** + * update function + * + * Will be called when the object given by first argument + * needs to be updated with the contents of the second object + * + * The function must return 0 for success and error for failure + * to update. In case of failure its assumed that the original + * object is not touched + */ + int (*oo_update)(struct nl_object *, struct nl_object *); + + /** + * Hash Key generator function + * + * When called returns a hash key for the object being + * referenced. This key will be used by higher level hash functions + * to build association lists. Each object type gets to specify + * it's own key formulation + */ + void (*oo_keygen)(struct nl_object *, uint32_t *, uint32_t); + + char *(*oo_attrs2str)(int, char *, size_t); + + /** + * Get key attributes by family function + */ + uint32_t (*oo_id_attrs_get)(struct nl_object *); +}; + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/netlink-private/route/link/api.h b/include/netlink-private/route/link/api.h new file mode 100644 index 0000000..bb98ccc --- /dev/null +++ b/include/netlink-private/route/link/api.h @@ -0,0 +1,153 @@ +/* + * netlink-private/route/link/api.h Link Modules API + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2013 Thomas Graf + */ + +#ifndef NETLINK_LINK_API_H_ +#define NETLINK_LINK_API_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup link_api + * + * Available operations to modules implementing a link info type. + */ +struct rtnl_link_info_ops +{ + /** Name of link info type, must match name on kernel side */ + char * io_name; + + /** Reference count, DO NOT MODIFY */ + int io_refcnt; + + /** Called to assign an info type to a link. + * Has to allocate enough resources to hold attributes. Can + * use link->l_info to store a pointer. */ + int (*io_alloc)(struct rtnl_link *); + + /** Called to parse the link info attribute. + * Must parse the attribute and assign all values to the link. + */ + int (*io_parse)(struct rtnl_link *, + struct nlattr *, + struct nlattr *); + + /** Called when the link object is dumped. + * Must dump the info type specific attributes. */ + void (*io_dump[NL_DUMP_MAX+1])(struct rtnl_link *, + struct nl_dump_params *); + + /** Called when a link object is cloned. + * Must clone all info type specific attributes. */ + int (*io_clone)(struct rtnl_link *, struct rtnl_link *); + + /** Called when construction a link netlink message. + * Must append all info type specific attributes to the message. */ + int (*io_put_attrs)(struct nl_msg *, struct rtnl_link *); + + /** Called to release all resources previously allocated + * in either io_alloc() or io_parse(). */ + void (*io_free)(struct rtnl_link *); + + struct nl_list_head io_list; +}; + +extern struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *); +extern void rtnl_link_info_ops_put(struct rtnl_link_info_ops *); +extern int rtnl_link_register_info(struct rtnl_link_info_ops *); +extern int rtnl_link_unregister_info(struct rtnl_link_info_ops *); + + +/** + * @ingroup link_api + * + * Available operations to modules implementing a link address family. + */ +struct rtnl_link_af_ops +{ + /** The address family this operations set implements */ + const unsigned int ao_family; + + /** Number of users of this operations, DO NOT MODIFY. */ + int ao_refcnt; + + /** Validation policy for IFLA_PROTINFO attribute. This pointer + * can be set to a nla_policy structure describing the minimal + * requirements the attribute must meet. Failure of meeting these + * requirements will result in a parsing error. */ + const struct nla_policy *ao_protinfo_policy; + + /** Called after address family has been assigned to link. Must + * allocate data buffer to hold address family specific data and + * store it in link->l_af_data. */ + void * (*ao_alloc)(struct rtnl_link *); + + /** Called when the link is cloned, must allocate a clone of the + * address family specific buffer and return it. */ + void * (*ao_clone)(struct rtnl_link *, void *); + + /** Called when the link gets freed. Must free all allocated data */ + void (*ao_free)(struct rtnl_link *, void *); + + /** Called if a IFLA_PROTINFO attribute needs to be parsed. Typically + * stores the parsed data in the address family specific buffer. */ + int (*ao_parse_protinfo)(struct rtnl_link *, + struct nlattr *, void *); + + /** Called if a IFLA_AF_SPEC attribute needs to be parsed. Typically + * stores the parsed data in the address family specific buffer. */ + int (*ao_parse_af)(struct rtnl_link *, + struct nlattr *, void *); + + /** Called if a link message is sent to the kernel. Must append the + * link address family specific attributes to the message. */ + int (*ao_fill_af)(struct rtnl_link *, + struct nl_msg *msg, void *); + + /** Dump address family specific link attributes */ + void (*ao_dump[NL_DUMP_MAX+1])(struct rtnl_link *, + struct nl_dump_params *, + void *); + + /** Comparison function + * + * Will be called when two links are compared for their af data. It + * takes two link objects in question, an object specific bitmask + * defining which attributes should be compared and flags to control + * the behaviour + * + * The function must return a bitmask with the relevant bit set for + * each attribute that mismatches + */ + int (*ao_compare)(struct rtnl_link *, + struct rtnl_link *, int, uint32_t, int); +}; + +extern struct rtnl_link_af_ops *rtnl_link_af_ops_lookup(unsigned int); +extern void rtnl_link_af_ops_put(struct rtnl_link_af_ops *); +extern void * rtnl_link_af_alloc(struct rtnl_link *, + const struct rtnl_link_af_ops *); +extern void * rtnl_link_af_data(const struct rtnl_link *, + const struct rtnl_link_af_ops *); +extern int rtnl_link_af_register(struct rtnl_link_af_ops *); +extern int rtnl_link_af_unregister(struct rtnl_link_af_ops *); +extern int rtnl_link_af_data_compare(struct rtnl_link *a, + struct rtnl_link *b, + int family); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/netlink-private/route/tc-api.h b/include/netlink-private/route/tc-api.h new file mode 100644 index 0000000..bf0c8a3 --- /dev/null +++ b/include/netlink-private/route/tc-api.h @@ -0,0 +1,134 @@ +/* + * netlink-private/route/tc-api.h Traffic Control API + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2011-2013 Thomas Graf + */ + +#ifndef NETLINK_TC_API_H_ +#define NETLINK_TC_API_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Traffic control object operations + * @ingroup tc + * + * This structure holds function pointers and settings implementing + * the features of each traffic control object implementation. + */ +struct rtnl_tc_ops +{ + /** + * Name of traffic control module + */ + char *to_kind; + + /** + * Type of traffic control object + */ + enum rtnl_tc_type to_type; + + + /** + * Size of private data + */ + size_t to_size; + + /** + * Dump callbacks + */ + void (*to_dump[NL_DUMP_MAX+1])(struct rtnl_tc *, void *, + struct nl_dump_params *); + /** + * Used to fill the contents of TCA_OPTIONS + */ + int (*to_msg_fill)(struct rtnl_tc *, void *, struct nl_msg *); + + /** + * Uesd to to fill tc related messages, unlike with to_msg_fill, + * the contents is not encapsulated with a TCA_OPTIONS nested + * attribute. + */ + int (*to_msg_fill_raw)(struct rtnl_tc *, void *, struct nl_msg *); + + /** + * TCA_OPTIONS message parser + */ + int (*to_msg_parser)(struct rtnl_tc *, void *); + + /** + * Called before a tc object is destroyed + */ + void (*to_free_data)(struct rtnl_tc *, void *); + + /** + * Called whenever a classifier object needs to be cloned + */ + int (*to_clone)(void *, void *); + + /** + * Internal, don't touch + */ + struct nl_list_head to_list; +}; + +struct rtnl_tc_type_ops +{ + enum rtnl_tc_type tt_type; + + char *tt_dump_prefix; + + /** + * Dump callbacks + */ + void (*tt_dump[NL_DUMP_MAX+1])(struct rtnl_tc *, + struct nl_dump_params *); +}; + +extern int rtnl_tc_msg_parse(struct nlmsghdr *, + struct rtnl_tc *); +extern int rtnl_tc_msg_build(struct rtnl_tc *, int, + int, struct nl_msg **); + +extern void rtnl_tc_free_data(struct nl_object *); +extern int rtnl_tc_clone(struct nl_object *, + struct nl_object *); +extern void rtnl_tc_dump_line(struct nl_object *, + struct nl_dump_params *); +extern void rtnl_tc_dump_details(struct nl_object *, + struct nl_dump_params *); +extern void rtnl_tc_dump_stats(struct nl_object *, + struct nl_dump_params *); +extern int rtnl_tc_compare(struct nl_object *, + struct nl_object *, + uint32_t, int); + +extern void * rtnl_tc_data(struct rtnl_tc *); +extern void * rtnl_tc_data_check(struct rtnl_tc *, + struct rtnl_tc_ops *); + +extern struct rtnl_tc_ops * rtnl_tc_lookup_ops(enum rtnl_tc_type, + const char *); +extern struct rtnl_tc_ops * rtnl_tc_get_ops(struct rtnl_tc *); +extern int rtnl_tc_register(struct rtnl_tc_ops *); +extern void rtnl_tc_unregister(struct rtnl_tc_ops *); + +extern void rtnl_tc_type_register(struct rtnl_tc_type_ops *); +extern void rtnl_tc_type_unregister(struct rtnl_tc_type_ops *); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/netlink-private/tc.h b/include/netlink-private/tc.h new file mode 100644 index 0000000..182adaa --- /dev/null +++ b/include/netlink-private/tc.h @@ -0,0 +1,55 @@ +/* + * netlink-private/tc.h Local Traffic Control Interface + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2013 Thomas Graf + */ + +#ifndef NETLINK_TC_PRIV_H_ +#define NETLINK_TC_PRIV_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define TCA_ATTR_HANDLE 0x0001 +#define TCA_ATTR_PARENT 0x0002 +#define TCA_ATTR_IFINDEX 0x0004 +#define TCA_ATTR_KIND 0x0008 +#define TCA_ATTR_FAMILY 0x0010 +#define TCA_ATTR_INFO 0x0020 +#define TCA_ATTR_OPTS 0x0040 +#define TCA_ATTR_STATS 0x0080 +#define TCA_ATTR_XSTATS 0x0100 +#define TCA_ATTR_LINK 0x0200 +#define TCA_ATTR_MTU 0x0400 +#define TCA_ATTR_MPU 0x0800 +#define TCA_ATTR_OVERHEAD 0x1000 +#define TCA_ATTR_LINKTYPE 0x2000 +#define TCA_ATTR_MAX TCA_ATTR_LINKTYPE + +extern int tca_parse(struct nlattr **, int, struct rtnl_tc *, + struct nla_policy *); + +#define RTNL_TC_RTABLE_SIZE 256 + +extern int rtnl_tc_build_rate_table(struct rtnl_tc *tc, struct rtnl_ratespec *, + uint32_t *); + + +static inline void *tca_xstats(struct rtnl_tc *tca) +{ + return tca->tc_xstats->d_data; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/netlink-private/types.h b/include/netlink-private/types.h new file mode 100644 index 0000000..60a3bce --- /dev/null +++ b/include/netlink-private/types.h @@ -0,0 +1,910 @@ +/* + * netlink-private/types.h Netlink Types (Private) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2013 Thomas Graf + */ + +#ifndef NETLINK_LOCAL_TYPES_H_ +#define NETLINK_LOCAL_TYPES_H_ + +#include +#include +#include +#include +#include +#include + +#define NL_SOCK_BUFSIZE_SET (1<<0) +#define NL_SOCK_PASSCRED (1<<1) +#define NL_OWN_PORT (1<<2) +#define NL_MSG_PEEK (1<<3) +#define NL_NO_AUTO_ACK (1<<4) + +#define NL_MSG_CRED_PRESENT 1 + +struct nl_cache_ops; +struct nl_sock; +struct nl_object; +struct nl_hash_table; + +struct nl_cb +{ + nl_recvmsg_msg_cb_t cb_set[NL_CB_TYPE_MAX+1]; + void * cb_args[NL_CB_TYPE_MAX+1]; + + nl_recvmsg_err_cb_t cb_err; + void * cb_err_arg; + + /** May be used to replace nl_recvmsgs with your own implementation + * in all internal calls to nl_recvmsgs. */ + int (*cb_recvmsgs_ow)(struct nl_sock *, + struct nl_cb *); + + /** Overwrite internal calls to nl_recv, must return the number of + * octets read and allocate a buffer for the received data. */ + int (*cb_recv_ow)(struct nl_sock *, + struct sockaddr_nl *, + unsigned char **, + struct ucred **); + + /** Overwrites internal calls to nl_send, must send the netlink + * message. */ + int (*cb_send_ow)(struct nl_sock *, + struct nl_msg *); + + int cb_refcnt; +}; + +struct nl_sock +{ + struct sockaddr_nl s_local; + struct sockaddr_nl s_peer; + int s_fd; + int s_proto; + unsigned int s_seq_next; + unsigned int s_seq_expect; + int s_flags; + struct nl_cb * s_cb; + size_t s_bufsize; +}; + +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; +}; + +struct nl_cache_assoc +{ + struct nl_cache * ca_cache; + change_func_t ca_change; + void * ca_change_data; +}; + +struct nl_cache_mngr +{ + int cm_protocol; + int cm_flags; + int cm_nassocs; + struct nl_sock * cm_sock; + struct nl_sock * cm_sync_sock; + struct nl_cache_assoc * cm_assocs; +}; + +struct nl_parser_param; + +#define LOOSE_COMPARISON 1 + +#define NL_OBJ_MARK 1 + +struct nl_data +{ + size_t d_size; + void * d_data; +}; + +struct nl_addr +{ + int a_family; + unsigned int a_maxsize; + unsigned int a_len; + int a_prefixlen; + int a_refcnt; + char a_addr[0]; +}; + +struct nl_msg +{ + int nm_protocol; + int nm_flags; + struct sockaddr_nl nm_src; + struct sockaddr_nl nm_dst; + struct ucred nm_creds; + struct nlmsghdr * nm_nlh; + size_t nm_size; + int nm_refcnt; +}; + +struct rtnl_link_map +{ + uint64_t lm_mem_start; + uint64_t lm_mem_end; + uint64_t lm_base_addr; + uint16_t lm_irq; + uint8_t lm_dma; + uint8_t lm_port; +}; + +#define IFQDISCSIZ 32 + +struct rtnl_link +{ + NLHDR_COMMON + + char l_name[IFNAMSIZ]; + uint32_t l_family; + uint32_t l_arptype; + uint32_t l_index; + uint32_t l_flags; + uint32_t l_change; + uint32_t l_mtu; + uint32_t l_link; + uint32_t l_txqlen; + uint32_t l_weight; + uint32_t l_master; + struct nl_addr * l_addr; + struct nl_addr * l_bcast; + char l_qdisc[IFQDISCSIZ]; + struct rtnl_link_map l_map; + uint64_t l_stats[RTNL_LINK_STATS_MAX+1]; + uint32_t l_flag_mask; + uint32_t l_num_vf; + uint8_t l_operstate; + uint8_t l_linkmode; + /* 2 byte hole */ + char * l_info_kind; + struct rtnl_link_info_ops * l_info_ops; + void * l_af_data[AF_MAX]; + void * l_info; + char * l_ifalias; + uint32_t l_promiscuity; + uint32_t l_num_tx_queues; + uint32_t l_num_rx_queues; + uint32_t l_group; + uint8_t l_carrier; +}; + +struct rtnl_ncacheinfo +{ + uint32_t nci_confirmed; /**< Time since neighbour validty was last confirmed */ + uint32_t nci_used; /**< Time since neighbour entry was last ued */ + uint32_t nci_updated; /**< Time since last update */ + uint32_t nci_refcnt; /**< Reference counter */ +}; + + +struct rtnl_neigh +{ + NLHDR_COMMON + uint32_t n_family; + uint32_t n_ifindex; + uint16_t n_state; + uint8_t n_flags; + uint8_t n_type; + struct nl_addr *n_lladdr; + struct nl_addr *n_dst; + uint32_t n_probes; + struct rtnl_ncacheinfo n_cacheinfo; + uint32_t n_state_mask; + uint32_t n_flag_mask; + uint32_t n_master; +}; + + +struct rtnl_addr_cacheinfo +{ + /* Preferred lifetime in seconds */ + uint32_t aci_prefered; + + /* Valid lifetime in seconds */ + uint32_t aci_valid; + + /* Timestamp of creation in 1/100s seince boottime */ + uint32_t aci_cstamp; + + /* Timestamp of last update in 1/100s since boottime */ + uint32_t aci_tstamp; +}; + +struct rtnl_addr +{ + NLHDR_COMMON + + uint8_t a_family; + uint8_t a_prefixlen; + uint8_t a_flags; + uint8_t a_scope; + uint32_t a_ifindex; + + struct nl_addr *a_peer; + struct nl_addr *a_local; + struct nl_addr *a_bcast; + struct nl_addr *a_anycast; + struct nl_addr *a_multicast; + + struct rtnl_addr_cacheinfo a_cacheinfo; + + char a_label[IFNAMSIZ]; + uint32_t a_flag_mask; + struct rtnl_link *a_link; +}; + +struct rtnl_nexthop +{ + uint8_t rtnh_flags; + uint8_t rtnh_flag_mask; + uint8_t rtnh_weight; + /* 1 byte spare */ + uint32_t rtnh_ifindex; + struct nl_addr * rtnh_gateway; + uint32_t ce_mask; /* HACK to support attr macros */ + struct nl_list_head rtnh_list; + uint32_t rtnh_realms; +}; + +struct rtnl_route +{ + NLHDR_COMMON + + uint8_t rt_family; + uint8_t rt_dst_len; + uint8_t rt_src_len; + uint8_t rt_tos; + uint8_t rt_protocol; + uint8_t rt_scope; + uint8_t rt_type; + uint8_t rt_nmetrics; + uint32_t rt_flags; + struct nl_addr * rt_dst; + struct nl_addr * rt_src; + uint32_t rt_table; + uint32_t rt_iif; + uint32_t rt_prio; + uint32_t rt_metrics[RTAX_MAX]; + uint32_t rt_metrics_mask; + uint32_t rt_nr_nh; + struct nl_addr * rt_pref_src; + struct nl_list_head rt_nexthops; + struct rtnl_rtcacheinfo rt_cacheinfo; + uint32_t rt_flag_mask; +}; + +struct rtnl_rule +{ + NLHDR_COMMON + uint8_t r_family; + uint8_t r_action; + uint8_t r_dsfield; /* ipv4 only */ + uint8_t r_unused; + uint32_t r_table; + uint32_t r_flags; + uint32_t r_prio; + uint32_t r_mark; + uint32_t r_mask; + uint32_t r_goto; + uint32_t r_flow; /* ipv4 only */ + struct nl_addr *r_src; + struct nl_addr *r_dst; + char r_iifname[IFNAMSIZ]; + char r_oifname[IFNAMSIZ]; +}; + +struct rtnl_neightbl_parms +{ + /** + * Interface index of the device this parameter set is assigned + * to or 0 for the default set. + */ + uint32_t ntp_ifindex; + + /** + * Number of references to this parameter set. + */ + uint32_t ntp_refcnt; + + /** + * Queue length for pending arp requests, i.e. the number of + * packets which are accepted from other layers while the + * neighbour address is still being resolved + */ + uint32_t ntp_queue_len; + + /** + * Number of requests to send to the user level ARP daemon. + * Specify 0 to disable. + */ + uint32_t ntp_app_probes; + + /** + * Maximum number of retries for unicast solicitation. + */ + uint32_t ntp_ucast_probes; + + /** + * Maximum number of retries for multicast solicitation. + */ + uint32_t ntp_mcast_probes; + + /** + * Base value in milliseconds to ompute reachable time, see RFC2461. + */ + uint64_t ntp_base_reachable_time; + + /** + * Actual reachable time (read-only) + */ + uint64_t ntp_reachable_time; /* secs */ + + /** + * The time in milliseconds between retransmitted Neighbor + * Solicitation messages. + */ + uint64_t ntp_retrans_time; + + /** + * Interval in milliseconds to check for stale neighbour + * entries. + */ + uint64_t ntp_gc_stale_time; /* secs */ + + /** + * Delay in milliseconds for the first time probe if + * the neighbour is reachable. + */ + uint64_t ntp_probe_delay; /* secs */ + + /** + * Maximum delay in milliseconds of an answer to a neighbour + * solicitation message. + */ + uint64_t ntp_anycast_delay; + + /** + * Minimum age in milliseconds before a neighbour entry + * may be replaced. + */ + uint64_t ntp_locktime; + + /** + * Delay in milliseconds before answering to an ARP request + * for which a proxy ARP entry exists. + */ + uint64_t ntp_proxy_delay; + + /** + * Queue length for the delayed proxy arp requests. + */ + uint32_t ntp_proxy_qlen; + + /** + * Mask of available parameter attributes + */ + uint32_t ntp_mask; +}; + +#define NTBLNAMSIZ 32 + +/** + * Neighbour table + * @ingroup neightbl + */ +struct rtnl_neightbl +{ + NLHDR_COMMON + + char nt_name[NTBLNAMSIZ]; + uint32_t nt_family; + uint32_t nt_gc_thresh1; + uint32_t nt_gc_thresh2; + uint32_t nt_gc_thresh3; + uint64_t nt_gc_interval; + struct ndt_config nt_config; + struct rtnl_neightbl_parms nt_parms; + struct ndt_stats nt_stats; +}; + +struct rtnl_ratespec +{ + uint8_t rs_cell_log; + uint16_t rs_overhead; + int16_t rs_cell_align; + uint16_t rs_mpu; + uint32_t rs_rate; +}; + +struct rtnl_tstats +{ + struct { + uint64_t bytes; + uint64_t packets; + } tcs_basic; + + struct { + uint32_t bps; + uint32_t pps; + } tcs_rate_est; + + struct { + uint32_t qlen; + uint32_t backlog; + uint32_t drops; + uint32_t requeues; + uint32_t overlimits; + } tcs_queue; +}; + +#define TCKINDSIZ 32 + +#define NL_TC_GENERIC(pre) \ + NLHDR_COMMON \ + uint32_t pre ##_family; \ + uint32_t pre ##_ifindex; \ + uint32_t pre ##_handle; \ + uint32_t pre ##_parent; \ + uint32_t pre ##_info; \ + uint32_t pre ##_mtu; \ + uint32_t pre ##_mpu; \ + uint32_t pre ##_overhead; \ + uint32_t pre ##_linktype; \ + char pre ##_kind[TCKINDSIZ]; \ + struct nl_data * pre ##_opts; \ + uint64_t pre ##_stats[RTNL_TC_STATS_MAX+1]; \ + struct nl_data * pre ##_xstats; \ + struct nl_data * pre ##_subdata; \ + struct rtnl_link * pre ##_link; \ + struct rtnl_tc_ops * pre ##_ops; \ + enum rtnl_tc_type pre ##_type + +struct rtnl_tc +{ + NL_TC_GENERIC(tc); +}; + +struct rtnl_qdisc +{ + NL_TC_GENERIC(q); +}; + +struct rtnl_class +{ + NL_TC_GENERIC(c); +}; + +struct rtnl_cls +{ + NL_TC_GENERIC(c); + uint16_t c_prio; + uint16_t c_protocol; +}; + +struct rtnl_u32 +{ + uint32_t cu_divisor; + uint32_t cu_hash; + uint32_t cu_classid; + uint32_t cu_link; + struct nl_data * cu_pcnt; + struct nl_data * cu_selector; + struct nl_data * cu_act; + struct nl_data * cu_police; + char cu_indev[IFNAMSIZ]; + int cu_mask; +}; + +struct rtnl_cgroup +{ + struct rtnl_ematch_tree *cg_ematch; + int cg_mask; +}; + +struct rtnl_fw +{ + uint32_t cf_classid; + struct nl_data * cf_act; + struct nl_data * cf_police; + char cf_indev[IFNAMSIZ]; + uint32_t cf_fwmask; + int cf_mask; +}; + +struct rtnl_ematch +{ + uint16_t e_id; + uint16_t e_kind; + uint16_t e_flags; + uint16_t e_index; + size_t e_datalen; + + struct nl_list_head e_childs; + struct nl_list_head e_list; + struct rtnl_ematch_ops *e_ops; + + void * e_data; +}; + +struct rtnl_ematch_tree +{ + uint16_t et_progid; + struct nl_list_head et_list; + +}; + +struct rtnl_dsmark_qdisc +{ + uint16_t qdm_indices; + uint16_t qdm_default_index; + uint32_t qdm_set_tc_index; + uint32_t qdm_mask; +}; + +struct rtnl_dsmark_class +{ + uint8_t cdm_bmask; + uint8_t cdm_value; + uint32_t cdm_mask; +}; + +struct rtnl_fifo +{ + uint32_t qf_limit; + uint32_t qf_mask; +}; + +struct rtnl_prio +{ + uint32_t qp_bands; + uint8_t qp_priomap[TC_PRIO_MAX+1]; + uint32_t qp_mask; +}; + +struct rtnl_tbf +{ + uint32_t qt_limit; + struct rtnl_ratespec qt_rate; + uint32_t qt_rate_bucket; + uint32_t qt_rate_txtime; + struct rtnl_ratespec qt_peakrate; + uint32_t qt_peakrate_bucket; + uint32_t qt_peakrate_txtime; + uint32_t qt_mask; +}; + +struct rtnl_sfq +{ + uint32_t qs_quantum; + uint32_t qs_perturb; + uint32_t qs_limit; + uint32_t qs_divisor; + uint32_t qs_flows; + uint32_t qs_mask; +}; + +struct rtnl_netem_corr +{ + uint32_t nmc_delay; + uint32_t nmc_loss; + uint32_t nmc_duplicate; +}; + +struct rtnl_netem_reo +{ + uint32_t nmro_probability; + uint32_t nmro_correlation; +}; + +struct rtnl_netem_crpt +{ + uint32_t nmcr_probability; + uint32_t nmcr_correlation; +}; + +struct rtnl_netem_dist +{ + int16_t * dist_data; + size_t dist_size; +}; + +struct rtnl_netem +{ + uint32_t qnm_latency; + uint32_t qnm_limit; + uint32_t qnm_loss; + uint32_t qnm_gap; + uint32_t qnm_duplicate; + uint32_t qnm_jitter; + uint32_t qnm_mask; + struct rtnl_netem_corr qnm_corr; + struct rtnl_netem_reo qnm_ro; + struct rtnl_netem_crpt qnm_crpt; + struct rtnl_netem_dist qnm_dist; +}; + +struct rtnl_htb_qdisc +{ + uint32_t qh_rate2quantum; + uint32_t qh_defcls; + uint32_t qh_mask; + uint32_t qh_direct_pkts; +}; + +struct rtnl_htb_class +{ + uint32_t ch_prio; + struct rtnl_ratespec ch_rate; + struct rtnl_ratespec ch_ceil; + uint32_t ch_rbuffer; + uint32_t ch_cbuffer; + uint32_t ch_quantum; + uint32_t ch_mask; + uint32_t ch_level; +}; + +struct rtnl_cbq +{ + struct tc_cbq_lssopt cbq_lss; + struct tc_ratespec cbq_rate; + struct tc_cbq_wrropt cbq_wrr; + struct tc_cbq_ovl cbq_ovl; + struct tc_cbq_fopt cbq_fopt; + struct tc_cbq_police cbq_police; +}; + +struct rtnl_red +{ + uint32_t qr_limit; + uint32_t qr_qth_min; + uint32_t qr_qth_max; + uint8_t qr_flags; + uint8_t qr_wlog; + uint8_t qr_plog; + uint8_t qr_scell_log; + uint32_t qr_mask; +}; + +struct rtnl_plug +{ + int action; + uint32_t limit; +}; + +struct flnl_request +{ + NLHDR_COMMON + + struct nl_addr * lr_addr; + uint32_t lr_fwmark; + uint8_t lr_tos; + uint8_t lr_scope; + uint8_t lr_table; +}; + + +struct flnl_result +{ + NLHDR_COMMON + + struct flnl_request * fr_req; + uint8_t fr_table_id; + uint8_t fr_prefixlen; + uint8_t fr_nh_sel; + uint8_t fr_type; + uint8_t fr_scope; + uint32_t fr_error; +}; + +#define GENL_OP_HAS_POLICY 1 +#define GENL_OP_HAS_DOIT 2 +#define GENL_OP_HAS_DUMPIT 4 + +struct genl_family_op +{ + uint32_t o_id; + uint32_t o_flags; + + struct nl_list_head o_list; +}; + +struct genl_family_grp { + struct genl_family *family; /* private */ + struct nl_list_head list; /* private */ + char name[GENL_NAMSIZ]; + u_int32_t id; +}; + +struct genl_family +{ + NLHDR_COMMON + + uint16_t gf_id; + char gf_name[GENL_NAMSIZ]; + uint32_t gf_version; + uint32_t gf_hdrsize; + uint32_t gf_maxattr; + + struct nl_list_head gf_ops; + struct nl_list_head gf_mc_grps; +}; + +union nfnl_ct_proto +{ + struct { + uint16_t src; + uint16_t dst; + } port; + struct { + uint16_t id; + uint8_t type; + uint8_t code; + } icmp; +}; + +struct nfnl_ct_dir { + struct nl_addr * src; + struct nl_addr * dst; + union nfnl_ct_proto proto; + uint64_t packets; + uint64_t bytes; +}; + +union nfnl_ct_protoinfo { + struct { + uint8_t state; + } tcp; +}; + +struct nfnl_ct { + NLHDR_COMMON + + uint8_t ct_family; + uint8_t ct_proto; + union nfnl_ct_protoinfo ct_protoinfo; + + uint32_t ct_status; + uint32_t ct_status_mask; + uint32_t ct_timeout; + uint32_t ct_mark; + uint32_t ct_use; + uint32_t ct_id; + + struct nfnl_ct_dir ct_orig; + struct nfnl_ct_dir ct_repl; +}; + +union nfnl_exp_protodata { + struct { + uint16_t src; + uint16_t dst; + } port; + struct { + uint16_t id; + uint8_t type; + uint8_t code; + } icmp; +}; + +// Allow for different master/expect l4 protocols +struct nfnl_exp_proto +{ + uint8_t l4protonum; + union nfnl_exp_protodata l4protodata; +}; + +struct nfnl_exp_dir { + struct nl_addr * src; + struct nl_addr * dst; + struct nfnl_exp_proto proto; +}; + +struct nfnl_exp { + NLHDR_COMMON + + uint8_t exp_family; + uint32_t exp_timeout; + uint32_t exp_id; + uint16_t exp_zone; + uint32_t exp_class; + uint32_t exp_flags; + char * exp_helper_name; + char * exp_fn; + uint8_t exp_nat_dir; + + struct nfnl_exp_dir exp_expect; + struct nfnl_exp_dir exp_master; + struct nfnl_exp_dir exp_mask; + struct nfnl_exp_dir exp_nat; +}; + +struct nfnl_log { + NLHDR_COMMON + + uint16_t log_group; + uint8_t log_copy_mode; + uint32_t log_copy_range; + uint32_t log_flush_timeout; + uint32_t log_alloc_size; + uint32_t log_queue_threshold; + uint32_t log_flags; + uint32_t log_flag_mask; +}; + +struct nfnl_log_msg { + NLHDR_COMMON + + uint8_t log_msg_family; + uint8_t log_msg_hook; + uint16_t log_msg_hwproto; + uint32_t log_msg_mark; + struct timeval log_msg_timestamp; + uint32_t log_msg_indev; + uint32_t log_msg_outdev; + uint32_t log_msg_physindev; + uint32_t log_msg_physoutdev; + uint8_t log_msg_hwaddr[8]; + int log_msg_hwaddr_len; + void * log_msg_payload; + int log_msg_payload_len; + char * log_msg_prefix; + uint32_t log_msg_uid; + uint32_t log_msg_gid; + uint32_t log_msg_seq; + uint32_t log_msg_seq_global; +}; + +struct nfnl_queue { + NLHDR_COMMON + + uint16_t queue_group; + uint32_t queue_maxlen; + uint32_t queue_copy_range; + uint8_t queue_copy_mode; +}; + +struct nfnl_queue_msg { + NLHDR_COMMON + + uint16_t queue_msg_group; + uint8_t queue_msg_family; + uint8_t queue_msg_hook; + uint16_t queue_msg_hwproto; + uint32_t queue_msg_packetid; + uint32_t queue_msg_mark; + struct timeval queue_msg_timestamp; + uint32_t queue_msg_indev; + uint32_t queue_msg_outdev; + uint32_t queue_msg_physindev; + uint32_t queue_msg_physoutdev; + uint8_t queue_msg_hwaddr[8]; + int queue_msg_hwaddr_len; + void * queue_msg_payload; + int queue_msg_payload_len; + uint32_t queue_msg_verdict; +}; + +struct ematch_quoted { + char * data; + size_t len; + int index; +}; + +#endif diff --git a/include/netlink-tc.h b/include/netlink-tc.h deleted file mode 100644 index 3e44642..0000000 --- a/include/netlink-tc.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * netlink-tc.h Local Traffic Control Interface - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * Copyright (c) 2003-2010 Thomas Graf - */ - -#ifndef NETLINK_TC_PRIV_H_ -#define NETLINK_TC_PRIV_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define TCA_ATTR_HANDLE 0x0001 -#define TCA_ATTR_PARENT 0x0002 -#define TCA_ATTR_IFINDEX 0x0004 -#define TCA_ATTR_KIND 0x0008 -#define TCA_ATTR_FAMILY 0x0010 -#define TCA_ATTR_INFO 0x0020 -#define TCA_ATTR_OPTS 0x0040 -#define TCA_ATTR_STATS 0x0080 -#define TCA_ATTR_XSTATS 0x0100 -#define TCA_ATTR_LINK 0x0200 -#define TCA_ATTR_MTU 0x0400 -#define TCA_ATTR_MPU 0x0800 -#define TCA_ATTR_OVERHEAD 0x1000 -#define TCA_ATTR_LINKTYPE 0x2000 -#define TCA_ATTR_MAX TCA_ATTR_LINKTYPE - -extern int tca_parse(struct nlattr **, int, struct rtnl_tc *, - struct nla_policy *); - -#define RTNL_TC_RTABLE_SIZE 256 - -extern int rtnl_tc_build_rate_table(struct rtnl_tc *tc, struct rtnl_ratespec *, - uint32_t *); - - -static inline void *tca_xstats(struct rtnl_tc *tca) -{ - return tca->tc_xstats->d_data; -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/netlink-types.h b/include/netlink-types.h deleted file mode 100644 index 46856a3..0000000 --- a/include/netlink-types.h +++ /dev/null @@ -1,910 +0,0 @@ -/* - * netlink-types.h Netlink Types (Private) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * Copyright (c) 2003-2012 Thomas Graf - */ - -#ifndef NETLINK_LOCAL_TYPES_H_ -#define NETLINK_LOCAL_TYPES_H_ - -#include -#include -#include -#include -#include -#include - -#define NL_SOCK_BUFSIZE_SET (1<<0) -#define NL_SOCK_PASSCRED (1<<1) -#define NL_OWN_PORT (1<<2) -#define NL_MSG_PEEK (1<<3) -#define NL_NO_AUTO_ACK (1<<4) - -#define NL_MSG_CRED_PRESENT 1 - -struct nl_cache_ops; -struct nl_sock; -struct nl_object; -struct nl_hash_table; - -struct nl_cb -{ - nl_recvmsg_msg_cb_t cb_set[NL_CB_TYPE_MAX+1]; - void * cb_args[NL_CB_TYPE_MAX+1]; - - nl_recvmsg_err_cb_t cb_err; - void * cb_err_arg; - - /** May be used to replace nl_recvmsgs with your own implementation - * in all internal calls to nl_recvmsgs. */ - int (*cb_recvmsgs_ow)(struct nl_sock *, - struct nl_cb *); - - /** Overwrite internal calls to nl_recv, must return the number of - * octets read and allocate a buffer for the received data. */ - int (*cb_recv_ow)(struct nl_sock *, - struct sockaddr_nl *, - unsigned char **, - struct ucred **); - - /** Overwrites internal calls to nl_send, must send the netlink - * message. */ - int (*cb_send_ow)(struct nl_sock *, - struct nl_msg *); - - int cb_refcnt; -}; - -struct nl_sock -{ - struct sockaddr_nl s_local; - struct sockaddr_nl s_peer; - int s_fd; - int s_proto; - unsigned int s_seq_next; - unsigned int s_seq_expect; - int s_flags; - struct nl_cb * s_cb; - size_t s_bufsize; -}; - -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; -}; - -struct nl_cache_assoc -{ - struct nl_cache * ca_cache; - change_func_t ca_change; - void * ca_change_data; -}; - -struct nl_cache_mngr -{ - int cm_protocol; - int cm_flags; - int cm_nassocs; - struct nl_sock * cm_sock; - struct nl_sock * cm_sync_sock; - struct nl_cache_assoc * cm_assocs; -}; - -struct nl_parser_param; - -#define LOOSE_COMPARISON 1 - -#define NL_OBJ_MARK 1 - -struct nl_data -{ - size_t d_size; - void * d_data; -}; - -struct nl_addr -{ - int a_family; - unsigned int a_maxsize; - unsigned int a_len; - int a_prefixlen; - int a_refcnt; - char a_addr[0]; -}; - -struct nl_msg -{ - int nm_protocol; - int nm_flags; - struct sockaddr_nl nm_src; - struct sockaddr_nl nm_dst; - struct ucred nm_creds; - struct nlmsghdr * nm_nlh; - size_t nm_size; - int nm_refcnt; -}; - -struct rtnl_link_map -{ - uint64_t lm_mem_start; - uint64_t lm_mem_end; - uint64_t lm_base_addr; - uint16_t lm_irq; - uint8_t lm_dma; - uint8_t lm_port; -}; - -#define IFQDISCSIZ 32 - -struct rtnl_link -{ - NLHDR_COMMON - - char l_name[IFNAMSIZ]; - uint32_t l_family; - uint32_t l_arptype; - uint32_t l_index; - uint32_t l_flags; - uint32_t l_change; - uint32_t l_mtu; - uint32_t l_link; - uint32_t l_txqlen; - uint32_t l_weight; - uint32_t l_master; - struct nl_addr * l_addr; - struct nl_addr * l_bcast; - char l_qdisc[IFQDISCSIZ]; - struct rtnl_link_map l_map; - uint64_t l_stats[RTNL_LINK_STATS_MAX+1]; - uint32_t l_flag_mask; - uint32_t l_num_vf; - uint8_t l_operstate; - uint8_t l_linkmode; - /* 2 byte hole */ - char * l_info_kind; - struct rtnl_link_info_ops * l_info_ops; - void * l_af_data[AF_MAX]; - void * l_info; - char * l_ifalias; - uint32_t l_promiscuity; - uint32_t l_num_tx_queues; - uint32_t l_num_rx_queues; - uint32_t l_group; - uint8_t l_carrier; -}; - -struct rtnl_ncacheinfo -{ - uint32_t nci_confirmed; /**< Time since neighbour validty was last confirmed */ - uint32_t nci_used; /**< Time since neighbour entry was last ued */ - uint32_t nci_updated; /**< Time since last update */ - uint32_t nci_refcnt; /**< Reference counter */ -}; - - -struct rtnl_neigh -{ - NLHDR_COMMON - uint32_t n_family; - uint32_t n_ifindex; - uint16_t n_state; - uint8_t n_flags; - uint8_t n_type; - struct nl_addr *n_lladdr; - struct nl_addr *n_dst; - uint32_t n_probes; - struct rtnl_ncacheinfo n_cacheinfo; - uint32_t n_state_mask; - uint32_t n_flag_mask; - uint32_t n_master; -}; - - -struct rtnl_addr_cacheinfo -{ - /* Preferred lifetime in seconds */ - uint32_t aci_prefered; - - /* Valid lifetime in seconds */ - uint32_t aci_valid; - - /* Timestamp of creation in 1/100s seince boottime */ - uint32_t aci_cstamp; - - /* Timestamp of last update in 1/100s since boottime */ - uint32_t aci_tstamp; -}; - -struct rtnl_addr -{ - NLHDR_COMMON - - uint8_t a_family; - uint8_t a_prefixlen; - uint8_t a_flags; - uint8_t a_scope; - uint32_t a_ifindex; - - struct nl_addr *a_peer; - struct nl_addr *a_local; - struct nl_addr *a_bcast; - struct nl_addr *a_anycast; - struct nl_addr *a_multicast; - - struct rtnl_addr_cacheinfo a_cacheinfo; - - char a_label[IFNAMSIZ]; - uint32_t a_flag_mask; - struct rtnl_link *a_link; -}; - -struct rtnl_nexthop -{ - uint8_t rtnh_flags; - uint8_t rtnh_flag_mask; - uint8_t rtnh_weight; - /* 1 byte spare */ - uint32_t rtnh_ifindex; - struct nl_addr * rtnh_gateway; - uint32_t ce_mask; /* HACK to support attr macros */ - struct nl_list_head rtnh_list; - uint32_t rtnh_realms; -}; - -struct rtnl_route -{ - NLHDR_COMMON - - uint8_t rt_family; - uint8_t rt_dst_len; - uint8_t rt_src_len; - uint8_t rt_tos; - uint8_t rt_protocol; - uint8_t rt_scope; - uint8_t rt_type; - uint8_t rt_nmetrics; - uint32_t rt_flags; - struct nl_addr * rt_dst; - struct nl_addr * rt_src; - uint32_t rt_table; - uint32_t rt_iif; - uint32_t rt_prio; - uint32_t rt_metrics[RTAX_MAX]; - uint32_t rt_metrics_mask; - uint32_t rt_nr_nh; - struct nl_addr * rt_pref_src; - struct nl_list_head rt_nexthops; - struct rtnl_rtcacheinfo rt_cacheinfo; - uint32_t rt_flag_mask; -}; - -struct rtnl_rule -{ - NLHDR_COMMON - uint8_t r_family; - uint8_t r_action; - uint8_t r_dsfield; /* ipv4 only */ - uint8_t r_unused; - uint32_t r_table; - uint32_t r_flags; - uint32_t r_prio; - uint32_t r_mark; - uint32_t r_mask; - uint32_t r_goto; - uint32_t r_flow; /* ipv4 only */ - struct nl_addr *r_src; - struct nl_addr *r_dst; - char r_iifname[IFNAMSIZ]; - char r_oifname[IFNAMSIZ]; -}; - -struct rtnl_neightbl_parms -{ - /** - * Interface index of the device this parameter set is assigned - * to or 0 for the default set. - */ - uint32_t ntp_ifindex; - - /** - * Number of references to this parameter set. - */ - uint32_t ntp_refcnt; - - /** - * Queue length for pending arp requests, i.e. the number of - * packets which are accepted from other layers while the - * neighbour address is still being resolved - */ - uint32_t ntp_queue_len; - - /** - * Number of requests to send to the user level ARP daemon. - * Specify 0 to disable. - */ - uint32_t ntp_app_probes; - - /** - * Maximum number of retries for unicast solicitation. - */ - uint32_t ntp_ucast_probes; - - /** - * Maximum number of retries for multicast solicitation. - */ - uint32_t ntp_mcast_probes; - - /** - * Base value in milliseconds to ompute reachable time, see RFC2461. - */ - uint64_t ntp_base_reachable_time; - - /** - * Actual reachable time (read-only) - */ - uint64_t ntp_reachable_time; /* secs */ - - /** - * The time in milliseconds between retransmitted Neighbor - * Solicitation messages. - */ - uint64_t ntp_retrans_time; - - /** - * Interval in milliseconds to check for stale neighbour - * entries. - */ - uint64_t ntp_gc_stale_time; /* secs */ - - /** - * Delay in milliseconds for the first time probe if - * the neighbour is reachable. - */ - uint64_t ntp_probe_delay; /* secs */ - - /** - * Maximum delay in milliseconds of an answer to a neighbour - * solicitation message. - */ - uint64_t ntp_anycast_delay; - - /** - * Minimum age in milliseconds before a neighbour entry - * may be replaced. - */ - uint64_t ntp_locktime; - - /** - * Delay in milliseconds before answering to an ARP request - * for which a proxy ARP entry exists. - */ - uint64_t ntp_proxy_delay; - - /** - * Queue length for the delayed proxy arp requests. - */ - uint32_t ntp_proxy_qlen; - - /** - * Mask of available parameter attributes - */ - uint32_t ntp_mask; -}; - -#define NTBLNAMSIZ 32 - -/** - * Neighbour table - * @ingroup neightbl - */ -struct rtnl_neightbl -{ - NLHDR_COMMON - - char nt_name[NTBLNAMSIZ]; - uint32_t nt_family; - uint32_t nt_gc_thresh1; - uint32_t nt_gc_thresh2; - uint32_t nt_gc_thresh3; - uint64_t nt_gc_interval; - struct ndt_config nt_config; - struct rtnl_neightbl_parms nt_parms; - struct ndt_stats nt_stats; -}; - -struct rtnl_ratespec -{ - uint8_t rs_cell_log; - uint16_t rs_overhead; - int16_t rs_cell_align; - uint16_t rs_mpu; - uint32_t rs_rate; -}; - -struct rtnl_tstats -{ - struct { - uint64_t bytes; - uint64_t packets; - } tcs_basic; - - struct { - uint32_t bps; - uint32_t pps; - } tcs_rate_est; - - struct { - uint32_t qlen; - uint32_t backlog; - uint32_t drops; - uint32_t requeues; - uint32_t overlimits; - } tcs_queue; -}; - -#define TCKINDSIZ 32 - -#define NL_TC_GENERIC(pre) \ - NLHDR_COMMON \ - uint32_t pre ##_family; \ - uint32_t pre ##_ifindex; \ - uint32_t pre ##_handle; \ - uint32_t pre ##_parent; \ - uint32_t pre ##_info; \ - uint32_t pre ##_mtu; \ - uint32_t pre ##_mpu; \ - uint32_t pre ##_overhead; \ - uint32_t pre ##_linktype; \ - char pre ##_kind[TCKINDSIZ]; \ - struct nl_data * pre ##_opts; \ - uint64_t pre ##_stats[RTNL_TC_STATS_MAX+1]; \ - struct nl_data * pre ##_xstats; \ - struct nl_data * pre ##_subdata; \ - struct rtnl_link * pre ##_link; \ - struct rtnl_tc_ops * pre ##_ops; \ - enum rtnl_tc_type pre ##_type - -struct rtnl_tc -{ - NL_TC_GENERIC(tc); -}; - -struct rtnl_qdisc -{ - NL_TC_GENERIC(q); -}; - -struct rtnl_class -{ - NL_TC_GENERIC(c); -}; - -struct rtnl_cls -{ - NL_TC_GENERIC(c); - uint16_t c_prio; - uint16_t c_protocol; -}; - -struct rtnl_u32 -{ - uint32_t cu_divisor; - uint32_t cu_hash; - uint32_t cu_classid; - uint32_t cu_link; - struct nl_data * cu_pcnt; - struct nl_data * cu_selector; - struct nl_data * cu_act; - struct nl_data * cu_police; - char cu_indev[IFNAMSIZ]; - int cu_mask; -}; - -struct rtnl_cgroup -{ - struct rtnl_ematch_tree *cg_ematch; - int cg_mask; -}; - -struct rtnl_fw -{ - uint32_t cf_classid; - struct nl_data * cf_act; - struct nl_data * cf_police; - char cf_indev[IFNAMSIZ]; - uint32_t cf_fwmask; - int cf_mask; -}; - -struct rtnl_ematch -{ - uint16_t e_id; - uint16_t e_kind; - uint16_t e_flags; - uint16_t e_index; - size_t e_datalen; - - struct nl_list_head e_childs; - struct nl_list_head e_list; - struct rtnl_ematch_ops *e_ops; - - void * e_data; -}; - -struct rtnl_ematch_tree -{ - uint16_t et_progid; - struct nl_list_head et_list; - -}; - -struct rtnl_dsmark_qdisc -{ - uint16_t qdm_indices; - uint16_t qdm_default_index; - uint32_t qdm_set_tc_index; - uint32_t qdm_mask; -}; - -struct rtnl_dsmark_class -{ - uint8_t cdm_bmask; - uint8_t cdm_value; - uint32_t cdm_mask; -}; - -struct rtnl_fifo -{ - uint32_t qf_limit; - uint32_t qf_mask; -}; - -struct rtnl_prio -{ - uint32_t qp_bands; - uint8_t qp_priomap[TC_PRIO_MAX+1]; - uint32_t qp_mask; -}; - -struct rtnl_tbf -{ - uint32_t qt_limit; - struct rtnl_ratespec qt_rate; - uint32_t qt_rate_bucket; - uint32_t qt_rate_txtime; - struct rtnl_ratespec qt_peakrate; - uint32_t qt_peakrate_bucket; - uint32_t qt_peakrate_txtime; - uint32_t qt_mask; -}; - -struct rtnl_sfq -{ - uint32_t qs_quantum; - uint32_t qs_perturb; - uint32_t qs_limit; - uint32_t qs_divisor; - uint32_t qs_flows; - uint32_t qs_mask; -}; - -struct rtnl_netem_corr -{ - uint32_t nmc_delay; - uint32_t nmc_loss; - uint32_t nmc_duplicate; -}; - -struct rtnl_netem_reo -{ - uint32_t nmro_probability; - uint32_t nmro_correlation; -}; - -struct rtnl_netem_crpt -{ - uint32_t nmcr_probability; - uint32_t nmcr_correlation; -}; - -struct rtnl_netem_dist -{ - int16_t * dist_data; - size_t dist_size; -}; - -struct rtnl_netem -{ - uint32_t qnm_latency; - uint32_t qnm_limit; - uint32_t qnm_loss; - uint32_t qnm_gap; - uint32_t qnm_duplicate; - uint32_t qnm_jitter; - uint32_t qnm_mask; - struct rtnl_netem_corr qnm_corr; - struct rtnl_netem_reo qnm_ro; - struct rtnl_netem_crpt qnm_crpt; - struct rtnl_netem_dist qnm_dist; -}; - -struct rtnl_htb_qdisc -{ - uint32_t qh_rate2quantum; - uint32_t qh_defcls; - uint32_t qh_mask; - uint32_t qh_direct_pkts; -}; - -struct rtnl_htb_class -{ - uint32_t ch_prio; - struct rtnl_ratespec ch_rate; - struct rtnl_ratespec ch_ceil; - uint32_t ch_rbuffer; - uint32_t ch_cbuffer; - uint32_t ch_quantum; - uint32_t ch_mask; - uint32_t ch_level; -}; - -struct rtnl_cbq -{ - struct tc_cbq_lssopt cbq_lss; - struct tc_ratespec cbq_rate; - struct tc_cbq_wrropt cbq_wrr; - struct tc_cbq_ovl cbq_ovl; - struct tc_cbq_fopt cbq_fopt; - struct tc_cbq_police cbq_police; -}; - -struct rtnl_red -{ - uint32_t qr_limit; - uint32_t qr_qth_min; - uint32_t qr_qth_max; - uint8_t qr_flags; - uint8_t qr_wlog; - uint8_t qr_plog; - uint8_t qr_scell_log; - uint32_t qr_mask; -}; - -struct rtnl_plug -{ - int action; - uint32_t limit; -}; - -struct flnl_request -{ - NLHDR_COMMON - - struct nl_addr * lr_addr; - uint32_t lr_fwmark; - uint8_t lr_tos; - uint8_t lr_scope; - uint8_t lr_table; -}; - - -struct flnl_result -{ - NLHDR_COMMON - - struct flnl_request * fr_req; - uint8_t fr_table_id; - uint8_t fr_prefixlen; - uint8_t fr_nh_sel; - uint8_t fr_type; - uint8_t fr_scope; - uint32_t fr_error; -}; - -#define GENL_OP_HAS_POLICY 1 -#define GENL_OP_HAS_DOIT 2 -#define GENL_OP_HAS_DUMPIT 4 - -struct genl_family_op -{ - uint32_t o_id; - uint32_t o_flags; - - struct nl_list_head o_list; -}; - -struct genl_family_grp { - struct genl_family *family; /* private */ - struct nl_list_head list; /* private */ - char name[GENL_NAMSIZ]; - u_int32_t id; -}; - -struct genl_family -{ - NLHDR_COMMON - - uint16_t gf_id; - char gf_name[GENL_NAMSIZ]; - uint32_t gf_version; - uint32_t gf_hdrsize; - uint32_t gf_maxattr; - - struct nl_list_head gf_ops; - struct nl_list_head gf_mc_grps; -}; - -union nfnl_ct_proto -{ - struct { - uint16_t src; - uint16_t dst; - } port; - struct { - uint16_t id; - uint8_t type; - uint8_t code; - } icmp; -}; - -struct nfnl_ct_dir { - struct nl_addr * src; - struct nl_addr * dst; - union nfnl_ct_proto proto; - uint64_t packets; - uint64_t bytes; -}; - -union nfnl_ct_protoinfo { - struct { - uint8_t state; - } tcp; -}; - -struct nfnl_ct { - NLHDR_COMMON - - uint8_t ct_family; - uint8_t ct_proto; - union nfnl_ct_protoinfo ct_protoinfo; - - uint32_t ct_status; - uint32_t ct_status_mask; - uint32_t ct_timeout; - uint32_t ct_mark; - uint32_t ct_use; - uint32_t ct_id; - - struct nfnl_ct_dir ct_orig; - struct nfnl_ct_dir ct_repl; -}; - -union nfnl_exp_protodata { - struct { - uint16_t src; - uint16_t dst; - } port; - struct { - uint16_t id; - uint8_t type; - uint8_t code; - } icmp; -}; - -// Allow for different master/expect l4 protocols -struct nfnl_exp_proto -{ - uint8_t l4protonum; - union nfnl_exp_protodata l4protodata; -}; - -struct nfnl_exp_dir { - struct nl_addr * src; - struct nl_addr * dst; - struct nfnl_exp_proto proto; -}; - -struct nfnl_exp { - NLHDR_COMMON - - uint8_t exp_family; - uint32_t exp_timeout; - uint32_t exp_id; - uint16_t exp_zone; - uint32_t exp_class; - uint32_t exp_flags; - char * exp_helper_name; - char * exp_fn; - uint8_t exp_nat_dir; - - struct nfnl_exp_dir exp_expect; - struct nfnl_exp_dir exp_master; - struct nfnl_exp_dir exp_mask; - struct nfnl_exp_dir exp_nat; -}; - -struct nfnl_log { - NLHDR_COMMON - - uint16_t log_group; - uint8_t log_copy_mode; - uint32_t log_copy_range; - uint32_t log_flush_timeout; - uint32_t log_alloc_size; - uint32_t log_queue_threshold; - uint32_t log_flags; - uint32_t log_flag_mask; -}; - -struct nfnl_log_msg { - NLHDR_COMMON - - uint8_t log_msg_family; - uint8_t log_msg_hook; - uint16_t log_msg_hwproto; - uint32_t log_msg_mark; - struct timeval log_msg_timestamp; - uint32_t log_msg_indev; - uint32_t log_msg_outdev; - uint32_t log_msg_physindev; - uint32_t log_msg_physoutdev; - uint8_t log_msg_hwaddr[8]; - int log_msg_hwaddr_len; - void * log_msg_payload; - int log_msg_payload_len; - char * log_msg_prefix; - uint32_t log_msg_uid; - uint32_t log_msg_gid; - uint32_t log_msg_seq; - uint32_t log_msg_seq_global; -}; - -struct nfnl_queue { - NLHDR_COMMON - - uint16_t queue_group; - uint32_t queue_maxlen; - uint32_t queue_copy_range; - uint8_t queue_copy_mode; -}; - -struct nfnl_queue_msg { - NLHDR_COMMON - - uint16_t queue_msg_group; - uint8_t queue_msg_family; - uint8_t queue_msg_hook; - uint16_t queue_msg_hwproto; - uint32_t queue_msg_packetid; - uint32_t queue_msg_mark; - struct timeval queue_msg_timestamp; - uint32_t queue_msg_indev; - uint32_t queue_msg_outdev; - uint32_t queue_msg_physindev; - uint32_t queue_msg_physoutdev; - uint8_t queue_msg_hwaddr[8]; - int queue_msg_hwaddr_len; - void * queue_msg_payload; - int queue_msg_payload_len; - uint32_t queue_msg_verdict; -}; - -struct ematch_quoted { - char * data; - size_t len; - int index; -}; - -#endif diff --git a/include/netlink/cache-api.h b/include/netlink/cache-api.h deleted file mode 100644 index 493a551..0000000 --- a/include/netlink/cache-api.h +++ /dev/null @@ -1,285 +0,0 @@ -/* - * netlink/cache-api.h Caching API - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * Copyright (c) 2003-2012 Thomas Graf - */ - -#ifndef NETLINK_CACHE_API_H_ -#define NETLINK_CACHE_API_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @ingroup cache - * @defgroup cache_api Cache Implementation - * @brief - * - * @par 1) Cache Definition - * @code - * struct nl_cache_ops my_cache_ops = { - * .co_name = "route/link", - * .co_protocol = NETLINK_ROUTE, - * .co_hdrsize = sizeof(struct ifinfomsg), - * .co_obj_ops = &my_obj_ops, - * }; - * @endcode - * - * @par 2) - * @code - * // The simplest way to fill a cache is by providing a request-update - * // function which must trigger a complete dump on the kernel-side of - * // whatever the cache covers. - * static int my_request_update(struct nl_cache *cache, - * struct nl_sock *socket) - * { - * // In this example, we request a full dump of the interface table - * return nl_rtgen_request(socket, RTM_GETLINK, AF_UNSPEC, NLM_F_DUMP); - * } - * - * // The resulting netlink messages sent back will be fed into a message - * // parser one at a time. The message parser has to extract all relevant - * // information from the message and create an object reflecting the - * // contents of the message and pass it on to the parser callback function - * // provide which will add the object to the cache. - * static int my_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who, - * struct nlmsghdr *nlh, struct nl_parser_param *pp) - * { - * struct my_obj *obj; - * - * obj = my_obj_alloc(); - * obj->ce_msgtype = nlh->nlmsg_type; - * - * // Parse the netlink message and continue creating the object. - * - * err = pp->pp_cb((struct nl_object *) obj, pp); - * if (err < 0) - * goto errout; - * } - * - * struct nl_cache_ops my_cache_ops = { - * ... - * .co_request_update = my_request_update, - * .co_msg_parser = my_msg_parser, - * }; - * @endcode - * - * @par 3) Notification based Updates - * @code - * // Caches can be kept up-to-date based on notifications if the kernel - * // sends out notifications whenever an object is added/removed/changed. - * // - * // It is trivial to support this, first a list of groups needs to be - * // defined which are required to join in order to receive all necessary - * // notifications. The groups are separated by address family to support - * // the common situation where a separate group is used for each address - * // family. If there is only one group, simply specify AF_UNSPEC. - * static struct nl_af_group addr_groups[] = { - * { AF_INET, RTNLGRP_IPV4_IFADDR }, - * { AF_INET6, RTNLGRP_IPV6_IFADDR }, - * { END_OF_GROUP_LIST }, - * }; - * - * // In order for the caching system to know the meaning of each message - * // type it requires a table which maps each supported message type to - * // a cache action, e.g. RTM_NEWADDR means address has been added or - * // updated, RTM_DELADDR means address has been removed. - * static struct nl_cache_ops rtnl_addr_ops = { - * ... - * .co_msgtypes = { - * { RTM_NEWADDR, NL_ACT_NEW, "new" }, - * { RTM_DELADDR, NL_ACT_DEL, "del" }, - * { RTM_GETADDR, NL_ACT_GET, "get" }, - * END_OF_MSGTYPES_LIST, - * }, - * .co_groups = addr_groups, - * }; - * - * // It is now possible to keep the cache up-to-date using the cache manager. - * @endcode - * @{ - */ - -enum { - NL_ACT_UNSPEC, - NL_ACT_NEW, - NL_ACT_DEL, - NL_ACT_GET, - NL_ACT_SET, - NL_ACT_CHANGE, - __NL_ACT_MAX, -}; - -#define NL_ACT_MAX (__NL_ACT_MAX - 1) - -#define END_OF_MSGTYPES_LIST { -1, -1, NULL } - -/** - * Message type to cache action association - */ -struct nl_msgtype -{ - /** Netlink message type */ - int mt_id; - - /** Cache action to take */ - int mt_act; - - /** Name of operation for human-readable printing */ - char * mt_name; -}; - -/** - * Address family to netlink group association - */ -struct nl_af_group -{ - /** Address family */ - int ag_family; - - /** Netlink group identifier */ - int ag_group; -}; - -#define END_OF_GROUP_LIST AF_UNSPEC, 0 - -/** - * Parser parameters - * - * This structure is used to configure what kind of parser to use - * when parsing netlink messages to create objects. - */ -struct nl_parser_param -{ - /** Function to parse netlink messages into objects */ - int (*pp_cb)(struct nl_object *, struct nl_parser_param *); - - /** Arbitary argument to be passed to the parser */ - void * pp_arg; -}; - -/** - * Cache Operations - * - * This structure defines the characterstics of a cache type. It contains - * pointers to functions which implement the specifics of the object type - * the cache can hold. - */ -struct nl_cache_ops -{ - /** Name of cache type (must be unique) */ - char * co_name; - - /** Size of family specific netlink header */ - int co_hdrsize; - - /** Netlink protocol */ - int co_protocol; - - /** cache object hash size **/ - int co_hash_size; - - /** cache flags */ - unsigned int co_flags; - - /** Reference counter */ - unsigned int co_refcnt; - - /** Group definition */ - struct nl_af_group * co_groups; - - /** - * Called whenever an update of the cache is required. Must send - * a request message to the kernel requesting a complete dump. - */ - int (*co_request_update)(struct nl_cache *, struct nl_sock *); - - /** - * Called whenever a message was received that needs to be parsed. - * Must parse the message and call the paser callback function - * (nl_parser_param) provided via the argument. - */ - int (*co_msg_parser)(struct nl_cache_ops *, struct sockaddr_nl *, - struct nlmsghdr *, struct nl_parser_param *); - - /** - * The function registered under this callback is called after a - * netlink notification associated with this cache type has been - * parsed into an object and is being considered for inclusio into - * the specified cache. - * - * The purpose of this function is to filter out notifications - * which should be ignored when updating caches. - * - * The function must return NL_SKIP to prevent the object from - * being included, or NL_OK to include it. - * - * @code - * int my_filter(struct nl_cache *cache, struct nl_object *obj) - * { - * if (reason_to_not_include_obj(obj)) - * return NL_SKIP; - * - * return NL_OK; - * } - * @endcode - */ - int (*co_event_filter)(struct nl_cache *, struct nl_object *obj); - - /** - * The function registered under this callback is called when an - * object formed from a notification event needs to be included in - * a cache. - * - * For each modified object, the change callback \c change_cb must - * be called with the \c data argument provided. - * - * If no function is registered, the function nl_cache_include() - * will be used for this purpose. - * - * @see nl_cache_include() - */ - int (*co_include_event)(struct nl_cache *cache, struct nl_object *obj, - change_func_t change_cb, void *data); - - void (*reserved_1)(void); - void (*reserved_2)(void); - void (*reserved_3)(void); - void (*reserved_4)(void); - void (*reserved_5)(void); - void (*reserved_6)(void); - void (*reserved_7)(void); - void (*reserved_8)(void); - - /** Object operations */ - struct nl_object_ops * co_obj_ops; - - /** Internal, do not touch! */ - struct nl_cache_ops *co_next; - - struct nl_cache *co_major_cache; - struct genl_ops * co_genl; - - /* Message type definition */ - struct nl_msgtype co_msgtypes[]; -}; - -extern void nl_cache_ops_get(struct nl_cache_ops *); -extern void nl_cache_ops_put(struct nl_cache_ops *); - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/netlink/object-api.h b/include/netlink/object-api.h deleted file mode 100644 index ae6180a..0000000 --- a/include/netlink/object-api.h +++ /dev/null @@ -1,375 +0,0 @@ -/* - * netlink/object-api.c Object API - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * Copyright (c) 2003-2007 Thomas Graf - */ - -#ifndef NETLINK_OBJECT_API_H_ -#define NETLINK_OBJECT_API_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @ingroup object - * @defgroup object_api Object API - * @brief - * - * @par 1) Object Definition - * @code - * // Define your object starting with the common object header - * struct my_obj { - * NLHDR_COMMON - * int my_data; - * }; - * - * // Fill out the object operations structure - * struct nl_object_ops my_ops = { - * .oo_name = "my_obj", - * .oo_size = sizeof(struct my_obj), - * }; - * - * // At this point the object can be allocated, you may want to provide a - * // separate _alloc() function to ease allocting objects of this kind. - * struct nl_object *obj = nl_object_alloc(&my_ops); - * - * // And release it again... - * nl_object_put(obj); - * @endcode - * - * @par 2) Allocating additional data - * @code - * // You may require to allocate additional data and store it inside - * // object, f.e. assuming there is a field `ptr'. - * struct my_obj { - * NLHDR_COMMON - * void * ptr; - * }; - * - * // And at some point you may assign allocated data to this field: - * my_obj->ptr = calloc(1, ...); - * - * // In order to not introduce any memory leaks you have to release - * // this data again when the last reference is given back. - * static void my_obj_free_data(struct nl_object *obj) - * { - * struct my_obj *my_obj = nl_object_priv(obj); - * - * free(my_obj->ptr); - * } - * - * // Also when the object is cloned, you must ensure for your pointer - * // stay valid even if one of the clones is freed by either making - * // a clone as well or increase the reference count. - * static int my_obj_clone(struct nl_object *src, struct nl_object *dst) - * { - * struct my_obj *my_src = nl_object_priv(src); - * struct my_obj *my_dst = nl_object_priv(dst); - * - * if (src->ptr) { - * dst->ptr = calloc(1, ...); - * memcpy(dst->ptr, src->ptr, ...); - * } - * } - * - * struct nl_object_ops my_ops = { - * ... - * .oo_free_data = my_obj_free_data, - * .oo_clone = my_obj_clone, - * }; - * @endcode - * - * @par 3) Object Dumping - * @code - * static int my_obj_dump_detailed(struct nl_object *obj, - * struct nl_dump_params *params) - * { - * struct my_obj *my_obj = nl_object_priv(obj); - * - * // It is absolutely essential to use nl_dump() when printing - * // any text to make sure the dumping parameters are respected. - * nl_dump(params, "Obj Integer: %d\n", my_obj->my_int); - * - * // Before we can dump the next line, make sure to prefix - * // this line correctly. - * nl_new_line(params); - * - * // You may also split a line into multiple nl_dump() calls. - * nl_dump(params, "String: %s ", my_obj->my_string); - * nl_dump(params, "String-2: %s\n", my_obj->another_string); - * } - * - * struct nl_object_ops my_ops = { - * ... - * .oo_dump[NL_DUMP_FULL] = my_obj_dump_detailed, - * }; - * @endcode - * - * @par 4) Object Attributes - * @code - * // The concept of object attributes is optional but can ease the typical - * // case of objects that have optional attributes, e.g. a route may have a - * // nexthop assigned but it is not required to. - * - * // The first step to define your object specific bitmask listing all - * // attributes - * #define MY_ATTR_FOO (1<<0) - * #define MY_ATTR_BAR (1<<1) - * - * // When assigning an optional attribute to the object, make sure - * // to mark its availability. - * my_obj->foo = 123123; - * my_obj->ce_mask |= MY_ATTR_FOO; - * - * // At any time you may use this mask to check for the availability - * // of the attribute, e.g. while dumping - * if (my_obj->ce_mask & MY_ATTR_FOO) - * nl_dump(params, "foo %d ", my_obj->foo); - * - * // One of the big advantages of this concept is that it allows for - * // standardized comparisons which make it trivial for caches to - * // identify unique objects by use of unified comparison functions. - * // In order for it to work, your object implementation must provide - * // a comparison function and define a list of attributes which - * // combined together make an object unique. - * - * static int my_obj_compare(struct nl_object *_a, struct nl_object *_b, - * uint32_t attrs, int flags) - * { - * struct my_obj *a = nl_object_priv(_a): - * struct my_obj *b = nl_object_priv(_b): - * int diff = 0; - * - * // We help ourselves in defining our own DIFF macro which will - * // call ATTR_DIFF() on both objects which will make sure to only - * // compare the attributes if required. - * #define MY_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, MY_ATTR_##ATTR, a, b, EXPR) - * - * // Call our own diff macro for each attribute to build a bitmask - * // representing the attributes which mismatch. - * diff |= MY_DIFF(FOO, a->foo != b->foo) - * diff |= MY_DIFF(BAR, strcmp(a->bar, b->bar)) - * - * return diff; - * } - * - * // In order to identify identical objects with differing attributes - * // you must specify the attributes required to uniquely identify - * // your object. Make sure to not include too many attributes, this - * // list is used when caches look for an old version of an object. - * struct nl_object_ops my_ops = { - * ... - * .oo_id_attrs = MY_ATTR_FOO, - * .oo_compare = my_obj_compare, - * }; - * @endcode - * @{ - */ - -/** - * Common Object Header - * - * This macro must be included as first member in every object - * definition to allow objects to be cached. - */ -#define NLHDR_COMMON \ - int ce_refcnt; \ - struct nl_object_ops * ce_ops; \ - struct nl_cache * ce_cache; \ - struct nl_list_head ce_list; \ - int ce_msgtype; \ - int ce_flags; \ - uint32_t ce_mask; - -struct nl_object -{ - NLHDR_COMMON -}; - - -/** - * Return true if attribute is available in both objects - * @arg A an object - * @arg B another object - * @arg ATTR attribute bit - * - * @return True if the attribute is available, otherwise false is returned. - */ -#define AVAILABLE(A, B, ATTR) (((A)->ce_mask & (B)->ce_mask) & (ATTR)) - -/** - * Return true if attribute is available in only one of both objects - * @arg A an object - * @arg B another object - * @arg ATTR attribute bit - * - * @return True if the attribute is available in only one of both objects, - * otherwise false is returned. - */ -#define AVAILABLE_MISMATCH(A, B, ATTR) (((A)->ce_mask ^ (B)->ce_mask) & (ATTR)) - -/** - * Return true if attributes mismatch - * @arg A an object - * @arg B another object - * @arg ATTR attribute bit - * @arg EXPR Comparison expression - * - * This function will check if the attribute in question is available - * in both objects, if not this will count as a mismatch. - * - * If available the function will execute the expression which must - * return true if the attributes mismatch. - * - * @return True if the attribute mismatch, or false if they match. - */ -#define ATTR_MISMATCH(A, B, ATTR, EXPR) (AVAILABLE_MISMATCH(A, B, ATTR) || \ - (AVAILABLE(A, B, ATTR) && (EXPR))) - -/** - * Return attribute bit if attribute does not match - * @arg LIST list of attributes to be compared - * @arg ATTR attribute bit - * @arg A an object - * @arg B another object - * @arg EXPR Comparison expression - * - * This function will check if the attribute in question is available - * in both objects, if not this will count as a mismatch. - * - * If available the function will execute the expression which must - * return true if the attributes mismatch. - * - * In case the attributes mismatch, the attribute is returned, otherwise - * 0 is returned. - * - * @code - * diff |= ATTR_DIFF(attrs, MY_ATTR_FOO, a, b, a->foo != b->foo); - * @endcode - */ -#define ATTR_DIFF(LIST, ATTR, A, B, EXPR) \ -({ int diff = 0; \ - if (((LIST) & (ATTR)) && ATTR_MISMATCH(A, B, ATTR, EXPR)) \ - diff = ATTR; \ - diff; }) - -/** - * Object Operations - */ -struct nl_object_ops -{ - /** - * Unique name of object type - * - * Must be in the form family/name, e.g. "route/addr" - */ - char * oo_name; - - /** Size of object including its header */ - size_t oo_size; - - /* List of attributes needed to uniquely identify the object */ - uint32_t oo_id_attrs; - - /** - * Constructor function - * - * Will be called when a new object of this type is allocated. - * Can be used to initialize members such as lists etc. - */ - void (*oo_constructor)(struct nl_object *); - - /** - * Destructor function - * - * Will be called when an object is freed. Must free all - * resources which may have been allocated as part of this - * object. - */ - void (*oo_free_data)(struct nl_object *); - - /** - * Cloning function - * - * Will be called when an object needs to be cloned. Please - * note that the generic object code will make an exact - * copy of the object first, therefore you only need to take - * care of members which require reference counting etc. - * - * May return a negative error code to abort cloning. - */ - int (*oo_clone)(struct nl_object *, struct nl_object *); - - /** - * Dumping functions - * - * Will be called when an object is dumped. The implementations - * have to use nl_dump(), nl_dump_line(), and nl_new_line() to - * dump objects. - * - * The functions must return the number of lines printed. - */ - void (*oo_dump[NL_DUMP_MAX+1])(struct nl_object *, - struct nl_dump_params *); - - /** - * Comparison function - * - * Will be called when two objects of the same type are - * compared. It takes the two objects in question, an object - * specific bitmask defining which attributes should be - * compared and flags to control the behaviour. - * - * The function must return a bitmask with the relevant bit - * set for each attribute that mismatches. - */ - int (*oo_compare)(struct nl_object *, struct nl_object *, - uint32_t, int); - - - /** - * update function - * - * Will be called when the object given by first argument - * needs to be updated with the contents of the second object - * - * The function must return 0 for success and error for failure - * to update. In case of failure its assumed that the original - * object is not touched - */ - int (*oo_update)(struct nl_object *, struct nl_object *); - - /** - * Hash Key generator function - * - * When called returns a hash key for the object being - * referenced. This key will be used by higher level hash functions - * to build association lists. Each object type gets to specify - * it's own key formulation - */ - void (*oo_keygen)(struct nl_object *, uint32_t *, uint32_t); - - char *(*oo_attrs2str)(int, char *, size_t); - - /** - * Get key attributes by family function - */ - uint32_t (*oo_id_attrs_get)(struct nl_object *); -}; - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/netlink/route/link/api.h b/include/netlink/route/link/api.h deleted file mode 100644 index 28f2464..0000000 --- a/include/netlink/route/link/api.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * netlink/route/link/api.h Link Modules API - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * Copyright (c) 2003-2010 Thomas Graf - */ - -#ifndef NETLINK_LINK_API_H_ -#define NETLINK_LINK_API_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @ingroup link_api - * - * Available operations to modules implementing a link info type. - */ -struct rtnl_link_info_ops -{ - /** Name of link info type, must match name on kernel side */ - char * io_name; - - /** Reference count, DO NOT MODIFY */ - int io_refcnt; - - /** Called to assign an info type to a link. - * Has to allocate enough resources to hold attributes. Can - * use link->l_info to store a pointer. */ - int (*io_alloc)(struct rtnl_link *); - - /** Called to parse the link info attribute. - * Must parse the attribute and assign all values to the link. - */ - int (*io_parse)(struct rtnl_link *, - struct nlattr *, - struct nlattr *); - - /** Called when the link object is dumped. - * Must dump the info type specific attributes. */ - void (*io_dump[NL_DUMP_MAX+1])(struct rtnl_link *, - struct nl_dump_params *); - - /** Called when a link object is cloned. - * Must clone all info type specific attributes. */ - int (*io_clone)(struct rtnl_link *, struct rtnl_link *); - - /** Called when construction a link netlink message. - * Must append all info type specific attributes to the message. */ - int (*io_put_attrs)(struct nl_msg *, struct rtnl_link *); - - /** Called to release all resources previously allocated - * in either io_alloc() or io_parse(). */ - void (*io_free)(struct rtnl_link *); - - struct nl_list_head io_list; -}; - -extern struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *); -extern void rtnl_link_info_ops_put(struct rtnl_link_info_ops *); -extern int rtnl_link_register_info(struct rtnl_link_info_ops *); -extern int rtnl_link_unregister_info(struct rtnl_link_info_ops *); - - -/** - * @ingroup link_api - * - * Available operations to modules implementing a link address family. - */ -struct rtnl_link_af_ops -{ - /** The address family this operations set implements */ - const unsigned int ao_family; - - /** Number of users of this operations, DO NOT MODIFY. */ - int ao_refcnt; - - /** Validation policy for IFLA_PROTINFO attribute. This pointer - * can be set to a nla_policy structure describing the minimal - * requirements the attribute must meet. Failure of meeting these - * requirements will result in a parsing error. */ - const struct nla_policy *ao_protinfo_policy; - - /** Called after address family has been assigned to link. Must - * allocate data buffer to hold address family specific data and - * store it in link->l_af_data. */ - void * (*ao_alloc)(struct rtnl_link *); - - /** Called when the link is cloned, must allocate a clone of the - * address family specific buffer and return it. */ - void * (*ao_clone)(struct rtnl_link *, void *); - - /** Called when the link gets freed. Must free all allocated data */ - void (*ao_free)(struct rtnl_link *, void *); - - /** Called if a IFLA_PROTINFO attribute needs to be parsed. Typically - * stores the parsed data in the address family specific buffer. */ - int (*ao_parse_protinfo)(struct rtnl_link *, - struct nlattr *, void *); - - /** Called if a IFLA_AF_SPEC attribute needs to be parsed. Typically - * stores the parsed data in the address family specific buffer. */ - int (*ao_parse_af)(struct rtnl_link *, - struct nlattr *, void *); - - /** Called if a link message is sent to the kernel. Must append the - * link address family specific attributes to the message. */ - int (*ao_fill_af)(struct rtnl_link *, - struct nl_msg *msg, void *); - - /** Dump address family specific link attributes */ - void (*ao_dump[NL_DUMP_MAX+1])(struct rtnl_link *, - struct nl_dump_params *, - void *); - - /** Comparison function - * - * Will be called when two links are compared for their af data. It - * takes two link objects in question, an object specific bitmask - * defining which attributes should be compared and flags to control - * the behaviour - * - * The function must return a bitmask with the relevant bit set for - * each attribute that mismatches - */ - int (*ao_compare)(struct rtnl_link *, - struct rtnl_link *, int, uint32_t, int); -}; - -extern struct rtnl_link_af_ops *rtnl_link_af_ops_lookup(unsigned int); -extern void rtnl_link_af_ops_put(struct rtnl_link_af_ops *); -extern void * rtnl_link_af_alloc(struct rtnl_link *, - const struct rtnl_link_af_ops *); -extern void * rtnl_link_af_data(const struct rtnl_link *, - const struct rtnl_link_af_ops *); -extern int rtnl_link_af_register(struct rtnl_link_af_ops *); -extern int rtnl_link_af_unregister(struct rtnl_link_af_ops *); -extern int rtnl_link_af_data_compare(struct rtnl_link *a, - struct rtnl_link *b, - int family); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/netlink/route/link/info-api.h b/include/netlink/route/link/info-api.h deleted file mode 100644 index 4750e18..0000000 --- a/include/netlink/route/link/info-api.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * netlink/route/link/info-api.h Link Info API - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * Copyright (c) 2003-2010 Thomas Graf - */ - -#ifndef NETLINK_LINK_INFO_API_H_ -#define NETLINK_LINK_INFO_API_H_ - -#warning " is obsolete and may be removed in the future." -#warning "include instead. - -#include - -#endif diff --git a/include/netlink/route/tc-api.h b/include/netlink/route/tc-api.h deleted file mode 100644 index 601a8df..0000000 --- a/include/netlink/route/tc-api.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * netlink/route/tc-api.h Traffic Control API - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * Copyright (c) 2011 Thomas Graf - */ - -#ifndef NETLINK_TC_API_H_ -#define NETLINK_TC_API_H_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define RTNL_TC_TYPE_MAX (__RTNL_TC_TYPE_MAX - 1) - -/** - * Traffic control object operations - * @ingroup tc - * - * This structure holds function pointers and settings implementing - * the features of each traffic control object implementation. - */ -struct rtnl_tc_ops -{ - /** - * Name of traffic control module - */ - char *to_kind; - - /** - * Type of traffic control object - */ - enum rtnl_tc_type to_type; - - - /** - * Size of private data - */ - size_t to_size; - - /** - * Dump callbacks - */ - void (*to_dump[NL_DUMP_MAX+1])(struct rtnl_tc *, void *, - struct nl_dump_params *); - /** - * Used to fill the contents of TCA_OPTIONS - */ - int (*to_msg_fill)(struct rtnl_tc *, void *, struct nl_msg *); - - /** - * Uesd to to fill tc related messages, unlike with to_msg_fill, - * the contents is not encapsulated with a TCA_OPTIONS nested - * attribute. - */ - int (*to_msg_fill_raw)(struct rtnl_tc *, void *, struct nl_msg *); - - /** - * TCA_OPTIONS message parser - */ - int (*to_msg_parser)(struct rtnl_tc *, void *); - - /** - * Called before a tc object is destroyed - */ - void (*to_free_data)(struct rtnl_tc *, void *); - - /** - * Called whenever a classifier object needs to be cloned - */ - int (*to_clone)(void *, void *); - - /** - * Internal, don't touch - */ - struct nl_list_head to_list; -}; - -struct rtnl_tc_type_ops -{ - enum rtnl_tc_type tt_type; - - char *tt_dump_prefix; - - /** - * Dump callbacks - */ - void (*tt_dump[NL_DUMP_MAX+1])(struct rtnl_tc *, - struct nl_dump_params *); -}; - -extern int rtnl_tc_msg_parse(struct nlmsghdr *, - struct rtnl_tc *); -extern int rtnl_tc_msg_build(struct rtnl_tc *, int, - int, struct nl_msg **); - -extern void rtnl_tc_free_data(struct nl_object *); -extern int rtnl_tc_clone(struct nl_object *, - struct nl_object *); -extern void rtnl_tc_dump_line(struct nl_object *, - struct nl_dump_params *); -extern void rtnl_tc_dump_details(struct nl_object *, - struct nl_dump_params *); -extern void rtnl_tc_dump_stats(struct nl_object *, - struct nl_dump_params *); -extern int rtnl_tc_compare(struct nl_object *, - struct nl_object *, - uint32_t, int); - -extern void * rtnl_tc_data(struct rtnl_tc *); -extern void * rtnl_tc_data_check(struct rtnl_tc *, - struct rtnl_tc_ops *); - -extern struct rtnl_tc_ops * rtnl_tc_lookup_ops(enum rtnl_tc_type, - const char *); -extern struct rtnl_tc_ops * rtnl_tc_get_ops(struct rtnl_tc *); -extern int rtnl_tc_register(struct rtnl_tc_ops *); -extern void rtnl_tc_unregister(struct rtnl_tc_ops *); - -extern void rtnl_tc_type_register(struct rtnl_tc_type_ops *); -extern void rtnl_tc_type_unregister(struct rtnl_tc_type_ops *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/netlink/route/tc.h b/include/netlink/route/tc.h index caee60c..836f7b1 100644 --- a/include/netlink/route/tc.h +++ b/include/netlink/route/tc.h @@ -30,6 +30,8 @@ enum rtnl_tc_type { __RTNL_TC_TYPE_MAX, }; +#define RTNL_TC_TYPE_MAX (__RTNL_TC_TYPE_MAX - 1) + /** * Compute tc handle based on major and minor parts * @ingroup tc -- cgit v1.2.1