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 struct sockaddr_storage source; 23 struct sockaddr_storage destination; 24 struct net_interface *interface; 25 uint32 flags; 26 uint32 size; 27 uint8 protocol; 28 } net_buffer; 29 30 struct net_buffer_module_info { 31 module_info info; 32 33 net_buffer * (*create)(size_t headerSpace); 34 void (*free)(net_buffer *buffer); 35 36 net_buffer * (*duplicate)(net_buffer *from); 37 net_buffer * (*clone)(net_buffer *from, bool shareFreeSpace); 38 net_buffer * (*split)(net_buffer *from, uint32 offset); 39 status_t (*merge)(net_buffer *buffer, net_buffer *with, bool after); 40 41 status_t (*prepend_size)(net_buffer *buffer, size_t size, 42 void **_contiguousBuffer); 43 status_t (*prepend)(net_buffer *buffer, const void *data, 44 size_t bytes); 45 status_t (*append_size)(net_buffer *buffer, size_t size, 46 void **_contiguousBuffer); 47 status_t (*append)(net_buffer *buffer, const void *data, 48 size_t bytes); 49 status_t (*insert)(net_buffer *buffer, uint32 offset, 50 const void *data, size_t bytes, uint32 flags); 51 status_t (*remove)(net_buffer *buffer, uint32 offset, 52 size_t bytes); 53 status_t (*remove_header)(net_buffer *buffer, size_t bytes); 54 status_t (*remove_trailer)(net_buffer *buffer, size_t bytes); 55 status_t (*trim)(net_buffer *buffer, size_t newSize); 56 57 status_t (*associate_data)(net_buffer *buffer, void *data); 58 59 status_t (*direct_access)(net_buffer *buffer, uint32 offset, 60 size_t bytes, void **_data); 61 status_t (*read)(net_buffer *buffer, uint32 offset, void *data, 62 size_t bytes); 63 status_t (*write)(net_buffer *buffer, uint32 offset, 64 const void *data, size_t bytes); 65 66 int32 (*checksum)(net_buffer *buffer, uint32 offset, size_t bytes, 67 bool finalize); 68 status_t (*get_memory_map)(net_buffer *buffer, 69 struct iovec *iovecs, uint32 vecCount); 70 uint32 (*get_iovecs)(net_buffer *buffer, 71 struct iovec *iovecs, uint32 vecCount); 72 uint32 (*count_iovecs)(net_buffer *buffer); 73 74 void (*dump)(net_buffer *buffer); 75 }; 76 77 #endif // NET_BUFFER_H 78