This repo is obsolete, please see git://git.code.sf.net/p/dummynet/code@master
[ipfw.git] / dummynet2 / ip_fw_dynamic.c
index 9c7d2cd..d33849d 100644 (file)
@@ -128,7 +128,7 @@ static VNET_DEFINE(struct callout, ipfw_timeout);
 #define V_ipfw_timeout                  VNET(ipfw_timeout)
 
 static uma_zone_t ipfw_dyn_rule_zone;
-#if defined( __linux__ ) || defined( _WIN32 )
+#ifndef __FreeBSD__
 DEFINE_SPINLOCK(ipfw_dyn_mtx);
 #else
 static struct mtx ipfw_dyn_mtx;                /* mutex guarding dynamic rules */
@@ -187,6 +187,9 @@ static VNET_DEFINE(u_int32_t, dyn_max);             /* max # of dynamic rules */
 #define        V_dyn_max                       VNET(dyn_max)
 
 #ifdef SYSCTL_NODE
+
+SYSBEGIN(f2)
+
 SYSCTL_DECL(_net_inet_ip_fw);
 SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, dyn_buckets,
     CTLFLAG_RW, &VNET_NAME(dyn_buckets), 0,
@@ -221,6 +224,9 @@ SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, dyn_short_lifetime,
 SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, dyn_keepalive,
     CTLFLAG_RW, &VNET_NAME(dyn_keepalive), 0,
     "Enable keepalives for dyn. rules");
+
+SYSEND
+
 #endif /* SYSCTL_NODE */
 
 
@@ -470,7 +476,7 @@ next:
                V_ipfw_dyn_v[i] = q;
        }
        if (pkt->proto == IPPROTO_TCP) { /* update state according to flags */
-               u_char flags = pkt->flags & (TH_FIN|TH_SYN|TH_RST);
+               u_char flags = pkt->_flags & (TH_FIN|TH_SYN|TH_RST);
 
 #define BOTH_SYN       (TH_SYN | (TH_SYN << 8))
 #define BOTH_FIN       (TH_FIN | (TH_FIN << 8))
@@ -888,10 +894,7 @@ struct mbuf *
 ipfw_send_pkt(struct mbuf *replyto, struct ipfw_flow_id *id, u_int32_t seq,
     u_int32_t ack, int flags)
 {
-#ifdef __linux__       // XXX to be revised
-       return NULL;
-#else
-       struct mbuf *m;
+       struct mbuf *m = NULL;          /* stupid compiler */
        int len, dir;
        struct ip *h = NULL;            /* stupid compiler */
 #ifdef INET6
@@ -1009,7 +1012,8 @@ ipfw_send_pkt(struct mbuf *replyto, struct ipfw_flow_id *id, u_int32_t seq,
                h->ip_hl = sizeof(*h) >> 2;
                h->ip_tos = IPTOS_LOWDELAY;
                h->ip_off = 0;
-               h->ip_len = htons(len);
+               /* ip_len must be in host format for ip_output */
+               h->ip_len = len;
                h->ip_ttl = V_ip_defttl;
                h->ip_sum = 0;
                break;
@@ -1026,14 +1030,14 @@ ipfw_send_pkt(struct mbuf *replyto, struct ipfw_flow_id *id, u_int32_t seq,
        }
 
        return (m);
-#endif /* !__linux__ */
 }
 
 /*
  * This procedure is only used to handle keepalives. It is invoked
  * every dyn_keepalive_period
  */
-static void
+ /* dummynet() and ipfw_tick() can't be static in windows */
+void
 ipfw_tick(void * vnetx) 
 {
        struct mbuf *m0, *m, *mnext, **mtailp;
@@ -1124,8 +1128,8 @@ ipfw_tick(void * vnetx)
        }
 #endif
 done:
-       callout_reset(&V_ipfw_timeout, V_dyn_keepalive_period * hz,
-                     ipfw_tick, vnetx);
+       callout_reset_on(&V_ipfw_timeout, V_dyn_keepalive_period * hz,
+                     ipfw_tick, vnetx, 0);
        CURVNET_RESTORE();
 }
 
@@ -1166,7 +1170,7 @@ ipfw_dyn_init(void)
         
         V_dyn_max = 4096;       /* max # of dynamic rules */
         callout_init(&V_ipfw_timeout, CALLOUT_MPSAFE);
-        callout_reset(&V_ipfw_timeout, hz, ipfw_tick, curvnet);
+        callout_reset_on(&V_ipfw_timeout, hz, ipfw_tick, curvnet, 0);
 }
 
 void