8 #include <sys/termios.h>
10 #include <sys/signal.h>
11 #include "user_util.h"
12 #include "kern_util.h"
16 #include "slip_common.h"
20 void slip_user_init(void *data
, void *dev
)
22 struct slip_data
*pri
= data
;
27 static int set_up_tty(int fd
)
32 if (tcgetattr(fd
, &tios
) < 0) {
33 printk("could not get initial terminal attributes\n");
37 tios
.c_cflag
= CS8
| CREAD
| HUPCL
| CLOCAL
;
38 tios
.c_iflag
= IGNBRK
| IGNPAR
;
41 for (i
= 0; i
< NCCS
; i
++)
46 cfsetospeed(&tios
, B38400
);
47 cfsetispeed(&tios
, B38400
);
49 if (tcsetattr(fd
, TCSAFLUSH
, &tios
) < 0) {
50 printk("failed to set terminal attributes\n");
56 struct slip_pre_exec_data
{
62 static void slip_pre_exec(void *arg
)
64 struct slip_pre_exec_data
*data
= arg
;
66 if(data
->stdin
>= 0) dup2(data
->stdin
, 0);
67 dup2(data
->stdout
, 1);
68 if(data
->close_me
>= 0) os_close_file(data
->close_me
);
71 static int slip_tramp(char **argv
, int fd
)
73 struct slip_pre_exec_data pe_data
;
75 int status
, pid
, fds
[2], err
, output_len
;
77 err
= os_pipe(fds
, 1, 0);
79 printk("slip_tramp : pipe failed, err = %d\n", -err
);
85 pe_data
.stdout
= fds
[1];
86 pe_data
.close_me
= fds
[0];
87 err
= run_helper(slip_pre_exec
, &pe_data
, argv
, NULL
);
92 output_len
= page_size();
93 output
= um_kmalloc(output_len
);
95 printk("slip_tramp : failed to allocate output buffer\n");
96 os_kill_process(pid
, 1);
101 os_close_file(fds
[1]);
102 read_output(fds
[0], output
, output_len
);
103 printk("%s", output
);
105 CATCH_EINTR(err
= waitpid(pid
, &status
, 0));
108 else if(!WIFEXITED(status
) || (WEXITSTATUS(status
) != 0)){
109 printk("'%s' didn't exit with status 0\n", argv
[0]);
114 os_close_file(fds
[0]);
121 os_close_file(fds
[0]);
122 os_close_file(fds
[1]);
127 static int slip_open(void *data
)
129 struct slip_data
*pri
= data
;
130 char version_buf
[sizeof("nnnnn\0")];
131 char gate_buf
[sizeof("nnn.nnn.nnn.nnn\0")];
132 char *argv
[] = { "uml_net", version_buf
, "slip", "up", gate_buf
,
138 printk("slip-open : Failed to open pty, err = %d\n", -err
);
143 err
= os_open_file(ptsname(mfd
), of_rdwr(OPENFLAGS()), 0);
145 printk("Couldn't open tty for slip line, err = %d\n", -err
);
156 if(pri
->gate_addr
!= NULL
){
157 sprintf(version_buf
, "%d", UML_NET_VERSION
);
158 strcpy(gate_buf
, pri
->gate_addr
);
160 err
= slip_tramp(argv
, sfd
);
163 printk("slip_tramp failed - err = %d\n", -err
);
166 err
= os_get_ifname(pri
->slave
, pri
->name
);
168 printk("get_ifname failed, err = %d\n", -err
);
171 iter_addresses(pri
->dev
, open_addr
, pri
->name
);
174 err
= os_set_slip(sfd
);
176 printk("Failed to set slip discipline encapsulation - "
190 static void slip_close(int fd
, void *data
)
192 struct slip_data
*pri
= data
;
193 char version_buf
[sizeof("nnnnn\0")];
194 char *argv
[] = { "uml_net", version_buf
, "slip", "down", pri
->name
,
198 if(pri
->gate_addr
!= NULL
)
199 iter_addresses(pri
->dev
, close_addr
, pri
->name
);
201 sprintf(version_buf
, "%d", UML_NET_VERSION
);
203 err
= slip_tramp(argv
, pri
->slave
);
206 printk("slip_tramp failed - errno = %d\n", -err
);
208 os_close_file(pri
->slave
);
212 int slip_user_read(int fd
, void *buf
, int len
, struct slip_data
*pri
)
214 return slip_proto_read(fd
, buf
, len
, &pri
->slip
);
217 int slip_user_write(int fd
, void *buf
, int len
, struct slip_data
*pri
)
219 return slip_proto_write(fd
, buf
, len
, &pri
->slip
);
222 static int slip_set_mtu(int mtu
, void *data
)
227 static void slip_add_addr(unsigned char *addr
, unsigned char *netmask
,
230 struct slip_data
*pri
= data
;
232 if(pri
->slave
< 0) return;
233 open_addr(addr
, netmask
, pri
->name
);
236 static void slip_del_addr(unsigned char *addr
, unsigned char *netmask
,
239 struct slip_data
*pri
= data
;
241 if(pri
->slave
< 0) return;
242 close_addr(addr
, netmask
, pri
->name
);
245 struct net_user_info slip_user_info
= {
246 .init
= slip_user_init
,
250 .set_mtu
= slip_set_mtu
,
251 .add_address
= slip_add_addr
,
252 .delete_address
= slip_del_addr
,
253 .max_packet
= BUF_SIZE