1 /* 2 * Copyright 2006, 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 70 bool (*is_local_address)(struct net_domain *domain, 71 const struct sockaddr *address, 72 net_interface **_interface, 73 uint32 *_matchedType); 74 75 // routes 76 status_t (*add_route)(struct net_domain *domain, 77 const struct net_route *route); 78 status_t (*remove_route)(struct net_domain *domain, 79 const struct net_route *route); 80 struct net_route *(*get_route)(struct net_domain *domain, 81 const struct sockaddr *address); 82 void (*put_route)(struct net_domain *domain, struct net_route *route); 83 84 status_t (*register_route_info)(struct net_domain *domain, 85 struct net_route_info *info); 86 status_t (*unregister_route_info)(struct net_domain *domain, 87 struct net_route_info *info); 88 status_t (*update_route_info)(struct net_domain *domain, 89 struct net_route_info *info); 90 }; 91 92 struct net_address_module_info { 93 module_info info; 94 95 status_t (*copy_address)(const sockaddr *from, sockaddr **to, 96 bool replaceWithZeros /* = false */, const sockaddr *mask /* = NULL*/); 97 98 status_t (*mask_address)(const sockaddr *address, const sockaddr *mask, 99 sockaddr *result); 100 101 bool (*equal_addresses)(const sockaddr *a, const sockaddr *b); 102 bool (*equal_ports)(const sockaddr *a, const sockaddr *b); 103 bool (*equal_addresses_and_ports)(const sockaddr *a, const sockaddr *b); 104 bool (*equal_masked_addresses)(const sockaddr *a, const sockaddr *b, 105 const sockaddr *mask); 106 bool (*is_empty_address)(const sockaddr *address, bool checkPort /* = true */); 107 108 int32 (*first_mask_bit)(const sockaddr *mask); 109 110 bool (*check_mask)(const sockaddr *address); 111 112 status_t (*print_address)(const sockaddr *address, char **buffer, 113 bool printPort); 114 115 uint16 (*get_port)(const sockaddr *address); 116 status_t (*set_port)(sockaddr *address, uint16 port); 117 118 status_t (*set_to)(sockaddr *address, const sockaddr *from); 119 status_t (*set_to_empty_address)(sockaddr *address); 120 121 uint32 (*hash_address_pair)(const sockaddr *ourAddress, 122 const sockaddr *peerAddress); 123 124 status_t (*checksum_address)(struct Checksum *checksum, 125 const sockaddr *address); 126 127 bool (*matches_broadcast_address)(const sockaddr *address, 128 const sockaddr *mask, const sockaddr *broadcastAddr); 129 }; 130 131 #endif // NET_DATALINK_H 132