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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 //Switch to the appropriate trace level
30 #define TRACE_LEVEL IPV6_TRACE_LEVEL
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "core/ip.h"
35 #include "ipv6/ipv6.h"
36 #include "ipv6/ipv6_pmtu.h"
37 #include "ipv6/ndp.h"
38 #include "ipv6/ndp_cache.h"
39 #include "debug.h"
40 
41 //Check TCP/IP stack configuration
42 #if (IPV6_SUPPORT == ENABLED && IPV6_PMTU_SUPPORT == ENABLED)
43 
44 
45 /**
46  * @brief Retrieve the PMTU for the specified path
47  * @param[in] interface Underlying network interface
48  * @param[in] destAddr Destination IPv6 address
49  * @return PMTU value
50  **/
51 
52 size_t ipv6GetPathMtu(NetInterface *interface, const Ipv6Addr *destAddr)
53 {
54  size_t pathMtu;
55 
56 #if (NDP_SUPPORT == ENABLED)
57  NdpDestCacheEntry *entry;
58 
59  //Search the Destination Cache for the specified IPv6 address
60  entry = ndpFindDestCacheEntry(interface, destAddr);
61 
62  //Check whether a matching entry has been found in the Destination Cache
63  if(entry != NULL)
64  {
65  //Use the existing PMTU estimate
66  pathMtu = entry->pathMtu;
67  }
68  else
69  {
70  //If no entry exists in the Destination Cache, the PMTU value for
71  //the path is assumed to be the MTU of the first-hop link
72  pathMtu = interface->ipv6Context.linkMtu;
73  }
74 #else
75  //The PMTU value for the path is assumed to be the MTU of the first-hop link
76  pathMtu = interface->ipv6Context.linkMtu;
77 #endif
78 
79  //Return the PMTU value
80  return pathMtu;
81 }
82 
83 
84 /**
85  * @brief Update the PMTU for the specified path
86  * @param[in] interface Underlying network interface
87  * @param[in] destAddr Destination IPv6 address
88  * @param[in] tentativePathMtu Tentative PMTU value
89  **/
90 
92  const Ipv6Addr *destAddr, size_t tentativePathMtu)
93 {
94 #if (NDP_SUPPORT == ENABLED)
95  NdpDestCacheEntry *entry;
96 
97  //The destination address from the original packet is used to determine
98  //which path the message applies to
99  entry = ndpFindDestCacheEntry(interface, destAddr);
100 
101  //Check whether a matching entry has been found in the Destination Cache
102  if(entry != NULL)
103  {
104  //Compare the tentative PMTU to the existing PMTU
105  if(tentativePathMtu < entry->pathMtu)
106  {
107  //If the tentative PMTU is less than the existing PMTU estimate,
108  //the tentative PMTU replaces the existing PMTU
109  entry->pathMtu = tentativePathMtu;
110  }
111  }
112 #endif
113 }
114 
115 #endif
void ipv6UpdatePathMtu(NetInterface *interface, const Ipv6Addr *destAddr, size_t tentativePathMtu)
Update the PMTU for the specified path.
Definition: ipv6_pmtu.c:91
TCP/IP stack core.
Debugging facilities.
IPv4 and IPv6 common routines.
__start_packed struct @183 Ipv6Addr
IPv6 network address.
Destination cache entry.
Definition: ndp.h:559
Neighbor and destination cache management.
size_t ipv6GetPathMtu(NetInterface *interface, const Ipv6Addr *destAddr)
Retrieve the PMTU for the specified path.
Definition: ipv6_pmtu.c:52
NdpDestCacheEntry * ndpFindDestCacheEntry(NetInterface *interface, const Ipv6Addr *destAddr)
Search the Destination Cache for a given destination address.
Definition: ndp_cache.c:443
IPv6 (Internet Protocol Version 6)
size_t pathMtu
Path MTU.
Definition: ndp.h:563
#define NetInterface
Definition: net.h:34
NDP (Neighbor Discovery Protocol)
Path MTU Discovery for IPv6.
MacAddr destAddr
Definition: ethernet.h:180