Skip to content

Commit

Permalink
Уменьшено потребление памяти при обработке ACL
Browse files Browse the repository at this point in the history
  • Loading branch information
max197616 committed Oct 21, 2019
1 parent a7320b2 commit bcabaa9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 54 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT(extFilter, 0.99.2, [email protected])
AC_INIT(extFilter, 0.99.3, [email protected])

DPDK_HOME=
DPDK_TARGET=
Expand Down
53 changes: 9 additions & 44 deletions src/acl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ rte_acl_ctx* ACL::_setup_acl(struct rte_acl_rule* acl_base, unsigned int acl_num
return NULL;
}

rte_acl_dump(context);

// rte_acl_dump(context); // debug
return context;
}

Expand Down Expand Up @@ -127,8 +128,6 @@ int ACL::initACL(std::map<std::string, int> &fns, int _numa_on, std::set<struct

uint32_t def_ipv6[4] = { 0, 0, 0, 0 };

// unsigned int acl_cnt = 0;

memset(&mapped[0], 0, sizeof(mapped));
std::vector<struct ACL::acl4_rule> acl4_rules;
std::vector<struct ACL::acl6_rule> acl6_rules;
Expand Down Expand Up @@ -295,46 +294,14 @@ int ACL::initACL(std::map<std::string, int> &fns, int _numa_on, std::set<struct
hf.close();
}
}
if(!acl4_rules.empty())
{
_logger.information("Preparing %d rules for IPv4 ACL", (int) acl4_rules.size());
// allocate memory
ipv4_rules = (rte_acl_rule *)calloc(acl4_rules.size(), sizeof(struct ACL::acl4_rule));
if(ipv4_rules == nullptr)
{
_logger.error("Unable to get memory for ipv4 rules");
return -1;
}

int z = 0;
for(auto i=acl4_rules.begin(); i != acl4_rules.end(); i++)
{
rte_memcpy((uint8_t *)ipv4_rules+z*sizeof(struct ACL::acl4_rule), &(*i), sizeof(struct ACL::acl4_rule));
z++;
}
}
poco_information_f2(_logger, "Used %z bytes of memory for acl4 rules (%d entries)", sizeof(ACL::acl4_rule)*acl4_rules.capacity(), (int) acl4_rules.size());
poco_information_f2(_logger, "Used %z bytes of memory for acl6 rules (%d entries)", sizeof(ACL::acl6_rule)*acl6_rules.capacity(), (int) acl6_rules.size());
if(!acl4_rules.empty())
ipv4_rules = (rte_acl_rule *)acl4_rules.data();

if(!acl6_rules.empty())
{
_logger.information("Preparing %d rules for IPv6 ACL", (int) acl6_rules.size());
// allocate memory
ipv6_rules = (rte_acl_rule *)calloc(acl6_rules.size(), sizeof(struct ACL::acl6_rule));
if(ipv6_rules == nullptr)
{
_logger.error("Unable to get memory for ipv6 rules");
free(ipv4_rules);
return -1;
}

int z = 0;
for(auto i=acl6_rules.begin(); i != acl6_rules.end(); i++)
{
rte_memcpy((uint8_t *)ipv6_rules+z*sizeof(struct ACL::acl6_rule), &(*i), sizeof(struct ACL::acl6_rule));
z++;
}
}


ipv6_rules = (rte_acl_rule *)acl6_rules.data();

if(!_numa_on)
{
Expand All @@ -349,8 +316,8 @@ int ACL::initACL(std::map<std::string, int> &fns, int _numa_on, std::set<struct
if (socketid >= NB_SOCKETS)
{
_logger.error("Socket %d of core %d is out of range %d", socketid, (int) lcore_id, NB_SOCKETS);
free(ipv4_rules);
free(ipv6_rules);
// free(ipv4_rules);
// free(ipv6_rules);
return -1;
}
mapped[socketid] = 1;
Expand Down Expand Up @@ -385,8 +352,6 @@ int ACL::initACL(std::map<std::string, int> &fns, int _numa_on, std::set<struct
}
}
}
free(ipv4_rules);
free(ipv6_rules);

int socketid, lcore_id;
for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
Expand Down
14 changes: 7 additions & 7 deletions src/ssl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int parse_ssl(const unsigned char* app_data, uint32_t data_length, ssl_state *st
{
case ssl_wp_header: if(data_length + state->parsed_len - pos <= 4)
{
if(data_length - pos + state->parsed_len > SSL_BUF_SIZE -1)
if(data_length - pos + state->parsed_len > sizeof(state->buf) -1)
{
return -1;
}
Expand Down Expand Up @@ -148,7 +148,7 @@ int parse_ssl(const unsigned char* app_data, uint32_t data_length, ssl_state *st
// state->wp = ssl_wp_pdu;
if(state->parsed_len > 0)
{
if(state->parsed_len > SSL_BUF_SIZE -1)
if(state->parsed_len > sizeof(state->buf) -1)
{
return -1;
}
Expand All @@ -164,7 +164,7 @@ int parse_ssl(const unsigned char* app_data, uint32_t data_length, ssl_state *st
case ssl_wp_handshake_hdr:
if(data_length - pos + state->parsed_len <= 8)
{
if(state->parsed_len - TLS_HEADER_LEN > SSL_BUF_SIZE - 1 || data_length - pos < 0 || state->parsed_len - TLS_HEADER_LEN + data_length - pos > SSL_BUF_SIZE - 1)
if(state->parsed_len - TLS_HEADER_LEN > (int)sizeof(state->buf) - 1 || data_length - pos < 0 || (state->parsed_len - TLS_HEADER_LEN + data_length - pos) > (int)sizeof(state->buf) - 1)
{
return -1;
}
Expand Down Expand Up @@ -205,7 +205,7 @@ int parse_ssl(const unsigned char* app_data, uint32_t data_length, ssl_state *st
} else {
state->wp = ssl_wp_begin_cmnname;
}
if(state->parsed_len - TLS_HEADER_LEN > SSL_BUF_SIZE - 1)
if(state->parsed_len - TLS_HEADER_LEN > (int)sizeof(state->buf) - 1)
{
return -1;
}
Expand Down Expand Up @@ -315,7 +315,7 @@ int parse_ssl(const unsigned char* app_data, uint32_t data_length, ssl_state *st
int z = state->cmnname_size + state->cmnname_pos - state->parsed_len;
if(z > i)
{
if(i < 0 || i + state->parse_cmnname > SSL_BUF_SIZE - 1)
if(i < 0 || i + state->parse_cmnname > (int)sizeof(state->buf) - 1)
{
return -1;
}
Expand All @@ -332,7 +332,7 @@ int parse_ssl(const unsigned char* app_data, uint32_t data_length, ssl_state *st
}
if(state->cmnname_size + state->cmnname_pos != state->parsed_len)
{
if(z + state->parse_cmnname > SSL_BUF_SIZE - 1)
if(z + state->parse_cmnname > (int)sizeof(state->buf) - 1)
return -1;
for(int l = 0; l < z; l++)
p_buf[state->parse_cmnname + l] = app_data[pos + l];
Expand Down Expand Up @@ -412,7 +412,7 @@ int parse_ssl(const unsigned char* app_data, uint32_t data_length, ssl_state *st
break;

case ssl_wp_ext_serv_name:
if(state->skip_size <= SSL_BUF_SIZE - 1)
if(state->skip_size <= sizeof(state->buf) - 1)
{
state->wp = ssl_wp_copy_sni;
state->cmnname_size = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ bool WorkerThread::run(uint32_t coreId)
uint8_t sender_port = m_WorkerConfig.sender_port;
uint16_t tx_queue_id = m_WorkerConfig.tx_queue_id;

_logger.debug("Starting working thread on core %u", coreId);
poco_debug_f1(_logger, "Starting working thread on core %u", coreId);

for (int i = 0; i < qconf->n_rx_queue; i++)
{
Expand Down Expand Up @@ -843,6 +843,6 @@ bool WorkerThread::run(uint32_t coreId)
prev_timer_tsc = cur_tsc;
}
}
_logger.debug("Worker thread on core %u terminated", coreId);
poco_debug_f1(_logger, "Worker thread on core %u terminated", coreId);
return true;
}

0 comments on commit bcabaa9

Please sign in to comment.