1 /* 2 * Copyright 2006, 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 data itself 21 // via associated data or something like this. Or this structure as a whole, too... 22 23 struct sockaddr *source; 24 struct sockaddr *destination; 25 struct net_interface *interface; 26 int32 type; 27 union { 28 struct { 29 uint16 start; 30 uint16 end; 31 } fragment; 32 uint32 sequence; 33 uint32 offset; 34 }; 35 uint32 flags; 36 uint32 size; 37 uint8 protocol; 38 } net_buffer; 39 40 struct net_buffer_module_info { 41 module_info info; 42 43 net_buffer * (*create)(size_t headerSpace); 44 void (*free)(net_buffer *buffer); 45 46 net_buffer * (*duplicate)(net_buffer *from); 47 net_buffer * (*clone)(net_buffer *from, bool shareFreeSpace); 48 net_buffer * (*split)(net_buffer *from, uint32 offset); 49 status_t (*merge)(net_buffer *buffer, net_buffer *with, bool after); 50 51 status_t (*prepend_size)(net_buffer *buffer, size_t size, 52 void **_contiguousBuffer); 53 status_t (*prepend)(net_buffer *buffer, const void *data, 54 size_t bytes); 55 status_t (*append_size)(net_buffer *buffer, size_t size, 56 void **_contiguousBuffer); 57 status_t (*append)(net_buffer *buffer, const void *data, 58 size_t bytes); 59 status_t (*insert)(net_buffer *buffer, uint32 offset, 60 const void *data, size_t bytes, uint32 flags); 61 status_t (*remove)(net_buffer *buffer, uint32 offset, 62 size_t bytes); 63 status_t (*remove_header)(net_buffer *buffer, size_t bytes); 64 status_t (*remove_trailer)(net_buffer *buffer, size_t bytes); 65 status_t (*trim)(net_buffer *buffer, size_t newSize); 66 status_t (*append_cloned)(net_buffer *buffer, net_buffer *source, 67 uint32 offset, size_t bytes); 68 69 status_t (*associate_data)(net_buffer *buffer, void *data); 70 71 status_t (*direct_access)(net_buffer *buffer, uint32 offset, 72 size_t bytes, void **_data); 73 status_t (*read)(net_buffer *buffer, uint32 offset, void *data, 74 size_t bytes); 75 status_t (*write)(net_buffer *buffer, uint32 offset, 76 const void *data, size_t bytes); 77 78 int32 (*checksum)(net_buffer *buffer, uint32 offset, size_t bytes, 79 bool finalize); 80 status_t (*get_memory_map)(net_buffer *buffer, 81 struct iovec *iovecs, uint32 vecCount); 82 uint32 (*get_iovecs)(net_buffer *buffer, 83 struct iovec *iovecs, uint32 vecCount); 84 uint32 (*count_iovecs)(net_buffer *buffer); 85 86 void (*swap_addresses)(net_buffer *buffer); 87 88 void (*dump)(net_buffer *buffer); 89 }; 90 91 #endif // NET_BUFFER_H 92