Also check for sha.h.
[tinc] / src / route.c
1 /*
2     route.c -- routing
3     Copyright (C) 2000 Ivo Timmermans <itimmermans@bigfoot.com>,
4                   2000 Guus Sliepen <guus@sliepen.warande.net>
5
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.
10
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.
15
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.
19
20     $Id: route.c,v 1.1.2.2 2000/11/04 22:57:33 guus Exp $
21 */
22
23 #include "config.h"
24
25 #include <utils.h>
26 #include <xalloc.h>
27
28 #include "net.h"
29 #include "connlist.h"
30
31 #include "system.h"
32
33 int routing_mode = 0;           /* Will be used to determine if we route by MAC or by payload's protocol */
34
35 conn_list_t *route_packet(vpn_packet_t *packet)
36 {
37   unsigned short type;
38 cp
39   type = ntohs(*((unsigned short*)(&packet.data[12])))
40
41   if(routing_mode)
42     {
43       return route_mac(packet);
44     }
45
46   switch(type)
47     {
48       case 0x0800:
49         return route_ipv4(packet);
50       case 0x86DD:
51         return route_ipv6(packet);
52 /*
53       case 0x8137:
54         return route_ipx(packet);
55       case 0x0806:
56         return route_arp(packet);
57 */
58       default:
59         if(debug_lvl >= DEBUG_TRAFFIC)
60           {
61             syslog(LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);
62           }
63         return NULL;
64      }
65 }
66
67 conn_list_t *route_mac(vpn_packet_t *packet)
68 {
69   conn_list_t *cl;
70 cp
71   cl = lookup_subnet_mac((mac_t *)(&packet.data[6]));
72   if(!cl)
73     if(debug_lvl >= DEBUG_TRAFFIC)
74       {
75         syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %x:%x:%x:%x:%x:%x"),
76                packet.data[6],
77                packet.data[7],
78                packet.data[8],
79                packet.data[9],
80                packet.data[10],
81                packet.data[11]);
82       } 
83 cp  
84   return cl;  
85 }
86
87
88 conn_list_t *route_ipv4(vpn_packet_t *packet)
89 {
90   ipv4_t dest;
91   conn_list_t *cl;
92 cp
93   dest = ntohl(*((unsigned long*)(&packet.data[30]);
94   
95   cl = lookup_subnet_ipv4(dest);
96   if(!cl)
97     if(debug_lvl >= DEBUG_TRAFFIC)
98       {
99         syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %d.%d.%d.%d"),
100                packet.data[30], packet.data[31], packet.data[32], packet.data[33]);
101       } 
102 cp
103   return cl;  
104 }
105
106 conn_list_t *route_ipv6(vpn_packet_t *packet)
107 {
108 cp
109   syslog(LOG_WARNING, _("Cannot route packet: IPv6 routing not implemented yet"));
110 cp
111   return NULL;
112 }