aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux/drivers
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2007-10-16 04:27:29 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 12:43:08 -0400
commitcd1ae0e49bdd814cfaa2e5ab28cff21a30e20085 (patch)
tree1b993b9de4cb9a8578022a4014063c3e87ec996e /arch/um/os-Linux/drivers
parent1a80521990a0e30e61a92994a009adc52161b070 (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/os-Linux/drivers')
-rw-r--r--arch/um/os-Linux/drivers/etap.h16
-rw-r--r--arch/um/os-Linux/drivers/ethertap_kern.c36
-rw-r--r--arch/um/os-Linux/drivers/ethertap_user.c86
-rw-r--r--arch/um/os-Linux/drivers/tuntap.h13
-rw-r--r--arch/um/os-Linux/drivers/tuntap_kern.c34
-rw-r--r--arch/um/os-Linux/drivers/tuntap_user.c75
6 files changed, 123 insertions, 137 deletions
diff --git a/arch/um/os-Linux/drivers/etap.h b/arch/um/os-Linux/drivers/etap.h
index 57ecdaf2f67e..ddffd41c3f3f 100644
--- a/arch/um/os-Linux/drivers/etap.h
+++ b/arch/um/os-Linux/drivers/etap.h
@@ -1,8 +1,11 @@
1/* 1/*
2 * Copyright (C) 2001 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#ifndef __DRIVERS_ETAP_H
7#define __DRIVERS_ETAP_H
8
6#include "net_user.h" 9#include "net_user.h"
7 10
8struct ethertap_data { 11struct ethertap_data {
@@ -15,13 +18,4 @@ struct ethertap_data {
15 18
16extern const struct net_user_info ethertap_user_info; 19extern const struct net_user_info ethertap_user_info;
17 20
18/* 21#endif
19 * Overrides for Emacs so that we follow Linus's tabbing style.
20 * Emacs will notice this stuff at the end of the file and automatically
21 * adjust the settings for this buffer only. This must remain at the end
22 * of the file.
23 * ---------------------------------------------------------------------------
24 * Local variables:
25 * c-file-style: "linux"
26 * End:
27 */
diff --git a/arch/um/os-Linux/drivers/ethertap_kern.c b/arch/um/os-Linux/drivers/ethertap_kern.c
index 12689141414d..542bcc58354c 100644
--- a/arch/um/os-Linux/drivers/ethertap_kern.c
+++ b/arch/um/os-Linux/drivers/ethertap_kern.c
@@ -1,16 +1,15 @@
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 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
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.
5 * Licensed under the GPL. 6 * Licensed under the GPL.
6 */ 7 */
7 8
8#include "linux/init.h" 9#include "linux/init.h"
9#include "linux/netdevice.h" 10#include <linux/netdevice.h>
10#include "linux/etherdevice.h"
11#include "net_kern.h"
12#include "net_user.h"
13#include "etap.h" 11#include "etap.h"
12#include "net_kern.h"
14 13
15struct ethertap_init { 14struct ethertap_init {
16 char *dev_name; 15 char *dev_name;
@@ -42,27 +41,30 @@ static int etap_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
42 int len; 41 int len;
43 42
44 *skb = ether_adjust_skb(*skb, ETH_HEADER_ETHERTAP); 43 *skb = ether_adjust_skb(*skb, ETH_HEADER_ETHERTAP);
45 if(*skb == NULL) return(-ENOMEM); 44 if (*skb == NULL)
45 return -ENOMEM;
46 len = net_recvfrom(fd, skb_mac_header(*skb), 46 len = net_recvfrom(fd, skb_mac_header(*skb),
47 (*skb)->dev->mtu + 2 * ETH_HEADER_ETHERTAP); 47 (*skb)->dev->mtu + 2 * ETH_HEADER_ETHERTAP);
48 if(len <= 0) return(len); 48 if (len <= 0)
49 return len;
49 skb_pull(*skb, 2); 50 skb_pull(*skb, 2);
50 len -= 2; 51 len -= 2;
51 return(len); 52 return len;
52} 53}
53 54
54static int etap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp) 55static int etap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp)
55{ 56{
56 if(skb_headroom(*skb) < 2){ 57 if (skb_headroom(*skb) < 2) {
57 struct sk_buff *skb2; 58 struct sk_buff *skb2;
58 59
59 skb2 = skb_realloc_headroom(*skb, 2); 60 skb2 = skb_realloc_headroom(*skb, 2);
60 dev_kfree_skb(*skb); 61 dev_kfree_skb(*skb);
61 if (skb2 == NULL) return(-ENOMEM); 62 if (skb2 == NULL)
63 return -ENOMEM;
62 *skb = skb2; 64 *skb = skb2;
63 } 65 }
64 skb_push(*skb, 2); 66 skb_push(*skb, 2);
65 return(net_send(fd, (*skb)->data, (*skb)->len)); 67 return net_send(fd, (*skb)->data, (*skb)->len);
66} 68}
67 69
68const struct net_kern_info ethertap_kern_info = { 70const struct net_kern_info ethertap_kern_info = {
@@ -79,15 +81,15 @@ int ethertap_setup(char *str, char **mac_out, void *data)
79 *init = ((struct ethertap_init) 81 *init = ((struct ethertap_init)
80 { .dev_name = NULL, 82 { .dev_name = NULL,
81 .gate_addr = NULL }); 83 .gate_addr = NULL });
82 if(tap_setup_common(str, "ethertap", &init->dev_name, mac_out, 84 if (tap_setup_common(str, "ethertap", &init->dev_name, mac_out,
83 &init->gate_addr)) 85 &init->gate_addr))
84 return(0); 86 return 0;
85 if(init->dev_name == NULL){ 87 if (init->dev_name == NULL) {
86 printk("ethertap_setup : Missing tap device name\n"); 88 printk(KERN_ERR "ethertap_setup : Missing tap device name\n");
87 return(0); 89 return 0;
88 } 90 }
89 91
90 return(1); 92 return 1;
91} 93}
92 94
93static struct transport ethertap_transport = { 95static struct transport ethertap_transport = {
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);
diff --git a/arch/um/os-Linux/drivers/tuntap.h b/arch/um/os-Linux/drivers/tuntap.h
index d3e8d3af6245..f17c31586c84 100644
--- a/arch/um/os-Linux/drivers/tuntap.h
+++ b/arch/um/os-Linux/drivers/tuntap.h
@@ -1,5 +1,5 @@
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
@@ -19,14 +19,3 @@ struct tuntap_data {
19extern const struct net_user_info tuntap_user_info; 19extern const struct net_user_info tuntap_user_info;
20 20
21#endif 21#endif
22
23/*
24 * Overrides for Emacs so that we follow Linus's tabbing style.
25 * Emacs will notice this stuff at the end of the file and automatically
26 * adjust the settings for this buffer only. This must remain at the end
27 * of the file.
28 * ---------------------------------------------------------------------------
29 * Local variables:
30 * c-file-style: "linux"
31 * End:
32 */
diff --git a/arch/um/os-Linux/drivers/tuntap_kern.c b/arch/um/os-Linux/drivers/tuntap_kern.c
index f1714e7fb1d0..9ade1f892ac8 100644
--- a/arch/um/os-Linux/drivers/tuntap_kern.c
+++ b/arch/um/os-Linux/drivers/tuntap_kern.c
@@ -1,16 +1,13 @@
1/* 1/*
2 * Copyright (C) 2001 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 "linux/stddef.h" 6#include <linux/netdevice.h>
7#include "linux/netdevice.h" 7#include <linux/init.h>
8#include "linux/etherdevice.h" 8#include <linux/skbuff.h>
9#include "linux/skbuff.h" 9#include <asm/errno.h>
10#include "linux/init.h"
11#include "asm/errno.h"
12#include "net_kern.h" 10#include "net_kern.h"
13#include "net_user.h"
14#include "tuntap.h" 11#include "tuntap.h"
15 12
16struct tuntap_init { 13struct tuntap_init {
@@ -38,19 +35,20 @@ static void tuntap_init(struct net_device *dev, void *data)
38 printk("\n"); 35 printk("\n");
39} 36}
40 37
41static int tuntap_read(int fd, struct sk_buff **skb, 38static int tuntap_read(int fd, struct sk_buff **skb,
42 struct uml_net_private *lp) 39 struct uml_net_private *lp)
43{ 40{
44 *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER); 41 *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
45 if(*skb == NULL) return(-ENOMEM); 42 if (*skb == NULL)
46 return(net_read(fd, skb_mac_header(*skb), 43 return -ENOMEM;
47 (*skb)->dev->mtu + ETH_HEADER_OTHER)); 44 return net_read(fd, skb_mac_header(*skb),
45 (*skb)->dev->mtu + ETH_HEADER_OTHER);
48} 46}
49 47
50static int tuntap_write(int fd, struct sk_buff **skb, 48static int tuntap_write(int fd, struct sk_buff **skb,
51 struct uml_net_private *lp) 49 struct uml_net_private *lp)
52{ 50{
53 return(net_write(fd, (*skb)->data, (*skb)->len)); 51 return net_write(fd, (*skb)->data, (*skb)->len);
54} 52}
55 53
56const struct net_kern_info tuntap_kern_info = { 54const struct net_kern_info tuntap_kern_info = {
@@ -67,11 +65,11 @@ int tuntap_setup(char *str, char **mac_out, void *data)
67 *init = ((struct tuntap_init) 65 *init = ((struct tuntap_init)
68 { .dev_name = NULL, 66 { .dev_name = NULL,
69 .gate_addr = NULL }); 67 .gate_addr = NULL });
70 if(tap_setup_common(str, "tuntap", &init->dev_name, mac_out, 68 if (tap_setup_common(str, "tuntap", &init->dev_name, mac_out,
71 &init->gate_addr)) 69 &init->gate_addr))
72 return(0); 70 return 0;
73 71
74 return(1); 72 return 1;
75} 73}
76 74
77static struct transport tuntap_transport = { 75static struct transport tuntap_transport = {
diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/arch/um/os-Linux/drivers/tuntap_user.c
index 72a2ff61556d..10714a413cfd 100644
--- a/arch/um/os-Linux/drivers/tuntap_user.c
+++ b/arch/um/os-Linux/drivers/tuntap_user.c
@@ -1,25 +1,22 @@
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 <stdio.h> 6#include <stdio.h>
7#include <stddef.h>
8#include <stdlib.h>
9#include <unistd.h> 7#include <unistd.h>
10#include <errno.h> 8#include <errno.h>
11#include <sys/wait.h> 9#include <string.h>
10#include <linux/if_tun.h>
11#include <net/if.h>
12#include <sys/ioctl.h>
12#include <sys/socket.h> 13#include <sys/socket.h>
13#include <sys/un.h> 14#include <sys/wait.h>
14#include <sys/uio.h> 15#include <sys/uio.h>
15#include <sys/ioctl.h> 16#include "kern_constants.h"
16#include <net/if.h> 17#include "os.h"
17#include <linux/if_tun.h>
18#include "net_user.h"
19#include "tuntap.h" 18#include "tuntap.h"
20#include "kern_util.h"
21#include "user.h" 19#include "user.h"
22#include "os.h"
23 20
24#define MAX_PACKET ETH_MAX_PACKET 21#define MAX_PACKET ETH_MAX_PACKET
25 22
@@ -37,7 +34,7 @@ static void tuntap_add_addr(unsigned char *addr, unsigned char *netmask,
37 struct tuntap_data *pri = data; 34 struct tuntap_data *pri = data;
38 35
39 tap_check_ips(pri->gate_addr, addr); 36 tap_check_ips(pri->gate_addr, addr);
40 if((pri->fd == -1) || pri->fixed_config) 37 if ((pri->fd == -1) || pri->fixed_config)
41 return; 38 return;
42 open_addr(addr, netmask, pri->dev_name); 39 open_addr(addr, netmask, pri->dev_name);
43} 40}
@@ -47,7 +44,7 @@ static void tuntap_del_addr(unsigned char *addr, unsigned char *netmask,
47{ 44{
48 struct tuntap_data *pri = data; 45 struct tuntap_data *pri = data;
49 46
50 if((pri->fd == -1) || pri->fixed_config) 47 if ((pri->fd == -1) || pri->fixed_config)
51 return; 48 return;
52 close_addr(addr, netmask, pri->dev_name); 49 close_addr(addr, netmask, pri->dev_name);
53} 50}
@@ -85,14 +82,14 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
85 82
86 pid = run_helper(tuntap_pre_exec, &data, argv); 83 pid = run_helper(tuntap_pre_exec, &data, argv);
87 84
88 if(pid < 0) 85 if (pid < 0)
89 return -pid; 86 return -pid;
90 87
91 close(remote); 88 close(remote);
92 89
93 msg.msg_name = NULL; 90 msg.msg_name = NULL;
94 msg.msg_namelen = 0; 91 msg.msg_namelen = 0;
95 if(buffer != NULL){ 92 if (buffer != NULL) {
96 iov = ((struct iovec) { buffer, buffer_len }); 93 iov = ((struct iovec) { buffer, buffer_len });
97 msg.msg_iov = &iov; 94 msg.msg_iov = &iov;
98 msg.msg_iovlen = 1; 95 msg.msg_iovlen = 1;
@@ -106,22 +103,24 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
106 msg.msg_flags = 0; 103 msg.msg_flags = 0;
107 n = recvmsg(me, &msg, 0); 104 n = recvmsg(me, &msg, 0);
108 *used_out = n; 105 *used_out = n;
109 if(n < 0){ 106 if (n < 0) {
110 err = -errno; 107 err = -errno;
111 printk("tuntap_open_tramp : recvmsg failed - errno = %d\n", 108 printk(UM_KERN_ERR "tuntap_open_tramp : recvmsg failed - "
112 errno); 109 "errno = %d\n", errno);
113 return err; 110 return err;
114 } 111 }
115 CATCH_EINTR(waitpid(pid, NULL, 0)); 112 CATCH_EINTR(waitpid(pid, NULL, 0));
116 113
117 cmsg = CMSG_FIRSTHDR(&msg); 114 cmsg = CMSG_FIRSTHDR(&msg);
118 if(cmsg == NULL){ 115 if (cmsg == NULL) {
119 printk("tuntap_open_tramp : didn't receive a message\n"); 116 printk(UM_KERN_ERR "tuntap_open_tramp : didn't receive a "
117 "message\n");
120 return -EINVAL; 118 return -EINVAL;
121 } 119 }
122 if((cmsg->cmsg_level != SOL_SOCKET) || 120 if ((cmsg->cmsg_level != SOL_SOCKET) ||
123 (cmsg->cmsg_type != SCM_RIGHTS)){ 121 (cmsg->cmsg_type != SCM_RIGHTS)) {
124 printk("tuntap_open_tramp : didn't receive a descriptor\n"); 122 printk(UM_KERN_ERR "tuntap_open_tramp : didn't receive a "
123 "descriptor\n");
125 return -EINVAL; 124 return -EINVAL;
126 } 125 }
127 *fd_out = ((int *) CMSG_DATA(cmsg))[0]; 126 *fd_out = ((int *) CMSG_DATA(cmsg))[0];
@@ -137,38 +136,39 @@ static int tuntap_open(void *data)
137 int err, fds[2], len, used; 136 int err, fds[2], len, used;
138 137
139 err = tap_open_common(pri->dev, pri->gate_addr); 138 err = tap_open_common(pri->dev, pri->gate_addr);
140 if(err < 0) 139 if (err < 0)
141 return err; 140 return err;
142 141
143 if(pri->fixed_config){ 142 if (pri->fixed_config) {
144 pri->fd = os_open_file("/dev/net/tun", 143 pri->fd = os_open_file("/dev/net/tun",
145 of_cloexec(of_rdwr(OPENFLAGS())), 0); 144 of_cloexec(of_rdwr(OPENFLAGS())), 0);
146 if(pri->fd < 0){ 145 if (pri->fd < 0) {
147 printk("Failed to open /dev/net/tun, err = %d\n", 146 printk(UM_KERN_ERR "Failed to open /dev/net/tun, "
148 -pri->fd); 147 "err = %d\n", -pri->fd);
149 return pri->fd; 148 return pri->fd;
150 } 149 }
151 memset(&ifr, 0, sizeof(ifr)); 150 memset(&ifr, 0, sizeof(ifr));
152 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; 151 ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
153 strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name)); 152 strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name));
154 if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){ 153 if (ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0) {
155 err = -errno; 154 err = -errno;
156 printk("TUNSETIFF failed, errno = %d\n", errno); 155 printk(UM_KERN_ERR "TUNSETIFF failed, errno = %d\n",
156 errno);
157 close(pri->fd); 157 close(pri->fd);
158 return err; 158 return err;
159 } 159 }
160 } 160 }
161 else { 161 else {
162 err = socketpair(AF_UNIX, SOCK_DGRAM, 0, fds); 162 err = socketpair(AF_UNIX, SOCK_DGRAM, 0, fds);
163 if(err){ 163 if (err) {
164 err = -errno; 164 err = -errno;
165 printk("tuntap_open : socketpair failed - errno = %d\n", 165 printk(UM_KERN_ERR "tuntap_open : socketpair failed - "
166 errno); 166 "errno = %d\n", errno);
167 return err; 167 return err;
168 } 168 }
169 169
170 buffer = get_output_buffer(&len); 170 buffer = get_output_buffer(&len);
171 if(buffer != NULL) 171 if (buffer != NULL)
172 len--; 172 len--;
173 used = 0; 173 used = 0;
174 174
@@ -176,10 +176,11 @@ static int tuntap_open(void *data)
176 fds[1], buffer, len, &used); 176 fds[1], buffer, len, &used);
177 177
178 output = buffer; 178 output = buffer;
179 if(err < 0) { 179 if (err < 0) {
180 printk("%s", output); 180 printk("%s", output);
181 free_output_buffer(buffer); 181 free_output_buffer(buffer);
182 printk("tuntap_open_tramp failed - err = %d\n", -err); 182 printk(UM_KERN_ERR "tuntap_open_tramp failed - "
183 "err = %d\n", -err);
183 return err; 184 return err;
184 } 185 }
185 186
@@ -199,7 +200,7 @@ static void tuntap_close(int fd, void *data)
199{ 200{
200 struct tuntap_data *pri = data; 201 struct tuntap_data *pri = data;
201 202
202 if(!pri->fixed_config) 203 if (!pri->fixed_config)
203 iter_addresses(pri->dev, close_addr, pri->dev_name); 204 iter_addresses(pri->dev, close_addr, pri->dev_name);
204 close(fd); 205 close(fd);
205 pri->fd = -1; 206 pri->fd = -1;