aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--arch/um/drivers/net_kern.c105
-rw-r--r--arch/um/include/net_kern.h14
-rw-r--r--arch/um/include/net_user.h1
3 files changed, 40 insertions, 80 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)){
diff --git a/arch/um/include/net_kern.h b/arch/um/include/net_kern.h
index 769fba43ee03..280459fb0b26 100644
--- a/arch/um/include/net_kern.h
+++ b/arch/um/include/net_kern.h
@@ -18,7 +18,6 @@ struct uml_net {
18 struct platform_device pdev; 18 struct platform_device pdev;
19 int index; 19 int index;
20 unsigned char mac[ETH_ALEN]; 20 unsigned char mac[ETH_ALEN];
21 int have_mac;
22}; 21};
23 22
24struct uml_net_private { 23struct uml_net_private {
@@ -29,7 +28,6 @@ struct uml_net_private {
29 struct net_device_stats stats; 28 struct net_device_stats stats;
30 int fd; 29 int fd;
31 unsigned char mac[ETH_ALEN]; 30 unsigned char mac[ETH_ALEN];
32 int have_mac;
33 unsigned short (*protocol)(struct sk_buff *); 31 unsigned short (*protocol)(struct sk_buff *);
34 int (*open)(void *); 32 int (*open)(void *);
35 void (*close)(int, void *); 33 void (*close)(int, void *);
@@ -62,7 +60,6 @@ struct transport {
62 60
63extern struct net_device *ether_init(int); 61extern struct net_device *ether_init(int);
64extern unsigned short ether_protocol(struct sk_buff *); 62extern unsigned short ether_protocol(struct sk_buff *);
65extern int setup_etheraddr(char *str, unsigned char *addr);
66extern struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra); 63extern struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra);
67extern int tap_setup_common(char *str, char *type, char **dev_name, 64extern int tap_setup_common(char *str, char *type, char **dev_name,
68 char **mac_out, char **gate_addr); 65 char **mac_out, char **gate_addr);
@@ -70,14 +67,3 @@ extern void register_transport(struct transport *new);
70extern unsigned short eth_protocol(struct sk_buff *skb); 67extern unsigned short eth_protocol(struct sk_buff *skb);
71 68
72#endif 69#endif
73
74/*
75 * Overrides for Emacs so that we follow Linus's tabbing style.
76 * Emacs will notice this stuff at the end of the file and automatically
77 * adjust the settings for this buffer only. This must remain at the end
78 * of the file.
79 * ---------------------------------------------------------------------------
80 * Local variables:
81 * c-file-style: "linux"
82 * End:
83 */
diff --git a/arch/um/include/net_user.h b/arch/um/include/net_user.h
index cd19defbfefc..99b3cea2dcdc 100644
--- a/arch/um/include/net_user.h
+++ b/arch/um/include/net_user.h
@@ -25,7 +25,6 @@ struct net_user_info {
25}; 25};
26 26
27extern void ether_user_init(void *data, void *dev); 27extern void ether_user_init(void *data, void *dev);
28extern void dev_ip_addr(void *d, unsigned char *bin_buf);
29extern void iter_addresses(void *d, void (*cb)(unsigned char *, 28extern void iter_addresses(void *d, void (*cb)(unsigned char *,
30 unsigned char *, void *), 29 unsigned char *, void *),
31 void *arg); 30 void *arg);