xref: /haiku/headers/private/net/net_buffer.h (revision 258ae0c892aa3022adfd6f500a38ea71d6e43eb4)
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 enum net_buffer_flags {
20 	NET_BUFFER_L3_CHECKSUM_VALID = (1 << 0),
21 	NET_BUFFER_L4_CHECKSUM_VALID = (1 << 1),
22 };
23 
24 
25 typedef struct net_buffer {
26 	struct list_link		link;
27 
28 	struct sockaddr*		source;
29 	struct sockaddr*		destination;
30 	struct net_interface_address* interface_address;
31 	union {
32 		struct {
33 			uint16			start;
34 			uint16			end;
35 		}					fragment;
36 		uint32				sequence;
37 		uint32				offset;
38 		uint32				index;
39 		int32				type;
40 	};
41 	uint32					msg_flags;
42 	uint32					size;
43 	uint8					protocol;
44 	uint16					buffer_flags;
45 } net_buffer;
46 
47 struct ancillary_data_container;
48 
49 struct net_buffer_module_info {
50 	module_info info;
51 
52 	net_buffer*		(*create)(size_t headerSpace);
53 	void 			(*free)(net_buffer* buffer);
54 
55 	net_buffer*		(*duplicate)(net_buffer* from);
56 	net_buffer*		(*clone)(net_buffer* from, bool shareFreeSpace);
57 	net_buffer*		(*split)(net_buffer* from, uint32 offset);
58 	status_t		(*merge)(net_buffer* buffer, net_buffer* with, bool after);
59 
60 	status_t		(*prepend_size)(net_buffer* buffer, size_t size,
61 						void** _contiguousBuffer);
62 	status_t		(*prepend)(net_buffer* buffer, const void* data,
63 						size_t bytes);
64 	status_t		(*append_size)(net_buffer* buffer, size_t size,
65 						void** _contiguousBuffer);
66 	status_t		(*append)(net_buffer* buffer, const void* data,
67 						size_t bytes);
68 	status_t		(*insert)(net_buffer* buffer, uint32 offset,
69 						const void* data, size_t bytes, uint32 flags);
70 	status_t		(*remove)(net_buffer* buffer, uint32 offset,
71 						size_t bytes);
72 	status_t		(*remove_header)(net_buffer* buffer, size_t bytes);
73 	status_t		(*remove_trailer)(net_buffer* buffer, size_t bytes);
74 	status_t		(*trim)(net_buffer* buffer, size_t newSize);
75 	status_t		(*append_cloned)(net_buffer* buffer, net_buffer* source,
76 						uint32 offset, size_t bytes);
77 
78 	status_t		(*associate_data)(net_buffer* buffer, void* data);
79 
80 	void			(*set_ancillary_data)(net_buffer* buffer,
81 						struct ancillary_data_container* container);
82 	struct ancillary_data_container* (*get_ancillary_data)(net_buffer* buffer);
83 	void*			(*transfer_ancillary_data)(net_buffer* from,
84 						net_buffer* to);
85 
86 	status_t		(*store_header)(net_buffer* buffer);
87 	ssize_t			(*stored_header_length)(net_buffer* buffer);
88 	status_t		(*restore_header)(net_buffer* buffer, uint32 offset,
89 						void* data, size_t bytes);
90 	status_t		(*append_restored_header)(net_buffer* buffer,
91 						net_buffer* source, uint32 offset, size_t bytes);
92 
93 	status_t		(*direct_access)(net_buffer* buffer, uint32 offset,
94 						size_t bytes, void** _data);
95 	status_t 		(*read)(net_buffer* buffer, size_t offset, void* data,
96 						size_t bytes);
97 	status_t		(*write)(net_buffer* buffer, size_t offset,
98 						const void* data, size_t bytes);
99 
100 	int32			(*checksum)(net_buffer* buffer, uint32 offset, size_t bytes,
101 						bool finalize);
102 	status_t		(*get_memory_map)(net_buffer* buffer,
103 						struct iovec* iovecs, uint32 vecCount);
104 	uint32 			(*get_iovecs)(net_buffer* buffer,
105 						struct iovec* iovecs, uint32 vecCount);
106 	uint32 			(*count_iovecs)(net_buffer* buffer);
107 
108 	void			(*swap_addresses)(net_buffer* buffer);
109 
110 	void			(*dump)(net_buffer* buffer);
111 };
112 
113 
114 #endif	// NET_BUFFER_H
115