OpenWrt – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 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 | #ifndef _GNU_SOURCE |
||
15 | #define _GNU_SOURCE |
||
16 | #endif |
||
17 | |||
18 | #include <stdio.h> |
||
19 | #include <errno.h> |
||
20 | #include <stdlib.h> |
||
21 | #include <string.h> |
||
22 | #include <unistd.h> |
||
23 | #include <fcntl.h> |
||
24 | #include <math.h> |
||
25 | #include <time.h> |
||
26 | #include <stdarg.h> |
||
27 | #include <ctype.h> |
||
28 | #include <sys/types.h> |
||
29 | #include <sys/socket.h> |
||
30 | #include <inttypes.h> |
||
31 | #include <assert.h> |
||
32 | #include <limits.h> |
||
33 | |||
34 | #include <arpa/inet.h> |
||
35 | #include <netdb.h> |
||
36 | |||
37 | #ifndef SOL_NETLINK |
||
38 | #define SOL_NETLINK 270 |
||
39 | #endif |
||
40 | |||
41 | #include <linux/types.h> |
||
42 | |||
43 | /* local header copies */ |
||
44 | #include <linux/if.h> |
||
45 | #include <linux/if_arp.h> |
||
46 | #include <linux/if_ether.h> |
||
47 | #include <linux/pkt_sched.h> |
||
48 | #include <linux/pkt_cls.h> |
||
49 | #include <linux/gen_stats.h> |
||
50 | |||
51 | #include <netlink/netlink.h> |
||
52 | #include <netlink/handlers.h> |
||
53 | #include <netlink/cache.h> |
||
54 | #include <netlink/object-api.h> |
||
55 | #include <netlink/cache-api.h> |
||
56 | #include <netlink-types.h> |
||
57 | |||
58 | struct trans_tbl { |
||
59 | int i; |
||
60 | const char *a; |
||
61 | }; |
||
62 | |||
63 | #define __ADD(id, name) { .i = id, .a = #name }, |
||
64 | |||
65 | struct trans_list { |
||
66 | int i; |
||
67 | char *a; |
||
68 | struct nl_list_head list; |
||
69 | }; |
||
70 | |||
71 | #define NL_DEBUG 1 |
||
72 | |||
73 | #define NL_DBG(LVL,FMT,ARG...) \ |
||
74 | do {} while (0) |
||
75 | |||
76 | #define BUG() \ |
||
77 | do { \ |
||
78 | fprintf(stderr, "BUG: %s:%d\n", \ |
||
79 | __FILE__, __LINE__); \ |
||
80 | assert(0); \ |
||
81 | } while (0) |
||
82 | |||
83 | extern int __nl_read_num_str_file(const char *path, |
||
84 | int (*cb)(long, const char *)); |
||
85 | |||
86 | extern int __trans_list_add(int, const char *, struct nl_list_head *); |
||
87 | extern void __trans_list_clear(struct nl_list_head *); |
||
88 | |||
89 | extern char *__type2str(int, char *, size_t, struct trans_tbl *, size_t); |
||
90 | extern int __str2type(const char *, struct trans_tbl *, size_t); |
||
91 | |||
92 | extern char *__list_type2str(int, char *, size_t, struct nl_list_head *); |
||
93 | extern int __list_str2type(const char *, struct nl_list_head *); |
||
94 | |||
95 | extern char *__flags2str(int, char *, size_t, struct trans_tbl *, size_t); |
||
96 | extern int __str2flags(const char *, struct trans_tbl *, size_t); |
||
97 | |||
98 | extern void dump_from_ops(struct nl_object *, struct nl_dump_params *); |
||
99 | |||
100 | #ifdef disabled |
||
101 | static inline struct nl_cache *dp_cache(struct nl_object *obj) |
||
102 | { |
||
103 | if (obj->ce_cache == NULL) |
||
104 | return nl_cache_mngt_require(obj->ce_ops->oo_name); |
||
105 | |||
106 | return obj->ce_cache; |
||
107 | } |
||
108 | #endif |
||
109 | |||
110 | static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg) |
||
111 | { |
||
112 | return cb->cb_set[type](msg, cb->cb_args[type]); |
||
113 | } |
||
114 | |||
115 | #define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0])) |
||
116 | #ifndef offsetof |
||
117 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
||
118 | #endif |
||
119 | |||
120 | #define __init __attribute__ ((constructor)) |
||
121 | #define __exit __attribute__ ((destructor)) |
||
122 | #undef __deprecated |
||
123 | #define __deprecated __attribute__ ((deprecated)) |
||
124 | |||
125 | #define min(x,y) ({ \ |
||
126 | typeof(x) _x = (x); \ |
||
127 | typeof(y) _y = (y); \ |
||
128 | (void) (&_x == &_y); \ |
||
129 | _x < _y ? _x : _y; }) |
||
130 | |||
131 | #define max(x,y) ({ \ |
||
132 | typeof(x) _x = (x); \ |
||
133 | typeof(y) _y = (y); \ |
||
134 | (void) (&_x == &_y); \ |
||
135 | _x > _y ? _x : _y; }) |
||
136 | |||
137 | extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *, |
||
138 | struct nlmsghdr *, struct nl_parser_param *); |
||
139 | |||
140 | |||
141 | static inline char *nl_cache_name(struct nl_cache *cache) |
||
142 | { |
||
143 | return cache->c_ops ? cache->c_ops->co_name : "unknown"; |
||
144 | } |
||
145 | |||
146 | #define GENL_FAMILY(id, name) \ |
||
147 | { \ |
||
148 | { id, NL_ACT_UNSPEC, name }, \ |
||
149 | END_OF_MSGTYPES_LIST, \ |
||
150 | } |
||
151 | |||
152 | static inline int wait_for_ack(struct nl_sock *sk) |
||
153 | { |
||
154 | if (sk->s_flags & NL_NO_AUTO_ACK) |
||
155 | return 0; |
||
156 | else |
||
157 | return nl_wait_for_ack(sk); |
||
158 | } |
||
159 | |||
160 | #endif |