From patchwork Mon Sep 27 12:50:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 65839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 494FCB70CD for ; Mon, 27 Sep 2010 22:52:43 +1000 (EST) Received: from localhost ([127.0.0.1]:33949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P0DCC-0007Zq-Rm for incoming@patchwork.ozlabs.org; Mon, 27 Sep 2010 08:52:40 -0400 Received: from [140.186.70.92] (port=43381 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P0DAj-0007YG-IW for qemu-devel@nongnu.org; Mon, 27 Sep 2010 08:51:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1P0DAf-0002XJ-7U for qemu-devel@nongnu.org; Mon, 27 Sep 2010 08:51:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50406) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1P0DAf-0002XE-0A for qemu-devel@nongnu.org; Mon, 27 Sep 2010 08:51:05 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8RCp3Fv021745 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 27 Sep 2010 08:51:03 -0400 Received: from dhcp-91-7.nay.redhat.com.englab.nay.redhat.com (dhcp-91-7.nay.redhat.com [10.66.91.7]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o8RCp0Ww009064; Mon, 27 Sep 2010 08:51:01 -0400 To: qemu-devel@nongnu.org, anthony@codemonkey.ws, mst@redhat.com From: Jason Wang Date: Mon, 27 Sep 2010 20:50:53 +0800 Message-ID: <20100927125053.12060.15146.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com> In-Reply-To: <20100927124606.12060.66912.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com> References: <20100927124606.12060.66912.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kvm@vger.kernel.org Subject: [Qemu-devel] [RFC PATCH 1/4] net: move announce_self_create to net.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Export and move announce_self_create to net.c in order to be used by model specific announcing function. Signed-off-by: Jason Wang --- net.c | 31 +++++++++++++++++++++++++++++++ net.h | 1 + savevm.c | 32 -------------------------------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/net.c b/net.c index 3d0fde7..5ec6912 100644 --- a/net.c +++ b/net.c @@ -42,6 +42,37 @@ static QTAILQ_HEAD(, VLANClientState) non_vlan_clients; int default_net = 1; +#ifndef ETH_P_RARP +#define ETH_P_RARP 0x8035 +#endif +#define ARP_HTYPE_ETH 0x0001 +#define ARP_PTYPE_IP 0x0800 +#define ARP_OP_REQUEST_REV 0x3 + +int announce_self_create(uint8_t *buf, uint8_t *mac_addr) +{ + /* Ethernet header. */ + memset(buf, 0xff, 6); /* destination MAC addr */ + memcpy(buf + 6, mac_addr, 6); /* source MAC addr */ + *(uint16_t *)(buf + 12) = htons(ETH_P_RARP); /* ethertype */ + + /* RARP header. */ + *(uint16_t *)(buf + 14) = htons(ARP_HTYPE_ETH); /* hardware addr space */ + *(uint16_t *)(buf + 16) = htons(ARP_PTYPE_IP); /* protocol addr space */ + *(buf + 18) = 6; /* hardware addr length (ethernet) */ + *(buf + 19) = 4; /* protocol addr length (IPv4) */ + *(uint16_t *)(buf + 20) = htons(ARP_OP_REQUEST_REV); /* opcode */ + memcpy(buf + 22, mac_addr, 6); /* source hw addr */ + memset(buf + 28, 0x00, 4); /* source protocol addr */ + memcpy(buf + 32, mac_addr, 6); /* target hw addr */ + memset(buf + 38, 0x00, 4); /* target protocol addr */ + + /* Padding to get up to 60 bytes (ethernet min packet size, minus FCS). */ + memset(buf + 42, 0x00, 18); + + return 60; /* len (FCS will be added by hardware) */ +} + /***********************************************************/ /* network device redirectors */ diff --git a/net.h b/net.h index 518cf9c..e3f643c 100644 --- a/net.h +++ b/net.h @@ -177,5 +177,6 @@ int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data); void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); int net_handle_fd_param(Monitor *mon, const char *param); +int announce_self_create(uint8_t *buf, uint8_t *mac_addr); #endif diff --git a/savevm.c b/savevm.c index 6fa7a5f..545d511 100644 --- a/savevm.c +++ b/savevm.c @@ -86,38 +86,6 @@ #define SELF_ANNOUNCE_ROUNDS 5 -#ifndef ETH_P_RARP -#define ETH_P_RARP 0x8035 -#endif -#define ARP_HTYPE_ETH 0x0001 -#define ARP_PTYPE_IP 0x0800 -#define ARP_OP_REQUEST_REV 0x3 - -static int announce_self_create(uint8_t *buf, - uint8_t *mac_addr) -{ - /* Ethernet header. */ - memset(buf, 0xff, 6); /* destination MAC addr */ - memcpy(buf + 6, mac_addr, 6); /* source MAC addr */ - *(uint16_t *)(buf + 12) = htons(ETH_P_RARP); /* ethertype */ - - /* RARP header. */ - *(uint16_t *)(buf + 14) = htons(ARP_HTYPE_ETH); /* hardware addr space */ - *(uint16_t *)(buf + 16) = htons(ARP_PTYPE_IP); /* protocol addr space */ - *(buf + 18) = 6; /* hardware addr length (ethernet) */ - *(buf + 19) = 4; /* protocol addr length (IPv4) */ - *(uint16_t *)(buf + 20) = htons(ARP_OP_REQUEST_REV); /* opcode */ - memcpy(buf + 22, mac_addr, 6); /* source hw addr */ - memset(buf + 28, 0x00, 4); /* source protocol addr */ - memcpy(buf + 32, mac_addr, 6); /* target hw addr */ - memset(buf + 38, 0x00, 4); /* target protocol addr */ - - /* Padding to get up to 60 bytes (ethernet min packet size, minus FCS). */ - memset(buf + 42, 0x00, 18); - - return 60; /* len (FCS will be added by hardware) */ -} - static void qemu_announce_self_iter(NICState *nic, void *opaque) { uint8_t buf[60];