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
38static struct mbuf*
39MCLGETL(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
48static int
49m_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
55static int
56m_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