]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
net: Encapsulate CDP packet identification
authorJoe Hershberger <joe.hershberger@ni.com>
Wed, 23 May 2012 07:58:00 +0000 (07:58 +0000)
committerJoe Hershberger <joe.hershberger@ni.com>
Wed, 23 May 2012 19:19:23 +0000 (14:19 -0500)
Checking for CDP packets should be encapsulated, not copied code.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
arch/powerpc/cpu/mpc8xx/fec.c
include/net.h
net/net.c

index 984539dbdf1051a600648d2fbc26493fe4018fb4..b348a98c5810a319b27c7f76d7bc49642344572e 100644 (file)
@@ -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
                        /*
index 8a5b09f2515a3b1edd48c2db4bd7915c42b75e32..453231bfbc99c74d0f46404969a92fa7bd061661 100644 (file)
@@ -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)
index 4cd5a0a73c858e69d17f835b941a667a7048dae1..8624db03a7d7d2d1db46f661efcd5038c4c99599 100644 (file)
--- 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);