xref: /haiku/src/add-ons/kernel/network/stack/interfaces.h (revision 9ecf9d1c1d4888d341a6eac72112c72d1ae3a4cb)
1 /*
2  * Copyright 2006, 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 struct net_device_monitor : public DoublyLinkedListLinkImpl<net_device_monitor> {
25 	net_receive_func	func;
26 	void				*cookie;
27 };
28 
29 typedef DoublyLinkedList<net_device_handler> DeviceHandlerList;
30 typedef DoublyLinkedList<net_device_monitor> DeviceMonitorList;
31 
32 struct net_device_interface {
33 	struct list_link	link;
34 	const char			*name;
35 	struct net_device_module_info *module;
36 	struct net_device	*device;
37 	uint32				up_count;
38 		// a device can be brought up by more than one interface
39 	int32				ref_count;
40 
41 	net_deframe_func	deframe_func;
42 	int32				deframe_ref_count;
43 
44 	DeviceMonitorList	monitor_funcs;
45 	DeviceHandlerList	receive_funcs;
46 };
47 
48 struct net_interface_private : net_interface {
49 	char				base_name[IF_NAMESIZE];
50 	net_device_interface *device_interface;
51 };
52 
53 
54 status_t init_interfaces();
55 status_t uninit_interfaces();
56 
57 // interfaces
58 struct net_interface_private *find_interface(struct net_domain *domain,
59 	const char *name);
60 struct net_interface_private *find_interface(struct net_domain *domain,
61 	uint32 index);
62 void put_interface(struct net_interface_private *interface);
63 struct net_interface_private *get_interface(net_domain *domain,
64 	const char *name);
65 status_t create_interface(net_domain *domain, const char *name,
66 	const char *baseName, net_device_interface *deviceInterface,
67 	struct net_interface_private **_interface);
68 void delete_interface(net_interface_private *interface);
69 
70 // device interfaces
71 void get_device_interface_address(net_device_interface *interface,
72 	sockaddr *address);
73 uint32 count_device_interfaces();
74 status_t list_device_interfaces(void *buffer, size_t size);
75 void put_device_interface(struct net_device_interface *interface);
76 struct net_device_interface *get_device_interface(uint32 index);
77 struct net_device_interface *get_device_interface(const char *name);
78 
79 // devices
80 status_t unregister_device_deframer(net_device *device);
81 status_t register_device_deframer(net_device *device, net_deframe_func deframeFunc);
82 status_t register_domain_device_handler(struct net_device *device, int32 type,
83 	struct net_domain *domain);
84 status_t register_device_handler(struct net_device *device, int32 type,
85 	net_receive_func receiveFunc, void *cookie);
86 status_t unregister_device_handler(struct net_device *device, int32 type);
87 status_t register_device_monitor(struct net_device *device,
88 	net_receive_func receiveFunc, void *cookie);
89 status_t unregister_device_monitor(struct net_device *device,
90 	net_receive_func receiveFunc, void *cookie);
91 status_t device_removed(net_device *device);
92 
93 #endif	// INTERFACES_H
94