Go to the documentation of this file.
32 #define TRACE_LEVEL NDP_TRACE_LEVEL
48 #if (IPV6_SUPPORT == ENABLED && NDP_ROUTER_ADV_SUPPORT == ENABLED)
70 interface = context->settings.interface;
72 settings = &context->settings;
78 if(interface->linkState && context->running)
91 context->timestamp =
time;
97 settings->maxRtrAdvInterval);
105 context->timeout =
MIN(context->timeout,
110 context->routerAdvCount++;
131 interface = context->settings.interface;
135 context->timeout = 0;
136 context->routerAdvCount = 0;
139 if(context->settings.curHopLimit != 0)
141 interface->ipv6Context.curHopLimit = context->settings.curHopLimit;
145 if(context->settings.reachableTime != 0)
147 interface->ndpContext.reachableTime = context->settings.reachableTime;
151 if(context->settings.retransTimer != 0)
153 interface->ndpContext.retransTimer = context->settings.retransTimer;
183 context = interface->ndpRouterAdvContext;
235 if(option != NULL && option->length == 1)
253 if(interface->ndpContext.enable)
262 entry->
ipAddr = pseudoHeader->srcAddr;
263 entry->
macAddr = option->linkLayerAddr;
283 entry->
macAddr = option->linkLayerAddr;
309 entry->
macAddr = option->linkLayerAddr;
325 if(
timeCompare(
time + delay, context->timestamp + context->timeout) > 0)
342 context->timeout =
time + delay - context->timestamp;
367 #if (ETH_SUPPORT == ENABLED)
372 interface = context->settings.interface;
374 settings = &context->settings;
382 &pseudoHeader.srcAddr);
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;
412 message->reachableTime =
htonl(settings->reachableTime);
423 #if (ETH_SUPPORT == ENABLED)
432 &logicalInterface->macAddr,
sizeof(
MacAddr));
437 if(settings->linkMtu > 0)
442 mtuOption.reserved = 0;
443 mtuOption.mtu =
htonl(settings->linkMtu);
447 (uint8_t *) &mtuOption +
sizeof(
NdpOption),
452 for(i = 0; i < settings->prefixListLength; i++)
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;
470 (uint8_t *) &prefixInfoOption +
sizeof(
NdpOption),
475 for(i = 0; i < settings->routeListLength; i++)
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;
490 (uint8_t *) &routeInfoOption +
sizeof(
NdpOption),
495 for(i = 0; i < settings->contextListLength; i++)
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;
518 if(context->settings.addOptionsCallback != NULL)
521 context->settings.addOptionsCallback(context,
message, &
length);
529 pseudoHeader.reserved[0] = 0;
530 pseudoHeader.reserved[1] = 0;
531 pseudoHeader.reserved[2] = 0;
NdpNeighborCacheEntry * ndpFindNeighborCacheEntry(NetInterface *interface, const Ipv6Addr *ipAddr)
Search the Neighbor cache for a given IPv6 address.
IPv6 (Internet Protocol Version 6)
#define NDP_MIN_DELAY_BETWEEN_RAS
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.
@ NDP_ROUTER_SEL_PREFERENCE_MEDIUM
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Helper functions for NDP (Neighbor Discovery Protocol)
#define IP_MIB_INC_COUNTER32(name, value)
void ndpDumpRouterSolMessage(const NdpRouterSolMessage *message)
Dump Router Solicitation message for debugging purpose.
Structure describing a buffer that spans multiple chunks.
void ndpAddOption(void *message, size_t *messageLen, uint8_t type, const void *value, size_t length)
Append an option to a NDP message.
@ NDP_OPT_SOURCE_LINK_LAYER_ADDR
void ndpRouterAdvTick(NdpRouterAdvContext *context)
RA service timer handler.
#define ipv6CompAddr(ipAddr1, ipAddr2)
#define timeCompare(t1, t2)
#define NDP_DELAY_FIRST_PROBE_TIME
Router advertisement service.
#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)
uint32_t netGenerateRandRange(uint32_t min, uint32_t max)
Generate a random value in the specified range.
MacAddr macAddr
Link layer address associated with the IPv6 address.
error_t ipv6SelectSourceAddr(NetInterface **interface, const Ipv6Addr *destAddr, Ipv6Addr *srcAddr)
IPv6 source address selection.
char_t * macAddrToString(const MacAddr *macAddr, char_t *str)
Convert a MAC address to a dash delimited string.
NdpNeighborCacheEntry * ndpCreateNeighborCacheEntry(NetInterface *interface)
Create a new entry in the Neighbor cache.
const Ipv6Addr IPV6_LINK_LOCAL_ALL_NODES_ADDR
#define NDP_MAX_INITIAL_RTR_ADVERTISEMENTS
void netBufferFree(NetBuffer *buffer)
Dispose a multi-part buffer.
uint_t ndpSendQueuedPackets(NetInterface *interface, NdpNeighborCacheEntry *entry)
Send packets that are waiting for address resolution.
Helper functions for IPv6.
const Ipv6Addr IPV6_UNSPECIFIED_ADDR
#define NDP_MAX_RA_DELAY_TIME
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
Neighbor and destination cache management.
NDP (Neighbor Discovery Protocol)
#define NDP_MAX_INITIAL_RTR_ADVERT_INTERVAL
uint32_t systime_t
System 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.
Ipv6Addr ipAddr
Unicast IPv6 address.
systime_t ndpRouterAdvTickCounter
error_t ipv6SendDatagram(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send an IPv6 datagram.
@ NDP_OPT_ROUTE_INFORMATION
NdpState state
Reachability state.
Ipv6AddrState ipv6GetLinkLocalAddrState(NetInterface *interface)
Get the state of the link-local address.
void * ndpGetOption(uint8_t *options, size_t length, uint8_t type)
Search a NDP message for a given option.
@ NDP_OPT_PREFIX_INFORMATION
error_t netBufferSetLength(NetBuffer *buffer, size_t length)
Adjust the length of a multi-part buffer.
#define macCompAddr(macAddr1, macAddr2)
error_t ndpCheckOptions(const uint8_t *options, size_t length)
Check NDP message options.
void ndpDumpRouterAdvMessage(const NdpRouterAdvMessage *message)
Dump Router Advertisement message for debugging purpose.
void * netBufferAt(const NetBuffer *buffer, size_t offset, size_t length)
Returns a pointer to a data segment.
void ndpRouterAdvLinkChangeEvent(NdpRouterAdvContext *context)
Callback function for link change event.
void ndpChangeState(NdpNeighborCacheEntry *entry, NdpState newState)
Update Neighbor cache entry state.
@ IPV6_ADDR_STATE_PREFERRED
An address assigned to an interface whose use is unrestricted.
Helper functions for router advertisement service.
NetInterface * nicGetLogicalInterface(NetInterface *interface)
Retrieve logical interface.
@ NDP_OPT_6LOWPAN_CONTEXT
const MacAddr MAC_UNSPECIFIED_ADDR
systime_t timeout
Timeout value.
bool_t isRouter
A flag indicating whether the neighbor is a router or a host.
systime_t osGetSystemTime(void)
Retrieve system time.