Work on the radix code, added support to compile on OpenWRT,
[ipfw.git] / dummynet / missing.h
index 76b8153..d18f503 100644 (file)
@@ -25,6 +25,7 @@
 
 /*
  * $Id$
+ *
  * Header for kernel variables and functions that are not available in
  * userland.
  */
@@ -55,9 +56,10 @@ struct inpcb;
 
 /*
  * Kernel locking support.
- * FreeBSD uses mtx in dummynet.c, and rwlocks in ipfw.c
+ * FreeBSD uses mtx in dummynet.c and struct rwlock ip_fw2.c
  *
  * In linux we use spinlock_bh to implement both.
+ * For 'struct rwlock' we need an #ifdef to change it to spinlock_t
  */
 
 #ifndef DEFINE_SPINLOCK        /* this is for linux 2.4 */
@@ -73,6 +75,7 @@ struct inpcb;
 #define rw_runlock(_l)         spin_unlock_bh(_l)
 #define rw_wlock(_l)           spin_lock_bh(_l)
 #define rw_wunlock(_l)         spin_unlock_bh(_l)
+#define rw_init_flags(_l, s, v)
 
 #define mtx_assert(a, b)
 #define        mtx_destroy(m)
@@ -82,6 +85,13 @@ struct inpcb;
 
 /* end of locking support */
 
+/* in netinet/in.h */
+#define        in_nullhost(x)  ((x).s_addr == INADDR_ANY)
+
+/* bzero not present on linux, but this should go in glue.h */
+#define bzero(s, n) memset(s, 0, n)
+#define bcmp(p1, p2, n) memcmp(p1, p2, n)
+
 /* ethernet stuff */
 #define        ETHERTYPE_IP            0x0800  /* IP protocol */
 #define        ETHER_ADDR_LEN          6       /* length of an Ethernet address */
@@ -263,12 +273,13 @@ struct pf_mtag {
         u_int32_t        qid;           /* queue id */
 };
 
-/* radix related */
-
+#if 0 // ndef radix
+/* radix stuff in radix.h and radix.c */
 struct radix_node {
        caddr_t rn_key;         /* object of search */
        caddr_t rn_mask;        /* netmask, if present */
 };
+#endif /* !radix */
 
 /* missing kernel functions */
 char *inet_ntoa(struct in_addr ina);
@@ -336,6 +347,17 @@ int sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen);
 /* defined in session.c */
 int priv_check(struct thread *td, int priv);
 
+/* struct ucred is in linux/socket.h and has pid, uid, gid.
+ * We need a 'bsd_ucred' to store also the extra info
+ */
+
+struct bsd_ucred {
+       uid_t           uid;
+       gid_t           gid;
+       uint32_t        xid;
+       uint32_t        nid;
+};
+
 int securelevel_ge(struct ucred *cr, int level);
 
 struct sysctl_oid;
@@ -345,12 +367,32 @@ struct sysctl_req;
  * sysctl are mapped into /sys/module/ipfw_mod parameters
  */
 #define CTLFLAG_RD             1
+#define CTLFLAG_RDTUN          1
 #define CTLFLAG_RW             2
 #define CTLFLAG_SECURE3                0 // unsupported
+#define CTLFLAG_VNET    0      /* unsupported */
 
 #ifdef _WIN32
 #define module_param_named(_name, _var, _ty, _perm)
 #else
+
+/* Linux 2.4 is mostly for openwrt */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#include <linux/bitops.h>       /* generic_ffs() used in ip_fw2.c */
+typedef uint32_t __be32;
+typedef uint16_t __be16;
+struct sock;
+struct net;
+struct inet_hashinfo;
+struct sock *inet_lookup(
+       struct inet_hashinfo *hashinfo,
+        const __be32 saddr, const __be16 sport,
+        const __be32 daddr, const __be16 dport,
+        const int dif);
+static int inet_iif(const struct sk_buff *skb);
+struct sock *tcp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
+#endif /* Linux < 2.6 */
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
 #define module_param_named(_name, _var, _ty, _perm)    \
        //module_param(_name, _ty, 0644)
@@ -358,6 +400,7 @@ struct sysctl_req;
 #endif /* __linux__ */
 
 #define SYSCTL_DECL(_1)
+#define SYSCTL_OID(_1, _2, _3, _4, _5, _6, _7, _8)
 #define SYSCTL_NODE(_1, _2, _3, _4, _5, _6)
 #define _SYSCTL_BASE(_name, _var, _ty, _perm)          \
        module_param_named(_name, *(_var), _ty,         \
@@ -374,13 +417,15 @@ struct sysctl_req;
        _SYSCTL_BASE(_name, _var, ulong, _mode)
 
 #define SYSCTL_UINT(_base, _oid, _name, _mode, _var, _val, _desc)      \
-       // _SYSCTL_BASE(_name, _var, uint, _mode)
+        _SYSCTL_BASE(_name, _var, uint, _mode)
 
 #define SYSCTL_HANDLER_ARGS            \
        struct sysctl_oid *oidp, void *arg1, int arg2, struct sysctl_req *req
 int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
 int sysctl_handle_long(SYSCTL_HANDLER_ARGS); 
 
+#define TUNABLE_INT(_name, _ptr)
+
 void ether_demux(struct ifnet *ifp, struct mbuf *m);
 
 int ether_output_frame(struct ifnet *ifp, struct mbuf *m);
@@ -398,8 +443,6 @@ u_short in_cksum_skip(struct mbuf *m, int len, int skip);
 #define INP_LOCK_ASSERT(a)
 #endif
 
-int rn_inithead(void **head, int off);
-
 int jailed(struct ucred *cred);
 
 /*
@@ -415,4 +458,50 @@ int in_localaddr(struct in_addr in);
 
 int fnmatch(const char *pattern, const char *string, int flags);
 
+int
+linux_lookup(const int proto, const __be32 saddr, const __be16 sport,
+       const __be32 daddr, const __be16 dport,
+       struct sk_buff *skb, int dir, struct bsd_ucred *u);
+
+/* vnet wrappers, in vnet.h and ip_var.h */
+int ipfw_init(void);
+void ipfw_destroy(void);
+struct ip_fw_args;
+extern int (*ip_dn_io_ptr)(struct mbuf **m, int dir, struct ip_fw_args *fwa);
+
+#define curvnet                 NULL
+#define        CURVNET_SET(_v)
+#define        CURVNET_RESTORE()
+#define VNET_ASSERT(condition)
+
+#define VNET_NAME(n)            n
+#define VNET_DECLARE(t, n)      extern t n
+#define VNET_DEFINE(t, n)       t n
+#define _VNET_PTR(b, n)         &VNET_NAME(n)
+/*
+ * Virtualized global variable accessor macros.
+ */
+#define VNET_VNET_PTR(vnet, n)          (&(n))
+#define VNET_VNET(vnet, n)              (n)
+
+#define VNET_PTR(n)             (&(n))
+#define VNET(n)                 (n)
+
+extern int (*ip_dn_ctl_ptr)(struct sockopt *);
+typedef int ip_fw_ctl_t(struct sockopt *);
+extern ip_fw_ctl_t *ip_fw_ctl_ptr;
+
+/* For kernel ipfw_ether and ipfw_bridge. */
+struct ip_fw_args;
+typedef int ip_fw_chk_t(struct ip_fw_args *args);
+extern  ip_fw_chk_t     *ip_fw_chk_ptr;
+
+#define V_ip_fw_chk_ptr         VNET(ip_fw_chk_ptr)
+#define V_ip_fw_ctl_ptr         VNET(ip_fw_ctl_ptr)
+#define        V_tcbinfo               VNET(tcbinfo)
+#define        V_udbinfo               VNET(udbinfo)
+
+#define SYSCTL_VNET_PROC       SYSCTL_PROC
+#define SYSCTL_VNET_INT                SYSCTL_INT
+
 #endif /* !_MISSING_H_ */