3 Copyright (C) 2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>,
4 2000,2001 Guus Sliepen <guus@sliepen.warande.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Id: route.c,v 1.1.2.9 2001/05/28 08:21:43 guus Exp $
26 #include <sys/param.h>
28 #include <netinet/in.h>
35 #include "connection.h"
41 int routing_mode = RMODE_ROUTER;
44 void learn_mac(connection_t *source, mac_t *address)
48 subnet = lookup_subnet_mac(address);
52 subnet = new_subnet();
53 subnet->type = SUBNET_MAC;
54 // subnet->lasttime = gettimeofday();
55 memcpy(&subnet->net.mac.address, address, sizeof(mac_t));
56 subnet_add(source, subnet);
58 if(debug_lvl >= DEBUG_TRAFFIC)
60 syslog(LOG_DEBUG, _("Learned new MAC address %x:%x:%x:%x:%x:%x from %s (%s)"),
67 source->name, source->hostname);
72 connection_t *route_mac(connection_t *source, vpn_packet_t *packet)
76 /* Learn source address */
78 learn_mac(source, (mac_t *)(&packet->data[0]));
80 /* Lookup destination address */
82 subnet = lookup_subnet_mac((mac_t *)(&packet->data[6]));
86 if(debug_lvl >= DEBUG_TRAFFIC)
88 syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %x:%x:%x:%x:%x:%x"),
102 connection_t *route_ipv4(vpn_packet_t *packet)
107 dest = ntohl(*((unsigned long*)(&packet->data[30])));
109 subnet = lookup_subnet_ipv4(&dest);
113 if(debug_lvl >= DEBUG_TRAFFIC)
115 syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %d.%d.%d.%d"),
116 packet->data[30], packet->data[31], packet->data[32], packet->data[33]);
122 return subnet->owner;
125 connection_t *route_ipv6(vpn_packet_t *packet)
128 if(debug_lvl > DEBUG_NOTHING)
130 syslog(LOG_WARNING, _("Cannot route packet: IPv6 routing not yet implemented"));
136 void route_outgoing(vpn_packet_t *packet)
138 unsigned short int type;
142 /* FIXME: multicast? */
147 type = ntohs(*((unsigned short*)(&packet->data[12])));
151 cl = route_ipv4(packet);
154 cl = route_ipv6(packet);
157 if(debug_lvl >= DEBUG_TRAFFIC)
159 syslog(LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);
164 send_packet(cl, packet);
168 cl = route_mac(myself, packet);
170 send_packet(cl, packet);
174 for(node = connection_tree->head; node; node = node->next)
176 cl = (connection_t *)node->data;
177 if(cl->status.active)
178 send_packet(cl, packet);
184 void route_incoming(connection_t *source, vpn_packet_t *packet)
189 memcpy(packet->data, mymac.net.mac.address.x, 6);
192 learn_mac(source, (mac_t *)(&packet->data[0]));
196 accept_packet(packet);