xref: /haiku/headers/private/net/net_datalink.h (revision 4b3b81da9e459443d75329cfd08bc9a57ad02653)
1 /*
2  * Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef NET_DATALINK_H
6 #define NET_DATALINK_H
7 
8 
9 #include <net_buffer.h>
10 #include <net_routing_info.h>
11 
12 #include <util/list.h>
13 
14 #include <net/if.h>
15 
16 
17 #define NET_DATALINK_MODULE_NAME "network/stack/datalink/v1"
18 
19 typedef struct net_datalink_protocol net_datalink_protocol;
20 
21 typedef struct net_domain {
22 	const char			*name;
23 	int					family;
24 	struct list			interfaces;
25 
26 	struct net_protocol_module_info *module;
27 	struct net_address_module_info *address_module;
28 } net_domain;
29 
30 struct net_interface {
31 	struct list_link	link;
32 	struct net_domain	*domain;
33 	struct net_device	*device;
34 	struct net_datalink_protocol *first_protocol;
35 	struct net_datalink_protocol_module_info *first_info;
36 
37 	char				name[IF_NAMESIZE];
38 	struct sockaddr		*address;
39 	struct sockaddr		*destination;
40 	struct sockaddr		*mask;
41 	uint32				index;
42 	uint32				flags;
43 	uint8				type;
44 	uint32				mtu;
45 	uint32				metric;
46 };
47 
48 struct net_route {
49 	struct sockaddr		*destination;
50 	struct sockaddr		*mask;
51 	struct sockaddr		*gateway;
52 	uint32				flags;
53 	uint32				mtu;
54 	struct net_interface *interface;
55 };
56 
57 struct net_route_info {
58 	struct list_link	link;
59 	struct net_route	*route;
60 	struct sockaddr		address;
61 };
62 
63 struct net_datalink_module_info {
64 	module_info info;
65 
66 	status_t (*control)(struct net_domain *domain, int32 option, void *value,
67 					size_t *_length);
68 	status_t (*send_data)(struct net_route *route, struct net_buffer *buffer);
69 	status_t (*send_datagram)(struct net_protocol *protocol,
70 					struct net_domain *domain, struct net_buffer *buffer);
71 
72 	bool (*is_local_address)(struct net_domain *domain,
73 					const struct sockaddr *address,
74 					net_interface **_interface,
75 					uint32 *_matchedType);
76 	net_interface *(*get_interface)(struct net_domain *domain, uint32 index);
77 	net_interface *(*get_interface_with_address)(struct net_domain *domain,
78 					const struct sockaddr *address);
79 
80 	// routes
81 	status_t (*add_route)(struct net_domain *domain,
82 					const struct net_route *route);
83 	status_t (*remove_route)(struct net_domain *domain,
84 					const struct net_route *route);
85 	struct net_route *(*get_route)(struct net_domain *domain,
86 					const struct sockaddr *address);
87 	status_t (*get_buffer_route)(struct net_domain *domain,
88 					struct net_buffer *buffer, struct net_route **_route);
89 	void (*put_route)(struct net_domain *domain, struct net_route *route);
90 
91 	status_t (*register_route_info)(struct net_domain *domain,
92 					struct net_route_info *info);
93 	status_t (*unregister_route_info)(struct net_domain *domain,
94 					struct net_route_info *info);
95 	status_t (*update_route_info)(struct net_domain *domain,
96 					struct net_route_info *info);
97 };
98 
99 struct net_address_module_info {
100 	module_info info;
101 
102 	status_t (*copy_address)(const sockaddr *from, sockaddr **to,
103 					bool replaceWithZeros, const sockaddr *mask);
104 
105 	status_t (*mask_address)(const sockaddr *address, const sockaddr *mask,
106 					sockaddr *result);
107 
108 	bool (*equal_addresses)(const sockaddr *a, const sockaddr *b);
109 	bool (*equal_ports)(const sockaddr *a, const sockaddr *b);
110 	bool (*equal_addresses_and_ports)(const sockaddr *a, const sockaddr *b);
111 	bool (*equal_masked_addresses)(const sockaddr *a, const sockaddr *b,
112 					const sockaddr *mask);
113 	bool (*is_empty_address)(const sockaddr *address, bool checkPort);
114 
115 	int32 (*first_mask_bit)(const sockaddr *mask);
116 
117 	bool (*check_mask)(const sockaddr *address);
118 
119 	status_t (*print_address)(const sockaddr *address, char **buffer,
120 					bool printPort);
121 	status_t (*print_address_buffer)(const sockaddr *address, char *buffer,
122 					size_t bufferSize, bool printPort);
123 
124 	uint16 (*get_port)(const sockaddr *address);
125 	status_t (*set_port)(sockaddr *address, uint16 port);
126 
127 	status_t (*set_to)(sockaddr *address, const sockaddr *from);
128 	status_t (*set_to_empty_address)(sockaddr *address);
129 	status_t (*set_to_defaults)(sockaddr *defaultMask,
130 					sockaddr *defaultBroadcast, sockaddr *address,
131 					sockaddr *netmask);
132 
133 	status_t (*update_to)(sockaddr *address, const sockaddr *from);
134 
135 	uint32 (*hash_address_pair)(const sockaddr *ourAddress,
136 					const sockaddr *peerAddress);
137 
138 	status_t (*checksum_address)(struct Checksum *checksum,
139 					const sockaddr *address);
140 
141 	bool (*matches_broadcast_address)(const sockaddr *address,
142 					const sockaddr *mask, const sockaddr *broadcastAddr);
143 };
144 
145 #endif	// NET_DATALINK_H
146