xref: /illumos-gate/usr/src/uts/common/ktli/t_kunbind.c (revision 2d6eb4a5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 /*
41  * Kernel TLI-like function to unbind a transport endpoint
42  * to an address.
43  *
44  * Returns 0 on success and ret is set if non-NULL,
45  * else positive error code.
46  */
47 
48 #include <sys/param.h>
49 #include <sys/types.h>
50 #include <sys/proc.h>
51 #include <sys/file.h>
52 #include <sys/user.h>
53 #include <sys/errno.h>
54 #include <sys/stream.h>
55 #include <sys/strsubr.h>
56 #include <sys/ioctl.h>
57 #include <sys/stropts.h>
58 #include <sys/vnode.h>
59 #include <sys/tihdr.h>
60 #include <sys/timod.h>
61 #include <sys/tiuser.h>
62 #include <sys/t_kuser.h>
63 #include <sys/kmem.h>
64 #include <sys/sysmacros.h>
65 
66 
67 int
t_kunbind(TIUSER * tiptr)68 t_kunbind(TIUSER *tiptr)
69 {
70 	struct T_unbind_req	*unbind_req;
71 	struct T_ok_ack		*ok_ack;
72 	int			unbindsz;
73 	vnode_t			*vp;
74 	file_t			*fp;
75 	char			*buf;
76 	struct strioctl		strioc;
77 	int			retval;
78 	int			error;
79 
80 	error = 0;
81 	retval = 0;
82 	fp = tiptr->fp;
83 	vp = fp->f_vnode;
84 
85 	/*
86 	 * send the ioctl request and wait
87 	 * for a reply.
88 	 */
89 	unbindsz = MAX(TUNBINDREQSZ, TOKACKSZ);
90 	buf = kmem_alloc(unbindsz, KM_SLEEP);
91 	/* LINTED pointer alignment */
92 	unbind_req = (struct T_unbind_req *)buf;
93 	unbind_req->PRIM_type = T_UNBIND_REQ;
94 
95 	strioc.ic_cmd = TI_UNBIND;
96 	strioc.ic_timout = 0;
97 	strioc.ic_dp = buf;
98 	strioc.ic_len = (int)TUNBINDREQSZ;
99 
100 	error = strdoioctl(vp->v_stream, &strioc, FNATIVE, K_TO_K, CRED(),
101 	    &retval);
102 	if (error)
103 		goto badbind;
104 
105 	if (retval) {
106 		if ((retval & 0xff) == TSYSERR)
107 			error = (retval >> 8) & 0xff;
108 		else
109 			error = t_tlitosyserr(retval & 0xff);
110 		goto badbind;
111 	}
112 
113 	/* LINTED pointer alignment */
114 	ok_ack = (struct T_ok_ack *)strioc.ic_dp;
115 	if (strioc.ic_len < TOKACKSZ ||
116 	    ok_ack->PRIM_type != T_OK_ACK ||
117 	    ok_ack->CORRECT_prim != T_UNBIND_REQ)
118 		error = EIO;
119 
120 badbind:
121 	kmem_free(buf, unbindsz);
122 	return (error);
123 }
124