aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/drivers/slip_user.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/drivers/slip_user.c')
-rw-r--r--arch/um/drivers/slip_user.c122
1 files changed, 67 insertions, 55 deletions
diff --git a/arch/um/drivers/slip_user.c b/arch/um/drivers/slip_user.c
index c0b73c28cff0..d78f324e7298 100644
--- a/arch/um/drivers/slip_user.c
+++ b/arch/um/drivers/slip_user.c
@@ -1,21 +1,22 @@
1/*
2 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL.
4 */
5
1#include <stdio.h> 6#include <stdio.h>
2#include <stdlib.h> 7#include <stdlib.h>
3#include <unistd.h> 8#include <unistd.h>
4#include <stddef.h>
5#include <sched.h>
6#include <string.h>
7#include <errno.h> 9#include <errno.h>
10#include <fcntl.h>
11#include <string.h>
8#include <sys/termios.h> 12#include <sys/termios.h>
9#include <sys/wait.h> 13#include <sys/wait.h>
10#include <sys/signal.h> 14#include "kern_constants.h"
11#include "kern_util.h"
12#include "user.h"
13#include "net_user.h" 15#include "net_user.h"
14#include "slip.h"
15#include "slip_common.h"
16#include "os.h" 16#include "os.h"
17#include "slip.h"
17#include "um_malloc.h" 18#include "um_malloc.h"
18#include "kern_constants.h" 19#include "user.h"
19 20
20static int slip_user_init(void *data, void *dev) 21static int slip_user_init(void *data, void *dev)
21{ 22{
@@ -31,8 +32,9 @@ static int set_up_tty(int fd)
31 struct termios tios; 32 struct termios tios;
32 33
33 if (tcgetattr(fd, &tios) < 0) { 34 if (tcgetattr(fd, &tios) < 0) {
34 printk("could not get initial terminal attributes\n"); 35 printk(UM_KERN_ERR "could not get initial terminal "
35 return(-1); 36 "attributes\n");
37 return -1;
36 } 38 }
37 39
38 tios.c_cflag = CS8 | CREAD | HUPCL | CLOCAL; 40 tios.c_cflag = CS8 | CREAD | HUPCL | CLOCAL;
@@ -48,10 +50,10 @@ static int set_up_tty(int fd)
48 cfsetispeed(&tios, B38400); 50 cfsetispeed(&tios, B38400);
49 51
50 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) { 52 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
51 printk("failed to set terminal attributes\n"); 53 printk(UM_KERN_ERR "failed to set terminal attributes\n");
52 return(-1); 54 return -1;
53 } 55 }
54 return(0); 56 return 0;
55} 57}
56 58
57struct slip_pre_exec_data { 59struct slip_pre_exec_data {
@@ -64,9 +66,11 @@ static void slip_pre_exec(void *arg)
64{ 66{
65 struct slip_pre_exec_data *data = arg; 67 struct slip_pre_exec_data *data = arg;
66 68
67 if(data->stdin >= 0) dup2(data->stdin, 0); 69 if (data->stdin >= 0)
70 dup2(data->stdin, 0);
68 dup2(data->stdout, 1); 71 dup2(data->stdout, 1);
69 if(data->close_me >= 0) os_close_file(data->close_me); 72 if (data->close_me >= 0)
73 close(data->close_me);
70} 74}
71 75
72static int slip_tramp(char **argv, int fd) 76static int slip_tramp(char **argv, int fd)
@@ -76,8 +80,9 @@ static int slip_tramp(char **argv, int fd)
76 int status, pid, fds[2], err, output_len; 80 int status, pid, fds[2], err, output_len;
77 81
78 err = os_pipe(fds, 1, 0); 82 err = os_pipe(fds, 1, 0);
79 if(err < 0){ 83 if (err < 0) {
80 printk("slip_tramp : pipe failed, err = %d\n", -err); 84 printk(UM_KERN_ERR "slip_tramp : pipe failed, err = %d\n",
85 -err);
81 goto out; 86 goto out;
82 } 87 }
83 88
@@ -86,41 +91,42 @@ static int slip_tramp(char **argv, int fd)
86 pe_data.stdout = fds[1]; 91 pe_data.stdout = fds[1];
87 pe_data.close_me = fds[0]; 92 pe_data.close_me = fds[0];
88 err = run_helper(slip_pre_exec, &pe_data, argv); 93 err = run_helper(slip_pre_exec, &pe_data, argv);
89 if(err < 0) 94 if (err < 0)
90 goto out_close; 95 goto out_close;
91 pid = err; 96 pid = err;
92 97
93 output_len = UM_KERN_PAGE_SIZE; 98 output_len = UM_KERN_PAGE_SIZE;
94 output = kmalloc(output_len, UM_GFP_KERNEL); 99 output = kmalloc(output_len, UM_GFP_KERNEL);
95 if(output == NULL){ 100 if (output == NULL) {
96 printk("slip_tramp : failed to allocate output buffer\n"); 101 printk(UM_KERN_ERR "slip_tramp : failed to allocate output "
102 "buffer\n");
97 os_kill_process(pid, 1); 103 os_kill_process(pid, 1);
98 err = -ENOMEM; 104 err = -ENOMEM;
99 goto out_free; 105 goto out_free;
100 } 106 }
101 107
102 os_close_file(fds[1]); 108 close(fds[1]);
103 read_output(fds[0], output, output_len); 109 read_output(fds[0], output, output_len);
104 printk("%s", output); 110 printk("%s", output);
105 111
106 CATCH_EINTR(err = waitpid(pid, &status, 0)); 112 CATCH_EINTR(err = waitpid(pid, &status, 0));
107 if(err < 0) 113 if (err < 0)
108 err = errno; 114 err = errno;
109 else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){ 115 else if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
110 printk("'%s' didn't exit with status 0\n", argv[0]); 116 printk(UM_KERN_ERR "'%s' didn't exit with status 0\n", argv[0]);
111 err = -EINVAL; 117 err = -EINVAL;
112 } 118 }
113 else err = 0; 119 else err = 0;
114 120
115 os_close_file(fds[0]); 121 close(fds[0]);
116 122
117out_free: 123out_free:
118 kfree(output); 124 kfree(output);
119 return err; 125 return err;
120 126
121out_close: 127out_close:
122 os_close_file(fds[0]); 128 close(fds[0]);
123 os_close_file(fds[1]); 129 close(fds[1]);
124out: 130out:
125 return err; 131 return err;
126} 132}
@@ -130,60 +136,64 @@ static int slip_open(void *data)
130 struct slip_data *pri = data; 136 struct slip_data *pri = data;
131 char version_buf[sizeof("nnnnn\0")]; 137 char version_buf[sizeof("nnnnn\0")];
132 char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")]; 138 char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")];
133 char *argv[] = { "uml_net", version_buf, "slip", "up", gate_buf, 139 char *argv[] = { "uml_net", version_buf, "slip", "up", gate_buf,
134 NULL }; 140 NULL };
135 int sfd, mfd, err; 141 int sfd, mfd, err;
136 142
137 err = get_pty(); 143 err = get_pty();
138 if(err < 0){ 144 if (err < 0) {
139 printk("slip-open : Failed to open pty, err = %d\n", -err); 145 printk(UM_KERN_ERR "slip-open : Failed to open pty, err = %d\n",
146 -err);
140 goto out; 147 goto out;
141 } 148 }
142 mfd = err; 149 mfd = err;
143 150
144 err = os_open_file(ptsname(mfd), of_rdwr(OPENFLAGS()), 0); 151 err = open(ptsname(mfd), O_RDWR, 0);
145 if(err < 0){ 152 if (err < 0) {
146 printk("Couldn't open tty for slip line, err = %d\n", -err); 153 printk(UM_KERN_ERR "Couldn't open tty for slip line, "
154 "err = %d\n", -err);
147 goto out_close; 155 goto out_close;
148 } 156 }
149 sfd = err; 157 sfd = err;
150 158
151 if(set_up_tty(sfd)) 159 if (set_up_tty(sfd))
152 goto out_close2; 160 goto out_close2;
153 161
154 pri->slave = sfd; 162 pri->slave = sfd;
155 pri->slip.pos = 0; 163 pri->slip.pos = 0;
156 pri->slip.esc = 0; 164 pri->slip.esc = 0;
157 if(pri->gate_addr != NULL){ 165 if (pri->gate_addr != NULL) {
158 sprintf(version_buf, "%d", UML_NET_VERSION); 166 sprintf(version_buf, "%d", UML_NET_VERSION);
159 strcpy(gate_buf, pri->gate_addr); 167 strcpy(gate_buf, pri->gate_addr);
160 168
161 err = slip_tramp(argv, sfd); 169 err = slip_tramp(argv, sfd);
162 170
163 if(err < 0){ 171 if (err < 0) {
164 printk("slip_tramp failed - err = %d\n", -err); 172 printk(UM_KERN_ERR "slip_tramp failed - err = %d\n",
173 -err);
165 goto out_close2; 174 goto out_close2;
166 } 175 }
167 err = os_get_ifname(pri->slave, pri->name); 176 err = os_get_ifname(pri->slave, pri->name);
168 if(err < 0){ 177 if (err < 0) {
169 printk("get_ifname failed, err = %d\n", -err); 178 printk(UM_KERN_ERR "get_ifname failed, err = %d\n",
179 -err);
170 goto out_close2; 180 goto out_close2;
171 } 181 }
172 iter_addresses(pri->dev, open_addr, pri->name); 182 iter_addresses(pri->dev, open_addr, pri->name);
173 } 183 }
174 else { 184 else {
175 err = os_set_slip(sfd); 185 err = os_set_slip(sfd);
176 if(err < 0){ 186 if (err < 0) {
177 printk("Failed to set slip discipline encapsulation - " 187 printk(UM_KERN_ERR "Failed to set slip discipline "
178 "err = %d\n", -err); 188 "encapsulation - err = %d\n", -err);
179 goto out_close2; 189 goto out_close2;
180 } 190 }
181 } 191 }
182 return(mfd); 192 return mfd;
183out_close2: 193out_close2:
184 os_close_file(sfd); 194 close(sfd);
185out_close: 195out_close:
186 os_close_file(mfd); 196 close(mfd);
187out: 197out:
188 return err; 198 return err;
189} 199}
@@ -192,21 +202,21 @@ static void slip_close(int fd, void *data)
192{ 202{
193 struct slip_data *pri = data; 203 struct slip_data *pri = data;
194 char version_buf[sizeof("nnnnn\0")]; 204 char version_buf[sizeof("nnnnn\0")];
195 char *argv[] = { "uml_net", version_buf, "slip", "down", pri->name, 205 char *argv[] = { "uml_net", version_buf, "slip", "down", pri->name,
196 NULL }; 206 NULL };
197 int err; 207 int err;
198 208
199 if(pri->gate_addr != NULL) 209 if (pri->gate_addr != NULL)
200 iter_addresses(pri->dev, close_addr, pri->name); 210 iter_addresses(pri->dev, close_addr, pri->name);
201 211
202 sprintf(version_buf, "%d", UML_NET_VERSION); 212 sprintf(version_buf, "%d", UML_NET_VERSION);
203 213
204 err = slip_tramp(argv, pri->slave); 214 err = slip_tramp(argv, pri->slave);
205 215
206 if(err != 0) 216 if (err != 0)
207 printk("slip_tramp failed - errno = %d\n", -err); 217 printk(UM_KERN_ERR "slip_tramp failed - errno = %d\n", -err);
208 os_close_file(fd); 218 close(fd);
209 os_close_file(pri->slave); 219 close(pri->slave);
210 pri->slave = -1; 220 pri->slave = -1;
211} 221}
212 222
@@ -222,7 +232,7 @@ int slip_user_write(int fd, void *buf, int len, struct slip_data *pri)
222 232
223static int slip_set_mtu(int mtu, void *data) 233static int slip_set_mtu(int mtu, void *data)
224{ 234{
225 return(mtu); 235 return mtu;
226} 236}
227 237
228static void slip_add_addr(unsigned char *addr, unsigned char *netmask, 238static void slip_add_addr(unsigned char *addr, unsigned char *netmask,
@@ -230,7 +240,8 @@ static void slip_add_addr(unsigned char *addr, unsigned char *netmask,
230{ 240{
231 struct slip_data *pri = data; 241 struct slip_data *pri = data;
232 242
233 if(pri->slave < 0) return; 243 if (pri->slave < 0)
244 return;
234 open_addr(addr, netmask, pri->name); 245 open_addr(addr, netmask, pri->name);
235} 246}
236 247
@@ -239,7 +250,8 @@ static void slip_del_addr(unsigned char *addr, unsigned char *netmask,
239{ 250{
240 struct slip_data *pri = data; 251 struct slip_data *pri = data;
241 252
242 if(pri->slave < 0) return; 253 if (pri->slave < 0)
254 return;
243 close_addr(addr, netmask, pri->name); 255 close_addr(addr, netmask, pri->name);
244} 256}
245 257