aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/drivers/net_kern.c
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2006-09-29 04:58:50 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-09-29 12:18:04 -0400
commitb10aeeef554eb1ff80e10111829f6e7484877811 (patch)
treeefe33871539700cb6f530ed38b755b405b3f3b08 /arch/um/drivers/net_kern.c
parentf3e7ed2b617824f79d1223f37430ccffae59e5b8 (diff)
[PATCH] uml: mechanical tidying after random MACs change
Mechanical, hopefully non-functional changes stemming from setup_etheraddr always succeeding now that it always assigns a MAC, either from the command line or generated randomly: the test of the return of setup_etheraddr is removed, and code dependent on it succeeding is now unconditional setup_etheraddr can now be made void struct uml_net.have_mac is now always 1, so tests of it can be similarly removed, and uses of it can be replaced with 1 struct uml_net.have_mac is no longer used, so it can be removed struct uml_net_private.have_mac is copied from struct uml_net, so it is always 1 tests of uml_net_private.have_mac can be removed uml_net_private.have_mac can now be removed the only call to dev_ip_addr was removed, so it can be deleted It also turns out that setup_etheraddr is called only once, from the same file, so it can be static and its declaration removed from net_kern.h. Similarly, set_ether_mac is defined and called only from one file. Finally, setup_etheraddr and set_ether_mac were moved to avoid needing forward declarations. Signed-off-by: Jeff Dike <jdike@addtoit.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/drivers/net_kern.c')
-rw-r--r--arch/um/drivers/net_kern.c105
1 files changed, 40 insertions, 65 deletions
diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
index 684a1ef93c87..c067abbbfd97 100644
--- a/arch/um/drivers/net_kern.c
+++ b/arch/um/drivers/net_kern.c
@@ -119,11 +119,6 @@ static int uml_net_open(struct net_device *dev)
119 goto out; 119 goto out;
120 } 120 }
121 121
122 if(!lp->have_mac){
123 dev_ip_addr(dev, &lp->mac[2]);
124 set_ether_mac(dev, lp->mac);
125 }
126
127 lp->fd = (*lp->open)(&lp->user); 122 lp->fd = (*lp->open)(&lp->user);
128 if(lp->fd < 0){ 123 if(lp->fd < 0){
129 err = lp->fd; 124 err = lp->fd;
@@ -287,6 +282,39 @@ void uml_net_user_timer_expire(unsigned long _conn)
287#endif 282#endif
288} 283}
289 284
285static void setup_etheraddr(char *str, unsigned char *addr)
286{
287 char *end;
288 int i;
289
290 if(str == NULL)
291 goto random;
292
293 for(i=0;i<6;i++){
294 addr[i] = simple_strtoul(str, &end, 16);
295 if((end == str) ||
296 ((*end != ':') && (*end != ',') && (*end != '\0'))){
297 printk(KERN_ERR
298 "setup_etheraddr: failed to parse '%s' "
299 "as an ethernet address\n", str);
300 goto random;
301 }
302 str = end + 1;
303 }
304 if(addr[0] & 1){
305 printk(KERN_ERR
306 "Attempt to assign a broadcast ethernet address to a "
307 "device disallowed\n");
308 goto random;
309 }
310 return;
311
312random:
313 addr[0] = 0xfe;
314 addr[1] = 0xfd;
315 random_mac(addr);
316}
317
290static DEFINE_SPINLOCK(devices_lock); 318static DEFINE_SPINLOCK(devices_lock);
291static LIST_HEAD(devices); 319static LIST_HEAD(devices);
292 320
@@ -322,15 +350,13 @@ static int eth_configure(int n, void *init, char *mac,
322 list_add(&device->list, &devices); 350 list_add(&device->list, &devices);
323 spin_unlock(&devices_lock); 351 spin_unlock(&devices_lock);
324 352
325 if (setup_etheraddr(mac, device->mac)) 353 setup_etheraddr(mac, device->mac);
326 device->have_mac = 1;
327 354
328 printk(KERN_INFO "Netdevice %d ", n); 355 printk(KERN_INFO "Netdevice %d ", n);
329 if (device->have_mac) 356 printk("(%02x:%02x:%02x:%02x:%02x:%02x) ",
330 printk("(%02x:%02x:%02x:%02x:%02x:%02x) ", 357 device->mac[0], device->mac[1],
331 device->mac[0], device->mac[1], 358 device->mac[2], device->mac[3],
332 device->mac[2], device->mac[3], 359 device->mac[4], device->mac[5]);
333 device->mac[4], device->mac[5]);
334 printk(": "); 360 printk(": ");
335 dev = alloc_etherdev(size); 361 dev = alloc_etherdev(size);
336 if (dev == NULL) { 362 if (dev == NULL) {
@@ -396,7 +422,6 @@ static int eth_configure(int n, void *init, char *mac,
396 .dev = dev, 422 .dev = dev,
397 .fd = -1, 423 .fd = -1,
398 .mac = { 0xfe, 0xfd, 0x0, 0x0, 0x0, 0x0}, 424 .mac = { 0xfe, 0xfd, 0x0, 0x0, 0x0, 0x0},
399 .have_mac = device->have_mac,
400 .protocol = transport->kern->protocol, 425 .protocol = transport->kern->protocol,
401 .open = transport->user->open, 426 .open = transport->user->open,
402 .close = transport->user->close, 427 .close = transport->user->close,
@@ -411,14 +436,12 @@ static int eth_configure(int n, void *init, char *mac,
411 init_timer(&lp->tl); 436 init_timer(&lp->tl);
412 spin_lock_init(&lp->lock); 437 spin_lock_init(&lp->lock);
413 lp->tl.function = uml_net_user_timer_expire; 438 lp->tl.function = uml_net_user_timer_expire;
414 if (lp->have_mac) 439 memcpy(lp->mac, device->mac, sizeof(lp->mac));
415 memcpy(lp->mac, device->mac, sizeof(lp->mac));
416 440
417 if (transport->user->init) 441 if (transport->user->init)
418 (*transport->user->init)(&lp->user, dev); 442 (*transport->user->init)(&lp->user, dev);
419 443
420 if (device->have_mac) 444 set_ether_mac(dev, device->mac);
421 set_ether_mac(dev, device->mac);
422 445
423 return 0; 446 return 0;
424} 447}
@@ -747,54 +770,6 @@ static void close_devices(void)
747 770
748__uml_exitcall(close_devices); 771__uml_exitcall(close_devices);
749 772
750int setup_etheraddr(char *str, unsigned char *addr)
751{
752 char *end;
753 int i;
754
755 if(str == NULL)
756 goto random;
757
758 for(i=0;i<6;i++){
759 addr[i] = simple_strtoul(str, &end, 16);
760 if((end == str) ||
761 ((*end != ':') && (*end != ',') && (*end != '\0'))){
762 printk(KERN_ERR
763 "setup_etheraddr: failed to parse '%s' "
764 "as an ethernet address\n", str);
765 goto random;
766 }
767 str = end + 1;
768 }
769 if(addr[0] & 1){
770 printk(KERN_ERR
771 "Attempt to assign a broadcast ethernet address to a "
772 "device disallowed\n");
773 goto random;
774 }
775 return 1;
776
777random:
778 addr[0] = 0xfe;
779 addr[1] = 0xfd;
780 random_mac(addr);
781 return 1;
782}
783
784void dev_ip_addr(void *d, unsigned char *bin_buf)
785{
786 struct net_device *dev = d;
787 struct in_device *ip = dev->ip_ptr;
788 struct in_ifaddr *in;
789
790 if((ip == NULL) || ((in = ip->ifa_list) == NULL)){
791 printk(KERN_WARNING "dev_ip_addr - device not assigned an "
792 "IP address\n");
793 return;
794 }
795 memcpy(bin_buf, &in->ifa_address, sizeof(in->ifa_address));
796}
797
798struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra) 773struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra)
799{ 774{
800 if((skb != NULL) && (skb_tailroom(skb) < extra)){ 775 if((skb != NULL) && (skb_tailroom(skb) < extra)){