aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/config/controlAddConnection.c
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/config/controlAddConnection.c')
-rw-r--r--hicn-light/src/hicn/config/controlAddConnection.c159
1 files changed, 101 insertions, 58 deletions
diff --git a/hicn-light/src/hicn/config/controlAddConnection.c b/hicn-light/src/hicn/config/controlAddConnection.c
index e5af5a251..eed37f3ad 100644
--- a/hicn-light/src/hicn/config/controlAddConnection.c
+++ b/hicn-light/src/hicn/config/controlAddConnection.c
@@ -35,34 +35,51 @@
static void _controlAddConnection_Init(CommandParser *parser, CommandOps *ops);
static CommandReturn _controlAddConnection_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
// ===================================================
#ifdef __linux__
-static CommandReturn _controlAddConnection_HicnHelpExecute(
- CommandParser *parser, CommandOps *ops, PARCList *args);
+static CommandReturn _controlAddConnection_HicnHelpExecute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddConnection_HicnExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
#endif
static CommandReturn _controlAddConnection_UdpHelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddConnection_UdpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddConnection_TcpHelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddConnection_TcpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
// ===================================================
@@ -140,14 +157,19 @@ static CommandOps *_controlAddConnection_TcpHelpCreate(ControlState *state) {
static CommandReturn _controlAddConnection_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("Available commands:\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
#ifdef __linux__
- printf(" %s\n", _commandAddConnectionHicn);
+ snprintf(output, output_size, "Available commands:\n %s\n %s\n %s\n\n",
+ _commandAddConnectionHicn,
+ _commandAddConnectionUdp,
+ _commandAddConnectionTcp);
+#else
+ snprintf(output, output_size, "Available commands:\n %s\n %s\n\n",
+ _commandAddConnectionUdp,
+ _commandAddConnectionTcp);
#endif
- printf(" %s\n", _commandAddConnectionUdp);
- printf(" %s\n", _commandAddConnectionTcp);
- printf("\n");
return CommandReturn_Success;
}
@@ -170,8 +192,10 @@ static void _controlAddConnection_Init(CommandParser *parser, CommandOps *ops) {
static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- return _controlAddConnection_HelpExecute(parser, ops, args);
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ return _controlAddConnection_HelpExecute(parser, ops, args, output, output_size);
}
// ===================================================
@@ -191,6 +215,8 @@ static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
* @param [in] remoteAddress The remote IP and port (both must be specified)
* @param [in] tunnelType The tunneling protocol
* @param [in] symbolic The symbolic name for the connection (must be unique)
+ * @param [in] output Output buffer
+ * @param [in] output_size Output buffer size
*
* @return <#value#> <#explanation#>
*
@@ -215,10 +241,15 @@ static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
* @endcode
*/
-static CommandReturn _controlAddConnection_CreateTunnel(
- CommandParser *parser, CommandOps *ops, const char *local_ip,
- const char *local_port, const char *remote_ip, const char *remote_port,
- connection_type tunnelType, const char *symbolic) {
+static CommandReturn _controlAddConnection_CreateTunnel(CommandParser *parser,
+ CommandOps *ops, const char *local_ip,
+ const char *local_port,
+ const char *remote_ip,
+ const char *remote_port,
+ connection_type tunnelType,
+ const char *symbolic,
+ char *output,
+ size_t output_size) {
ControlState *state = ops->closure;
// a request like this always has an interface index of 0 [FIELD REMOVED]
// unsigned int interfaceIndex = 0;
@@ -240,7 +271,7 @@ static CommandReturn _controlAddConnection_CreateTunnel(
addConnectionCommand->ipType = ADDR_INET6;
} else {
- printf("Error: local address %s not same type as remote address %s\n",
+ snprintf(output, output_size, "Error: local address %s not same type as remote address %s\n",
local_ip, remote_ip);
parcMemory_Deallocate(&addConnectionCommand);
return CommandReturn_Failure;
@@ -268,47 +299,51 @@ static CommandReturn _controlAddConnection_CreateTunnel(
static CommandReturn _controlAddConnection_IpHelp(CommandParser *parser,
CommandOps *ops,
PARCList *args,
- const char *protocol) {
-#ifdef __linux__
- printf("add connection hicn <symbolic> <remote_ip> <local_ip>\n");
-#endif
- printf(
- "add connection udp <symbolic> <remote_ip> <port> <local_ip> <port>\n");
- printf(
- " <symbolic> : symbolic name, e.g. 'conn1' (must be "
- "unique, start with alpha)\n");
- printf(
- " <remote_ip> : the IPv4 or IPv6 or hostname of the remote system\n");
- printf(" <local_ip> : optional local IP address to bind to\n");
- printf("\n");
+ const char *protocol,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size,
+ #ifdef __linux__
+ "add connection hicn <symbolic> <remote_ip> <local_ip>\n"
+ #endif
+ "add connection udp <symbolic> <remote_ip> <port> <local_ip> <port>\n"
+ " <symbolic> : symbolic name, e.g. 'conn1' (must be "
+ "unique, start with alpha)\n"
+ " <remote_ip> : the IPv4 or IPv6 or hostname of the remote system\n"
+ " <local_ip> : optional local IP address to bind to\n"
+ "\n");
return CommandReturn_Success;
}
#ifdef __linux__
-static CommandReturn _controlAddConnection_HicnHelpExecute(
- CommandParser *parser, CommandOps *ops, PARCList *args) {
- _controlAddConnection_IpHelp(parser, ops, args, "hicn");
+static CommandReturn _controlAddConnection_HicnHelpExecute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ _controlAddConnection_IpHelp(parser, ops, args, "hicn", output, output_size);
return CommandReturn_Success;
}
static CommandReturn _controlAddConnection_HicnExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
static const int _indexSymbolic = 3;
static const int _indexRemAddr = 4;
static const int _indexLocAddr = 5;
if (parcList_Size(args) != 6) {
- _controlAddConnection_HicnHelpExecute(parser, ops, args);
+ _controlAddConnection_HicnHelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
char *symbolic = parcList_GetAtIndex(args, _indexSymbolic);
if (!utils_ValidateSymbolicName(symbolic)) {
- printf(
- "Invalid symbolic name. Must begin with alpha and contain only "
+ snprintf(output, output_size, "Invalid symbolic name. Must begin with alpha and contain only "
"alphanum.\n");
return CommandReturn_Failure;
}
@@ -318,21 +353,25 @@ static CommandReturn _controlAddConnection_HicnExecute(CommandParser *parser,
char *port = "1234"; // this is a random port number that will be ignored
return _controlAddConnection_CreateTunnel(
- parser, ops, local_ip, port, remote_ip, port, HICN_CONN, symbolic);
+ parser, ops, local_ip, port, remote_ip, port, HICN_CONN, symbolic, output, output_size);
}
#endif
static CommandReturn _controlAddConnection_UdpHelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- _controlAddConnection_IpHelp(parser, ops, args, "udp");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ _controlAddConnection_IpHelp(parser, ops, args, "udp", output, output_size);
return CommandReturn_Success;
}
static CommandReturn _controlAddConnection_UdpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
static const int _indexSymbolic = 3;
static const int _indexRemAddr = 4;
static const int _indexRemPort = 5;
@@ -340,14 +379,14 @@ static CommandReturn _controlAddConnection_UdpExecute(CommandParser *parser,
static const int _indexLocPort = 7;
if (parcList_Size(args) != 8) {
- _controlAddConnection_UdpHelpExecute(parser, ops, args);
+ _controlAddConnection_UdpHelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
char *symbolic = parcList_GetAtIndex(args, _indexSymbolic);
-
+ size_t offset = 0;
if (!utils_ValidateSymbolicName(symbolic)) {
- printf(
+ snprintf(output, output_size,
"Invalid symbolic name. Must begin with alpha and contain only "
"alphanum.\n");
return CommandReturn_Failure;
@@ -361,20 +400,25 @@ static CommandReturn _controlAddConnection_UdpExecute(CommandParser *parser,
return _controlAddConnection_CreateTunnel(parser, ops, local_ip, local_port,
remote_ip, remote_port, UDP_CONN,
- symbolic);
+ symbolic,
+ output + offset, output_size - offset);
}
static CommandReturn _controlAddConnection_TcpHelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- _controlAddConnection_IpHelp(parser, ops, args, "tcp");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ _controlAddConnection_IpHelp(parser, ops, args, "tcp", output, output_size);
return CommandReturn_Success;
}
static CommandReturn _controlAddConnection_TcpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
static const int _indexSymbolic = 3;
static const int _indexRemAddr = 4;
static const int _indexRemPort = 5;
@@ -382,15 +426,13 @@ static CommandReturn _controlAddConnection_TcpExecute(CommandParser *parser,
static const int _indexLocPort = 7;
if (parcList_Size(args) != 8) {
- _controlAddConnection_UdpHelpExecute(parser, ops, args);
+ _controlAddConnection_UdpHelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
char *symbolic = parcList_GetAtIndex(args, _indexSymbolic);
-
if (!utils_ValidateSymbolicName(symbolic)) {
- printf(
- "Invalid symbolic name. Must begin with alpha and contain only "
+ snprintf(output, output_size, "Invalid symbolic name. Must begin with alpha and contain only "
"alphanum.\n");
return CommandReturn_Failure;
}
@@ -403,5 +445,6 @@ static CommandReturn _controlAddConnection_TcpExecute(CommandParser *parser,
return _controlAddConnection_CreateTunnel(parser, ops, local_ip, local_port,
remote_ip, remote_port, TCP_CONN,
- symbolic);
+ symbolic,
+ output, output_size);
}