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 uint32 index; 33 int32 type; 34 }; 35 uint32 flags; 36 uint32 size; 37 uint8 protocol; 38 } net_buffer; 39 40 struct ancillary_data_container; 41 42 struct net_buffer_module_info { 43 module_info info; 44 45 net_buffer* (*create)(size_t headerSpace); 46 void (*free)(net_buffer* buffer); 47 48 net_buffer* (*duplicate)(net_buffer* from); 49 net_buffer* (*clone)(net_buffer* from, bool shareFreeSpace); 50 net_buffer* (*split)(net_buffer* from, uint32 offset); 51 status_t (*merge)(net_buffer* buffer, net_buffer* with, bool after); 52 53 status_t (*prepend_size)(net_buffer* buffer, size_t size, 54 void** _contiguousBuffer); 55 status_t (*prepend)(net_buffer* buffer, const void* data, 56 size_t bytes); 57 status_t (*append_size)(net_buffer* buffer, size_t size, 58 void** _contiguousBuffer); 59 status_t (*append)(net_buffer* buffer, const void* data, 60 size_t bytes); 61 status_t (*insert)(net_buffer* buffer, uint32 offset, 62 const void* data, size_t bytes, uint32 flags); 63 status_t (*remove)(net_buffer* buffer, uint32 offset, 64 size_t bytes); 65 status_t (*remove_header)(net_buffer* buffer, size_t bytes); 66 status_t (*remove_trailer)(net_buffer* buffer, size_t bytes); 67 status_t (*trim)(net_buffer* buffer, size_t newSize); 68 status_t (*append_cloned)(net_buffer* buffer, net_buffer* source, 69 uint32 offset, size_t bytes); 70 71 status_t (*associate_data)(net_buffer* buffer, void* data); 72 73 void (*set_ancillary_data)(net_buffer* buffer, 74 struct ancillary_data_container* container); 75 struct ancillary_data_container* (*get_ancillary_data)(net_buffer* buffer); 76 void* (*transfer_ancillary_data)(net_buffer* from, 77 net_buffer* to); 78 79 status_t (*store_header)(net_buffer* buffer); 80 ssize_t (*stored_header_length)(net_buffer* buffer); 81 status_t (*restore_header)(net_buffer* buffer, uint32 offset, 82 void* data, size_t bytes); 83 status_t (*append_restored_header)(net_buffer* buffer, 84 net_buffer* source, uint32 offset, size_t bytes); 85 86 status_t (*direct_access)(net_buffer* buffer, uint32 offset, 87 size_t bytes, void** _data); 88 status_t (*read)(net_buffer* buffer, size_t offset, void* data, 89 size_t bytes); 90 status_t (*write)(net_buffer* buffer, size_t offset, 91 const void* data, size_t bytes); 92 93 int32 (*checksum)(net_buffer* buffer, uint32 offset, size_t bytes, 94 bool finalize); 95 status_t (*get_memory_map)(net_buffer* buffer, 96 struct iovec* iovecs, uint32 vecCount); 97 uint32 (*get_iovecs)(net_buffer* buffer, 98 struct iovec* iovecs, uint32 vecCount); 99 uint32 (*count_iovecs)(net_buffer* buffer); 100 101 void (*swap_addresses)(net_buffer* buffer); 102 103 void (*dump)(net_buffer* buffer); 104 }; 105 106 107 #endif // NET_BUFFER_H 108