Commit a349e291 authored by Daniele Lacamera's avatar Daniele Lacamera

Experimental inclusion of ipv6 branch elements

parent faaf2011
......@@ -34,6 +34,10 @@ ZMQ?=1
OLSR?=1
SLAACV4?=1
#IPv6 related
IPV6?=0
ICMP6?=0
CFLAGS=-Iinclude -Imodules -Wall -Wdeclaration-after-statement -W -Wextra -Wshadow -Wcast-qual -Wwrite-strings -Wmissing-field-initializers $(EXTRA_CFLAGS)
# extra flags recommanded by TIOBE TICS framework to score an A on compiler warnings
CFLAGS+= -Wconversion
......@@ -186,6 +190,12 @@ endif
ifneq ($(SLAACV4),0)
include rules/slaacv4.mk
endif
ifneq ($(IPV6),0)
include rules/ipv6.mk
endif
ifneq ($(ICMP6),0)
include rules/icmp6.mk
endif
all: mod core lib
......
......@@ -115,6 +115,9 @@ static inline uint64_t long_long_be(uint64_t le)
/*** *** *** *** *** *** ***
*** ARP CONFIG ***
*** *** *** *** *** *** ***/
#include "pico_addressing.h"
/* Maximum amount of accepted ARP requests per burst interval */
#define PICO_ARP_MAX_RATE 1
/* Duration of the burst interval in milliseconds */
......
......@@ -9,6 +9,7 @@
#include "pico_frame.h"
#include "pico_addressing.h"
#include "pico_tree.h"
#include "pico_ipv6_nd.h"
#define MAX_DEVICE_NAME 16
......@@ -30,6 +31,9 @@ struct pico_device {
int __serving_interrupt;
/* used to signal the upper layer the number of events arrived since the last processing */
volatile int eventCnt;
#ifdef PICO_SUPPORT_IPV6
struct pico_nd_hostvars hostvars;
#endif
};
int pico_device_init(struct pico_device *dev, const char *name, uint8_t *mac);
......
......@@ -94,4 +94,18 @@ static inline int pico_is_digit(char c)
return 1;
}
static inline int pico_is_hex(char c)
{
if (c >= '0' && c <= '9')
return 1;
if (c >= 'a' && c <= 'f')
return 1;
if (c >= 'A' && c <= 'F')
return 1;
return 0;
}
#endif
......@@ -5,26 +5,96 @@
.
*********************************************************************/
#ifndef INCLUDE_PICO_IPV6
#define INCLUDE_PICO_IPV6
#ifndef _INCLUDE_PICO_IPV6
#define _INCLUDE_PICO_IPV6
#include "pico_addressing.h"
#include "pico_protocol.h"
#define PICO_SIZE_IP6HDR ((sizeof(struct pico_ipv6_hdr)))
#define PICO_IPV6_DEFAULT_HOP 64
#define PICO_IPV6_MIN_MTU 1280
extern const uint8_t PICO_IP6_ANY[PICO_SIZE_IP6];
extern struct pico_protocol pico_proto_ipv6;
extern const uint8_t PICO_IPV6_ANY[PICO_SIZE_IP6];
struct __attribute__((packed)) pico_ipv6_hdr {
uint32_t vtf;
uint16_t len;
uint8_t nxthdr;
uint8_t hop;
struct pico_ip6 src;
struct pico_ip6 dst;
uint8_t extensions[0];
};
struct __attribute__((packed)) pico_ipv6_pseudo_hdr
{
struct pico_ip6 src;
struct pico_ip6 dst;
uint32_t len;
uint8_t zero[3];
uint8_t nxthdr;
};
struct pico_ipv6_link
{
struct pico_device *dev;
struct pico_ip6 address;
struct pico_ip6 netmask;
uint8_t istentative : 1;
uint8_t isduplicate : 1;
};
struct __attribute__((packed)) pico_ipv6_exthdr {
uint8_t nxthdr;
union {
struct {
uint8_t len;
uint8_t options[0];
} hopbyhop;
struct {
uint8_t len;
uint8_t options[0];
} destopt;
/* This module is responsible for routing outgoing packets and
* delivering incoming packets to other layers
*/
struct {
uint8_t len;
uint8_t routtype;
uint8_t segleft;
} routing;
/* Interface for processing incoming ipv6 packets (decap/deliver) */
int pico_ipv6_process_in(struct pico_frame *f);
struct {
uint8_t res;
uint8_t frm[2];
uint8_t id[4];
} fragm;
} ext;
};
/* Interface for processing outgoing ipv6 frames (encap/push) */
int pico_ipv6_process_out(struct pico_frame *f);
int pico_string_to_ipv6(const char *ipstr, uint8_t *ip);
int pico_ipv6_to_string(char *ipbuf, const uint8_t ip[PICO_SIZE_IP6]);
int pico_ipv6_is_unicast(const uint8_t addr[PICO_SIZE_IP6]);
int pico_ipv6_is_multicast(const uint8_t addr[PICO_SIZE_IP6]);
int pico_ipv6_is_global(const uint8_t addr[PICO_SIZE_IP6]);
int pico_ipv6_is_uniquelocal(const uint8_t addr[PICO_SIZE_IP6]);
int pico_ipv6_is_sitelocal(const uint8_t addr[PICO_SIZE_IP6]);
int pico_ipv6_is_linklocal(const uint8_t addr[PICO_SIZE_IP6]);
int pico_ipv6_is_solicited(const uint8_t addr[PICO_SIZE_IP6]);
int pico_ipv6_is_unspecified(const uint8_t addr[PICO_SIZE_IP6]);
/* Return estimated overhead for ipv6 frames to define allocation */
int pico_ipv6_overhead(struct pico_frame *f);
int pico_ipv6_frame_push(struct pico_frame *f, struct pico_ip6 *dst, uint8_t proto);
int pico_ipv6_rebound(struct pico_frame *f);
int pico_ipv6_route_add(struct pico_ip6 address, struct pico_ip6 netmask, struct pico_ip6 gateway, int metric, struct pico_ipv6_link *link);
void pico_ipv6_unreachable(struct pico_frame *f, uint8_t code);
int pico_ipv6_link_add(struct pico_device *dev, struct pico_ip6 address, struct pico_ip6 netmask);
int pico_ipv6_link_del(struct pico_device *dev, struct pico_ip6 address);
int pico_ipv6_cleanup_links(struct pico_device *dev);
struct pico_ipv6_link *pico_ipv6_link_istentative(struct pico_ip6 *address);
struct pico_ipv6_link *pico_ipv6_link_get(struct pico_ip6 *address);
struct pico_device *pico_ipv6_link_find(struct pico_ip6 *address);
struct pico_ip6 pico_ipv6_route_get_gateway(struct pico_ip6 *addr);
struct pico_ip6 *pico_ipv6_source_find(const struct pico_ip6 *dst);
#endif
#include <stdint.h>
#include "pico_socket.h"
#include "pico_ipv4.h"
#include "pico_ipv6.h"
#include "pico_tcp.h"
int pico_getsockopt_tcp(struct pico_socket *s, int option, void *value)
......@@ -104,16 +105,23 @@ int pico_socket_tcp_deliver(struct pico_sockport *sp, struct pico_frame *f)
#endif
#ifdef PICO_SUPPORT_IPV6
if (IS_IPV6(f)) {
struct pico_ipv6_hdr *ip6hdr = (struct pico_ipv6_hdr*)(f->net_hdr);
if ((s->remote_port == localport)) {
struct pico_ip6 s_local = {{0}}, s_remote = {{0}}, p_src = {{0}}, p_dst = {{0}};
struct pico_ipv6_hdr *ip6hdr = (struct pico_ipv6_hdr *)(f->net_hdr);
s_local = s->local_addr.ip6;
s_remote = s->remote_addr.ip6;
p_src = ip6hdr->src;
p_dst = ip6hdr->dst;
if ((s->remote_port == tr->sport) &&
(!memcmp(s_remote.addr, p_src.addr, PICO_SIZE_IP6)) &&
((!memcmp(s_local.addr, PICO_IP6_ANY, PICO_SIZE_IP6)) || (!memcmp(s_local.addr, p_dst.addr, PICO_SIZE_IP6)))) {
found = s;
break;
} else if (s->remote_port == 0) {
} else if ((s->remote_port == 0) && /* not connected... listening */
((!memcmp(s_local.addr, PICO_IP6_ANY, PICO_SIZE_IP6)) || (!memcmp(s_local.addr, p_dst.addr, PICO_SIZE_IP6)))) {
/* listen socket */
found = s;
}
}
#endif
} /* FOREACH */
if (found != NULL) {
......
......@@ -92,7 +92,7 @@ static int32_t socket_cmp_ipv6(struct pico_socket *a, struct pico_socket *b)
(void)a;
(void)b;
#ifdef PICO_SUPPORT_IPV6
if ((memcmp(a->local_addr.ip6.addr, PICO_IP6_ANY, PICO_SIZE_IP6) == 0) || memcmp((b->local_addr.ip6.addr, PICO_IP6_ANY, PICO_SIZE_IP6) == 0))
if ((memcmp(a->local_addr.ip6.addr, PICO_IP6_ANY, PICO_SIZE_IP6) == 0) || (memcmp(b->local_addr.ip6.addr, PICO_IP6_ANY, PICO_SIZE_IP6) == 0))
ret = 0;
else
ret = memcmp(a->local_addr.ip6.addr, b->local_addr.ip6.addr, PICO_SIZE_IP6);
......@@ -874,7 +874,7 @@ static struct pico_remote_endpoint *pico_socket_sendto_destination_ipv6(struct p
return NULL;
}
memcpy(ep->remote_addr.ip6, dst, sizeof(struct pico_ip6));
memcpy(&ep->remote_addr.ip6, dst, sizeof(struct pico_ip6));
ep->remote_port = port;
#endif
return ep;
......
......@@ -21,6 +21,7 @@
#include "pico_ipv4.h"
#include "pico_ipv6.h"
#include "pico_icmp4.h"
#include "pico_icmp6.h"
#include "pico_igmp.h"
#include "pico_udp.h"
#include "pico_tcp.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment