3 Copyright (C) 2000 Ivo Timmermans <itimmermans@bigfoot.com>,
4 2000 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.4 2001/01/05 23:53:53 guus Exp $
30 #include "connection.h"
36 int routing_mode = RMODE_ROUTER; /* Will be used to determine if we route by MAC or by payload's protocol */
38 connection_t *route_mac(connection_t *source, vpn_packet_t *packet)
40 connection_t *oldsrc, *dst;
43 /* Learn source address */
45 oldsrc = lookup_subnet_mac((mac_t *)(&packet->data[0]))->owner;
49 subnet = new_subnet();
50 subnet->type = SUBNET_MAC;
51 memcpy(&subnet->net.mac.address, (mac_t *)(&packet->data[0]), sizeof(mac_t));
52 subnet_add(source, subnet);
55 /* FIXME: do ageing and roaming */
57 /* Lookup destination address */
59 dst = lookup_subnet_mac((mac_t *)(&packet->data[6]))->owner;
62 if(debug_lvl >= DEBUG_TRAFFIC)
64 syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %x:%x:%x:%x:%x:%x"),
76 connection_t *route_ipv4(vpn_packet_t *packet)
81 dest = ntohl(*((unsigned long*)(&packet->data[30])));
83 cl = lookup_subnet_ipv4(&dest)->owner;
85 if(debug_lvl >= DEBUG_TRAFFIC)
87 syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %d.%d.%d.%d"),
88 packet->data[30], packet->data[31], packet->data[32], packet->data[33]);
94 connection_t *route_ipv6(vpn_packet_t *packet)
97 if(debug_lvl > DEBUG_NOTHING)
99 syslog(LOG_WARNING, _("Cannot route packet: IPv6 routing not implemented yet"));
105 connection_t *route_packet(connection_t *source, vpn_packet_t *packet)
107 unsigned short int type;
109 /* FIXME: multicast? */
117 return route_mac(source, packet);
120 type = ntohs(*((unsigned short*)(&packet->data[12])));
124 return route_ipv4(packet);
126 return route_ipv6(packet);
129 return route_ipx(packet);
131 return route_arp(packet);
134 if(debug_lvl >= DEBUG_TRAFFIC)
136 syslog(LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);