This source file includes following definitions.
- svr4_find_socket
- svr4_delete_socket
- svr4_add_socket
- svr4_sys_socket
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 #include <sys/param.h>
45 #include <sys/kernel.h>
46 #include <sys/systm.h>
47 #include <sys/queue.h>
48 #include <sys/mbuf.h>
49 #include <sys/file.h>
50 #include <sys/mount.h>
51 #include <sys/socket.h>
52 #include <sys/socketvar.h>
53 #include <sys/syscallargs.h>
54 #include <sys/un.h>
55 #include <sys/stat.h>
56
57 #include <compat/svr4/svr4_types.h>
58 #include <compat/svr4/svr4_util.h>
59 #include <compat/svr4/svr4_socket.h>
60 #include <compat/svr4/svr4_signal.h>
61 #include <compat/svr4/svr4_sockmod.h>
62 #include <compat/svr4/svr4_syscallargs.h>
63
64 struct svr4_sockcache_entry {
65 struct proc *p;
66 void *cookie;
67 struct sockaddr_un sock;
68 dev_t dev;
69 ino_t ino;
70 TAILQ_ENTRY(svr4_sockcache_entry) entries;
71 };
72
73 static TAILQ_HEAD(svr4_sockcache_head, svr4_sockcache_entry) svr4_head;
74 static int initialized = 0;
75
76 struct sockaddr_un *
77 svr4_find_socket(p, fp, dev, ino)
78 struct proc *p;
79 struct file *fp;
80 dev_t dev;
81 ino_t ino;
82 {
83 struct svr4_sockcache_entry *e;
84 void *cookie = ((struct socket *) fp->f_data)->so_internal;
85
86 if (!initialized) {
87 DPRINTF(("svr4_find_socket: uninitialized [%p,%d,%d]\n",
88 p, dev, ino));
89 TAILQ_INIT(&svr4_head);
90 initialized = 1;
91 return NULL;
92 }
93
94
95 DPRINTF(("svr4_find_socket: [%p,%d,%d]: ", p, dev, ino));
96 TAILQ_FOREACH(e, &svr4_head, entries)
97 if (e->p == p && e->dev == dev && e->ino == ino) {
98 #ifdef DIAGNOSTIC
99 if (e->cookie != NULL && e->cookie != cookie)
100 panic("svr4 socket cookie mismatch");
101 #endif
102 e->cookie = cookie;
103 DPRINTF(("%s\n", e->sock.sun_path));
104 return &e->sock;
105 }
106
107 DPRINTF(("not found\n"));
108 return NULL;
109 }
110
111
112 void
113 svr4_delete_socket(p, fp)
114 struct proc *p;
115 struct file *fp;
116 {
117 struct svr4_sockcache_entry *e;
118 void *cookie = ((struct socket *) fp->f_data)->so_internal;
119
120 if (!initialized) {
121 TAILQ_INIT(&svr4_head);
122 initialized = 1;
123 return;
124 }
125
126 TAILQ_FOREACH(e, &svr4_head, entries)
127 if (e->p == p && e->cookie == cookie) {
128 TAILQ_REMOVE(&svr4_head, e, entries);
129 DPRINTF(("svr4_delete_socket: %s [%p,%d,%d]\n",
130 e->sock.sun_path, p, e->dev, e->ino));
131 free(e, M_TEMP);
132 return;
133 }
134 }
135
136
137 int
138 svr4_add_socket(p, path, st)
139 struct proc *p;
140 const char *path;
141 struct stat *st;
142 {
143 struct svr4_sockcache_entry *e;
144 size_t len;
145 int error;
146
147 if (!initialized) {
148 TAILQ_INIT(&svr4_head);
149 initialized = 1;
150 }
151
152 e = malloc(sizeof(*e), M_TEMP, M_WAITOK);
153 e->cookie = NULL;
154 e->dev = st->st_dev;
155 e->ino = st->st_ino;
156 e->p = p;
157
158 if ((error = copyinstr(path, e->sock.sun_path,
159 sizeof(e->sock.sun_path), &len)) != 0) {
160 DPRINTF(("svr4_add_socket: copyinstr failed %d\n", error));
161 free(e, M_TEMP);
162 return error;
163 }
164
165 e->sock.sun_family = AF_UNIX;
166 e->sock.sun_len = len;
167
168 TAILQ_INSERT_HEAD(&svr4_head, e, entries);
169 DPRINTF(("svr4_add_socket: %s [%p,%d,%d]\n", e->sock.sun_path,
170 p, e->dev, e->ino));
171 return 0;
172 }
173
174
175 int
176 svr4_sys_socket(p, v, retval)
177 struct proc *p;
178 void *v;
179 register_t *retval;
180 {
181 struct svr4_sys_socket_args *uap = v;
182
183 switch (SCARG(uap, type)) {
184 case SVR4_SOCK_DGRAM:
185 SCARG(uap, type) = SOCK_DGRAM;
186 break;
187
188 case SVR4_SOCK_STREAM:
189 SCARG(uap, type) = SOCK_STREAM;
190 break;
191
192 case SVR4_SOCK_RAW:
193 SCARG(uap, type) = SOCK_RAW;
194 break;
195
196 case SVR4_SOCK_RDM:
197 SCARG(uap, type) = SOCK_RDM;
198 break;
199
200 case SVR4_SOCK_SEQPACKET:
201 SCARG(uap, type) = SOCK_SEQPACKET;
202 break;
203 default:
204 return EINVAL;
205 }
206 return sys_socket(p, uap, retval);
207 }