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.7 2001/03/04 13:59:32 guus Exp $
25 #include <netinet/in.h>
31 #include "connection.h"
37 int routing_mode = RMODE_ROUTER;
40 void learn_mac(connection_t *source, mac_t *address)
44 subnet = lookup_subnet_mac(address);
48 subnet = new_subnet();
49 subnet->type = SUBNET_MAC;
50 // subnet->lasttime = gettimeofday();
51 memcpy(&subnet->net.mac.address, address, sizeof(mac_t));
52 subnet_add(source, subnet);
54 if(debug_lvl >= DEBUG_TRAFFIC)
56 syslog(LOG_DEBUG, _("Learned new MAC address %x:%x:%x:%x:%x:%x from %s (%s)"),
63 source->name, source->hostname);
68 connection_t *route_mac(connection_t *source, vpn_packet_t *packet)
72 /* Learn source address */
74 learn_mac(source, (mac_t *)(&packet->data[0]));
76 /* Lookup destination address */
78 subnet = lookup_subnet_mac((mac_t *)(&packet->data[6]));
82 if(debug_lvl >= DEBUG_TRAFFIC)
84 syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %x:%x:%x:%x:%x:%x"),
98 connection_t *route_ipv4(vpn_packet_t *packet)
103 dest = ntohl(*((unsigned long*)(&packet->data[30])));
105 subnet = lookup_subnet_ipv4(&dest);
109 if(debug_lvl >= DEBUG_TRAFFIC)
111 syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %d.%d.%d.%d"),
112 packet->data[30], packet->data[31], packet->data[32], packet->data[33]);
118 return subnet->owner;
121 connection_t *route_ipv6(vpn_packet_t *packet)
124 if(debug_lvl > DEBUG_NOTHING)
126 syslog(LOG_WARNING, _("Cannot route packet: IPv6 routing not yet implemented"));
132 void route_outgoing(vpn_packet_t *packet)
134 unsigned short int type;
138 /* FIXME: multicast? */
143 type = ntohs(*((unsigned short*)(&packet->data[12])));
147 cl = route_ipv4(packet);
150 cl = route_ipv6(packet);
153 if(debug_lvl >= DEBUG_TRAFFIC)
155 syslog(LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);
160 send_packet(cl, packet);
164 cl = route_mac(myself, packet);
166 send_packet(cl, packet);
170 for(node = connection_tree->head; node; node = node->next)
172 cl = (connection_t *)node->data;
173 if(cl->status.active)
174 send_packet(cl, packet);
180 void route_incoming(connection_t *source, vpn_packet_t *packet)
185 learn_mac(source, (mac_t *)(&packet->data[0]));
188 memcpy(packet->data, mymac.net.mac.address.x, 6);
191 accept_packet(packet);