00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef _OLSR_INTERFACE
00044 #define _OLSR_INTERFACE
00045
00046 #include <sys/types.h>
00047 #ifdef _MSC_VER
00048 #include <WS2tcpip.h>
00049 #undef interface
00050 #else
00051 #include <sys/socket.h>
00052 #endif
00053 #include <time.h>
00054
00055
00056 struct interface;
00057
00066 enum interface_mode {
00067 IF_MODE_MESH,
00068 IF_MODE_ETHER,
00069
00070
00071 IF_MODE_COUNT
00072 };
00073
00074 #include "olsr_types.h"
00075 #include "olsr_cfg.h"
00076 #include "olsr_clock.h"
00077 #include "common/list.h"
00078 #include "common/avl.h"
00079
00080 #define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6"
00081
00082
00083 #define IPV6_ADDR_ANY 0x0000U
00084
00085 #define IPV6_ADDR_UNICAST 0x0001U
00086 #define IPV6_ADDR_MULTICAST 0x0002U
00087 #define IPV6_ADDR_ANYCAST 0x0004U
00088
00089 #define IPV6_ADDR_LOOPBACK 0x0010U
00090 #define IPV6_ADDR_LINKLOCAL 0x0020U
00091 #define IPV6_ADDR_SITELOCAL 0x0040U
00092
00093 #define IPV6_ADDR_COMPATv4 0x0080U
00094
00095 #define IPV6_ADDR_SCOPE_MASK 0x00f0U
00096
00097 #define IPV6_ADDR_MAPPED 0x1000U
00098 #define IPV6_ADDR_RESERVED 0x2000U
00099
00100
00101 #define MAX_IF_METRIC 100
00102
00103 #define WEIGHT_LOWEST 0
00104 #define WEIGHT_LOW 1
00105 #define WEIGHT_ETHERNET_1GBP 2
00106 #define WEIGHT_ETHERNET_1GB 4
00107 #define WEIGHT_ETHERNET_100MB 8
00108 #define WEIGHT_ETHERNET_10MB 16
00109 #define WEIGHT_ETHERNET_DEFAULT 32
00110 #define WEIGHT_WLAN_HIGH 64
00111 #define WEIGHT_WLAN_54MB 128
00112 #define WEIGHT_WLAN_11MB 256
00113 #define WEIGHT_WLAN_LOW 512
00114 #define WEIGHT_WLAN_DEFAULT 1024
00115 #define WEIGHT_SERIAL 2048
00116 #define WEIGHT_HIGH 4096
00117 #define WEIGHT_HIGHEST 8192
00118
00119 #if 0
00120 struct if_gen_property {
00121 uint32_t owner_id;
00122 void *data;
00123 struct if_gen_property *next;
00124 };
00125 #endif
00126
00127 extern const char *INTERFACE_MODE_NAMES[];
00128
00129
00130
00131
00132
00133 struct olsr_netbuf {
00134 uint8_t *buff;
00135 int bufsize;
00136 int maxsize;
00137 int pending;
00138 int reserved;
00139 };
00140
00145 struct interface {
00146 struct list_entity int_node;
00147
00148
00149 struct olsr_if_config *if_cfg;
00150
00151 enum interface_mode mode;
00152
00153
00154 union olsr_sockaddr int_src;
00155 union olsr_sockaddr int_multicast;
00156
00157
00158 union olsr_ip_addr ip_addr;
00159
00160
00161 struct olsr_socket_entry *olsr_socket;
00162
00163
00164 struct olsr_socket_entry *send_socket_;
00165 int send_socket_fd;
00166
00167
00168 int int_mtu;
00169 int if_index;
00170 char *int_name;
00171
00172
00173 uint16_t olsr_seqnum;
00174
00175
00176 struct olsr_timer_entry *hello_gen_timer;
00177
00178
00179 struct olsr_timer_entry *buffer_hold_timer;
00180 struct olsr_netbuf netbuf;
00181
00182 #ifdef linux
00183
00184
00185 struct nic_state {
00186 char redirect;
00187 char spoof;
00188 } nic_state;
00189 #endif
00190
00191 uint32_t hello_interval;
00192 uint32_t hello_validity;
00193
00194 uint32_t refcount;
00195 };
00196
00197
00198 #define OLSR_FOR_ALL_INTERFACES(interface, iterator) list_for_each_element_safe(&interface_head, interface, int_node, iterator)
00199
00200 struct interface_lost {
00201 struct avl_node node;
00202 union olsr_ip_addr ip;
00203 uint32_t valid_until;
00204 };
00205
00206 #define OLSR_FOR_ALL_LOSTIF_ENTRIES(lostif, iterator) avl_for_each_element_safe(&interface_lost_tree, lostif, node, iterator)
00207
00208 #define OLSR_BUFFER_HOLD_JITTER 25
00209 #define OLSR_BUFFER_HOLD_TIME 100
00210
00211 #define OLSR_DEFAULT_MTU 1500
00212
00213
00214
00215 #define IFCHG_IF_ADD 1
00216 #define IFCHG_IF_REMOVE 2
00217 #define IFCHG_IF_UPDATE 3
00218
00219
00220 extern struct list_entity EXPORT(interface_head);
00221
00222 typedef int (*ifchg_cb_func) (struct interface *, int);
00223
00224
00225 bool init_interfaces(void);
00226 bool EXPORT(is_lost_interface_ip)(union olsr_ip_addr *ip);
00227 void destroy_interfaces(void);
00228 struct interface *add_interface(struct olsr_if_config *iface);
00229 void remove_interface(struct interface *);
00230 void run_ifchg_cbs(struct interface *, int);
00231 struct interface *if_ifwithsock(int);
00232 struct interface *EXPORT(if_ifwithaddr) (const union olsr_ip_addr *);
00233 struct interface *if_ifwithname(const char *);
00234 const char *if_ifwithindex_name(const int if_index);
00235 struct interface *if_ifwithindex(const int if_index);
00236 void EXPORT(add_ifchgf) (ifchg_cb_func f);
00237 #if 0
00238 int del_ifchgf(ifchg_cb_func f);
00239 #endif
00240 void lock_interface(struct interface *);
00241 void unlock_interface(struct interface *);
00242
00243 #endif
00244
00245
00246
00247
00248
00249
00250