ipv6_pmtu.c
Go to the documentation of this file.
1 /**
2  * @file ipv6_pmtu.c
3  * @brief Path MTU Discovery for IPv6
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2020 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 1.9.8
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL IPV6_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/ip.h"
37 #include "ipv6/ipv6.h"
38 #include "ipv6/ipv6_pmtu.h"
39 #include "ipv6/ndp.h"
40 #include "ipv6/ndp_cache.h"
41 #include "debug.h"
42 
43 //Check TCP/IP stack configuration
44 #if (IPV6_SUPPORT == ENABLED && IPV6_PMTU_SUPPORT == ENABLED)
45 
46 
47 /**
48  * @brief Retrieve the PMTU for the specified path
49  * @param[in] interface Underlying network interface
50  * @param[in] destAddr Destination IPv6 address
51  * @return PMTU value
52  **/
53 
54 size_t ipv6GetPathMtu(NetInterface *interface, const Ipv6Addr *destAddr)
55 {
56  size_t pathMtu;
57 
58 #if (NDP_SUPPORT == ENABLED)
59  NdpDestCacheEntry *entry;
60 
61  //Search the Destination Cache for the specified IPv6 address
62  entry = ndpFindDestCacheEntry(interface, destAddr);
63 
64  //Check whether a matching entry has been found in the Destination Cache
65  if(entry != NULL)
66  {
67  //Use the existing PMTU estimate
68  pathMtu = entry->pathMtu;
69  }
70  else
71  {
72  //If no entry exists in the Destination Cache, the PMTU value for
73  //the path is assumed to be the MTU of the first-hop link
74  pathMtu = interface->ipv6Context.linkMtu;
75  }
76 #else
77  //The PMTU value for the path is assumed to be the MTU of the first-hop link
78  pathMtu = interface->ipv6Context.linkMtu;
79 #endif
80 
81  //Return the PMTU value
82  return pathMtu;
83 }
84 
85 
86 /**
87  * @brief Update the PMTU for the specified path
88  * @param[in] interface Underlying network interface
89  * @param[in] destAddr Destination IPv6 address
90  * @param[in] tentativePathMtu Tentative PMTU value
91  **/
92 
94  const Ipv6Addr *destAddr, size_t tentativePathMtu)
95 {
96 #if (NDP_SUPPORT == ENABLED)
97  NdpDestCacheEntry *entry;
98 
99  //The destination address from the original packet is used to determine
100  //which path the message applies to
101  entry = ndpFindDestCacheEntry(interface, destAddr);
102 
103  //Check whether a matching entry has been found in the Destination Cache
104  if(entry != NULL)
105  {
106  //Compare the tentative PMTU to the existing PMTU
107  if(tentativePathMtu < entry->pathMtu)
108  {
109  //If the tentative PMTU is less than the existing PMTU estimate,
110  //the tentative PMTU replaces the existing PMTU
111  entry->pathMtu = tentativePathMtu;
112  }
113  }
114 #endif
115 }
116 
117 #endif
IPv6 (Internet Protocol Version 6)
NdpDestCacheEntry * ndpFindDestCacheEntry(NetInterface *interface, const Ipv6Addr *destAddr)
Search the Destination Cache for a given destination address.
Definition: ndp_cache.c:446
size_t ipv6GetPathMtu(NetInterface *interface, const Ipv6Addr *destAddr)
Retrieve the PMTU for the specified path.
Definition: ipv6_pmtu.c:54
void ipv6UpdatePathMtu(NetInterface *interface, const Ipv6Addr *destAddr, size_t tentativePathMtu)
Update the PMTU for the specified path.
Definition: ipv6_pmtu.c:93
size_t pathMtu
Path MTU.
Definition: ndp.h:567
MacAddr destAddr
Definition: ethernet.h:206
#define NetInterface
Definition: net.h:36
Neighbor and destination cache management.
Path MTU Discovery for IPv6.
NDP (Neighbor Discovery Protocol)
IPv4 and IPv6 common routines.
Destination cache entry.
Definition: ndp.h:563
__start_packed struct @77 Ipv6Addr
IPv6 network address.
TCP/IP stack core.
Debugging facilities.