2 * Copyright (C) 2009 Luigi Rizzo, Marta Carbone, Universita` di Pisa
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * Header for kernel variables and functions that are not available in
37 #ifndef DEFINE_SPINLOCK
38 #define DEFINE_SPINLOCK(x) FAST_MUTEX x
40 /* spinlock --> Guarded Mutex KGUARDED_MUTEX */
41 /* http://www.reactos.org/wiki/index.php/Guarded_Mutex */
42 #define spin_lock_init(_l)
43 #define spin_lock_bh(_l)
44 #define spin_unlock_bh(_l)
46 #include <sys/socket.h> /* bsd-compat.c */
47 #include <netinet/in.h> /* bsd-compat.c */
48 #include <netinet/ip.h> /* local version */
52 #include <linux/time.h> /* do_gettimeofday */
53 #include <netinet/ip.h> /* local version */
57 * Kernel locking support.
58 * FreeBSD uses mtx in dummynet.c, and rwlocks in ipfw.c
60 * In linux we use spinlock_bh to implement both.
63 #ifndef DEFINE_SPINLOCK /* this is for linux 2.4 */
64 #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
67 #endif /* __linux__ */
69 #define rw_assert(a, b)
70 #define rw_destroy(_l)
71 #define rw_init(_l, msg) spin_lock_init(_l)
72 #define rw_rlock(_l) spin_lock_bh(_l)
73 #define rw_runlock(_l) spin_unlock_bh(_l)
74 #define rw_wlock(_l) spin_lock_bh(_l)
75 #define rw_wunlock(_l) spin_unlock_bh(_l)
77 #define mtx_assert(a, b)
78 #define mtx_destroy(m)
79 #define mtx_init(m, a,b,c) spin_lock_init(m)
80 #define mtx_lock(_l) spin_lock_bh(_l)
81 #define mtx_unlock(_l) spin_unlock_bh(_l)
83 /* end of locking support */
86 #define ETHERTYPE_IP 0x0800 /* IP protocol */
87 #define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
89 u_char ether_dhost[ETHER_ADDR_LEN];
90 u_char ether_shost[ETHER_ADDR_LEN];
94 #define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
95 #define ETHER_TYPE_LEN 2 /* length of the Ethernet type field */
96 #define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
99 #define __FreeBSD_version 500035
103 int my_mod_register(struct moduledata *mod, const char *name, int order);
105 /* define some macro for ip_dummynet */
110 #define MALLOC_DEFINE(type, shortdesc, longdesc) \
111 struct malloc_type type[1]; void *md_dummy_ ## type = type
115 #define log(_level, fmt, arg...) printk(KERN_ERR fmt, ##arg)
118 * gettimeofday would be in sys/time.h but it is not
119 * visible if _KERNEL is defined
121 int gettimeofday(struct timeval *, struct timezone *);
124 #define MALLOC_DEFINE(a,b,c)
128 extern long tick; /* exists in 2.4 but not in 2.6 */
129 extern int bootverbose;
130 extern time_t time_uptime;
131 extern struct timeval boottime;
133 extern int max_linkhdr;
134 extern int ip_defttl;
135 extern u_long in_ifaddrhmask; /* mask for hash table */
136 extern struct in_ifaddrhashhead *in_ifaddrhashtbl; /* inet addr hash table */
138 /*-------------------------------------------------*/
140 /* define, includes and functions missing in linux */
141 /* include and define */
142 #include <arpa/inet.h> /* inet_ntoa */
146 /* used by ip_dummynet.c */
147 void reinject_drop(struct mbuf* m);
149 #include <linux/errno.h> /* error define */
150 #include <linux/if.h> /* IFNAMESIZ */
153 * some network structure can be defined in the bsd way
154 * by using the _FAVOR_BSD definition. This is not true
155 * for icmp structure.
156 * XXX struct icmp contains bsd names in
157 * /usr/include/netinet/ip_icmp.h
160 #define icmp_code code
161 #define icmp_type type
163 /* linux in6_addr has no member __u6_addr
164 * replace the whole structure ?
166 #define __u6_addr in6_u
167 #define __u6_addr32 u6_addr32
168 #endif /* __linux__ */
170 /* defined in linux/sctp.h with no bsd definition */
172 uint16_t src_port; /* source port */
173 uint16_t dest_port; /* destination port */
174 uint32_t v_tag; /* verification tag of packet */
175 uint32_t checksum; /* Adler32 C-Sum */
176 /* chunks follow... */
179 /* missing definition */
185 #define RTF_CLONING 0x100 /* generate new routes on use */
187 #define IPPROTO_OSPFIGP 89 /* OSPFIGP */
188 #define IPPROTO_CARP 112 /* CARP */
190 #define IPPROTO_IPV4 IPPROTO_IPIP /* for compatibility */
193 #define CARP_VERSION 2
194 #define CARP_ADVERTISEMENT 0x01
196 #define PRIV_NETINET_IPFW 491 /* Administer IPFW firewall. */
198 #define IP_FORWARDING 0x1 /* most of ip header exists */
200 #define NETISR_IP 2 /* same as AF_INET */
202 #define PRIV_NETINET_DUMMYNET 494 /* Administer DUMMYNET. */
204 extern int securelevel;
207 #if BYTE_ORDER == LITTLE_ENDIAN
208 u_int8_t carp_type:4,
211 #if BYTE_ORDER == BIG_ENDIAN
212 u_int8_t carp_version:4,
218 int dummy; /* windows compiler does not like empty definition */
222 struct rtentry *ro_rt;
223 struct sockaddr ro_dst;
231 * ifnet->if_snd is used in ip_dummynet.c to take the transmission
234 #if defined( __linux__)
235 #define if_xname name
237 #elif defined( _WIN32 )
238 /* used in ip_dummynet.c */
240 char if_xname[IFNAMSIZ]; /* external name (name + unit) */
241 // struct ifaltq if_snd; /* output queue (includes altq) */
245 char if_xname[IFNAMSIZ]; /* external name (name + unit) */
250 int in_cksum(struct mbuf *m, int len);
251 #define divert_cookie(mtag) 0
252 #define divert_info(mtag) 0
253 #define INADDR_TO_IFP(a, b) b = NULL
254 #define pf_find_mtag(a) NULL
255 #define pf_get_mtag(a) NULL
257 #define AF_LINK AF_ASH /* ? our sys/socket.h */
261 void *hdr; /* saved hdr pos in mbuf, for ECN */
262 sa_family_t af; /* for ECN */
263 u_int32_t qid; /* queue id */
269 caddr_t rn_key; /* object of search */
270 caddr_t rn_mask; /* netmask, if present */
273 /* missing kernel functions */
274 char *inet_ntoa(struct in_addr ina);
278 * Return the risult of a/b
280 * this is used in linux kernel space,
281 * since the 64bit division needs to
282 * be done using a macro
285 div64(int64_t a, int64_t b);
288 inet_ntoa_r(struct in_addr ina, char *buf);
290 /* from bsd sys/queue.h */
291 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
292 for ((var) = TAILQ_FIRST((head)); \
293 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
296 #define SLIST_FOREACH_SAFE(var, head, field, tvar) \
297 for ((var) = SLIST_FIRST((head)); \
298 (var) && ((tvar) = SLIST_NEXT((var), field), 1); \
301 /* depending of linux version */
302 #ifndef ETHERTYPE_IPV6
303 #define ETHERTYPE_IPV6 0x86dd /* IP protocol version 6 */
306 /*-------------------------------------------------*/
308 extern u_int rt_numfibs;
310 /* involves kernel locking function */
313 #define RTFREE(a) fprintf(stderr, "RTFREE: commented out locks\n");
316 void getmicrouptime(struct timeval *tv);
318 /* from sys/netinet/ip_output.c */
323 struct mbuf *ip_reass(struct mbuf *);
324 u_short in_cksum_hdr(struct ip *);
325 int ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
326 struct ip_moptions *imo, struct inpcb *inp);
328 /* from net/netisr.c */
329 void netisr_dispatch(int num, struct mbuf *m);
331 /* definition moved in missing.c */
332 int sooptcopyout(struct sockopt *sopt, const void *buf, size_t len);
334 int sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen);
336 /* defined in session.c */
337 int priv_check(struct thread *td, int priv);
339 int securelevel_ge(struct ucred *cr, int level);
345 * sysctl are mapped into /sys/module/ipfw_mod parameters
349 #define CTLFLAG_SECURE3 0 // unsupported
352 #define module_param_named(_name, _var, _ty, _perm)
354 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
355 #define module_param_named(_name, _var, _ty, _perm) \
356 //module_param(_name, _ty, 0644)
358 #endif /* __linux__ */
360 #define SYSCTL_DECL(_1)
361 #define SYSCTL_NODE(_1, _2, _3, _4, _5, _6)
362 #define _SYSCTL_BASE(_name, _var, _ty, _perm) \
363 module_param_named(_name, *(_var), _ty, \
364 ( (_perm) == CTLFLAG_RD) ? 0444: 0644 )
365 #define SYSCTL_PROC(_base, _oid, _name, _mode, _var, _val, _desc, _a, _b)
367 #define SYSCTL_INT(_base, _oid, _name, _mode, _var, _val, _desc) \
368 _SYSCTL_BASE(_name, _var, int, _mode)
370 #define SYSCTL_LONG(_base, _oid, _name, _mode, _var, _val, _desc) \
371 _SYSCTL_BASE(_name, _var, long, _mode)
373 #define SYSCTL_ULONG(_base, _oid, _name, _mode, _var, _val, _desc) \
374 _SYSCTL_BASE(_name, _var, ulong, _mode)
376 #define SYSCTL_UINT(_base, _oid, _name, _mode, _var, _val, _desc) \
377 // _SYSCTL_BASE(_name, _var, uint, _mode)
379 #define SYSCTL_HANDLER_ARGS \
380 struct sysctl_oid *oidp, void *arg1, int arg2, struct sysctl_req *req
381 int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
382 int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
384 void ether_demux(struct ifnet *ifp, struct mbuf *m);
386 int ether_output_frame(struct ifnet *ifp, struct mbuf *m);
388 void in_rtalloc_ign(struct route *ro, u_long ignflags, u_int fibnum);
390 void icmp_error(struct mbuf *n, int type, int code, uint32_t dest, int mtu);
392 void rtfree(struct rtentry *rt);
394 u_short in_cksum_skip(struct mbuf *m, int len, int skip);
396 #ifdef INP_LOCK_ASSERT
397 #undef INP_LOCK_ASSERT
398 #define INP_LOCK_ASSERT(a)
401 int rn_inithead(void **head, int off);
403 int jailed(struct ucred *cred);
406 * Return 1 if an internet address is for a ``local'' host
407 * (one to which we have a connection). If subnetsarelocal
408 * is true, this includes other subnets of the local net.
409 * Otherwise, it includes only the directly-connected (sub)nets.
411 int in_localaddr(struct in_addr in);
413 /* the prototype is already in the headers */
414 //int ipfw_chg_hook(SYSCTL_HANDLER_ARGS);
416 int fnmatch(const char *pattern, const char *string, int flags);
418 #endif /* !_MISSING_H_ */