proc->thread stage 4: rework the VFS and DEVICE subsystems to take thread
[dragonfly.git] / sys / netproto / ncp / ncp_conn.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1999, Boris Popov
3 * 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
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: src/sys/netncp/ncp_conn.h,v 1.3 1999/12/29 04:46:15 peter Exp $
dadab5e9 33 * $DragonFly: src/sys/netproto/ncp/ncp_conn.h,v 1.3 2003/06/25 03:56:05 dillon Exp $
984263bc
MD
34 */
35#ifndef _NETNCP_NCP_CONN_H_
36#define _NETNCP_NCP_CONN_H_
37
38#ifdef INET
39#ifndef _NETINET_IN_H_
40#include <netinet/in.h>
41#endif
42#endif
43
44#ifdef IPX
45#ifndef _NETIPX_IPX_H_
46#include <netipx/ipx.h>
47#endif
48#endif
49
50#ifndef _SYS_SOCKET_H_
51#include <sys/socket.h>
52#endif
53
54/* type of transport we use */
55/*#define NCP_ON_IPX 0
56#define NCP_ON_TCP 1*/
57
58/* flags field in conn structure */
59#define NCPFL_SOCONN 0x01 /* socket layer is up */
60#define NCPFL_ATTACHED 0x02 /* ncp layer is up */
61#define NCPFL_LOGGED 0x04 /* logged in to server */
62#define NCPFL_INVALID 0x08 /* last request was not completed */
63#define NCPFL_INTR 0x10 /* interrupted call */
64#define NCPFL_RESTORING 0x20 /* trying to reconnect */
65#define NCPFL_PERMANENT 0x40 /* no way to kill conn, when this set */
66#define NCPFL_PRIMARY 0x80 /* have meaning only for owner */
67#define NCPFL_SIGNACTIVE 0x1000 /* packet signing active */
68#define NCPFL_SIGNWANTED 0x2000 /* signing should start */
69
70/* access mode for connection */
71#define NCPM_READ 0400 /* able to fetch conn params */
72#define NCPM_WRITE 0200 /* modify/close */
73#define NCPM_EXECUTE 0100 /* run requests */
74
75#define NCP_DEFAULT_OWNER ((uid_t)-1)
76#define NCP_DEFAULT_GROUP ((uid_t)-1)
77
78
79/* args used to create connection */
80#define ncp_conn_loginfo ncp_conn_args
81struct ncp_conn_args {
82 int opt;
83#define NCP_OPT_WDOG 1 /* need watch dog socket */
84#define NCP_OPT_MSG 2 /* need message socket */
85#define NCP_OPT_SIGN 4 /* signatures wanted */
86#define NCP_OPT_BIND 8 /* force bindery login */
87#define NCP_OPT_PERMANENT 0x10 /* only for refernce, completly ignored */
88#define NCP_OPT_NOUPCASEPASS 0x20 /* leave password as is */
89 int sig_level; /* wanted signature level */
90 char server[NCP_BINDERY_NAME_LEN+1];
91 char *user;
92 char *password;
93 u_int32_t objtype;
94 union {
95 struct sockaddr addr;
96#ifdef IPX
97 struct sockaddr_ipx ipxaddr;
98#endif
99#ifdef INET
100 struct sockaddr_in inaddr;
101#endif
102 } addr;
103 int timeout; /* ncp rq timeout */
104 int retry_count; /* counts to give an error */
105 uid_t owner; /* proposed owner of connection */
106 gid_t group; /* proposed group of connection */
107 mode_t access_mode; /* R/W - can do rq's, X - can see the conn */
108};
109
110#define ipxaddr addr.ipxaddr
111#define inaddr addr.inaddr
112#define saddr addr.addr
113
114/* user side structure to issue ncp calls */
115struct ncp_buf {
116 int rqsize; /* request size without ncp header */
117 int rpsize; /* reply size minus ncp header */
118 int cc; /* completion code */
119 int cs; /* connection state */
120 char packet[NCP_MAX_PACKET_SIZE];/* Here we prepare requests and receive replies */
121};
122
123/*
124 * Connection status, returned via sysctl(vfs.nwfs.connstat)
125 */
126struct ncp_conn_stat {
127 struct ncp_conn_args li;
128 int connRef;
129 int ref_cnt;
130 int connid;
131 int buffer_size;
132 int flags;
133 int sign_active;
134 uid_t owner;
135 gid_t group;
136 char user[NCP_MAXUSERNAMELEN+1];
137};
138
139#ifdef _KERNEL
140
141#ifndef LK_SHARED
142#include <sys/lock.h>
143#endif
144
145struct socket;
146struct u_cred;
147
148SLIST_HEAD(ncp_conn_head,ncp_conn);
149
150struct ncp_rq;
151struct ncp_conn;
152
153/*
154 * External and internal processes can reference connection only by handle.
155 * This gives us a freedom in maintance of underlying connections.
156 */
157struct ncp_handle {
158 SLIST_ENTRY(ncp_handle) nh_next;
159 int nh_id; /* handle id */
160 struct ncp_conn*nh_conn; /* which conn we are refernce */
dadab5e9 161 struct thread * nh_td; /* who owns the handle */
984263bc
MD
162 int nh_ref; /* one process can asquire many handles, but we return the one */
163};
164
165/*
166 * Describes any connection to server
167 */
168struct ncp_conn {
169 SLIST_ENTRY(ncp_conn) nc_next;
170 struct ncp_conn_args li;
171 struct ucred *nc_owner;
172 gid_t nc_group;
173 int flags;
174 int nc_id;
175 struct socket *ncp_so;
176 struct socket *wdg_so;
177 struct socket *msg_so;
178 struct socket *bc_so;
179 int ref_cnt; /* how many handles leased */
180 SLIST_HEAD(ncp_ref_hd,ncp_ref) ref_list;/* list of handles */
181 struct lock nc_lock; /* excl locks */
182 int nc_lwant; /* number of wanted locks */
dadab5e9 183 struct thread *td; /* thread currently operates */
984263bc
MD
184 struct ucred *ucred; /* usr currently operates */
185 struct ncp_rq *nc_rq; /* current request */
186 /* Fields used to process ncp requests */
187 int connid; /* assigned by server */
188 u_int8_t seq;
189 int buffer_size; /* Negotiated bufsize */
190 /* Fields used to make packet signatures */
191 u_int32_t sign_root[2];
192 u_int32_t sign_state[4]; /* md4 state */
193#ifdef NCPBURST
194 /* Fields used for packet bursting */
195 u_long bc_pktseq; /* raw packet sequence */
196 u_short bc_seq; /* burst sequence */
197 u_long bc_locid; /* local connection id */
198 u_long bc_remid; /* remote connection id */
199 u_long bc_pktsize; /* negotiated burst packet size */
200#endif
201};
202
203#define ncp_conn_signwanted(conn) ((conn)->flags & NCPFL_SIGNWANTED)
204#define ncp_conn_valid(conn) ((conn->flags & NCPFL_INVALID) == 0)
205#define ncp_conn_invalidate(conn) {conn->flags |= NCPFL_INVALID;}
206
207int ncp_conn_init(void);
dadab5e9 208int ncp_conn_alloc(struct thread *td,struct ucred *cred, struct ncp_conn **connid);
984263bc
MD
209int ncp_conn_free(struct ncp_conn *conn);
210int ncp_conn_access(struct ncp_conn *conn,struct ucred *cred,mode_t mode);
dadab5e9
MD
211int ncp_conn_lock(struct ncp_conn *conn,struct thread *td,struct ucred *cred,int mode);
212void ncp_conn_unlock(struct ncp_conn *conn,struct thread *td);
213int ncp_conn_assert_locked(struct ncp_conn *conn,char *checker,struct thread *td);
984263bc
MD
214/*int ncp_conn_ref(struct ncp_conn *conn, pid_t pid);
215int ncp_conn_rm_ref(struct ncp_conn *conn, pid_t pid, int force);
216void ncp_conn_list_rm_ref(pid_t pid);*/
dadab5e9 217int ncp_conn_getbyref(int connRef,struct thread *td,struct ucred *cred, int mode,
984263bc 218 struct ncp_conn **connpp);
dadab5e9 219int ncp_conn_getbyli(struct ncp_conn_loginfo *li,struct thread *td,struct ucred *cred,
984263bc
MD
220 int mode, struct ncp_conn **connpp);
221int ncp_conn_setprimary(struct ncp_conn *conn, int on);
dadab5e9
MD
222int ncp_conn_locklist(int flags, struct thread *td);
223void ncp_conn_unlocklist(struct thread *td);
224int ncp_conn_gethandle(struct ncp_conn *conn, struct thread *td, struct ncp_handle **handle);
225int ncp_conn_puthandle(struct ncp_handle *handle, struct thread *td, int force);
226int ncp_conn_findhandle(int connHandle, struct thread *td, struct ncp_handle **handle);
227int ncp_conn_getattached(struct ncp_conn_args *li,struct thread *td,struct ucred *cred,int mode, struct ncp_conn **connpp);
228int ncp_conn_putprochandles(struct thread *td);
984263bc
MD
229int ncp_conn_getinfo(struct ncp_conn *ncp, struct ncp_conn_stat *ncs);
230
231extern struct ncp_conn_head conn_list;
232extern int ncp_burst_enabled;
233
234#ifdef MALLOC_DECLARE
235MALLOC_DECLARE(M_NCPDATA);
236#endif
237
238#endif /* _KERNEL */
239#endif /* _NCP_CONN_H_ */