VBoxManageNATNetwork.cpp revision e5b0208675ead20da446a0a114cb9f76babf5e11
/* $Id$ */
/** @file
* VBoxManage - Implementation of NAT Network command command.
*/
/*
* Copyright (C) 2006-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifndef VBOX_ONLY_DOCS
#endif /* !VBOX_ONLY_DOCS */
#ifndef RT_OS_WINDOWS
#else
/* from <ws2ipdef.h> */
# define INET6_ADDRSTRLEN 65
#endif
#define IPv6
#include <vector>
#include <string>
#include "VBoxManage.h"
#include "VBoxPortForwardString.h"
#ifndef VBOX_ONLY_DOCS
using namespace com;
typedef enum enMainOpCodes
{
OP_ADD = 1000,
} OPCODE;
static const RTGETOPTDEF g_aNATNetworkIPOptions[]
= {
};
typedef struct PFNAME2DELETE
{
char szName[PF_NAMELEN];
bool fIPv6;
{
const char *pNetworkCidr = NULL;
int enable = -1;
int dhcp = -1;
int ipv6 = -1;
int c;
a->argc,
a->argv,
enmCode != OP_REMOVE ? RT_ELEMENTS(g_aNATNetworkIPOptions) : 4, /* we use only --netname and --ifname for remove*/
{
switch (c)
{
case 't': // --netname
if (pNetName)
else
break;
case 'n': // --network
if (pNetworkCidr)
else
break;
case 'e': // --enable
if (enable >= 0)
else
enable = 1;
break;
case 'd': // --disable
if (enable >= 0)
else
enable = 0;
break;
case 'h':
if (dhcp != -1)
dhcp = ValueUnion.f;
break;
case '6':
if (ipv6 != -1)
ipv6 = ValueUnion.f;
break;
case 'L': /* ipv6 loopback */
case 'l': /* ipv4 loopback */
{
/* deletion */
"loopback couldn't be deleted on modified\n");
if (c == 'L')
loopback6Offset = -1;
else
{
int vrc;
if (RT_FAILURE(vrc))
return errorSyntax(USAGE_NATNETWORK,
"Not enough parmaters\n");
}
}
else /* addition */
{
if (c == 'L')
else
}
break;
case 'P': /* ipv6 portforwarding*/
case 'p': /* ipv4 portforwarding */
{
{
/* netPfStrToPf will clean up the Pfr */
if (RT_FAILURE(irc))
return errorSyntax(USAGE_NATNETWORK,
"Invalid port-forward rule %s\n",
}
else
{
int vrc;
return errorSyntax(USAGE_NATNETWORK,
"Port-forward could be deleted on modify \n");
if (RT_FAILURE(vrc))
return errorSyntax(USAGE_NATNETWORK,
"Not enough parmaters\n");
return errorSyntax(USAGE_NATNETWORK,
"Port-forward rule name is too long\n");
}
break;
}
case VINF_GETOPT_NOT_OPTION:
return errorSyntax(USAGE_NATNETWORK,
"unhandled parameter: %s",
default:
if (c > 0)
{
if (RT_C_IS_GRAPH(c))
return errorSyntax(USAGE_NATNETWORK,
"unhandled option: -%c", c);
else
return errorSyntax(USAGE_NATNETWORK,
"unhandled option: %i", c);
}
else if (c == VERR_GETOPT_UNKNOWN_OPTION)
return errorSyntax(USAGE_NATNETWORK,
else if (ValueUnion.pDef)
return errorSyntax(USAGE_NATNETWORK,
else
}
}
if (!pNetName)
return errorSyntax(USAGE_NATNETWORK,
"You need to specify the --netname option");
/* verification */
switch (enmCode)
{
case OP_ADD:
if (!pNetworkCidr)
return errorSyntax(USAGE_NATNETWORK,
"You need to specify the --network option");
break;
case OP_MODIFY:
case OP_REMOVE:
case OP_START:
case OP_STOP:
break;
default:
}
{
return errorArgument("NATNetwork server already exists");
return errorArgument("Failed to create the NAT network service");
}
return errorArgument("NATNetwork server does not exist");
switch (enmCode)
{
case OP_ADD:
case OP_MODIFY:
{
if (pNetworkCidr)
{
return errorArgument("Failed to set configuration");
}
if (dhcp >= 0)
{
return errorArgument("Failed to set configuration");
}
if (ipv6 >= 0)
{
return errorArgument("Failed to set configuration");
}
if (!vPfName2Delete.empty())
{
{
return errorArgument("Failed to delete pf");
}
}
{
{
else
continue; /* XXX: warning here. */
(*it).u16PfrHostPort,
(*it).u16PfrGuestPort));
return errorArgument("Failed to add pf");
}
}
if (loopback6Offset)
{
if (loopback6Offset == -1)
loopback6Offset = 0; /* deletion */
}
/* addLocalMapping (hostid, offset) */
if (!vLoopback2Add.empty())
{
/* we're expecting stings 127.0.0.1=5 */
++it)
{
}
}
if (!vLoopback2Delete.empty())
{
/* we're expecting stings 127.0.0.1 */
++it)
{
}
}
if (enable >= 0)
{
return errorArgument("Failed to set configuration");
}
break;
}
case OP_REMOVE:
{
return errorArgument("Failed to remove nat network");
break;
}
case OP_START:
{
return errorArgument("Failed to start network");
break;
}
case OP_STOP:
{
return errorArgument("Failed to start network");
break;
}
default:;
}
return 0;
}
int handleNATNetwork(HandlerArg *a)
{
if (a->argc < 1)
int result;
int cProcessed;
else
return result;
}
#endif /* !VBOX_ONLY_DOCS */