@@ -176,30 +176,32 @@ Ddosmitigator::getBlacklistSrcList() {
176176
177177void Ddosmitigator::addBlacklistSrc (const std::string &ip,
178178 const BlacklistSrcJsonObject &conf) {
179- logger ()->debug (" BlacklistSrc create" );
180-
181- try {
182- logger ()->debug (" blacklist size {0} " , blacklistsrc_.size ());
183- // TODO check if src ip rules are already present
184- // and reinject datapath with srcblacklist ps
185-
186- if (blacklistsrc_.size () >= 0 ) {
187- setSrcMatch (true );
188- reloadCode ();
179+ if (blacklistsrc_.count (ip) == 0 ) {
180+ logger ()->debug (" BlacklistSrc create" );
181+
182+ try {
183+ logger ()->debug (" blacklist size {0} " , blacklistsrc_.size ());
184+ // TODO check if src ip rules are already present
185+ // and reinject datapath with srcblacklist ps
186+
187+ if (blacklistsrc_.size () >= 0 ) {
188+ setSrcMatch (true );
189+ reloadCode ();
190+ }
191+
192+ auto srcblacklist =
193+ get_percpuhash_table<uint32_t , uint64_t >(" srcblacklist" );
194+ srcblacklist.set (utils::ip_string_to_nbo_uint (ip), 0 );
195+ } catch (...) {
196+ throw std::runtime_error (" unable to add element to map" );
189197 }
190198
191- auto srcblacklist =
192- get_percpuhash_table<uint32_t , uint64_t >(" srcblacklist" );
193- srcblacklist.set (utils::ip_string_to_nbo_uint (ip), 0 );
194- } catch (...) {
195- throw std::runtime_error (" unable to add element to map" );
196- }
199+ BlacklistSrcJsonObject configuration;
200+ configuration.setIp (ip);
197201
198- BlacklistSrcJsonObject configuration;
199- configuration.setIp (ip);
200-
201- blacklistsrc_.emplace (std::piecewise_construct, std::forward_as_tuple (ip),
202- std::forward_as_tuple (*this , configuration));
202+ blacklistsrc_.emplace (std::piecewise_construct, std::forward_as_tuple (ip),
203+ std::forward_as_tuple (*this , configuration));
204+ }
203205}
204206
205207void Ddosmitigator::addBlacklistSrcList (
@@ -264,29 +266,31 @@ Ddosmitigator::getBlacklistDstList() {
264266
265267void Ddosmitigator::addBlacklistDst (const std::string &ip,
266268 const BlacklistDstJsonObject &conf) {
267- logger ()->debug (" BlacklistDst create" );
268-
269- try {
270- // TODO check if dst ip rules are already present
271- // and reinject datapath with dstblacklist ps
272-
273- if (blacklistdst_.size () >= 0 ) {
274- setDstMatch (true );
275- reloadCode ();
269+ if (blacklistdst_.count (ip) == 0 ) {
270+ logger ()->debug (" BlacklistDst create" );
271+
272+ try {
273+ // TODO check if dst ip rules are already present
274+ // and reinject datapath with dstblacklist ps
275+
276+ if (blacklistdst_.size () >= 0 ) {
277+ setDstMatch (true );
278+ reloadCode ();
279+ }
280+
281+ auto dstblacklist =
282+ get_percpuhash_table<uint32_t , uint64_t >(" dstblacklist" );
283+ dstblacklist.set (utils::ip_string_to_nbo_uint (ip), 0 );
284+ } catch (...) {
285+ throw std::runtime_error (" unable to add element to map" );
276286 }
277287
278- auto dstblacklist =
279- get_percpuhash_table<uint32_t , uint64_t >(" dstblacklist" );
280- dstblacklist.set (utils::ip_string_to_nbo_uint (ip), 0 );
281- } catch (...) {
282- throw std::runtime_error (" unable to add element to map" );
283- }
288+ BlacklistDstJsonObject configuration;
289+ configuration.setIp (ip);
284290
285- BlacklistDstJsonObject configuration;
286- configuration.setIp (ip);
287-
288- blacklistdst_.emplace (std::piecewise_construct, std::forward_as_tuple (ip),
289- std::forward_as_tuple (*this , configuration));
291+ blacklistdst_.emplace (std::piecewise_construct, std::forward_as_tuple (ip),
292+ std::forward_as_tuple (*this , configuration));
293+ }
290294}
291295
292296void Ddosmitigator::addBlacklistDstList (
0 commit comments