/*
route.c -- routing
Copyright (C) 2000-2005 Ivo Timmermans,
- 2000-2012 Guus Sliepen <guus@tinc-vpn.org>
+ 2000-2013 Guus Sliepen <guus@tinc-vpn.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
-static struct event age_subnets_event;
+static timeout_t age_subnets_timeout;
/* RFC 1071 */
static bool ratelimit(int frequency) {
static time_t lasttime = 0;
static int count = 0;
- time_t now = time(NULL);
- if(lasttime == now) {
+ if(lasttime == now.tv_sec) {
if(count >= frequency)
return true;
} else {
- lasttime = now;
+ lasttime = now.tv_sec;
count = 0;
}
memcpy(&packet->data[6], &tmp, sizeof tmp);
}
-static void age_subnets(int fd, short events, void *data) {
+static void age_subnets(void *data) {
bool left = false;
- time_t now = time(NULL);
for splay_each(subnet_t, s, myself->subnet_tree) {
- if(s->expires && s->expires < now) {
+ if(s->expires && s->expires < now.tv_sec) {
if(debug_level >= DEBUG_TRAFFIC) {
char netstr[MAXNETSTR];
if(net2str(netstr, sizeof netstr, s))
}
if(left)
- event_add(&age_subnets_event, &(struct timeval){10, rand() % 100000});
+ timeout_set(&age_subnets_timeout, &(struct timeval){10, rand() % 100000});
}
static void learn_mac(mac_t *address) {
subnet = new_subnet();
subnet->type = SUBNET_MAC;
- subnet->expires = time(NULL) + macexpire;
+ subnet->expires = now.tv_sec + macexpire;
subnet->net.mac.address = *address;
subnet->weight = 10;
subnet_add(myself, subnet);
if(c->status.active)
send_add_subnet(c, subnet);
- if(!timeout_initialized(&age_subnets_event))
- timeout_set(&age_subnets_event, age_subnets, NULL);
- event_add(&age_subnets_event, &(struct timeval){10, rand() % 100000});
+ timeout_add(&age_subnets_timeout, age_subnets, NULL, &(struct timeval){10, rand() % 100000});
} else {
if(subnet->expires)
- subnet->expires = time(NULL) + macexpire;
+ subnet->expires = now.tv_sec + macexpire;
}
}
if(forwarding_mode == FMODE_OFF && source != myself && subnet->owner != myself)
return;
+ uint16_t type = packet->data[12] << 8 | packet->data[13];
+
+ if(priorityinheritance && type == ETH_P_IP && packet->len >= ether_size + ip_size)
+ packet->priority = packet->data[15];
+
// Handle packets larger than PMTU
node_t *via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
if(via && packet->len > via->mtu && via != myself) {
logger(DEBUG_TRAFFIC, LOG_INFO, "Packet for %s (%s) length %d larger than MTU %d", subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
- uint16_t type = packet->data[12] << 8 | packet->data[13];
length_t ethlen = 14;
if(type == ETH_P_8021Q) {