[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 return 0; 147 } 148 149 150 /* 151 * Determine the packet's protocol ID. The rule here is that we ··· 171 struct ethhdr *eth; 172 unsigned char *rawp; 173 174 - skb->mac.raw=skb->data; 175 skb_pull(skb,ETH_HLEN); 176 eth = eth_hdr(skb); 177 178 - if(*eth->h_dest&1) 179 - { 180 - if(memcmp(eth->h_dest,dev->broadcast, ETH_ALEN)==0) 181 - skb->pkt_type=PACKET_BROADCAST; 182 else 183 - skb->pkt_type=PACKET_MULTICAST; 184 } 185 186 /* ··· 190 * seems to set IFF_PROMISC. 191 */ 192 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; 197 } 198 199 if (ntohs(eth->h_proto) >= 1536)
··· 146 return 0; 147 } 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 + } 162 163 /* 164 * Determine the packet's protocol ID. The rule here is that we ··· 158 struct ethhdr *eth; 159 unsigned char *rawp; 160 161 + skb->mac.raw = skb->data; 162 skb_pull(skb,ETH_HLEN); 163 eth = eth_hdr(skb); 164 165 + if (*eth->h_dest&1) { 166 + if (!compare_eth_addr(eth->h_dest, dev->broadcast)) 167 + skb->pkt_type = PACKET_BROADCAST; 168 else 169 + skb->pkt_type = PACKET_MULTICAST; 170 } 171 172 /* ··· 178 * seems to set IFF_PROMISC. 179 */ 180 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; 184 } 185 186 if (ntohs(eth->h_proto) >= 1536)