ndp_router_adv_misc.c
Go to the documentation of this file.
1 /**
2  * @file ndp_router_adv_misc.c
3  * @brief Helper functions for router advertisement service
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2022 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.2.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL NDP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "ipv6/ipv6.h"
37 #include "ipv6/ipv6_misc.h"
38 #include "ipv6/icmpv6.h"
39 #include "ipv6/ndp.h"
40 #include "ipv6/ndp_cache.h"
41 #include "ipv6/ndp_misc.h"
42 #include "ipv6/ndp_router_adv.h"
44 #include "mibs/ip_mib_module.h"
45 #include "debug.h"
46 
47 //Check TCP/IP stack configuration
48 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
49 
50 //Tick counter to handle periodic operations
52 
53 
54 /**
55  * @brief RA service timer handler
56  * @param[in] context Pointer to the RA service context
57  **/
58 
60 {
62  NetInterface *interface;
63  NdpRouterAdvSettings *settings;
64 
65  //Make sure the RA service has been properly instantiated
66  if(context == NULL)
67  return;
68 
69  //Point to the underlying network interface
70  interface = context->settings.interface;
71  //Point to the router configuration variables
72  settings = &context->settings;
73 
74  //Get current time
76 
77  //Make sure that the link is up and the service is running
78  if(interface->linkState && context->running)
79  {
80  //Make sure that a valid link-local address has been assigned to the
81  //interface
83  {
84  //Check current time
85  if(timeCompare(time, context->timestamp + context->timeout) >= 0)
86  {
87  //Send an unsolicited Router Advertisement
88  ndpSendRouterAdv(context, context->settings.defaultLifetime);
89 
90  //Save the time at which the message was sent
91  context->timestamp = time;
92 
93  //Whenever a multicast advertisement is sent from an interface, the
94  //timer is reset to a uniformly distributed random value between
95  //MinRtrAdvInterval and MaxRtrAdvInterval
96  context->timeout = netGenerateRandRange(settings->minRtrAdvInterval,
97  settings->maxRtrAdvInterval);
98 
99  //First Router Advertisements to be sent from this interface?
101  {
102  //For the first few advertisements sent from an interface when it
103  //becomes an advertising interface, the randomly chosen interval
104  //should not be greater than MAX_INITIAL_RTR_ADVERT_INTERVAL
106  }
107 
108  //Increment counter
109  context->routerAdvCount++;
110  }
111  }
112  }
113 }
114 
115 
116 /**
117  * @brief Callback function for link change event
118  * @param[in] context Pointer to the RA service context
119  **/
120 
122 {
123  NetInterface *interface;
124 
125  //Make sure the RA service has been properly instantiated
126  if(context == NULL)
127  return;
128 
129  //Point to the underlying network interface
130  interface = context->settings.interface;
131 
132  //Reset variables
133  context->timestamp = osGetSystemTime();
134  context->timeout = 0;
135  context->routerAdvCount = 0;
136 
137  //Default Hop Limit value
138  if(context->settings.curHopLimit != 0)
139  {
140  interface->ipv6Context.curHopLimit = context->settings.curHopLimit;
141  }
142 
143  //The time a node assumes a neighbor is reachable
144  if(context->settings.reachableTime != 0)
145  {
146  interface->ndpContext.reachableTime = context->settings.reachableTime;
147  }
148 
149  //The time between retransmissions of NS messages
150  if(context->settings.retransTimer != 0)
151  {
152  interface->ndpContext.retransTimer = context->settings.retransTimer;
153  }
154 }
155 
156 
157 /**
158  * @brief Router Solicitation message processing
159  * @param[in] interface Underlying network interface
160  * @param[in] pseudoHeader IPv6 pseudo header
161  * @param[in] buffer Multi-part buffer containing the Router Advertisement message
162  * @param[in] offset Offset to the first byte of the message
163  * @param[in] hopLimit Hop Limit field from IPv6 header
164  **/
165 
166 void ndpProcessRouterSol(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader,
167  const NetBuffer *buffer, size_t offset, uint8_t hopLimit)
168 {
169  error_t error;
170  uint_t n;
171  size_t length;
172  systime_t time;
173  systime_t delay;
174  NdpRouterAdvContext *context;
176  NdpLinkLayerAddrOption *option;
177  NdpNeighborCacheEntry *entry;
178 
179  //Point to the RA service context
180  context = interface->ndpRouterAdvContext;
181 
182  //A host must silently discard any received Router Solicitation
183  if(context == NULL)
184  return;
185 
186  //Get current time
187  time = osGetSystemTime();
188 
189  //Retrieve the length of the message
190  length = netBufferGetLength(buffer) - offset;
191 
192  //Check the length of the Router Solicitation message
193  if(length < sizeof(NdpRouterSolMessage))
194  return;
195 
196  //Point to the beginning of the message
197  message = netBufferAt(buffer, offset);
198  //Sanity check
199  if(message == NULL)
200  return;
201 
202  //Debug message
203  TRACE_INFO("Router Solicitation message received (%" PRIuSIZE " bytes)...\r\n",
204  length);
205 
206  //Dump message contents for debugging purpose
208 
209  //The IPv6 Hop Limit field must have a value of 255 to ensure that the
210  //packet has not been forwarded by a router
211  if(hopLimit != NDP_HOP_LIMIT)
212  return;
213 
214  //ICMPv6 Code must be 0
215  if(message->code)
216  return;
217 
218  //Calculate the length of the Options field
219  length -= sizeof(NdpRouterSolMessage);
220 
221  //Parse Options field
222  error = ndpCheckOptions(message->options, length);
223  //All included options must have a length that is greater than zero
224  if(error)
225  return;
226 
227  //Search for the Source Link-Layer Address option
228  option = ndpGetOption(message->options,
230 
231  //Source Link-Layer Address option found?
232  if(option != NULL && option->length == 1)
233  {
234  //Debug message
235  TRACE_DEBUG(" Source Link-Layer Address = %s\r\n",
236  macAddrToString(&option->linkLayerAddr, NULL));
237 
238  //The Source Link-Layer Address option must not be included when the
239  //source IP address is the unspecified address
240  if(ipv6CompAddr(&pseudoHeader->srcAddr, &IPV6_UNSPECIFIED_ADDR))
241  return;
242 
243  //Search the Neighbor Cache for the source address of the solicitation
244  entry = ndpFindNeighborCacheEntry(interface, &pseudoHeader->srcAddr);
245 
246  //No matching entry has been found?
247  if(!entry)
248  {
249  //Create an entry
250  entry = ndpCreateNeighborCacheEntry(interface);
251 
252  //Neighbor Cache entry successfully created?
253  if(entry)
254  {
255  //Record the IPv6 and the corresponding MAC address
256  entry->ipAddr = pseudoHeader->srcAddr;
257  entry->macAddr = option->linkLayerAddr;
258  //The IsRouter flag must be set to FALSE
259  entry->isRouter = FALSE;
260  //Save current time
261  entry->timestamp = time;
262  //Enter the STALE state
263  entry->state = NDP_STATE_STALE;
264  }
265  }
266  else
267  {
268  //If a Neighbor Cache entry for the solicitation's sender exists the
269  //entry's IsRouter flag must be set to FALSE
270  entry->isRouter = FALSE;
271 
272  //INCOMPLETE state?
273  if(entry->state == NDP_STATE_INCOMPLETE)
274  {
275  //Record link-layer address
276  entry->macAddr = option->linkLayerAddr;
277  //Send all the packets that are pending for transmission
278  n = ndpSendQueuedPackets(interface, entry);
279  //Save current time
280  entry->timestamp = time;
281 
282  //Check whether any packets have been sent
283  if(n > 0)
284  {
285  //Start delay timer
287  //Switch to the DELAY state
288  entry->state = NDP_STATE_DELAY;
289  }
290  else
291  {
292  //Enter the STALE state
293  entry->state = NDP_STATE_STALE;
294  }
295  }
296  //REACHABLE, STALE, DELAY or PROBE state?
297  else
298  {
299  //Different link-layer address than cached?
300  if(!macCompAddr(&entry->macAddr, &option->linkLayerAddr))
301  {
302  //Update link-layer address
303  entry->macAddr = option->linkLayerAddr;
304  //Save current time
305  entry->timestamp = time;
306  //Enter the STALE state
307  entry->state = NDP_STATE_STALE;
308  }
309  }
310  }
311  }
312 
313  //Upon receipt of a Router Solicitation, compute a random delay within the
314  //range 0 through MAX_RA_DELAY_TIME
316 
317  //If the computed value corresponds to a time later than the time the next
318  //multicast Router Advertisement is scheduled to be sent, ignore the random
319  //delay and send the advertisement at the already-scheduled time
320  if(timeCompare(time + delay, context->timestamp + context->timeout) > 0)
321  return;
322 
323  //Check whether the router sent a multicast Router Advertisement (solicited
324  //or unsolicited) within the last MIN_DELAY_BETWEEN_RAS seconds
326  {
327  //Schedule the advertisement to be sent at a time corresponding to
328  //MIN_DELAY_BETWEEN_RAS plus the random value after the previous
329  //advertisement was sent. This ensures that the multicast Router
330  //Advertisements are rate limited
331  context->timeout = NDP_MIN_DELAY_BETWEEN_RAS + delay;
332  }
333  else
334  {
335  //Schedule the sending of a Router Advertisement at the time given by the
336  //random value
337  context->timeout = time + delay - context->timestamp;
338  }
339 }
340 
341 
342 /**
343  * @brief Send a Router Advertisement message
344  * @param[in] context Pointer to the RA service context
345  * @param[in] routerLifetime Router Lifetime field
346  * @return Error code
347  **/
348 
350 {
351  error_t error;
352  uint_t i;
353  uint32_t n;
354  size_t offset;
355  size_t length;
356  NetBuffer *buffer;
357  NetInterface *interface;
359  NdpRouterAdvSettings *settings;
360  Ipv6PseudoHeader pseudoHeader;
361  NetTxAncillary ancillary;
362 #if (ETH_SUPPORT == ENABLED)
363  NetInterface *logicalInterface;
364 #endif
365 
366  //Point to the underlying network interface
367  interface = context->settings.interface;
368  //Point to the router configuration variables
369  settings = &context->settings;
370 
371  //The destination address is typically the all-nodes multicast address
372  pseudoHeader.destAddr = IPV6_LINK_LOCAL_ALL_NODES_ADDR;
373 
374  //Routers must use their link-local address as the source for Router
375  //Advertisement messages so that hosts can uniquely identify routers
376  error = ipv6SelectSourceAddr(&interface, &pseudoHeader.destAddr,
377  &pseudoHeader.srcAddr);
378 
379  //No link-local address assigned to the interface?
380  if(error)
381  return error;
382 
383  //Compute the maximum size of the Router Advertisement message
384  length = sizeof(NdpRouterAdvMessage) +
385  sizeof(NdpLinkLayerAddrOption) + sizeof(NdpMtuOption) +
386  settings->prefixListLength * sizeof(NdpPrefixInfoOption) +
387  settings->routeListLength * sizeof(NdpRouteInfoOption) +
388  settings->contextListLength * sizeof(NdpContextOption);
389 
390  //Sanity check
391  if((length + sizeof(Ipv6Header)) > IPV6_DEFAULT_MTU)
392  return ERROR_FAILURE;
393 
394  //Allocate a memory buffer to hold the Router Advertisement message
395  buffer = ipAllocBuffer(length, &offset);
396  //Failed to allocate memory?
397  if(buffer == NULL)
398  return ERROR_OUT_OF_MEMORY;
399 
400  //Point to the beginning of the message
401  message = netBufferAt(buffer, offset);
402 
403  //Format Router Advertisement message
405  message->code = 0;
406  message->checksum = 0;
407  message->curHopLimit = settings->curHopLimit;
408  message->m = settings->managedFlag;
409  message->o = settings->otherConfigFlag;
410  message->h = settings->homeAgentFlag;
411  message->prf = settings->preference;
412  message->p = settings->proxyFlag;
413  message->reserved = 0;
414  message->routerLifetime = htons(routerLifetime);
415  message->reachableTime = htonl(settings->reachableTime);
416  message->retransTimer = htonl(settings->retransTimer);
417 
418  //If the Router Lifetime is zero, the preference value must be set to
419  //zero by the sender
420  if(routerLifetime == 0)
422 
423  //Length of the message, excluding any option
424  length = sizeof(NdpRouterAdvMessage);
425 
426 #if (ETH_SUPPORT == ENABLED)
427  //Point to the logical interface
428  logicalInterface = nicGetLogicalInterface(interface);
429 
430  //Check whether a MAC address has been assigned to the interface
431  if(!macCompAddr(&logicalInterface->macAddr, &MAC_UNSPECIFIED_ADDR))
432  {
433  //Add Source Link-Layer Address option
435  &logicalInterface->macAddr, sizeof(MacAddr));
436  }
437 #endif
438 
439  //A value of zero indicates that no MTU option is sent
440  if(settings->linkMtu > 0)
441  {
442  NdpMtuOption mtuOption;
443 
444  //The MTU option specifies the recommended MTU for the link
445  mtuOption.reserved = 0;
446  mtuOption.mtu = htonl(settings->linkMtu);
447 
448  //Add MTU option
450  (uint8_t *) &mtuOption + sizeof(NdpOption),
451  sizeof(NdpMtuOption) - sizeof(NdpOption));
452  }
453 
454  //Loop through the list of IPv6 prefixes
455  for(i = 0; i < settings->prefixListLength; i++)
456  {
457  NdpPrefixInfoOption prefixInfoOption;
458 
459  //The Prefix Information option provide hosts with on-link prefixes and
460  //prefixes for Address Autoconfiguration
461  prefixInfoOption.prefixLength = settings->prefixList[i].length;
462  prefixInfoOption.l = settings->prefixList[i].onLinkFlag;
463  prefixInfoOption.a = settings->prefixList[i].autonomousFlag;
464  prefixInfoOption.r = 0;
465  prefixInfoOption.reserved1 = 0;
466  prefixInfoOption.validLifetime = htonl(settings->prefixList[i].validLifetime);
467  prefixInfoOption.preferredLifetime = htonl(settings->prefixList[i].preferredLifetime);
468  prefixInfoOption.reserved2 = 0;
469  prefixInfoOption.prefix = settings->prefixList[i].prefix;
470 
471  //Add Prefix Information option (PIO)
473  (uint8_t *) &prefixInfoOption + sizeof(NdpOption),
474  sizeof(NdpPrefixInfoOption) - sizeof(NdpOption));
475  }
476 
477  //Loop through the list of routes
478  for(i = 0; i < settings->routeListLength; i++)
479  {
480  NdpRouteInfoOption routeInfoOption;
481 
482  //The Route Information option specifies prefixes that are reachable via
483  //the router
484  routeInfoOption.prefixLength = settings->routeList[i].length;
485  routeInfoOption.reserved1 = 0;
486  routeInfoOption.prf = settings->routeList[i].preference;
487  routeInfoOption.reserved2 = 0;
488  routeInfoOption.routeLifetime = htonl(settings->routeList[i].routeLifetime);
489  routeInfoOption.prefix = settings->routeList[i].prefix;
490 
491  //Add Route Information option (RIO)
493  (uint8_t *) &routeInfoOption + sizeof(NdpOption),
494  sizeof(NdpRouteInfoOption) - sizeof(NdpOption));
495  }
496 
497  //Loop through the list of 6LoWPAN compression contexts
498  for(i = 0; i < settings->contextListLength; i++)
499  {
500  NdpContextOption contextOption;
501 
502  //The 6LoWPAN Context option (6CO) carries prefix information for LoWPAN
503  //header compression
504  contextOption.contextLength = settings->contextList[i].length;
505  contextOption.reserved1 = 0;
506  contextOption.c = settings->contextList[i].compression;
507  contextOption.cid = settings->contextList[i].cid;
508  contextOption.reserved2 = 0;
509  contextOption.validLifetime = htons(settings->contextList[i].validLifetime);
510  contextOption.contextPrefix = settings->contextList[i].prefix;
511 
512  //Calculate the length of the option in bytes
513  n = sizeof(NdpContextOption) - sizeof(Ipv6Addr) + (contextOption.contextLength / 8);
514 
515  //Add 6LoWPAN Context option (6CO)
517  (uint8_t *) &contextOption + sizeof(NdpOption), n - sizeof(NdpOption));
518  }
519 
520  //Adjust the length of the multi-part buffer
521  netBufferSetLength(buffer, offset + length);
522 
523  //Format IPv6 pseudo header
524  pseudoHeader.length = htonl(length);
525  pseudoHeader.reserved[0] = 0;
526  pseudoHeader.reserved[1] = 0;
527  pseudoHeader.reserved[2] = 0;
528  pseudoHeader.nextHeader = IPV6_ICMPV6_HEADER;
529 
530  //Calculate ICMPv6 header checksum
531  message->checksum = ipCalcUpperLayerChecksumEx(&pseudoHeader,
532  sizeof(Ipv6PseudoHeader), buffer, offset, length);
533 
534  //Total number of ICMP messages which this entity attempted to send
535  IP_MIB_INC_COUNTER32(icmpv6Stats.icmpStatsOutMsgs, 1);
536  //Increment per-message type ICMP counter
537  IP_MIB_INC_COUNTER32(icmpv6MsgStatsTable.icmpMsgStatsOutPkts[ICMPV6_TYPE_ROUTER_ADV], 1);
538 
539  //Debug message
540  TRACE_INFO("Sending Router Advertisement message (%" PRIuSIZE " bytes)...\r\n",
541  length);
542 
543  //Dump message contents for debugging purpose
545 
546  //Additional options can be passed to the stack along with the packet
547  ancillary = NET_DEFAULT_TX_ANCILLARY;
548 
549  //By setting the Hop Limit to 255, Neighbor Discovery is immune to off-link
550  //senders that accidentally or intentionally send NDP messages (refer to
551  //RFC 4861, section 3.1)
552  ancillary.ttl = NDP_HOP_LIMIT;
553 
554  //Send Router Advertisement message
555  error = ipv6SendDatagram(interface, &pseudoHeader, buffer, offset,
556  &ancillary);
557 
558  //Free previously allocated memory
559  netBufferFree(buffer);
560  //Return status code
561  return error;
562 }
563 
564 #endif
@ ICMPV6_TYPE_ROUTER_ADV
Definition: icmpv6.h:63
uint8_t length
Definition: coap_common.h:193
NdpNeighborCacheEntry * ndpFindNeighborCacheEntry(NetInterface *interface, const Ipv6Addr *ipAddr)
Search the Neighbor cache for a given IPv6 address.
Definition: ndp_cache.c:106
#define htons(value)
Definition: cpu_endian.h:413
IPv6 (Internet Protocol Version 6)
#define NDP_MIN_DELAY_BETWEEN_RAS
Definition: ndp.h:102
error_t ndpSendRouterAdv(NdpRouterAdvContext *context, uint16_t routerLifetime)
Send a Router Advertisement message.
NetBuffer * ipAllocBuffer(size_t length, size_t *offset)
Allocate a buffer to hold an IP packet.
Definition: ip.c:717
@ NDP_ROUTER_SEL_PREFERENCE_MEDIUM
Definition: ndp.h:236
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Definition: net_misc.c:71
__start_packed struct @6 NdpLinkLayerAddrOption
Source/Target Link-Layer Address option.
#define NDP_HOP_LIMIT
Definition: ndp.h:199
@ NDP_STATE_STALE
Definition: ndp.h:252
Helper functions for NDP (Neighbor Discovery Protocol)
NdpRouterAdvSettings settings
RA service settings.
@ NDP_OPT_MTU
Definition: ndp.h:220
#define IP_MIB_INC_COUNTER32(name, value)
Definition: ip_mib_module.h:46
void ndpDumpRouterSolMessage(const NdpRouterSolMessage *message)
Dump Router Solicitation message for debugging purpose.
Definition: ndp.c:1953
__start_packed struct @9 NdpMtuOption
MTU option.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
systime_t timestamp
Timestamp to manage retransmissions.
void ndpAddOption(void *message, size_t *messageLen, uint8_t type, const void *value, size_t length)
Append an option to a NDP message.
Definition: ndp_misc.c:593
@ NDP_OPT_SOURCE_LINK_LAYER_ADDR
Definition: ndp.h:216
#define Ipv6Header
Definition: ipv6.h:36
bool_t running
This flag tells whether the RA service is running.
void ndpRouterAdvTick(NdpRouterAdvContext *context)
RA service timer handler.
Neighbor cache entry.
Definition: ndp.h:545
uint_t routerAdvCount
Router Advertisement message counter.
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
#define ipv6CompAddr(ipAddr1, ipAddr2)
Definition: ipv6.h:121
@ IPV6_ICMPV6_HEADER
Definition: ipv6.h:187
#define timeCompare(t1, t2)
Definition: os_port.h:42
__start_packed struct @13 NdpContextOption
6LoWPAN Context option (6CO)
#define NDP_DELAY_FIRST_PROBE_TIME
Definition: ndp.h:193
Router advertisement service.
systime_t timestamp
Timestamp to manage entry lifetime.
Definition: ndp.h:550
#define FALSE
Definition: os_port.h:46
__start_packed struct @0 MacAddr
MAC address.
ICMPv6 (Internet Control Message Protocol Version 6)
#define htonl(value)
Definition: cpu_endian.h:414
uint32_t netGenerateRandRange(uint32_t min, uint32_t max)
Generate a random value in the specified range.
Definition: net_misc.c:900
MacAddr macAddr
Link layer address associated with the IPv6 address.
Definition: ndp.h:548
__start_packed struct @10 NdpRouteInfoOption
Route Information option (RIO)
error_t
Error codes.
Definition: error.h:43
uint16_t routerLifetime
Definition: ndp.h:304
#define Ipv6PseudoHeader
Definition: ipv6.h:42
__start_packed struct @0 NdpRouterSolMessage
Router Solicitation message.
error_t ipv6SelectSourceAddr(NetInterface **interface, const Ipv6Addr *destAddr, Ipv6Addr *srcAddr)
IPv6 source address selection.
Definition: ipv6_misc.c:879
void * netBufferAt(const NetBuffer *buffer, size_t offset)
Returns a pointer to the data at the specified position.
Definition: net_mem.c:413
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
char_t * macAddrToString(const MacAddr *macAddr, char_t *str)
Convert a MAC address to a dash delimited string.
Definition: ethernet.c:920
NdpNeighborCacheEntry * ndpCreateNeighborCacheEntry(NetInterface *interface)
Create a new entry in the Neighbor cache.
Definition: ndp_cache.c:53
const Ipv6Addr IPV6_LINK_LOCAL_ALL_NODES_ADDR
Definition: ipv6.c:74
#define NetInterface
Definition: net.h:36
#define NDP_MAX_INITIAL_RTR_ADVERTISEMENTS
Definition: ndp.h:88
void netBufferFree(NetBuffer *buffer)
Dispose a multi-part buffer.
Definition: net_mem.c:282
uint_t ndpSendQueuedPackets(NetInterface *interface, NdpNeighborCacheEntry *entry)
Send packets that are waiting for address resolution.
Definition: ndp_cache.c:293
@ NDP_STATE_DELAY
Definition: ndp.h:253
Helper functions for IPv6.
#define NetTxAncillary
Definition: net_misc.h:36
const Ipv6Addr IPV6_UNSPECIFIED_ADDR
Definition: ipv6.c:66
#define NDP_MAX_RA_DELAY_TIME
Definition: ndp.h:109
#define TRACE_INFO(...)
Definition: debug.h:95
__start_packed struct @7 NdpPrefixInfoOption
Prefix Information option (PIO)
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
Definition: net_mem.c:297
@ NDP_STATE_INCOMPLETE
Definition: ndp.h:250
#define MIN(a, b)
Definition: os_port.h:62
Neighbor and destination cache management.
NDP (Neighbor Discovery Protocol)
#define NDP_MAX_INITIAL_RTR_ADVERT_INTERVAL
Definition: ndp.h:81
uint32_t systime_t
System time.
#define TRACE_DEBUG(...)
Definition: debug.h:107
RA service context.
RA service settings.
uint32_t time
uint16_t ipCalcUpperLayerChecksumEx(const void *pseudoHeader, size_t pseudoHeaderLen, const NetBuffer *buffer, size_t offset, size_t length)
Calculate IP upper-layer checksum over a multi-part buffer.
Definition: ip.c:692
Ipv6Addr ipAddr
Unicast IPv6 address.
Definition: ndp.h:547
#define IPV6_DEFAULT_MTU
Definition: ipv6.h:109
systime_t ndpRouterAdvTickCounter
uint8_t n
void ndpProcessRouterSol(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, uint8_t hopLimit)
Router Solicitation message processing.
IP MIB module.
@ NDP_OPT_ROUTE_INFORMATION
Definition: ndp.h:221
NdpState state
Reachability state.
Definition: ndp.h:546
Ipv6AddrState ipv6GetLinkLocalAddrState(NetInterface *interface)
Get the state of the link-local address.
Definition: ipv6.c:297
void * ndpGetOption(uint8_t *options, size_t length, uint8_t type)
Search a NDP message for a given option.
Definition: ndp_misc.c:641
@ NDP_OPT_PREFIX_INFORMATION
Definition: ndp.h:218
error_t netBufferSetLength(NetBuffer *buffer, size_t length)
Adjust the length of a multi-part buffer.
Definition: net_mem.c:320
#define macCompAddr(macAddr1, macAddr2)
Definition: ethernet.h:130
uint8_t message[]
Definition: chap.h:152
error_t ndpCheckOptions(const uint8_t *options, size_t length)
Check NDP message options.
Definition: ndp_misc.c:683
__start_packed struct @5 NdpOption
Neighbor Discovery option general format.
systime_t timeout
Timeout value.
void ndpDumpRouterAdvMessage(const NdpRouterAdvMessage *message)
Dump Router Advertisement message for debugging purpose.
Definition: ndp.c:1967
error_t ipv6SendDatagram(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send an IPv6 datagram.
Definition: ipv6.c:1636
void ndpRouterAdvLinkChangeEvent(NdpRouterAdvContext *context)
Callback function for link change event.
@ IPV6_ADDR_STATE_PREFERRED
An address assigned to an interface whose use is unrestricted.
Definition: ipv6.h:169
#define PRIuSIZE
unsigned int uint_t
Definition: compiler_port.h:45
Helper functions for router advertisement service.
TCP/IP stack core.
NetInterface * nicGetLogicalInterface(NetInterface *interface)
Retrieve logical interface.
Definition: nic.c:52
__start_packed struct @1 NdpRouterAdvMessage
Router Advertisement message.
__start_packed struct @0 Ipv6Addr
IPv6 network address.
@ NDP_OPT_6LOWPAN_CONTEXT
Definition: ndp.h:224
const MacAddr MAC_UNSPECIFIED_ADDR
Definition: ethernet.c:55
systime_t timeout
Timeout value.
Definition: ndp.h:551
Debugging facilities.
bool_t isRouter
A flag indicating whether the neighbor is a router or a host.
Definition: ndp.h:549
systime_t osGetSystemTime(void)
Retrieve system time.