integrated
[ipfw.git] / dummynet2 / include / sys / mbuf.h
index 12837bf..e65bbb6 100644 (file)
@@ -64,14 +64,24 @@ struct mbuf {
        void *m_data;
        int m_len;      /* length in this mbuf */
        int m_flags;
+#ifdef __linux__
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
        struct nf_info *queue_entry;
 #else
        struct nf_queue_entry *queue_entry;
+#endif
+#else /* _WIN32 */
+       int             direction;      /* could go in rcvif */
+       NDIS_HANDLE     context;        /* replaces queue_entry or skb ?*/
+       PNDIS_PACKET    pkt;
 #endif
        struct sk_buff *m_skb;
        struct {
+#ifdef __linux__
                struct net_device *rcvif;
+#else
+               struct ifnet *rcvif;
+#endif
                int len;        /* total packet len */
                SLIST_HEAD (packet_tags, m_tag) tags;
        } m_pkthdr;
@@ -154,10 +164,20 @@ m_tag_delete(struct mbuf *m, struct m_tag *t)
 static __inline struct m_tag *
 m_tag_locate(struct mbuf *m, u_int32_t n, int x, struct m_tag *t)
 {
-       return NULL;
+       struct m_tag *tag;
+
+       tag = m_tag_first(m);
+       if (tag == NULL)
+               return NULL;
+
+       if (tag->m_tag_cookie != n || tag->m_tag_id != x)
+               return NULL;
+       else
+               return tag;
 };
 
 #define M_SETFIB(_m, _fib)     /* nothing on linux */
+
 static __inline void
 m_freem(struct mbuf *m)
 {
@@ -173,12 +193,34 @@ m_freem(struct mbuf *m)
        free(m, M_IPFW);
 };
 
-/* we cannot pullup */
-//#define m_pullup(__m, __i)   (m)
+/* m_pullup is not supported, there is a macro in missing.h */
 
 #define M_GETFIB(_m)   0
 
-#endif /* !__linux__ */
+/* macro used to create a new mbuf */
+#define MT_DATA         1       /* dynamic (data) allocation */
+#define MSIZE           256     /* size of an mbuf */
+#define MGETHDR(_m, _how, _type)   ((_m) = m_gethdr((_how), (_type)))
+
+/* allocate and init a new mbuf using the same structure of FreeBSD */
+static __inline struct mbuf *
+m_gethdr(int how, short type)
+{
+       struct mbuf *m;
+
+       m = malloc(MSIZE, M_IPFW, M_NOWAIT);
+
+       if (m == NULL) {
+               return m;
+       }
+
+       /* here we have MSIZE - sizeof(struct mbuf) available */
+       m->m_data = m + 1;
+
+       return m;
+}
+
+#endif /* __linux__ || _WIN32 */
 
 /*
  * Persistent tags stay with an mbuf until the mbuf is reclaimed.  Otherwise