1 /* 2 * Copyright (c) 2016-2018 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24 #ifndef __PBUF_H__ 25 #define __PBUF_H__ 26 27 #include <sys/mbuf.h> 28 29 enum pbuf_type { 30 PBUF_TYPE_ZOMBIE = 0, 31 PBUF_TYPE_MBUF, 32 PBUF_TYPE_MEMORY 33 }; 34 35 enum pbuf_action { 36 PBUF_ACTION_DESTROY 37 }; 38 39 #define PBUF_ACTION_RV_SUCCESS 0 40 #define PBUF_ACTION_RV_FAILURE (-1) 41 42 struct pbuf_memory { 43 uint8_t *pm_buffer; // Pointer to start of buffer 44 u_int pm_buffer_len; // Total length of buffer 45 u_int pm_offset; // Offset to start of payload 46 u_int pm_len; // Length of payload 47 uint32_t pm_csum_flags; 48 uint32_t pm_csum_data; 49 uint8_t pm_proto; 50 uint8_t pm_flowsrc; 51 uint32_t pm_flowid; 52 uint32_t pm_flags; 53 struct pf_mtag pm_pftag; 54 struct pf_fragment_tag pm_pf_fragtag; 55 int (*pm_action)(struct pbuf_memory *, enum pbuf_action); 56 void *pm_action_cookie; 57 }; 58 59 typedef struct pbuf { 60 enum pbuf_type pb_type; 61 union { 62 struct mbuf *pbu_mbuf; 63 struct pbuf_memory pbu_memory; 64 } pb_u; 65 #define pb_mbuf pb_u.pbu_mbuf 66 #define pb_memory pb_u.pbu_memory 67 68 void *pb_data; 69 uint32_t pb_packet_len; 70 uint32_t pb_contig_len; 71 uint32_t *pb_csum_flags; 72 uint32_t *pb_csum_data; /* data field used by csum routines */ 73 uint8_t *pb_proto; 74 uint8_t *pb_flowsrc; 75 uint32_t *pb_flowid; 76 uint32_t *pb_flags; 77 struct pf_mtag *pb_pftag; 78 struct pf_fragment_tag *pb_pf_fragtag; 79 struct ifnet *pb_ifp; 80 struct pbuf *pb_next; 81 } pbuf_t; 82 83 #define pbuf_is_valid(pb) (!((pb) == NULL || (pb)->pb_type == PBUF_TYPE_ZOMBIE)) 84 85 void pbuf_init_mbuf(pbuf_t *, struct mbuf *, struct ifnet *); 86 void pbuf_init_memory(pbuf_t *, const struct pbuf_memory *, 87 struct ifnet *); 88 void pbuf_destroy(pbuf_t *); 89 void pbuf_sync(pbuf_t *); 90 91 struct mbuf *pbuf_to_mbuf(pbuf_t *, boolean_t); 92 struct mbuf *pbuf_clone_to_mbuf(pbuf_t *); 93 94 void * pbuf_ensure_contig(pbuf_t *, size_t); 95 void * pbuf_ensure_writable(pbuf_t *, size_t); 96 97 void * pbuf_resize_segment(pbuf_t *, int off, int olen, int nlen); 98 void * pbuf_contig_segment(pbuf_t *, int off, int len); 99 100 void pbuf_copy_data(pbuf_t *, int, int, void *); 101 void pbuf_copy_back(pbuf_t *, int, int, void *); 102 103 uint16_t pbuf_inet_cksum(const pbuf_t *, uint32_t, uint32_t, uint32_t); 104 uint16_t pbuf_inet6_cksum(const pbuf_t *, uint32_t, uint32_t, uint32_t); 105 106 mbuf_svc_class_t pbuf_get_service_class(const pbuf_t *); 107 void * pbuf_get_packet_buffer_address(const pbuf_t *); 108 #endif /* __PBUF_H__ */ 109