xref: /haiku/src/add-ons/kernel/network/stack/interfaces.h (revision 14e3d1b5768e7110b3d5c0855833267409b71dbb)
1 /*
2  * Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Axel Dörfler, axeld@pinc-software.de
7  */
8 #ifndef INTERFACES_H
9 #define INTERFACES_H
10 
11 
12 #include <net_datalink.h>
13 #include <net_stack.h>
14 
15 #include <util/DoublyLinkedList.h>
16 
17 
18 struct net_device_handler : public DoublyLinkedListLinkImpl<net_device_handler> {
19 	net_receive_func	func;
20 	int32				type;
21 	void				*cookie;
22 };
23 
24 typedef DoublyLinkedList<net_device_handler> DeviceHandlerList;
25 
26 typedef DoublyLinkedList<net_device_monitor,
27 	DoublyLinkedListCLink<net_device_monitor> > DeviceMonitorList;
28 
29 struct net_device_interface : DoublyLinkedListLinkImpl<net_device_interface> {
30 	const char			*name;
31 	struct net_device_module_info *module;
32 	struct net_device	*device;
33 	thread_id			reader_thread;
34 	uint32				up_count;
35 		// a device can be brought up by more than one interface
36 	int32				ref_count;
37 
38 	net_deframe_func	deframe_func;
39 	int32				deframe_ref_count;
40 
41 	DeviceMonitorList	monitor_funcs;
42 	DeviceHandlerList	receive_funcs;
43 
44 	recursive_lock		rx_lock;
45 
46 	thread_id			consumer_thread;
47 	net_fifo			receive_queue;
48 };
49 
50 typedef DoublyLinkedList<net_device_interface> DeviceInterfaceList;
51 
52 struct net_interface_private : net_interface {
53 	char				base_name[IF_NAMESIZE];
54 	net_device_interface *device_interface;
55 };
56 
57 
58 status_t init_interfaces();
59 status_t uninit_interfaces();
60 
61 // interfaces
62 struct net_interface_private *find_interface(struct net_domain *domain,
63 	const char *name);
64 struct net_interface_private *find_interface(struct net_domain *domain,
65 	uint32 index);
66 void put_interface(struct net_interface_private *interface);
67 struct net_interface_private *get_interface(net_domain *domain,
68 	const char *name);
69 status_t create_interface(net_domain *domain, const char *name,
70 	const char *baseName, net_device_interface *deviceInterface,
71 	struct net_interface_private **_interface);
72 void delete_interface(net_interface_private *interface);
73 void interface_set_down(net_interface *);
74 
75 // device interfaces
76 void get_device_interface_address(net_device_interface *interface,
77 	sockaddr *address);
78 uint32 count_device_interfaces();
79 status_t list_device_interfaces(void *buffer, size_t *_bufferSize);
80 void put_device_interface(struct net_device_interface *interface);
81 struct net_device_interface *get_device_interface(uint32 index);
82 struct net_device_interface *get_device_interface(const char *name,
83 	bool create = true);
84 void down_device_interface(net_device_interface *interface);
85 
86 // devices
87 status_t unregister_device_deframer(net_device *device);
88 status_t register_device_deframer(net_device *device, net_deframe_func deframeFunc);
89 status_t register_domain_device_handler(struct net_device *device, int32 type,
90 	struct net_domain *domain);
91 status_t register_device_handler(struct net_device *device, int32 type,
92 	net_receive_func receiveFunc, void *cookie);
93 status_t unregister_device_handler(struct net_device *device, int32 type);
94 status_t register_device_monitor(struct net_device *device,
95 	struct net_device_monitor *monitor);
96 status_t unregister_device_monitor(struct net_device *device,
97 	struct net_device_monitor *monitor);
98 status_t device_link_changed(net_device *device);
99 status_t device_removed(net_device *device);
100 status_t device_enqueue_buffer(net_device *device, net_buffer *buffer);
101 
102 #endif	// INTERFACES_H
103