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
29 * Header for kernel variables and functions that are not available in
38 #ifndef DEFINE_SPINLOCK
39 #define DEFINE_SPINLOCK(x) FAST_MUTEX x
41 /* spinlock --> Guarded Mutex KGUARDED_MUTEX */
42 /* http://www.reactos.org/wiki/index.php/Guarded_Mutex */
43 #define spin_lock_init(_l)
44 #define spin_lock_bh(_l)
45 #define spin_unlock_bh(_l)
47 #include <sys/socket.h> /* bsd-compat.c */
48 #include <netinet/in.h> /* bsd-compat.c */
49 #include <netinet/ip.h> /* local version */
53 #include <linux/time.h> /* do_gettimeofday */
54 #include <netinet/ip.h> /* local version */
58 * Kernel locking support.
59 * FreeBSD uses mtx in dummynet.c, and rwlocks in ipfw.c
61 * In linux we use spinlock_bh to implement both.
64 #ifndef DEFINE_SPINLOCK /* this is for linux 2.4 */
65 #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
68 #endif /* __linux__ */
70 #define rw_assert(a, b)
71 #define rw_destroy(_l)
72 #define rw_init(_l, msg) spin_lock_init(_l)
73 #define rw_rlock(_l) spin_lock_bh(_l)
74 #define rw_runlock(_l) spin_unlock_bh(_l)
75 #define rw_wlock(_l) spin_lock_bh(_l)
76 #define rw_wunlock(_l) spin_unlock_bh(_l)
78 #define mtx_assert(a, b)
79 #define mtx_destroy(m)
80 #define mtx_init(m, a,b,c) spin_lock_init(m)
81 #define mtx_lock(_l) spin_lock_bh(_l)
82 #define mtx_unlock(_l) spin_unlock_bh(_l)
84 /* end of locking support */
87 #define ETHERTYPE_IP 0x0800 /* IP protocol */
88 #define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
90 u_char ether_dhost[ETHER_ADDR_LEN];
91 u_char ether_shost[ETHER_ADDR_LEN];
95 #define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
96 #define ETHER_TYPE_LEN 2 /* length of the Ethernet type field */
97 #define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
100 #define __FreeBSD_version 500035
104 int my_mod_register(struct moduledata *mod, const char *name, int order);
106 /* define some macro for ip_dummynet */
111 #define MALLOC_DEFINE(type, shortdesc, longdesc) \
112 struct malloc_type type[1]; void *md_dummy_ ## type = type
116 #define log(_level, fmt, arg...) printk(KERN_ERR fmt, ##arg)
119 * gettimeofday would be in sys/time.h but it is not
120 * visible if _KERNEL is defined
122 int gettimeofday(struct timeval *, struct timezone *);
125 #define MALLOC_DEFINE(a,b,c)
129 extern long tick; /* exists in 2.4 but not in 2.6 */
130 extern int bootverbose;
131 extern time_t time_uptime;
132 extern struct timeval boottime;
134 extern int max_linkhdr;
135 extern int ip_defttl;
136 extern u_long in_ifaddrhmask; /* mask for hash table */
137 extern struct in_ifaddrhashhead *in_ifaddrhashtbl; /* inet addr hash table */
139 /*-------------------------------------------------*/
141 /* define, includes and functions missing in linux */
142 /* include and define */
143 #include <arpa/inet.h> /* inet_ntoa */
147 /* used by ip_dummynet.c */
148 void reinject_drop(struct mbuf* m);
150 #include <linux/errno.h> /* error define */
151 #include <linux/if.h> /* IFNAMESIZ */
154 * some network structure can be defined in the bsd way
155 * by using the _FAVOR_BSD definition. This is not true
156 * for icmp structure.
157 * XXX struct icmp contains bsd names in
158 * /usr/include/netinet/ip_icmp.h
161 #define icmp_code code
162 #define icmp_type type
164 /* linux in6_addr has no member __u6_addr
165 * replace the whole structure ?
167 #define __u6_addr in6_u
168 #define __u6_addr32 u6_addr32
169 #endif /* __linux__ */
171 /* defined in linux/sctp.h with no bsd definition */
173 uint16_t src_port; /* source port */
174 uint16_t dest_port; /* destination port */
175 uint32_t v_tag; /* verification tag of packet */
176 uint32_t checksum; /* Adler32 C-Sum */
177 /* chunks follow... */
180 /* missing definition */
186 #define RTF_CLONING 0x100 /* generate new routes on use */
188 #define IPPROTO_OSPFIGP 89 /* OSPFIGP */
189 #define IPPROTO_CARP 112 /* CARP */
191 #define IPPROTO_IPV4 IPPROTO_IPIP /* for compatibility */
194 #define CARP_VERSION 2
195 #define CARP_ADVERTISEMENT 0x01
197 #define PRIV_NETINET_IPFW 491 /* Administer IPFW firewall. */
199 #define IP_FORWARDING 0x1 /* most of ip header exists */
201 #define NETISR_IP 2 /* same as AF_INET */
203 #define PRIV_NETINET_DUMMYNET 494 /* Administer DUMMYNET. */
205 extern int securelevel;
208 #if BYTE_ORDER == LITTLE_ENDIAN
209 u_int8_t carp_type:4,
212 #if BYTE_ORDER == BIG_ENDIAN
213 u_int8_t carp_version:4,
219 int dummy; /* windows compiler does not like empty definition */
223 struct rtentry *ro_rt;
224 struct sockaddr ro_dst;
232 * ifnet->if_snd is used in ip_dummynet.c to take the transmission
235 #if defined( __linux__)
236 #define if_xname name
238 #elif defined( _WIN32 )
239 /* used in ip_dummynet.c */
241 char if_xname[IFNAMSIZ]; /* external name (name + unit) */
242 // struct ifaltq if_snd; /* output queue (includes altq) */
246 char if_xname[IFNAMSIZ]; /* external name (name + unit) */
251 int in_cksum(struct mbuf *m, int len);
252 #define divert_cookie(mtag) 0
253 #define divert_info(mtag) 0
254 #define INADDR_TO_IFP(a, b) b = NULL
255 #define pf_find_mtag(a) NULL
256 #define pf_get_mtag(a) NULL
258 #define AF_LINK AF_ASH /* ? our sys/socket.h */
262 void *hdr; /* saved hdr pos in mbuf, for ECN */
263 sa_family_t af; /* for ECN */
264 u_int32_t qid; /* queue id */
270 caddr_t rn_key; /* object of search */
271 caddr_t rn_mask; /* netmask, if present */
274 /* missing kernel functions */
275 char *inet_ntoa(struct in_addr ina);
279 * Return the risult of a/b
281 * this is used in linux kernel space,
282 * since the 64bit division needs to
283 * be done using a macro
286 div64(int64_t a, int64_t b);
289 inet_ntoa_r(struct in_addr ina, char *buf);
291 /* from bsd sys/queue.h */
292 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
293 for ((var) = TAILQ_FIRST((head)); \
294 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
297 #define SLIST_FOREACH_SAFE(var, head, field, tvar) \
298 for ((var) = SLIST_FIRST((head)); \
299 (var) && ((tvar) = SLIST_NEXT((var), field), 1); \
302 /* depending of linux version */
303 #ifndef ETHERTYPE_IPV6
304 #define ETHERTYPE_IPV6 0x86dd /* IP protocol version 6 */
307 /*-------------------------------------------------*/
309 extern u_int rt_numfibs;
311 /* involves kernel locking function */
314 #define RTFREE(a) fprintf(stderr, "RTFREE: commented out locks\n");
317 void getmicrouptime(struct timeval *tv);
319 /* from sys/netinet/ip_output.c */
324 struct mbuf *ip_reass(struct mbuf *);
325 u_short in_cksum_hdr(struct ip *);
326 int ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
327 struct ip_moptions *imo, struct inpcb *inp);
329 /* from net/netisr.c */
330 void netisr_dispatch(int num, struct mbuf *m);
332 /* definition moved in missing.c */
333 int sooptcopyout(struct sockopt *sopt, const void *buf, size_t len);
335 int sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen);
337 /* defined in session.c */
338 int priv_check(struct thread *td, int priv);
340 int securelevel_ge(struct ucred *cr, int level);
346 * sysctl are mapped into /sys/module/ipfw_mod parameters
350 #define CTLFLAG_SECURE3 0 // unsupported
353 #define module_param_named(_name, _var, _ty, _perm)
355 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
356 #define module_param_named(_name, _var, _ty, _perm) \
357 //module_param(_name, _ty, 0644)
359 #endif /* __linux__ */
361 #define SYSCTL_DECL(_1)
362 #define SYSCTL_NODE(_1, _2, _3, _4, _5, _6)
363 #define _SYSCTL_BASE(_name, _var, _ty, _perm) \
364 module_param_named(_name, *(_var), _ty, \
365 ( (_perm) == CTLFLAG_RD) ? 0444: 0644 )
366 #define SYSCTL_PROC(_base, _oid, _name, _mode, _var, _val, _desc, _a, _b)
368 #define SYSCTL_INT(_base, _oid, _name, _mode, _var, _val, _desc) \
369 _SYSCTL_BASE(_name, _var, int, _mode)
371 #define SYSCTL_LONG(_base, _oid, _name, _mode, _var, _val, _desc) \
372 _SYSCTL_BASE(_name, _var, long, _mode)
374 #define SYSCTL_ULONG(_base, _oid, _name, _mode, _var, _val, _desc) \
375 _SYSCTL_BASE(_name, _var, ulong, _mode)
377 #define SYSCTL_UINT(_base, _oid, _name, _mode, _var, _val, _desc) \
378 // _SYSCTL_BASE(_name, _var, uint, _mode)
380 #define SYSCTL_HANDLER_ARGS \
381 struct sysctl_oid *oidp, void *arg1, int arg2, struct sysctl_req *req
382 int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
383 int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
385 void ether_demux(struct ifnet *ifp, struct mbuf *m);
387 int ether_output_frame(struct ifnet *ifp, struct mbuf *m);
389 void in_rtalloc_ign(struct route *ro, u_long ignflags, u_int fibnum);
391 void icmp_error(struct mbuf *n, int type, int code, uint32_t dest, int mtu);
393 void rtfree(struct rtentry *rt);
395 u_short in_cksum_skip(struct mbuf *m, int len, int skip);
397 #ifdef INP_LOCK_ASSERT
398 #undef INP_LOCK_ASSERT
399 #define INP_LOCK_ASSERT(a)
402 int rn_inithead(void **head, int off);
404 int jailed(struct ucred *cred);
407 * Return 1 if an internet address is for a ``local'' host
408 * (one to which we have a connection). If subnetsarelocal
409 * is true, this includes other subnets of the local net.
410 * Otherwise, it includes only the directly-connected (sub)nets.
412 int in_localaddr(struct in_addr in);
414 /* the prototype is already in the headers */
415 //int ipfw_chg_hook(SYSCTL_HANDLER_ARGS);
417 int fnmatch(const char *pattern, const char *string, int flags);
421 linux_lookup(const int proto, const __be32 saddr, const __be16 sport,
422 const __be32 daddr, const __be16 dport,
423 struct sk_buff *skb, int dir, struct ip_fw_ugid *ugp);
425 #endif /* !_MISSING_H_ */