19#ifndef PORTFORWARDING_H
20#define PORTFORWARDING_H
23#include "NetworkingHelper.h"
24#include "DobbyRdkPluginUtils.h"
25#include <rt_defs_plugins.h>
28#include <netinet/in.h>
59 const std::shared_ptr<NetworkingHelper> &helper,
60 const std::string &containerId,
61 rt_defs_plugins_networking_data_port_forwarding *portsConfig);
64 const std::shared_ptr<NetworkingHelper> &helper,
65 const std::string &containerId,
66 rt_defs_plugins_networking_data_port_forwarding *portsConfig);
69 const std::shared_ptr<DobbyRdkPluginUtils> &utils,
70 rt_defs_plugins_networking_data_port_forwarding *portsConfig);
81 std::vector<struct PortForward> hostToContainer;
82 std::vector<struct PortForward> containerToHost;
86std::string parseProtocol(
const std::string &protocol);
87PortForwards parsePortsConfig(rt_defs_plugins_networking_data_port_forwarding *portsConfig);
89std::vector<Netfilter::RuleSet> constructPortForwardingRules(
const std::shared_ptr<NetworkingHelper> &helper,
90 const std::string &containerId,
94std::vector<Netfilter::RuleSet> constructMasqueradeRules(
const std::shared_ptr<NetworkingHelper> &helper,
95 const std::string &containerId,
99bool constructHostToContainerRules(std::vector<Netfilter::RuleSet> &ruleSets,
100 const std::string &containerId,
101 const std::string &containerAddress,
102 const std::vector<struct PortForward> &ports,
103 const int ipVersion);
105std::string createPreroutingRule(
const PortForward &portForward,
106 const std::string &
id,
107 const std::string &ipAddress,
108 const int ipVersion);
110std::string createForwardingRule(
const PortForward &portForward,
111 const std::string &
id,
112 const std::string &ipAddress,
113 const int ipVersion);
115bool constructContainerToHostRules(std::vector<Netfilter::RuleSet> &ruleSets,
116 const std::string &containerId,
117 const std::string &containerAddress,
118 const std::string &vethName,
119 const std::vector<struct PortForward> &ports,
120 const int ipVersion);
122std::string createDnatRule(
const PortForward &portForward,
123 const std::string &
id,
124 const std::string &ipAddress,
125 const int ipVersion);
127std::string createAcceptRule(
const PortForward &portForward,
128 const std::string &
id,
129 const std::string &ipAddress,
130 const std::string &vethName,
131 const int ipVersion);
133std::string createMasqueradeDnatRule(
const PortForward &portForward,
134 const std::string &
id,
135 const std::string &ipAddress,
136 const int ipVersion);
138std::string createMasqueradeSnatRule(
const PortForward &portForward,
139 const std::string &
id,
140 const std::string &ipAddress,
141 const int ipVersion);
143std::string createLocalLinkSnatRule(
const PortForward &portForward,
144 const std::string &
id,
145 const std::string &ipAddress,
146 const int ipVersion);
148std::string createNoIpv6LocalRule(
const PortForward &portForward,
149 const std::string &
id,
150 const std::string &ipAddress,
151 const int ipVersion);
Used to add iptables firewall rules to allow port forwarding between the container and the host.
bool addLocalhostMasquerading(const std::shared_ptr< NetworkingHelper > &helper, const std::shared_ptr< DobbyRdkPluginUtils > &utils, rt_defs_plugins_networking_data_port_forwarding *portsConfig)
Adds iptables rules to forward packets from the container localhost to the host's localhost on specif...
Definition PortForwarding.cpp:222
bool removePortForwards(const std::shared_ptr< Netfilter > &netfilter, const std::shared_ptr< NetworkingHelper > &helper, const std::string &containerId, rt_defs_plugins_networking_data_port_forwarding *portsConfig)
Removes port forwarding rules assigned to the container.
Definition PortForwarding.cpp:135
bool addPortForwards(const std::shared_ptr< Netfilter > &netfilter, const std::shared_ptr< NetworkingHelper > &helper, const std::string &containerId, rt_defs_plugins_networking_data_port_forwarding *portsConfig)
Adds the two iptables firewall rules to enable port forwarding.
Definition PortForwarding.cpp:41
Definition PortForwarding.h:74
Definition PortForwarding.h:80