-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnlinline+.h
181 lines (168 loc) · 7.02 KB
/
nlinline+.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* nlinline plus: compact library of inline function providing the most common
* network configuration operations.
*
* Copyright (C) 2019 Renzo Davoli <[email protected]> VirtualSquare team.
*
* nlinline is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef NLINLINEPLUS_H
#define NLINLINEPLUS_H
#ifdef NLINLINE_H
#error nlinline+.h must be included instead of nlinline.h
#else
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
/**************************
* Implementation
**************************/
typedef int msocket_t (void *, int, int, int);
struct _stackinfo {
msocket_t *msocket;
void *mstack;
typeof(socket) *socket;
typeof(bind) *bind;
typeof(send) *send;
typeof(recv) *recv;
typeof(close) *close;
};
#define __NLINLINE_PLUSTYPE struct _stackinfo
#include <nlinline.h>
#define __LIB_STACKINFO(X, Y) \
struct _stackinfo stackinfo = {\
NULL, NULL, \
X ## socket, \
Y ## bind, \
Y ## send, \
Y ## recv, \
Y ## close \
}
#define __LIB_NLINLINE(NAME, X, Y) \
static inline int NAME ## if_nametoindex(const char *ifname) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_if_nametoindex(&stackinfo, ifname); \
} \
static inline int NAME ## linksetupdown(unsigned int ifindex, int updown) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_linksetupdown(&stackinfo, ifindex, updown); \
} \
static inline int NAME ## linksetaddr(unsigned int ifindex, void *macaddr) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_linksetaddr(&stackinfo, ifindex, macaddr); \
} \
static inline int NAME ## linkgetaddr(unsigned int ifindex, void *macaddr) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_linkgetaddr(&stackinfo, ifindex, macaddr); \
} \
static inline int NAME ## linksetmtu(unsigned int ifindex, unsigned int mtu) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_linksetmtu(&stackinfo, ifindex, mtu); \
} \
static inline int NAME ## ipaddr_add(int family, void *addr, int prefixlen, unsigned int ifindex) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_ipaddr_add(&stackinfo, family, addr, prefixlen, ifindex); \
} \
static inline int NAME ## ipaddr_del(int family, void *addr, int prefixlen, unsigned int ifindex) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_ipaddr_del(&stackinfo, family, addr, prefixlen, ifindex); \
} \
static inline int NAME ## iproute_add(int family, void *dst_addr, int dst_prefixlen, void *gw_addr, unsigned int ifindex) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_iproute_add(&stackinfo, family, dst_addr, dst_prefixlen, gw_addr, ifindex); \
} \
static inline int NAME ## iproute_del(int family, void *dst_addr, int dst_prefixlen, void *gw_addr, unsigned int ifindex) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_iproute_del(&stackinfo, family, dst_addr, dst_prefixlen, gw_addr, ifindex); \
} \
static inline int NAME ## iplink_add(const char *ifname, unsigned int ifindex, const char *type, struct nl_iplink_data *ifd, int nifd) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_iplink_add(&stackinfo, ifname, ifindex, type, ifd, nifd); \
} \
static inline int NAME ## iplink_del(const char *ifname, unsigned int ifindex) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_iplink_del(&stackinfo, ifname, ifindex); \
} \
static inline int NAME ## nldialog(const char *ifname, void *msg) {\
__LIB_STACKINFO(X, Y); \
return __nlinline_nldialog(&stackinfo, msg); \
}
#define NLINLINE_LIB(X) __LIB_NLINLINE(X, X, X)
#define NLINLINE_LIBCOMP(X) __LIB_NLINLINE(X, X, )
#define __LIBMULTI_STACKINFO(X, Y, MSTACK) \
struct _stackinfo stackinfo = {\
(msocket_t *) X ## msocket, \
MSTACK, \
NULL, \
Y ## bind, \
Y ## send, \
Y ## recv, \
Y ## close \
}
#define __LIBMULTI_NLINLINE(X, Y) \
static inline int X ## if_nametoindex(void *mstack, const char *ifname) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_if_nametoindex(&stackinfo, ifname); \
} \
static inline int X ## linksetupdown(void *mstack, unsigned int ifindex, int updown) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_linksetupdown(&stackinfo, ifindex, updown); \
} \
static inline int X ## linksetaddr(void *mstack, unsigned int ifindex, void *macaddr) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_linksetaddr(&stackinfo, ifindex, macaddr); \
} \
static inline int X ## linkgetaddr(void *mstack, unsigned int ifindex, void *macaddr) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_linkgetaddr(&stackinfo, ifindex, macaddr); \
} \
static inline int X ## linksetmtu(void *mstack, unsigned int ifindex, unsigned int mtu) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_linksetmtu(&stackinfo, ifindex, mtu); \
} \
static inline int X ## ipaddr_add(void *mstack, int family, void *addr, int prefixlen, int ifindex) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_ipaddr_add(&stackinfo, family, addr, prefixlen, ifindex); \
} \
static inline int X ## ipaddr_del(void *mstack, int family, void *addr, int prefixlen, int ifindex) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_ipaddr_del(&stackinfo, family, addr, prefixlen, ifindex); \
} \
static inline int X ## iproute_add(void *mstack, int family, void *dst_addr, int dst_prefixlen, void *gw_addr, unsigned int ifindex) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_iproute_add(&stackinfo, family, dst_addr, dst_prefixlen, gw_addr, ifindex); \
} \
static inline int X ## iproute_del(void *mstack, int family, void *dst_addr, int dst_prefixlen, void *gw_addr, unsigned int ifindex) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_iproute_del(&stackinfo, family, dst_addr, dst_prefixlen, gw_addr, ifindex); \
} \
static inline int X ## iplink_add(void *mstack, const char *ifname, unsigned int ifindex, const char *type, struct nl_iplink_data *ifd, int nifd) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_iplink_add(&stackinfo, ifname, ifindex, type, ifd, nifd); \
} \
static inline int X ## iplink_del(void *mstack, const char *ifname, unsigned int ifindex) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_iplink_del(&stackinfo, ifname, ifindex); \
} \
static inline int X ## nldialog(void *mstack, void *msg) {\
__LIBMULTI_STACKINFO(X, Y, mstack); \
return __nlinline_nldialog(&stackinfo, msg); \
}
#define NLINLINE_LIBMULTI(X) __LIBMULTI_NLINLINE(X, X)
#define NLINLINE_LIBMULTICOMP(X) __LIBMULTI_NLINLINE(X, )
/* define the standard inline functions nlinline_... */
__LIB_NLINLINE(nlinline_,,)
#endif
#endif