Skip to content

Commit 09d1bd5

Browse files
authored
Merge pull request #121 from polycube-network/pr/port_firewall_to_transparent_services
port firewall to transparent services
2 parents b813c67 + ca9557c commit 09d1bd5

92 files changed

Lines changed: 667 additions & 2389 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/polycubed/src/polycubed.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "config.h"
3030
#include "polycube/services/json.hpp"
31+
#include "netlink.h"
3132
#include "rest_server.h"
3233
#include "utils.h"
3334
#include "version.h"
@@ -53,6 +54,7 @@ std::shared_ptr<spdlog::logger> logger;
5354
// create core instance
5455
PolycubedCore *core;
5556
RestServer *restserver;
57+
int netlink_nofitication_id = -1;
5658

5759
void shutdown() {
5860
static bool done = false;
@@ -67,6 +69,12 @@ void shutdown() {
6769
delete core;
6870
delete restserver;
6971
}
72+
73+
if (netlink_nofitication_id != -1) {
74+
Netlink::getInstance().unregisterObserver(Netlink::Event::LINK_DELETED,
75+
netlink_nofitication_id);
76+
}
77+
7078
logger->info("polycubed is shutting down. Bye!");
7179
done = true;
7280
}
@@ -246,6 +254,12 @@ int main(int argc, char *argv[]) {
246254
auto base_model = new BaseModel();
247255
core = new PolycubedCore(base_model);
248256

257+
// register handler to detect interfaces that are deleted
258+
netlink_nofitication_id = Netlink::getInstance().registerObserver(
259+
Netlink::Event::LINK_DELETED,
260+
std::bind(&ServiceController::netlink_notification, std::placeholders::_1,
261+
std::placeholders::_2));
262+
249263
// setup rest server
250264
int thr = 4;
251265
Address addr(config.getServerIP(), Pistache::Port(config.getServerPort()));

src/polycubed/src/port.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include "port.h"
1818
#include "controller.h"
1919
#include "extiface.h"
20-
#include "netlink.h"
21-
2220
#include "service_controller.h"
2321

2422
// workaround for now
@@ -37,17 +35,9 @@ Port::Port(CubeIface &parent, const std::string &name, uint16_t index,
3735
index_(index),
3836
uuid_(GuidGenerator().newGuid()),
3937
peer_port_(nullptr),
40-
logger(spdlog::get("polycubed")) {
41-
netlink_notification_index = Netlink::getInstance().registerObserver(
42-
Netlink::Event::LINK_DELETED,
43-
std::bind(&Port::netlink_notification, this, std::placeholders::_1,
44-
std::placeholders::_2));
45-
}
38+
logger(spdlog::get("polycubed")) {}
4639

47-
Port::~Port() {
48-
Netlink::getInstance().unregisterObserver(Netlink::Event::LINK_DELETED,
49-
netlink_notification_index);
50-
}
40+
Port::~Port() {}
5141

5242
uint16_t Port::get_port_id() const {
5343
return index_; // TODO: rename this variable
@@ -141,12 +131,6 @@ bool Port::operator==(const PortIface &rhs) const {
141131
return false;
142132
}
143133

144-
void Port::netlink_notification(int ifindex, const std::string &ifname) {
145-
if (peer_ == ifname) {
146-
set_peer("");
147-
}
148-
}
149-
150134
void Port::set_peer(const std::string &peer) {
151135
{
152136
std::lock_guard<std::mutex> guard(port_mutex_);

src/polycubed/src/port.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ class Port : public polycube::service::PortIface, public PeerIface {
7676
virtual void set_conf(const nlohmann::json &conf);
7777
virtual nlohmann::json to_json() const;
7878

79-
void netlink_notification(int ifindex, const std::string &ifname);
80-
8179
static void connect(PeerIface &p1, PeerIface &p2);
8280
static void unconnect(PeerIface &p1, PeerIface &p2);
8381

@@ -93,7 +91,6 @@ class Port : public polycube::service::PortIface, public PeerIface {
9391
uint16_t index_;
9492
Guid uuid_;
9593
std::string peer_;
96-
int netlink_notification_index;
9794

9895
// TODO: I know, a better name is needed
9996
PeerIface *peer_port_;

src/polycubed/src/service_controller.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,26 @@ bool ServiceController::parse_peer_name(const std::string &peer,
284284
return true;
285285
}
286286

287+
void ServiceController::netlink_notification(int ifindex,
288+
const std::string &ifname) {
289+
std::lock_guard<std::mutex> guard(service_ctrl_mutex_);
290+
if (ports_to_ifaces.count(ifname) == 0) {
291+
return; // nothing to do here
292+
}
293+
294+
auto iface = ports_to_ifaces.at(ifname);
295+
296+
auto peer = iface->get_peer_iface();
297+
if (peer) {
298+
auto port = dynamic_cast<Port*>(peer);
299+
if (port) {
300+
port->set_peer("");
301+
}
302+
}
303+
304+
// try to remove it if existed
305+
ports_to_ifaces.erase(ifname);
306+
}
307+
287308
} // namespace polycubed
288309
} // namespace polycube

src/polycubed/src/service_controller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class ServiceController {
8888
static std::unordered_map<std::string, std::shared_ptr<ExtIface>>
8989
ports_to_ifaces;
9090

91+
static void netlink_notification(int ifindex, const std::string &ifname);
92+
9193
private:
9294
std::shared_ptr<spdlog::logger> l;
9395
std::shared_ptr<ManagementInterface> management_interface_;

src/services/pcn-firewall/datamodel/firewall.yang

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module firewall {
44
prefix "firewall";
55

66
import polycube-base { prefix "polycube-base"; }
7-
import polycube-standard-base { prefix "polycube-standard-base"; }
7+
import polycube-transparent-base { prefix "polycube-transparent-base"; }
88

99
organization "Polycube open source project";
1010
description "YANG data model for the Polycube Firewall service";
@@ -14,7 +14,7 @@ module firewall {
1414
polycube-base:service-name "firewall";
1515
polycube-base:service-min-kernel-version "4.14.0";
1616

17-
uses "polycube-standard-base:standard-base-yang-module";
17+
uses "polycube-transparent-base:transparent-base-yang-module";
1818

1919
typedef action {
2020
type enumeration {
@@ -97,16 +97,6 @@ module firewall {
9797
}
9898
}
9999

100-
leaf ingress-port {
101-
type string;
102-
description "Name for the ingress port, from which arrives traffic processed by INGRESS chain (by default it's the first port of the cube)";
103-
}
104-
105-
leaf egress-port {
106-
type string;
107-
description "Name for the egress port, from which arrives traffic processed by EGRESS chain (by default it's the second port of the cube)";
108-
}
109-
110100
leaf conntrack {
111101
type enumeration {
112102
enum ON;
@@ -126,7 +116,7 @@ module firewall {
126116
leaf interactive {
127117
type boolean;
128118
description "Interactive mode applies new rules immediately; if 'false', the command 'apply-rules' has to be used to apply all the rules at once. Default is TRUE.";
129-
default true;
119+
default true;
130120
}
131121

132122
list session-table {

src/services/pcn-firewall/src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ add_library(pcn-firewall SHARED
2323
ChainStats.cpp
2424
SessionTable.cpp
2525
Firewall.cpp
26-
Ports.cpp
2726
Firewall-lib.cpp
2827
Utils.cpp)
2928

0 commit comments

Comments
 (0)