aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/drivers/net_user.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/drivers/net_user.c')
-rw-r--r--arch/um/drivers/net_user.c126
1 files changed, 66 insertions, 60 deletions
diff --git a/arch/um/drivers/net_user.c b/arch/um/drivers/net_user.c
index da946e3e1bf2..90d7f2e8ead8 100644
--- a/arch/um/drivers/net_user.c
+++ b/arch/um/drivers/net_user.c
@@ -1,34 +1,32 @@
1/* 1/*
2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) 2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
5 5
6#include <stddef.h>
7#include <stdarg.h>
8#include <unistd.h>
9#include <stdio.h> 6#include <stdio.h>
7#include <unistd.h>
8#include <stdarg.h>
10#include <errno.h> 9#include <errno.h>
11#include <stdlib.h> 10#include <stddef.h>
12#include <string.h> 11#include <string.h>
13#include <sys/socket.h> 12#include <sys/socket.h>
14#include <sys/wait.h> 13#include <sys/wait.h>
15#include <sys/time.h>
16#include "user.h"
17#include "kern_util.h"
18#include "net_user.h" 14#include "net_user.h"
15#include "kern_constants.h"
19#include "os.h" 16#include "os.h"
20#include "um_malloc.h" 17#include "um_malloc.h"
21#include "kern_constants.h" 18#include "user.h"
22 19
23int tap_open_common(void *dev, char *gate_addr) 20int tap_open_common(void *dev, char *gate_addr)
24{ 21{
25 int tap_addr[4]; 22 int tap_addr[4];
26 23
27 if(gate_addr == NULL) 24 if (gate_addr == NULL)
28 return 0; 25 return 0;
29 if(sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0], 26 if (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
30 &tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4){ 27 &tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4) {
31 printk("Invalid tap IP address - '%s'\n", gate_addr); 28 printk(UM_KERN_ERR "Invalid tap IP address - '%s'\n",
29 gate_addr);
32 return -EINVAL; 30 return -EINVAL;
33 } 31 }
34 return 0; 32 return 0;
@@ -38,15 +36,15 @@ void tap_check_ips(char *gate_addr, unsigned char *eth_addr)
38{ 36{
39 int tap_addr[4]; 37 int tap_addr[4];
40 38
41 if((gate_addr != NULL) && 39 if ((gate_addr != NULL) &&
42 (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0], 40 (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
43 &tap_addr[1], &tap_addr[2], &tap_addr[3]) == 4) && 41 &tap_addr[1], &tap_addr[2], &tap_addr[3]) == 4) &&
44 (eth_addr[0] == tap_addr[0]) && 42 (eth_addr[0] == tap_addr[0]) &&
45 (eth_addr[1] == tap_addr[1]) && 43 (eth_addr[1] == tap_addr[1]) &&
46 (eth_addr[2] == tap_addr[2]) && 44 (eth_addr[2] == tap_addr[2]) &&
47 (eth_addr[3] == tap_addr[3])){ 45 (eth_addr[3] == tap_addr[3])) {
48 printk("The tap IP address and the UML eth IP address" 46 printk(UM_KERN_ERR "The tap IP address and the UML eth IP "
49 " must be different\n"); 47 "address must be different\n");
50 } 48 }
51} 49}
52 50
@@ -57,24 +55,28 @@ void read_output(int fd, char *output, int len)
57 char c; 55 char c;
58 char *str; 56 char *str;
59 57
60 if(output == NULL){ 58 if (output == NULL) {
61 output = &c; 59 output = &c;
62 len = sizeof(c); 60 len = sizeof(c);
63 } 61 }
64 62
65 *output = '\0'; 63 *output = '\0';
66 ret = os_read_file(fd, &remain, sizeof(remain)); 64 ret = read(fd, &remain, sizeof(remain));
67 65
68 if (ret != sizeof(remain)) { 66 if (ret != sizeof(remain)) {
67 if (ret < 0)
68 ret = -errno;
69 expected = sizeof(remain); 69 expected = sizeof(remain);
70 str = "length"; 70 str = "length";
71 goto err; 71 goto err;
72 } 72 }
73 73
74 while(remain != 0){ 74 while (remain != 0) {
75 expected = (remain < len) ? remain : len; 75 expected = (remain < len) ? remain : len;
76 ret = os_read_file(fd, output, expected); 76 ret = read(fd, output, expected);
77 if (ret != expected) { 77 if (ret != expected) {
78 if (ret < 0)
79 ret = -errno;
78 str = "data"; 80 str = "data";
79 goto err; 81 goto err;
80 } 82 }
@@ -85,20 +87,22 @@ void read_output(int fd, char *output, int len)
85 87
86err: 88err:
87 if (ret < 0) 89 if (ret < 0)
88 printk("read_output - read of %s failed, errno = %d\n", str, -ret); 90 printk(UM_KERN_ERR "read_output - read of %s failed, "
91 "errno = %d\n", str, -ret);
89 else 92 else
90 printk("read_output - read of %s failed, read only %d of %d bytes\n", str, ret, expected); 93 printk(UM_KERN_ERR "read_output - read of %s failed, read only "
94 "%d of %d bytes\n", str, ret, expected);
91} 95}
92 96
93int net_read(int fd, void *buf, int len) 97int net_read(int fd, void *buf, int len)
94{ 98{
95 int n; 99 int n;
96 100
97 n = os_read_file(fd, buf, len); 101 n = read(fd, buf, len);
98 102
99 if(n == -EAGAIN) 103 if ((n < 0) && (errno == EAGAIN))
100 return 0; 104 return 0;
101 else if(n == 0) 105 else if (n == 0)
102 return -ENOTCONN; 106 return -ENOTCONN;
103 return n; 107 return n;
104} 108}
@@ -108,12 +112,12 @@ int net_recvfrom(int fd, void *buf, int len)
108 int n; 112 int n;
109 113
110 CATCH_EINTR(n = recvfrom(fd, buf, len, 0, NULL, NULL)); 114 CATCH_EINTR(n = recvfrom(fd, buf, len, 0, NULL, NULL));
111 if(n < 0){ 115 if (n < 0) {
112 if(errno == EAGAIN) 116 if (errno == EAGAIN)
113 return 0; 117 return 0;
114 return -errno; 118 return -errno;
115 } 119 }
116 else if(n == 0) 120 else if (n == 0)
117 return -ENOTCONN; 121 return -ENOTCONN;
118 return n; 122 return n;
119} 123}
@@ -122,11 +126,11 @@ int net_write(int fd, void *buf, int len)
122{ 126{
123 int n; 127 int n;
124 128
125 n = os_write_file(fd, buf, len); 129 n = write(fd, buf, len);
126 130
127 if(n == -EAGAIN) 131 if ((n < 0) && (errno == EAGAIN))
128 return 0; 132 return 0;
129 else if(n == 0) 133 else if (n == 0)
130 return -ENOTCONN; 134 return -ENOTCONN;
131 return n; 135 return n;
132} 136}
@@ -136,12 +140,12 @@ int net_send(int fd, void *buf, int len)
136 int n; 140 int n;
137 141
138 CATCH_EINTR(n = send(fd, buf, len, 0)); 142 CATCH_EINTR(n = send(fd, buf, len, 0));
139 if(n < 0){ 143 if (n < 0) {
140 if(errno == EAGAIN) 144 if (errno == EAGAIN)
141 return 0; 145 return 0;
142 return -errno; 146 return -errno;
143 } 147 }
144 else if(n == 0) 148 else if (n == 0)
145 return -ENOTCONN; 149 return -ENOTCONN;
146 return n; 150 return n;
147} 151}
@@ -152,12 +156,12 @@ int net_sendto(int fd, void *buf, int len, void *to, int sock_len)
152 156
153 CATCH_EINTR(n = sendto(fd, buf, len, 0, (struct sockaddr *) to, 157 CATCH_EINTR(n = sendto(fd, buf, len, 0, (struct sockaddr *) to,
154 sock_len)); 158 sock_len));
155 if(n < 0){ 159 if (n < 0) {
156 if(errno == EAGAIN) 160 if (errno == EAGAIN)
157 return 0; 161 return 0;
158 return -errno; 162 return -errno;
159 } 163 }
160 else if(n == 0) 164 else if (n == 0)
161 return -ENOTCONN; 165 return -ENOTCONN;
162 return n; 166 return n;
163} 167}
@@ -171,7 +175,7 @@ static void change_pre_exec(void *arg)
171{ 175{
172 struct change_pre_exec_data *data = arg; 176 struct change_pre_exec_data *data = arg;
173 177
174 os_close_file(data->close_me); 178 close(data->close_me);
175 dup2(data->stdout, 1); 179 dup2(data->stdout, 1);
176} 180}
177 181
@@ -181,8 +185,9 @@ static int change_tramp(char **argv, char *output, int output_len)
181 struct change_pre_exec_data pe_data; 185 struct change_pre_exec_data pe_data;
182 186
183 err = os_pipe(fds, 1, 0); 187 err = os_pipe(fds, 1, 0);
184 if(err < 0){ 188 if (err < 0) {
185 printk("change_tramp - pipe failed, err = %d\n", -err); 189 printk(UM_KERN_ERR "change_tramp - pipe failed, err = %d\n",
190 -err);
186 return err; 191 return err;
187 } 192 }
188 pe_data.close_me = fds[0]; 193 pe_data.close_me = fds[0];
@@ -192,8 +197,8 @@ static int change_tramp(char **argv, char *output, int output_len)
192 if (pid > 0) /* Avoid hang as we won't get data in failure case. */ 197 if (pid > 0) /* Avoid hang as we won't get data in failure case. */
193 read_output(fds[0], output, output_len); 198 read_output(fds[0], output, output_len);
194 199
195 os_close_file(fds[0]); 200 close(fds[0]);
196 os_close_file(fds[1]); 201 close(fds[1]);
197 202
198 if (pid > 0) 203 if (pid > 0)
199 CATCH_EINTR(err = waitpid(pid, NULL, 0)); 204 CATCH_EINTR(err = waitpid(pid, NULL, 0));
@@ -206,25 +211,26 @@ static void change(char *dev, char *what, unsigned char *addr,
206 char addr_buf[sizeof("255.255.255.255\0")]; 211 char addr_buf[sizeof("255.255.255.255\0")];
207 char netmask_buf[sizeof("255.255.255.255\0")]; 212 char netmask_buf[sizeof("255.255.255.255\0")];
208 char version[sizeof("nnnnn\0")]; 213 char version[sizeof("nnnnn\0")];
209 char *argv[] = { "uml_net", version, what, dev, addr_buf, 214 char *argv[] = { "uml_net", version, what, dev, addr_buf,
210 netmask_buf, NULL }; 215 netmask_buf, NULL };
211 char *output; 216 char *output;
212 int output_len, pid; 217 int output_len, pid;
213 218
214 sprintf(version, "%d", UML_NET_VERSION); 219 sprintf(version, "%d", UML_NET_VERSION);
215 sprintf(addr_buf, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]); 220 sprintf(addr_buf, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
216 sprintf(netmask_buf, "%d.%d.%d.%d", netmask[0], netmask[1], 221 sprintf(netmask_buf, "%d.%d.%d.%d", netmask[0], netmask[1],
217 netmask[2], netmask[3]); 222 netmask[2], netmask[3]);
218 223
219 output_len = UM_KERN_PAGE_SIZE; 224 output_len = UM_KERN_PAGE_SIZE;
220 output = kmalloc(output_len, UM_GFP_KERNEL); 225 output = kmalloc(output_len, UM_GFP_KERNEL);
221 if(output == NULL) 226 if (output == NULL)
222 printk("change : failed to allocate output buffer\n"); 227 printk(UM_KERN_ERR "change : failed to allocate output "
228 "buffer\n");
223 229
224 pid = change_tramp(argv, output, output_len); 230 pid = change_tramp(argv, output, output_len);
225 if(pid < 0) return; 231 if (pid < 0) return;
226 232
227 if(output != NULL){ 233 if (output != NULL) {
228 printk("%s", output); 234 printk("%s", output);
229 kfree(output); 235 kfree(output);
230 } 236 }
@@ -246,13 +252,13 @@ char *split_if_spec(char *str, ...)
246 va_list ap; 252 va_list ap;
247 253
248 va_start(ap, str); 254 va_start(ap, str);
249 while((arg = va_arg(ap, char **)) != NULL){ 255 while ((arg = va_arg(ap, char **)) != NULL) {
250 if(*str == '\0') 256 if (*str == '\0')
251 return NULL; 257 return NULL;
252 end = strchr(str, ','); 258 end = strchr(str, ',');
253 if(end != str) 259 if (end != str)
254 *arg = str; 260 *arg = str;
255 if(end == NULL) 261 if (end == NULL)
256 return NULL; 262 return NULL;
257 *end++ = '\0'; 263 *end++ = '\0';
258 str = end; 264 str = end;