aboutsummaryrefslogtreecommitdiff
path: root/net/colo.c
diff options
context:
space:
mode:
authorRao, Lei <lei.rao@intel.com>2021-11-03 10:21:12 +0800
committerJuan Quintela <quintela@trasno.org>2021-11-03 09:39:48 +0100
commit64153ca613d0a50d1301eae4bd895aade001fcca (patch)
tree3db1ca0c48fc2d127e9a58263b18420e0bcba33c /net/colo.c
parente5fdf920964b65678798960d8b3a55453c2e9094 (diff)
downloadqemu-64153ca613d0a50d1301eae4bd895aade001fcca.zip
qemu-64153ca613d0a50d1301eae4bd895aade001fcca.tar.gz
qemu-64153ca613d0a50d1301eae4bd895aade001fcca.tar.bz2
Optimized the function of fill_connection_key.
Remove some unnecessary code to improve the performance of the filter-rewriter module. Signed-off-by: Lei Rao <lei.rao@intel.com> Reviewed-by: Zhang Chen <chen.zhang@intel.com> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Juan Quintela <quintela@trasno.org>
Diffstat (limited to 'net/colo.c')
-rw-r--r--net/colo.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/net/colo.c b/net/colo.c
index 3a3e6e8..1f8162f 100644
--- a/net/colo.c
+++ b/net/colo.c
@@ -83,19 +83,26 @@ int parse_packet_early(Packet *pkt)
return 0;
}
-void extract_ip_and_port(uint32_t tmp_ports, ConnectionKey *key, Packet *pkt)
+void extract_ip_and_port(uint32_t tmp_ports, ConnectionKey *key,
+ Packet *pkt, bool reverse)
{
+ if (reverse) {
+ key->src = pkt->ip->ip_dst;
+ key->dst = pkt->ip->ip_src;
+ key->src_port = ntohs(tmp_ports & 0xffff);
+ key->dst_port = ntohs(tmp_ports >> 16);
+ } else {
key->src = pkt->ip->ip_src;
key->dst = pkt->ip->ip_dst;
key->src_port = ntohs(tmp_ports >> 16);
key->dst_port = ntohs(tmp_ports & 0xffff);
+ }
}
-void fill_connection_key(Packet *pkt, ConnectionKey *key)
+void fill_connection_key(Packet *pkt, ConnectionKey *key, bool reverse)
{
- uint32_t tmp_ports;
+ uint32_t tmp_ports = 0;
- memset(key, 0, sizeof(*key));
key->ip_proto = pkt->ip->ip_p;
switch (key->ip_proto) {
@@ -106,29 +113,15 @@ void fill_connection_key(Packet *pkt, ConnectionKey *key)
case IPPROTO_SCTP:
case IPPROTO_UDPLITE:
tmp_ports = *(uint32_t *)(pkt->transport_header);
- extract_ip_and_port(tmp_ports, key, pkt);
break;
case IPPROTO_AH:
tmp_ports = *(uint32_t *)(pkt->transport_header + 4);
- extract_ip_and_port(tmp_ports, key, pkt);
break;
default:
break;
}
-}
-
-void reverse_connection_key(ConnectionKey *key)
-{
- struct in_addr tmp_ip;
- uint16_t tmp_port;
-
- tmp_ip = key->src;
- key->src = key->dst;
- key->dst = tmp_ip;
- tmp_port = key->src_port;
- key->src_port = key->dst_port;
- key->dst_port = tmp_port;
+ extract_ip_and_port(tmp_ports, key, pkt, reverse);
}
Connection *connection_new(ConnectionKey *key)