mirror of
https://code.semirocket.science/wrapsix
synced 2024-11-21 13:31:02 +02:00
Basic preprocessing of IPv6 packets; pseudoheader
This commit is contained in:
parent
94cbbb5c53
commit
d44253f5ed
29
src/ipv6.c
29
src/ipv6.c
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* WrapSix
|
||||
* Copyright (C) 2008-2010 Michal Zima <xhire@mujmalysvet.cz>
|
||||
* Copyright (C) 2008-2012 Michal Zima <xhire@mujmalysvet.cz>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@ -16,11 +16,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <netinet/in.h> /* IPPROTO_* */
|
||||
#include <stdio.h>
|
||||
#include <string.h> /* memcpy */
|
||||
#include <string.h> /* memcmp */
|
||||
|
||||
#include "wrapper.h"
|
||||
#include "ipv6.h"
|
||||
#include "wrapper.h"
|
||||
|
||||
int ipv6(struct s_ethernet *eth, char *packet)
|
||||
{
|
||||
@ -28,14 +29,34 @@ int ipv6(struct s_ethernet *eth, char *packet)
|
||||
char *payload;
|
||||
|
||||
/* load data into structures */
|
||||
ip = (struct s_ipv6*) packet;
|
||||
ip = (struct s_ipv6 *) packet;
|
||||
payload = packet + sizeof(struct s_ipv6);
|
||||
|
||||
/* test if this packet belongs to us */
|
||||
if (memcmp(&wrapsix_ipv6_prefix, &ip->ip_dest, 12) != 0 &&
|
||||
memcmp(&ndp_multicast_addr, &ip->ip_dest, 13) != 0) {
|
||||
printf("[Debug] This is unfamiliar packet\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
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");
|
||||
/*ipv6_udp(eth, ip, payload);*/
|
||||
break;
|
||||
case IPPROTO_ICMPV6:
|
||||
printf("[Debug] IPv6 Protocol: ICMP\n");
|
||||
/*ipv6_icmp(eth, ip, payload);*/
|
||||
break;
|
||||
default:
|
||||
printf("[Debug] IPv6 Protocol: unknown [%d/0x%x]\n",
|
||||
ip->next_header, ip->next_header);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
28
src/ipv6.h
28
src/ipv6.h
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* WrapSix
|
||||
* Copyright (C) 2008-2011 Michal Zima <xhire@mujmalysvet.cz>
|
||||
* Copyright (C) 2008-2012 Michal Zima <xhire@mujmalysvet.cz>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@ -28,16 +28,26 @@ struct s_ipv6_addr {
|
||||
|
||||
/* IPv6 header structure */
|
||||
struct s_ipv6 {
|
||||
unsigned char ver; /* 8 b; version */
|
||||
unsigned char traffic_class; /* 8 b; traffic class */
|
||||
unsigned short flow_label; /* 16 b; flow label (qos) */
|
||||
unsigned short len; /* 16 b; payload length */
|
||||
unsigned char next_header; /* 8 b; next header */
|
||||
unsigned char hop_limit; /* 8 b; hop limit (replaces ttl) */
|
||||
struct s_ipv6_addr ip_src; /* 128 b; source address */
|
||||
struct s_ipv6_addr ip_dest; /* 128 b; destination address */
|
||||
unsigned char ver; /* 4 b; version */
|
||||
unsigned char traffic_class; /* 8 b; traffic class */
|
||||
unsigned short flow_label; /* 20 b; flow label (qos) */
|
||||
unsigned short len; /* 16 b; payload length */
|
||||
unsigned char next_header; /* 8 b; next header */
|
||||
unsigned char hop_limit; /* 8 b; hop limit (replaces ttl) */
|
||||
struct s_ipv6_addr ip_src; /* 128 b; source address */
|
||||
struct s_ipv6_addr ip_dest; /* 128 b; destination address */
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/* IPv6 pseudoheader structure for checksum */
|
||||
struct s_ipv6_pseudo {
|
||||
struct s_ipv6_addr ip_src; /* 128 b; source address */
|
||||
struct s_ipv6_addr ip_dest; /* 128 b; destination address */
|
||||
unsigned int len; /* 32 b; payload length */
|
||||
unsigned int zeros:24; /* 24 b; reserved */
|
||||
unsigned char next_header; /* 8 b; next header */
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
|
||||
int ipv6(struct s_ethernet *eth, char *packet);
|
||||
|
||||
#endif /* IPV6_H */
|
||||
|
Loading…
Reference in New Issue
Block a user