diff options
Diffstat (limited to 'arch/um/os-Linux/drivers/ethertap_user.c')
-rw-r--r-- | arch/um/os-Linux/drivers/ethertap_user.c | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/arch/um/os-Linux/drivers/ethertap_user.c b/arch/um/os-Linux/drivers/ethertap_user.c index d74eedb7e682..29404b955f18 100644 --- a/arch/um/os-Linux/drivers/ethertap_user.c +++ b/arch/um/os-Linux/drivers/ethertap_user.c | |||
@@ -1,4 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) | ||
2 | * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and | 3 | * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and |
3 | * James Leu (jleu@mindspring.net). | 4 | * James Leu (jleu@mindspring.net). |
4 | * Copyright (C) 2001 by various other people who didn't put their name here. | 5 | * Copyright (C) 2001 by various other people who didn't put their name here. |
@@ -7,20 +8,16 @@ | |||
7 | 8 | ||
8 | #include <stdio.h> | 9 | #include <stdio.h> |
9 | #include <unistd.h> | 10 | #include <unistd.h> |
10 | #include <stddef.h> | 11 | #include <errno.h> |
11 | #include <stdlib.h> | 12 | #include <string.h> |
12 | #include <sys/errno.h> | ||
13 | #include <sys/socket.h> | 13 | #include <sys/socket.h> |
14 | #include <sys/wait.h> | 14 | #include <sys/wait.h> |
15 | #include <sys/un.h> | ||
16 | #include <net/if.h> | ||
17 | #include "user.h" | ||
18 | #include "kern_util.h" | ||
19 | #include "net_user.h" | ||
20 | #include "etap.h" | 15 | #include "etap.h" |
16 | #include "kern_constants.h" | ||
21 | #include "os.h" | 17 | #include "os.h" |
18 | #include "net_user.h" | ||
22 | #include "um_malloc.h" | 19 | #include "um_malloc.h" |
23 | #include "kern_constants.h" | 20 | #include "user.h" |
24 | 21 | ||
25 | #define MAX_PACKET ETH_MAX_PACKET | 22 | #define MAX_PACKET ETH_MAX_PACKET |
26 | 23 | ||
@@ -49,16 +46,18 @@ static void etap_change(int op, unsigned char *addr, unsigned char *netmask, | |||
49 | memcpy(change.addr, addr, sizeof(change.addr)); | 46 | memcpy(change.addr, addr, sizeof(change.addr)); |
50 | memcpy(change.netmask, netmask, sizeof(change.netmask)); | 47 | memcpy(change.netmask, netmask, sizeof(change.netmask)); |
51 | CATCH_EINTR(n = write(fd, &change, sizeof(change))); | 48 | CATCH_EINTR(n = write(fd, &change, sizeof(change))); |
52 | if(n != sizeof(change)){ | 49 | if (n != sizeof(change)) { |
53 | printk("etap_change - request failed, err = %d\n", errno); | 50 | printk(UM_KERN_ERR "etap_change - request failed, err = %d\n", |
51 | errno); | ||
54 | return; | 52 | return; |
55 | } | 53 | } |
56 | 54 | ||
57 | output = kmalloc(UM_KERN_PAGE_SIZE, UM_GFP_KERNEL); | 55 | output = kmalloc(UM_KERN_PAGE_SIZE, UM_GFP_KERNEL); |
58 | if(output == NULL) | 56 | if (output == NULL) |
59 | printk("etap_change : Failed to allocate output buffer\n"); | 57 | printk(UM_KERN_ERR "etap_change : Failed to allocate output " |
58 | "buffer\n"); | ||
60 | read_output(fd, output, UM_KERN_PAGE_SIZE); | 59 | read_output(fd, output, UM_KERN_PAGE_SIZE); |
61 | if(output != NULL){ | 60 | if (output != NULL) { |
62 | printk("%s", output); | 61 | printk("%s", output); |
63 | kfree(output); | 62 | kfree(output); |
64 | } | 63 | } |
@@ -107,7 +106,7 @@ static int etap_tramp(char *dev, char *gate, int control_me, | |||
107 | 106 | ||
108 | sprintf(data_fd_buf, "%d", data_remote); | 107 | sprintf(data_fd_buf, "%d", data_remote); |
109 | sprintf(version_buf, "%d", UML_NET_VERSION); | 108 | sprintf(version_buf, "%d", UML_NET_VERSION); |
110 | if(gate != NULL){ | 109 | if (gate != NULL) { |
111 | strcpy(gate_buf, gate); | 110 | strcpy(gate_buf, gate); |
112 | args = setup_args; | 111 | args = setup_args; |
113 | } | 112 | } |
@@ -119,24 +118,26 @@ static int etap_tramp(char *dev, char *gate, int control_me, | |||
119 | pe_data.data_me = data_me; | 118 | pe_data.data_me = data_me; |
120 | pid = run_helper(etap_pre_exec, &pe_data, args); | 119 | pid = run_helper(etap_pre_exec, &pe_data, args); |
121 | 120 | ||
122 | if(pid < 0) | 121 | if (pid < 0) |
123 | err = pid; | 122 | err = pid; |
124 | close(data_remote); | 123 | close(data_remote); |
125 | close(control_remote); | 124 | close(control_remote); |
126 | CATCH_EINTR(n = read(control_me, &c, sizeof(c))); | 125 | CATCH_EINTR(n = read(control_me, &c, sizeof(c))); |
127 | if(n != sizeof(c)){ | 126 | if (n != sizeof(c)) { |
128 | err = -errno; | 127 | err = -errno; |
129 | printk("etap_tramp : read of status failed, err = %d\n", -err); | 128 | printk(UM_KERN_ERR "etap_tramp : read of status failed, " |
129 | "err = %d\n", -err); | ||
130 | return err; | 130 | return err; |
131 | } | 131 | } |
132 | if(c != 1){ | 132 | if (c != 1) { |
133 | printk("etap_tramp : uml_net failed\n"); | 133 | printk(UM_KERN_ERR "etap_tramp : uml_net failed\n"); |
134 | err = -EINVAL; | 134 | err = -EINVAL; |
135 | CATCH_EINTR(n = waitpid(pid, &status, 0)); | 135 | CATCH_EINTR(n = waitpid(pid, &status, 0)); |
136 | if(n < 0) | 136 | if (n < 0) |
137 | err = -errno; | 137 | err = -errno; |
138 | else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 1)) | 138 | else if (!WIFEXITED(status) || (WEXITSTATUS(status) != 1)) |
139 | printk("uml_net didn't exit with status 1\n"); | 139 | printk(UM_KERN_ERR "uml_net didn't exit with " |
140 | "status 1\n"); | ||
140 | } | 141 | } |
141 | return err; | 142 | return err; |
142 | } | 143 | } |
@@ -148,22 +149,22 @@ static int etap_open(void *data) | |||
148 | int data_fds[2], control_fds[2], err, output_len; | 149 | int data_fds[2], control_fds[2], err, output_len; |
149 | 150 | ||
150 | err = tap_open_common(pri->dev, pri->gate_addr); | 151 | err = tap_open_common(pri->dev, pri->gate_addr); |
151 | if(err) | 152 | if (err) |
152 | return err; | 153 | return err; |
153 | 154 | ||
154 | err = socketpair(AF_UNIX, SOCK_DGRAM, 0, data_fds); | 155 | err = socketpair(AF_UNIX, SOCK_DGRAM, 0, data_fds); |
155 | if(err){ | 156 | if (err) { |
156 | err = -errno; | 157 | err = -errno; |
157 | printk("etap_open - data socketpair failed - err = %d\n", | 158 | printk(UM_KERN_ERR "etap_open - data socketpair failed - " |
158 | errno); | 159 | "err = %d\n", errno); |
159 | return err; | 160 | return err; |
160 | } | 161 | } |
161 | 162 | ||
162 | err = socketpair(AF_UNIX, SOCK_STREAM, 0, control_fds); | 163 | err = socketpair(AF_UNIX, SOCK_STREAM, 0, control_fds); |
163 | if(err){ | 164 | if (err) { |
164 | err = -errno; | 165 | err = -errno; |
165 | printk("etap_open - control socketpair failed - err = %d\n", | 166 | printk(UM_KERN_ERR "etap_open - control socketpair failed - " |
166 | errno); | 167 | "err = %d\n", errno); |
167 | goto out_close_data; | 168 | goto out_close_data; |
168 | } | 169 | } |
169 | 170 | ||
@@ -173,15 +174,16 @@ static int etap_open(void *data) | |||
173 | output = kmalloc(output_len, UM_GFP_KERNEL); | 174 | output = kmalloc(output_len, UM_GFP_KERNEL); |
174 | read_output(control_fds[0], output, output_len); | 175 | read_output(control_fds[0], output, output_len); |
175 | 176 | ||
176 | if(output == NULL) | 177 | if (output == NULL) |
177 | printk("etap_open : failed to allocate output buffer\n"); | 178 | printk(UM_KERN_ERR "etap_open : failed to allocate output " |
179 | "buffer\n"); | ||
178 | else { | 180 | else { |
179 | printk("%s", output); | 181 | printk("%s", output); |
180 | kfree(output); | 182 | kfree(output); |
181 | } | 183 | } |
182 | 184 | ||
183 | if(err < 0){ | 185 | if (err < 0) { |
184 | printk("etap_tramp failed - err = %d\n", -err); | 186 | printk(UM_KERN_ERR "etap_tramp failed - err = %d\n", -err); |
185 | goto out_close_control; | 187 | goto out_close_control; |
186 | } | 188 | } |
187 | 189 | ||
@@ -206,14 +208,14 @@ static void etap_close(int fd, void *data) | |||
206 | iter_addresses(pri->dev, etap_close_addr, &pri->control_fd); | 208 | iter_addresses(pri->dev, etap_close_addr, &pri->control_fd); |
207 | close(fd); | 209 | close(fd); |
208 | 210 | ||
209 | if(shutdown(pri->data_fd, SHUT_RDWR) < 0) | 211 | if (shutdown(pri->data_fd, SHUT_RDWR) < 0) |
210 | printk("etap_close - shutdown data socket failed, errno = %d\n", | 212 | printk(UM_KERN_ERR "etap_close - shutdown data socket failed, " |
211 | errno); | ||
212 | |||
213 | if(shutdown(pri->control_fd, SHUT_RDWR) < 0) | ||
214 | printk("etap_close - shutdown control socket failed, " | ||
215 | "errno = %d\n", errno); | 213 | "errno = %d\n", errno); |
216 | 214 | ||
215 | if (shutdown(pri->control_fd, SHUT_RDWR) < 0) | ||
216 | printk(UM_KERN_ERR "etap_close - shutdown control socket " | ||
217 | "failed, errno = %d\n", errno); | ||
218 | |||
217 | close(pri->data_fd); | 219 | close(pri->data_fd); |
218 | pri->data_fd = -1; | 220 | pri->data_fd = -1; |
219 | close(pri->control_fd); | 221 | close(pri->control_fd); |
@@ -231,7 +233,7 @@ static void etap_add_addr(unsigned char *addr, unsigned char *netmask, | |||
231 | struct ethertap_data *pri = data; | 233 | struct ethertap_data *pri = data; |
232 | 234 | ||
233 | tap_check_ips(pri->gate_addr, addr); | 235 | tap_check_ips(pri->gate_addr, addr); |
234 | if(pri->control_fd == -1) | 236 | if (pri->control_fd == -1) |
235 | return; | 237 | return; |
236 | etap_open_addr(addr, netmask, &pri->control_fd); | 238 | etap_open_addr(addr, netmask, &pri->control_fd); |
237 | } | 239 | } |
@@ -241,7 +243,7 @@ static void etap_del_addr(unsigned char *addr, unsigned char *netmask, | |||
241 | { | 243 | { |
242 | struct ethertap_data *pri = data; | 244 | struct ethertap_data *pri = data; |
243 | 245 | ||
244 | if(pri->control_fd == -1) | 246 | if (pri->control_fd == -1) |
245 | return; | 247 | return; |
246 | 248 | ||
247 | etap_close_addr(addr, netmask, &pri->control_fd); | 249 | etap_close_addr(addr, netmask, &pri->control_fd); |