2 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL.
12 #include <sys/termios.h>
17 #include <um_malloc.h>
19 static int slip_user_init(void *data, void *dev)
21 struct slip_data *pri = data;
27 static int set_up_tty(int fd)
32 if (tcgetattr(fd, &tios) < 0) {
33 printk(UM_KERN_ERR "could not get initial terminal "
38 tios.c_cflag = CS8 | CREAD | HUPCL | CLOCAL;
39 tios.c_iflag = IGNBRK | IGNPAR;
42 for (i = 0; i < NCCS; i++)
47 cfsetospeed(&tios, B38400);
48 cfsetispeed(&tios, B38400);
50 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
51 printk(UM_KERN_ERR "failed to set terminal attributes\n");
57 struct slip_pre_exec_data {
63 static void slip_pre_exec(void *arg)
65 struct slip_pre_exec_data *data = arg;
69 dup2(data->stdout, 1);
70 if (data->close_me >= 0)
71 close(data->close_me);
74 static int slip_tramp(char **argv, int fd)
76 struct slip_pre_exec_data pe_data;
78 int pid, fds[2], err, output_len;
80 err = os_pipe(fds, 1, 0);
82 printk(UM_KERN_ERR "slip_tramp : pipe failed, err = %d\n",
89 pe_data.stdout = fds[1];
90 pe_data.close_me = fds[0];
91 err = run_helper(slip_pre_exec, &pe_data, argv);
96 output_len = UM_KERN_PAGE_SIZE;
97 output = uml_kmalloc(output_len, UM_GFP_KERNEL);
99 printk(UM_KERN_ERR "slip_tramp : failed to allocate output "
101 os_kill_process(pid, 1);
107 read_output(fds[0], output, output_len);
108 printk("%s", output);
110 err = helper_wait(pid);
123 static int slip_open(void *data)
125 struct slip_data *pri = data;
126 char version_buf[sizeof("nnnnn\0")];
127 char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")];
128 char *argv[] = { "uml_net", version_buf, "slip", "up", gate_buf,
134 printk(UM_KERN_ERR "slip-open : Failed to open pty, err = %d\n",
140 err = open(ptsname(mfd), O_RDWR, 0);
142 printk(UM_KERN_ERR "Couldn't open tty for slip line, "
154 if (pri->gate_addr != NULL) {
155 sprintf(version_buf, "%d", UML_NET_VERSION);
156 strcpy(gate_buf, pri->gate_addr);
158 err = slip_tramp(argv, sfd);
161 printk(UM_KERN_ERR "slip_tramp failed - err = %d\n",
165 err = os_get_ifname(pri->slave, pri->name);
167 printk(UM_KERN_ERR "get_ifname failed, err = %d\n",
171 iter_addresses(pri->dev, open_addr, pri->name);
174 err = os_set_slip(sfd);
176 printk(UM_KERN_ERR "Failed to set slip discipline "
177 "encapsulation - err = %d\n", -err);
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(UM_KERN_ERR "slip_tramp failed - errno = %d\n", -err);
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 void slip_add_addr(unsigned char *addr, unsigned char *netmask,
225 struct slip_data *pri = data;
229 open_addr(addr, netmask, pri->name);
232 static void slip_del_addr(unsigned char *addr, unsigned char *netmask,
235 struct slip_data *pri = data;
239 close_addr(addr, netmask, pri->name);
242 const struct net_user_info slip_user_info = {
243 .init = slip_user_init,
247 .add_address = slip_add_addr,
248 .delete_address = slip_del_addr,
250 .max_packet = BUF_SIZE,