xref: /haiku/headers/private/net/net_buffer.h (revision 3cb015b1ee509d69c643506e8ff573808c86dcfc)
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 	union {
26 		struct {
27 			uint16	start;
28 			uint16	end;
29 		}		fragment;
30 		uint32	sequence;
31 		uint32	offset;
32 	};
33 	uint32	flags;
34 	uint32	size;
35 	uint8	protocol;
36 } net_buffer;
37 
38 struct net_buffer_module_info {
39 	module_info info;
40 
41 	net_buffer *	(*create)(size_t headerSpace);
42 	void 			(*free)(net_buffer *buffer);
43 
44 	net_buffer *	(*duplicate)(net_buffer *from);
45 	net_buffer *	(*clone)(net_buffer *from, bool shareFreeSpace);
46 	net_buffer *	(*split)(net_buffer *from, uint32 offset);
47 	status_t		(*merge)(net_buffer *buffer, net_buffer *with, bool after);
48 
49 	status_t		(*prepend_size)(net_buffer *buffer, size_t size,
50 						void **_contiguousBuffer);
51 	status_t		(*prepend)(net_buffer *buffer, const void *data,
52 						size_t bytes);
53 	status_t		(*append_size)(net_buffer *buffer, size_t size,
54 						void **_contiguousBuffer);
55 	status_t		(*append)(net_buffer *buffer, const void *data,
56 						size_t bytes);
57 	status_t		(*insert)(net_buffer *buffer, uint32 offset,
58 						const void *data, size_t bytes, uint32 flags);
59 	status_t		(*remove)(net_buffer *buffer, uint32 offset,
60 						size_t bytes);
61 	status_t		(*remove_header)(net_buffer *buffer, size_t bytes);
62 	status_t		(*remove_trailer)(net_buffer *buffer, size_t bytes);
63 	status_t		(*trim)(net_buffer *buffer, size_t newSize);
64 	status_t		(*append_cloned)(net_buffer *buffer, net_buffer *source,
65 						uint32 offset, size_t bytes);
66 
67 	status_t		(*associate_data)(net_buffer *buffer, void *data);
68 
69 	status_t		(*direct_access)(net_buffer *buffer, uint32 offset,
70 						size_t bytes, void **_data);
71 	status_t 		(*read)(net_buffer *buffer, uint32 offset, void *data,
72 						size_t bytes);
73 	status_t		(*write)(net_buffer *buffer, uint32 offset,
74 						const void *data, size_t bytes);
75 
76 	int32			(*checksum)(net_buffer *buffer, uint32 offset, size_t bytes,
77 						bool finalize);
78 	status_t		(*get_memory_map)(net_buffer *buffer,
79 						struct iovec *iovecs, uint32 vecCount);
80 	uint32 			(*get_iovecs)(net_buffer *buffer,
81 						struct iovec *iovecs, uint32 vecCount);
82 	uint32 			(*count_iovecs)(net_buffer *buffer);
83 
84 	void			(*dump)(net_buffer *buffer);
85 };
86 
87 #endif	// NET_BUFFER_H
88