4 * Created on: 05.01.2010
11 #include "common/avl.h"
12 #include "common/list.h"
15 #include "scheduler.h"
16 #include "gateway_list.h"
19 /** used to signal to olsr_delete_gateway_entry to force deletion */
20 #define FORCE_DELETE_GW_ENTRY 255
22 /** the interval (in milliseconds) on which to run gateway cleanup */
23 #define GW_CLEANUP_INTERVAL 30000
26 * @return true if multi-gateway mode is enabled
28 static inline bool multi_gateway_mode(void) {
29 return (olsr_cnf->smart_gw_use_count > 1);
33 * hack for Vienna network:
34 * set MAXIMUM_GATEWAY_PREFIX_LENGTH to 1 to remove 0.0.0.0/128.0.0.0 and
35 * 128.0.0.0/128.0.0.0 routes
37 // #define MAXIMUM_GATEWAY_PREFIX_LENGTH 1
39 /** gateway HNA flags */
40 enum gateway_hna_flags {
41 GW_HNA_FLAG_LINKSPEED = 1 << 0,
42 GW_HNA_FLAG_IPV4 = 1 << 1,
43 GW_HNA_FLAG_IPV4_NAT = 1 << 2,
44 GW_HNA_FLAG_IPV6 = 1 << 3,
45 GW_HNA_FLAG_IPV6PREFIX = 1 << 4
48 /** gateway HNA field byte offsets in the netmask field of the HNA */
49 enum gateway_hna_fields {
54 GW_HNA_V6PREFIXLEN = 4,
58 /** a gateway entry */
59 struct gateway_entry {
61 union olsr_ip_addr originator;
62 struct olsr_ip_prefix external_prefix;
65 int64_t path_cost; /**< the gateway path costs */
70 struct timer_entry *cleanup_timer;
74 enum sgw_multi_change_phase {
75 GW_MULTI_CHANGE_PHASE_STARTUP = 0,
76 GW_MULTI_CHANGE_PHASE_RUNTIME = 1,
77 GW_MULTI_CHANGE_PHASE_SHUTDOWN = 2
81 /** structure that holds an interface name, mark and a pointer to the gateway that uses it */
82 struct interfaceName {
83 char name[IFNAMSIZ]; /**< interface name */
84 uint8_t tableNr; /**< routing table number */
85 uint8_t ruleNr; /**< IP rule number */
86 uint8_t bypassRuleNr; /**< bypass IP rule number */
87 struct gateway_entry *gw; /**< gateway that uses this interface name */
89 #endif /* __linux__ */
92 * static inline struct gateway_entry * node2gateway (struct avl_node *ptr)
94 * Converts a node into a gateway entry
96 AVLNODE2STRUCT(node2gateway, struct gateway_entry, node);
99 * Loop over all gateway entries and put the iterated gateway entry in gw
101 #define OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) \
103 struct avl_node *gw_node, *next_gw_node; \
104 for (gw_node = avl_walk_first(&gateway_tree); \
105 gw_node; gw_node = next_gw_node) { \
106 next_gw_node = avl_walk_next(gw_node); \
107 gw = node2gateway(gw_node);
108 #define OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw) }}
110 /** the gateway tree */
111 extern struct avl_tree gateway_tree;
113 /** the list IPv4 gateways */
114 extern struct gw_list gw_list_ipv4;
116 /** the list IPv6 gateways */
117 extern struct gw_list gw_list_ipv6;
120 * Function pointer table for gateway plugin hooks.
122 struct olsr_gw_handler {
124 * Called on olsrd startup to initialise the plugin.
129 * Called on olsrd shutdown to cleanup the plugin.
131 void (*cleanup)(void);
134 * Called on olsrd startup to perform the initial gateway selection.
136 void (*startup)(void);
139 * Called when the costs of a gateway must be determined.
141 * @param gw the gateway
144 int64_t (*getcosts)(struct gateway_entry *gw);
147 * Called when a new gateway must be chosen.
149 * @param ipv4 true when an IPv4 gateway must be chosen
150 * @param ipv6 true when an IPv6 gateway must be chosen
152 void (*choose)(bool ipv4, bool ipv6);
155 * Called when a gateway HNA is received.
157 * @param gw the gateway entry
159 void (*update)(struct gateway_entry * gw);
162 * Called when a TC or a HNA is removed.
164 * @param gw the gateway entry
166 void (* delete)(struct gateway_entry * gw);
173 int olsr_init_gateways(void);
174 int olsr_startup_gateways(void);
175 void olsr_shutdown_gateways(void);
176 void olsr_cleanup_gateways(void);
177 void olsr_trigger_inetgw_startup(void);
179 void olsr_print_gateway_entries(void);
181 #define olsr_print_gateway_entries() do { } while(0)
188 void olsr_modifiy_inetgw_netmask(union olsr_ip_addr *mask, int prefixlen);
191 * Interface to adjust uplink/downlink speed
194 void refresh_smartgw_netmask(void);
197 * TC/SPF/HNA Interface
200 bool olsr_is_smart_gateway(struct olsr_ip_prefix *prefix, union olsr_ip_addr *net);
201 void olsr_update_gateway_entry(union olsr_ip_addr *originator, union olsr_ip_addr *mask, int prefixlen, uint16_t seqno);
202 void olsr_delete_gateway_entry(union olsr_ip_addr *originator, uint8_t prefixlen, bool immediate);
203 void olsr_trigger_gatewayloss_check(void);
206 * Gateway Plugin Functions
209 bool olsr_set_inet_gateway(struct gateway_entry * chosen_gw, bool ipv4, bool ipv6);
210 struct gateway_entry *olsr_get_inet_gateway(bool ipv6);
213 * Multi Smart Gateway functions
216 void doRoutesMultiGw(bool egressChanged, bool olsrChanged, enum sgw_multi_change_phase phase);
218 #endif /* GATEWAY_H_ */