3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <net/packet.h>
28 #include <net/checksum.h>
33 #define DEFAULT_TUN6_ADDRESS NET_IPV4_TO_ADDR (216,66,80,30)
36 unsigned tun6_addr (net_ipv4 tun6
)
43 unsigned tun6_addr_get ()
48 unsigned net_proto_tun6_send (netif_t
*netif
, packet_t
*packet
, proto_ipv6_t
*ip
, char *buf
, unsigned len
)
50 char *buf_ip
= (char *) kmalloc ((len
+ 1 + sizeof (proto_ipv6_t
)));
55 unsigned l
= sizeof (proto_ipv6_t
);
57 /* put ip header and buf data to one buffer */
58 memcpy (buf_ip
, (char *) ip
, l
);
59 memcpy (buf_ip
+l
, buf
, len
);
64 packet
->type
= NET_PACKET_TYPE_IPV4
;
67 proto_ip_t
*ipv4
= (proto_ip_t
*) kmalloc (sizeof (proto_ip_t
));
72 /* there are some fixed values - yeah it is horrible */
80 ipv4
->proto
= NET_PROTO_IP_TYPE_TUN6
;
81 ipv4
->ip_source
= netif
->ip
;
82 ipv4
->ip_dest
= tun6_addr_get ();
84 /* calculate total length of packet (ipv6/ip) */
85 unsigned i
= ipv4
->head_len
* 4;
86 ipv4
->total_len
= swap16 (i
+l
+len
);
88 unsigned ret
= net_proto_ip_send (netif
, packet
, ipv4
, buf_ip
, l
+len
);
96 unsigned net_proto_tun6_handler (packet_t
*packet
, proto_ip_t
*ip
, char *buf
, unsigned len
)
98 proto_ipv6_t
*ipv6
= (proto_ipv6_t
*) buf
;
100 /* ipv6 provide directly length of data - payload length */
101 unsigned data_len
= swap16 (ipv6
->pl_len
);
103 //printf ("tun6 -> 0x%x\n", ipv6->nhead);
105 switch (ipv6
->nhead
) {
106 case NET_PROTO_IP_TYPE_TCP6
:
107 return net_proto_tcp6_handler (packet
, ipv6
, buf
+sizeof (proto_ipv6_t
), data_len
);
108 case NET_PROTO_IP_TYPE_UDP6
:
109 return net_proto_udp6_handler (packet
, ipv6
, buf
+sizeof (proto_ipv6_t
), data_len
);
110 case NET_PROTO_IP_TYPE_ICMP6
:
111 return net_proto_icmp6_handler (packet
, ipv6
, buf
+sizeof (proto_ipv6_t
), data_len
);
117 unsigned init_net_proto_tun6 ()