1 /* 2 * Copyright 2006-2010, 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/if.h> 10 11 #include <net_buffer.h> 12 #include <net_routing_info.h> 13 14 #include <util/list.h> 15 16 17 #define NET_DATALINK_MODULE_NAME "network/stack/datalink/v1" 18 19 20 struct Checksum; 21 struct net_protocol; 22 23 24 typedef struct net_datalink_protocol net_datalink_protocol; 25 26 27 typedef struct net_domain { 28 const char* name; 29 int family; 30 31 struct net_protocol_module_info* module; 32 struct net_address_module_info* address_module; 33 } net_domain; 34 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; 41 uint32_t flags; 42 } net_interface_address; 43 44 typedef struct net_interface { 45 struct net_device* device; 46 47 char name[IF_NAMESIZE]; 48 uint32 index; 49 uint32 flags; 50 uint8 type; 51 uint32 mtu; 52 uint32 metric; 53 } net_interface; 54 55 typedef struct net_route { 56 struct sockaddr* destination; 57 struct sockaddr* mask; 58 struct sockaddr* gateway; 59 uint32 flags; 60 uint32 mtu; 61 struct net_interface_address* interface_address; 62 } net_route; 63 64 typedef struct net_route_info { 65 struct list_link link; 66 struct net_route* route; 67 struct sockaddr address; 68 } net_route_info; 69 70 71 struct net_datalink_module_info { 72 module_info info; 73 74 status_t (*control)(net_domain* domain, int32 option, void* value, 75 size_t* _length); 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); 79 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); 87 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); 92 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); 98 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); 103 104 // routes 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); 112 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); 119 }; 120 121 #define NET_ADDRESS_MODULE_FLAG_BROADCAST_ADDRESS 0x01 122 123 struct net_address_module_info { 124 module_info info; 125 uint32 flags; 126 127 status_t (*copy_address)(const struct sockaddr* from, 128 struct sockaddr** to, bool replaceWithZeros, 129 const struct sockaddr* mask); 130 131 status_t (*mask_address)(const struct sockaddr* address, 132 const struct sockaddr* mask, struct sockaddr* result); 133 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, 143 bool checkPort); 144 bool (*is_same_family)(const struct sockaddr* address); 145 146 int32 (*first_mask_bit)(const struct sockaddr* mask); 147 148 bool (*check_mask)(const struct sockaddr* address); 149 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); 154 155 uint16 (*get_port)(const struct sockaddr* address); 156 status_t (*set_port)(struct sockaddr* address, uint16 port); 157 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); 165 166 status_t (*update_to)(struct sockaddr* address, 167 const struct sockaddr* from); 168 169 uint32 (*hash_address)(const struct sockaddr* address, 170 bool includePort); 171 uint32 (*hash_address_pair)(const struct sockaddr* ourAddress, 172 const struct sockaddr* peerAddress); 173 174 status_t (*checksum_address)(struct Checksum* checksum, 175 const struct sockaddr* address); 176 177 void (*get_loopback_address)(struct sockaddr* result); 178 }; 179 180 181 #endif // NET_DATALINK_H 182