xref: /haiku/headers/private/net/net_protocol.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2  * Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef NET_PROTOCOL_H
6 #define NET_PROTOCOL_H
7 
8 
9 #include <net_buffer.h>
10 #include <net_socket.h>
11 
12 
13 // level flags to pass to control()
14 #define LEVEL_SET_OPTION		0x10000000
15 #define LEVEL_GET_OPTION		0x20000000
16 #define LEVEL_DRIVER_IOCTL		0x0f000000
17 #define LEVEL_MASK				0x0fffffff
18 
19 struct ancillary_data_container;
20 struct ancillary_data_header;
21 
22 struct iovec;
23 
24 typedef struct net_protocol {
25 	struct net_protocol				*next;
26 	struct net_protocol_module_info	*module;
27 	net_socket						*socket;
28 } net_protocol;
29 
30 // net_protocol_module_info::flags field
31 #define NET_PROTOCOL_ATOMIC_MESSAGES 0x01
32 
33 struct net_protocol_module_info {
34 	module_info info;
35 	uint32		flags;
36 
37 	net_protocol *(*init_protocol)(net_socket *socket);
38 	status_t	(*uninit_protocol)(net_protocol *self);
39 
40 	status_t	(*open)(net_protocol *self);
41 	status_t	(*close)(net_protocol *self);
42 	status_t	(*free)(net_protocol *self);
43 
44 	status_t	(*connect)(net_protocol *self, const struct sockaddr *address);
45 	status_t	(*accept)(net_protocol *self, struct net_socket **_acceptedSocket);
46 	status_t	(*control)(net_protocol *self, int level, int option, void *value,
47 					size_t *_length);
48 	status_t	(*getsockopt)(net_protocol *self, int level, int option,
49 					void *value, int *_length);
50 	status_t	(*setsockopt)(net_protocol *self, int level, int option,
51 					const void *value, int length);
52 
53 	status_t	(*bind)(net_protocol *self, const struct sockaddr *address);
54 	status_t	(*unbind)(net_protocol *self, struct sockaddr *address);
55 	status_t	(*listen)(net_protocol *self, int count);
56 	status_t	(*shutdown)(net_protocol *self, int direction);
57 
58 	status_t	(*send_data)(net_protocol *self, net_buffer *buffer);
59 	status_t	(*send_routed_data)(net_protocol *self,
60 					struct net_route *route, net_buffer *buffer);
61 	ssize_t		(*send_avail)(net_protocol *self);
62 
63 	status_t	(*read_data)(net_protocol *self, size_t numBytes, uint32 flags,
64 					net_buffer **_buffer);
65 	ssize_t		(*read_avail)(net_protocol *self);
66 
67 	struct net_domain *(*get_domain)(net_protocol *self);
68 	size_t		(*get_mtu)(net_protocol *self, const struct sockaddr *address);
69 
70 	status_t	(*receive_data)(net_buffer *data);
71 	status_t	(*deliver_data)(net_protocol *protocol, net_buffer *data);
72 
73 	status_t	(*error)(uint32 code, net_buffer *data);
74 	status_t	(*error_reply)(net_protocol *self, net_buffer *causedError,
75 					uint32 code, void *errorData);
76 
77 	status_t	(*add_ancillary_data)(net_protocol *self,
78 					ancillary_data_container *container, const cmsghdr *header);
79 	ssize_t		(*process_ancillary_data)(net_protocol *self,
80 					const ancillary_data_header *header, const void *data,
81 					void *buffer, size_t bufferSize);
82 	ssize_t		(*process_ancillary_data_no_container)(net_protocol *self,
83 					net_buffer *buffer, void *data, size_t bufferSize);
84 
85 	ssize_t		(*send_data_no_buffer)(net_protocol *self, const iovec *vecs,
86 					size_t vecCount, ancillary_data_container *ancillaryData,
87 					const struct sockaddr *address, socklen_t addressLength);
88 	ssize_t		(*read_data_no_buffer)(net_protocol *self, const iovec *vecs,
89 					size_t vecCount, ancillary_data_container **_ancillaryData,
90 					struct sockaddr *_address, socklen_t *_addressLength);
91 };
92 
93 #endif	// NET_PROTOCOL_H
94