1
0
mirror of https://code.semirocket.science/wrapsix synced 2024-09-19 23:11:04 +03:00
wrapsix/src/ipv6.c

83 lines
2.2 KiB
C
Raw Normal View History

2010-02-06 12:31:29 +02:00
/*
* WrapSix
* Copyright (C) 2008-2017 xHire <xhire@wrapsix.org>
2010-02-06 12:31:29 +02:00
*
* This program is free software: you can redistribute it and/or modify
2012-07-04 20:04:42 +03:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
2010-02-06 12:31:29 +02:00
*
* 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
2012-07-04 20:04:42 +03:00
* GNU General Public License for more details.
2010-02-06 12:31:29 +02:00
*
2012-07-04 20:04:42 +03:00
* You should have received a copy of the GNU General Public License
2010-02-06 12:31:29 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <netinet/in.h> /* IPPROTO_* */
#include <string.h> /* memcmp */
2010-02-06 12:31:29 +02:00
#include "icmp.h"
2010-02-06 12:31:29 +02:00
#include "ipv6.h"
#include "log.h"
2012-04-07 12:49:26 +03:00
#include "tcp.h"
2012-04-06 18:02:40 +03:00
#include "udp.h"
#include "wrapper.h"
2010-02-06 12:31:29 +02:00
2012-07-03 12:15:10 +03:00
/**
* Processing of IPv6 packets.
*
* @param eth Ethernet header
* @param packet Packet data
*
* @return 0 for success
* @return 1 for failure
*/
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 */
ip = (struct s_ipv6 *) packet;
2010-02-06 12:31:29 +02:00
payload = packet + sizeof(struct s_ipv6);
/* 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) {
return 1;
}
2013-02-14 15:26:01 +02:00
/* check and decrease hop limit */
if (ip->hop_limit <= 1) {
/* deny this error for error ICMP messages */
if (ip->next_header != IPPROTO_ICMPV6 || payload[0] & 0x80) {
/* code 0 = hl exceeded in transmit */
icmp6_error(eth->src, ip->ip_src, ICMPV6_TIME_EXCEEDED,
0, packet,
2013-02-14 15:26:01 +02:00
htons(ip->len) + sizeof(struct s_ipv6));
}
return 1;
} else {
ip->hop_limit--;
}
switch (ip->next_header) {
case IPPROTO_TCP:
log_debug("IPv6 Protocol: TCP");
2012-07-03 12:15:10 +03:00
return tcp_ipv6(eth, ip, payload);
case IPPROTO_UDP:
log_debug("IPv6 Protocol: UDP");
2012-07-03 12:15:10 +03:00
return udp_ipv6(eth, ip, payload);
case IPPROTO_ICMPV6:
log_debug("IPv6 Protocol: ICMP");
2012-07-03 12:15:10 +03:00
return icmp_ipv6(eth, ip, payload);
default:
log_debug("IPv6 Protocol: unknown [%d/0x%x]",
ip->next_header, ip->next_header);
return 1;
}
2010-02-06 12:31:29 +02:00
}