Webserver+3d print

Dependents:   Nucleo

Committer:
Sergunb
Date:
Sat Feb 04 18:15:49 2017 +0000
Revision:
0:8918a71cdbe9
nothing else

Who changed what in which revision?

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