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 class 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 metric; 52 } net_interface; 53 54 typedef struct net_route { 55 struct sockaddr* destination; 56 struct sockaddr* mask; 57 struct sockaddr* gateway; 58 uint32 flags; 59 uint32 mtu; 60 struct net_interface_address* interface_address; 61 } net_route; 62 63 typedef struct net_route_info { 64 struct list_link link; 65 struct net_route* route; 66 struct sockaddr address; 67 } net_route_info; 68 69 70 struct net_datalink_module_info { 71 module_info info; 72 73 status_t (*control)(net_domain* domain, int32 option, void* value, 74 size_t* _length); 75 status_t (*send_routed_data)(net_route* route, net_buffer* buffer); 76 status_t (*send_data)(struct net_protocol* protocol, 77 net_domain* domain, net_buffer* buffer); 78 79 bool (*is_local_address)(net_domain* domain, 80 const struct sockaddr* address, 81 net_interface_address** _interfaceAddress, 82 uint32* _matchedType); 83 bool (*is_local_link_address)(net_domain* domain, 84 bool unconfigured, const struct sockaddr* address, 85 net_interface_address** _interfaceAddress); 86 87 net_interface* (*get_interface)(net_domain* domain, uint32 index); 88 net_interface* (*get_interface_with_address)( 89 const struct sockaddr* address); 90 void (*put_interface)(net_interface* interface); 91 92 net_interface_address* (*get_interface_address)( 93 const struct sockaddr* address); 94 bool (*get_next_interface_address)(net_interface* interface, 95 net_interface_address** _address); 96 void (*put_interface_address)(net_interface_address* address); 97 98 status_t (*join_multicast)(net_interface* interface, 99 net_domain* domain, const struct sockaddr* address); 100 status_t (*leave_multicast)(net_interface* interface, 101 net_domain* domain, const struct sockaddr* address); 102 103 // routes 104 status_t (*add_route)(net_domain* domain, const net_route* route); 105 status_t (*remove_route)(net_domain* domain, const net_route* route); 106 net_route* (*get_route)(net_domain* domain, 107 const struct sockaddr* address); 108 status_t (*get_buffer_route)(net_domain* domain, 109 struct net_buffer* buffer, net_route** _route); 110 void (*put_route)(net_domain* domain, net_route* route); 111 112 status_t (*register_route_info)(net_domain* domain, 113 net_route_info* info); 114 status_t (*unregister_route_info)(net_domain* domain, 115 net_route_info* info); 116 status_t (*update_route_info)(net_domain* domain, 117 net_route_info* info); 118 }; 119 120 #define NET_ADDRESS_MODULE_FLAG_BROADCAST_ADDRESS 0x01 121 122 struct net_address_module_info { 123 module_info info; 124 uint32 flags; 125 126 status_t (*copy_address)(const struct sockaddr* from, 127 struct sockaddr** to, bool replaceWithZeros, 128 const struct sockaddr* mask); 129 130 status_t (*mask_address)(const struct sockaddr* address, 131 const struct sockaddr* mask, struct sockaddr* result); 132 133 bool (*equal_addresses)(const struct sockaddr* a, 134 const struct sockaddr* b); 135 bool (*equal_ports)(const struct sockaddr* a, 136 const struct sockaddr* b); 137 bool (*equal_addresses_and_ports)(const struct sockaddr* a, 138 const struct sockaddr* b); 139 bool (*equal_masked_addresses)(const struct sockaddr* a, 140 const struct sockaddr* b, const struct sockaddr* mask); 141 bool (*is_empty_address)(const struct sockaddr* address, 142 bool checkPort); 143 bool (*is_same_family)(const struct sockaddr* address); 144 145 int32 (*first_mask_bit)(const struct sockaddr* mask); 146 147 bool (*check_mask)(const struct sockaddr* address); 148 149 status_t (*print_address)(const struct sockaddr* address, 150 char** buffer, bool printPort); 151 status_t (*print_address_buffer)(const struct sockaddr* address, 152 char* buffer, size_t bufferSize, bool printPort); 153 154 uint16 (*get_port)(const struct sockaddr* address); 155 status_t (*set_port)(struct sockaddr* address, uint16 port); 156 157 status_t (*set_to)(struct sockaddr* address, 158 const struct sockaddr* from); 159 status_t (*set_to_empty_address)(struct sockaddr* address); 160 status_t (*set_to_defaults)(struct sockaddr* defaultMask, 161 struct sockaddr* defaultBroadcast, 162 const struct sockaddr* address, 163 const struct sockaddr* netmask); 164 165 status_t (*update_to)(struct sockaddr* address, 166 const struct sockaddr* from); 167 168 uint32 (*hash_address)(const struct sockaddr* address, 169 bool includePort); 170 uint32 (*hash_address_pair)(const struct sockaddr* ourAddress, 171 const struct sockaddr* peerAddress); 172 173 status_t (*checksum_address)(Checksum* checksum, 174 const struct sockaddr* address); 175 176 void (*get_loopback_address)(struct sockaddr* result); 177 }; 178 179 180 #endif // NET_DATALINK_H 181