Debian Codegraph @

lwip-contrib/ports/unix/include/lwipv6.h

raw symbols SCIP
1 /**
2 * @file
3 */
4 /* This is part of LWIPv6
5 * Developed for the Ale4NET project
6 * Application Level Environment for Networking
7 *
8 * Copyright 2004 Renzo Davoli University of Bologna - Italy
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24 #ifndef _LWIPV6_H
25 #define _LWIPV6_H
26 #include <stdio.h>
27 #include <stdlib.h> /* timeval */
28 #include <stdint.h> /* uint32_t */
29 #include <errno.h>
30 #include <sys/poll.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34
35 #ifndef AF_UNSPEC
36 #define AF_UNSPEC 0
37 #endif
38 #ifndef PF_UNSPEC
39 #define PF_UNSPEC AF_UNSPEC
40 #endif
41 #ifndef AF_INET
42 #define AF_INET 2
43 #endif
44 #ifndef PF_INET
45 #define PF_INET AF_INET
46 #endif
47 #ifndef AF_INET6
48 #define AF_INET6 10
49 #endif
50 #ifndef PF_INET6
51 #define PF_INET6 AF_INET6
52 #endif
53 #ifndef AF_NETLINK
54 #define AF_NETLINK 16
55 #endif
56 #ifndef PF_NETLINK
57 #define PF_NETLINK AF_NETLINK
58 #endif
59 #ifndef AF_PACKET
60 #define AF_PACKET 17
61 #endif
62 #ifndef PF_PACKET
63 #define PF_PACKET AF_PACKET
64 #endif
65
66 struct ip_addr {
67 uint32_t addr[4];
68 };
69
70 #define IP4_ADDRX(ip4ax, a,b,c,d) \
71 (ip4ax) = htonl(((uint32_t)((a) & 0xff) << 24) | ((uint32_t)((b) & 0xff) << 16) | \
72 ((uint32_t)((c) & 0xff) << 8) | (uint32_t)((d) & 0xff))
73
74 #define IP64_PREFIX (htonl(0xffff))
75
76 #define IP6_ADDR(ipaddr, a,b,c,d,e,f,g,h) ({ \
77 (ipaddr)->addr[0] = htonl((uint32_t)(((a) & 0xffff) << 16) | ((b) & 0xffff)); \
78 (ipaddr)->addr[1] = htonl((((c) & 0xffff) << 16) | ((d) & 0xffff)); \
79 (ipaddr)->addr[2] = htonl((((e) & 0xffff) << 16) | ((f) & 0xffff)); \
80 (ipaddr)->addr[3] = htonl((((g) & 0xffff) << 16) | ((h) & 0xffff)); } )
81
82 #define IP64_ADDR(ipaddr, a,b,c,d) ({ \
83 (ipaddr)->addr[0] = 0; \
84 (ipaddr)->addr[1] = 0; \
85 (ipaddr)->addr[2] = IP64_PREFIX; \
86 IP4_ADDRX(((ipaddr)->addr[3]),(a),(b),(c),(d)); })
87
88 #define IP64_MASKADDR(ipaddr, a,b,c,d) do { \
89 (ipaddr)->addr[0] = 0xffffffff; \
90 (ipaddr)->addr[1] = 0xffffffff; \
91 (ipaddr)->addr[2] = 0xffffffff; \
92 IP4_ADDRX(((ipaddr)->addr[3]),(a),(b),(c),(d)); } while (0)
93
94 #define IP_ADDR_IS_V4(ipaddr) \
95 (((ipaddr)->addr[0] == 0) && \
96 ((ipaddr)->addr[1] == 0) && \
97 ((ipaddr)->addr[2] == IP64_PREFIX))
98
99 /* if set use IPv6 AUTOCONF */
100 #define NETIF_FLAG_AUTOCONF 0x800U
101 /* if set this interface supports Router Advertising */
102 #define NETIF_FLAG_RADV 0x2000U
103 #define NETIF_STD_FLAGS (NETIF_FLAG_AUTOCONF)
104 #define NETIF_ADD_FLAGS (NETIF_FLAG_AUTOCONF | NETIF_FLAG_RADV)
105
106 /** if set, the interface is configured using DHCP */
107 #define NETIF_FLAG_DHCP 0x4000U
108 #define NETIF_IFUP_FLAGS (NETIF_FLAG_DHCP)
109
110 /* netif creation with standard flags */
111 #define lwip_vdeif_add(S,A) lwip_add_vdeif((S),(A),NETIF_STD_FLAGS)
112 #define lwip_tapif_add(S,A) lwip_add_tapif((S),(A),NETIF_STD_FLAGS)
113 #define lwip_tunif_add(S,A) lwip_add_tunif((S),(A),NETIF_STD_FLAGS)
114 #define lwip_slirpif_add(S,A) lwip_add_slirpif((S),(A),0)
115 #define lwip_ifup(N) lwip_ifup_flags((N),0)
116 #define lwip_ifup_dhcp(N) lwip_ifup_flags((N),NETIF_FLAG_DHCP)
117
118 #ifndef LWIPV6DL
119 typedef void (*lwipvoidfun)();
120 extern const struct ip_addr ip_addr_any;
121 #define IP_ADDR_ANY ((struct ip_addr *)&ip_addr_any)
122 struct netif;
123 struct sockaddr;
124 struct stack;
125 struct msghdr;
126
127 /* constructor and destructors are automagically called when lwipv6
128 * gets loaded/unloaded as a shared library.
129 * lwip_init/lwip_fini are for static linking only */
130 void lwip_init(void);
131 void lwip_fini(void);
132
133 void lwip_thread_new(void (* thread)(void *arg), void *arg);
134 /* old interface */
135 struct stack *lwip_stack_new(void);
136 void lwip_stack_free(struct stack *stack);
137 #define LWIP_STACK_FLAG_FORWARDING 1
138 #define LWIP_STACK_FLAG_USERFILTER 0x2
139 #define LWIP_STACK_FLAG_UF_NAT 0x10000
140
141 typedef int (* lwip_capfun) (void);
142
143 /* new api */
144 struct stack *lwip_add_stack(unsigned long flags);
145 struct stack *lwip_add_stack_cap(unsigned long flags, lwip_capfun capfun);
146 void lwip_del_stack(struct stack *stack);
147
148 struct stack *lwip_stack_get(void);
149 void lwip_stack_set(struct stack *stack);
150
151 unsigned long lwip_stack_flags_get(struct stack *stackid);
152 void lwip_stack_flags_set(struct stack *stackid, unsigned long flags);
153
154 struct netif *lwip_add_vdeif(struct stack *stack, void *arg, int flags);
155 struct netif *lwip_add_tapif(struct stack *stack, void *arg, int flags);
156 struct netif *lwip_add_tunif(struct stack *stack, void *arg, int flags);
157 struct netif *lwip_add_slirpif(struct stack *stack, void *arg, int flags);
158
159 int lwip_add_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask);
160 int lwip_del_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask);
161 int lwip_add_route(struct stack *stack, struct ip_addr *addr, struct ip_addr *netmask, struct ip_addr *nexthop, struct netif *netif, int flags);
162 int lwip_del_route(struct stack *stack, struct ip_addr *addr, struct ip_addr *netmask, struct ip_addr *nexthop, struct netif *netif, int flags);
163 int lwip_ifup_flags(struct netif *netif, int flags);
164 int lwip_ifdown(struct netif *netif);
165
166 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
167 int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen);
168 int lwip_shutdown(int s, int how);
169 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
170 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
171 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
172 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
173 int lwip_close(int s);
174 int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen);
175 int lwip_listen(int s, int backlog);
176 ssize_t lwip_recv(int s, void *mem, int len, unsigned int flags);
177 ssize_t lwip_read(int s, void *mem, int len);
178 ssize_t lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
179 struct sockaddr *from, socklen_t *fromlen);
180 ssize_t lwip_send(int s, const void *dataptr, int size, unsigned int flags);
181 ssize_t lwip_sendto(int s, const void *dataptr, int size, unsigned int flags,
182 const struct sockaddr *to, socklen_t tolen);
183 ssize_t lwip_recvmsg(int fd, struct msghdr *msg, int flags);
184 ssize_t lwip_sendmsg(int fd, const struct msghdr *msg, int flags);
185
186 int lwip_msocket(struct stack *stack, int domain, int type, int protocol);
187 int lwip_socket(int domain, int type, int protocol);
188 ssize_t lwip_write(int s, void *dataptr, int size);
189 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
190 struct timeval *timeout);
191 int lwip_pselect(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
192 const struct timespec *timeout, const sigset_t *sigmask);
193 int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout);
194 int lwip_ppoll(struct pollfd *fds, nfds_t nfds,
195 const struct timespec *timeout, const sigset_t *sigmask);
196
197 int lwip_ioctl(int s, long cmd, void *argp);
198 int lwip_fcntl64(int s, int cmd, long arg);
199 int lwip_fcntl(int s, int cmd, long arg);
200
201 struct iovec;
202 ssize_t lwip_writev(int s, struct iovec *vector, int count);
203 ssize_t lwip_readv(int s, struct iovec *vector, int count);
204
205 void lwip_radv_load_config(struct stack *stack,FILE *filein);
206 int lwip_radv_load_configfile(struct stack *stack,void *arg);
207
208 int lwip_event_subscribe(lwipvoidfun cb, void *arg, int fd, int how);
209
210 /* Allows binding to TCP/UDP sockets below 1024 */
211 #define LWIP_CAP_NET_BIND_SERVICE 1<<10
212 /* Allow broadcasting, listen to multicast */
213 #define LWIP_CAP_NET_BROADCAST 1<<11
214 /* Allow interface configuration */
215 #define LWIP_CAP_NET_ADMIN 1<<12
216 /* Allow use of RAW sockets */
217 /* Allow use of PACKET sockets */
218 #define LWIP_CAP_NET_RAW 1<<13
219
220 /* add/delete a slirp port forwarding rule.
221 src/srcport is the local address/port (in the native stack)
222 dest/destport is the virtual address/port where all the
223 traffic to src/srcport must be forwarded */
224 #define SLIRP_LISTEN_UDP 0x1000
225 #define SLIRP_LISTEN_TCP 0x2000
226 #define SLIRP_LISTEN_UNIXSTREAM 0x3000
227 #define SLIRP_LISTEN_TYPEMASK 0x7000
228 #define SLIRP_LISTEN_ONCE 0x8000
229
230 int lwip_slirp_listen_add(struct netif *slirpif,
231 struct ip_addr *dest, int destport,
232 const void *src, int srcport, int flags);
233 int lwip_slirp_listen_del(struct netif *slirpif,
234 struct ip_addr *dest, int destport,
235 const void *src, int srcport, int flags);
236
237 #else /* Dynamic Loading */
238 #include <dlfcn.h>
239
240 struct ip_addr *pip_addr_any;
241 #define IP_ADDR_ANY ((struct ip_addr *)pip_addr_any)
242
243 struct netif;
244 typedef struct netif *pnetif;
245 typedef struct stack *pstack;
246 typedef pnetif (*pnetiffun)();
247 typedef pstack (*pstackfun)();
248 typedef int (*lwiplongfun)();
249 typedef ssize_t (*lwipssizetfun)();
250 typedef void (*lwipvoidfun)();
251
252 pstackfun lwip_stack_new,lwip_stack_new_cap;
253 lwipvoidfun lwip_stack_free;
254 pstackfun lwip_stack_get;
255 lwipvoidfun lwip_stack_set;
256 lwipvoidfun lwip_thread_new;
257
258 pnetiffun lwip_add_vdeif, lwip_add_tapif, lwip_add_tunif, lwip_add_slirpif;
259
260 lwiplongfun lwip_add_addr,
261 lwip_del_addr,
262 lwip_add_route,
263 lwip_del_route,
264 lwip_ifup_flags,
265 lwip_ifdown,
266 lwip_accept,
267 lwip_bind,
268 lwip_shutdown,
269 lwip_getpeername,
270 lwip_getsockname,
271 lwip_getsockopt,
272 lwip_setsockopt,
273 lwip_close,
274 lwip_connect,
275 lwip_listen,
276 lwip_socket,
277 lwip_select,
278 lwip_pselect,
279 lwip_poll,
280 lwip_ppoll,
281 lwip_ioctl,
282 lwip_msocket,
283 lwip_event_subscribe;
284
285 lwipssizetfun lwip_recv,
286 lwip_read,
287 lwip_recvfrom,
288 lwip_send,
289 lwip_sendto,
290 lwip_recvmsg,
291 lwip_sendmsg,
292 lwip_write,
293 lwip_writev,
294 lwip_readv;
295
296
297 /* Added by Diego Billi */
298 lwiplongfun lwip_radv_load_configfile;
299
300 static inline void *loadlwipv6dl()
301 {
302 struct lwipname2fun {
303 char *funcname;
304 lwiplongfun *f;
305 } lwiplibtab[] = {
306 {"lwip_stack_new", (lwiplongfun*)&lwip_stack_new},
307 {"lwip_stack_new_cap", (lwiplongfun*)&lwip_stack_new_cap},
308 {"lwip_stack_free", (lwiplongfun*)&lwip_stack_free},
309 {"lwip_stack_get", (lwiplongfun*)&lwip_stack_get},
310 {"lwip_stack_set", (lwiplongfun*)&lwip_stack_set},
311 {"lwip_add_addr", &lwip_add_addr},
312 {"lwip_del_addr", &lwip_del_addr},
313 {"lwip_add_route", &lwip_add_route},
314 {"lwip_del_route", &lwip_del_route},
315 {"lwip_ifup_flags", &lwip_ifup},
316 {"lwip_ifdown", &lwip_ifdown},
317 {"lwip_accept", &lwip_accept},
318 {"lwip_bind", &lwip_bind},
319 {"lwip_shutdown", &lwip_shutdown},
320 {"lwip_getpeername", &lwip_getpeername},
321 {"lwip_getsockname", &lwip_getsockname},
322 {"lwip_getsockopt", &lwip_getsockopt},
323 {"lwip_setsockopt", &lwip_setsockopt},
324 {"lwip_close", &lwip_close},
325 {"lwip_connect", &lwip_connect},
326 {"lwip_listen", &lwip_listen},
327 {"lwip_recv", &lwip_recv},
328 {"lwip_read", &lwip_read},
329 {"lwip_recvfrom", &lwip_recvfrom},
330 {"lwip_send", &lwip_send},
331 {"lwip_sendto", &lwip_sendto},
332 {"lwip_recvmsg", &lwip_recvmsg},
333 {"lwip_sendmsg", &lwip_sendmsg},
334 {"lwip_socket", &lwip_socket},
335 {"lwip_write", &lwip_write},
336 {"lwip_select", &lwip_select},
337 {"lwip_pselect", &lwip_pselect},
338 {"lwip_poll", &lwip_poll},
339 {"lwip_ppoll", &lwip_ppoll},
340 {"lwip_ioctl", &lwip_ioctl},
341 {"lwip_readv", &lwip_readv},
342 {"lwip_writev", &lwip_writev},
343 {"lwip_msocket", &lwip_msocket},
344 {"lwip_add_vdeif", (lwiplongfun *)(&lwip_add_vdeif)},
345 {"lwip_add_tapif", (lwiplongfun *)(&lwip_add_tapif)},
346 {"lwip_add_tunif", (lwiplongfun *)(&lwip_add_tunif)},
347 {"lwip_add_slirpif", (lwiplongfun *)(&lwip_add_slirpif)},
348 {"lwip_radv_load_configfile", (lwiplongfun *)(&lwip_radv_load_configfile)},
349 {"lwip_thread_new", (lwipvoidfun*) (&lwip_thread_new)},
350 {"lwip_event_subscribe", (lwipvoidfun*) (&lwip_event_subscribe)}
351 };
352 int i;
353 void *lwiphandle = dlopen("liblwipv6.so",RTLD_NOW);
354 if(lwiphandle == NULL) {
355 errno=ENOENT;
356 } else {
357 for (i=0; i<(sizeof(lwiplibtab)/sizeof(struct lwipname2fun)); i++)
358 *lwiplibtab[i].f = dlsym(lwiphandle,lwiplibtab[i].funcname);
359 pip_addr_any = dlsym(lwiphandle,"ip_addr_any");
360 }
361 return lwiphandle;
362 }
363
364 #endif
365 #endif