1 /* 2 * The olsr.org Optimized Link-State Routing daemon (olsrd) 3 * 4 * (c) by the OLSR project 5 * 6 * See our Git repository to find out who worked on this file 7 * and thus is a copyright holder on it. 8 * 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 15 * * Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * * Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in 19 * the documentation and/or other materials provided with the 20 * distribution. 21 * * Neither the name of olsr.org, olsrd nor the names of its 22 * contributors may be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 29 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 * 38 * Visit http://www.olsr.org for more information. 39 * 40 * If you find this software useful feel free to make a donation 41 * to the project. For more information see the website or contact 42 * the copyright holders. 43 * 44 */ 45 46 #ifndef _OLSR_INTERFACE 47 #define _OLSR_INTERFACE 48 49 #include <sys/types.h> 50 #ifdef _MSC_VER 51 #include <WS2tcpip.h> 52 #undef interface 53 #else /* _MSC_VER */ 54 #include <sys/socket.h> 55 #endif /* _MSC_VER */ 56 #include <time.h> 57 58 #include "olsr_types.h" 59 #include "mantissa.h" 60 61 #define IPV6_ADDR_ANY 0x0000U 62 63 #define IPV6_ADDR_UNICAST 0x0001U 64 #define IPV6_ADDR_MULTICAST 0x0002U 65 #define IPV6_ADDR_ANYCAST 0x0004U 66 67 #define IPV6_ADDR_LOOPBACK 0x0010U 68 #define IPV6_ADDR_LINKLOCAL 0x0020U 69 #define IPV6_ADDR_SITELOCAL 0x0040U 70 71 #define IPV6_ADDR_COMPATv4 0x0080U 72 73 #define IPV6_ADDR_SCOPE_MASK 0x00f0U 74 75 #define IPV6_ADDR_MAPPED 0x1000U 76 #define IPV6_ADDR_RESERVED 0x2000U 77 78 #define MAX_IF_METRIC 100 79 80 #define WEIGHT_LOWEST 0 /* No weight */ 81 #define WEIGHT_LOW 1 /* Low */ 82 #define WEIGHT_ETHERNET_1GBP 2 /* Ethernet 1Gb+ */ 83 #define WEIGHT_ETHERNET_1GB 4 /* Ethernet 1Gb */ 84 #define WEIGHT_ETHERNET_100MB 8 /* Ethernet 100Mb */ 85 #define WEIGHT_ETHERNET_10MB 16 /* Ethernet 10Mb */ 86 #define WEIGHT_ETHERNET_DEFAULT 32 /* Ethernet unknown rate */ 87 #define WEIGHT_WLAN_HIGH 64 /* >54Mb WLAN */ 88 #define WEIGHT_WLAN_54MB 128 /* 54Mb 802.11g */ 89 #define WEIGHT_WLAN_11MB 256 /* 11Mb 802.11b */ 90 #define WEIGHT_WLAN_LOW 512 /* <11Mb WLAN */ 91 #define WEIGHT_WLAN_DEFAULT 1024 /* WLAN unknown rate */ 92 #define WEIGHT_SERIAL 2048 /* Serial device */ 93 #define WEIGHT_HIGH 4096 /* High */ 94 #define WEIGHT_HIGHEST 8192 /* Really high */ 95 96 struct if_gen_property { 97 uint32_t owner_id; 98 void *data; 99 struct if_gen_property *next; 100 }; 101 102 struct vtimes { 103 uint8_t hello; 104 uint8_t tc; 105 uint8_t mid; 106 uint8_t hna; 107 uint32_t hna_reltime; 108 }; 109 110 /* Output buffer structure. This should actually be in net_olsr.h but we have circular references then. 111 */ 112 struct olsr_netbuf { 113 uint8_t *buff; /* Pointer to the allocated buffer */ 114 int bufsize; /* Size of the buffer */ 115 int maxsize; /* Max bytes of payload that can be added to the buffer */ 116 int pending; /* How much data is currently pending in the buffer */ 117 int reserved; /* Plugins can reserve space in buffers */ 118 }; 119 120 /** 121 *A struct containing all necessary information about each 122 *interface participating in the OLSRD routing 123 */ 124 struct interface_olsr { 125 /* IP version 4 */ 126 struct sockaddr_in int_addr; /* address */ 127 struct sockaddr_in int_netmask; /* netmask */ 128 struct sockaddr_in int_broadaddr; /* broadcast address */ 129 int mode; /* interface mode */ 130 /* IP version 6 */ 131 struct sockaddr_in6 int6_addr; /* Address */ 132 struct sockaddr_in6 int6_multaddr; /* Multicast */ 133 /* IP independent */ 134 union olsr_ip_addr ip_addr; 135 int is_hcif; /* Is this a emulated host-client if? */ 136 137 int olsr_socket; /* The broadcast socket for this interface */ 138 int send_socket; /* The send socket for this interface */ 139 140 int int_metric; /* metric of interface */ 141 int int_mtu; /* MTU of interface */ 142 int int_flags; /* see below */ 143 int if_index; /* Kernels index of this interface */ 144 int is_wireless; /* wireless interface or not */ 145 char *int_name; /* from kernel if structure */ 146 uint16_t olsr_seqnum; /* Olsr message seqno */ 147 148 /* Periodic message generation timers */ 149 struct timer_entry *hello_gen_timer; 150 struct timer_entry *hna_gen_timer; 151 struct timer_entry *mid_gen_timer; 152 struct timer_entry *tc_gen_timer; 153 154 #ifdef __linux__ 155 156 /* Struct used to store original redirect/ingress setting */ 157 struct nic_state { 158 /* The original state of icmp redirect */ 159 char redirect; 160 161 /* The original state of the IP spoof filter */ 162 char spoof; 163 } nic_state; 164 #endif /* __linux__ */ 165 166 olsr_reltime hello_etime; 167 struct vtimes valtimes; 168 169 /* Timeout for OLSR forwarding on this if */ 170 uint32_t fwdtimer; 171 172 /* Timeout for OLSR to keep sending zero bandwidth sgw HNAs */ 173 uint32_t sgw_sgw_zero_bw_timeout; 174 175 /* the buffer to construct the packet data */ 176 struct olsr_netbuf netbuf; 177 178 /* Generic interface properties */ 179 struct if_gen_property *gen_properties; 180 181 /* index in TTL array for fish-eye */ 182 int ttl_index; 183 184 /* Hello's are sent immediately normally, this flag prefers to send TC's */ 185 bool immediate_send_tc; 186 187 /* backpointer to olsr_if configuration */ 188 struct olsr_if *olsr_if; 189 struct interface_olsr *int_next; 190 }; 191 192 #define OLSR_DEFAULT_MTU 1500 193 194 /* Ifchange actions */ 195 196 enum olsr_ifchg_flag { 197 IFCHG_IF_ADD = 1, 198 IFCHG_IF_REMOVE = 2, 199 IFCHG_IF_UPDATE = 3 200 }; 201 202 /* The interface linked-list */ 203 extern struct interface_olsr *ifnet; 204 205 int olsr_init_interfacedb(void); 206 void olsr_delete_interfaces(void); 207 208 void olsr_trigger_ifchange(int if_index, struct interface_olsr *, enum olsr_ifchg_flag); 209 210 struct interface_olsr *if_ifwithsock(int); 211 212 struct interface_olsr *if_ifwithaddr(const union olsr_ip_addr *); 213 214 struct interface_olsr *if_ifwithname(const char *); 215 struct olsr_if *olsrif_ifwithname(const char *if_name); 216 217 const char *if_ifwithindex_name(const int if_index); 218 219 struct interface_olsr *if_ifwithindex(const int if_index); 220 221 struct olsr_if *olsr_create_olsrif(const char *name, int hemu); 222 223 int olsr_add_ifchange_handler(void (*f) (int if_index, struct interface_olsr *, enum olsr_ifchg_flag)); 224 int olsr_remove_ifchange_handler(void (*f) (int if_index, struct interface_olsr *, enum olsr_ifchg_flag)); 225 226 void olsr_remove_interface(struct olsr_if *); 227 228 extern struct olsr_cookie_info *interface_poll_timer_cookie; 229 extern struct olsr_cookie_info *hello_gen_timer_cookie; 230 extern struct olsr_cookie_info *tc_gen_timer_cookie; 231 extern struct olsr_cookie_info *mid_gen_timer_cookie; 232 extern struct olsr_cookie_info *hna_gen_timer_cookie; 233 234 #endif /* _OLSR_INTERFACE */ 235 236 /* 237 * Local Variables: 238 * c-basic-offset: 2 239 * indent-tabs-mode: nil 240 * End: 241 */ 242