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-2026 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.6.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 "debug.h"
45 
46 //Check TCP/IP stack configuration
47 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
48 
49 
50 /**
51  * @brief RA service timer handler
52  * @param[in] context Pointer to the RA service context
53  **/
54 
56 {
58  NetInterface *interface;
59 
60  //Make sure the RA service has been properly instantiated
61  if(context == NULL)
62  return;
63 
64  //Point to the underlying network interface
65  interface = context->interface;
66 
67  //Get current time
69 
70  //Make sure that the link is up and the service is running
71  if(interface->linkState && context->running)
72  {
73  //Make sure that a valid link-local address has been assigned to the
74  //interface
76  {
77  //Check current time
78  if(timeCompare(time, context->timestamp + context->timeout) >= 0)
79  {
80  //Send an unsolicited Router Advertisement
81  ndpSendRouterAdv(context, context->defaultLifetime);
82 
83  //Save the time at which the message was sent
84  context->timestamp = time;
85 
86  //Whenever a multicast advertisement is sent from an interface, the
87  //timer is reset to a uniformly distributed random value between
88  //MinRtrAdvInterval and MaxRtrAdvInterval
89  context->timeout = netGenerateRandRange(context->netContext,
90  context->minRtrAdvInterval, context->maxRtrAdvInterval);
91 
92  //First Router Advertisements to be sent from this interface?
93  if(context->routerAdvCount < NDP_MAX_INITIAL_RTR_ADVERTISEMENTS)
94  {
95  //For the first few advertisements sent from an interface when it
96  //becomes an advertising interface, the randomly chosen interval
97  //should not be greater than MAX_INITIAL_RTR_ADVERT_INTERVAL
98  context->timeout = MIN(context->timeout,
100  }
101 
102  //Increment counter
103  context->routerAdvCount++;
104  }
105  }
106  }
107 }
108 
109 
110 /**
111  * @brief Callback function for link change event
112  * @param[in] context Pointer to the RA service context
113  **/
114 
116 {
117  NetInterface *interface;
118 
119  //Make sure the RA service has been properly instantiated
120  if(context == NULL)
121  return;
122 
123  //Point to the underlying network interface
124  interface = context->interface;
125 
126  //Reset variables
127  context->timestamp = osGetSystemTime();
128  context->timeout = 0;
129  context->routerAdvCount = 0;
130 
131  //Default Hop Limit value
132  if(context->curHopLimit != 0)
133  {
134  interface->ipv6Context.curHopLimit = context->curHopLimit;
135  }
136 
137  //The time a node assumes a neighbor is reachable
138  if(context->reachableTime != 0)
139  {
140  interface->ndpContext.reachableTime = context->reachableTime;
141  }
142 
143  //The time between retransmissions of NS messages
144  if(context->retransTimer != 0)
145  {
146  interface->ndpContext.retransTimer = context->retransTimer;
147  }
148 }
149 
150 
151 /**
152  * @brief Router Solicitation message processing
153  * @param[in] interface Underlying network interface
154  * @param[in] pseudoHeader IPv6 pseudo header
155  * @param[in] buffer Multi-part buffer containing the Router Advertisement message
156  * @param[in] offset Offset to the first byte of the message
157  * @param[in] ancillary Additional options passed to the stack along with
158  * the packet
159  **/
160 
162  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
163  size_t offset, const NetRxAncillary *ancillary)
164 {
165  error_t error;
166  uint_t n;
167  size_t length;
168  systime_t time;
169  systime_t delay;
170  NdpRouterAdvContext *context;
172  NdpLinkLayerAddrOption *option;
173  NdpNeighborCacheEntry *entry;
174 
175  //Point to the RA service context
176  context = interface->ndpRouterAdvContext;
177 
178  //A host must silently discard any received Router Solicitation
179  if(context == NULL)
180  return;
181 
182  //Get current time
183  time = osGetSystemTime();
184 
185  //Retrieve the length of the message
186  length = netBufferGetLength(buffer) - offset;
187 
188  //Check the length of the Router Solicitation message
189  if(length < sizeof(NdpRouterSolMessage))
190  return;
191 
192  //Point to the beginning of the message
193  message = netBufferAt(buffer, offset, length);
194  //Sanity check
195  if(message == NULL)
196  return;
197 
198  //Debug message
199  TRACE_INFO("Router Solicitation message received (%" PRIuSIZE " bytes)...\r\n",
200  length);
201 
202  //Dump message contents for debugging purpose
204 
205  //The IPv6 Hop Limit field must have a value of 255 to ensure that the
206  //packet has not been forwarded by a router
207  if(ancillary->ttl != NDP_HOP_LIMIT)
208  return;
209 
210  //ICMPv6 Code must be 0
211  if(message->code)
212  return;
213 
214  //Calculate the length of the Options field
215  length -= sizeof(NdpRouterSolMessage);
216 
217  //Parse Options field
218  error = ndpCheckOptions(message->options, length);
219  //All included options must have a length that is greater than zero
220  if(error)
221  return;
222 
223  //Search for the Source Link-Layer Address option
224  option = ndpGetOption(message->options,
226 
227  //Source Link-Layer Address option found?
228  if(option != NULL && option->length == 1)
229  {
230  //Debug message
231  TRACE_DEBUG(" Source Link-Layer Address = %s\r\n",
232  macAddrToString(&option->linkLayerAddr, NULL));
233 
234  //The Source Link-Layer Address option must not be included when the
235  //source IP address is the unspecified address
236  if(ipv6CompAddr(&pseudoHeader->srcAddr, &IPV6_UNSPECIFIED_ADDR))
237  return;
238 
239  //Search the Neighbor Cache for the source address of the solicitation
240  entry = ndpFindNeighborCacheEntry(interface, &pseudoHeader->srcAddr);
241 
242  //No matching entry found?
243  if(entry == NULL)
244  {
245  //Check whether Neighbor Discovery protocol is enabled
246  if(interface->ndpContext.enable)
247  {
248  //Create a new entry
249  entry = ndpCreateNeighborCacheEntry(interface);
250 
251  //Neighbor Cache entry successfully created?
252  if(entry != NULL)
253  {
254  //Record the IPv6 and the corresponding MAC address
255  entry->ipAddr = pseudoHeader->srcAddr;
256  entry->macAddr = option->linkLayerAddr;
257 
258  //The IsRouter flag must be set to FALSE
259  entry->isRouter = FALSE;
260 
261  //Enter the STALE state
263  }
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 
278  //Send all the packets that are pending for transmission
279  n = ndpSendQueuedPackets(interface, entry);
280 
281  //Check whether any packets have been sent
282  if(n > 0)
283  {
284  //Start delay timer
286  //Switch to the DELAY state
288  }
289  else
290  {
291  //Enter the STALE state
293  }
294  }
295  //REACHABLE, STALE, DELAY or PROBE state?
296  else
297  {
298  //Different link-layer address than cached?
299  if(!macCompAddr(&entry->macAddr, &option->linkLayerAddr))
300  {
301  //Update link-layer address
302  entry->macAddr = option->linkLayerAddr;
303 
304  //Enter the STALE state
306  }
307  }
308  }
309  }
310 
311  //Upon receipt of a Router Solicitation, compute a random delay within the
312  //range 0 through MAX_RA_DELAY_TIME
313  delay = netGenerateRandRange(context->netContext,0, NDP_MAX_RA_DELAY_TIME);
314 
315  //If the computed value corresponds to a time later than the time the next
316  //multicast Router Advertisement is scheduled to be sent, ignore the random
317  //delay and send the advertisement at the already-scheduled time
318  if(timeCompare(time + delay, context->timestamp + context->timeout) > 0)
319  return;
320 
321  //Check whether the router sent a multicast Router Advertisement (solicited
322  //or unsolicited) within the last MIN_DELAY_BETWEEN_RAS seconds
323  if(timeCompare(time, context->timestamp + NDP_MIN_DELAY_BETWEEN_RAS) < 0)
324  {
325  //Schedule the advertisement to be sent at a time corresponding to
326  //MIN_DELAY_BETWEEN_RAS plus the random value after the previous
327  //advertisement was sent. This ensures that the multicast Router
328  //Advertisements are rate limited
329  context->timeout = NDP_MIN_DELAY_BETWEEN_RAS + delay;
330  }
331  else
332  {
333  //Schedule the sending of a Router Advertisement at the time given by the
334  //random value
335  context->timeout = time + delay - context->timestamp;
336  }
337 }
338 
339 
340 /**
341  * @brief Send a Router Advertisement message
342  * @param[in] context Pointer to the RA service context
343  * @param[in] routerLifetime Router Lifetime field
344  * @return Error code
345  **/
346 
348 {
349  error_t error;
350  uint_t i;
351  uint32_t n;
352  size_t offset;
353  size_t length;
354  NetBuffer *buffer;
355  NetInterface *interface;
357  Ipv6PseudoHeader pseudoHeader;
358  NetTxAncillary ancillary;
359 #if (ETH_SUPPORT == ENABLED)
360  NetInterface *logicalInterface;
361 #endif
362 
363  //Point to the underlying network interface
364  interface = context->interface;
365 
366  //The destination address is typically the all-nodes multicast address
367  pseudoHeader.destAddr = IPV6_LINK_LOCAL_ALL_NODES_ADDR;
368 
369  //Routers must use their link-local address as the source for Router
370  //Advertisement messages so that hosts can uniquely identify routers
371  error = ipv6SelectSourceAddr(interface->netContext, &interface,
372  &pseudoHeader.destAddr, &pseudoHeader.srcAddr);
373 
374  //No link-local address assigned to the interface?
375  if(error)
376  return error;
377 
378  //Compute the maximum size of the Router Advertisement message
379  length = IPV6_DEFAULT_MTU - sizeof(Ipv6Header);
380 
381  //Allocate a memory buffer to hold the Router Advertisement message
382  buffer = ipAllocBuffer(length, &offset);
383  //Failed to allocate memory?
384  if(buffer == NULL)
385  return ERROR_OUT_OF_MEMORY;
386 
387  //Point to the beginning of the message
388  message = netBufferAt(buffer, offset, 0);
389 
390  //Format Router Advertisement message
392  message->code = 0;
393  message->checksum = 0;
394  message->curHopLimit = context->curHopLimit;
395  message->m = context->managedFlag;
396  message->o = context->otherConfigFlag;
397  message->h = context->homeAgentFlag;
398  message->prf = context->preference;
399  message->p = context->proxyFlag;
400  message->reserved = 0;
401  message->routerLifetime = htons(routerLifetime);
402  message->reachableTime = htonl(context->reachableTime);
403  message->retransTimer = htonl(context->retransTimer);
404 
405  //If the Router Lifetime is zero, the preference value must be set to
406  //zero by the sender
407  if(routerLifetime == 0)
408  {
410  }
411 
412  //Length of the message, excluding any option
413  length = sizeof(NdpRouterAdvMessage);
414 
415 #if (ETH_SUPPORT == ENABLED)
416  //Point to the logical interface
417  logicalInterface = nicGetLogicalInterface(interface);
418 
419  //Check whether a MAC address has been assigned to the interface
420  if(!macCompAddr(&logicalInterface->macAddr, &MAC_UNSPECIFIED_ADDR))
421  {
422  //Add Source Link-Layer Address option
424  &logicalInterface->macAddr, sizeof(MacAddr));
425  }
426 #endif
427 
428  //A value of zero indicates that no MTU option is sent
429  if(context->linkMtu > 0)
430  {
431  NdpMtuOption mtuOption;
432 
433  //The MTU option specifies the recommended MTU for the link
434  mtuOption.reserved = 0;
435  mtuOption.mtu = htonl(context->linkMtu);
436 
437  //Add MTU option
439  (uint8_t *) &mtuOption + sizeof(NdpOption),
440  sizeof(NdpMtuOption) - sizeof(NdpOption));
441  }
442 
443  //Loop through the list of IPv6 prefixes
444  for(i = 0; i < context->prefixListLength; i++)
445  {
446  NdpPrefixInfoOption prefixInfoOption;
447 
448  //The Prefix Information option provide hosts with on-link prefixes and
449  //prefixes for Address Autoconfiguration
450  prefixInfoOption.prefixLength = context->prefixList[i].length;
451  prefixInfoOption.l = context->prefixList[i].onLinkFlag;
452  prefixInfoOption.a = context->prefixList[i].autonomousFlag;
453  prefixInfoOption.r = 0;
454  prefixInfoOption.reserved1 = 0;
455  prefixInfoOption.validLifetime = htonl(context->prefixList[i].validLifetime);
456  prefixInfoOption.preferredLifetime = htonl(context->prefixList[i].preferredLifetime);
457  prefixInfoOption.reserved2 = 0;
458  prefixInfoOption.prefix = context->prefixList[i].prefix;
459 
460  //Add Prefix Information option (PIO)
462  (uint8_t *) &prefixInfoOption + sizeof(NdpOption),
463  sizeof(NdpPrefixInfoOption) - sizeof(NdpOption));
464  }
465 
466  //Loop through the list of routes
467  for(i = 0; i < context->routeListLength; i++)
468  {
469  NdpRouteInfoOption routeInfoOption;
470 
471  //The Route Information option specifies prefixes that are reachable via
472  //the router
473  routeInfoOption.prefixLength = context->routeList[i].length;
474  routeInfoOption.reserved1 = 0;
475  routeInfoOption.prf = context->routeList[i].preference;
476  routeInfoOption.reserved2 = 0;
477  routeInfoOption.routeLifetime = htonl(context->routeList[i].routeLifetime);
478  routeInfoOption.prefix = context->routeList[i].prefix;
479 
480  //Add Route Information option (RIO)
482  (uint8_t *) &routeInfoOption + sizeof(NdpOption),
483  sizeof(NdpRouteInfoOption) - sizeof(NdpOption));
484  }
485 
486  //Loop through the list of 6LoWPAN compression contexts
487  for(i = 0; i < context->contextListLength; i++)
488  {
489  NdpContextOption contextOption;
490 
491  //The 6LoWPAN Context option (6CO) carries prefix information for LoWPAN
492  //header compression
493  contextOption.contextLength = context->contextList[i].length;
494  contextOption.reserved1 = 0;
495  contextOption.c = context->contextList[i].compression;
496  contextOption.cid = context->contextList[i].cid;
497  contextOption.reserved2 = 0;
498  contextOption.validLifetime = htons(context->contextList[i].validLifetime);
499  contextOption.contextPrefix = context->contextList[i].prefix;
500 
501  //Calculate the length of the option in bytes
502  n = sizeof(NdpContextOption) - sizeof(Ipv6Addr) + (contextOption.contextLength / 8);
503 
504  //Add 6LoWPAN Context option (6CO)
506  (uint8_t *) &contextOption + sizeof(NdpOption), n - sizeof(NdpOption));
507  }
508 
509  //Any registered callback?
510  if(context->addOptionsCallback != NULL)
511  {
512  //Invoke user callback function
513  context->addOptionsCallback(context, message, &length);
514  }
515 
516  //Adjust the length of the multi-part buffer
517  netBufferSetLength(buffer, offset + length);
518 
519  //Format IPv6 pseudo header
520  pseudoHeader.length = htonl(length);
521  pseudoHeader.reserved[0] = 0;
522  pseudoHeader.reserved[1] = 0;
523  pseudoHeader.reserved[2] = 0;
524  pseudoHeader.nextHeader = IPV6_ICMPV6_HEADER;
525 
526  //Calculate ICMPv6 header checksum
527  message->checksum = ipCalcUpperLayerChecksumEx(&pseudoHeader,
528  sizeof(Ipv6PseudoHeader), buffer, offset, length);
529 
530  //Total number of ICMP messages which this entity attempted to send
531  ICMPV6_STATS_INC_COUNTER32(outMsgs, 1);
532  //Increment per-message type ICMP counter
534 
535  //Debug message
536  TRACE_INFO("Sending Router Advertisement message (%" PRIuSIZE " bytes)...\r\n",
537  length);
538 
539  //Dump message contents for debugging purpose
541 
542  //Additional options can be passed to the stack along with the packet
543  ancillary = NET_DEFAULT_TX_ANCILLARY;
544 
545  //By setting the Hop Limit to 255, Neighbor Discovery is immune to off-link
546  //senders that accidentally or intentionally send NDP messages (refer to
547  //RFC 4861, section 3.1)
548  ancillary.ttl = NDP_HOP_LIMIT;
549 
550  //Send Router Advertisement message
551  error = ipv6SendDatagram(interface, &pseudoHeader, buffer, offset,
552  &ancillary);
553 
554  //Free previously allocated memory
555  netBufferFree(buffer);
556 
557  //Return status code
558  return error;
559 }
560 
561 #endif
@ ICMPV6_TYPE_ROUTER_ADV
Definition: icmpv6.h:81
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:716
@ NDP_ROUTER_SEL_PREFERENCE_MEDIUM
Definition: ndp.h:236
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Definition: net_misc.c:70
#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
void ndpDumpRouterSolMessage(const NdpRouterSolMessage *message)
Dump Router Solicitation message for debugging purpose.
Definition: ndp.c:2260
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:280
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:134
@ IPV6_ICMPV6_HEADER
Definition: ipv6.h:213
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
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
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:926
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:73
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:40
#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
uint32_t netGenerateRandRange(NetContext *context, uint32_t min, uint32_t max)
Generate a random value in the specified range.
Definition: net_misc.c:983
Helper functions for IPv6.
#define NetTxAncillary
Definition: net_misc.h:36
const Ipv6Addr IPV6_UNSPECIFIED_ADDR
Definition: ipv6.c:65
NdpRouterSolMessage
Definition: ndp.h:278
#define NDP_MAX_RA_DELAY_TIME
Definition: ndp.h:109
#define TRACE_INFO(...)
Definition: debug.h:105
uint8_t length
Definition: tcp.h:375
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:197
NdpRouteInfoOption
Definition: ndp.h:468
#define ICMPV6_STATS_INC_COUNTER32(name, value)
Definition: icmpv6.h:50
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:119
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:691
Ipv6Addr ipAddr
Unicast IPv6 address.
Definition: ndp.h:551
NdpLinkLayerAddrOption
Definition: ndp.h:391
#define IPV6_DEFAULT_MTU
Definition: ipv6.h:122
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:1716
@ 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:330
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:2274
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:195
#define PRIuSIZE
unsigned int uint_t
Definition: compiler_port.h:57
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:51
@ NDP_OPT_6LOWPAN_CONTEXT
Definition: ndp.h:224
error_t ipv6SelectSourceAddr(NetContext *context, NetInterface **interface, const Ipv6Addr *destAddr, Ipv6Addr *srcAddr)
IPv6 source address selection.
Definition: ipv6_misc.c:891
const MacAddr MAC_UNSPECIFIED_ADDR
Definition: ethernet.c:51
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.