diff options
author | Jeff Dike <jdike@addtoit.com> | 2007-05-08 03:35:04 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-08 14:15:20 -0400 |
commit | 7d98230a73c21b4d0cee9c3aca38190d215e0e39 (patch) | |
tree | c2a5b5ff2e7927c3519ed49c3cb907ee29a5a90a /arch/um | |
parent | a436ed9c5106b41606cbb55ab3b28389fe8ae04f (diff) |
uml: network and pcap cleanup
Some network device cleanup.
When setup_etheraddr found a globally valid MAC being assigned to an
interface, it went ahead and used it rather than assigning a random MAC like
the other cases do. This isn't really an error like the others, but it seems
consistent to make it behave the same.
We were getting some duplicate kfree() in the error case in eth_configure
because platform_device_unregister frees buffers that the error cases
following tried to free again.
The pcap initialization routine wasn't doing the proper printk of its
information, causing a printk of the first part of that line to be
unterminated by a newline.
The pcap code had a bunch of style violations, which are now fixed.
pcap_setup wasn't returning false when it detected an unrecognized
option.
The printks in pcap_user all got UM_KERN_BLAH prepended to their
format strings.
pcap_remove now checks for a non-NULL pcap structure before it calls
pcap_close.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Acked-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/um')
-rw-r--r-- | arch/um/drivers/net_kern.c | 15 | ||||
-rw-r--r-- | arch/um/drivers/pcap_kern.c | 25 | ||||
-rw-r--r-- | arch/um/drivers/pcap_user.c | 23 |
3 files changed, 38 insertions, 25 deletions
diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c index baac4ad5e68e..72773dd54425 100644 --- a/arch/um/drivers/net_kern.c +++ b/arch/um/drivers/net_kern.c | |||
@@ -316,12 +316,14 @@ static void setup_etheraddr(char *str, unsigned char *addr, char *name) | |||
316 | } | 316 | } |
317 | if (!is_local_ether_addr(addr)) { | 317 | if (!is_local_ether_addr(addr)) { |
318 | printk(KERN_WARNING | 318 | printk(KERN_WARNING |
319 | "Warning: attempt to assign a globally valid ethernet address to a " | 319 | "Warning: attempt to assign a globally valid ethernet " |
320 | "device\n"); | 320 | "address to a device\n"); |
321 | printk(KERN_WARNING "You should better enable the 2nd rightmost bit " | 321 | printk(KERN_WARNING "You should better enable the 2nd " |
322 | "in the first byte of the MAC, i.e. " | 322 | "rightmost bit in the first byte of the MAC,\n"); |
323 | "%02x:%02x:%02x:%02x:%02x:%02x\n", | 323 | printk(KERN_WARNING "i.e. %02x:%02x:%02x:%02x:%02x:%02x\n", |
324 | addr[0] | 0x02, addr[1], addr[2], addr[3], addr[4], addr[5]); | 324 | addr[0] | 0x02, addr[1], addr[2], addr[3], addr[4], |
325 | addr[5]); | ||
326 | goto random; | ||
325 | } | 327 | } |
326 | return; | 328 | return; |
327 | 329 | ||
@@ -478,6 +480,7 @@ out_undo_user_init: | |||
478 | (*transport->user->remove)(&lp->user); | 480 | (*transport->user->remove)(&lp->user); |
479 | out_unregister: | 481 | out_unregister: |
480 | platform_device_unregister(&device->pdev); | 482 | platform_device_unregister(&device->pdev); |
483 | return; /* platform_device_unregister frees dev and device */ | ||
481 | out_free_netdev: | 484 | out_free_netdev: |
482 | free_netdev(dev); | 485 | free_netdev(dev); |
483 | out_free_device: | 486 | out_free_device: |
diff --git a/arch/um/drivers/pcap_kern.c b/arch/um/drivers/pcap_kern.c index 948849343ca4..8b27eae357ef 100644 --- a/arch/um/drivers/pcap_kern.c +++ b/arch/um/drivers/pcap_kern.c | |||
@@ -29,21 +29,25 @@ void pcap_init(struct net_device *dev, void *data) | |||
29 | ppri->promisc = init->promisc; | 29 | ppri->promisc = init->promisc; |
30 | ppri->optimize = init->optimize; | 30 | ppri->optimize = init->optimize; |
31 | ppri->filter = init->filter; | 31 | ppri->filter = init->filter; |
32 | |||
33 | printk("pcap backend, host interface %s\n", ppri->host_if); | ||
32 | } | 34 | } |
33 | 35 | ||
34 | static int pcap_read(int fd, struct sk_buff **skb, | 36 | static int pcap_read(int fd, struct sk_buff **skb, |
35 | struct uml_net_private *lp) | 37 | struct uml_net_private *lp) |
36 | { | 38 | { |
37 | *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER); | 39 | *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER); |
38 | if(*skb == NULL) return(-ENOMEM); | 40 | if(*skb == NULL) |
39 | return(pcap_user_read(fd, skb_mac_header(*skb), | 41 | return -ENOMEM; |
42 | |||
43 | return pcap_user_read(fd, skb_mac_header(*skb), | ||
40 | (*skb)->dev->mtu + ETH_HEADER_OTHER, | 44 | (*skb)->dev->mtu + ETH_HEADER_OTHER, |
41 | (struct pcap_data *) &lp->user)); | 45 | (struct pcap_data *) &lp->user); |
42 | } | 46 | } |
43 | 47 | ||
44 | static int pcap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp) | 48 | static int pcap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp) |
45 | { | 49 | { |
46 | return(-EPERM); | 50 | return -EPERM; |
47 | } | 51 | } |
48 | 52 | ||
49 | static const struct net_kern_info pcap_kern_info = { | 53 | static const struct net_kern_info pcap_kern_info = { |
@@ -65,12 +69,12 @@ int pcap_setup(char *str, char **mac_out, void *data) | |||
65 | .optimize = 0, | 69 | .optimize = 0, |
66 | .filter = NULL }); | 70 | .filter = NULL }); |
67 | 71 | ||
68 | remain = split_if_spec(str, &host_if, &init->filter, | 72 | remain = split_if_spec(str, &host_if, &init->filter, |
69 | &options[0], &options[1], NULL); | 73 | &options[0], &options[1], NULL); |
70 | if(remain != NULL){ | 74 | if(remain != NULL){ |
71 | printk(KERN_ERR "pcap_setup - Extra garbage on " | 75 | printk(KERN_ERR "pcap_setup - Extra garbage on " |
72 | "specification : '%s'\n", remain); | 76 | "specification : '%s'\n", remain); |
73 | return(0); | 77 | return 0; |
74 | } | 78 | } |
75 | 79 | ||
76 | if(host_if != NULL) | 80 | if(host_if != NULL) |
@@ -87,10 +91,13 @@ int pcap_setup(char *str, char **mac_out, void *data) | |||
87 | init->optimize = 1; | 91 | init->optimize = 1; |
88 | else if(!strcmp(options[i], "nooptimize")) | 92 | else if(!strcmp(options[i], "nooptimize")) |
89 | init->optimize = 0; | 93 | init->optimize = 0; |
90 | else printk("pcap_setup : bad option - '%s'\n", options[i]); | 94 | else { |
95 | printk("pcap_setup : bad option - '%s'\n", options[i]); | ||
96 | return 0; | ||
97 | } | ||
91 | } | 98 | } |
92 | 99 | ||
93 | return(1); | 100 | return 1; |
94 | } | 101 | } |
95 | 102 | ||
96 | static struct transport pcap_transport = { | 103 | static struct transport pcap_transport = { |
diff --git a/arch/um/drivers/pcap_user.c b/arch/um/drivers/pcap_user.c index dc0a903ef9a6..483aa15222a4 100644 --- a/arch/um/drivers/pcap_user.c +++ b/arch/um/drivers/pcap_user.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include "pcap_user.h" | 13 | #include "pcap_user.h" |
14 | #include "user.h" | 14 | #include "user.h" |
15 | #include "um_malloc.h" | 15 | #include "um_malloc.h" |
16 | #include "kern_constants.h" | ||
16 | 17 | ||
17 | #define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER) | 18 | #define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER) |
18 | 19 | ||
@@ -26,8 +27,8 @@ static int pcap_user_init(void *data, void *dev) | |||
26 | 27 | ||
27 | p = pcap_open_live(pri->host_if, MAX_PACKET, pri->promisc, 0, errors); | 28 | p = pcap_open_live(pri->host_if, MAX_PACKET, pri->promisc, 0, errors); |
28 | if(p == NULL){ | 29 | if(p == NULL){ |
29 | printk("pcap_user_init : pcap_open_live failed - '%s'\n", | 30 | printk(UM_KERN_ERR "pcap_user_init : pcap_open_live failed - " |
30 | errors); | 31 | "'%s'\n", errors); |
31 | return -EINVAL; | 32 | return -EINVAL; |
32 | } | 33 | } |
33 | 34 | ||
@@ -48,13 +49,13 @@ static int pcap_open(void *data) | |||
48 | if(pri->filter != NULL){ | 49 | if(pri->filter != NULL){ |
49 | err = dev_netmask(pri->dev, &netmask); | 50 | err = dev_netmask(pri->dev, &netmask); |
50 | if(err < 0){ | 51 | if(err < 0){ |
51 | printk("pcap_open : dev_netmask failed\n"); | 52 | printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n"); |
52 | return -EIO; | 53 | return -EIO; |
53 | } | 54 | } |
54 | 55 | ||
55 | pri->compiled = um_kmalloc(sizeof(struct bpf_program)); | 56 | pri->compiled = um_kmalloc(sizeof(struct bpf_program)); |
56 | if(pri->compiled == NULL){ | 57 | if(pri->compiled == NULL){ |
57 | printk("pcap_open : kmalloc failed\n"); | 58 | printk(UM_KERN_ERR "pcap_open : kmalloc failed\n"); |
58 | return -ENOMEM; | 59 | return -ENOMEM; |
59 | } | 60 | } |
60 | 61 | ||
@@ -62,15 +63,15 @@ static int pcap_open(void *data) | |||
62 | (struct bpf_program *) pri->compiled, | 63 | (struct bpf_program *) pri->compiled, |
63 | pri->filter, pri->optimize, netmask); | 64 | pri->filter, pri->optimize, netmask); |
64 | if(err < 0){ | 65 | if(err < 0){ |
65 | printk("pcap_open : pcap_compile failed - '%s'\n", | 66 | printk(UM_KERN_ERR "pcap_open : pcap_compile failed - " |
66 | pcap_geterr(pri->pcap)); | 67 | "'%s'\n", pcap_geterr(pri->pcap)); |
67 | return -EIO; | 68 | return -EIO; |
68 | } | 69 | } |
69 | 70 | ||
70 | err = pcap_setfilter(pri->pcap, pri->compiled); | 71 | err = pcap_setfilter(pri->pcap, pri->compiled); |
71 | if(err < 0){ | 72 | if(err < 0){ |
72 | printk("pcap_open : pcap_setfilter failed - '%s'\n", | 73 | printk(UM_KERN_ERR "pcap_open : pcap_setfilter " |
73 | pcap_geterr(pri->pcap)); | 74 | "failed - '%s'\n", pcap_geterr(pri->pcap)); |
74 | return -EIO; | 75 | return -EIO; |
75 | } | 76 | } |
76 | } | 77 | } |
@@ -85,7 +86,8 @@ static void pcap_remove(void *data) | |||
85 | if(pri->compiled != NULL) | 86 | if(pri->compiled != NULL) |
86 | pcap_freecode(pri->compiled); | 87 | pcap_freecode(pri->compiled); |
87 | 88 | ||
88 | pcap_close(pri->pcap); | 89 | if(pri->pcap != NULL) |
90 | pcap_close(pri->pcap); | ||
89 | } | 91 | } |
90 | 92 | ||
91 | struct pcap_handler_data { | 93 | struct pcap_handler_data { |
@@ -114,7 +116,8 @@ int pcap_user_read(int fd, void *buffer, int len, struct pcap_data *pri) | |||
114 | 116 | ||
115 | n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata); | 117 | n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata); |
116 | if(n < 0){ | 118 | if(n < 0){ |
117 | printk("pcap_dispatch failed - %s\n", pcap_geterr(pri->pcap)); | 119 | printk(UM_KERN_ERR "pcap_dispatch failed - %s\n", |
120 | pcap_geterr(pri->pcap)); | ||
118 | return -EIO; | 121 | return -EIO; |
119 | } | 122 | } |
120 | else if(n == 0) | 123 | else if(n == 0) |