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.6 2001/01/07 17:09:06 guus Exp $
30 #include "connection.h"
36 int routing_mode = RMODE_ROUTER;
38 void learn_mac(connection_t *source, mac_t *address)
43 old = lookup_subnet_mac(address)->owner;
47 subnet = new_subnet();
48 subnet->type = SUBNET_MAC;
49 // subnet->lasttime = gettimeofday();
50 memcpy(&subnet->net.mac.address, address, sizeof(mac_t));
51 subnet_add(source, subnet);
53 if(DEBUG_LVL >= DEBUG_TRAFFIC)
55 syslog(LOG_DEBUG, _("Learned new MAC address %x:%x:%x:%x:%x:%x from %s (%s)"),
56 address->address.x[0],
57 address->address.x[1],
58 address->address.x[2],
59 address->address.x[3],
60 address->address.x[4],
61 address->address.x[5],
62 cl->name, cl->hostname);
67 connection_t *route_mac(connection_t *source, vpn_packet_t *packet)
69 connection_t *oldsrc, *dst;
72 /* Learn source address */
74 learn_mac(source, (mac_t *)(&packet->data[0]));
76 /* Lookup destination address */
78 dst = lookup_subnet_mac((mac_t *)(&packet->data[6]))->owner;
81 if(debug_lvl >= DEBUG_TRAFFIC)
83 syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %x:%x:%x:%x:%x:%x"),
95 connection_t *route_ipv4(vpn_packet_t *packet)
100 dest = ntohl(*((unsigned long*)(&packet->data[30])));
102 cl = lookup_subnet_ipv4(&dest)->owner;
104 if(debug_lvl >= DEBUG_TRAFFIC)
106 syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %d.%d.%d.%d"),
107 packet->data[30], packet->data[31], packet->data[32], packet->data[33]);
113 connection_t *route_ipv6(vpn_packet_t *packet)
116 if(debug_lvl > DEBUG_NOTHING)
118 syslog(LOG_WARNING, _("Cannot route packet: IPv6 routing not yet implemented"));
124 void route_outgoing(vpn_packet_t *packet)
126 unsigned short int type;
130 /* FIXME: multicast? */
135 type = ntohs(*((unsigned short*)(&packet->data[12])));
139 cl = route_ipv4(packet);
142 cl = route_ipv6(packet);
145 if(debug_lvl >= DEBUG_TRAFFIC)
147 syslog(LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);
151 send_packet(cl, packet);
155 cl = route_mac(packet);
157 send_packet(cl, packet);
161 for(node = connection_tree->head; node; node = node->next)
163 cl = (connection_t *)node->data;
164 if(cl->status.active)
165 send_packet(cl, packet);
171 void route_incoming(connection_t *source, vpn_packet_t *packet)
176 learn_mac(source, &packet->data[0]);
180 accept_packet(packet);