2 * Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
11 #include <net_buffer.h>
12 #include <net_routing_info.h>
14 #include <util/list.h>
17 #define NET_DATALINK_MODULE_NAME "network/stack/datalink/v1"
24 typedef struct net_datalink_protocol net_datalink_protocol
;
27 typedef struct net_domain
{
31 struct net_protocol_module_info
* module
;
32 struct net_address_module_info
* address_module
;
35 typedef struct net_interface_address
{
36 struct net_domain
* domain
;
37 struct net_interface
* interface
;
38 struct sockaddr
* local
;
39 struct sockaddr
* destination
;
40 struct sockaddr
* mask
;
42 } net_interface_address
;
44 typedef struct net_interface
{
45 struct net_device
* device
;
47 char name
[IF_NAMESIZE
];
55 typedef struct net_route
{
56 struct sockaddr
* destination
;
57 struct sockaddr
* mask
;
58 struct sockaddr
* gateway
;
61 struct net_interface_address
* interface_address
;
64 typedef struct net_route_info
{
65 struct list_link link
;
66 struct net_route
* route
;
67 struct sockaddr address
;
71 struct net_datalink_module_info
{
74 status_t (*control
)(net_domain
* domain
, int32 option
, void* value
,
76 status_t (*send_routed_data
)(net_route
* route
, net_buffer
* buffer
);
77 status_t (*send_data
)(struct net_protocol
* protocol
,
78 net_domain
* domain
, net_buffer
* buffer
);
80 bool (*is_local_address
)(net_domain
* domain
,
81 const struct sockaddr
* address
,
82 net_interface_address
** _interfaceAddress
,
83 uint32
* _matchedType
);
84 bool (*is_local_link_address
)(net_domain
* domain
,
85 bool unconfigured
, const struct sockaddr
* address
,
86 net_interface_address
** _interfaceAddress
);
88 net_interface
* (*get_interface
)(net_domain
* domain
, uint32 index
);
89 net_interface
* (*get_interface_with_address
)(
90 const struct sockaddr
* address
);
91 void (*put_interface
)(net_interface
* interface
);
93 net_interface_address
* (*get_interface_address
)(
94 const struct sockaddr
* address
);
95 bool (*get_next_interface_address
)(net_interface
* interface
,
96 net_interface_address
** _address
);
97 void (*put_interface_address
)(net_interface_address
* address
);
99 status_t (*join_multicast
)(net_interface
* interface
,
100 net_domain
* domain
, const struct sockaddr
* address
);
101 status_t (*leave_multicast
)(net_interface
* interface
,
102 net_domain
* domain
, const struct sockaddr
* address
);
105 status_t (*add_route
)(net_domain
* domain
, const net_route
* route
);
106 status_t (*remove_route
)(net_domain
* domain
, const net_route
* route
);
107 net_route
* (*get_route
)(net_domain
* domain
,
108 const struct sockaddr
* address
);
109 status_t (*get_buffer_route
)(net_domain
* domain
,
110 struct net_buffer
* buffer
, net_route
** _route
);
111 void (*put_route
)(net_domain
* domain
, net_route
* route
);
113 status_t (*register_route_info
)(net_domain
* domain
,
114 net_route_info
* info
);
115 status_t (*unregister_route_info
)(net_domain
* domain
,
116 net_route_info
* info
);
117 status_t (*update_route_info
)(net_domain
* domain
,
118 net_route_info
* info
);
121 #define NET_ADDRESS_MODULE_FLAG_BROADCAST_ADDRESS 0x01
123 struct net_address_module_info
{
127 status_t (*copy_address
)(const struct sockaddr
* from
,
128 struct sockaddr
** to
, bool replaceWithZeros
,
129 const struct sockaddr
* mask
);
131 status_t (*mask_address
)(const struct sockaddr
* address
,
132 const struct sockaddr
* mask
, struct sockaddr
* result
);
134 bool (*equal_addresses
)(const struct sockaddr
* a
,
135 const struct sockaddr
* b
);
136 bool (*equal_ports
)(const struct sockaddr
* a
,
137 const struct sockaddr
* b
);
138 bool (*equal_addresses_and_ports
)(const struct sockaddr
* a
,
139 const struct sockaddr
* b
);
140 bool (*equal_masked_addresses
)(const struct sockaddr
* a
,
141 const struct sockaddr
* b
, const struct sockaddr
* mask
);
142 bool (*is_empty_address
)(const struct sockaddr
* address
,
144 bool (*is_same_family
)(const struct sockaddr
* address
);
146 int32 (*first_mask_bit
)(const struct sockaddr
* mask
);
148 bool (*check_mask
)(const struct sockaddr
* address
);
150 status_t (*print_address
)(const struct sockaddr
* address
,
151 char** buffer
, bool printPort
);
152 status_t (*print_address_buffer
)(const struct sockaddr
* address
,
153 char* buffer
, size_t bufferSize
, bool printPort
);
155 uint16 (*get_port
)(const struct sockaddr
* address
);
156 status_t (*set_port
)(struct sockaddr
* address
, uint16 port
);
158 status_t (*set_to
)(struct sockaddr
* address
,
159 const struct sockaddr
* from
);
160 status_t (*set_to_empty_address
)(struct sockaddr
* address
);
161 status_t (*set_to_defaults
)(struct sockaddr
* defaultMask
,
162 struct sockaddr
* defaultBroadcast
,
163 const struct sockaddr
* address
,
164 const struct sockaddr
* netmask
);
166 status_t (*update_to
)(struct sockaddr
* address
,
167 const struct sockaddr
* from
);
169 uint32 (*hash_address
)(const struct sockaddr
* address
,
171 uint32 (*hash_address_pair
)(const struct sockaddr
* ourAddress
,
172 const struct sockaddr
* peerAddress
);
174 status_t (*checksum_address
)(struct Checksum
* checksum
,
175 const struct sockaddr
* address
);
177 void (*get_loopback_address
)(struct sockaddr
* result
);
181 #endif // NET_DATALINK_H