pico_ipv6.h 6.63 KB
Newer Older
1
/*********************************************************************
2 3
   PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
   See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
4

5
   .
6

7
 *********************************************************************/
8 9
#ifndef _INCLUDE_PICO_IPV6
#define _INCLUDE_PICO_IPV6
10 11
#include "pico_addressing.h"
#include "pico_protocol.h"
roel0's avatar
roel0 committed
12
#include "pico_ipv4.h"
13

14
#define PICO_SIZE_IP6HDR ((uint32_t)(sizeof(struct pico_ipv6_hdr)))
15 16
#define PICO_IPV6_DEFAULT_HOP 64
#define PICO_IPV6_MIN_MTU 1280
roel0's avatar
roel0 committed
17
#define PICO_IPV6_STRING 46
18 19 20 21 22 23 24 25 26

#define PICO_IPV6_EXTHDR_HOPBYHOP 0
#define PICO_IPV6_EXTHDR_ROUTING 43
#define PICO_IPV6_EXTHDR_FRAG 44
#define PICO_IPV6_EXTHDR_ESP 50
#define PICO_IPV6_EXTHDR_AUTH 51
#define PICO_IPV6_EXTHDR_NONE 59
#define PICO_IPV6_EXTHDR_DESTOPT 60

27 28
#define PICO_IPV6_EXTHDR_FRAG_SIZE 8

roel0's avatar
roel0 committed
29
#define PICO_IPV6_EXTHDR_OPT_ROUTER_ALERT 5
roel0's avatar
roel0 committed
30
#define PICO_IPV6_EXTHDR_OPT_ROUTER_ALERT_DATALEN 2
31

roel0's avatar
roel0 committed
32
#define HBH_LEN(hbh) ((((hbh->ext.hopbyhop.len + 1) << 3) - 2)) /* len in bytes, minus nxthdr and len byte */
33
#define IPV6_OPTLEN(x) ((uint16_t)(((x + 1) << 3)))
34

35
extern const uint8_t PICO_IP6_ANY[PICO_SIZE_IP6];
36
extern struct pico_protocol pico_proto_ipv6;
37
extern struct pico_tree IPV6Routes;
38

39
PACKED_STRUCT_DEF pico_ipv6_hdr {
40 41 42 43 44 45 46 47
    uint32_t vtf;
    uint16_t len;
    uint8_t nxthdr;
    uint8_t hop;
    struct pico_ip6 src;
    struct pico_ip6 dst;
};

48
PACKED_STRUCT_DEF pico_ipv6_pseudo_hdr
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
{
    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;
64
    uint8_t rs_retries;
65
    uint32_t dad_timer;
66
    uint16_t dup_detect_retrans;
67
    uint8_t retrans;
68
    pico_time expire_time;
69
    pico_time rs_expire_time;
roel0's avatar
roel0 committed
70 71 72 73 74
#ifdef PICO_SUPPORT_MCAST
    struct pico_tree *MCASTGroups;
    uint8_t mcast_compatibility;
    uint8_t mcast_last_query_interval;
#endif
75
    uint32_t mtu;
76
};
77

roel0's avatar
roel0 committed
78 79 80
union pico_link {
    struct pico_ipv4_link ipv4;
    struct pico_ipv6_link ipv6;
81 82
};

83 84 85 86
struct pico_ipv6_hbhoption {
    uint8_t type;
    uint8_t len;
};
roel0's avatar
roel0 committed
87 88 89 90 91 92 93 94
#ifdef PICO_SUPPORT_MCAST
struct pico_ipv6_mcast_group {
    uint8_t filter_mode;
    uint16_t reference_count;
    struct pico_ip6 mcast_addr;
    struct pico_tree MCASTSources;
};
#endif
95 96 97 98 99 100 101 102 103 104
struct pico_ipv6_destoption {
    uint8_t type;
    uint8_t len;
};

struct pico_ipv6_route
{
    struct pico_ip6 dest;
    struct pico_ip6 netmask;
    struct pico_ip6 gateway;
105 106
    pico_time backoff;
    uint8_t retrans;
107 108 109 110
    struct pico_ipv6_link *link;
    uint32_t metric;
};

111
PACKED_STRUCT_DEF pico_ipv6_exthdr {
112 113
    uint8_t nxthdr;

114
    PACKED_UNION_DEF ipv6_ext_u {
115
        PEDANTIC_STRUCT_DEF hopbyhop_s {
116 117 118
            uint8_t len;
        } hopbyhop;

119
        PEDANTIC_STRUCT_DEF destopt_s {
120 121
            uint8_t len;
        } destopt;
122

123
        PEDANTIC_STRUCT_DEF routing_s {
124 125 126 127
            uint8_t len;
            uint8_t routtype;
            uint8_t segleft;
        } routing;
128

129
        PEDANTIC_STRUCT_DEF fragmentation_s {
130
            uint8_t res;
131
            uint8_t om[2];
132
            uint8_t id[4];
133
        } frag;
134 135
    } ext;
};
136

137
int pico_ipv6_compare(const struct pico_ip6 *a, const struct pico_ip6 *b);
138 139
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]);
140
int pico_ipv6_is_unicast(struct pico_ip6 *a);
141
int pico_ipv6_is_multicast(const uint8_t addr[PICO_SIZE_IP6]);
142
int pico_ipv6_is_allhosts_multicast(const uint8_t addr[PICO_SIZE_IP6]);
143
int pico_ipv6_is_solnode_multicast(const uint8_t addr[PICO_SIZE_IP6], struct pico_device *dev);
144 145 146 147 148 149
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]);
150
int pico_ipv6_is_localhost(const uint8_t addr[PICO_SIZE_IP6]);
151

152
int pico_ipv6_frame_push(struct pico_frame *f, struct pico_ip6 *src, struct pico_ip6 *dst, uint8_t proto, int is_dad);
153
int pico_ipv6_route_add(struct pico_ip6 address, struct pico_ip6 netmask, struct pico_ip6 gateway, int metric, struct pico_ipv6_link *link);
154
int pico_ipv6_route_del(struct pico_ip6 address, struct pico_ip6 netmask, struct pico_ip6 gateway, int metric, struct pico_ipv6_link *link);
155
void pico_ipv6_unreachable(struct pico_frame *f, uint8_t code);
156

157
struct pico_ipv6_link *pico_ipv6_link_add(struct pico_device *dev, struct pico_ip6 address, struct pico_ip6 netmask);
158
struct pico_ipv6_link *pico_ipv6_link_add_no_dad(struct pico_device *dev, struct pico_ip6 address, struct pico_ip6 netmask);
159 160 161 162 163 164 165
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);
166
struct pico_device *pico_ipv6_source_dev_find(const struct pico_ip6 *dst);
167
struct pico_ipv6_link *pico_ipv6_link_by_dev(struct pico_device *dev);
168
struct pico_ipv6_link *pico_ipv6_link_by_dev_next(struct pico_device *dev, struct pico_ipv6_link *last);
169 170
struct pico_ipv6_link *pico_ipv6_global_get(struct pico_device *dev);
struct pico_ipv6_link *pico_ipv6_linklocal_get(struct pico_device *dev);
171
struct pico_ipv6_link *pico_ipv6_sitelocal_get(struct pico_device *dev);
172
struct pico_ipv6_link *pico_ipv6_prefix_configured(struct pico_ip6 *prefix);
173 174
struct pico_ipv6_route *pico_ipv6_gateway_by_dev(struct pico_device *dev);
struct pico_ipv6_route *pico_ipv6_gateway_by_dev_next(struct pico_device *dev, struct pico_ipv6_route *last);
175
int pico_ipv6_lifetime_set(struct pico_ipv6_link *l, pico_time expire);
176 177
int pico_ipv6_dev_routing_enable(struct pico_device *dev);
int pico_ipv6_dev_routing_disable(struct pico_device *dev);
178
void pico_ipv6_router_down(const struct pico_ip6 *address);
roel0's avatar
roel0 committed
179 180 181 182 183 184

int pico_ipv6_mcast_join(struct pico_ip6 *mcast_link, struct pico_ip6 *mcast_group, uint8_t reference_count, uint8_t filter_mode, struct pico_tree *_MCASTFilter);
int pico_ipv6_mcast_leave(struct pico_ip6 *mcast_link, struct pico_ip6 *mcast_group, uint8_t reference_count, uint8_t filter_mode, struct pico_tree *_MCASTFilter);

struct pico_ipv6_link *pico_ipv6_get_default_mcastlink(void);

185
int pico_ipv6_is_null_address(struct pico_ip6 *ip6);
186
#endif