Webserver+3d print
Embed:
(wiki syntax)
Show/hide line numbers
auto_ip.h
Go to the documentation of this file.
00001 /** 00002 * @file auto_ip.h 00003 * @brief Auto-IP (Dynamic Configuration of IPv4 Link-Local Addresses) 00004 * 00005 * @section License 00006 * 00007 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. 00008 * 00009 * This file is part of CycloneTCP Open. 00010 * 00011 * This program is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU General Public License 00013 * as published by the Free Software Foundation; either version 2 00014 * of the License, or (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software Foundation, 00023 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00024 * 00025 * @author Oryx Embedded SARL (www.oryx-embedded.com) 00026 * @version 1.7.6 00027 **/ 00028 00029 #ifndef _AUTO_IP_H 00030 #define _AUTO_IP_H 00031 00032 //Dependencies 00033 #include "core/net.h" 00034 00035 //Auto-IP support 00036 #ifndef AUTO_IP_SUPPORT 00037 #define AUTO_IP_SUPPORT DISABLED 00038 #elif (AUTO_IP_SUPPORT != ENABLED && AUTO_IP_SUPPORT != DISABLED) 00039 #error AUTO_IP_SUPPORT parameter is not valid 00040 #endif 00041 00042 //Bonjour Conformance Test support 00043 #ifndef AUTO_IP_BCT_SUPPORT 00044 #define AUTO_IP_BCT_SUPPORT DISABLED 00045 #elif (AUTO_IP_BCT_SUPPORT != ENABLED && AUTO_IP_BCT_SUPPORT != DISABLED) 00046 #error AUTO_IP_BCT_SUPPORT parameter is not valid 00047 #endif 00048 00049 //Auto-IP tick interval 00050 #ifndef AUTO_IP_TICK_INTERVAL 00051 #define AUTO_IP_TICK_INTERVAL 200 00052 #elif (AUTO_IP_TICK_INTERVAL < 10) 00053 #error AUTO_IP_TICK_INTERVAL parameter is not valid 00054 #endif 00055 00056 //Initial random delay 00057 #ifndef AUTO_IP_PROBE_WAIT 00058 #define AUTO_IP_PROBE_WAIT 1000 00059 #elif (AUTO_IP_PROBE_WAIT < 0) 00060 #error AUTO_IP_PROBE_WAIT parameter is not valid 00061 #endif 00062 00063 //Number of probe packets 00064 #ifndef AUTO_IP_PROBE_NUM 00065 #define AUTO_IP_PROBE_NUM 3 00066 #elif (AUTO_IP_PROBE_NUM < 1) 00067 #error AUTO_IP_PROBE_NUM parameter is not valid 00068 #endif 00069 00070 //Minimum delay till repeated probe 00071 #ifndef AUTO_IP_PROBE_MIN 00072 #define AUTO_IP_PROBE_MIN 1000 00073 #elif (AUTO_IP_PROBE_MIN < 100) 00074 #error AUTO_IP_PROBE_MIN parameter is not valid 00075 #endif 00076 00077 //Maximum delay till repeated probe 00078 #ifndef AUTO_IP_PROBE_MAX 00079 #define AUTO_IP_PROBE_MAX 2000 00080 #elif (AUTO_IP_PROBE_MAX < AUTO_IP_PROBE_MIN) 00081 #error AUTO_IP_PROBE_MAX parameter is not valid 00082 #endif 00083 00084 //Delay before announcing 00085 #ifndef AUTO_IP_ANNOUNCE_WAIT 00086 #define AUTO_IP_ANNOUNCE_WAIT 2000 00087 #elif (AUTO_IP_ANNOUNCE_WAIT < 100) 00088 #error AUTO_IP_ANNOUNCE_WAIT parameter is not valid 00089 #endif 00090 00091 //Number of announcement packets 00092 #ifndef AUTO_IP_ANNOUNCE_NUM 00093 #define AUTO_IP_ANNOUNCE_NUM 2 00094 #elif (AUTO_IP_ANNOUNCE_NUM < 1) 00095 #error AUTO_IP_ANNOUNCE_NUM parameter is not valid 00096 #endif 00097 00098 //Time between announcement packets 00099 #ifndef AUTO_IP_ANNOUNCE_INTERVAL 00100 #define AUTO_IP_ANNOUNCE_INTERVAL 2000 00101 #elif (AUTO_IP_ANNOUNCE_INTERVAL < 100) 00102 #error AUTO_IP_ANNOUNCE_INTERVAL parameter is not valid 00103 #endif 00104 00105 //Max conflicts before rate limiting 00106 #ifndef AUTO_IP_MAX_CONFLICTS 00107 #define AUTO_IP_MAX_CONFLICTS 10 00108 #elif (AUTO_IP_MAX_CONFLICTS < 1) 00109 #error AUTO_IP_MAX_CONFLICTS parameter is not valid 00110 #endif 00111 00112 //Delay between successive attempts 00113 #ifndef AUTO_IP_RATE_LIMIT_INTERVAL 00114 #define AUTO_IP_RATE_LIMIT_INTERVAL 60000 00115 #elif (AUTO_IP_RATE_LIMIT_INTERVAL < 1000) 00116 #error AUTO_IP_RATE_LIMIT_INTERVAL parameter is not valid 00117 #endif 00118 00119 //Minimum interval between defensive 00120 #ifndef AUTO_IP_DEFEND_INTERVAL 00121 #define AUTO_IP_DEFEND_INTERVAL 10000 00122 #elif (AUTO_IP_DEFEND_INTERVAL < 1000) 00123 #error AUTO_IP_DEFEND_INTERVAL parameter is not valid 00124 #endif 00125 00126 //Auto-IP address prefix 00127 #define AUTO_IP_PREFIX IPV4_ADDR(169, 254, 0, 0) 00128 //Auto-IP subnet mask 00129 #define AUTO_IP_MASK IPV4_ADDR(255, 255, 0, 0) 00130 00131 //Auto-IP address range 00132 #define AUTO_IP_ADDR_MIN IPV4_ADDR(169, 254, 1, 0) 00133 #define AUTO_IP_ADDR_MAX IPV4_ADDR(169, 254, 254, 255) 00134 00135 //Forward declaration of AutoIpContext structure 00136 struct _AutoIpContext; 00137 #define AutoIpContext struct _AutoIpContext 00138 00139 00140 /** 00141 * @brief Auto-IP FSM states 00142 **/ 00143 00144 typedef enum 00145 { 00146 AUTO_IP_STATE_INIT, 00147 AUTO_IP_STATE_PROBING, 00148 AUTO_IP_STATE_ANNOUNCING, 00149 AUTO_IP_STATE_CONFIGURED, 00150 AUTO_IP_STATE_DEFENDING 00151 } AutoIpState; 00152 00153 00154 /** 00155 * @brief Link state change callback 00156 **/ 00157 00158 typedef void (*AutoIpLinkChangeCallback)(AutoIpContext *context, 00159 NetInterface *interface, bool_t linkState); 00160 00161 00162 /** 00163 * @brief FSM state change callback 00164 **/ 00165 00166 typedef void (*AutoIpStateChangeCallback)(AutoIpContext *context, 00167 NetInterface *interface, AutoIpState state); 00168 00169 00170 /** 00171 * @brief Auto-IP settings 00172 **/ 00173 00174 typedef struct 00175 { 00176 NetInterface *interface; ///<Network interface to configure 00177 Ipv4Addr linkLocalAddr; ///<Initial link-local address to be used 00178 AutoIpLinkChangeCallback linkChangeEvent; ///<Link state change event 00179 AutoIpStateChangeCallback stateChangeEvent; ///<FSM state change event 00180 } AutoIpSettings; 00181 00182 00183 /** 00184 * @brief Auto-IP context 00185 **/ 00186 00187 struct _AutoIpContext 00188 { 00189 AutoIpSettings settings; ///<Auto-IP settings 00190 bool_t running; ///<Auto-IP is currently running 00191 AutoIpState state; ///<Current state of the FSM 00192 Ipv4Addr linkLocalAddr; ///<Link-local address 00193 systime_t timestamp; ///<Timestamp to manage retransmissions 00194 systime_t timeout; ///<Timeout value 00195 uint_t retransmitCount; ///<Retransmission counter 00196 uint_t conflictCount; ///<Number of conflicts 00197 }; 00198 00199 00200 //Tick counter to handle periodic operations 00201 extern systime_t autoIpTickCounter; 00202 00203 //Auto-IP related functions 00204 void autoIpGetDefaultSettings(AutoIpSettings *settings); 00205 error_t autoIpInit(AutoIpContext *context, const AutoIpSettings *settings); 00206 error_t autoIpStart(AutoIpContext *context); 00207 error_t autoIpStop(AutoIpContext *context); 00208 AutoIpState autoIpGetState(AutoIpContext *context); 00209 00210 void autoIpTick(AutoIpContext *context); 00211 void autoIpLinkChangeEvent(AutoIpContext *context); 00212 00213 void autoIpChangeState(AutoIpContext *context, 00214 AutoIpState newState, systime_t delay); 00215 00216 void autoIpGenerateAddr(Ipv4Addr *ipAddr); 00217 00218 void autoIpDumpConfig(AutoIpContext *context); 00219 00220 #endif 00221
Generated on Tue Jul 12 2022 17:10:12 by
