mikroSDK Reference Manual
ndp.h
Go to the documentation of this file.
1
31#ifndef _NDP_H
32#define _NDP_H
33
34//Dependencies
35#include "core/net.h"
36
37//NDP support
38#ifndef NDP_SUPPORT
39 #define NDP_SUPPORT ENABLED
40#elif (NDP_SUPPORT != ENABLED && NDP_SUPPORT != DISABLED)
41 #error NDP_SUPPORT parameter is not valid
42#endif
43
44//NDP tick interval
45#ifndef NDP_TICK_INTERVAL
46 #define NDP_TICK_INTERVAL 200
47#elif (NDP_TICK_INTERVAL < 10)
48 #error NDP_TICK_INTERVAL parameter is not valid
49#endif
50
51//Neighbor cache size
52#ifndef NDP_NEIGHBOR_CACHE_SIZE
53 #define NDP_NEIGHBOR_CACHE_SIZE 8
54#elif (NDP_NEIGHBOR_CACHE_SIZE < 1)
55 #error NDP_NEIGHBOR_CACHE_SIZE parameter is not valid
56#endif
57
58//Destination cache size
59#ifndef NDP_DEST_CACHE_SIZE
60 #define NDP_DEST_CACHE_SIZE 8
61#elif (NDP_DEST_CACHE_SIZE < 1)
62 #error NDP_DEST_CACHE_SIZE parameter is not valid
63#endif
64
65//Maximum number of packets waiting for address resolution to complete
66#ifndef NDP_MAX_PENDING_PACKETS
67 #define NDP_MAX_PENDING_PACKETS 2
68#elif (NDP_MAX_PENDING_PACKETS < 1)
69 #error NDP_MAX_PENDING_PACKETS parameter is not valid
70#endif
71
72//Maximum time interval between Router Advertisements
73#ifndef NDP_MAX_RTR_ADVERT_INTERVAL
74 #define NDP_MAX_RTR_ADVERT_INTERVAL 600000
75#elif (NDP_MAX_RTR_ADVERT_INTERVAL < 1000)
76 #error NDP_MAX_RTR_ADVERT_INTERVAL parameter is not valid
77#endif
78
79//Maximum time interval between initial Router Advertisements
80#ifndef NDP_MAX_INITIAL_RTR_ADVERT_INTERVAL
81 #define NDP_MAX_INITIAL_RTR_ADVERT_INTERVAL 16000
82#elif (NDP_MAX_INITIAL_RTR_ADVERT_INTERVAL < 1000)
83 #error NDP_MAX_INITIAL_RTR_ADVERT_INTERVAL parameter is not valid
84#endif
85
86//Maximum number of initial Router Advertisements
87#ifndef NDP_MAX_INITIAL_RTR_ADVERTISEMENTS
88 #define NDP_MAX_INITIAL_RTR_ADVERTISEMENTS 3
89#elif (NDP_MAX_INITIAL_RTR_ADVERTISEMENTS < 1)
90 #error NDP_MAX_INITIAL_RTR_ADVERTISEMENTS parameter is not valid
91#endif
92
93//Maximum number of final Router Advertisements
94#ifndef NDP_MAX_FINAL_RTR_ADVERTISEMENTS
95 #define NDP_MAX_FINAL_RTR_ADVERTISEMENTS 3
96#elif (NDP_MAX_FINAL_RTR_ADVERTISEMENTS < 1)
97 #error NDP_MAX_FINAL_RTR_ADVERTISEMENTS parameter is not valid
98#endif
99
100//Minimum delay between Router Advertisements
101#ifndef NDP_MIN_DELAY_BETWEEN_RAS
102 #define NDP_MIN_DELAY_BETWEEN_RAS 3000
103#elif (NDP_MIN_DELAY_BETWEEN_RAS < 1000)
104 #error NDP_MIN_DELAY_BETWEEN_RAS parameter is not valid
105#endif
106
107//Maximum delay for Router Advertisements sent in response to a Router Solicitation
108#ifndef NDP_MAX_RA_DELAY_TIME
109 #define NDP_MAX_RA_DELAY_TIME 500
110#elif (NDP_MAX_RA_DELAY_TIME < 100)
111 #error NDP_MAX_RA_DELAY_TIME parameter is not valid
112#endif
113
114//Minimum delay before transmitting the first Router Solicitation message
115#ifndef NDP_MIN_RTR_SOLICITATION_DELAY
116 #define NDP_MIN_RTR_SOLICITATION_DELAY 0
117#elif (NDP_MIN_RTR_SOLICITATION_DELAY < 0)
118 #error NDP_MIN_RTR_SOLICITATION_DELAY parameter is not valid
119#endif
120
121//Maximum delay before transmitting the first Router Solicitation message
122#ifndef NDP_MAX_RTR_SOLICITATION_DELAY
123 #define NDP_MAX_RTR_SOLICITATION_DELAY 1000
124#elif (NDP_MAX_RTR_SOLICITATION_DELAY < 0)
125 #error NDP_MAX_RTR_SOLICITATION_DELAY parameter is not valid
126#endif
127
128//The time between retransmissions of Router Solicitation messages
129#ifndef NDP_RTR_SOLICITATION_INTERVAL
130 #define NDP_RTR_SOLICITATION_INTERVAL 4000
131#elif (NDP_RTR_SOLICITATION_INTERVAL < 1000)
132 #error NDP_RTR_SOLICITATION_INTERVAL parameter is not valid
133#endif
134
135//Number of retransmissions for Router Solicitation messages
136#ifndef NDP_MAX_RTR_SOLICITATIONS
137 #define NDP_MAX_RTR_SOLICITATIONS 3
138#elif (NDP_MAX_RTR_SOLICITATIONS < 1)
139 #error NDP_MAX_RTR_SOLICITATIONS parameter is not valid
140#endif
141
142//Number of retransmissions for multicast Neighbor Solicitation messages
143#ifndef NDP_MAX_MULTICAST_SOLICIT
144 #define NDP_MAX_MULTICAST_SOLICIT 3
145#elif (NDP_MAX_MULTICAST_SOLICIT < 1)
146 #error NDP_MAX_MULTICAST_SOLICIT parameter is not valid
147#endif
148
149//Number of retransmissions for unicast Neighbor Solicitation messages
150#ifndef NDP_MAX_UNICAST_SOLICIT
151 #define NDP_MAX_UNICAST_SOLICIT 3
152#elif (NDP_MAX_UNICAST_SOLICIT < 1)
153 #error NDP_MAX_UNICAST_SOLICIT parameter is not valid
154#endif
155
156//Maximum number of Neighbor Solicitation messages sent while performing DAD
157#ifndef NDP_DUP_ADDR_DETECT_TRANSMITS
158 #define NDP_DUP_ADDR_DETECT_TRANSMITS 1
159#elif (NDP_DUP_ADDR_DETECT_TRANSMITS < 0)
160 #error NDP_DUP_ADDR_DETECT_TRANSMITS parameter is not valid
161#endif
162
163//Delay before sending Neighbor Advertisements if the target address is an anycast address
164#ifndef NDP_MAX_ANYCAST_DELAY_TIME
165 #define NDP_MAX_ANYCAST_DELAY_TIME 1000
166#elif (NDP_MAX_ANYCAST_DELAY_TIME < 100)
167 #error NDP_MAX_ANYCAST_DELAY_TIME parameter is not valid
168#endif
169
170//Maximum number of unsolicited Neighbor Advertisements
171#ifndef NDP_MAX_NEIGHBOR_ADVERTISEMENT
172 #define NDP_MAX_NEIGHBOR_ADVERTISEMENT 3
173#elif (NDP_MAX_NEIGHBOR_ADVERTISEMENT < 0)
174 #error NDP_MAX_NEIGHBOR_ADVERTISEMENT parameter is not valid
175#endif
176
177//The time a neighbor is considered reachable after receiving a reachability confirmation
178#ifndef NDP_REACHABLE_TIME
179 #define NDP_REACHABLE_TIME 30000
180#elif (NDP_REACHABLE_TIME < 1000)
181 #error NDP_REACHABLE_TIME parameter is not valid
182#endif
183
184//The time between retransmissions of Neighbor Solicitation messages
185#ifndef NDP_RETRANS_TIMER
186 #define NDP_RETRANS_TIMER 1000
187#elif (NDP_RETRANS_TIMER < 100)
188 #error NDP_RETRANS_TIMER parameter is not valid
189#endif
190
191//Delay before sending the first probe
192#ifndef NDP_DELAY_FIRST_PROBE_TIME
193 #define NDP_DELAY_FIRST_PROBE_TIME 5000
194#elif (NDP_DELAY_FIRST_PROBE_TIME < 1000)
195 #error NDP_DELAY_FIRST_PROBE_TIME parameter is not valid
196#endif
197
198//Hop Limit used by NDP messages
199#define NDP_HOP_LIMIT 255
200
201//Infinite lifetime
202#define NDP_INFINITE_LIFETIME 0xFFFFFFFF
203
204//C++ guard
205#ifdef __cplusplus
206extern "C" {
207#endif
208
209
214typedef enum
215{
216 NDP_OPT_SOURCE_LINK_LAYER_ADDR = 1,
217 NDP_OPT_TARGET_LINK_LAYER_ADDR = 2,
218 NDP_OPT_PREFIX_INFORMATION = 3,
219 NDP_OPT_REDIRECTED_HEADER = 4,
220 NDP_OPT_MTU = 5,
221 NDP_OPT_ROUTE_INFORMATION = 24,
222 NDP_OPT_RECURSIVE_DNS_SERVER = 25,
223 NDP_OPT_DNS_SEARCH_LIST = 31,
224 NDP_OPT_6LOWPAN_CONTEXT = 34,
225 NDP_OPT_CAPTIVE_PORTAL = 37,
226 NDP_OPT_ANY = 255
228
229
234typedef enum
235{
236 NDP_ROUTER_SEL_PREFERENCE_MEDIUM = 0,
237 NDP_ROUTER_SEL_PREFERENCE_HIGH = 1,
238 NDP_ROUTER_SEL_PREFERENCE_RESERVED = 2,
239 NDP_ROUTER_SEL_PREFERENCE_LOW = 3
241
242
247typedef enum
248{
249 NDP_STATE_NONE = 0,
250 NDP_STATE_INCOMPLETE = 1,
251 NDP_STATE_REACHABLE = 2,
252 NDP_STATE_STALE = 3,
253 NDP_STATE_DELAY = 4,
254 NDP_STATE_PROBE = 5,
255 NDP_STATE_PERMANENT = 6
256} NdpState;
257
258
259//CodeWarrior or Win32 compiler?
260#if defined(__CWCC__) || defined(_WIN32)
261 #pragma pack(push, 1)
262#endif
263
264
270{
271 uint8_t type; //0
272 uint8_t code; //1
273 uint16_t checksum; //2-3
274 uint32_t reserved; //4-7
275 uint8_t options[]; //8
276} NdpRouterSolMessage;
277
278
283typedef __packed_struct
284{
285 uint8_t type; //0
286 uint8_t code; //1
287 uint16_t checksum; //2-3
288 uint8_t curHopLimit; //4
289#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
290 uint8_t m : 1; //5
291 uint8_t o : 1;
292 uint8_t h : 1;
293 uint8_t prf : 2;
294 uint8_t p : 1;
295 uint8_t reserved : 2;
296#else
297 uint8_t reserved : 2; //5
298 uint8_t p : 1;
299 uint8_t prf : 2;
300 uint8_t h : 1;
301 uint8_t o : 1;
302 uint8_t m : 1;
303#endif
304 uint16_t routerLifetime; //6-7
305 uint32_t reachableTime; //8-11
306 uint32_t retransTimer; //12-15
307 uint8_t options[]; //16
308} NdpRouterAdvMessage;
309
310
315typedef __packed_struct
316{
317 uint8_t type; //0
318 uint8_t code; //1
319 uint16_t checksum; //2-3
320 uint32_t reserved; //4-7
321 Ipv6Addr targetAddr; //8-23
322 uint8_t options[]; //24
323} NdpNeighborSolMessage;
324
325
330typedef __packed_struct
331{
332 uint8_t type; //0
333 uint8_t code; //1
334 uint16_t checksum; //2-3
335#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
336 uint8_t r : 1; //4
337 uint8_t s : 1;
338 uint8_t o : 1;
339 uint8_t reserved1 : 5;
340#else
341 uint8_t reserved1 : 5; //4
342 uint8_t o : 1;
343 uint8_t s : 1;
344 uint8_t r : 1;
345#endif
346 uint8_t reserved2[3]; //5-7
347 Ipv6Addr targetAddr; //8-23
348 uint8_t options[]; //24
349} NdpNeighborAdvMessage;
350
351
356typedef __packed_struct
357{
358 uint8_t type; //0
359 uint8_t code; //1
360 uint16_t checksum; //2-3
361 uint32_t reserved; //4-7
362 Ipv6Addr targetAddr; //8-23
363 Ipv6Addr destAddr; //24-39
364 uint8_t options[]; //40
365} NdpRedirectMessage;
366
367
372typedef __packed_struct
373{
374 uint8_t type; //0
375 uint8_t length; //1
376 uint8_t value[]; //2
377} NdpOption;
378
379
384typedef __packed_struct
385{
386 uint8_t type; //0
387 uint8_t length; //1
388 MacAddr linkLayerAddr; //2-7
389} NdpLinkLayerAddrOption;
390
391
396typedef __packed_struct
397{
398 uint8_t type; //0
399 uint8_t length; //1
400 uint8_t prefixLength; //2
401#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
402 uint8_t l : 1; //3
403 uint8_t a : 1;
404 uint8_t r : 1;
405 uint8_t reserved1 : 5;
406#else
407 uint8_t reserved1 : 5; //3
408 uint8_t r : 1;
409 uint8_t a : 1;
410 uint8_t l : 1;
411#endif
412 uint32_t validLifetime; //4-7
413 uint32_t preferredLifetime; //8-11
414 uint32_t reserved2; //12-15
415 Ipv6Addr prefix; //16-31
416} NdpPrefixInfoOption;
417
418
423typedef __packed_struct
424{
425 uint8_t type; //0
426 uint8_t length; //1
427 uint16_t reserved1; //2-3
428 uint32_t reserved2; //4-7
429 uint8_t ipPacket[]; //8
430} NdpRedirectedHeaderOption;
431
432
437typedef __packed_struct
438{
439 uint8_t type; //0
440 uint8_t length; //1
441 uint16_t reserved; //2-3
442 uint32_t mtu; //4-7
443} NdpMtuOption;
444
445
450typedef __packed_struct
451{
452 uint8_t type; //0
453 uint8_t length; //1
454 uint8_t prefixLength; //2
455#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
456 uint8_t reserved1 : 3; //3
457 uint8_t prf : 2;
458 uint8_t reserved2 : 3;
459#else
460 uint8_t reserved2 : 3; //3
461 uint8_t prf : 2;
462 uint8_t reserved1 : 3;
463#endif
464 uint32_t routeLifetime; //4-7
465 Ipv6Addr prefix; //8
466} NdpRouteInfoOption;
467
468
473typedef __packed_struct
474{
475 uint8_t type; //0
476 uint8_t length; //1
477 uint16_t reserved; //2-3
478 uint32_t lifetime; //4-7
479 Ipv6Addr address[]; //8
480} NdpRdnssOption;
481
482
487typedef __packed_struct
488{
489 uint8_t type; //0
490 uint8_t length; //1
491 uint16_t reserved; //2-3
492 uint32_t lifetime; //4-7
493 uint8_t domainNames[]; //8
494} NdpDnsslOption;
495
496
501typedef __packed_struct
502{
503 uint8_t type; //0
504 uint8_t length; //1
505 uint8_t contextLength; //2
506#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
507 uint8_t reserved1 : 3; //3
508 uint8_t c : 1;
509 uint8_t cid : 4;
510#else
511 uint8_t cid : 4; //3
512 uint8_t c : 1;
513 uint8_t reserved1 : 3;
514#endif
515 uint16_t reserved2; //4-5
516 uint16_t validLifetime; //6-7
517 Ipv6Addr contextPrefix; //8
518} NdpContextOption;
519
520
521//CodeWarrior or Win32 compiler?
522#if defined(__CWCC__) || defined(_WIN32)
523 #pragma pack(pop)
524#endif
525
526
531typedef struct
532{
533 NetInterface *srcInterface;
535 size_t offset;
536 NetTxAncillary ancillary;
538
539
544typedef struct
545{
547 Ipv6Addr ipAddr;
548 MacAddr macAddr;
549 bool_t isRouter;
553 NdpQueueItem queue[NDP_MAX_PENDING_PACKETS];
554 uint_t queueSize;
556
557
562typedef struct
563{
564 Ipv6Addr destAddr;
565 Ipv6Addr nextHop;
566 size_t pathMtu;
569
570
592
593
594//Tick counter to handle periodic operations
595extern systime_t ndpTickCounter;
596
597//NDP related functions
598error_t ndpInit(NetInterface *interface);
599error_t ndpEnable(NetInterface *interface, bool_t enable);
600
601error_t ndpAddStaticEntry(NetInterface *interface, const Ipv6Addr *ipAddr,
602 const MacAddr *macAddr);
603
604error_t ndpRemoveStaticEntry(NetInterface *interface, const Ipv6Addr *ipAddr);
605
606error_t ndpResolve(NetInterface *interface, const Ipv6Addr *ipAddr,
607 MacAddr *macAddr);
608
609error_t ndpEnqueuePacket(NetInterface *srcInterface,
610 NetInterface *destInterface, const Ipv6Addr *ipAddr, NetBuffer *buffer,
611 size_t offset, NetTxAncillary *ancillary);
612
613void ndpTick(NetInterface *interface);
614void ndpLinkChangeEvent(NetInterface *interface);
615
616void ndpProcessRouterAdv(NetInterface *interface,
617 const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
618 size_t offset, uint8_t hopLimit);
619
620void ndpProcessNeighborSol(NetInterface *interface,
621 const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
622 size_t offset, uint8_t hopLimit);
623
624void ndpProcessNeighborAdv(NetInterface *interface,
625 const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
626 size_t offset, uint8_t hopLimit);
627
628void ndpProcessRedirect(NetInterface *interface,
629 const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
630 size_t offset, uint8_t hopLimit);
631
632error_t ndpSendRouterSol(NetInterface *interface);
633
634error_t ndpSendNeighborSol(NetInterface *interface,
635 const Ipv6Addr *targetIpAddr, bool_t multicast);
636
637error_t ndpSendNeighborAdv(NetInterface *interface,
638 const Ipv6Addr *targetIpAddr, const Ipv6Addr *destIpAddr);
639
640error_t ndpSendRedirect(NetInterface *interface, const Ipv6Addr *targetAddr,
641 const NetBuffer *ipPacket, size_t ipPacketOffset);
642
643void ndpDumpRouterSolMessage(const NdpRouterSolMessage *message);
644void ndpDumpRouterAdvMessage(const NdpRouterAdvMessage *message);
645void ndpDumpNeighborSolMessage(const NdpNeighborSolMessage *message);
646void ndpDumpNeighborAdvMessage(const NdpNeighborAdvMessage *message);
647void ndpDumpRedirectMessage(const NdpRedirectMessage *message);
648
649//C++ guard
650#ifdef __cplusplus
651}
652#endif
653
654#endif
error_t
Error codes.
Definition error.h:43
NdpRouterSelPreference
Router selection preferences.
Definition ndp.h:235
NdpState
Neighbor cache entry states.
Definition ndp.h:248
typedef __packed_struct
Router Solicitation message.
Definition ndp.h:270
NdpOptionType
Neighbor Discovery options.
Definition ndp.h:215
TCP/IP stack core.
uint32_t systime_t
System time.
Definition os_port_none.h:90
NDP context.
Definition ndp.h:576
systime_t timestamp
Timestamp to manage retransmissions.
Definition ndp.h:586
systime_t timeout
Timeout value.
Definition ndp.h:587
bool_t enable
Enable address resolution using Neighbor Discovery protocol.
Definition ndp.h:588
uint_t dupAddrDetectTransmits
Maximum number of NS messages sent while performing DAD.
Definition ndp.h:579
uint32_t retransTimer
The time between retransmissions of NS messages.
Definition ndp.h:578
uint32_t reachableTime
The time a node assumes a neighbor is reachable.
Definition ndp.h:577
systime_t maxRtrSolicitationDelay
Maximum delay before transmitting the first RS message.
Definition ndp.h:581
systime_t minRtrSolicitationDelay
Minimum delay before transmitting the first RS message.
Definition ndp.h:580
uint_t rtrSolicitationCount
Retransmission counter for RS messages.
Definition ndp.h:584
uint_t maxRtrSolicitations
Number of retransmissions for RS messages.
Definition ndp.h:583
systime_t rtrSolicitationInterval
Time interval between retransmissions of RS messages.
Definition ndp.h:582
bool_t rtrAdvReceived
Valid RA message received.
Definition ndp.h:585
Destination cache entry.
Definition ndp.h:563
Ipv6Addr destAddr
Destination IPv6 address.
Definition ndp.h:564
systime_t timestamp
Timestamp to manage entry lifetime.
Definition ndp.h:567
size_t pathMtu
Path MTU.
Definition ndp.h:566
Ipv6Addr nextHop
IPv6 address of the next-hop neighbor.
Definition ndp.h:565
Neighbor cache entry.
Definition ndp.h:545
systime_t timestamp
Timestamp to manage entry lifetime.
Definition ndp.h:550
MacAddr macAddr
Link layer address associated with the IPv6 address.
Definition ndp.h:548
systime_t timeout
Timeout value.
Definition ndp.h:551
Ipv6Addr ipAddr
Unicast IPv6 address.
Definition ndp.h:547
uint_t retransmitCount
Retransmission counter.
Definition ndp.h:552
NdpState state
Reachability state.
Definition ndp.h:546
uint_t queueSize
Number of queued packets.
Definition ndp.h:554
bool_t isRouter
A flag indicating whether the neighbor is a router or a host.
Definition ndp.h:549
NDP queue item.
Definition ndp.h:532
NetBuffer * buffer
Packet waiting for address resolution.
Definition ndp.h:534
size_t offset
Offset to the first byte of the packet.
Definition ndp.h:535
NetTxAncillary ancillary
Additional options.
Definition ndp.h:536
NetInterface * srcInterface
Interface from which the packet has been received.
Definition ndp.h:533
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89