aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux/drivers/ethertap_user.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/os-Linux/drivers/ethertap_user.c')
-rw-r--r--arch/um/os-Linux/drivers/ethertap_user.c66
1 files changed, 32 insertions, 34 deletions
diff --git a/arch/um/os-Linux/drivers/ethertap_user.c b/arch/um/os-Linux/drivers/ethertap_user.c
index 863981ba1468..acba30161287 100644
--- a/arch/um/os-Linux/drivers/ethertap_user.c
+++ b/arch/um/os-Linux/drivers/ethertap_user.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and 2 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
3 * James Leu (jleu@mindspring.net). 3 * James Leu (jleu@mindspring.net).
4 * Copyright (C) 2001 by various other people who didn't put their name here. 4 * Copyright (C) 2001 by various other people who didn't put their name here.
5 * Licensed under the GPL. 5 * Licensed under the GPL.
@@ -16,19 +16,20 @@
16#include <net/if.h> 16#include <net/if.h>
17#include "user.h" 17#include "user.h"
18#include "kern_util.h" 18#include "kern_util.h"
19#include "user_util.h"
20#include "net_user.h" 19#include "net_user.h"
21#include "etap.h" 20#include "etap.h"
22#include "os.h" 21#include "os.h"
23#include "um_malloc.h" 22#include "um_malloc.h"
23#include "kern_constants.h"
24 24
25#define MAX_PACKET ETH_MAX_PACKET 25#define MAX_PACKET ETH_MAX_PACKET
26 26
27void etap_user_init(void *data, void *dev) 27static int etap_user_init(void *data, void *dev)
28{ 28{
29 struct ethertap_data *pri = data; 29 struct ethertap_data *pri = data;
30 30
31 pri->dev = dev; 31 pri->dev = dev;
32 return 0;
32} 33}
33 34
34struct addr_change { 35struct addr_change {
@@ -47,13 +48,16 @@ static void etap_change(int op, unsigned char *addr, unsigned char *netmask,
47 change.what = op; 48 change.what = op;
48 memcpy(change.addr, addr, sizeof(change.addr)); 49 memcpy(change.addr, addr, sizeof(change.addr));
49 memcpy(change.netmask, netmask, sizeof(change.netmask)); 50 memcpy(change.netmask, netmask, sizeof(change.netmask));
50 n = os_write_file(fd, &change, sizeof(change)); 51 CATCH_EINTR(n = write(fd, &change, sizeof(change)));
51 if(n != sizeof(change)) 52 if(n != sizeof(change)){
52 printk("etap_change - request failed, err = %d\n", -n); 53 printk("etap_change - request failed, err = %d\n", errno);
53 output = um_kmalloc(page_size()); 54 return;
55 }
56
57 output = um_kmalloc(UM_KERN_PAGE_SIZE);
54 if(output == NULL) 58 if(output == NULL)
55 printk("etap_change : Failed to allocate output buffer\n"); 59 printk("etap_change : Failed to allocate output buffer\n");
56 read_output(fd, output, page_size()); 60 read_output(fd, output, UM_KERN_PAGE_SIZE);
57 if(output != NULL){ 61 if(output != NULL){
58 printk("%s", output); 62 printk("%s", output);
59 kfree(output); 63 kfree(output);
@@ -115,13 +119,15 @@ static int etap_tramp(char *dev, char *gate, int control_me,
115 pe_data.data_me = data_me; 119 pe_data.data_me = data_me;
116 pid = run_helper(etap_pre_exec, &pe_data, args, NULL); 120 pid = run_helper(etap_pre_exec, &pe_data, args, NULL);
117 121
118 if(pid < 0) err = pid; 122 if(pid < 0)
123 err = pid;
119 os_close_file(data_remote); 124 os_close_file(data_remote);
120 os_close_file(control_remote); 125 os_close_file(control_remote);
121 n = os_read_file(control_me, &c, sizeof(c)); 126 CATCH_EINTR(n = read(control_me, &c, sizeof(c)));
122 if(n != sizeof(c)){ 127 if(n != sizeof(c)){
123 printk("etap_tramp : read of status failed, err = %d\n", -n); 128 err = -errno;
124 return(-EINVAL); 129 printk("etap_tramp : read of status failed, err = %d\n", -err);
130 return err;
125 } 131 }
126 if(c != 1){ 132 if(c != 1){
127 printk("etap_tramp : uml_net failed\n"); 133 printk("etap_tramp : uml_net failed\n");
@@ -132,7 +138,7 @@ static int etap_tramp(char *dev, char *gate, int control_me,
132 else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 1)) 138 else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 1))
133 printk("uml_net didn't exit with status 1\n"); 139 printk("uml_net didn't exit with status 1\n");
134 } 140 }
135 return(err); 141 return err;
136} 142}
137 143
138static int etap_open(void *data) 144static int etap_open(void *data)
@@ -142,23 +148,24 @@ static int etap_open(void *data)
142 int data_fds[2], control_fds[2], err, output_len; 148 int data_fds[2], control_fds[2], err, output_len;
143 149
144 err = tap_open_common(pri->dev, pri->gate_addr); 150 err = tap_open_common(pri->dev, pri->gate_addr);
145 if(err) return(err); 151 if(err)
152 return err;
146 153
147 err = os_pipe(data_fds, 0, 0); 154 err = os_pipe(data_fds, 0, 0);
148 if(err < 0){ 155 if(err < 0){
149 printk("data os_pipe failed - err = %d\n", -err); 156 printk("data os_pipe failed - err = %d\n", -err);
150 return(err); 157 return err;
151 } 158 }
152 159
153 err = os_pipe(control_fds, 1, 0); 160 err = os_pipe(control_fds, 1, 0);
154 if(err < 0){ 161 if(err < 0){
155 printk("control os_pipe failed - err = %d\n", -err); 162 printk("control os_pipe failed - err = %d\n", -err);
156 return(err); 163 return err;
157 } 164 }
158 165
159 err = etap_tramp(pri->dev_name, pri->gate_addr, control_fds[0], 166 err = etap_tramp(pri->dev_name, pri->gate_addr, control_fds[0],
160 control_fds[1], data_fds[0], data_fds[1]); 167 control_fds[1], data_fds[0], data_fds[1]);
161 output_len = page_size(); 168 output_len = UM_KERN_PAGE_SIZE;
162 output = um_kmalloc(output_len); 169 output = um_kmalloc(output_len);
163 read_output(control_fds[0], output, output_len); 170 read_output(control_fds[0], output, output_len);
164 171
@@ -171,13 +178,13 @@ static int etap_open(void *data)
171 178
172 if(err < 0){ 179 if(err < 0){
173 printk("etap_tramp failed - err = %d\n", -err); 180 printk("etap_tramp failed - err = %d\n", -err);
174 return(err); 181 return err;
175 } 182 }
176 183
177 pri->data_fd = data_fds[0]; 184 pri->data_fd = data_fds[0];
178 pri->control_fd = control_fds[0]; 185 pri->control_fd = control_fds[0];
179 iter_addresses(pri->dev, etap_open_addr, &pri->control_fd); 186 iter_addresses(pri->dev, etap_open_addr, &pri->control_fd);
180 return(data_fds[0]); 187 return data_fds[0];
181} 188}
182 189
183static void etap_close(int fd, void *data) 190static void etap_close(int fd, void *data)
@@ -195,7 +202,7 @@ static void etap_close(int fd, void *data)
195 202
196static int etap_set_mtu(int mtu, void *data) 203static int etap_set_mtu(int mtu, void *data)
197{ 204{
198 return(mtu); 205 return mtu;
199} 206}
200 207
201static void etap_add_addr(unsigned char *addr, unsigned char *netmask, 208static void etap_add_addr(unsigned char *addr, unsigned char *netmask,
@@ -204,7 +211,8 @@ static void etap_add_addr(unsigned char *addr, unsigned char *netmask,
204 struct ethertap_data *pri = data; 211 struct ethertap_data *pri = data;
205 212
206 tap_check_ips(pri->gate_addr, addr); 213 tap_check_ips(pri->gate_addr, addr);
207 if(pri->control_fd == -1) return; 214 if(pri->control_fd == -1)
215 return;
208 etap_open_addr(addr, netmask, &pri->control_fd); 216 etap_open_addr(addr, netmask, &pri->control_fd);
209} 217}
210 218
@@ -213,7 +221,8 @@ static void etap_del_addr(unsigned char *addr, unsigned char *netmask,
213{ 221{
214 struct ethertap_data *pri = data; 222 struct ethertap_data *pri = data;
215 223
216 if(pri->control_fd == -1) return; 224 if(pri->control_fd == -1)
225 return;
217 etap_close_addr(addr, netmask, &pri->control_fd); 226 etap_close_addr(addr, netmask, &pri->control_fd);
218} 227}
219 228
@@ -227,14 +236,3 @@ const struct net_user_info ethertap_user_info = {
227 .delete_address = etap_del_addr, 236 .delete_address = etap_del_addr,
228 .max_packet = MAX_PACKET - ETH_HEADER_ETHERTAP 237 .max_packet = MAX_PACKET - ETH_HEADER_ETHERTAP
229}; 238};
230
231/*
232 * Overrides for Emacs so that we follow Linus's tabbing style.
233 * Emacs will notice this stuff at the end of the file and automatically
234 * adjust the settings for this buffer only. This must remain at the end
235 * of the file.
236 * ---------------------------------------------------------------------------
237 * Local variables:
238 * c-file-style: "linux"
239 * End:
240 */