[NET]: Slightly optimize ethernet address comparison.

We know the thing is at least 2-byte aligned, so take
advantage of that instead of invoking memcmp() which
results in truly horrifically inefficient code because
it can't assume anything about alignment.

Signed-off-by: David S. Miller <davem@davemloft.net>

+21 -10
+21 -10
net/ethernet/eth.c
··· 146 146 return 0; 147 147 } 148 148 149 + static inline unsigned int compare_eth_addr(const unsigned char *__a, const unsigned char *__b) 150 + { 151 + const unsigned short *dest = (unsigned short *) __a; 152 + const unsigned short *devaddr = (unsigned short *) __b; 153 + unsigned int res; 154 + 155 + BUILD_BUG_ON(ETH_ALEN != 6); 156 + res = ((dest[0] ^ devaddr[0]) | 157 + (dest[1] ^ devaddr[1]) | 158 + (dest[2] ^ devaddr[2])) != 0; 159 + 160 + return res; 161 + } 149 162 150 163 /* 151 164 * Determine the packet's protocol ID. The rule here is that we ··· 171 158 struct ethhdr *eth; 172 159 unsigned char *rawp; 173 160 174 - skb->mac.raw=skb->data; 161 + skb->mac.raw = skb->data; 175 162 skb_pull(skb,ETH_HLEN); 176 163 eth = eth_hdr(skb); 177 164 178 - if(*eth->h_dest&1) 179 - { 180 - if(memcmp(eth->h_dest,dev->broadcast, ETH_ALEN)==0) 181 - skb->pkt_type=PACKET_BROADCAST; 165 + if (*eth->h_dest&1) { 166 + if (!compare_eth_addr(eth->h_dest, dev->broadcast)) 167 + skb->pkt_type = PACKET_BROADCAST; 182 168 else 183 - skb->pkt_type=PACKET_MULTICAST; 169 + skb->pkt_type = PACKET_MULTICAST; 184 170 } 185 171 186 172 /* ··· 190 178 * seems to set IFF_PROMISC. 191 179 */ 192 180 193 - else if(1 /*dev->flags&IFF_PROMISC*/) 194 - { 195 - if(memcmp(eth->h_dest,dev->dev_addr, ETH_ALEN)) 196 - skb->pkt_type=PACKET_OTHERHOST; 181 + else if(1 /*dev->flags&IFF_PROMISC*/) { 182 + if (unlikely(!compare_eth_addr(eth->h_dest, dev->dev_addr))) 183 + skb->pkt_type = PACKET_OTHERHOST; 197 184 } 198 185 199 186 if (ntohs(eth->h_proto) >= 1536)