diff --git a/src/ipv6.c b/src/ipv6.c index e2ae27e..4a84a1e 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -1,6 +1,6 @@ /* * WrapSix - * Copyright (C) 2008-2010 Michal Zima + * Copyright (C) 2008-2012 Michal Zima * * 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 . */ +#include /* IPPROTO_* */ #include -#include /* memcpy */ +#include /* 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; } diff --git a/src/ipv6.h b/src/ipv6.h index 27e3903..273f07b 100644 --- a/src/ipv6.h +++ b/src/ipv6.h @@ -1,6 +1,6 @@ /* * WrapSix - * Copyright (C) 2008-2011 Michal Zima + * Copyright (C) 2008-2012 Michal Zima * * 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 */