2010-02-06 12:31:29 +02:00
|
|
|
/*
|
|
|
|
* WrapSix
|
2012-03-31 12:27:18 +03:00
|
|
|
* Copyright (C) 2008-2012 Michal Zima <xhire@mujmalysvet.cz>
|
2010-02-06 12:31:29 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-03-31 12:27:18 +03:00
|
|
|
#include <netinet/in.h> /* IPPROTO_* */
|
2010-02-06 12:31:29 +02:00
|
|
|
#include <stdio.h>
|
2012-03-31 12:27:18 +03:00
|
|
|
#include <string.h> /* memcmp */
|
2010-02-06 12:31:29 +02:00
|
|
|
|
2012-04-02 14:44:14 +03:00
|
|
|
#include "icmp.h"
|
2010-02-06 12:31:29 +02:00
|
|
|
#include "ipv6.h"
|
2012-04-06 18:02:40 +03:00
|
|
|
#include "udp.h"
|
2012-03-31 12:27:18 +03:00
|
|
|
#include "wrapper.h"
|
2010-02-06 12:31:29 +02:00
|
|
|
|
|
|
|
int ipv6(struct s_ethernet *eth, char *packet)
|
|
|
|
{
|
|
|
|
struct s_ipv6 *ip;
|
|
|
|
char *payload;
|
|
|
|
|
|
|
|
/* load data into structures */
|
2012-03-31 12:27:18 +03:00
|
|
|
ip = (struct s_ipv6 *) packet;
|
2010-02-06 12:31:29 +02:00
|
|
|
payload = packet + sizeof(struct s_ipv6);
|
|
|
|
|
2012-03-31 12:27:18 +03:00
|
|
|
/* test if this packet belongs to us */
|
2010-02-06 12:31:29 +02:00
|
|
|
if (memcmp(&wrapsix_ipv6_prefix, &ip->ip_dest, 12) != 0 &&
|
|
|
|
memcmp(&ndp_multicast_addr, &ip->ip_dest, 13) != 0) {
|
2012-04-02 14:44:14 +03:00
|
|
|
printf("[Debug] [IPv6] This is unfamiliar packet\n");
|
2010-02-06 12:31:29 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-03-31 12:27:18 +03:00
|
|
|
switch (ip->next_header) {
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
printf("[Debug] IPv6 Protocol: TCP\n");
|
|
|
|
/*ipv6_tcp(eth, ip, payload);*/
|
|
|
|
break;
|
|
|
|
case IPPROTO_UDP:
|
|
|
|
printf("[Debug] IPv6 Protocol: UDP\n");
|
2012-04-06 18:02:40 +03:00
|
|
|
udp_ipv6(eth, ip, payload);
|
2012-03-31 12:27:18 +03:00
|
|
|
break;
|
|
|
|
case IPPROTO_ICMPV6:
|
|
|
|
printf("[Debug] IPv6 Protocol: ICMP\n");
|
2012-04-02 14:44:14 +03:00
|
|
|
icmp_ipv6(eth, ip, payload);
|
2012-03-31 12:27:18 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("[Debug] IPv6 Protocol: unknown [%d/0x%x]\n",
|
|
|
|
ip->next_header, ip->next_header);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-02-06 12:31:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|