sys_socket.c (4e27d36d38f4c3b12bcc1855c5d41527d08d1ce0) sys_socket.c (9696feebe2320c9976607df4090f91a34c6549c3)
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 20 unchanged lines hidden (view full) ---

29 * @(#)sys_socket.c 8.1 (Berkeley) 6/10/93
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD$");
34
35#include <sys/param.h>
36#include <sys/systm.h>
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 20 unchanged lines hidden (view full) ---

29 * @(#)sys_socket.c 8.1 (Berkeley) 6/10/93
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD$");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/domain.h>
37#include <sys/file.h>
38#include <sys/filedesc.h>
38#include <sys/file.h>
39#include <sys/filedesc.h>
40#include <sys/malloc.h>
39#include <sys/proc.h>
40#include <sys/protosw.h>
41#include <sys/sigio.h>
42#include <sys/signal.h>
43#include <sys/signalvar.h>
44#include <sys/socket.h>
45#include <sys/socketvar.h>
46#include <sys/filio.h> /* XXX */
47#include <sys/sockio.h>
48#include <sys/stat.h>
49#include <sys/uio.h>
50#include <sys/ucred.h>
41#include <sys/proc.h>
42#include <sys/protosw.h>
43#include <sys/sigio.h>
44#include <sys/signal.h>
45#include <sys/signalvar.h>
46#include <sys/socket.h>
47#include <sys/socketvar.h>
48#include <sys/filio.h> /* XXX */
49#include <sys/sockio.h>
50#include <sys/stat.h>
51#include <sys/uio.h>
52#include <sys/ucred.h>
53#include <sys/un.h>
54#include <sys/unpcb.h>
55#include <sys/user.h>
51
52#include <net/if.h>
53#include <net/if_var.h>
54#include <net/route.h>
55#include <net/vnet.h>
56
56
57#include <net/if.h>
58#include <net/if_var.h>
59#include <net/route.h>
60#include <net/vnet.h>
61
62#include <netinet/in.h>
63#include <netinet/in_pcb.h>
64
57#include <security/mac/mac_framework.h>
58
59static fo_rdwr_t soo_read;
60static fo_rdwr_t soo_write;
61static fo_ioctl_t soo_ioctl;
62static fo_poll_t soo_poll;
63extern fo_kqfilter_t soo_kqfilter;
64static fo_stat_t soo_stat;
65static fo_close_t soo_close;
65#include <security/mac/mac_framework.h>
66
67static fo_rdwr_t soo_read;
68static fo_rdwr_t soo_write;
69static fo_ioctl_t soo_ioctl;
70static fo_poll_t soo_poll;
71extern fo_kqfilter_t soo_kqfilter;
72static fo_stat_t soo_stat;
73static fo_close_t soo_close;
74static fo_fill_kinfo_t soo_fill_kinfo;
66
67struct fileops socketops = {
68 .fo_read = soo_read,
69 .fo_write = soo_write,
70 .fo_truncate = invfo_truncate,
71 .fo_ioctl = soo_ioctl,
72 .fo_poll = soo_poll,
73 .fo_kqfilter = soo_kqfilter,
74 .fo_stat = soo_stat,
75 .fo_close = soo_close,
76 .fo_chmod = invfo_chmod,
77 .fo_chown = invfo_chown,
78 .fo_sendfile = invfo_sendfile,
75
76struct fileops socketops = {
77 .fo_read = soo_read,
78 .fo_write = soo_write,
79 .fo_truncate = invfo_truncate,
80 .fo_ioctl = soo_ioctl,
81 .fo_poll = soo_poll,
82 .fo_kqfilter = soo_kqfilter,
83 .fo_stat = soo_stat,
84 .fo_close = soo_close,
85 .fo_chmod = invfo_chmod,
86 .fo_chown = invfo_chown,
87 .fo_sendfile = invfo_sendfile,
88 .fo_fill_kinfo = soo_fill_kinfo,
79 .fo_flags = DFLAG_PASSABLE
80};
81
82static int
83soo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
84 int flags, struct thread *td)
85{
86 struct socket *so = fp->f_data;

--- 201 unchanged lines hidden (view full) ---

288 so = fp->f_data;
289 fp->f_ops = &badfileops;
290 fp->f_data = NULL;
291
292 if (so)
293 error = soclose(so);
294 return (error);
295}
89 .fo_flags = DFLAG_PASSABLE
90};
91
92static int
93soo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
94 int flags, struct thread *td)
95{
96 struct socket *so = fp->f_data;

--- 201 unchanged lines hidden (view full) ---

298 so = fp->f_data;
299 fp->f_ops = &badfileops;
300 fp->f_data = NULL;
301
302 if (so)
303 error = soclose(so);
304 return (error);
305}
306
307static int
308soo_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
309{
310 struct sockaddr *sa;
311 struct inpcb *inpcb;
312 struct unpcb *unpcb;
313 struct socket *so;
314 int error;
315
316 kif->kf_type = KF_TYPE_SOCKET;
317 so = fp->f_data;
318 kif->kf_sock_domain = so->so_proto->pr_domain->dom_family;
319 kif->kf_sock_type = so->so_type;
320 kif->kf_sock_protocol = so->so_proto->pr_protocol;
321 kif->kf_un.kf_sock.kf_sock_pcb = (uintptr_t)so->so_pcb;
322 switch (kif->kf_sock_domain) {
323 case AF_INET:
324 case AF_INET6:
325 if (kif->kf_sock_protocol == IPPROTO_TCP) {
326 if (so->so_pcb != NULL) {
327 inpcb = (struct inpcb *)(so->so_pcb);
328 kif->kf_un.kf_sock.kf_sock_inpcb =
329 (uintptr_t)inpcb->inp_ppcb;
330 }
331 }
332 break;
333 case AF_UNIX:
334 if (so->so_pcb != NULL) {
335 unpcb = (struct unpcb *)(so->so_pcb);
336 if (unpcb->unp_conn) {
337 kif->kf_un.kf_sock.kf_sock_unpconn =
338 (uintptr_t)unpcb->unp_conn;
339 kif->kf_un.kf_sock.kf_sock_rcv_sb_state =
340 so->so_rcv.sb_state;
341 kif->kf_un.kf_sock.kf_sock_snd_sb_state =
342 so->so_snd.sb_state;
343 }
344 }
345 break;
346 }
347 error = so->so_proto->pr_usrreqs->pru_sockaddr(so, &sa);
348 if (error == 0 && sa->sa_len <= sizeof(kif->kf_sa_local)) {
349 bcopy(sa, &kif->kf_sa_local, sa->sa_len);
350 free(sa, M_SONAME);
351 }
352 error = so->so_proto->pr_usrreqs->pru_peeraddr(so, &sa);
353 if (error == 0 && sa->sa_len <= sizeof(kif->kf_sa_peer)) {
354 bcopy(sa, &kif->kf_sa_peer, sa->sa_len);
355 free(sa, M_SONAME);
356 }
357 strncpy(kif->kf_path, so->so_proto->pr_domain->dom_name,
358 sizeof(kif->kf_path));
359 return (0);
360}