diff options
-rw-r--r-- | net/ethernet/eth.c | 96 |
1 files changed, 46 insertions, 50 deletions
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 72bdb15036ec..43863933f27f 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c | |||
@@ -78,39 +78,37 @@ __setup("ether=", netdev_boot_setup); | |||
78 | * in here instead. It is up to the 802.2 layer to carry protocol information. | 78 | * in here instead. It is up to the 802.2 layer to carry protocol information. |
79 | */ | 79 | */ |
80 | int eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type, | 80 | int eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type, |
81 | void *daddr, void *saddr, unsigned len) | 81 | void *daddr, void *saddr, unsigned len) |
82 | { | 82 | { |
83 | struct ethhdr *eth = (struct ethhdr *)skb_push(skb,ETH_HLEN); | 83 | struct ethhdr *eth = (struct ethhdr *)skb_push(skb, ETH_HLEN); |
84 | 84 | ||
85 | if(type!=ETH_P_802_3) | 85 | if (type != ETH_P_802_3) |
86 | eth->h_proto = htons(type); | 86 | eth->h_proto = htons(type); |
87 | else | 87 | else |
88 | eth->h_proto = htons(len); | 88 | eth->h_proto = htons(len); |
89 | 89 | ||
90 | /* | 90 | /* |
91 | * Set the source hardware address. | 91 | * Set the source hardware address. |
92 | */ | 92 | */ |
93 | 93 | ||
94 | if(!saddr) | 94 | if (!saddr) |
95 | saddr = dev->dev_addr; | 95 | saddr = dev->dev_addr; |
96 | memcpy(eth->h_source,saddr,dev->addr_len); | 96 | memcpy(eth->h_source, saddr, dev->addr_len); |
97 | 97 | ||
98 | if(daddr) | 98 | if (daddr) { |
99 | { | 99 | memcpy(eth->h_dest, daddr, dev->addr_len); |
100 | memcpy(eth->h_dest,daddr,dev->addr_len); | ||
101 | return ETH_HLEN; | 100 | return ETH_HLEN; |
102 | } | 101 | } |
103 | 102 | ||
104 | /* | 103 | /* |
105 | * Anyway, the loopback-device should never use this function... | 104 | * Anyway, the loopback-device should never use this function... |
106 | */ | 105 | */ |
107 | 106 | ||
108 | if (dev->flags & (IFF_LOOPBACK|IFF_NOARP)) | 107 | if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) { |
109 | { | ||
110 | memset(eth->h_dest, 0, dev->addr_len); | 108 | memset(eth->h_dest, 0, dev->addr_len); |
111 | return ETH_HLEN; | 109 | return ETH_HLEN; |
112 | } | 110 | } |
113 | 111 | ||
114 | return -ETH_HLEN; | 112 | return -ETH_HLEN; |
115 | } | 113 | } |
116 | 114 | ||
@@ -129,17 +127,16 @@ int eth_rebuild_header(struct sk_buff *skb) | |||
129 | struct ethhdr *eth = (struct ethhdr *)skb->data; | 127 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
130 | struct net_device *dev = skb->dev; | 128 | struct net_device *dev = skb->dev; |
131 | 129 | ||
132 | switch (eth->h_proto) | 130 | switch (eth->h_proto) { |
133 | { | ||
134 | #ifdef CONFIG_INET | 131 | #ifdef CONFIG_INET |
135 | case __constant_htons(ETH_P_IP): | 132 | case __constant_htons(ETH_P_IP): |
136 | return arp_find(eth->h_dest, skb); | 133 | return arp_find(eth->h_dest, skb); |
137 | #endif | 134 | #endif |
138 | default: | 135 | default: |
139 | printk(KERN_DEBUG | 136 | printk(KERN_DEBUG |
140 | "%s: unable to resolve type %X addresses.\n", | 137 | "%s: unable to resolve type %X addresses.\n", |
141 | dev->name, (int)eth->h_proto); | 138 | dev->name, (int)eth->h_proto); |
142 | 139 | ||
143 | memcpy(eth->h_source, dev->dev_addr, dev->addr_len); | 140 | memcpy(eth->h_source, dev->dev_addr, dev->addr_len); |
144 | break; | 141 | break; |
145 | } | 142 | } |
@@ -147,7 +144,6 @@ int eth_rebuild_header(struct sk_buff *skb) | |||
147 | return 0; | 144 | return 0; |
148 | } | 145 | } |
149 | 146 | ||
150 | |||
151 | /** | 147 | /** |
152 | * eth_type_trans - determine the packet's protocol ID. | 148 | * eth_type_trans - determine the packet's protocol ID. |
153 | * @skb: received socket data | 149 | * @skb: received socket data |
@@ -161,50 +157,51 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev) | |||
161 | { | 157 | { |
162 | struct ethhdr *eth; | 158 | struct ethhdr *eth; |
163 | unsigned char *rawp; | 159 | unsigned char *rawp; |
164 | 160 | ||
165 | skb->mac.raw = skb->data; | 161 | skb->mac.raw = skb->data; |
166 | skb_pull(skb,ETH_HLEN); | 162 | skb_pull(skb, ETH_HLEN); |
167 | eth = eth_hdr(skb); | 163 | eth = eth_hdr(skb); |
168 | 164 | ||
169 | if (is_multicast_ether_addr(eth->h_dest)) { | 165 | if (is_multicast_ether_addr(eth->h_dest)) { |
170 | if (!compare_ether_addr(eth->h_dest, dev->broadcast)) | 166 | if (!compare_ether_addr(eth->h_dest, dev->broadcast)) |
171 | skb->pkt_type = PACKET_BROADCAST; | 167 | skb->pkt_type = PACKET_BROADCAST; |
172 | else | 168 | else |
173 | skb->pkt_type = PACKET_MULTICAST; | 169 | skb->pkt_type = PACKET_MULTICAST; |
174 | } | 170 | } |
175 | 171 | ||
176 | /* | 172 | /* |
177 | * This ALLMULTI check should be redundant by 1.4 | 173 | * This ALLMULTI check should be redundant by 1.4 |
178 | * so don't forget to remove it. | 174 | * so don't forget to remove it. |
179 | * | 175 | * |
180 | * Seems, you forgot to remove it. All silly devices | 176 | * Seems, you forgot to remove it. All silly devices |
181 | * seems to set IFF_PROMISC. | 177 | * seems to set IFF_PROMISC. |
182 | */ | 178 | */ |
183 | 179 | ||
184 | else if(1 /*dev->flags&IFF_PROMISC*/) { | 180 | else if (1 /*dev->flags&IFF_PROMISC */ ) { |
185 | if (unlikely(compare_ether_addr(eth->h_dest, dev->dev_addr))) | 181 | if (unlikely(compare_ether_addr(eth->h_dest, dev->dev_addr))) |
186 | skb->pkt_type = PACKET_OTHERHOST; | 182 | skb->pkt_type = PACKET_OTHERHOST; |
187 | } | 183 | } |
188 | 184 | ||
189 | if (ntohs(eth->h_proto) >= 1536) | 185 | if (ntohs(eth->h_proto) >= 1536) |
190 | return eth->h_proto; | 186 | return eth->h_proto; |
191 | 187 | ||
192 | rawp = skb->data; | 188 | rawp = skb->data; |
193 | 189 | ||
194 | /* | 190 | /* |
195 | * This is a magic hack to spot IPX packets. Older Novell breaks | 191 | * This is a magic hack to spot IPX packets. Older Novell breaks |
196 | * the protocol design and runs IPX over 802.3 without an 802.2 LLC | 192 | * the protocol design and runs IPX over 802.3 without an 802.2 LLC |
197 | * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This | 193 | * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This |
198 | * won't work for fault tolerant netware but does for the rest. | 194 | * won't work for fault tolerant netware but does for the rest. |
199 | */ | 195 | */ |
200 | if (*(unsigned short *)rawp == 0xFFFF) | 196 | if (*(unsigned short *)rawp == 0xFFFF) |
201 | return htons(ETH_P_802_3); | 197 | return htons(ETH_P_802_3); |
202 | 198 | ||
203 | /* | 199 | /* |
204 | * Real 802.2 LLC | 200 | * Real 802.2 LLC |
205 | */ | 201 | */ |
206 | return htons(ETH_P_802_2); | 202 | return htons(ETH_P_802_2); |
207 | } | 203 | } |
204 | EXPORT_SYMBOL(eth_type_trans); | ||
208 | 205 | ||
209 | /** | 206 | /** |
210 | * eth_header_parse - extract hardware address from packet | 207 | * eth_header_parse - extract hardware address from packet |
@@ -230,8 +227,8 @@ int eth_header_cache(struct neighbour *neigh, struct hh_cache *hh) | |||
230 | struct ethhdr *eth; | 227 | struct ethhdr *eth; |
231 | struct net_device *dev = neigh->dev; | 228 | struct net_device *dev = neigh->dev; |
232 | 229 | ||
233 | eth = (struct ethhdr*) | 230 | eth = (struct ethhdr *) |
234 | (((u8*)hh->hh_data) + (HH_DATA_OFF(sizeof(*eth)))); | 231 | (((u8 *) hh->hh_data) + (HH_DATA_OFF(sizeof(*eth)))); |
235 | 232 | ||
236 | if (type == __constant_htons(ETH_P_802_3)) | 233 | if (type == __constant_htons(ETH_P_802_3)) |
237 | return -1; | 234 | return -1; |
@@ -251,14 +248,13 @@ int eth_header_cache(struct neighbour *neigh, struct hh_cache *hh) | |||
251 | * | 248 | * |
252 | * Called by Address Resolution module to notify changes in address. | 249 | * Called by Address Resolution module to notify changes in address. |
253 | */ | 250 | */ |
254 | void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev, unsigned char * haddr) | 251 | void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev, |
252 | unsigned char *haddr) | ||
255 | { | 253 | { |
256 | memcpy(((u8*)hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)), | 254 | memcpy(((u8 *) hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)), |
257 | haddr, dev->addr_len); | 255 | haddr, dev->addr_len); |
258 | } | 256 | } |
259 | 257 | ||
260 | EXPORT_SYMBOL(eth_type_trans); | ||
261 | |||
262 | /** | 258 | /** |
263 | * eth_mac_addr - set new Ethernet hardware address | 259 | * eth_mac_addr - set new Ethernet hardware address |
264 | * @dev: network device | 260 | * @dev: network device |
@@ -270,10 +266,10 @@ EXPORT_SYMBOL(eth_type_trans); | |||
270 | */ | 266 | */ |
271 | static int eth_mac_addr(struct net_device *dev, void *p) | 267 | static int eth_mac_addr(struct net_device *dev, void *p) |
272 | { | 268 | { |
273 | struct sockaddr *addr=p; | 269 | struct sockaddr *addr = p; |
274 | if (netif_running(dev)) | 270 | if (netif_running(dev)) |
275 | return -EBUSY; | 271 | return -EBUSY; |
276 | memcpy(dev->dev_addr, addr->sa_data,dev->addr_len); | 272 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
277 | return 0; | 273 | return 0; |
278 | } | 274 | } |
279 | 275 | ||
@@ -315,7 +311,7 @@ void ether_setup(struct net_device *dev) | |||
315 | dev->tx_queue_len = 1000; /* Ethernet wants good queues */ | 311 | dev->tx_queue_len = 1000; /* Ethernet wants good queues */ |
316 | dev->flags = IFF_BROADCAST|IFF_MULTICAST; | 312 | dev->flags = IFF_BROADCAST|IFF_MULTICAST; |
317 | 313 | ||
318 | memset(dev->broadcast,0xFF, ETH_ALEN); | 314 | memset(dev->broadcast, 0xFF, ETH_ALEN); |
319 | 315 | ||
320 | } | 316 | } |
321 | EXPORT_SYMBOL(ether_setup); | 317 | EXPORT_SYMBOL(ether_setup); |