#ifdef DEBUG
OLSR_PRINTF(BMSG_DBGLVL, "\tNet: %s\n", olsr_ip_prefix_to_string(&h->net));
#endif
+
+ if (olsr_cnf->smart_gateway_active && h->net.prefix_len == 0) {
+ /* this is the default route, overwrite it with the smart gateway */
+ ip_addr.v4 = olsr_cnf->smart_gateway_netmask.v4;
+ }
+ else {
+ olsr_prefix_to_netmask(&ip_addr, h->net.prefix_len);
+ }
pair->addr = h->net.prefix.v4.s_addr;
- olsr_prefix_to_netmask(&ip_addr, h->net.prefix_len);
pair->netmask = ip_addr.v4.s_addr;
pair++;
curr_size += (2 * olsr_cnf->ipsize);
#ifdef DEBUG
OLSR_PRINTF(BMSG_DBGLVL, "\tNet: %s\n", olsr_ip_prefix_to_string(&h->net));
#endif
- pair6->addr = h->net.prefix.v6;
olsr_prefix_to_netmask(&tmp_netmask, h->net.prefix_len);
+ if (olsr_cnf->smart_gateway_active && h->net.prefix_len == 0) {
+ /* this is the default gateway, so overwrite it with the smart one */
+ tmp_netmask = olsr_cnf->smart_gateway_netmask;
+ }
+ else {
+ olsr_prefix_to_netmask(&tmp_netmask, h->net.prefix_len);
+ }
+ pair6->addr = h->net.prefix.v6;
pair6->netmask = tmp_netmask.v6;
pair6++;
curr_size += (2 * olsr_cnf->ipsize);
}
}
-bool olsr_is_smart_gateway(union olsr_ip_addr *netmask) {
+bool olsr_is_smart_gateway(union olsr_ip_addr *net, union olsr_ip_addr *mask) {
uint8_t i;
uint8_t *ip;
- ip = (uint8_t *)netmask;
+ ip = (uint8_t *)net;
+ for (i=0; i<olsr_cnf->ipsize; i++) {
+ if (*ip++) {
+ return false;
+ }
+ }
+ ip = (uint8_t *)mask;
for (i=0; i<olsr_cnf->ipsize-2; i++) {
if (*ip++ != 0) {
return false;
struct gateway_entry *olsr_find_gateway(union olsr_ip_addr *originator);
void olsr_set_gateway(union olsr_ip_addr *originator, union olsr_ip_addr *subnetmask);
void olsr_delete_gateway(union olsr_ip_addr *originator);
-bool olsr_is_smart_gateway(union olsr_ip_addr *netmask);
+bool olsr_is_smart_gateway(union olsr_ip_addr *net, union olsr_ip_addr *mask);
#endif /* GATEWAY_H_ */
#include "net_olsr.h"
#include "tc_set.h"
#include "parser.h"
+#include "gateway.h"
struct hna_entry hna_set[HASHSIZE];
struct olsr_cookie_info *hna_net_timer_cookie = NULL;
}
#if 1
while (curr < curr_end) {
- union olsr_ip_addr net;
+ union olsr_ip_addr net, mask;
uint8_t prefixlen;
struct ip_prefix_list *entry;
pkt_get_ipaddress(&curr, &net);
- pkt_get_prefixlen(&curr, &prefixlen);
- entry = ip_prefix_list_find(olsr_cnf->hna_entries, &net, prefixlen);
- if (entry == NULL) {
- /* only update if it's not from us */
- olsr_update_hna_entry(&originator, &net, prefixlen, vtime);
+ pkt_get_ipaddress(&curr, &mask);
+ if (olsr_cnf->smart_gateway_active && olsr_is_smart_gateway(&net, &mask)) {
+ olsr_set_gateway(&originator, &mask);
+ }
+ else {
+ prefixlen = olsr_netmask_to_prefix(&mask);
+ if (olsr_cnf->smart_gateway_active && prefixlen <= MAXIMUM_GATEWAY_PREFIX_LENGTH) {
+ continue;
+ }
+
+ entry = ip_prefix_list_find(olsr_cnf->hna_entries, &net, prefixlen);
+ if (entry == NULL) {
+ /* only update if it's not from us */
+ olsr_update_hna_entry(&originator, &net, prefixlen, vtime);
+ }
}
}
#else