softwarecontainer
0.18.0-739e8d7 2017-05-04
|
Sets up and manages network access and routing to the container. More...
#include <networkgateway.h>
Public Types | |
enum | GatewayState : unsigned int { CREATED, CONFIGURED, ACTIVATED } |
Public Member Functions | |
NetworkGateway (const int32_t id, const std::string bridgeDevice, const std::string gateway, const uint8_t maskBits, std::shared_ptr< ContainerAbstractInterface > container) | |
Creates a network gateway. More... | |
bool | readConfigElement (const json_t *element) override |
Gateway specific parsing of config elements. More... | |
bool | activateGateway () override |
Implements Gateway::activateGateway. More... | |
bool | teardownGateway () override |
Implements Gateway::teardownGateway. More... | |
virtual std::string | id () const |
Returns the ID of the gateway. More... | |
virtual bool | setConfig (const json_t *config) |
Configure this gateway according to the supplied JSON configuration string. More... | |
virtual bool | activate () |
Applies any configuration set by setConfig() More... | |
virtual bool | teardown () |
Restore system to the state prior to launching of gateway. More... | |
virtual bool | isConfigured () |
Is the gateway configured or not? More... | |
virtual bool | isActivated () |
Is the gateway activated or not? More... | |
Protected Member Functions | |
std::shared_ptr< ContainerAbstractInterface > | getContainer () |
Get a handle to the associated container. More... | |
bool | setEnvironmentVariable (const std::string &variable, const std::string &value) |
Set an environment variable in the associated container. More... | |
Protected Attributes | |
bool | m_activatedOnce |
Sets up and manages network access and routing to the container.
The responsibility of NetworkGateway is to setup network connection as specified by given configuration. This configuration is described in detail in the user documentation, but a short summary of it is how to handle incoming and outgoing network packages using the three targets: ACCEPT, DROP and REJECT.
Definition at line 39 of file networkgateway.h.
softwarecontainer::NetworkGateway::NetworkGateway | ( | const int32_t | id, |
const std::string | bridgeDevice, | ||
const std::string | gateway, | ||
const uint8_t | maskBits, | ||
std::shared_ptr< ContainerAbstractInterface > | container | ||
) |
Creates a network gateway.
SoftwareContainerError | if there is an error during initialization. |
Definition at line 29 of file networkgateway.cpp.
|
overridevirtual |
Gateway specific parsing of config elements.
All gateways implement this method in order to provide gateway specific parsing of the configuration content.
element | A JSON configuration item. |
Implements softwarecontainer::Gateway.
Definition at line 45 of file networkgateway.cpp.
References softwarecontainer::NetworkGatewayParser::parseNetworkGatewayConfiguration().
|
overridevirtual |
Implements Gateway::activateGateway.
Implements softwarecontainer::Gateway.
Definition at line 58 of file networkgateway.cpp.
References softwarecontainer::NetworkGatewayFunctions::generateIP(), and softwarecontainer::Gateway::getContainer().
|
overridevirtual |
Implements Gateway::teardownGateway.
Implements softwarecontainer::Gateway.
Definition at line 102 of file networkgateway.cpp.
References softwarecontainer::Netlink::findAddresses(), softwarecontainer::Netlink::findLink(), softwarecontainer::Gateway::getContainer(), softwarecontainer::Netlink::hasAddress(), softwarecontainer::Netlink::linkDown(), softwarecontainer::Netlink::linkUp(), softwarecontainer::Netlink::setDefaultGateway(), and softwarecontainer::Netlink::setIP().
|
virtualinherited |
Returns the ID of the gateway.
Definition at line 36 of file gateway.cpp.
Referenced by softwarecontainer::Gateway::activate(), softwarecontainer::DBusGatewayInstance::DBusGatewayInstance(), softwarecontainer::Gateway::setConfig(), and softwarecontainer::Gateway::teardown().
|
virtualinherited |
Configure this gateway according to the supplied JSON configuration string.
config | JSON string containing gateway-specific JSON configuration |
config
was successfully parsed, false otherwiseGatewayError | If called on an already activated gateway. |
Reimplemented in softwarecontainer::DBusGateway.
Definition at line 41 of file gateway.cpp.
References softwarecontainer::Gateway::id(), and softwarecontainer::Gateway::readConfigElement().
|
virtualinherited |
Applies any configuration set by setConfig()
GatewayError | If called on an already activated gateway, or if the gateway has not been previously configured, or if there is not container instance set. |
Reimplemented in softwarecontainer::DBusGateway.
Definition at line 78 of file gateway.cpp.
References softwarecontainer::Gateway::id().
|
virtualinherited |
Restore system to the state prior to launching of gateway.
Any cleanup code (removal of files, virtual interfaces, etc) should be placed here.
GatewayError | If called on a non activated gateway. |
Reimplemented in softwarecontainer::DBusGateway.
Definition at line 103 of file gateway.cpp.
References softwarecontainer::Gateway::id().
Referenced by softwarecontainer::DBusGatewayInstance::DBusGatewayInstance().
|
virtualinherited |
Is the gateway configured or not?
Reimplemented in softwarecontainer::DBusGateway.
Definition at line 134 of file gateway.cpp.
|
virtualinherited |
Is the gateway activated or not?
Dynamic gateways will return true if they have been activated at least once. Non-dynamic gateways will return true if they are in state ACTIVATED
Reimplemented in softwarecontainer::DBusGateway.
Definition at line 139 of file gateway.cpp.
Referenced by softwarecontainer::DBusGatewayInstance::DBusGatewayInstance().
|
protectedinherited |
Get a handle to the associated container.
GatewayError | If called before setContainer() has been called. |
Definition at line 128 of file gateway.cpp.
Referenced by activateGateway(), softwarecontainer::DBusGatewayInstance::activateGateway(), softwarecontainer::WaylandGateway::readConfigElement(), and teardownGateway().
|
protectedinherited |
Set an environment variable in the associated container.