GNUnet 0.22.2
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;
164 enum GNUNET_NAT_Type type = ntohl (res->type);
165 enum GNUNET_NAT_StatusCode status = ntohl (res->status_code);
166
167 left = ntohs (res->header.size) - sizeof(*res);
169 if (GNUNET_OK !=
171 (const char *) &res[1],
172 left,
173 NULL))
174 {
175 GNUNET_break (0);
176 ah->arc (ah->arc_cls,
177 NULL,
179 type);
180 }
181 else
182 {
183 ah->arc (ah->arc_cls,
184 cfg,
185 status,
186 type);
187 }
190}
191
192
199static void
201 enum GNUNET_MQ_Error error)
202{
203 struct GNUNET_NAT_AUTO_AutoHandle *ah = cls;
204
205 ah->arc (ah->arc_cls,
206 NULL,
210}
211
212
225 void *cb_cls)
226{
230 GNUNET_MQ_hd_var_size (auto_result,
233 ah),
235 };
236 struct GNUNET_MQ_Envelope *env;
238 char *buf;
239 size_t size;
240
242 &size);
243 if (size > GNUNET_MAX_MESSAGE_SIZE - sizeof(*req))
244 {
245 GNUNET_break (0);
246 GNUNET_free (buf);
247 GNUNET_free (ah);
248 return NULL;
249 }
250 ah->arc = cb;
251 ah->arc_cls = cb_cls;
253 "nat",
254 handlers,
256 ah);
257 if (NULL == ah->mq)
258 {
259 GNUNET_break (0);
260 GNUNET_free (buf);
261 GNUNET_free (ah);
262 return NULL;
263 }
265 size,
267 GNUNET_memcpy (&req[1],
268 buf,
269 size);
270 GNUNET_free (buf);
272 env);
273 return ah;
274}
275
276
282void
284{
286 GNUNET_free (ah);
287}
288
289
290/* 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:108
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:1060
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
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.
#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:305
#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:61
#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:700
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:223
void GNUNET_NAT_AUTO_autoconfig_cancel(struct GNUNET_NAT_AUTO_AutoHandle *ah)
Abort autoconfiguration.
Definition: nat_auto_api.c:283
@ 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.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#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:200
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