diff options
author | Jeff Dike <jdike@addtoit.com> | 2007-10-16 04:27:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-16 12:43:08 -0400 |
commit | cd1ae0e49bdd814cfaa2e5ab28cff21a30e20085 (patch) | |
tree | 1b993b9de4cb9a8578022a4014063c3e87ec996e /arch/um/drivers/pcap_user.c | |
parent | 1a80521990a0e30e61a92994a009adc52161b070 (diff) |
uml: network formatting
Style and other non-functional changes in the UML networking code, including
include tidying
style violations
copyright updates
printks getting severities
userspace code calling libc directly rather than using the os_*
wrappers
There's also a exit path cleanup in the pcap driver.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/um/drivers/pcap_user.c')
-rw-r--r-- | arch/um/drivers/pcap_user.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/arch/um/drivers/pcap_user.c b/arch/um/drivers/pcap_user.c index 1316456e2a28..cf996b82af56 100644 --- a/arch/um/drivers/pcap_user.c +++ b/arch/um/drivers/pcap_user.c | |||
@@ -1,19 +1,17 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2002 Jeff Dike <jdike@karaya.com> | 2 | * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
3 | * Licensed under the GPL. | 3 | * Licensed under the GPL. |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <unistd.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <string.h> | ||
9 | #include <errno.h> | 6 | #include <errno.h> |
10 | #include <pcap.h> | 7 | #include <pcap.h> |
8 | #include <string.h> | ||
11 | #include <asm/types.h> | 9 | #include <asm/types.h> |
12 | #include "net_user.h" | 10 | #include "net_user.h" |
13 | #include "pcap_user.h" | 11 | #include "pcap_user.h" |
14 | #include "user.h" | ||
15 | #include "um_malloc.h" | ||
16 | #include "kern_constants.h" | 12 | #include "kern_constants.h" |
13 | #include "um_malloc.h" | ||
14 | #include "user.h" | ||
17 | 15 | ||
18 | #define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER) | 16 | #define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER) |
19 | 17 | ||
@@ -26,7 +24,7 @@ static int pcap_user_init(void *data, void *dev) | |||
26 | char errors[PCAP_ERRBUF_SIZE]; | 24 | char errors[PCAP_ERRBUF_SIZE]; |
27 | 25 | ||
28 | p = pcap_open_live(pri->host_if, MAX_PACKET, pri->promisc, 0, errors); | 26 | p = pcap_open_live(pri->host_if, MAX_PACKET, pri->promisc, 0, errors); |
29 | if(p == NULL){ | 27 | if (p == NULL) { |
30 | printk(UM_KERN_ERR "pcap_user_init : pcap_open_live failed - " | 28 | printk(UM_KERN_ERR "pcap_user_init : pcap_open_live failed - " |
31 | "'%s'\n", errors); | 29 | "'%s'\n", errors); |
32 | return -EINVAL; | 30 | return -EINVAL; |
@@ -43,50 +41,55 @@ static int pcap_open(void *data) | |||
43 | __u32 netmask; | 41 | __u32 netmask; |
44 | int err; | 42 | int err; |
45 | 43 | ||
46 | if(pri->pcap == NULL) | 44 | if (pri->pcap == NULL) |
47 | return -ENODEV; | 45 | return -ENODEV; |
48 | 46 | ||
49 | if(pri->filter != NULL){ | 47 | if (pri->filter != NULL) { |
50 | err = dev_netmask(pri->dev, &netmask); | 48 | err = dev_netmask(pri->dev, &netmask); |
51 | if(err < 0){ | 49 | if (err < 0) { |
52 | printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n"); | 50 | printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n"); |
53 | return -EIO; | 51 | return -EIO; |
54 | } | 52 | } |
55 | 53 | ||
56 | pri->compiled = kmalloc(sizeof(struct bpf_program), UM_GFP_KERNEL); | 54 | pri->compiled = kmalloc(sizeof(struct bpf_program), |
57 | if(pri->compiled == NULL){ | 55 | UM_GFP_KERNEL); |
56 | if (pri->compiled == NULL) { | ||
58 | printk(UM_KERN_ERR "pcap_open : kmalloc failed\n"); | 57 | printk(UM_KERN_ERR "pcap_open : kmalloc failed\n"); |
59 | return -ENOMEM; | 58 | return -ENOMEM; |
60 | } | 59 | } |
61 | 60 | ||
62 | err = pcap_compile(pri->pcap, | 61 | err = pcap_compile(pri->pcap, |
63 | (struct bpf_program *) pri->compiled, | 62 | (struct bpf_program *) pri->compiled, |
64 | pri->filter, pri->optimize, netmask); | 63 | pri->filter, pri->optimize, netmask); |
65 | if(err < 0){ | 64 | if (err < 0) { |
66 | printk(UM_KERN_ERR "pcap_open : pcap_compile failed - " | 65 | printk(UM_KERN_ERR "pcap_open : pcap_compile failed - " |
67 | "'%s'\n", pcap_geterr(pri->pcap)); | 66 | "'%s'\n", pcap_geterr(pri->pcap)); |
68 | return -EIO; | 67 | goto out; |
69 | } | 68 | } |
70 | 69 | ||
71 | err = pcap_setfilter(pri->pcap, pri->compiled); | 70 | err = pcap_setfilter(pri->pcap, pri->compiled); |
72 | if(err < 0){ | 71 | if (err < 0) { |
73 | printk(UM_KERN_ERR "pcap_open : pcap_setfilter " | 72 | printk(UM_KERN_ERR "pcap_open : pcap_setfilter " |
74 | "failed - '%s'\n", pcap_geterr(pri->pcap)); | 73 | "failed - '%s'\n", pcap_geterr(pri->pcap)); |
75 | return -EIO; | 74 | goto out; |
76 | } | 75 | } |
77 | } | 76 | } |
78 | 77 | ||
79 | return PCAP_FD(pri->pcap); | 78 | return PCAP_FD(pri->pcap); |
79 | |||
80 | out: | ||
81 | kfree(pri->compiled); | ||
82 | return -EIO; | ||
80 | } | 83 | } |
81 | 84 | ||
82 | static void pcap_remove(void *data) | 85 | static void pcap_remove(void *data) |
83 | { | 86 | { |
84 | struct pcap_data *pri = data; | 87 | struct pcap_data *pri = data; |
85 | 88 | ||
86 | if(pri->compiled != NULL) | 89 | if (pri->compiled != NULL) |
87 | pcap_freecode(pri->compiled); | 90 | pcap_freecode(pri->compiled); |
88 | 91 | ||
89 | if(pri->pcap != NULL) | 92 | if (pri->pcap != NULL) |
90 | pcap_close(pri->pcap); | 93 | pcap_close(pri->pcap); |
91 | } | 94 | } |
92 | 95 | ||
@@ -95,7 +98,7 @@ struct pcap_handler_data { | |||
95 | int len; | 98 | int len; |
96 | }; | 99 | }; |
97 | 100 | ||
98 | static void handler(u_char *data, const struct pcap_pkthdr *header, | 101 | static void handler(u_char *data, const struct pcap_pkthdr *header, |
99 | const u_char *packet) | 102 | const u_char *packet) |
100 | { | 103 | { |
101 | int len; | 104 | int len; |
@@ -115,12 +118,12 @@ int pcap_user_read(int fd, void *buffer, int len, struct pcap_data *pri) | |||
115 | int n; | 118 | int n; |
116 | 119 | ||
117 | n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata); | 120 | n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata); |
118 | if(n < 0){ | 121 | if (n < 0) { |
119 | printk(UM_KERN_ERR "pcap_dispatch failed - %s\n", | 122 | printk(UM_KERN_ERR "pcap_dispatch failed - %s\n", |
120 | pcap_geterr(pri->pcap)); | 123 | pcap_geterr(pri->pcap)); |
121 | return -EIO; | 124 | return -EIO; |
122 | } | 125 | } |
123 | else if(n == 0) | 126 | else if (n == 0) |
124 | return 0; | 127 | return 0; |
125 | return hdata.len; | 128 | return hdata.len; |
126 | } | 129 | } |