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