xref: /haiku/src/libs/compat/openbsd_network/compat/sys/mbuf.h (revision fbc5512274d323fae1e217964941e6dd720cf4ff)
1 /*
2  * Copyright 2022, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _OBSD_COMPAT_SYS_MBUF_H_
6 #define _OBSD_COMPAT_SYS_MBUF_H_
7 
8 #include <sys/systm.h>
9 
10 /* FreeBSD KASSERT */
11 #undef KASSERT
12 #define KASSERT KASSERT_FREEBSD
13 
14 #include_next <sys/mbuf.h>
15 
16 /* back to OpenBSD KASSERT */
17 #undef KASSERT
18 #define KASSERT KASSERT_OPENBSD
19 
20 #include <sys/mutex.h>
21 
22 
23 #define ph_cookie PH_loc.ptr
24 
25 #define M_DATABUF(m)	M_START(m)
26 #define M_READONLY(m)	(!M_WRITABLE(m))
27 
28 #define MAXMCLBYTES MJUM16BYTES
29 
30 #define M_IPV4_CSUM_OUT		CSUM_IP
31 #define M_TCP_CSUM_OUT		CSUM_IP_TCP
32 #define M_UDP_CSUM_OUT		CSUM_IP_UDP
33 #define M_IPV4_CSUM_IN_OK	(CSUM_IP_CHECKED | CSUM_IP_VALID)
34 #define M_TCP_CSUM_IN_OK	(CSUM_DATA_VALID | CSUM_PSEUDO_HDR)
35 #define M_UDP_CSUM_IN_OK	(CSUM_DATA_VALID | CSUM_PSEUDO_HDR)
36 
37 
38 static struct mbuf*
MCLGETL(struct mbuf * m,int how,int size)39 MCLGETL(struct mbuf* m, int how, int size)
40 {
41 	if (m == NULL)
42 		return m_get2(size, how, MT_DATA, M_PKTHDR);
43 
44 	m_cljget(m, how, size);
45 	return m;
46 }
47 
48 static int
m_dup_pkthdr_openbsd(struct mbuf * to,const struct mbuf * from,int how)49 m_dup_pkthdr_openbsd(struct mbuf* to, const struct mbuf* from, int how)
50 {
51 	return !m_dup_pkthdr(to, from, how);
52 }
53 #define m_dup_pkthdr m_dup_pkthdr_openbsd
54 
55 static int
m_tag_copy_chain_openbsd(struct mbuf * to,const struct mbuf * from,int how)56 m_tag_copy_chain_openbsd(struct mbuf* to, const struct mbuf* from, int how)
57 {
58 	return !m_tag_copy_chain(to, from, how);
59 }
60 #define m_tag_copy_chain m_tag_copy_chain_openbsd
61 
62 
63 /* FreeBSD methods not compatible with their OpenBSD counterparts */
64 #define m_defrag(mbuf, how) __m_defrag_unimplemented()
65 
66 
67 #include "mbuf-obsd.h"
68 
69 
70 #endif	/* _OBSD_COMPAT_SYS_MBUF_H_ */
71