xref: /haiku/headers/private/net/net_protocol.h (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2  * Copyright 2006, 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 typedef struct net_protocol {
20 	struct net_protocol				*next;
21 	struct net_protocol_module_info	*module;
22 	net_socket						*socket;
23 } net_protocol;
24 
25 struct net_protocol_module_info {
26 	module_info info;
27 
28 	net_protocol *(*init_protocol)(net_socket *socket);
29 	status_t	(*uninit_protocol)(net_protocol *self);
30 
31 	status_t	(*open)(net_protocol *self);
32 	status_t	(*close)(net_protocol *self);
33 	status_t	(*free)(net_protocol *self);
34 
35 	status_t	(*connect)(net_protocol *self, const struct sockaddr *address);
36 	status_t	(*accept)(net_protocol *self, struct net_socket **_acceptedSocket);
37 	status_t	(*control)(net_protocol *self, int level, int option, void *value,
38 					size_t *_length);
39 	status_t	(*getsockopt)(net_protocol *self, int level, int option,
40 					void *value, int *_length);
41 	status_t	(*setsockopt)(net_protocol *self, int level, int option,
42 					const void *value, int length);
43 
44 	status_t	(*bind)(net_protocol *self, const struct sockaddr *address);
45 	status_t	(*unbind)(net_protocol *self, struct sockaddr *address);
46 	status_t	(*listen)(net_protocol *self, int count);
47 	status_t	(*shutdown)(net_protocol *self, int direction);
48 
49 	status_t	(*send_data)(net_protocol *self, net_buffer *buffer);
50 	status_t	(*send_routed_data)(net_protocol *self,
51 					struct net_route *route, net_buffer *buffer);
52 	ssize_t		(*send_avail)(net_protocol *self);
53 
54 	status_t	(*read_data)(net_protocol *self, size_t numBytes, uint32 flags,
55 					net_buffer **_buffer);
56 	ssize_t		(*read_avail)(net_protocol *self);
57 
58 	struct net_domain *(*get_domain)(net_protocol *self);
59 	size_t		(*get_mtu)(net_protocol *self, const struct sockaddr *address);
60 
61 	status_t	(*receive_data)(net_buffer *data);
62 	status_t	(*deliver_data)(net_protocol *protocol, net_buffer *data);
63 
64 	status_t	(*error)(uint32 code, net_buffer *data);
65 	status_t	(*error_reply)(net_protocol *self, net_buffer *causedError,
66 					uint32 code, void *errorData);
67 };
68 
69 #endif	// NET_PROTOCOL_H
70