1 /* 2 * Copyright 2006-2010, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef NET_BUFFER_H 6 #define NET_BUFFER_H 7 8 9 #include <sys/socket.h> 10 11 #include <module.h> 12 13 #include <util/list.h> 14 15 16 #define NET_BUFFER_MODULE_NAME "network/stack/buffer/v1" 17 18 19 typedef struct net_buffer { 20 struct list_link link; 21 22 struct sockaddr* source; 23 struct sockaddr* destination; 24 struct net_interface_address* interface_address; 25 union { 26 struct { 27 uint16 start; 28 uint16 end; 29 } fragment; 30 uint32 sequence; 31 uint32 offset; 32 int32 type; 33 }; 34 uint32 flags; 35 uint32 size; 36 uint8 protocol; 37 } net_buffer; 38 39 struct ancillary_data_container; 40 41 struct net_buffer_module_info { 42 module_info info; 43 44 net_buffer* (*create)(size_t headerSpace); 45 void (*free)(net_buffer* buffer); 46 47 net_buffer* (*duplicate)(net_buffer* from); 48 net_buffer* (*clone)(net_buffer* from, bool shareFreeSpace); 49 net_buffer* (*split)(net_buffer* from, uint32 offset); 50 status_t (*merge)(net_buffer* buffer, net_buffer* with, bool after); 51 52 status_t (*prepend_size)(net_buffer* buffer, size_t size, 53 void** _contiguousBuffer); 54 status_t (*prepend)(net_buffer* buffer, const void* data, 55 size_t bytes); 56 status_t (*append_size)(net_buffer* buffer, size_t size, 57 void** _contiguousBuffer); 58 status_t (*append)(net_buffer* buffer, const void* data, 59 size_t bytes); 60 status_t (*insert)(net_buffer* buffer, uint32 offset, 61 const void* data, size_t bytes, uint32 flags); 62 status_t (*remove)(net_buffer* buffer, uint32 offset, 63 size_t bytes); 64 status_t (*remove_header)(net_buffer* buffer, size_t bytes); 65 status_t (*remove_trailer)(net_buffer* buffer, size_t bytes); 66 status_t (*trim)(net_buffer* buffer, size_t newSize); 67 status_t (*append_cloned)(net_buffer* buffer, net_buffer* source, 68 uint32 offset, size_t bytes); 69 70 status_t (*associate_data)(net_buffer* buffer, void* data); 71 72 void (*set_ancillary_data)(net_buffer* buffer, 73 struct ancillary_data_container* container); 74 struct ancillary_data_container* (*get_ancillary_data)(net_buffer* buffer); 75 void* (*transfer_ancillary_data)(net_buffer* from, 76 net_buffer* to); 77 78 status_t (*store_header)(net_buffer* buffer); 79 ssize_t (*stored_header_length)(net_buffer* buffer); 80 status_t (*restore_header)(net_buffer* buffer, uint32 offset, 81 void* data, size_t bytes); 82 status_t (*append_restored_header)(net_buffer* buffer, 83 net_buffer* source, uint32 offset, size_t bytes); 84 85 status_t (*direct_access)(net_buffer* buffer, uint32 offset, 86 size_t bytes, void** _data); 87 status_t (*read)(net_buffer* buffer, uint32 offset, void* data, 88 size_t bytes); 89 status_t (*write)(net_buffer* buffer, uint32 offset, 90 const void* data, size_t bytes); 91 92 int32 (*checksum)(net_buffer* buffer, uint32 offset, size_t bytes, 93 bool finalize); 94 status_t (*get_memory_map)(net_buffer* buffer, 95 struct iovec* iovecs, uint32 vecCount); 96 uint32 (*get_iovecs)(net_buffer* buffer, 97 struct iovec* iovecs, uint32 vecCount); 98 uint32 (*count_iovecs)(net_buffer* buffer); 99 100 void (*swap_addresses)(net_buffer* buffer); 101 102 void (*dump)(net_buffer* buffer); 103 }; 104 105 106 #endif // NET_BUFFER_H 107