2 * Copyright (C) 2009 Luigi Rizzo, Universita` di Pisa
6 * A simple compatibility interface to map mbufs onto sk_buff
12 #include <sys/malloc.h> /* we use free() */
13 /* hopefully queue.h is already included by someone else */
14 #include <sys/queue.h>
17 /* bzero not present on linux, but this should go in glue.h */
18 // #define bzero(s, n) memset(s, 0, n)
21 * We implement a very simplified UMA allocator where the backend
22 * is simply malloc, and uma_zone only stores the length of the components.
24 typedef int uma_zone_t; /* the zone size */
26 #define uma_zcreate(name, len, _3, _4, _5, _6, _7, _8) (len)
29 #define uma_zfree(zone, item) free(item, M_IPFW)
30 #define uma_zalloc(zone, flags) malloc(zone, M_IPFW, flags)
31 #define uma_zdestroy(zone) do {} while (0)
34 * Macros for type conversion:
35 * mtod(m, t) -- Convert mbuf pointer to data pointer of correct type.
37 #define mtod(m, t) ((t)((m)->m_data))
42 * Packet tag structure (see below for details).
45 SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
46 u_int16_t m_tag_id; /* Tag ID */
47 u_int16_t m_tag_len; /* Length of data */
48 u_int32_t m_tag_cookie; /* ABI/Module ID */
49 void (*m_tag_free)(struct m_tag *);
52 #if defined(__linux__) || defined( _WIN32 )
55 * Auxiliary structure to store values from the sk_buf.
56 * Note that we should not alter the sk_buff, and if we do
57 * so make sure to keep the values in sync between the mbuf
58 * and the sk_buff (especially m_len and m_pkthdr.len).
63 struct mbuf *m_nextpkt;
65 int m_len; /* length in this mbuf */
67 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
68 struct nf_info *queue_entry;
70 struct nf_queue_entry *queue_entry;
72 struct sk_buff *m_skb;
74 struct net_device *rcvif;
75 int len; /* total packet len */
76 SLIST_HEAD (packet_tags, m_tag) tags;
80 #define M_SKIP_FIREWALL 0x01 /* skip firewall processing */
81 #define M_BCAST 0x02 /* send/received as link-level broadcast */
82 #define M_MCAST 0x04 /* send/received as link-level multicast */
84 #define M_DONTWAIT M_NOWAIT /* should not be here... */
88 * m_dup() is used in the TEE case, currently unsupported so we
91 static __inline struct mbuf *m_dup(struct mbuf __unused *m, int __unused n)
96 #define MTAG_ABI_COMPAT 0 /* compatibility ABI */
97 static __inline struct m_tag *
98 m_tag_find(struct mbuf __unused *m, int __unused type, struct m_tag __unused *start)
105 m_tag_prepend(struct mbuf *m, struct m_tag *t)
107 SLIST_INSERT_HEAD(&m->m_pkthdr.tags, t, m_tag_link);
111 * Return the next tag in the list of tags associated with an mbuf.
113 static __inline struct m_tag *
114 m_tag_next(struct mbuf *m, struct m_tag *t)
117 return (SLIST_NEXT(t, m_tag_link));
121 * Create an mtag of the given type
123 static __inline struct m_tag *
124 m_tag_alloc(uint32_t cookie, int type, int length, int wait)
126 int l = length + sizeof(struct m_tag);
127 struct m_tag *m = malloc(l, 0, M_NOWAIT);
131 m->m_tag_len = length;
132 m->m_tag_cookie = cookie;
137 static __inline struct m_tag *
138 m_tag_get(int type, int length, int wait)
140 return m_tag_alloc(MTAG_ABI_COMPAT, type, length, wait);
143 static __inline struct m_tag *
144 m_tag_first(struct mbuf *m)
146 return SLIST_FIRST(&m->m_pkthdr.tags);
150 m_tag_delete(struct mbuf *m, struct m_tag *t)
154 static __inline struct m_tag *
155 m_tag_locate(struct mbuf *m, u_int32_t n, int x, struct m_tag *t)
160 #define M_SETFIB(_m, _fib) /* nothing on linux */
162 m_freem(struct mbuf *m)
166 /* free the m_tag chain */
167 while ( (t = SLIST_FIRST(&m->m_pkthdr.tags) ) ) {
168 SLIST_REMOVE_HEAD(&m->m_pkthdr.tags, m_tag_link);
176 /* we cannot pullup */
177 //#define m_pullup(__m, __i) (m)
179 #define M_GETFIB(_m) 0
181 #endif /* !__linux__ */
184 * Persistent tags stay with an mbuf until the mbuf is reclaimed. Otherwise
185 * tags are expected to ``vanish'' when they pass through a network
186 * interface. For most interfaces this happens normally as the tags are
187 * reclaimed when the mbuf is free'd. However in some special cases
188 * reclaiming must be done manually. An example is packets that pass through
189 * the loopback interface. Also, one must be careful to do this when
190 * ``turning around'' packets (e.g., icmp_reflect).
192 * To mark a tag persistent bit-or this flag in when defining the tag id.
193 * The tag will then be treated as described above.
195 #define MTAG_PERSISTENT 0x800
197 #define PACKET_TAG_NONE 0 /* Nadda */
199 /* Packet tags for use with PACKET_ABI_COMPAT. */
200 #define PACKET_TAG_IPSEC_IN_DONE 1 /* IPsec applied, in */
201 #define PACKET_TAG_IPSEC_OUT_DONE 2 /* IPsec applied, out */
202 #define PACKET_TAG_IPSEC_IN_CRYPTO_DONE 3 /* NIC IPsec crypto done */
203 #define PACKET_TAG_IPSEC_OUT_CRYPTO_NEEDED 4 /* NIC IPsec crypto req'ed */
204 #define PACKET_TAG_IPSEC_IN_COULD_DO_CRYPTO 5 /* NIC notifies IPsec */
205 #define PACKET_TAG_IPSEC_PENDING_TDB 6 /* Reminder to do IPsec */
206 #define PACKET_TAG_BRIDGE 7 /* Bridge processing done */
207 #define PACKET_TAG_GIF 8 /* GIF processing done */
208 #define PACKET_TAG_GRE 9 /* GRE processing done */
209 #define PACKET_TAG_IN_PACKET_CHECKSUM 10 /* NIC checksumming done */
210 #define PACKET_TAG_ENCAP 11 /* Encap. processing */
211 #define PACKET_TAG_IPSEC_SOCKET 12 /* IPSEC socket ref */
212 #define PACKET_TAG_IPSEC_HISTORY 13 /* IPSEC history */
213 #define PACKET_TAG_IPV6_INPUT 14 /* IPV6 input processing */
214 #define PACKET_TAG_DUMMYNET 15 /* dummynet info */
215 #define PACKET_TAG_DIVERT 17 /* divert info */
216 #define PACKET_TAG_IPFORWARD 18 /* ipforward info */
217 #define PACKET_TAG_MACLABEL (19 | MTAG_PERSISTENT) /* MAC label */
218 #define PACKET_TAG_PF 21 /* PF + ALTQ information */
219 #define PACKET_TAG_RTSOCKFAM 25 /* rtsock sa family */
220 #define PACKET_TAG_IPOPTIONS 27 /* Saved IP options */
221 #define PACKET_TAG_CARP 28 /* CARP info */
223 #endif /* !_SYS_MBUF_H_ */