1 /* 2 * Copyright 2006-2008, 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 <util/list.h> 10 11 #include <module.h> 12 #include <sys/socket.h> 13 14 15 #define NET_BUFFER_MODULE_NAME "network/stack/buffer/v1" 16 17 typedef struct net_buffer { 18 struct list_link link; 19 20 // TODO: we should think about moving the address fields into the buffer 21 // data itself via associated data or something like this. Or this 22 // structure as a whole, too... 23 24 struct sockaddr *source; 25 struct sockaddr *destination; 26 struct net_interface *interface; 27 int32 type; 28 union { 29 struct { 30 uint16 start; 31 uint16 end; 32 } fragment; 33 uint32 sequence; 34 uint32 offset; 35 }; 36 uint32 flags; 37 uint32 size; 38 uint8 protocol; 39 } net_buffer; 40 41 struct ancillary_data_container; 42 43 struct net_buffer_module_info { 44 module_info info; 45 46 net_buffer * (*create)(size_t headerSpace); 47 void (*free)(net_buffer *buffer); 48 49 net_buffer * (*duplicate)(net_buffer *from); 50 net_buffer * (*clone)(net_buffer *from, bool shareFreeSpace); 51 net_buffer * (*split)(net_buffer *from, uint32 offset); 52 status_t (*merge)(net_buffer *buffer, net_buffer *with, bool after); 53 54 status_t (*prepend_size)(net_buffer *buffer, size_t size, 55 void **_contiguousBuffer); 56 status_t (*prepend)(net_buffer *buffer, const void *data, 57 size_t bytes); 58 status_t (*append_size)(net_buffer *buffer, size_t size, 59 void **_contiguousBuffer); 60 status_t (*append)(net_buffer *buffer, const void *data, 61 size_t bytes); 62 status_t (*insert)(net_buffer *buffer, uint32 offset, 63 const void *data, size_t bytes, uint32 flags); 64 status_t (*remove)(net_buffer *buffer, uint32 offset, 65 size_t bytes); 66 status_t (*remove_header)(net_buffer *buffer, size_t bytes); 67 status_t (*remove_trailer)(net_buffer *buffer, size_t bytes); 68 status_t (*trim)(net_buffer *buffer, size_t newSize); 69 status_t (*append_cloned)(net_buffer *buffer, net_buffer *source, 70 uint32 offset, size_t bytes); 71 72 status_t (*associate_data)(net_buffer *buffer, void *data); 73 74 void (*set_ancillary_data)(net_buffer *buffer, 75 struct ancillary_data_container *container); 76 struct ancillary_data_container* (*get_ancillary_data)(net_buffer *buffer); 77 void * (*transfer_ancillary_data)(net_buffer *from, 78 net_buffer *to); 79 80 status_t (*direct_access)(net_buffer *buffer, uint32 offset, 81 size_t bytes, void **_data); 82 status_t (*read)(net_buffer *buffer, uint32 offset, void *data, 83 size_t bytes); 84 status_t (*write)(net_buffer *buffer, uint32 offset, 85 const void *data, size_t bytes); 86 87 int32 (*checksum)(net_buffer *buffer, uint32 offset, size_t bytes, 88 bool finalize); 89 status_t (*get_memory_map)(net_buffer *buffer, 90 struct iovec *iovecs, uint32 vecCount); 91 uint32 (*get_iovecs)(net_buffer *buffer, 92 struct iovec *iovecs, uint32 vecCount); 93 uint32 (*count_iovecs)(net_buffer *buffer); 94 95 void (*swap_addresses)(net_buffer *buffer); 96 97 void (*dump)(net_buffer *buffer); 98 }; 99 100 #endif // NET_BUFFER_H 101