pico_icmp6.h 7.97 KB
Newer Older
1
/*********************************************************************
2
   PicoTCP. Copyright (c) 2012-2015 Altran Intelligent Systems. Some rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
   See LICENSE and COPYING for usage.

   .

 *********************************************************************/
#ifndef _INCLUDE_PICO_ICMP6
#define _INCLUDE_PICO_ICMP6
#include "pico_addressing.h"
#include "pico_protocol.h"

/* ICMP header sizes */
#define PICO_ICMP6HDR_DRY_SIZE          4
#define PICO_ICMP6HDR_ECHO_REQUEST_SIZE 8
#define PICO_ICMP6HDR_DEST_UNREACH_SIZE 8
#define PICO_ICMP6HDR_TIME_XCEEDED_SIZE 8
18
#define PICO_ICMP6HDR_PARAM_PROBLEM_SIZE 8
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#define PICO_ICMP6HDR_NEIGH_SOL_SIZE    24
#define PICO_ICMP6HDR_NEIGH_ADV_SIZE    24
#define PICO_ICMP6HDR_ROUTER_SOL_SIZE   8
#define PICO_ICMP6HDR_ROUTER_ADV_SIZE   16
#define PICO_ICMP6HDR_REDIRECT_SIZE     40

/* ICMP types */
#define PICO_ICMP6_DEST_UNREACH        1
#define PICO_ICMP6_PKT_TOO_BIG         2
#define PICO_ICMP6_TIME_EXCEEDED       3
#define PICO_ICMP6_PARAM_PROBLEM       4
#define PICO_ICMP6_ECHO_REQUEST        128
#define PICO_ICMP6_ECHO_REPLY          129
#define PICO_ICMP6_ROUTER_SOL          133
#define PICO_ICMP6_ROUTER_ADV          134
#define PICO_ICMP6_NEIGH_SOL           135
#define PICO_ICMP6_NEIGH_ADV           136
#define PICO_ICMP6_REDIRECT            137

/* destination unreachable codes */
#define PICO_ICMP6_UNREACH_NOROUTE     0
#define PICO_ICMP6_UNREACH_ADMIN       1
#define PICO_ICMP6_UNREACH_SRCSCOPE    2
#define PICO_ICMP6_UNREACH_ADDR        3
#define PICO_ICMP6_UNREACH_PORT        4
#define PICO_ICMP6_UNREACH_SRCFILTER   5
#define PICO_ICMP6_UNREACH_REJROUTE    6

/* time exceeded codes */
#define PICO_ICMP6_TIMXCEED_INTRANS    0
#define PICO_ICMP6_TIMXCEED_REASS      1

/* parameter problem codes */
#define PICO_ICMP6_PARAMPROB_HDRFIELD  0
#define PICO_ICMP6_PARAMPROB_NXTHDR    1
#define PICO_ICMP6_PARAMPROB_IPV6OPT   2

/* ping error codes */
#define PICO_PING6_ERR_REPLIED         0
#define PICO_PING6_ERR_TIMEOUT         1
#define PICO_PING6_ERR_UNREACH         2
60
#define PICO_PING6_ERR_ABORTED         3
61 62
#define PICO_PING6_ERR_PENDING         0xFFFF

63
/* ND configuration */
64
#define PICO_ND_MAX_FRAMES_QUEUED      4 /* max frames queued while awaiting address resolution */
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

/* ND RFC constants */
#define PICO_ND_MAX_SOLICIT            3
#define PICO_ND_MAX_NEIGHBOR_ADVERT    3
#define PICO_ND_DELAY_INCOMPLETE       1000 /* msec */
#define PICO_ND_DELAY_FIRST_PROBE_TIME 5000 /* msec */

/* neighbor discovery options */
#define PICO_ND_OPT_LLADDR_SRC         1
#define PICO_ND_OPT_LLADDR_TGT         2
#define PICO_ND_OPT_PREFIX             3
#define PICO_ND_OPT_REDIRECT           4
#define PICO_ND_OPT_MTU                5
#define PICO_ND_OPT_RDNSS             25 /* RFC 5006 */

/* ND advertisement flags */
#define PICO_ND_ROUTER             0x80000000
#define PICO_ND_SOLICITED          0x40000000
#define PICO_ND_OVERRIDE           0x20000000
#define IS_ROUTER(x) (long_be(x->msg.info.neigh_adv.rsor) & (PICO_ND_ROUTER))           /* router flag set? */
#define IS_SOLICITED(x) (long_be(x->msg.info.neigh_adv.rsor) & (PICO_ND_SOLICITED))     /* solicited flag set? */
#define IS_OVERRIDE(x) (long_be(x->msg.info.neigh_adv.rsor) & (PICO_ND_OVERRIDE))   /* override flag set? */

#define PICO_ND_PREFIX_LIFETIME_INF    0xFFFFFFFFu
Daniele Lacamera's avatar
Daniele Lacamera committed
89
/* #define PICO_ND_DESTINATION_LRU_TIME   600000u / * msecs (10min) * / */
90

91 92 93 94 95 96 97 98 99
/* custom defines */
#define PICO_ICMP6_ND_UNICAST          0
#define PICO_ICMP6_ND_ANYCAST          1
#define PICO_ICMP6_ND_SOLICITED        2
#define PICO_ICMP6_ND_DAD              3

#define PICO_ICMP6_MAX_RTR_SOL_DELAY   1000

#define PICO_SIZE_ICMP6HDR ((sizeof(struct pico_icmp6_hdr)))
100
#define PICO_ICMP6_OPT_LLADDR_SIZE (8)
101 102 103

extern struct pico_protocol pico_proto_icmp6;

104
PACKED_STRUCT_DEF pico_icmp6_hdr {
105 106 107 108
    uint8_t type;
    uint8_t code;
    uint16_t crc;

109
    PACKED_UNION_DEF icmp6_msg_u {
110
        /* error messages */
111
        PACKED_UNION_DEF icmp6_err_u {
112
            PEDANTIC_STRUCT_DEF dest_unreach_s {
113 114 115
                uint32_t unused;
                uint8_t data[0];
            } dest_unreach;
116
            PEDANTIC_STRUCT_DEF pkt_too_big_s {
117 118 119
                uint32_t mtu;
                uint8_t data[0];
            } pkt_too_big;
120
            PEDANTIC_STRUCT_DEF time_exceeded_s {
121 122 123
                uint32_t unused;
                uint8_t data[0];
            } time_exceeded;
124
            PEDANTIC_STRUCT_DEF param_problem_s {
125 126 127 128 129 130
                uint32_t ptr;
                uint8_t data[0];
            } param_problem;
        } err;

        /* informational messages */
131
        PACKED_UNION_DEF icmp6_info_u {
132
            PEDANTIC_STRUCT_DEF echo_request_s {
133 134 135 136
                uint16_t id;
                uint16_t seq;
                uint8_t data[0];
            } echo_request;
137
            PEDANTIC_STRUCT_DEF echo_reply_s {
138 139 140 141
                uint16_t id;
                uint16_t seq;
                uint8_t data[0];
            } echo_reply;
142
            PEDANTIC_STRUCT_DEF router_sol_s {
143 144 145
                uint32_t unused;
                uint8_t options[0];
            } router_sol;
146
            PEDANTIC_STRUCT_DEF router_adv_s {
147 148 149 150 151 152 153
                uint8_t hop;
                uint8_t mor;
                uint16_t life_time;
                uint32_t reachable_time;
                uint32_t retrans_time;
                uint8_t options[0];
            } router_adv;
154
            PEDANTIC_STRUCT_DEF neigh_sol_s {
155 156 157 158
                uint32_t unused;
                struct pico_ip6 target;
                uint8_t options[0];
            } neigh_sol;
159
            PEDANTIC_STRUCT_DEF neigh_adv_s {
160 161 162 163
                uint32_t rsor;
                struct pico_ip6 target;
                uint8_t options[0];
            } neigh_adv;
164
            PEDANTIC_STRUCT_DEF redirect_s {
165 166 167 168 169 170 171 172 173
                uint32_t reserved;
                struct pico_ip6 target;
                struct pico_ip6 dest;
                uint8_t options[0];
            } redirect;
        } info;
    } msg;
};

174
PACKED_STRUCT_DEF pico_icmp6_opt_lladdr
175 176 177
{
    uint8_t type;
    uint8_t len;
178
    PACKED_UNION_DEF icmp6_opt_hw_addr_u {
179 180 181 182
        struct pico_eth mac;
    } addr;
};

183
PACKED_STRUCT_DEF pico_icmp6_opt_prefix
184 185 186 187 188 189 190 191 192 193 194 195 196
{
    uint8_t type;
    uint8_t len;
    uint8_t prefix_len;
    uint8_t res : 6;
    uint8_t aac : 1;
    uint8_t onlink : 1;
    uint32_t val_lifetime;
    uint32_t pref_lifetime;
    uint32_t reserved;
    struct pico_ip6 prefix;
};

197
PACKED_STRUCT_DEF pico_icmp6_opt_mtu
198 199 200 201 202 203 204
{
    uint8_t type;
    uint8_t len;
    uint16_t res;
    uint32_t mtu;
};

205
PACKED_STRUCT_DEF pico_icmp6_opt_redirect
206 207 208 209 210 211 212 213
{
    uint8_t type;
    uint8_t len;
    uint16_t res0;
    uint32_t res1;
    uint8_t data[0];
};

214 215 216 217 218 219 220 221 222
PACKED_STRUCT_DEF pico_icmp6_opt_rdnss
{
    uint8_t type;
    uint8_t len;
    uint16_t res0;
    uint32_t lifetime;
    struct pico_ip6 addr[];
};

223
PACKED_STRUCT_DEF pico_icmp6_opt_na
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
{
    uint8_t type;
    uint8_t len;
    uint8_t options[0];
};

struct pico_icmp6_stats
{
    unsigned long size;
    unsigned long seq;
    pico_time time;
    unsigned long ttl;
    int err;
    struct pico_ip6 dst;
};

240
int pico_icmp6_ping(char *dst, int count, int interval, int timeout, int size, void (*cb)(struct pico_icmp6_stats *), struct pico_device *dev);
241
int pico_icmp6_ping_abort(int id);
242 243 244 245 246 247 248 249 250 251

int pico_icmp6_neighbor_solicitation(struct pico_device *dev, struct pico_ip6 *dst, uint8_t type);
int pico_icmp6_neighbor_advertisement(struct pico_frame *f, struct pico_ip6 *target);
int pico_icmp6_router_solicitation(struct pico_device *dev, struct pico_ip6 *src);

int pico_icmp6_port_unreachable(struct pico_frame *f);
int pico_icmp6_proto_unreachable(struct pico_frame *f);
int pico_icmp6_dest_unreachable(struct pico_frame *f);
int pico_icmp6_ttl_expired(struct pico_frame *f);
int pico_icmp6_packet_filtered(struct pico_frame *f);
252
int pico_icmp6_parameter_problem(struct pico_frame *f, uint8_t problem, uint32_t ptr);
253
int pico_icmp6_pkt_too_big(struct pico_frame *f);
254
int pico_icmp6_frag_expired(struct pico_frame *f);
255 256

uint16_t pico_icmp6_checksum(struct pico_frame *f);
257
int pico_icmp6_router_advertisement(struct pico_device *dev, struct pico_ip6 *dst);
258 259

#endif