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-2024 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.4.4
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?
100  if(context->routerAdvCount < NDP_MAX_INITIAL_RTR_ADVERTISEMENTS)
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
105  context->timeout = MIN(context->timeout,
107  }
108 
109  //Increment counter
110  context->routerAdvCount++;
111  }
112  }
113  }
114 }
115 
116 
117 /**
118  * @brief Callback function for link change event
119  * @param[in] context Pointer to the RA service context
120  **/
121 
123 {
124  NetInterface *interface;
125 
126  //Make sure the RA service has been properly instantiated
127  if(context == NULL)
128  return;
129 
130  //Point to the underlying network interface
131  interface = context->settings.interface;
132 
133  //Reset variables
134  context->timestamp = osGetSystemTime();
135  context->timeout = 0;
136  context->routerAdvCount = 0;
137 
138  //Default Hop Limit value
139  if(context->settings.curHopLimit != 0)
140  {
141  interface->ipv6Context.curHopLimit = context->settings.curHopLimit;
142  }
143 
144  //The time a node assumes a neighbor is reachable
145  if(context->settings.reachableTime != 0)
146  {
147  interface->ndpContext.reachableTime = context->settings.reachableTime;
148  }
149 
150  //The time between retransmissions of NS messages
151  if(context->settings.retransTimer != 0)
152  {
153  interface->ndpContext.retransTimer = context->settings.retransTimer;
154  }
155 }
156 
157 
158 /**
159  * @brief Router Solicitation message processing
160  * @param[in] interface Underlying network interface
161  * @param[in] pseudoHeader IPv6 pseudo header
162  * @param[in] buffer Multi-part buffer containing the Router Advertisement message
163  * @param[in] offset Offset to the first byte of the message
164  * @param[in] ancillary Additional options passed to the stack along with
165  * the packet
166  **/
167 
169  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
170  size_t offset, const NetRxAncillary *ancillary)
171 {
172  error_t error;
173  uint_t n;
174  size_t length;
175  systime_t time;
176  systime_t delay;
177  NdpRouterAdvContext *context;
179  NdpLinkLayerAddrOption *option;
180  NdpNeighborCacheEntry *entry;
181 
182  //Point to the RA service context
183  context = interface->ndpRouterAdvContext;
184 
185  //A host must silently discard any received Router Solicitation
186  if(context == NULL)
187  return;
188 
189  //Get current time
190  time = osGetSystemTime();
191 
192  //Retrieve the length of the message
193  length = netBufferGetLength(buffer) - offset;
194 
195  //Check the length of the Router Solicitation message
196  if(length < sizeof(NdpRouterSolMessage))
197  return;
198 
199  //Point to the beginning of the message
200  message = netBufferAt(buffer, offset, length);
201  //Sanity check
202  if(message == NULL)
203  return;
204 
205  //Debug message
206  TRACE_INFO("Router Solicitation message received (%" PRIuSIZE " bytes)...\r\n",
207  length);
208 
209  //Dump message contents for debugging purpose
211 
212  //The IPv6 Hop Limit field must have a value of 255 to ensure that the
213  //packet has not been forwarded by a router
214  if(ancillary->ttl != NDP_HOP_LIMIT)
215  return;
216 
217  //ICMPv6 Code must be 0
218  if(message->code)
219  return;
220 
221  //Calculate the length of the Options field
222  length -= sizeof(NdpRouterSolMessage);
223 
224  //Parse Options field
225  error = ndpCheckOptions(message->options, length);
226  //All included options must have a length that is greater than zero
227  if(error)
228  return;
229 
230  //Search for the Source Link-Layer Address option
231  option = ndpGetOption(message->options,
233 
234  //Source Link-Layer Address option found?
235  if(option != NULL && option->length == 1)
236  {
237  //Debug message
238  TRACE_DEBUG(" Source Link-Layer Address = %s\r\n",
239  macAddrToString(&option->linkLayerAddr, NULL));
240 
241  //The Source Link-Layer Address option must not be included when the
242  //source IP address is the unspecified address
243  if(ipv6CompAddr(&pseudoHeader->srcAddr, &IPV6_UNSPECIFIED_ADDR))
244  return;
245 
246  //Search the Neighbor Cache for the source address of the solicitation
247  entry = ndpFindNeighborCacheEntry(interface, &pseudoHeader->srcAddr);
248 
249  //No matching entry found?
250  if(entry == NULL)
251  {
252  //Check whether Neighbor Discovery protocol is enabled
253  if(interface->ndpContext.enable)
254  {
255  //Create a new entry
256  entry = ndpCreateNeighborCacheEntry(interface);
257 
258  //Neighbor Cache entry successfully created?
259  if(entry != NULL)
260  {
261  //Record the IPv6 and the corresponding MAC address
262  entry->ipAddr = pseudoHeader->srcAddr;
263  entry->macAddr = option->linkLayerAddr;
264 
265  //The IsRouter flag must be set to FALSE
266  entry->isRouter = FALSE;
267 
268  //Enter the STALE state
270  }
271  }
272  }
273  else
274  {
275  //If a Neighbor Cache entry for the solicitation's sender exists the
276  //entry's IsRouter flag must be set to FALSE
277  entry->isRouter = FALSE;
278 
279  //INCOMPLETE state?
280  if(entry->state == NDP_STATE_INCOMPLETE)
281  {
282  //Record link-layer address
283  entry->macAddr = option->linkLayerAddr;
284 
285  //Send all the packets that are pending for transmission
286  n = ndpSendQueuedPackets(interface, entry);
287 
288  //Check whether any packets have been sent
289  if(n > 0)
290  {
291  //Start delay timer
293  //Switch to the DELAY state
295  }
296  else
297  {
298  //Enter the STALE state
300  }
301  }
302  //REACHABLE, STALE, DELAY or PROBE state?
303  else
304  {
305  //Different link-layer address than cached?
306  if(!macCompAddr(&entry->macAddr, &option->linkLayerAddr))
307  {
308  //Update link-layer address
309  entry->macAddr = option->linkLayerAddr;
310 
311  //Enter the STALE state
313  }
314  }
315  }
316  }
317 
318  //Upon receipt of a Router Solicitation, compute a random delay within the
319  //range 0 through MAX_RA_DELAY_TIME
321 
322  //If the computed value corresponds to a time later than the time the next
323  //multicast Router Advertisement is scheduled to be sent, ignore the random
324  //delay and send the advertisement at the already-scheduled time
325  if(timeCompare(time + delay, context->timestamp + context->timeout) > 0)
326  return;
327 
328  //Check whether the router sent a multicast Router Advertisement (solicited
329  //or unsolicited) within the last MIN_DELAY_BETWEEN_RAS seconds
330  if(timeCompare(time, context->timestamp + NDP_MIN_DELAY_BETWEEN_RAS) < 0)
331  {
332  //Schedule the advertisement to be sent at a time corresponding to
333  //MIN_DELAY_BETWEEN_RAS plus the random value after the previous
334  //advertisement was sent. This ensures that the multicast Router
335  //Advertisements are rate limited
336  context->timeout = NDP_MIN_DELAY_BETWEEN_RAS + delay;
337  }
338  else
339  {
340  //Schedule the sending of a Router Advertisement at the time given by the
341  //random value
342  context->timeout = time + delay - context->timestamp;
343  }
344 }
345 
346 
347 /**
348  * @brief Send a Router Advertisement message
349  * @param[in] context Pointer to the RA service context
350  * @param[in] routerLifetime Router Lifetime field
351  * @return Error code
352  **/
353 
355 {
356  error_t error;
357  uint_t i;
358  uint32_t n;
359  size_t offset;
360  size_t length;
361  NetBuffer *buffer;
362  NetInterface *interface;
364  NdpRouterAdvSettings *settings;
365  Ipv6PseudoHeader pseudoHeader;
366  NetTxAncillary ancillary;
367 #if (ETH_SUPPORT == ENABLED)
368  NetInterface *logicalInterface;
369 #endif
370 
371  //Point to the underlying network interface
372  interface = context->settings.interface;
373  //Point to the router configuration variables
374  settings = &context->settings;
375 
376  //The destination address is typically the all-nodes multicast address
377  pseudoHeader.destAddr = IPV6_LINK_LOCAL_ALL_NODES_ADDR;
378 
379  //Routers must use their link-local address as the source for Router
380  //Advertisement messages so that hosts can uniquely identify routers
381  error = ipv6SelectSourceAddr(&interface, &pseudoHeader.destAddr,
382  &pseudoHeader.srcAddr);
383 
384  //No link-local address assigned to the interface?
385  if(error)
386  return error;
387 
388  //Compute the maximum size of the Router Advertisement message
389  length = IPV6_DEFAULT_MTU - sizeof(Ipv6Header);
390 
391  //Allocate a memory buffer to hold the Router Advertisement message
392  buffer = ipAllocBuffer(length, &offset);
393  //Failed to allocate memory?
394  if(buffer == NULL)
395  return ERROR_OUT_OF_MEMORY;
396 
397  //Point to the beginning of the message
398  message = netBufferAt(buffer, offset, 0);
399 
400  //Format Router Advertisement message
402  message->code = 0;
403  message->checksum = 0;
404  message->curHopLimit = settings->curHopLimit;
405  message->m = settings->managedFlag;
406  message->o = settings->otherConfigFlag;
407  message->h = settings->homeAgentFlag;
408  message->prf = settings->preference;
409  message->p = settings->proxyFlag;
410  message->reserved = 0;
411  message->routerLifetime = htons(routerLifetime);
412  message->reachableTime = htonl(settings->reachableTime);
413  message->retransTimer = htonl(settings->retransTimer);
414 
415  //If the Router Lifetime is zero, the preference value must be set to
416  //zero by the sender
417  if(routerLifetime == 0)
419 
420  //Length of the message, excluding any option
421  length = sizeof(NdpRouterAdvMessage);
422 
423 #if (ETH_SUPPORT == ENABLED)
424  //Point to the logical interface
425  logicalInterface = nicGetLogicalInterface(interface);
426 
427  //Check whether a MAC address has been assigned to the interface
428  if(!macCompAddr(&logicalInterface->macAddr, &MAC_UNSPECIFIED_ADDR))
429  {
430  //Add Source Link-Layer Address option
432  &logicalInterface->macAddr, sizeof(MacAddr));
433  }
434 #endif
435 
436  //A value of zero indicates that no MTU option is sent
437  if(settings->linkMtu > 0)
438  {
439  NdpMtuOption mtuOption;
440 
441  //The MTU option specifies the recommended MTU for the link
442  mtuOption.reserved = 0;
443  mtuOption.mtu = htonl(settings->linkMtu);
444 
445  //Add MTU option
447  (uint8_t *) &mtuOption + sizeof(NdpOption),
448  sizeof(NdpMtuOption) - sizeof(NdpOption));
449  }
450 
451  //Loop through the list of IPv6 prefixes
452  for(i = 0; i < settings->prefixListLength; i++)
453  {
454  NdpPrefixInfoOption prefixInfoOption;
455 
456  //The Prefix Information option provide hosts with on-link prefixes and
457  //prefixes for Address Autoconfiguration
458  prefixInfoOption.prefixLength = settings->prefixList[i].length;
459  prefixInfoOption.l = settings->prefixList[i].onLinkFlag;
460  prefixInfoOption.a = settings->prefixList[i].autonomousFlag;
461  prefixInfoOption.r = 0;
462  prefixInfoOption.reserved1 = 0;
463  prefixInfoOption.validLifetime = htonl(settings->prefixList[i].validLifetime);
464  prefixInfoOption.preferredLifetime = htonl(settings->prefixList[i].preferredLifetime);
465  prefixInfoOption.reserved2 = 0;
466  prefixInfoOption.prefix = settings->prefixList[i].prefix;
467 
468  //Add Prefix Information option (PIO)
470  (uint8_t *) &prefixInfoOption + sizeof(NdpOption),
471  sizeof(NdpPrefixInfoOption) - sizeof(NdpOption));
472  }
473 
474  //Loop through the list of routes
475  for(i = 0; i < settings->routeListLength; i++)
476  {
477  NdpRouteInfoOption routeInfoOption;
478 
479  //The Route Information option specifies prefixes that are reachable via
480  //the router
481  routeInfoOption.prefixLength = settings->routeList[i].length;
482  routeInfoOption.reserved1 = 0;
483  routeInfoOption.prf = settings->routeList[i].preference;
484  routeInfoOption.reserved2 = 0;
485  routeInfoOption.routeLifetime = htonl(settings->routeList[i].routeLifetime);
486  routeInfoOption.prefix = settings->routeList[i].prefix;
487 
488  //Add Route Information option (RIO)
490  (uint8_t *) &routeInfoOption + sizeof(NdpOption),
491  sizeof(NdpRouteInfoOption) - sizeof(NdpOption));
492  }
493 
494  //Loop through the list of 6LoWPAN compression contexts
495  for(i = 0; i < settings->contextListLength; i++)
496  {
497  NdpContextOption contextOption;
498 
499  //The 6LoWPAN Context option (6CO) carries prefix information for LoWPAN
500  //header compression
501  contextOption.contextLength = settings->contextList[i].length;
502  contextOption.reserved1 = 0;
503  contextOption.c = settings->contextList[i].compression;
504  contextOption.cid = settings->contextList[i].cid;
505  contextOption.reserved2 = 0;
506  contextOption.validLifetime = htons(settings->contextList[i].validLifetime);
507  contextOption.contextPrefix = settings->contextList[i].prefix;
508 
509  //Calculate the length of the option in bytes
510  n = sizeof(NdpContextOption) - sizeof(Ipv6Addr) + (contextOption.contextLength / 8);
511 
512  //Add 6LoWPAN Context option (6CO)
514  (uint8_t *) &contextOption + sizeof(NdpOption), n - sizeof(NdpOption));
515  }
516 
517  //Any registered callback?
518  if(context->settings.addOptionsCallback != NULL)
519  {
520  //Invoke user callback function
521  context->settings.addOptionsCallback(context, message, &length);
522  }
523 
524  //Adjust the length of the multi-part buffer
525  netBufferSetLength(buffer, offset + length);
526 
527  //Format IPv6 pseudo header
528  pseudoHeader.length = htonl(length);
529  pseudoHeader.reserved[0] = 0;
530  pseudoHeader.reserved[1] = 0;
531  pseudoHeader.reserved[2] = 0;
532  pseudoHeader.nextHeader = IPV6_ICMPV6_HEADER;
533 
534  //Calculate ICMPv6 header checksum
535  message->checksum = ipCalcUpperLayerChecksumEx(&pseudoHeader,
536  sizeof(Ipv6PseudoHeader), buffer, offset, length);
537 
538  //Total number of ICMP messages which this entity attempted to send
539  IP_MIB_INC_COUNTER32(icmpv6Stats.icmpStatsOutMsgs, 1);
540  //Increment per-message type ICMP counter
541  IP_MIB_INC_COUNTER32(icmpv6MsgStatsTable.icmpMsgStatsOutPkts[ICMPV6_TYPE_ROUTER_ADV], 1);
542 
543  //Debug message
544  TRACE_INFO("Sending Router Advertisement message (%" PRIuSIZE " bytes)...\r\n",
545  length);
546 
547  //Dump message contents for debugging purpose
549 
550  //Additional options can be passed to the stack along with the packet
551  ancillary = NET_DEFAULT_TX_ANCILLARY;
552 
553  //By setting the Hop Limit to 255, Neighbor Discovery is immune to off-link
554  //senders that accidentally or intentionally send NDP messages (refer to
555  //RFC 4861, section 3.1)
556  ancillary.ttl = NDP_HOP_LIMIT;
557 
558  //Send Router Advertisement message
559  error = ipv6SendDatagram(interface, &pseudoHeader, buffer, offset,
560  &ancillary);
561 
562  //Free previously allocated memory
563  netBufferFree(buffer);
564 
565  //Return status code
566  return error;
567 }
568 
569 #endif
@ ICMPV6_TYPE_ROUTER_ADV
Definition: icmpv6.h:63
NdpNeighborCacheEntry * ndpFindNeighborCacheEntry(NetInterface *interface, const Ipv6Addr *ipAddr)
Search the Neighbor cache for a given IPv6 address.
Definition: ndp_cache.c:154
#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:711
@ NDP_ROUTER_SEL_PREFERENCE_MEDIUM
Definition: ndp.h:236
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Definition: net_misc.c:71
#define NDP_HOP_LIMIT
Definition: ndp.h:199
@ NDP_STATE_STALE
Definition: ndp.h:252
Helper functions for NDP (Neighbor Discovery Protocol)
@ 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:2166
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t message[]
Definition: chap.h:154
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:605
@ NDP_OPT_SOURCE_LINK_LAYER_ADDR
Definition: ndp.h:216
#define Ipv6Header
Definition: ipv6.h:36
Ipv6Addr
Definition: ipv6.h:260
void ndpRouterAdvTick(NdpRouterAdvContext *context)
RA service timer handler.
Neighbor cache entry.
Definition: ndp.h:549
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
#define ipv6CompAddr(ipAddr1, ipAddr2)
Definition: ipv6.h:127
@ IPV6_ICMPV6_HEADER
Definition: ipv6.h:193
NdpContextOption
Definition: ndp.h:520
#define timeCompare(t1, t2)
Definition: os_port.h:40
#define NDP_DELAY_FIRST_PROBE_TIME
Definition: ndp.h:193
Router advertisement service.
#define FALSE
Definition: os_port.h:46
#define NdpRouterAdvContext
void ndpProcessRouterSol(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Router Solicitation message processing.
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:948
MacAddr macAddr
Link layer address associated with the IPv6 address.
Definition: ndp.h:552
NdpRouterAdvMessage
Definition: ndp.h:310
error_t
Error codes.
Definition: error.h:43
uint16_t routerLifetime
Definition: ndp.h:306
#define Ipv6PseudoHeader
Definition: ipv6.h:42
error_t ipv6SelectSourceAddr(NetInterface **interface, const Ipv6Addr *destAddr, Ipv6Addr *srcAddr)
IPv6 source address selection.
Definition: ipv6_misc.c:870
NdpOption
Definition: ndp.h:379
char_t * macAddrToString(const MacAddr *macAddr, char_t *str)
Convert a MAC address to a dash delimited string.
Definition: ethernet.c:919
NdpNeighborCacheEntry * ndpCreateNeighborCacheEntry(NetInterface *interface)
Create a new entry in the Neighbor cache.
Definition: ndp_cache.c:72
const Ipv6Addr IPV6_LINK_LOCAL_ALL_NODES_ADDR
Definition: ipv6.c:74
#define NetRxAncillary
Definition: net_misc.h:40
#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
NdpMtuOption
Definition: ndp.h:445
uint_t ndpSendQueuedPackets(NetInterface *interface, NdpNeighborCacheEntry *entry)
Send packets that are waiting for address resolution.
Definition: ndp_cache.c:350
@ 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
NdpRouterSolMessage
Definition: ndp.h:278
#define NDP_MAX_RA_DELAY_TIME
Definition: ndp.h:109
#define TRACE_INFO(...)
Definition: debug.h:95
uint8_t length
Definition: tcp.h:368
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:63
Neighbor and destination cache management.
MacAddr
Definition: ethernet.h:195
NdpRouteInfoOption
Definition: ndp.h:468
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 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:686
Ipv6Addr ipAddr
Unicast IPv6 address.
Definition: ndp.h:551
NdpLinkLayerAddrOption
Definition: ndp.h:391
#define IPV6_DEFAULT_MTU
Definition: ipv6.h:115
systime_t ndpRouterAdvTickCounter
uint8_t n
error_t ipv6SendDatagram(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send an IPv6 datagram.
Definition: ipv6.c:1703
IP MIB module.
@ NDP_OPT_ROUTE_INFORMATION
Definition: ndp.h:221
NdpState state
Reachability state.
Definition: ndp.h:550
Ipv6AddrState ipv6GetLinkLocalAddrState(NetInterface *interface)
Get the state of the link-local address.
Definition: ipv6.c:327
void * ndpGetOption(uint8_t *options, size_t length, uint8_t type)
Search a NDP message for a given option.
Definition: ndp_misc.c:653
@ 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:322
#define macCompAddr(macAddr1, macAddr2)
Definition: ethernet.h:130
error_t ndpCheckOptions(const uint8_t *options, size_t length)
Check NDP message options.
Definition: ndp_misc.c:696
void ndpDumpRouterAdvMessage(const NdpRouterAdvMessage *message)
Dump Router Advertisement message for debugging purpose.
Definition: ndp.c:2180
void * netBufferAt(const NetBuffer *buffer, size_t offset, size_t length)
Returns a pointer to a data segment.
Definition: net_mem.c:418
void ndpRouterAdvLinkChangeEvent(NdpRouterAdvContext *context)
Callback function for link change event.
void ndpChangeState(NdpNeighborCacheEntry *entry, NdpState newState)
Update Neighbor cache entry state.
Definition: ndp_cache.c:53
@ IPV6_ADDR_STATE_PREFERRED
An address assigned to an interface whose use is unrestricted.
Definition: ipv6.h:175
#define PRIuSIZE
unsigned int uint_t
Definition: compiler_port.h:50
NdpPrefixInfoOption
Definition: ndp.h:418
Helper functions for router advertisement service.
TCP/IP stack core.
NetInterface * nicGetLogicalInterface(NetInterface *interface)
Retrieve logical interface.
Definition: nic.c:53
@ NDP_OPT_6LOWPAN_CONTEXT
Definition: ndp.h:224
const MacAddr MAC_UNSPECIFIED_ADDR
Definition: ethernet.c:53
systime_t timeout
Timeout value.
Definition: ndp.h:555
Debugging facilities.
bool_t isRouter
A flag indicating whether the neighbor is a router or a host.
Definition: ndp.h:553
systime_t osGetSystemTime(void)
Retrieve system time.