2
* netlink-local.h Local Netlink Interface
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation version 2.1
9
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
12
#ifndef NETLINK_LOCAL_H_
13
#define NETLINK_LOCAL_H_
25
#include <sys/types.h>
27
#include <sys/socket.h>
33
#include <arpa/inet.h>
37
#define SOL_NETLINK 270
40
#include <linux/types.h>
42
/* local header copies */
44
#include <linux/if_arp.h>
45
#include <linux/if_ether.h>
46
#include <linux/pkt_sched.h>
47
#include <linux/pkt_cls.h>
48
#include <linux/gen_stats.h>
49
#include <linux/ip_mp_alg.h>
50
#include <linux/atm.h>
51
#include <linux/inetdevice.h>
52
#include <linux/ipv6.h>
53
#include <linux/snmp.h>
55
#include <netlink/netlink.h>
56
#include <netlink/handlers.h>
57
#include <netlink/cache.h>
58
#include <netlink/route/tc.h>
59
#include <netlink/object-api.h>
60
#include <netlink/cache-api.h>
61
#include <netlink-types.h>
68
#define __ADD(id, name) { .i = id, .a = #name },
73
struct nl_list_head list;
78
#define NL_DBG(LVL,FMT,ARG...) \
80
if (LVL <= nl_debug) \
81
fprintf(stderr, "DBG<" #LVL ">: " FMT, ##ARG); \
86
fprintf(stderr, "BUG: %s:%d\n", \
87
__FILE__, __LINE__); \
91
extern int __nl_read_num_str_file(const char *path,
92
int (*cb)(long, const char *));
94
extern int __trans_list_add(int, const char *, struct nl_list_head *);
95
extern void __trans_list_clear(struct nl_list_head *);
97
extern char *__type2str(int, char *, size_t, const struct trans_tbl *, size_t);
98
extern int __str2type(const char *, const struct trans_tbl *, size_t);
100
extern char *__list_type2str(int, char *, size_t, struct nl_list_head *);
101
extern int __list_str2type(const char *, struct nl_list_head *);
103
extern char *__flags2str(int, char *, size_t, const struct trans_tbl *, size_t);
104
extern int __str2flags(const char *, const struct trans_tbl *, size_t);
106
extern void dump_from_ops(struct nl_object *, struct nl_dump_params *);
108
static inline struct nl_cache *dp_cache(struct nl_object *obj)
110
if (obj->ce_cache == NULL)
111
return nl_cache_mngt_require(obj->ce_ops->oo_name);
113
return obj->ce_cache;
116
static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg)
118
return cb->cb_set[type](msg, cb->cb_args[type]);
121
#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
122
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
124
#define __init __attribute__ ((constructor))
125
#define __exit __attribute__ ((destructor))
127
#define __deprecated __attribute__ ((deprecated))
129
#define min(x,y) ({ \
130
typeof(x) _x = (x); \
131
typeof(y) _y = (y); \
132
(void) (&_x == &_y); \
133
_x < _y ? _x : _y; })
135
#define max(x,y) ({ \
136
typeof(x) _x = (x); \
137
typeof(y) _y = (y); \
138
(void) (&_x == &_y); \
139
_x > _y ? _x : _y; })
141
#define min_t(type,x,y) \
142
({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
143
#define max_t(type,x,y) \
144
({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
146
extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
147
struct nlmsghdr *, struct nl_parser_param *);
150
static inline void rtnl_copy_ratespec(struct rtnl_ratespec *dst,
151
struct tc_ratespec *src)
153
dst->rs_cell_log = src->cell_log;
154
dst->rs_overhead = src->overhead;
155
dst->rs_cell_align = src->cell_align;
156
dst->rs_mpu = src->mpu;
157
dst->rs_rate = src->rate;
160
static inline void rtnl_rcopy_ratespec(struct tc_ratespec *dst,
161
struct rtnl_ratespec *src)
163
dst->cell_log = src->rs_cell_log;
164
dst->overhead = src->rs_overhead;
165
dst->cell_align = src->rs_cell_align;
166
dst->mpu = src->rs_mpu;
167
dst->rate = src->rs_rate;
170
static inline char *nl_cache_name(struct nl_cache *cache)
172
return cache->c_ops ? cache->c_ops->co_name : "unknown";
175
#define GENL_FAMILY(id, name) \
177
{ id, NL_ACT_UNSPEC, name }, \
178
END_OF_MSGTYPES_LIST, \
181
static inline int wait_for_ack(struct nl_sock *sk)
183
if (sk->s_flags & NL_NO_AUTO_ACK)
186
return nl_wait_for_ack(sk);