~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/um/drivers/slirp_user.c

Version: ~ [ linux-5.2 ] ~ [ linux-5.1.16 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.57 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.132 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.184 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.184 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.69 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3  * Licensed under the GPL.
  4  */
  5 
  6 #include <unistd.h>
  7 #include <errno.h>
  8 #include <string.h>
  9 #include <sys/wait.h>
 10 #include <net_user.h>
 11 #include <os.h>
 12 #include "slirp.h"
 13 
 14 static int slirp_user_init(void *data, void *dev)
 15 {
 16         struct slirp_data *pri = data;
 17 
 18         pri->dev = dev;
 19         return 0;
 20 }
 21 
 22 struct slirp_pre_exec_data {
 23         int stdin_fd;
 24         int stdout_fd;
 25 };
 26 
 27 static void slirp_pre_exec(void *arg)
 28 {
 29         struct slirp_pre_exec_data *data = arg;
 30 
 31         if (data->stdin_fd != -1)
 32                 dup2(data->stdin_fd, 0);
 33         if (data->stdout_fd != -1)
 34                 dup2(data->stdout_fd, 1);
 35 }
 36 
 37 static int slirp_tramp(char **argv, int fd)
 38 {
 39         struct slirp_pre_exec_data pe_data;
 40         int pid;
 41 
 42         pe_data.stdin_fd = fd;
 43         pe_data.stdout_fd = fd;
 44         pid = run_helper(slirp_pre_exec, &pe_data, argv);
 45 
 46         return pid;
 47 }
 48 
 49 static int slirp_open(void *data)
 50 {
 51         struct slirp_data *pri = data;
 52         int fds[2], pid, err;
 53 
 54         err = os_pipe(fds, 1, 1);
 55         if (err)
 56                 return err;
 57 
 58         err = slirp_tramp(pri->argw.argv, fds[1]);
 59         if (err < 0) {
 60                 printk(UM_KERN_ERR "slirp_tramp failed - errno = %d\n", -err);
 61                 goto out;
 62         }
 63         pid = err;
 64 
 65         pri->slave = fds[1];
 66         pri->slip.pos = 0;
 67         pri->slip.esc = 0;
 68         pri->pid = err;
 69 
 70         return fds[0];
 71 out:
 72         close(fds[0]);
 73         close(fds[1]);
 74         return err;
 75 }
 76 
 77 static void slirp_close(int fd, void *data)
 78 {
 79         struct slirp_data *pri = data;
 80         int err;
 81 
 82         close(fd);
 83         close(pri->slave);
 84 
 85         pri->slave = -1;
 86 
 87         if (pri->pid<1) {
 88                 printk(UM_KERN_ERR "slirp_close: no child process to shut "
 89                        "down\n");
 90                 return;
 91         }
 92 
 93 #if 0
 94         if (kill(pri->pid, SIGHUP)<0) {
 95                 printk(UM_KERN_ERR "slirp_close: sending hangup to %d failed "
 96                        "(%d)\n", pri->pid, errno);
 97         }
 98 #endif
 99         err = helper_wait(pri->pid);
100         if (err < 0)
101                 return;
102 
103         pri->pid = -1;
104 }
105 
106 int slirp_user_read(int fd, void *buf, int len, struct slirp_data *pri)
107 {
108         return slip_proto_read(fd, buf, len, &pri->slip);
109 }
110 
111 int slirp_user_write(int fd, void *buf, int len, struct slirp_data *pri)
112 {
113         return slip_proto_write(fd, buf, len, &pri->slip);
114 }
115 
116 const struct net_user_info slirp_user_info = {
117         .init           = slirp_user_init,
118         .open           = slirp_open,
119         .close          = slirp_close,
120         .remove         = NULL,
121         .add_address    = NULL,
122         .delete_address = NULL,
123         .mtu            = BUF_SIZE,
124         .max_packet     = BUF_SIZE,
125 };
126 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp