@@ -57,97 +57,6 @@ BlacklistSrcJsonObject BlacklistSrc::toJsonObject() {
5757 return conf;
5858}
5959
60- void BlacklistSrc::create (Ddosmitigator &parent, const std::string &ip,
61- const BlacklistSrcJsonObject &conf) {
62- // This method creates the actual BlacklistSrc object given thee key param.
63- // Please remember to call here the create static method for all sub-objects
64- // of BlacklistSrc.
65- parent.logger ()->debug (" BlacklistSrc create" );
66-
67- try {
68- parent.logger ()->debug (" blacklist size {0} " , parent.blacklistsrc_ .size ());
69- // TODO check if src ip rules are already present
70- // and reinject datapath with srcblacklist ps
71-
72- if (parent.blacklistsrc_ .size () >= 0 ) {
73- parent.setSrcMatch (true );
74- parent.reloadCode ();
75- }
76-
77- auto srcblacklist =
78- parent.get_percpuhash_table <uint32_t , uint64_t >(" srcblacklist" );
79- srcblacklist.set (utils::ip_string_to_be_uint (ip), 0 );
80- } catch (...) {
81- throw std::runtime_error (" unable to add element to map" );
82- }
83-
84- BlacklistSrcJsonObject configuration;
85- configuration.setIp (ip);
86-
87- parent.blacklistsrc_ .emplace (std::piecewise_construct,
88- std::forward_as_tuple (ip),
89- std::forward_as_tuple (parent, configuration));
90- }
91-
92- std::shared_ptr<BlacklistSrc> BlacklistSrc::getEntry (Ddosmitigator &parent,
93- const std::string &ip) {
94- // This method retrieves the pointer to BlacklistSrc object specified by its
95- // keys.
96- parent.logger ()->debug (" BlacklistSrc getEntry" );
97-
98- return std::shared_ptr<BlacklistSrc>(&parent.blacklistsrc_ .at (ip),
99- [](BlacklistSrc *) {});
100- }
101-
102- void BlacklistSrc::removeEntry (Ddosmitigator &parent, const std::string &ip) {
103- // This method removes the single BlacklistSrc object specified by its keys.
104- // Remember to call here the remove static method for all-sub-objects of
105- // BlacklistSrc.
106- parent.logger ()->debug (" BlacklistSrc removeEntry" );
107-
108- // ebpf map remove is performed in destructor
109- parent.blacklistsrc_ .erase (ip);
110-
111- if (parent.blacklistsrc_ .size () == 0 ) {
112- parent.setSrcMatch (false );
113- parent.reloadCode ();
114- }
115-
116- return ;
117- }
118-
119- std::vector<std::shared_ptr<BlacklistSrc>> BlacklistSrc::get (
120- Ddosmitigator &parent) {
121- // This methods get the pointers to all the BlacklistSrc objects in
122- // Ddosmitigator.
123- parent.logger ()->debug (" BlacklistSrc get vector" );
124-
125- std::vector<std::shared_ptr<BlacklistSrc>> blacklistsrc;
126-
127- for (auto &it : parent.blacklistsrc_ ) {
128- blacklistsrc.push_back (BlacklistSrc::getEntry (parent, it.first ));
129- }
130-
131- return blacklistsrc;
132- }
133-
134- void BlacklistSrc::remove (Ddosmitigator &parent) {
135- // This method removes all BlacklistSrc objects in Ddosmitigator.
136- // Remember to call here the remove static method for all-sub-objects of
137- // BlacklistSrc.
138- parent.logger ()->debug (" BlacklistSrc remove" );
139-
140- // ebpf maps remove performed in destructor
141- parent.blacklistsrc_ .clear ();
142-
143- if (parent.blacklistsrc_ .size () == 0 ) {
144- parent.setSrcMatch (false );
145- parent.reloadCode ();
146- }
147-
148- return ;
149- }
150-
15160std::string BlacklistSrc::getIp () {
15261 logger ()->debug (" BlacklistSrc getIp {0} " , this ->ip_ );
15362
0 commit comments