2 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL.
12 #include <sys/termios.h>
14 #include "kern_constants.h"
18 #include "um_malloc.h"
21 static int slip_user_init(void *data
, void *dev
)
23 struct slip_data
*pri
= data
;
29 static int set_up_tty(int fd
)
34 if (tcgetattr(fd
, &tios
) < 0) {
35 printk(UM_KERN_ERR
"could not get initial terminal "
40 tios
.c_cflag
= CS8
| CREAD
| HUPCL
| CLOCAL
;
41 tios
.c_iflag
= IGNBRK
| IGNPAR
;
44 for (i
= 0; i
< NCCS
; i
++)
49 cfsetospeed(&tios
, B38400
);
50 cfsetispeed(&tios
, B38400
);
52 if (tcsetattr(fd
, TCSAFLUSH
, &tios
) < 0) {
53 printk(UM_KERN_ERR
"failed to set terminal attributes\n");
59 struct slip_pre_exec_data
{
65 static void slip_pre_exec(void *arg
)
67 struct slip_pre_exec_data
*data
= arg
;
71 dup2(data
->stdout
, 1);
72 if (data
->close_me
>= 0)
73 close(data
->close_me
);
76 static int slip_tramp(char **argv
, int fd
)
78 struct slip_pre_exec_data pe_data
;
80 int pid
, fds
[2], err
, output_len
;
82 err
= os_pipe(fds
, 1, 0);
84 printk(UM_KERN_ERR
"slip_tramp : pipe failed, err = %d\n",
91 pe_data
.stdout
= fds
[1];
92 pe_data
.close_me
= fds
[0];
93 err
= run_helper(slip_pre_exec
, &pe_data
, argv
);
98 output_len
= UM_KERN_PAGE_SIZE
;
99 output
= kmalloc(output_len
, UM_GFP_KERNEL
);
100 if (output
== NULL
) {
101 printk(UM_KERN_ERR
"slip_tramp : failed to allocate output "
103 os_kill_process(pid
, 1);
109 read_output(fds
[0], output
, output_len
);
110 printk("%s", output
);
112 err
= helper_wait(pid
);
126 static int slip_open(void *data
)
128 struct slip_data
*pri
= data
;
129 char version_buf
[sizeof("nnnnn\0")];
130 char gate_buf
[sizeof("nnn.nnn.nnn.nnn\0")];
131 char *argv
[] = { "uml_net", version_buf
, "slip", "up", gate_buf
,
137 printk(UM_KERN_ERR
"slip-open : Failed to open pty, err = %d\n",
143 err
= open(ptsname(mfd
), O_RDWR
, 0);
145 printk(UM_KERN_ERR
"Couldn't open tty for slip line, "
157 if (pri
->gate_addr
!= NULL
) {
158 sprintf(version_buf
, "%d", UML_NET_VERSION
);
159 strcpy(gate_buf
, pri
->gate_addr
);
161 err
= slip_tramp(argv
, sfd
);
164 printk(UM_KERN_ERR
"slip_tramp failed - err = %d\n",
168 err
= os_get_ifname(pri
->slave
, pri
->name
);
170 printk(UM_KERN_ERR
"get_ifname failed, err = %d\n",
174 iter_addresses(pri
->dev
, open_addr
, pri
->name
);
177 err
= os_set_slip(sfd
);
179 printk(UM_KERN_ERR
"Failed to set slip discipline "
180 "encapsulation - err = %d\n", -err
);
193 static void slip_close(int fd
, void *data
)
195 struct slip_data
*pri
= data
;
196 char version_buf
[sizeof("nnnnn\0")];
197 char *argv
[] = { "uml_net", version_buf
, "slip", "down", pri
->name
,
201 if (pri
->gate_addr
!= NULL
)
202 iter_addresses(pri
->dev
, close_addr
, pri
->name
);
204 sprintf(version_buf
, "%d", UML_NET_VERSION
);
206 err
= slip_tramp(argv
, pri
->slave
);
209 printk(UM_KERN_ERR
"slip_tramp failed - errno = %d\n", -err
);
215 int slip_user_read(int fd
, void *buf
, int len
, struct slip_data
*pri
)
217 return slip_proto_read(fd
, buf
, len
, &pri
->slip
);
220 int slip_user_write(int fd
, void *buf
, int len
, struct slip_data
*pri
)
222 return slip_proto_write(fd
, buf
, len
, &pri
->slip
);
225 static void slip_add_addr(unsigned char *addr
, unsigned char *netmask
,
228 struct slip_data
*pri
= data
;
232 open_addr(addr
, netmask
, pri
->name
);
235 static void slip_del_addr(unsigned char *addr
, unsigned char *netmask
,
238 struct slip_data
*pri
= data
;
242 close_addr(addr
, netmask
, pri
->name
);
245 const struct net_user_info slip_user_info
= {
246 .init
= slip_user_init
,
250 .add_address
= slip_add_addr
,
251 .delete_address
= slip_del_addr
,
253 .max_packet
= BUF_SIZE
,