xref: /haiku/headers/private/net/net_stack.h (revision a381c8a06378de22ff08adf4282b4e3f7e50d250)
1 /*
2  * Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef NET_STACK_H
6 #define NET_STACK_H
7 
8 
9 #include <lock.h>
10 #include <util/list.h>
11 
12 #include <module.h>
13 
14 
15 #define NET_STACK_MODULE_NAME "network/stack/v1"
16 
17 
18 struct net_address_module_info;
19 struct net_protocol_module_info;
20 
21 struct net_buffer;
22 struct net_device;
23 struct net_domain;
24 struct net_socket;
25 struct net_timer;
26 
27 struct net_fifo {
28 	benaphore	lock;
29 	sem_id		notify;
30 	int32		waiting;
31 
32 	size_t		max_bytes;
33 	size_t		current_bytes;
34 
35 	struct list	buffers;
36 };
37 
38 typedef void (*net_timer_func)(struct net_timer *timer, void *data);
39 
40 struct net_timer {
41 	struct list_link link;
42 	net_timer_func	hook;
43 	void			*data;
44 	bigtime_t		due;
45 };
46 
47 typedef int32 (*net_deframe_func)(struct net_device *device,
48 	struct net_buffer *buffer);
49 typedef status_t (*net_receive_func)(void *cookie, struct net_device *device,
50 	struct net_buffer *buffer);
51 
52 enum {
53 	B_DEVICE_GOING_UP = 1,
54 	B_DEVICE_GOING_DOWN,
55 	B_DEVICE_BEING_REMOVED,
56 };
57 
58 struct net_device_monitor {
59 	struct list_link link;
60 	void *cookie;
61 
62 	status_t (*receive)(struct net_device_monitor *monitor,
63 		struct net_buffer *buffer);
64 	void (*event)(struct net_device_monitor *monitor, int32 event);
65 };
66 
67 struct net_stack_module_info {
68 	module_info info;
69 
70 	status_t (*register_domain)(int family, const char *name,
71 					struct net_protocol_module_info *module,
72 					struct net_address_module_info *addressModule,
73 					struct net_domain **_domain);
74 	status_t (*unregister_domain)(struct net_domain *domain);
75 	struct net_domain *(*get_domain)(int family);
76 
77 	status_t (*register_domain_protocols)(int family, int type, int protocol, ...);
78 	status_t (*register_domain_datalink_protocols)(int family, int type, ...);
79 	status_t (*register_domain_receiving_protocol)(int family, int type,
80 					const char *moduleName);
81 
82 	status_t (*get_domain_receiving_protocol)(struct net_domain *domain,
83 					uint32 type, struct net_protocol_module_info **_module);
84 	status_t (*put_domain_receiving_protocol)(struct net_domain *domain,
85 					uint32 type);
86 
87 	// devices
88 	status_t (*register_device_deframer)(struct net_device *device,
89 					net_deframe_func deframeFunc);
90 	status_t (*unregister_device_deframer)(struct net_device *device);
91 
92 	status_t (*register_domain_device_handler)(struct net_device *device,
93 					int32 type, struct net_domain *domain);
94 	status_t (*register_device_handler)(struct net_device *device, int32 type,
95 					net_receive_func receiveFunc, void *cookie);
96 	status_t (*unregister_device_handler)(struct net_device *device, int32 type);
97 
98 	status_t (*register_device_monitor)(struct net_device *device,
99 					struct net_device_monitor *monitor);
100 	status_t (*unregister_device_monitor)(struct net_device *device,
101 					struct net_device_monitor *monitor);
102 
103 	status_t (*device_link_changed)(struct net_device *device);
104 	status_t (*device_removed)(struct net_device *device);
105 
106 	status_t (*device_enqueue_buffer)(struct net_device *device,
107 					struct net_buffer *buffer);
108 
109 	// Utility Functions
110 
111 	// notification
112 	status_t (*notify_socket)(struct net_socket *socket, uint8 event,
113 					int32 value);
114 
115 	// checksum
116 	uint16 (*checksum)(uint8 *buffer, size_t length);
117 
118 	// fifo
119 	status_t (*init_fifo)(struct net_fifo *fifo, const char *name,
120 					size_t maxBytes);
121 	void (*uninit_fifo)(struct net_fifo *fifo);
122 	status_t (*fifo_enqueue_buffer)(struct net_fifo *fifo,
123 					struct net_buffer *buffer);
124 	ssize_t (*fifo_dequeue_buffer)(struct net_fifo *fifo, uint32 flags,
125 					bigtime_t timeout, struct net_buffer **_buffer);
126 	status_t (*clear_fifo)(struct net_fifo *fifo);
127 	status_t (*fifo_socket_enqueue_buffer)(struct net_fifo *fifo,
128 					struct net_socket *socket, uint8 event,
129 					struct net_buffer *buffer);
130 
131 	// timer
132 	void (*init_timer)(struct net_timer *timer, net_timer_func hook, void *data);
133 	void (*set_timer)(struct net_timer *timer, bigtime_t delay);
134 	bool (*cancel_timer)(struct net_timer *timer);
135 	bool (*is_timer_active)(struct net_timer *timer);
136 
137 	// syscall restart
138 	bool (*is_restarted_syscall)(void);
139 	void (*store_syscall_restart_timeout)(bigtime_t timeout);
140 	bigtime_t (*restore_syscall_restart_timeout)(void);
141 };
142 
143 #endif	// NET_STACK_H
144