ipv6_routing.c
Go to the documentation of this file.
1 /**
2  * @file ipv6_routing.c
3  * @brief IPv6 routing
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 IPV6_TRACE_LEVEL
33 
34 //Dependencies
35 #include <limits.h>
36 #include "core/net.h"
37 #include "core/ip.h"
38 #include "ipv6/ipv6.h"
39 #include "ipv6/ipv6_misc.h"
40 #include "ipv6/ipv6_routing.h"
41 #include "ipv6/icmpv6.h"
42 #include "ipv6/ndp.h"
43 #include "debug.h"
44 
45 //Check TCP/IP stack configuration
46 #if (IPV6_SUPPORT == ENABLED && IPV6_ROUTING_SUPPORT == ENABLED)
47 
48 //IPv6 routing table
49 static Ipv6RoutingTableEntry ipv6RoutingTable[IPV6_ROUTING_TABLE_SIZE];
50 
51 
52 /**
53  * @brief Initialize IPv6 routing table
54  * @return Error code
55  **/
56 
58 {
59  //Clear the routing table
60  osMemset(ipv6RoutingTable, 0, sizeof(ipv6RoutingTable));
61 
62  //Successful initialization
63  return NO_ERROR;
64 }
65 
66 
67 /**
68  * @brief Enable routing for the specified interface
69  * @param[in] interface Underlying network interface
70  * @param[in] enable When the flag is set to TRUE, routing is enabled on the
71  * interface and the router can forward packets to or from the interface
72  * @return Error code
73  **/
74 
76 {
77  //Check parameters
78  if(interface == NULL)
80 
81  //Get exclusive access
83  //Enable or disable routing
84  interface->ipv6Context.isRouter = enable;
85  //Release exclusive access
87 
88  //Successful processing
89  return NO_ERROR;
90 }
91 
92 
93 /**
94  * @brief Add a new entry in the IPv6 routing table
95  * @param[in] prefix Network destination
96  * @param[in] prefixLen Length of the prefix, in bits
97  * @param[in] interface Network interface where to forward the packet
98  * @param[in] nextHop IPv6 address of the next hop
99  * @param[in] metric Metric value
100  * @return Error code
101  **/
102 
104  NetInterface *interface, const Ipv6Addr *nextHop, uint_t metric)
105 {
106  error_t error;
107  uint_t i;
108  Ipv6RoutingTableEntry *entry;
109  Ipv6RoutingTableEntry *firstFreeEntry;
110 
111  //Check parameters
112  if(prefix == NULL || interface == NULL)
114 
115  //Keep track of the first free entry
116  firstFreeEntry = NULL;
117 
118  //Get exclusive access
120 
121  //Loop through routing table entries
122  for(i = 0; i < IPV6_ROUTING_TABLE_SIZE; i++)
123  {
124  //Point to the current entry
125  entry = &ipv6RoutingTable[i];
126 
127  //Valid entry?
128  if(entry->valid)
129  {
130  //Check prefix length
131  if(entry->prefixLen == prefixLen)
132  {
133  //Check whether the current entry matches the specified destination
134  if(ipv6CompPrefix(&entry->prefix, prefix, prefixLen))
135  break;
136  }
137  }
138  else
139  {
140  //Keep track of the first free entry
141  if(firstFreeEntry == NULL)
142  firstFreeEntry = entry;
143  }
144  }
145 
146  //If the routing table does not contain the specified destination,
147  //then a new entry should be created
148  if(i >= IPV6_ROUTING_TABLE_SIZE)
149  entry = firstFreeEntry;
150 
151  //Check whether the routing table runs out of space
152  if(entry != NULL)
153  {
154  //Network destination
155  entry->prefix = *prefix;
156  entry->prefixLen = prefixLen;
157 
158  //Interface where to forward the packet
159  entry->interface = interface;
160 
161  //Address of the next hop
162  if(nextHop != NULL)
163  {
164  entry->nextHop = *nextHop;
165  }
166  else
167  {
169  }
170 
171  //Metric value
172  entry->metric = metric;
173  //The entry is now valid
174  entry->valid = TRUE;
175 
176  //Successful processing
177  error = NO_ERROR;
178  }
179  else
180  {
181  //The routing table is full
182  error = ERROR_FAILURE;
183  }
184 
185  //Release exclusive access
187 
188  //Return status code
189  return error;
190 }
191 
192 
193 /**
194  * @brief Remove an entry from the IPv6 routing table
195  * @param[in] prefix Network destination
196  * @param[in] prefixLen Length of the prefix, in bits
197  * @return Error code
198  **/
199 
201 {
202  error_t error;
203  uint_t i;
204  Ipv6RoutingTableEntry *entry;
205 
206  //Initialize status code
207  error = ERROR_NOT_FOUND;
208 
209  //Get exclusive access
211 
212  //Loop through routing table entries
213  for(i = 0; i < IPV6_ROUTING_TABLE_SIZE; i++)
214  {
215  //Point to the current entry
216  entry = &ipv6RoutingTable[i];
217 
218  //Valid entry?
219  if(entry->valid)
220  {
221  //Check prefix length
222  if(entry->prefixLen == prefixLen)
223  {
224  //Check whether the current entry matches the specified destination
225  if(ipv6CompPrefix(&entry->prefix, prefix, prefixLen))
226  {
227  //Delete current entry
228  entry->valid = FALSE;
229  //The route was successfully deleted from the routing table
230  error = NO_ERROR;
231  }
232  }
233  }
234  }
235 
236  //Release exclusive access
238 
239  //Return status code
240  return error;
241 }
242 
243 
244 /**
245  * @brief Delete all routes from the IPv6 routing table
246  * @return Error code
247  **/
248 
250 {
251  //Get exclusive access
253  //Clear the routing table
254  osMemset(ipv6RoutingTable, 0, sizeof(ipv6RoutingTable));
255  //Release exclusive access
257 
258  //Successful processing
259  return NO_ERROR;
260 }
261 
262 
263 /**
264  * @brief Forward an IPv6 packet
265  * @param[in] srcInterface Network interface on which the packet was received
266  * @param[in] ipPacket Multi-part buffer that holds the IPv6 packet to forward
267  * @param[in] ipPacketOffset Offset to the first byte of the IPv6 packet
268  * @return Error code
269  **/
270 
272  size_t ipPacketOffset)
273 {
274  error_t error;
275  uint_t i;
276  uint_t metric;
278  bool_t match;
279  size_t length;
280  size_t destOffset;
281  NetInterface *destInterface;
282  NetBuffer *destBuffer;
283  Ipv6Header *ipHeader;
284  Ipv6RoutingTableEntry *entry;
286 #if (ETH_SUPPORT == ENABLED)
287  NetInterface *physicalInterface;
288 #endif
289 
290  //Silently drop any IP packets received on an interface that has
291  //not been assigned a valid link-local address
293  return ERROR_NOT_CONFIGURED;
294 
295  //If routing is not enabled on the interface, then the router cannot
296  //forward packets from the interface
297  if(!srcInterface->ipv6Context.isRouter)
298  return ERROR_FAILURE;
299 
300  //Calculate the length of the IPv6 packet
301  length = netBufferGetLength(ipPacket) - ipPacketOffset;
302 
303  //Ensure the packet length is greater than 40 bytes
304  if(length < sizeof(Ipv6Header))
305  return ERROR_INVALID_LENGTH;
306 
307  //Point to the IPv6 header
308  ipHeader = netBufferAt(ipPacket, ipPacketOffset);
309 
310  //Sanity check
311  if(ipHeader == NULL)
312  return ERROR_FAILURE;
313 
314  //An IPv6 packet with a source address of unspecified must never be
315  //forwarded by an IPv6 router (refer to RFC section 3513 2.5.2)
316  if(ipv6CompAddr(&ipHeader->srcAddr, &IPV6_UNSPECIFIED_ADDR))
317  return ERROR_INVALID_ADDRESS;
318 
319  //The unspecified address must not be used as the destination address
320  //of IPv6 packets (refer to RFC section 3513 2.5.2)
321  if(ipv6CompAddr(&ipHeader->destAddr, &IPV6_UNSPECIFIED_ADDR))
322  return ERROR_INVALID_ADDRESS;
323 
324  //An IPv6 packet with a destination address of loopback must never be
325  //forwarded by an IPv6 router (refer to RFC 3513 section 2.5.3)
326  if(ipv6CompAddr(&ipHeader->destAddr, &IPV6_LOOPBACK_ADDR))
327  return ERROR_INVALID_ADDRESS;
328 
329  //Check whether the destination address is a link-local address
330  if(ipv6IsLinkLocalUnicastAddr(&ipHeader->destAddr))
331  {
332  //Forward the packet on the same network interface
333  destInterface = srcInterface;
334  //Next hop
335  destIpAddr = ipHeader->destAddr;
336  }
337  else
338  {
339  //Lowest metric value
340  metric = UINT_MAX;
341  //Longest prefix length
342  prefixLen = 0;
343  //Outgoing network interface
344  destInterface = NULL;
345 
346  //Route determination process
347  for(i = 0; i < IPV6_ROUTING_TABLE_SIZE; i++)
348  {
349  //Point to the current entry
350  entry = &ipv6RoutingTable[i];
351 
352  //Valid entry?
353  if(entry->valid && entry->interface != NULL)
354  {
355  //Clear flag
356  match = FALSE;
357 
358  //Do not forward any IP packets to an interface that has not
359  //been assigned a valid link-local address...
361  {
362  //If routing is enabled on the interface, then the router
363  //can forward packets to the interface
364  if(entry->interface->ipv6Context.isRouter)
365  {
366  //Compare the destination address with the current entry for a match
367  if(ipv6CompPrefix(&ipHeader->destAddr, &entry->prefix, entry->prefixLen))
368  {
369  //The longest matching route is the most specific route to the
370  //destination IPv6 address...
371  if(entry->prefixLen > prefixLen)
372  {
373  //Give the current route the higher precedence
374  match = TRUE;
375  }
376  else if(entry->prefixLen == prefixLen)
377  {
378  //If multiple entries with the longest match are found, the
379  //router uses the lowest metric to select the best route
380  if(entry->metric < metric)
381  {
382  //Give the current route the higher precedence
383  match = TRUE;
384  }
385  }
386  }
387  }
388  }
389 
390  //Matching entry?
391  if(match)
392  {
393  //Select the current route
394  metric = entry->metric;
395  prefixLen = entry->prefixLen;
396 
397  //Outgoing interface on which to forward the packet
398  destInterface = entry->interface;
399 
400  //Next hop
402  {
403  destIpAddr = entry->nextHop;
404  }
405  else
406  {
407  destIpAddr = ipHeader->destAddr;
408  }
409  }
410  }
411  }
412  }
413 
414  //No route to the destination?
415  if(destInterface == NULL)
416  {
417  //A Destination Unreachable message should be generated by a router
418  //in response to a packet that cannot be delivered
420  ICMPV6_CODE_NO_ROUTE_TO_DEST, 0, ipPacket, ipPacketOffset);
421 
422  //Exit immediately
423  return ERROR_NO_ROUTE;
424  }
425 
426  //Check whether the length of the IPv6 packet is larger than the link MTU
427  if(length > destInterface->ipv6Context.linkMtu)
428  {
429  //A Packet Too Big must be sent by a router in response to a packet
430  //that it cannot forward because the packet is larger than the MTU
431  //of the outgoing link
433  0, destInterface->ipv6Context.linkMtu, ipPacket, ipPacketOffset);
434 
435  //Exit immediately
436  return ERROR_INVALID_LENGTH;
437  }
438 
439  //Check whether the packet is explicitly addressed to the router itself
440  if(!ipv6CheckDestAddr(destInterface, &ipHeader->destAddr))
441  {
442  //Valid unicast address?
443  if(!ipv6IsMulticastAddr(&ipHeader->destAddr))
444  {
445  //Process IPv6 packet
446  //ipv6ProcessPacket(destInterface, ipPacket, ipPacketOffset);
447  //Exit immediately
448  return NO_ERROR;
449  }
450  }
451 
452  //Check whether the IPv6 packet is about to be sent out the interface
453  //on which it was received
454  if(destInterface == srcInterface)
455  {
456 #if (NDP_SUPPORT == ENABLED)
457  //A router should send a Redirect message whenever it forwards a packet
458  //that is not explicitly addressed to itself in which the source address
459  //identifies a neighbor, and
460  if(ipv6IsOnLink(srcInterface, &ipHeader->srcAddr))
461  {
462  //The router determines that a better first-hop node resides on the
463  //same link as the sending node for the destination address of the
464  //packet being forwarded, and
465  if(ipv6IsOnLink(destInterface, &destIpAddr))
466  {
467  //The destination address of the packet is not a multicast address
468  if(!ipv6IsMulticastAddr(&ipHeader->destAddr))
469  {
470  //Transmit a Redirect message
471  ndpSendRedirect(srcInterface, &destIpAddr, ipPacket, ipPacketOffset);
472  }
473  }
474  }
475 #endif
476  }
477  else
478  {
479  //Check whether the scope of the source address is smaller than the
480  //scope of the destination address
481  if(ipv6GetAddrScope(&ipHeader->srcAddr) < ipv6GetAddrScope(&ipHeader->destAddr))
482  {
483  //A Destination Unreachable message should be generated by a router
484  //in response to a packet that cannot be delivered without leaving
485  //the scope of the source address
487  ICMPV6_CODE_BEYOND_SCOPE_OF_SRC_ADDR, 0, ipPacket, ipPacketOffset);
488 
489  //Exit immediately
490  return ERROR_INVALID_ADDRESS;
491  }
492  }
493 
494  //Hop Limit exceeded in transit?
495  if(ipHeader->hopLimit <= 1)
496  {
497  //If a router receives a packet with a Hop Limit of zero, or if a router
498  //decrements a packet's Hop Limit to zero, it must discard the packet
499  //and originate an ICMPv6 Time Exceeded message
501  ICMPV6_CODE_HOP_LIMIT_EXCEEDED, 0, ipPacket, ipPacketOffset);
502 
503  //Exit immediately
504  return ERROR_FAILURE;
505  }
506 
507  //The Hop-by-Hop Options header, when present, must immediately follow
508  //the IPv6 header. Its presence is indicated by the value zero in the
509  //Next Header field of the IPv6 header
510  if(ipHeader->nextHeader == IPV6_HOP_BY_HOP_OPT_HEADER)
511  {
512  //Point to the extension header
513  size_t headerOffset = ipPacketOffset + sizeof(Ipv6Header);
514 
515  //Calculate the offset of the Next Header field
516  size_t nextHeaderOffset = ipPacketOffset +
517  &ipHeader->nextHeader - (uint8_t *) ipHeader;
518 
519  //The Hop-by-Hop Options header is used to carry optional information
520  //that must be examined by every node along a packet's delivery path
521  error = ipv6ParseHopByHopOptHeader(srcInterface,
522  ipPacket, ipPacketOffset, &headerOffset, &nextHeaderOffset);
523 
524  //Any error while processing the extension header?
525  if(error)
526  return error;
527  }
528 
529  //Allocate a buffer to hold the IPv6 packet
530  destBuffer = ethAllocBuffer(length, &destOffset);
531 
532  //Successful memory allocation?
533  if(destBuffer != NULL)
534  {
535  //Copy IPv6 header
536  error = netBufferCopy(destBuffer, destOffset, ipPacket, ipPacketOffset,
537  length);
538 
539  //Check status code
540  if(!error)
541  {
542  //Point to the IPv6 header
543  ipHeader = netBufferAt(destBuffer, destOffset);
544  //Every time a router forwards a packet, it decrements the Hop Limit field
545  ipHeader->hopLimit--;
546 
547 #if (ETH_SUPPORT == ENABLED)
548  //Point to the physical interface
549  physicalInterface = nicGetPhysicalInterface(destInterface);
550 
551  //Ethernet interface?
552  if(physicalInterface->nicDriver != NULL &&
553  physicalInterface->nicDriver->type == NIC_TYPE_ETHERNET)
554  {
555  MacAddr destMacAddr;
556  NetTxAncillary ancillary;
557 
558  //Additional options can be passed to the stack along with the packet
559  ancillary = NET_DEFAULT_TX_ANCILLARY;
560 
561  //Destination IPv6 address
563  destIpAddr = ipHeader->destAddr;
564 
565  //Check whether the destination IPv6 address is a multicast address?
567  {
568  //Map IPv6 multicast address to MAC-layer multicast address
569  error = ipv6MapMulticastAddrToMac(&destIpAddr, &destMacAddr);
570  }
571  else
572  {
573  //Resolve host address using Neighbor Discovery protocol
574  error = ndpResolve(destInterface, &destIpAddr, &destMacAddr);
575  }
576 
577  //Successful address resolution?
578  if(!error)
579  {
580  //Debug message
581  TRACE_INFO("Forwarding IPv6 packet to %s (%" PRIuSIZE " bytes)...\r\n",
582  destInterface->name, length);
583  //Dump IP header contents for debugging purpose
584  ipv6DumpHeader(ipHeader);
585 
586  //Send Ethernet frame
587  error = ethSendFrame(destInterface, NULL, &destMacAddr, ETH_TYPE_IPV6,
588  destBuffer, destOffset, &ancillary);
589  }
590  //Address resolution in progress?
591  else if(error == ERROR_IN_PROGRESS)
592  {
593  //Debug message
594  TRACE_INFO("Enqueuing IPv6 packet (%" PRIuSIZE " bytes)...\r\n", length);
595  //Dump IP header contents for debugging purpose
596  ipv6DumpHeader(ipHeader);
597 
598  //Enqueue packets waiting for address resolution
599  error = ndpEnqueuePacket(srcInterface, destInterface, &destIpAddr,
600  destBuffer, destOffset, &ancillary);
601  }
602  //Address resolution failed?
603  else
604  {
605  //Debug message
606  TRACE_WARNING("Cannot map IPv6 address to Ethernet address!\r\n");
607  }
608  }
609  else
610 #endif
611 #if (PPP_SUPPORT == ENABLED)
612  //PPP interface?
613  if(destInterface->nicDriver != NULL &&
614  destInterface->nicDriver->type == NIC_TYPE_PPP)
615  {
616  //Debug message
617  TRACE_INFO("Forwarding IPv6 packet to %s (%" PRIuSIZE " bytes)...\r\n",
618  destInterface->name, length);
619  //Dump IP header contents for debugging purpose
620  ipv6DumpHeader(ipHeader);
621 
622  //Send PPP frame
623  error = pppSendFrame(destInterface, destBuffer, destOffset,
625  }
626  else
627 #endif
628  //6LoWPAN interface?
629  if(destInterface->nicDriver != NULL &&
630  destInterface->nicDriver->type == NIC_TYPE_6LOWPAN)
631  {
632  NetTxAncillary ancillary;
633 
634  //Debug message
635  TRACE_INFO("Forwarding IPv6 packet to %s (%" PRIuSIZE " bytes)...\r\n",
636  destInterface->name, length);
637  //Dump IP header contents for debugging purpose
638  ipv6DumpHeader(ipHeader);
639 
640  //Additional options can be passed to the stack along with the packet
641  ancillary = NET_DEFAULT_TX_ANCILLARY;
642 
643  //Send the packet over the specified link
644  error = nicSendPacket(destInterface, destBuffer, destOffset,
645  &ancillary);
646  }
647  else
648  //Unknown interface type?
649  {
650  //Report an error
651  error = ERROR_INVALID_INTERFACE;
652  }
653  }
654 
655  //Free previously allocated memory
656  netBufferFree(destBuffer);
657  }
658  else
659  {
660  //Failed to allocate memory
661  error = ERROR_OUT_OF_MEMORY;
662  }
663 
664  //Return status code
665  return error;
666 }
667 
668 #endif
unsigned int uint_t
Definition: compiler_port.h:50
#define PRIuSIZE
int bool_t
Definition: compiler_port.h:53
Debugging facilities.
#define TRACE_WARNING(...)
Definition: debug.h:85
#define TRACE_INFO(...)
Definition: debug.h:95
Ipv6Addr prefix
uint8_t prefixLen
error_t
Error codes.
Definition: error.h:43
@ ERROR_IN_PROGRESS
Definition: error.h:213
@ ERROR_INVALID_INTERFACE
Invalid interface.
Definition: error.h:53
@ ERROR_INVALID_ADDRESS
Definition: error.h:103
@ ERROR_NO_ROUTE
Definition: error.h:219
@ ERROR_NOT_FOUND
Definition: error.h:147
@ ERROR_NOT_CONFIGURED
Definition: error.h:217
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
@ ERROR_INVALID_LENGTH
Definition: error.h:111
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
error_t ethSendFrame(NetInterface *interface, const MacAddr *destAddr, uint16_t type, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send an Ethernet frame.
Definition: ethernet.c:399
NetBuffer * ethAllocBuffer(size_t length, size_t *offset)
Allocate a buffer to hold an Ethernet frame.
Definition: ethernet.c:775
@ ETH_TYPE_IPV6
Definition: ethernet.h:168
MacAddr
Definition: ethernet.h:195
error_t icmpv6SendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code, uint32_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset)
Send an ICMPv6 Error message.
Definition: icmpv6.c:507
ICMPv6 (Internet Control Message Protocol Version 6)
@ ICMPV6_TYPE_DEST_UNREACHABLE
Definition: icmpv6.h:53
@ ICMPV6_TYPE_PACKET_TOO_BIG
Definition: icmpv6.h:54
@ ICMPV6_TYPE_TIME_EXCEEDED
Definition: icmpv6.h:55
@ ICMPV6_CODE_BEYOND_SCOPE_OF_SRC_ADDR
Definition: icmpv6.h:79
@ ICMPV6_CODE_NO_ROUTE_TO_DEST
Definition: icmpv6.h:77
@ ICMPV6_CODE_HOP_LIMIT_EXCEEDED
Definition: icmpv6.h:91
IPv4 and IPv6 common routines.
Ipv4Addr destIpAddr
Definition: ipcp.h:80
const Ipv6Addr IPV6_UNSPECIFIED_ADDR
Definition: ipv6.c:65
const Ipv6Addr IPV6_LOOPBACK_ADDR
Definition: ipv6.c:69
void ipv6DumpHeader(const Ipv6Header *ipHeader)
Dump IPv6 header for debugging purpose.
Definition: ipv6.c:2447
error_t ipv6ParseHopByHopOptHeader(NetInterface *interface, const NetBuffer *ipPacket, size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset)
Parse Hop-by-Hop Options header.
Definition: ipv6.c:1289
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
@ IPV6_HOP_BY_HOP_OPT_HEADER
Definition: ipv6.h:179
#define ipv6IsMulticastAddr(ipAddr)
Definition: ipv6.h:132
#define ipv6IsLinkLocalUnicastAddr(ipAddr)
Definition: ipv6.h:124
#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 ipv6MapMulticastAddrToMac(const Ipv6Addr *ipAddr, MacAddr *macAddr)
Map an IPv6 multicast address to a MAC-layer multicast address.
Definition: ipv6_misc.c:1428
bool_t ipv6CompPrefix(const Ipv6Addr *ipAddr1, const Ipv6Addr *ipAddr2, size_t length)
Compare IPv6 address prefixes.
Definition: ipv6_misc.c:1221
bool_t ipv6IsOnLink(NetInterface *interface, const Ipv6Addr *ipAddr)
Check whether an IPv6 address is on-link.
Definition: ipv6_misc.c:1045
error_t ipv6CheckDestAddr(NetInterface *interface, const Ipv6Addr *ipAddr)
Destination IPv6 address filtering.
Definition: ipv6_misc.c:789
uint_t ipv6GetAddrScope(const Ipv6Addr *ipAddr)
Retrieve the scope of an IPv6 address.
Definition: ipv6_misc.c:1266
Helper functions for IPv6.
error_t ipv6ForwardPacket(NetInterface *srcInterface, NetBuffer *ipPacket, size_t ipPacketOffset)
Forward an IPv6 packet.
Definition: ipv6_routing.c:271
error_t ipv6DeleteAllRoutes(void)
Delete all routes from the IPv6 routing table.
Definition: ipv6_routing.c:249
error_t ipv6InitRouting(void)
Initialize IPv6 routing table.
Definition: ipv6_routing.c:57
error_t ipv6DeleteRoute(const Ipv6Addr *prefix, uint_t prefixLen)
Remove an entry from the IPv6 routing table.
Definition: ipv6_routing.c:200
error_t ipv6AddRoute(const Ipv6Addr *prefix, uint_t prefixLen, NetInterface *interface, const Ipv6Addr *nextHop, uint_t metric)
Add a new entry in the IPv6 routing table.
Definition: ipv6_routing.c:103
error_t ipv6EnableRouting(NetInterface *interface, bool_t enable)
Enable routing for the specified interface.
Definition: ipv6_routing.c:75
IPv6 routing.
#define IPV6_ROUTING_TABLE_SIZE
Definition: ipv6_routing.h:47
error_t ndpSendRedirect(NetInterface *interface, const Ipv6Addr *targetAddr, const NetBuffer *ipPacket, size_t ipPacketOffset)
Send a Redirect message.
Definition: ndp.c:1991
error_t ndpEnqueuePacket(NetInterface *srcInterface, NetInterface *destInterface, const Ipv6Addr *ipAddr, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Enqueue an IPv6 packet waiting for address resolution.
Definition: ndp.c:360
error_t ndpResolve(NetInterface *interface, const Ipv6Addr *ipAddr, MacAddr *macAddr)
Address resolution using Neighbor Discovery protocol.
Definition: ndp.c:260
NDP (Neighbor Discovery Protocol)
uint8_t ipPacket[]
Definition: ndp.h:431
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
#define netMutex
Definition: net_legacy.h:195
void * netBufferAt(const NetBuffer *buffer, size_t offset)
Returns a pointer to the data at the specified position.
Definition: net_mem.c:415
error_t netBufferCopy(NetBuffer *dest, size_t destOffset, const NetBuffer *src, size_t srcOffset, size_t length)
Copy data between multi-part buffers.
Definition: net_mem.c:506
void netBufferFree(NetBuffer *buffer)
Dispose a multi-part buffer.
Definition: net_mem.c:282
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
#define NetTxAncillary
Definition: net_misc.h:36
error_t nicSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet to the network controller.
Definition: nic.c:280
NetInterface * nicGetPhysicalInterface(NetInterface *interface)
Retrieve physical interface.
Definition: nic.c:84
@ NIC_TYPE_6LOWPAN
6LoWPAN interface
Definition: nic.h:87
@ NIC_TYPE_ETHERNET
Ethernet interface.
Definition: nic.h:83
@ NIC_TYPE_PPP
PPP interface.
Definition: nic.h:84
#define osMemset(p, value, length)
Definition: os_port.h:135
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
error_t pppSendFrame(NetInterface *interface, NetBuffer *buffer, size_t offset, uint16_t protocol)
Send a PPP frame.
Definition: ppp.c:1035
@ PPP_PROTOCOL_IPV6
Internet Protocol version 6.
Definition: ppp.h:200
Routing table entry.
Definition: ipv6_routing.h:63
uint_t metric
Metric value.
Definition: ipv6_routing.h:69
Ipv6Addr prefix
Destination.
Definition: ipv6_routing.h:65
Ipv6Addr nextHop
Next hop.
Definition: ipv6_routing.h:68
uint_t prefixLen
IPv6 prefix length.
Definition: ipv6_routing.h:66
bool_t valid
Valid entry.
Definition: ipv6_routing.h:64
NetInterface * interface
Outgoing network interface.
Definition: ipv6_routing.h:67
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t length
Definition: tcp.h:368