~ubuntu-branches/ubuntu/trusty/libnl3/trusty

« back to all changes in this revision

Viewing changes to include/netlink-local.h

  • Committer: Bazaar Package Importer
  • Author(s): Heiko Stuebner
  • Date: 2011-05-21 19:25:13 UTC
  • Revision ID: james.westby@ubuntu.com-20110521192513-1ieyu9w9kym4bt16
Tags: upstream-3.0
ImportĀ upstreamĀ versionĀ 3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * netlink-local.h              Local Netlink Interface
 
3
 *
 
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
 
7
 *      of the License.
 
8
 *
 
9
 * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
 
10
 */
 
11
 
 
12
#ifndef NETLINK_LOCAL_H_
 
13
#define NETLINK_LOCAL_H_
 
14
 
 
15
#include <stdio.h>
 
16
#include <errno.h>
 
17
#include <stdlib.h>
 
18
#include <string.h>
 
19
#include <unistd.h>
 
20
#include <fcntl.h>
 
21
#include <math.h>
 
22
#include <time.h>
 
23
#include <stdarg.h>
 
24
#include <ctype.h>
 
25
#include <sys/types.h>
 
26
#include <sys/stat.h>
 
27
#include <sys/socket.h>
 
28
#include <inttypes.h>
 
29
#include <assert.h>
 
30
#include <limits.h>
 
31
#include <search.h>
 
32
 
 
33
#include <arpa/inet.h>
 
34
#include <netdb.h>
 
35
 
 
36
#ifndef SOL_NETLINK
 
37
#define SOL_NETLINK 270
 
38
#endif
 
39
 
 
40
#include <linux/types.h>
 
41
 
 
42
/* local header copies */
 
43
#include <linux/if.h>
 
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>
 
54
 
 
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>
 
62
 
 
63
struct trans_tbl {
 
64
        int i;
 
65
        const char *a;
 
66
};
 
67
 
 
68
#define __ADD(id, name) { .i = id, .a = #name },
 
69
 
 
70
struct trans_list {
 
71
        int i;
 
72
        char *a;
 
73
        struct nl_list_head list;
 
74
};
 
75
 
 
76
#define NL_DEBUG        1
 
77
 
 
78
#define NL_DBG(LVL,FMT,ARG...) \
 
79
        do {    \
 
80
                if (LVL <= nl_debug) \
 
81
                        fprintf(stderr, "DBG<" #LVL ">: " FMT, ##ARG); \
 
82
        } while (0)
 
83
 
 
84
#define BUG()                            \
 
85
        do {                                 \
 
86
                fprintf(stderr, "BUG: %s:%d\n",  \
 
87
                        __FILE__, __LINE__);         \
 
88
                assert(0);      \
 
89
        } while (0)
 
90
 
 
91
extern int __nl_read_num_str_file(const char *path,
 
92
                                  int (*cb)(long, const char *));
 
93
 
 
94
extern int __trans_list_add(int, const char *, struct nl_list_head *);
 
95
extern void __trans_list_clear(struct nl_list_head *);
 
96
 
 
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);
 
99
 
 
100
extern char *__list_type2str(int, char *, size_t, struct nl_list_head *);
 
101
extern int __list_str2type(const char *, struct nl_list_head *);
 
102
 
 
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);
 
105
 
 
106
extern void dump_from_ops(struct nl_object *, struct nl_dump_params *);
 
107
 
 
108
static inline struct nl_cache *dp_cache(struct nl_object *obj)
 
109
{
 
110
        if (obj->ce_cache == NULL)
 
111
                return nl_cache_mngt_require(obj->ce_ops->oo_name);
 
112
 
 
113
        return obj->ce_cache;
 
114
}
 
115
 
 
116
static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg)
 
117
{
 
118
        return cb->cb_set[type](msg, cb->cb_args[type]);
 
119
}
 
120
 
 
121
#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
 
122
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 
123
 
 
124
#define __init __attribute__ ((constructor))
 
125
#define __exit __attribute__ ((destructor))
 
126
#undef __deprecated
 
127
#define __deprecated __attribute__ ((deprecated))
 
128
 
 
129
#define min(x,y) ({ \
 
130
        typeof(x) _x = (x);     \
 
131
        typeof(y) _y = (y);     \
 
132
        (void) (&_x == &_y);            \
 
133
        _x < _y ? _x : _y; })
 
134
 
 
135
#define max(x,y) ({ \
 
136
        typeof(x) _x = (x);     \
 
137
        typeof(y) _y = (y);     \
 
138
        (void) (&_x == &_y);            \
 
139
        _x > _y ? _x : _y; })
 
140
 
 
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; })
 
145
 
 
146
extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
 
147
                          struct nlmsghdr *, struct nl_parser_param *);
 
148
 
 
149
 
 
150
static inline void rtnl_copy_ratespec(struct rtnl_ratespec *dst,
 
151
                                      struct tc_ratespec *src)
 
152
{
 
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;
 
158
}
 
159
 
 
160
static inline void rtnl_rcopy_ratespec(struct tc_ratespec *dst,
 
161
                                       struct rtnl_ratespec *src)
 
162
{
 
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;
 
168
}
 
169
 
 
170
static inline char *nl_cache_name(struct nl_cache *cache)
 
171
{
 
172
        return cache->c_ops ? cache->c_ops->co_name : "unknown";
 
173
}
 
174
 
 
175
#define GENL_FAMILY(id, name) \
 
176
        { \
 
177
                { id, NL_ACT_UNSPEC, name }, \
 
178
                END_OF_MSGTYPES_LIST, \
 
179
        }
 
180
 
 
181
static inline int wait_for_ack(struct nl_sock *sk)
 
182
{
 
183
        if (sk->s_flags & NL_NO_AUTO_ACK)
 
184
                return 0;
 
185
        else
 
186
                return nl_wait_for_ack(sk);
 
187
}
 
188
 
 
189
#endif