+ logger(DEBUG_TRAFFIC, LOG_INFO, "Learned new MAC address %x:%x:%x:%x:%x:%x",
+ address->x[0], address->x[1], address->x[2], address->x[3],
+ address->x[4], address->x[5]);
+
+ subnet = new_subnet();
+ subnet->type = SUBNET_MAC;
+ subnet->expires = now.tv_sec + macexpire;
+ subnet->net.mac.address = *address;
+ subnet->weight = 10;
+ subnet_add(myself, subnet);
+ subnet_update(myself, subnet, true);
+
+ /* And tell all other tinc daemons it's our MAC */
+
+ for list_each(connection_t, c, connection_list)
+ if(c->edge)
+ send_add_subnet(c, subnet);
+
+ timeout_add(&age_subnets_timeout, age_subnets, NULL, &(struct timeval){10, rand() % 100000});
+ } else {
+ if(subnet->expires)
+ subnet->expires = now.tv_sec + macexpire;
+ }
+}
+
+static void route_broadcast(node_t *source, vpn_packet_t *packet) {
+ if(decrement_ttl && source != myself)
+ if(!do_decrement_ttl(source, packet))
+ return;
+
+ broadcast_packet(source, packet);
+}
+
+/* RFC 791 */
+
+static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet, length_t ether_size) {
+ struct ip ip;
+ vpn_packet_t fragment;
+ int len, maxlen, todo;
+ uint8_t *offset;
+ uint16_t ip_off, origf;
+
+ memcpy(&ip, DATA(packet) + ether_size, ip_size);
+ fragment.priority = packet->priority;
+ fragment.offset = DEFAULT_PACKET_OFFSET;
+
+ if(ip.ip_hl != ip_size / 4)
+ return;
+
+ todo = ntohs(ip.ip_len) - ip_size;
+
+ if(ether_size + ip_size + todo != packet->len) {
+ logger(DEBUG_TRAFFIC, LOG_WARNING, "Length of packet (%d) doesn't match length in IPv4 header (%d)", packet->len, (int)(ether_size + ip_size + todo));
+ return;
+ }
+
+ logger(DEBUG_TRAFFIC, LOG_INFO, "Fragmenting packet of %d bytes to %s (%s)", packet->len, dest->name, dest->hostname);
+
+ offset = DATA(packet) + ether_size + ip_size;
+ maxlen = (dest->mtu - ether_size - ip_size) & ~0x7;
+ ip_off = ntohs(ip.ip_off);
+ origf = ip_off & ~IP_OFFMASK;
+ ip_off &= IP_OFFMASK;
+
+ while(todo) {
+ len = todo > maxlen ? maxlen : todo;
+ memcpy(DATA(&fragment) + ether_size + ip_size, offset, len);
+ todo -= len;
+ offset += len;
+
+ ip.ip_len = htons(ip_size + len);
+ ip.ip_off = htons(ip_off | origf | (todo ? IP_MF : 0));
+ ip.ip_sum = 0;
+ ip.ip_sum = inet_checksum(&ip, ip_size, ~0);
+ memcpy(DATA(&fragment), DATA(packet), ether_size);
+ memcpy(DATA(&fragment) + ether_size, &ip, ip_size);
+ fragment.len = ether_size + ip_size + len;
+
+ send_packet(dest, &fragment);
+
+ ip_off += len / 8;
+ }
+}
+
+static void route_ipv4(node_t *source, vpn_packet_t *packet) {
+ if(!checklength(source, packet, ether_size + ip_size))
+ return;
+
+ subnet_t *subnet;
+ node_t *via;
+ ipv4_t dest;
+
+ memcpy(&dest, &DATA(packet)[30], sizeof dest);
+ subnet = lookup_subnet_ipv4(&dest);
+
+ if(!subnet) {
+ logger(DEBUG_TRAFFIC, LOG_WARNING, "Cannot route packet from %s (%s): unknown IPv4 destination address %d.%d.%d.%d",