Blame view

RIOT/sys/include/net/ndp.h 10.3 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
  /*
   * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup    net_ndp IPv6 neighbor discovery
   * @ingroup     net_ipv6
   * @brief       Provides IPv6 neighbor discovery message types
   * @{
   *
   * @file
   * @brief       IPv6 neighbor discovery message type definitions
   *
   * @author  Martine Lenders <mlenders@inf.fu-berlin.de>
   */
  #ifndef NET_NDP_H
  #define NET_NDP_H
  
  #include <stdint.h>
  
  #include "byteorder.h"
  #include "net/ipv6/addr.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @name    Router advertisement flags
   * @see     [RFC 4861, section 4.2](https://tools.ietf.org/html/rfc4861#section-4.2)
   * @{
   */
  #define NDP_RTR_ADV_FLAGS_MASK      (0xc0)
  #define NDP_RTR_ADV_FLAGS_M         (0x80)  /**< managed address configuration */
  #define NDP_RTR_ADV_FLAGS_O         (0x40)  /**< other configuration */
  /**
   * @}
   */
  
  /**
   * @brief   Router advertisement constants
   * @see     [RFC 4861, section 4.2](https://tools.ietf.org/html/rfc4861#section-4.2)
   * @{
   */
  #define NDP_RTR_ADV_CUR_HL_UNSPEC   (0) /**< current hop limit unspecified by advertising router */
  
  /**
   * @brief   maximum router lifetime in seconds
   * @see     [RFC 4861, section 6.2.1](https://tools.ietf.org/html/rfc4861#section-6.2.1)
   */
  #define NDP_RTR_ADV_LTIME_SEC_MAX   (9000)
  
  /**
   * @brief   router should not be a default router
   * @see     [RFC 4861, section 6.2.1](https://tools.ietf.org/html/rfc4861#section-6.2.1)
   */
  #define NDP_NBR_ADV_LTIME_NOT_DR    (0)
  
  #define NDP_NBR_ADV_REACH_TIME      (0)     /**< reachable time unspecified by advertising router */
  #define NDP_NBR_ADV_RETRANS_TIMER   (0)     /**< retrans. timer unspecified by advertising router */
  /** @} */
  
  /**
   * @name    Neighbor advertisement flags
   * @see     [RFC 4861, section 4.4](https://tools.ietf.org/html/rfc4861#section-4.4)
   * @{
   */
  #define NDP_NBR_ADV_FLAGS_MASK      (0xe0)
  #define NDP_NBR_ADV_FLAGS_R         (0x80)  /**< router */
  #define NDP_NBR_ADV_FLAGS_S         (0x40)  /**< solicited */
  #define NDP_NBR_ADV_FLAGS_O         (0x20)  /**< override */
  /**
   * @}
   */
  
  /**
   * @name    NDP option types
   * @{
   * @see     [IANA, IPv6 Neighbor Discovery Option Formats]
   *          (http://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-5")
   */
  #define NDP_OPT_SL2A                (1)     /**< source link-layer address option */
  #define NDP_OPT_TL2A                (2)     /**< target link-layer address option */
  #define NDP_OPT_PI                  (3)     /**< prefix information option */
  #define NDP_OPT_RH                  (4)     /**< redirected option */
  #define NDP_OPT_MTU                 (5)     /**< MTU option */
  #define NDP_OPT_AR                  (33)    /**< address registration option */
  #define NDP_OPT_6CTX                (34)    /**< 6LoWPAN context option */
  #define NDP_OPT_ABR                 (35)    /**< authoritative border router option */
  /** @} */
  
  /**
   * @{
   * @name    Flags for prefix information option
   */
  #define NDP_OPT_PI_FLAGS_MASK       (0xc0)
  #define NDP_OPT_PI_FLAGS_L          (0x80)  /**< on-link */
  #define NDP_OPT_PI_FLAGS_A          (0x40)  /**< autonomous address configuration */
  /** @} */
  
  /**
   * @{
   * @name    Prefix information option constants
   * @see     [RFC 4861, section 4.6.2](https://tools.ietf.org/html/rfc4861#section-4.6.2)
   */
  #define NDP_OPT_PI_VALID_LTIME_INF  (UINT32_MAX)    /**< infinite valid lifetime */
  #define NDP_OPT_PI_PREF_LTIME_INF   (UINT32_MAX)    /**< infinite preferred lifetime */
  /** @} */
  
  /**
   * @{
   * @name    Lengths for fixed length options
   * @note    Options don't use bytes as their length unit, but 8 bytes.
   */
  #define NDP_OPT_PI_LEN              (4U)
  #define NDP_OPT_MTU_LEN             (1U)
  /** @} */
  
  /**
   * @{
   * @name    Router constants
   * @see     [RFC 4861, section 10](https://tools.ietf.org/html/rfc4861#section-10)
   */
  #define NDP_MAX_INIT_RA_INTERVAL        (16000U)   /**< MAX_INITIAL_RTR_ADVERT_INTERVAL (in ms) */
  #define NDP_MAX_INIT_RA_NUMOF           (3U)       /**< MAX_INITIAL_RTR_ADVERTISEMENT */
  #define NDP_MAX_FIN_RA_NUMOF            (3U)       /**< MAX_FINAL_RTR_ADVERTISEMENT */
  #define NDP_MIN_MS_DELAY_BETWEEN_RAS    (3000U)    /**< MIN_DELAY_BETWEEN_RAS (in ms) */
  #define NDP_MAX_RA_DELAY                (500U)     /**< MAX_RA_DELAY_TIME (in ms) */
  /** @} */
  
  /**
   * @{
   * @name    Host constants
   * @see     [RFC 4861, section 10](https://tools.ietf.org/html/rfc4861#section-10)
   */
  #define NDP_MAX_RS_MS_DELAY         (1000U)     /**< MAX_RTR_SOLICITATION_DELAY (in ms) */
  #define NDP_RS_MS_INTERVAL          (4000U)     /**< RTR_SOLICITATION_INTERVAL (in ms) */
  #define NDP_MAX_RS_NUMOF            (3U)        /**< MAX_RTR_SOLICITATIONS */
  /** @} */
  
  /**
   * @name    Node constants
   * @see     [RFC 4861, section 10](https://tools.ietf.org/html/rfc4861#section-10)
   * @{
   */
  #define NDP_MAX_MC_SOL_NUMOF        (3U)        /**< MAX_MULTICAST_SOLICIT */
  #define NDP_MAX_UC_SOL_NUMOF        (3U)        /**< MAX_UNICAST_SOLICIT */
  #define NDP_MAX_ANYCAST_MS_DELAY    (1000U)     /**< MAX_ANYCAST_DELAY_TIME (in ms) */
  #define NDP_MAX_NA_NUMOF            (3U)        /**< MAX_NEIGHBOR_ADVERTISEMENT */
  #define NDP_REACH_MS                (30000U)    /**< REACHABLE_TIME (in ms) */
  #define NDP_RETRANS_TIMER_MS        (1000U)     /**< RETRANS_TIMER (in ms) */
  /**
   * @brief   MAX_RETRANS_TIMER (in ms)
   *
   * @see     [RFC 7048](https://tools.ietf.org/html/rfc7048)
   */
  #define NDP_MAX_RETRANS_TIMER_MS    (60000U)
  #define NDP_DELAY_FIRST_PROBE_MS    (5000U)     /**< DELAY_FIRST_PROBE_TIME (in ms) */
  #define NDP_MIN_RANDOM_FACTOR       (500U)      /**< MIN_RANDOM_FACTOR (x 1000) */
  #define NDP_MAX_RANDOM_FACTOR       (1500U)     /**< MAX_RANDOM_FACTOR (x 1000) */
  /** @} */
  
  /**
   * @brief   Router solicitation message format.
   * @extends icmpv6_hdr_t
   *
   * @see     [RFC 4861, section 4.1](https://tools.ietf.org/html/rfc4861#section-4.1)
   */
  typedef struct __attribute__((packed)) {
      uint8_t type;           /**< message type */
      uint8_t code;           /**< message code */
      network_uint16_t csum;  /**< checksum */
      network_uint32_t resv;  /**< reserved field */
  } ndp_rtr_sol_t;
  
  /**
   * @brief   Router advertisement message format.
   * @extends icmpv6_hdr_t
   *
   * @see     [RFC 4861, section 4.2](https://tools.ietf.org/html/rfc4861#section-4.2)
   */
  typedef struct __attribute__((packed)) {
      uint8_t type;                       /**< message type */
      uint8_t code;                       /**< message code */
      network_uint16_t csum;              /**< checksum */
      uint8_t cur_hl;                     /**< current hop limit */
      uint8_t flags;                      /**< flags */
      network_uint16_t ltime;             /**< router lifetime */
      network_uint32_t reach_time;        /**< reachable time */
      network_uint32_t retrans_timer;     /**< retransmission timer */
  } ndp_rtr_adv_t;
  
  /**
   * @brief   Neighbor solicitation message format.
   * @extends icmpv6_hdr_t
   *
   * @see     [RFC 4861, section 4.3](https://tools.ietf.org/html/rfc4861#section-4.3)
   */
  typedef struct __attribute__((packed)) {
      uint8_t type;           /**< message type */
      uint8_t code;           /**< message code */
      network_uint16_t csum;  /**< checksum */
      network_uint32_t resv;  /**< reserved field */
      ipv6_addr_t tgt;        /**< target address */
  } ndp_nbr_sol_t;
  
  /**
   * @brief   Neighbor advertisement message format.
   * @extends icmpv6_hdr_t
   *
   * @see     [RFC 4861, section 4.4](https://tools.ietf.org/html/rfc4861#section-4.4)
   */
  typedef struct __attribute__((packed)) {
      uint8_t type;           /**< message type */
      uint8_t code;           /**< message code */
      network_uint16_t csum;  /**< checksum */
      uint8_t flags;          /**< flags */
      uint8_t resv[3];        /**< reserved fields */
      ipv6_addr_t tgt;        /**< target address */
  } ndp_nbr_adv_t;
  
  /**
   * @brief   Redirect message format.
   * @extends icmpv6_hdr_t
   *
   * @see     [RFC 4861, section 4.5](https://tools.ietf.org/html/rfc4861#section-4.5)
   */
  typedef struct __attribute__((packed)) {
      uint8_t type;           /**< message type */
      uint8_t code;           /**< message code */
      network_uint16_t csum;  /**< checksum */
      network_uint32_t resv;  /**< reserved field */
      ipv6_addr_t tgt;        /**< target address */
      ipv6_addr_t dst;        /**< destination address */
  } ndp_redirect_t;
  
  /**
   * @brief   General NDP option format
   * @see     [RFC 4861, section 4.6](https://tools.ietf.org/html/rfc4861#section-4.6)
   */
  typedef struct __attribute__((packed)) {
      uint8_t type;   /**< option type */
      uint8_t len;    /**< length in units of 8 octets */
  } ndp_opt_t;
  
  /* XXX: slla and tlla are just ndp_opt_t with variable link layer address
   * appended */
  
  /**
   * @brief   Prefix information option format
   * @extends ndp_opt_t
   *
   * @see     [RFC 4861, section 4.6.2](https://tools.ietf.org/html/rfc4861#section-4.6.2)
   */
  typedef struct __attribute__((packed)) {
      uint8_t type;                   /**< option type */
      uint8_t len;                    /**< length in units of 8 octets */
      uint8_t prefix_len;             /**< prefix length */
      uint8_t flags;                  /**< flags */
      network_uint32_t valid_ltime;   /**< valid lifetime */
      network_uint32_t pref_ltime;    /**< preferred lifetime */
      network_uint32_t resv;          /**< reserved field */
      ipv6_addr_t prefix;             /**< prefix */
  } ndp_opt_pi_t;
  
  /**
   * @brief   Redirected header option format
   * @extends ndp_opt_t
   *
   * @see     [RFC 4861, section 4.6.3](https://tools.ietf.org/html/rfc4861#section-4.6.3)
   */
  typedef struct __attribute__((packed)) {
      uint8_t type;           /**< option type */
      uint8_t len;            /**< length in units of 8 octets */
      uint8_t resv[6];        /**< reserved field */
  } ndp_opt_rh_t;
  
  /**
   * @brief   MTU option format
   * @extends ndp_opt_t
   *
   * @see     [RFC 4861, section 4.6.4](https://tools.ietf.org/html/rfc4861#section-4.6.4)
   */
  typedef struct __attribute__((packed)) {
      uint8_t type;           /**< option type */
      uint8_t len;            /**< length in units of 8 octets */
      network_uint16_t resv;  /**< reserved field */
      network_uint32_t mtu;   /**< MTU */
  } ndp_opt_mtu_t;
  
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* NET_NDP_H */
  /** @} */