GNUnet 0.21.1
nat_auto_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2007-2017 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
28#include "platform.h"
29#include "gnunet_nat_service.h"
31#include "nat-auto.h"
32
33
38{
43
48
53
57 void *arc_cls;
58};
59
60
67const char *
69{
70 switch (err)
71 {
73 return _ ("Operation Successful");
74
76 return _ ("IPC failure");
77
79 return _ ("Failure in network subsystem, check permissions.");
80
82 return _ ("Encountered timeout while performing operation");
83
85 return _ ("detected that we are offline");
86
88 return _ ("`upnpc` command not found");
89
91 return _ ("Failed to run `upnpc` command");
92
94 return _ ("`upnpc' command took too long, process killed");
95
97 return _ ("`upnpc' command failed to establish port mapping");
98
100 return _ ("`external-ip' command not found");
101
103 return _ ("Failed to run `external-ip` command");
104
106 return _ ("`external-ip' command output invalid");
107
109 return _ ("no valid address was returned by `external-ip'");
110
112 return _ (
113 "Could not determine interface with internal/local network address");
114
116 return _ ("No functioning gnunet-helper-nat-server installation found");
117
119 return _ ("NAT test could not be initialized");
120
122 return _ ("NAT test timeout reached");
123
125 return _ ("could not register NAT");
126
128 return _ ("No working gnunet-helper-nat-client installation found");
129
130 default:
131 return "unknown status code";
132 }
133}
134
135
143static int
146{
147 return GNUNET_OK;
148}
149
150
157static void
160{
161 struct GNUNET_NAT_AUTO_AutoHandle *ah = cls;
162 size_t left;
165 = (enum GNUNET_NAT_Type) ntohl (res->type);
167 = (enum GNUNET_NAT_StatusCode) ntohl (res->status_code);
168
169 left = ntohs (res->header.size) - sizeof(*res);
171 if (GNUNET_OK !=
173 (const char *) &res[1],
174 left,
175 NULL))
176 {
177 GNUNET_break (0);
178 ah->arc (ah->arc_cls,
179 NULL,
181 type);
182 }
183 else
184 {
185 ah->arc (ah->arc_cls,
186 cfg,
187 status,
188 type);
189 }
192}
193
194
201static void
203 enum GNUNET_MQ_Error error)
204{
205 struct GNUNET_NAT_AUTO_AutoHandle *ah = cls;
206
207 ah->arc (ah->arc_cls,
208 NULL,
212}
213
214
227 void *cb_cls)
228{
232 GNUNET_MQ_hd_var_size (auto_result,
235 ah),
237 };
238 struct GNUNET_MQ_Envelope *env;
240 char *buf;
241 size_t size;
242
244 &size);
245 if (size > GNUNET_MAX_MESSAGE_SIZE - sizeof(*req))
246 {
247 GNUNET_break (0);
248 GNUNET_free (buf);
249 GNUNET_free (ah);
250 return NULL;
251 }
252 ah->arc = cb;
253 ah->arc_cls = cb_cls;
255 "nat",
256 handlers,
258 ah);
259 if (NULL == ah->mq)
260 {
261 GNUNET_break (0);
262 GNUNET_free (buf);
263 GNUNET_free (ah);
264 return NULL;
265 }
267 size,
269 GNUNET_memcpy (&req[1],
270 buf,
271 size);
272 GNUNET_free (buf);
274 env);
275 return ah;
276}
277
278
284void
286{
288 GNUNET_free (ah);
289}
290
291
292/* end of nat_api_auto.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static char * res
Currently read line or NULL on EOF.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
static int status
The program status; 0 for success.
Definition: gnunet-nse.c:39
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
GNUNET_NAT_StatusCode
Error Types for the NAT subsystem (which can then later be converted/resolved to a string)
GNUNET_NAT_Type
What the situation of the NAT connectivity.
const char * GNUNET_NAT_AUTO_status2string(enum GNUNET_NAT_StatusCode err)
Converts enum GNUNET_NAT_StatusCode to string.
Definition: nat_auto_api.c:68
void(* GNUNET_NAT_AUTO_AutoResultCallback)(void *cls, const struct GNUNET_CONFIGURATION_Handle *diff, enum GNUNET_NAT_StatusCode result, enum GNUNET_NAT_Type type)
Function called with the result from the autoconfiguration.
struct GNUNET_NAT_AUTO_AutoHandle * GNUNET_NAT_AUTO_autoconfig_start(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NAT_AUTO_AutoResultCallback cb, void *cb_cls)
Start auto-configuration routine.
Definition: nat_auto_api.c:225
void GNUNET_NAT_AUTO_autoconfig_cancel(struct GNUNET_NAT_AUTO_AutoHandle *ah)
Abort autoconfiguration.
Definition: nat_auto_api.c:285
@ GNUNET_NAT_ERROR_UPNPC_NOT_FOUND
upnpc command not found
@ GNUNET_NAT_ERROR_NOT_ONLINE
detected that we are offline
@ GNUNET_NAT_ERROR_UPNPC_TIMEOUT
‘upnpc’ command took too long, process killed
@ GNUNET_NAT_ERROR_SUCCESS
Just the default.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID
‘external-ip’ command output invalid
@ GNUNET_NAT_ERROR_UPNPC_FAILED
Failed to run upnpc command.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED
Failed to run external-ip command.
@ GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR
Failure in network subsystem, check permissions.
@ GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND
@ GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED
‘upnpc’ command failed to establish port mapping
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND
‘external-ip’ command not found
@ GNUNET_NAT_ERROR_NAT_REGISTER_FAILED
NAT test failed to initiate.
@ GNUNET_NAT_ERROR_IPC_FAILURE
IPC Failure.
@ GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO
Could not determine interface with internal/local network address.
@ GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND
No working gnunet-helper-nat-server found.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID
"no valid address was returned by `external-ip'"
@ GNUNET_NAT_ERROR_NAT_TEST_START_FAILED
NAT test could not be initialized.
@ GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT
NAT test timeout.
@ GNUNET_NAT_ERROR_TIMEOUT
test timed out
@ GNUNET_NAT_TYPE_UNKNOWN
We know nothing about the NAT.
#define GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT
Message from NAT service with the autoconfiguration result.
#define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG
Message to ask NAT service to request autoconfiguration.
static void ah_error_handler(void *cls, enum GNUNET_MQ_Error error)
Handle queue errors by reporting autoconfiguration failure.
Definition: nat_auto_api.c:202
static int check_auto_result(void *cls, const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res)
Check result from autoconfiguration attempt.
Definition: nat_auto_api.c:144
static void handle_auto_result(void *cls, const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res)
Handle result from autoconfiguration attempt.
Definition: nat_auto_api.c:158
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Handle to auto-configuration in progress.
Definition: nat_auto_api.c:38
void * arc_cls
Closure for arc.
Definition: nat_auto_api.c:57
struct GNUNET_MQ_Handle * mq
Message queue for communicating with the NAT service.
Definition: nat_auto_api.c:47
GNUNET_NAT_AUTO_AutoResultCallback arc
Function called with the result from the autoconfiguration.
Definition: nat_auto_api.c:52
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition: nat_auto_api.c:42
Client requesting automatic configuration.
Definition: nat-auto.h:71
Service responding with proposed configuration.
Definition: nat-auto.h:85