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>
32 #include <arpa/inet.h>
36 #define SOL_NETLINK 270
39 #include <linux/types.h>
41 /* local header copies */
43 #include <linux/if_arp.h>
44 #include <linux/if_ether.h>
45 #include <linux/pkt_sched.h>
46 #include <linux/pkt_cls.h>
47 #include <linux/gen_stats.h>
48 #include <linux/ip_mp_alg.h>
50 #include <netlink/netlink.h>
51 #include <netlink/handlers.h>
52 #include <netlink/cache.h>
53 #include <netlink/route/tc.h>
54 #include <netlink/object-api.h>
55 #include <netlink/cache-api.h>
56 #include <netlink-types.h>
63 #define __ADD(id, name) { .i = id, .a = #name },
68 struct nl_list_head list;
73 #define NL_DBG(LVL,FMT,ARG...) \
75 if (LVL <= nl_debug) \
76 fprintf(stderr, "DBG<" #LVL ">: " FMT, ##ARG); \
81 fprintf(stderr, "BUG: %s:%d\n", \
82 __FILE__, __LINE__); \
86 extern int __nl_read_num_str_file(const char *path,
87 int (*cb)(long, const char *));
89 extern int __trans_list_add(int, const char *, struct nl_list_head *);
90 extern void __trans_list_clear(struct nl_list_head *);
92 extern char *__type2str(int, char *, size_t, struct trans_tbl *, size_t);
93 extern int __str2type(const char *, struct trans_tbl *, size_t);
95 extern char *__list_type2str(int, char *, size_t, struct nl_list_head *);
96 extern int __list_str2type(const char *, struct nl_list_head *);
98 extern char *__flags2str(int, char *, size_t, struct trans_tbl *, size_t);
99 extern int __str2flags(const char *, struct trans_tbl *, size_t);
101 extern void dump_from_ops(struct nl_object *, struct nl_dump_params *);
103 static inline struct nl_cache *dp_cache(struct nl_object *obj)
105 if (obj->ce_cache == NULL)
106 return nl_cache_mngt_require(obj->ce_ops->oo_name);
108 return obj->ce_cache;
111 static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg)
113 return cb->cb_set[type](msg, cb->cb_args[type]);
116 #define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
117 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
119 #define __init __attribute__ ((constructor))
120 #define __exit __attribute__ ((destructor))
122 #define __deprecated __attribute__ ((deprecated))
124 #define min(x,y) ({ \
125 typeof(x) _x = (x); \
126 typeof(y) _y = (y); \
127 (void) (&_x == &_y); \
128 _x < _y ? _x : _y; })
130 #define max(x,y) ({ \
131 typeof(x) _x = (x); \
132 typeof(y) _y = (y); \
133 (void) (&_x == &_y); \
134 _x > _y ? _x : _y; })
136 #define min_t(type,x,y) \
137 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
138 #define max_t(type,x,y) \
139 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
141 extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
142 struct nlmsghdr *, struct nl_parser_param *);
145 static inline void rtnl_copy_ratespec(struct rtnl_ratespec *dst,
146 struct tc_ratespec *src)
148 dst->rs_cell_log = src->cell_log;
149 dst->rs_feature = src->feature;
150 dst->rs_addend = src->addend;
151 dst->rs_mpu = src->mpu;
152 dst->rs_rate = src->rate;
155 static inline void rtnl_rcopy_ratespec(struct tc_ratespec *dst,
156 struct rtnl_ratespec *src)
158 dst->cell_log = src->rs_cell_log;
159 dst->feature = src->rs_feature;
160 dst->addend = src->rs_addend;
161 dst->mpu = src->rs_mpu;
162 dst->rate = src->rs_rate;
165 static inline char *nl_cache_name(struct nl_cache *cache)
167 return cache->c_ops ? cache->c_ops->co_name : "unknown";
170 #define GENL_FAMILY(id, name) \
172 { id, NL_ACT_UNSPEC, name }, \
173 END_OF_MSGTYPES_LIST, \
176 static inline int wait_for_ack(struct nl_sock *sk)
178 if (sk->s_flags & NL_NO_AUTO_ACK)
181 return nl_wait_for_ack(sk);