diff options
Diffstat (limited to 'net/ethernet/eth.c')
-rw-r--r-- | net/ethernet/eth.c | 100 |
1 files changed, 69 insertions, 31 deletions
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 387c71c584ee..72bdb15036ec 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c | |||
@@ -64,23 +64,24 @@ | |||
64 | 64 | ||
65 | __setup("ether=", netdev_boot_setup); | 65 | __setup("ether=", netdev_boot_setup); |
66 | 66 | ||
67 | /* | 67 | /** |
68 | * Create the Ethernet MAC header for an arbitrary protocol layer | 68 | * eth_header - create the Ethernet header |
69 | * @skb: buffer to alter | ||
70 | * @dev: source device | ||
71 | * @type: Ethernet type field | ||
72 | * @daddr: destination address (NULL leave destination address) | ||
73 | * @saddr: source address (NULL use device source address) | ||
74 | * @len: packet length (<= skb->len) | ||
69 | * | 75 | * |
70 | * saddr=NULL means use device source address | 76 | * |
71 | * daddr=NULL means leave destination address (eg unresolved arp) | 77 | * Set the protocol type. For a packet of type ETH_P_802_3 we put the length |
78 | * in here instead. It is up to the 802.2 layer to carry protocol information. | ||
72 | */ | 79 | */ |
73 | |||
74 | 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, |
75 | void *daddr, void *saddr, unsigned len) | 81 | void *daddr, void *saddr, unsigned len) |
76 | { | 82 | { |
77 | struct ethhdr *eth = (struct ethhdr *)skb_push(skb,ETH_HLEN); | 83 | struct ethhdr *eth = (struct ethhdr *)skb_push(skb,ETH_HLEN); |
78 | 84 | ||
79 | /* | ||
80 | * Set the protocol type. For a packet of type ETH_P_802_3 we put the length | ||
81 | * in here instead. It is up to the 802.2 layer to carry protocol information. | ||
82 | */ | ||
83 | |||
84 | if(type!=ETH_P_802_3) | 85 | if(type!=ETH_P_802_3) |
85 | eth->h_proto = htons(type); | 86 | eth->h_proto = htons(type); |
86 | else | 87 | else |
@@ -113,16 +114,16 @@ int eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type, | |||
113 | return -ETH_HLEN; | 114 | return -ETH_HLEN; |
114 | } | 115 | } |
115 | 116 | ||
116 | 117 | /** | |
117 | /* | 118 | * eth_rebuild_header- rebuild the Ethernet MAC header. |
118 | * Rebuild the Ethernet MAC header. This is called after an ARP | 119 | * @skb: socket buffer to update |
119 | * (or in future other address resolution) has completed on this | 120 | * |
120 | * sk_buff. We now let ARP fill in the other fields. | 121 | * This is called after an ARP or IPV6 ndisc it's resolution on this |
122 | * sk_buff. We now let protocol (ARP) fill in the other fields. | ||
121 | * | 123 | * |
122 | * This routine CANNOT use cached dst->neigh! | 124 | * This routine CANNOT use cached dst->neigh! |
123 | * Really, it is used only when dst->neigh is wrong. | 125 | * Really, it is used only when dst->neigh is wrong. |
124 | */ | 126 | */ |
125 | |||
126 | int eth_rebuild_header(struct sk_buff *skb) | 127 | int eth_rebuild_header(struct sk_buff *skb) |
127 | { | 128 | { |
128 | struct ethhdr *eth = (struct ethhdr *)skb->data; | 129 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
@@ -147,12 +148,15 @@ int eth_rebuild_header(struct sk_buff *skb) | |||
147 | } | 148 | } |
148 | 149 | ||
149 | 150 | ||
150 | /* | 151 | /** |
151 | * Determine the packet's protocol ID. The rule here is that we | 152 | * eth_type_trans - determine the packet's protocol ID. |
152 | * assume 802.3 if the type field is short enough to be a length. | 153 | * @skb: received socket data |
153 | * This is normal practice and works for any 'now in use' protocol. | 154 | * @dev: receiving network device |
155 | * | ||
156 | * The rule here is that we | ||
157 | * assume 802.3 if the type field is short enough to be a length. | ||
158 | * This is normal practice and works for any 'now in use' protocol. | ||
154 | */ | 159 | */ |
155 | |||
156 | __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev) | 160 | __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev) |
157 | { | 161 | { |
158 | struct ethhdr *eth; | 162 | struct ethhdr *eth; |
@@ -202,6 +206,11 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev) | |||
202 | return htons(ETH_P_802_2); | 206 | return htons(ETH_P_802_2); |
203 | } | 207 | } |
204 | 208 | ||
209 | /** | ||
210 | * eth_header_parse - extract hardware address from packet | ||
211 | * @skb: packet to extract header from | ||
212 | * @haddr: destination buffer | ||
213 | */ | ||
205 | static int eth_header_parse(struct sk_buff *skb, unsigned char *haddr) | 214 | static int eth_header_parse(struct sk_buff *skb, unsigned char *haddr) |
206 | { | 215 | { |
207 | struct ethhdr *eth = eth_hdr(skb); | 216 | struct ethhdr *eth = eth_hdr(skb); |
@@ -209,6 +218,12 @@ static int eth_header_parse(struct sk_buff *skb, unsigned char *haddr) | |||
209 | return ETH_ALEN; | 218 | return ETH_ALEN; |
210 | } | 219 | } |
211 | 220 | ||
221 | /** | ||
222 | * eth_header_cache - fill cache entry from neighbour | ||
223 | * @neigh: source neighbour | ||
224 | * @hh: destination cache entry | ||
225 | * Create an Ethernet header template from the neighbour. | ||
226 | */ | ||
212 | int eth_header_cache(struct neighbour *neigh, struct hh_cache *hh) | 227 | int eth_header_cache(struct neighbour *neigh, struct hh_cache *hh) |
213 | { | 228 | { |
214 | unsigned short type = hh->hh_type; | 229 | unsigned short type = hh->hh_type; |
@@ -228,10 +243,14 @@ int eth_header_cache(struct neighbour *neigh, struct hh_cache *hh) | |||
228 | return 0; | 243 | return 0; |
229 | } | 244 | } |
230 | 245 | ||
231 | /* | 246 | /** |
247 | * eth_header_cache_update - update cache entry | ||
248 | * @hh: destination cache entry | ||
249 | * @dev: network device | ||
250 | * @haddr: new hardware address | ||
251 | * | ||
232 | * Called by Address Resolution module to notify changes in address. | 252 | * Called by Address Resolution module to notify changes in address. |
233 | */ | 253 | */ |
234 | |||
235 | void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev, unsigned char * haddr) | 254 | void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev, unsigned char * haddr) |
236 | { | 255 | { |
237 | memcpy(((u8*)hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)), | 256 | memcpy(((u8*)hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)), |
@@ -240,6 +259,15 @@ void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev, unsign | |||
240 | 259 | ||
241 | EXPORT_SYMBOL(eth_type_trans); | 260 | EXPORT_SYMBOL(eth_type_trans); |
242 | 261 | ||
262 | /** | ||
263 | * eth_mac_addr - set new Ethernet hardware address | ||
264 | * @dev: network device | ||
265 | * @p: socket address | ||
266 | * Change hardware address of device. | ||
267 | * | ||
268 | * This doesn't change hardware matching, so needs to be overridden | ||
269 | * for most real devices. | ||
270 | */ | ||
243 | static int eth_mac_addr(struct net_device *dev, void *p) | 271 | static int eth_mac_addr(struct net_device *dev, void *p) |
244 | { | 272 | { |
245 | struct sockaddr *addr=p; | 273 | struct sockaddr *addr=p; |
@@ -249,6 +277,14 @@ static int eth_mac_addr(struct net_device *dev, void *p) | |||
249 | return 0; | 277 | return 0; |
250 | } | 278 | } |
251 | 279 | ||
280 | /** | ||
281 | * eth_change_mtu - set new MTU size | ||
282 | * @dev: network device | ||
283 | * @new_mtu: new Maximum Transfer Unit | ||
284 | * | ||
285 | * Allow changing MTU size. Needs to be overridden for devices | ||
286 | * supporting jumbo frames. | ||
287 | */ | ||
252 | static int eth_change_mtu(struct net_device *dev, int new_mtu) | 288 | static int eth_change_mtu(struct net_device *dev, int new_mtu) |
253 | { | 289 | { |
254 | if (new_mtu < 68 || new_mtu > ETH_DATA_LEN) | 290 | if (new_mtu < 68 || new_mtu > ETH_DATA_LEN) |
@@ -257,8 +293,10 @@ static int eth_change_mtu(struct net_device *dev, int new_mtu) | |||
257 | return 0; | 293 | return 0; |
258 | } | 294 | } |
259 | 295 | ||
260 | /* | 296 | /** |
261 | * Fill in the fields of the device structure with ethernet-generic values. | 297 | * ether_setup - setup Ethernet network device |
298 | * @dev: network device | ||
299 | * Fill in the fields of the device structure with Ethernet-generic values. | ||
262 | */ | 300 | */ |
263 | void ether_setup(struct net_device *dev) | 301 | void ether_setup(struct net_device *dev) |
264 | { | 302 | { |
@@ -283,15 +321,15 @@ void ether_setup(struct net_device *dev) | |||
283 | EXPORT_SYMBOL(ether_setup); | 321 | EXPORT_SYMBOL(ether_setup); |
284 | 322 | ||
285 | /** | 323 | /** |
286 | * alloc_etherdev - Allocates and sets up an ethernet device | 324 | * alloc_etherdev - Allocates and sets up an Ethernet device |
287 | * @sizeof_priv: Size of additional driver-private structure to be allocated | 325 | * @sizeof_priv: Size of additional driver-private structure to be allocated |
288 | * for this ethernet device | 326 | * for this Ethernet device |
289 | * | 327 | * |
290 | * Fill in the fields of the device structure with ethernet-generic | 328 | * Fill in the fields of the device structure with Ethernet-generic |
291 | * values. Basically does everything except registering the device. | 329 | * values. Basically does everything except registering the device. |
292 | * | 330 | * |
293 | * Constructs a new net device, complete with a private data area of | 331 | * Constructs a new net device, complete with a private data area of |
294 | * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for | 332 | * size (sizeof_priv). A 32-byte (not bit) alignment is enforced for |
295 | * this private data area. | 333 | * this private data area. |
296 | */ | 334 | */ |
297 | 335 | ||