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