From patchwork Tue Nov 14 02:11:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 837668 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ybWHs45jdz9s7G for ; Tue, 14 Nov 2017 13:12:57 +1100 (AEDT) Received: from localhost ([::1]:57261 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEQid-0005GG-I1 for incoming@patchwork.ozlabs.org; Mon, 13 Nov 2017 21:12:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEQhq-00054s-3q for qemu-devel@nongnu.org; Mon, 13 Nov 2017 21:12:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEQhm-0000qV-UN for qemu-devel@nongnu.org; Mon, 13 Nov 2017 21:12:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33702) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eEQhm-0000q4-OT for qemu-devel@nongnu.org; Mon, 13 Nov 2017 21:12:02 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9292C0587FA; Tue, 14 Nov 2017 02:12:01 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-130.pek2.redhat.com [10.72.12.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 593205D6AE; Tue, 14 Nov 2017 02:11:59 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Tue, 14 Nov 2017 10:11:35 +0800 Message-Id: <1510625498-4821-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1510625498-4821-1-git-send-email-jasowang@redhat.com> References: <1510625498-4821-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 14 Nov 2017 02:12:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/8] colo: Consolidate the duplicate code chunk into a routine X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mao Zhongyi , Jason Wang , Li Zhijian , Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mao Zhongyi Consolidate the code that extract the ip address(src,dst) and port number(src,dst) of the packet into a separate routine extract_ip_and_port() since the same chunk of code is called from two place. Cc: Zhang Chen Cc: Li Zhijian Cc: Jason Wang Signed-off-by: Mao Zhongyi Signed-off-by: Jason Wang --- net/colo.c | 18 ++++++++++-------- net/colo.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/net/colo.c b/net/colo.c index 28ce7c8..a39d600 100644 --- a/net/colo.c +++ b/net/colo.c @@ -82,6 +82,14 @@ int parse_packet_early(Packet *pkt) return 0; } +void extract_ip_and_port(uint32_t tmp_ports, ConnectionKey *key, Packet *pkt) +{ + 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) { uint32_t tmp_ports; @@ -97,17 +105,11 @@ void fill_connection_key(Packet *pkt, ConnectionKey *key) case IPPROTO_SCTP: case IPPROTO_UDPLITE: tmp_ports = *(uint32_t *)(pkt->transport_header); - key->src = pkt->ip->ip_src; - key->dst = pkt->ip->ip_dst; - key->src_port = ntohs(tmp_ports & 0xffff); - key->dst_port = ntohs(tmp_ports >> 16); + extract_ip_and_port(tmp_ports, key, pkt); break; case IPPROTO_AH: tmp_ports = *(uint32_t *)(pkt->transport_header + 4); - key->src = pkt->ip->ip_src; - key->dst = pkt->ip->ip_dst; - key->src_port = ntohs(tmp_ports & 0xffff); - key->dst_port = ntohs(tmp_ports >> 16); + extract_ip_and_port(tmp_ports, key, pkt); break; default: break; diff --git a/net/colo.h b/net/colo.h index caedb0d..0658e86 100644 --- a/net/colo.h +++ b/net/colo.h @@ -76,6 +76,7 @@ typedef struct Connection { uint32_t connection_key_hash(const void *opaque); int connection_key_equal(const void *opaque1, const void *opaque2); int parse_packet_early(Packet *pkt); +void extract_ip_and_port(uint32_t tmp_ports, ConnectionKey *key, Packet *pkt); void fill_connection_key(Packet *pkt, ConnectionKey *key); void reverse_connection_key(ConnectionKey *key); Connection *connection_new(ConnectionKey *key);