4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
29 * Functions called by the IO deamon (IOD).
30 * Here in the library to simplify testing.
41 #include <sys/byteorder.h>
42 #include <sys/types.h>
43 #include <sys/fcntl.h>
44 #include <sys/ioctl.h>
46 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <netinet/tcp.h>
50 #include <arpa/inet.h>
52 #include <netsmb/smb.h>
53 #include <netsmb/smb_lib.h>
54 #include <netsmb/netbios.h>
55 #include <netsmb/nb_lib.h>
56 #include <netsmb/smb_dev.h>
62 * Be the reader thread for this VC.
65 smb_iod_work(smb_ctx_t
*ctx
)
67 smbioc_ssn_work_t
*work
= &ctx
->ct_work
;
70 DPRINT("server: %s", ctx
->ct_srvname
);
72 /* Calle should have opened these */
73 if (ctx
->ct_tran_fd
== -1 || ctx
->ct_dev_fd
== -1) {
79 * This is the reader / reconnect loop.
81 * We could start with state "idle", but
82 * we know someone wants a connection to
83 * this server, so start in "vcactive".
85 * XXX: Add some syslog calls in here?
87 vcst
= SMBIOD_ST_VCACTIVE
;
94 * Wait for driver requests to arrive
95 * for this VC, then return here.
96 * Next state is normally RECONNECT.
98 DPRINT("state: idle");
99 if (ioctl(ctx
->ct_dev_fd
,
100 SMBIOC_IOD_IDLE
, &vcst
) == -1) {
102 DPRINT("ioc_idle: err %d", err
);
107 case SMBIOD_ST_RECONNECT
:
108 DPRINT("state: reconnect");
109 err
= smb_iod_connect(ctx
);
111 vcst
= SMBIOD_ST_VCACTIVE
;
114 DPRINT("_iod_connect: err %d", err
);
116 * If the error was EAUTH, retry is
117 * not likely to succeed either, so
118 * just exit this thread. The user
119 * will need to run smbutil to get
120 * a new thread with new auth info.
124 vcst
= SMBIOD_ST_RCFAILED
;
127 case SMBIOD_ST_RCFAILED
:
128 DPRINT("state: rcfailed");
130 * Reconnect failed. Kill off any
131 * requests waiting in the driver,
132 * then get ready to try again.
133 * Next state is normally IDLE.
135 if (ioctl(ctx
->ct_dev_fd
,
136 SMBIOC_IOD_RCFAIL
, &vcst
) == -1) {
138 DPRINT("ioc_rcfail: err %d", err
);
143 case SMBIOD_ST_VCACTIVE
:
144 DPRINT("state: active");
145 if (ioctl(ctx
->ct_dev_fd
,
146 SMBIOC_IOD_WORK
, work
) == -1) {
148 DPRINT("ioc_work: err %d", err
);
151 vcst
= work
->wk_out_state
;
153 * Go ahead and close the transport now,
154 * rather than wait until reconnect to
157 close(ctx
->ct_tran_fd
);
158 ctx
->ct_tran_fd
= -1;
162 DPRINT("state: dead");
167 DPRINT("state: BAD(%d)", vcst
);
174 if (ctx
->ct_tran_fd
!= -1) {
175 close(ctx
->ct_tran_fd
);
176 ctx
->ct_tran_fd
= -1;
178 if (ctx
->ct_dev_fd
!= -1) {
179 close(ctx
->ct_dev_fd
);