From patchwork Wed May 23 17:58:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 160995 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 32AD9B6FBB for ; Thu, 24 May 2012 04:02:11 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 21607280F9; Wed, 23 May 2012 20:00:51 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9pdUwblB31oe; Wed, 23 May 2012 20:00:50 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7A59E28104; Wed, 23 May 2012 19:58:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0C4BA280AE for ; Wed, 23 May 2012 19:58:28 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lWn9lvZUaDb9 for ; Wed, 23 May 2012 19:58:27 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from spamkiller05.natinst.com (mailserver5.natinst.com [130.164.80.5]) by theia.denx.de (Postfix) with ESMTP id 12F242809D for ; Wed, 23 May 2012 19:58:19 +0200 (CEST) Received: from mailserv58-us.natinst.com (nb-hsrp-1338.natinst.com [130.164.19.133]) by spamkiller05.natinst.com (8.14.4/8.14.4) with ESMTP id q4NHwIQR006970; Wed, 23 May 2012 12:58:18 -0500 Received: from localhost.localdomain ([130.164.14.197]) by mailserv58-us.natinst.com (Lotus Domino Release 8.5.2FP3) with ESMTP id 2012052312581824-530908 ; Wed, 23 May 2012 12:58:18 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Wed, 23 May 2012 12:58:00 -0500 Message-Id: <1337795897-19231-5-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1332891772-17279-1-git-send-email-joe.hershberger@ni.com> References: <1332891772-17279-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on MailServ58-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 05/23/2012 12:58:18 PM, Serialize by Router on MailServ58-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 05/23/2012 12:58:18 PM, Serialize complete at 05/23/2012 12:58:18 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7724, 1.0.260, 0.0.0000 definitions=2012-05-23_01:2012-05-23, 2012-05-22, 1970-01-01 signatures=0 Cc: Joe Hershberger Subject: [U-Boot] [PATCH v3 04/21] net: Encapsulate CDP packet identification X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Checking for CDP packets should be encapsulated, not copied code. Signed-off-by: Joe Hershberger Cc: Joe Hershberger --- Changes for v2: - Split from patch "Move CDP out of net.c" - Changed to static inline Changes for v3: - Added a function comment - Added a blank line arch/powerpc/cpu/mpc8xx/fec.c | 2 +- include/net.h | 12 ++++++++++-- net/net.c | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/cpu/mpc8xx/fec.c b/arch/powerpc/cpu/mpc8xx/fec.c index f2a2c3a..0bc1e5d 100644 --- a/arch/powerpc/cpu/mpc8xx/fec.c +++ b/arch/powerpc/cpu/mpc8xx/fec.c @@ -274,7 +274,7 @@ static int fec_recv (struct eth_device *dev) #if defined(CONFIG_CMD_CDP) if ((rx[0] & 1) != 0 && memcmp ((uchar *) rx, NetBcastAddr, 6) != 0 - && memcmp ((uchar *) rx, NetCDPAddr, 6) != 0) + && !is_cdp_packet((uchar *)rx)) rx = NULL; #endif /* diff --git a/include/net.h b/include/net.h index 8a5b09f..453231b 100644 --- a/include/net.h +++ b/include/net.h @@ -356,8 +356,6 @@ extern uchar NetEtherNullAddr[6]; extern ushort NetOurVLAN; /* Our VLAN */ extern ushort NetOurNativeVLAN; /* Our Native VLAN */ -extern const uchar NetCDPAddr[6]; /* Ethernet CDP address */ - extern int NetState; /* Network loop state */ #define NETLOOP_CONTINUE 1 #define NETLOOP_RESTART 2 @@ -387,6 +385,16 @@ extern IPaddr_t NetPingIP; /* the ip address to ping */ /* when CDP completes these hold the return values */ extern ushort CDPNativeVLAN; /* CDP returned native VLAN */ extern ushort CDPApplianceVLAN; /* CDP returned appliance VLAN */ + +/* + * Check for a CDP packet by examining the received MAC address field + */ +static inline int is_cdp_packet(const uchar *et_addr) +{ + extern const uchar NetCDPAddr[6]; + + return memcmp(et_addr, NetCDPAddr, 6) == 0; +} #endif #if defined(CONFIG_CMD_SNTP) diff --git a/net/net.c b/net/net.c index 4cd5a0a..8624db0 100644 --- a/net/net.c +++ b/net/net.c @@ -1099,7 +1099,7 @@ NetReceive(uchar *inpkt, int len) #if defined(CONFIG_CMD_CDP) /* keep track if packet is CDP */ - iscdp = memcmp(et->et_dest, NetCDPAddr, 6) == 0; + iscdp = is_cdp_packet(et->et_dest); #endif myvlanid = ntohs(NetOurVLAN);