[qca-nss-ecm] Improved IP and MAC address string handling.
- Replace sprintf with snprintf
- Donot use ecm_ip_addr_to_string() function where the
IP version is known. Instead use the IPv4 and IPv6 formatting
macros.
- Removed unused string code from the neigbour solicitation send
function.
Change-Id: Iefc73478e5e99f7c67af259000a1f95adb8aae0a
Signed-off-by: Murat Sezgin <msezgin@codeaurora.org>
diff --git a/ecm_classifier_pcc.c b/ecm_classifier_pcc.c
index de27104..9af9ecc 100644
--- a/ecm_classifier_pcc.c
+++ b/ecm_classifier_pcc.c
@@ -217,21 +217,13 @@
ECM_NIN4_ADDR_TO_IP_ADDR(ecm_src_ip, src_ip);
ECM_NIN4_ADDR_TO_IP_ADDR(ecm_dest_ip, dest_ip);
- {
- char src_ip_str[40];
- char dest_ip_str[40];
-
- ecm_ip_addr_to_string(src_ip_str, ecm_src_ip);
- ecm_ip_addr_to_string(dest_ip_str, ecm_dest_ip);
-
- DEBUG_INFO("Permit Accel v4, lookup connection using \n"
- "Protocol: %d\n"
- "src: %s:%d\n"
- "dest: %s:%d\n",
- protocol,
- src_ip_str, src_port,
- dest_ip_str, dest_port);
- }
+ DEBUG_INFO("Permit Accel v4, lookup connection using \n"
+ "Protocol: %d\n"
+ "src: " ECM_IP_ADDR_DOT_FMT ":%d\n"
+ "dest: " ECM_IP_ADDR_DOT_FMT ":%d\n",
+ protocol,
+ ECM_IP_ADDR_TO_DOT(ecm_src_ip), src_port,
+ ECM_IP_ADDR_TO_DOT(ecm_dest_ip), dest_port);
ci = ecm_db_connection_find_and_ref(ecm_src_ip, ecm_dest_ip, protocol, src_port, dest_port);
if (!ci) {
@@ -296,21 +288,13 @@
in6 = *dest_ip;
ECM_NIN6_ADDR_TO_IP_ADDR(ecm_dest_ip, in6);
- {
- char src_ip_str[40];
- char dest_ip_str[40];
-
- ecm_ip_addr_to_string(src_ip_str, ecm_src_ip);
- ecm_ip_addr_to_string(dest_ip_str, ecm_dest_ip);
-
- DEBUG_INFO("Permit Accel v6, lookup connection using \n"
- "Protocol: %d\n"
- "src: %s:%d\n"
- "dest: %s:%d\n",
- protocol,
- src_ip_str, src_port,
- dest_ip_str, dest_port);
- }
+ DEBUG_INFO("Permit Accel v6, lookup connection using \n"
+ "Protocol: %d\n"
+ "src: " ECM_IP_ADDR_OCTAL_FMT ":%d\n"
+ "dest: " ECM_IP_ADDR_OCTAL_FMT ":%d\n",
+ protocol,
+ ECM_IP_ADDR_TO_OCTAL(ecm_src_ip), src_port,
+ ECM_IP_ADDR_TO_OCTAL(ecm_dest_ip), dest_port);
ci = ecm_db_connection_find_and_ref(ecm_src_ip, ecm_dest_ip, protocol, src_port, dest_port);
if (!ci) {
@@ -369,21 +353,13 @@
ECM_NIN4_ADDR_TO_IP_ADDR(ecm_src_ip, src_ip);
ECM_NIN4_ADDR_TO_IP_ADDR(ecm_dest_ip, dest_ip);
- {
- char src_ip_str[40];
- char dest_ip_str[40];
-
- ecm_ip_addr_to_string(src_ip_str, ecm_src_ip);
- ecm_ip_addr_to_string(dest_ip_str, ecm_dest_ip);
-
- DEBUG_INFO("Deny Accel v4, lookup connection using \n"
- "Protocol: %d\n"
- "src: %s:%d\n"
- "dest: %s:%d\n",
- protocol,
- src_ip_str, src_port,
- dest_ip_str, dest_port);
- }
+ DEBUG_INFO("Deny Accel v4, lookup connection using \n"
+ "Protocol: %d\n"
+ "src: " ECM_IP_ADDR_DOT_FMT ":%d\n"
+ "dest: " ECM_IP_ADDR_DOT_FMT ":%d\n",
+ protocol,
+ ECM_IP_ADDR_TO_DOT(ecm_src_ip), src_port,
+ ECM_IP_ADDR_TO_DOT(ecm_dest_ip), dest_port);
ci = ecm_db_connection_find_and_ref(ecm_src_ip, ecm_dest_ip, protocol, src_port, dest_port);
if (!ci) {
@@ -455,21 +431,13 @@
in6 = *dest_ip;
ECM_NIN6_ADDR_TO_IP_ADDR(ecm_dest_ip, in6);
- {
- char src_ip_str[40];
- char dest_ip_str[40];
-
- ecm_ip_addr_to_string(src_ip_str, ecm_src_ip);
- ecm_ip_addr_to_string(dest_ip_str, ecm_dest_ip);
-
- DEBUG_INFO("Deny Accel v6, lookup connection using \n"
- "Protocol: %d\n"
- "src: %s:%d\n"
- "dest: %s:%d\n",
- protocol,
- src_ip_str, src_port,
- dest_ip_str, dest_port);
- }
+ DEBUG_INFO("Deny Accel v6, lookup connection using \n"
+ "Protocol: %d\n"
+ "src: " ECM_IP_ADDR_OCTAL_FMT ":%d\n"
+ "dest: " ECM_IP_ADDR_OCTAL_FMT ":%d\n",
+ protocol,
+ ECM_IP_ADDR_TO_OCTAL(ecm_src_ip), src_port,
+ ECM_IP_ADDR_TO_OCTAL(ecm_dest_ip), dest_port);
ci = ecm_db_connection_find_and_ref(ecm_src_ip, ecm_dest_ip, protocol, src_port, dest_port);
if (!ci) {
diff --git a/ecm_db.c b/ecm_db.c
index 516b98e..6b3e940 100644
--- a/ecm_db.c
+++ b/ecm_db.c
@@ -8159,16 +8159,16 @@
long int expires_in;
int sport;
int sport_nat;
- char snode_address[25];
- char snode_address_nat[25];
- char sip_address[50];
- char sip_address_nat[50];
- char dnode_address[25];
- char dnode_address_nat[25];
+ char snode_address[ECM_MAC_ADDR_STR_BUFF_SIZE];
+ char snode_address_nat[ECM_MAC_ADDR_STR_BUFF_SIZE];
+ char sip_address[ECM_IP_ADDR_STR_BUFF_SIZE];
+ char sip_address_nat[ECM_IP_ADDR_STR_BUFF_SIZE];
+ char dnode_address[ECM_MAC_ADDR_STR_BUFF_SIZE];
+ char dnode_address_nat[ECM_MAC_ADDR_STR_BUFF_SIZE];
int dport;
int dport_nat;
- char dip_address[50];
- char dip_address_nat[50];
+ char dip_address[ECM_IP_ADDR_STR_BUFF_SIZE];
+ char dip_address_nat[ECM_IP_ADDR_STR_BUFF_SIZE];
ecm_db_direction_t direction;
int ip_version;
int protocol;
@@ -8236,22 +8236,22 @@
hi = ci->mapping_to->host;
ecm_ip_addr_to_string(dip_address, hi->address);
ni = ci->to_node;
- sprintf(dnode_address, "%pM", ni->address);
+ snprintf(dnode_address, sizeof(dnode_address), "%pM", ni->address);
hi = ci->mapping_nat_to->host;
ecm_ip_addr_to_string(dip_address_nat, hi->address);
hi = ci->mapping_from->host;
ecm_ip_addr_to_string(sip_address, hi->address);
ni = ci->from_node;
- sprintf(snode_address, "%pM", ni->address);
+ snprintf(snode_address, sizeof(snode_address), "%pM", ni->address);
hi = ci->mapping_nat_from->host;
ecm_ip_addr_to_string(sip_address_nat, hi->address);
ni = ci->to_nat_node;
- sprintf(dnode_address_nat, "%pM", ni->address);
+ snprintf(dnode_address_nat, sizeof(dnode_address_nat), "%pM", ni->address);
ni = ci->from_nat_node;
- sprintf(snode_address_nat, "%pM", ni->address);
+ snprintf(snode_address_nat, sizeof(snode_address_nat), "%pM", ni->address);
direction = ci->direction;
ip_version = ci->ip_version;
@@ -8517,7 +8517,7 @@
{
int result;
int port;
- char address[25];
+ char address[ECM_IP_ADDR_STR_BUFF_SIZE];
int tcp_from;
int tcp_to;
int udp_from;
@@ -8647,7 +8647,7 @@
int ecm_db_host_state_get(struct ecm_state_file_instance *sfi, struct ecm_db_host_instance *hi)
{
int result;
- char address[50];
+ char address[ECM_IP_ADDR_STR_BUFF_SIZE];
#ifdef ECM_DB_XREF_ENABLE
int mapping_count;
#endif
@@ -8724,7 +8724,7 @@
int ecm_db_node_state_get(struct ecm_state_file_instance *sfi, struct ecm_db_node_instance *ni)
{
int result;
- char address[25];
+ char address[ECM_MAC_ADDR_STR_BUFF_SIZE];
#ifdef ECM_DB_XREF_ENABLE
int from_connections_count;
int to_connections_count;
@@ -8760,7 +8760,7 @@
spin_unlock_bh(&ecm_db_lock);
#endif
time_added = ni->time_added;
- sprintf(address, "%pM", ni->address);
+ snprintf(address, sizeof(address), "%pM", ni->address);
#ifdef ECM_DB_ADVANCED_STATS_ENABLE
ecm_db_node_data_stats_get(ni, &from_data_total, &to_data_total,
diff --git a/ecm_interface.c b/ecm_interface.c
index e3d5247..adb322f 100644
--- a/ecm_interface.c
+++ b/ecm_interface.c
@@ -874,14 +874,9 @@
struct in6_addr mc_dst_addr;
struct rt6_info *rt6i;
struct neighbour *neigh;
- ip_addr_t ecm_mc_dst_addr, ecm_src_addr;
struct net *netf = dev_net(dev);
int ret;
- char __attribute__((unused)) dst_addr_str[ECM_IP_ADDR_STRING_BUFFER_SIZE];
- char __attribute__((unused)) mc_dst_addr_str[ECM_IP_ADDR_STRING_BUFFER_SIZE];
- char __attribute__((unused)) src_addr_str[ECM_IP_ADDR_STRING_BUFFER_SIZE];
-
/*
* Find source and destination addresses in Linux format. We need
* mcast destination address as well.
@@ -891,20 +886,11 @@
ret = ipv6_dev_get_saddr(netf, dev, &dst_addr, 0, &src_addr);
/*
- * IP address in string format for debug
- */
- ecm_ip_addr_to_string(dst_addr_str, addr);
- ECM_NIN6_ADDR_TO_IP_ADDR(ecm_mc_dst_addr, mc_dst_addr);
- ecm_ip_addr_to_string(mc_dst_addr_str, ecm_mc_dst_addr);
- ECM_NIN6_ADDR_TO_IP_ADDR(ecm_src_addr, src_addr);
- ecm_ip_addr_to_string(src_addr_str, ecm_src_addr);
-
- /*
* Find the route entry
*/
rt6i = rt6_lookup(netf, &dst_addr, NULL, 0, 0);
if (!rt6i) {
- DEBUG_TRACE("IPv6 Route lookup failure for destination IPv6 address %s\n", dst_addr_str);
+ DEBUG_TRACE("IPv6 Route lookup failure for destination IPv6 address " ECM_IP_ADDR_OCTAL_FMT "\n", ECM_IP_ADDR_TO_OCTAL(addr));
return;
}
@@ -917,7 +903,7 @@
neigh = rt6i->dst.ops->neigh_lookup(&rt6i->dst, NULL, &dst_addr);
#endif
if (neigh == NULL) {
- DEBUG_TRACE("Neighbour lookup failure for destination IPv6 address %s\n", dst_addr_str);
+ DEBUG_TRACE("Neighbour lookup failure for destination IPv6 address " ECM_IP_ADDR_OCTAL_FMT "\n", ECM_IP_ADDR_TO_OCTAL(addr));
dst_release(&rt6i->dst);
return;
}
diff --git a/ecm_types.h b/ecm_types.h
index 44c0c26..97b1435 100644
--- a/ecm_types.h
+++ b/ecm_types.h
@@ -44,7 +44,9 @@
#define ECM_IP_ADDR_NULL {0, 0, 0, 0}
-#define ECM_IP_ADDR_STRING_BUFFER_SIZE 40
+#define ECM_MAC_ADDR_STR_BUFF_SIZE 18 /* This is the size of a string in the format of aa:bb:cc:dd:ee:ff */
+#define ECM_IP_ADDR_STR_BUFF_SIZE 40 /* This is the size of a string in the format of aaaa:bbbb:cccc:0000:1111:dddd:eeee:ffff */
+#define ECM_IP_ADDR_DOT_FMT_STR_BUFF_SIZE 16 /* This is the size of a string in the format of 192.168.100.200 */
/*
* Type checking functions for various forms of IP address
@@ -344,12 +346,12 @@
{
#ifdef ECM_IPV6_ENABLE
if (!ECM_IP_ADDR_IS_V4(a)) {
- sprintf(str, ECM_IP_ADDR_OCTAL_FMT, ECM_IP_ADDR_TO_OCTAL(a));
+ snprintf(str, ECM_IP_ADDR_STR_BUFF_SIZE, ECM_IP_ADDR_OCTAL_FMT, ECM_IP_ADDR_TO_OCTAL(a));
return;
}
#endif
- sprintf(str, ECM_IP_ADDR_DOT_FMT, ECM_IP_ADDR_TO_DOT(a));
+ snprintf(str, ECM_IP_ADDR_DOT_FMT_STR_BUFF_SIZE, ECM_IP_ADDR_DOT_FMT, ECM_IP_ADDR_TO_DOT(a));
}
/*