blob: f06cde4adf7167a35c30b2c37fad0066b55910e3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * ncp_fs_sb.h
4 *
5 * Copyright (C) 1995, 1996 by Volker Lendecke
6 *
7 */
8
9#ifndef _NCP_FS_SB
10#define _NCP_FS_SB
11
12#include <linux/types.h>
13#include <linux/ncp_mount.h>
14#include <linux/net.h>
Ingo Molnar8e3f9042006-03-23 03:00:43 -080015#include <linux/mutex.h>
Jens Axboef1970c72010-04-22 12:31:11 +020016#include <linux/backing-dev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/workqueue.h>
18
19#define NCP_DEFAULT_OPTIONS 0 /* 2 for packet signatures */
20
21struct sock;
22
Al Viro32c419d2011-01-12 17:37:47 -050023struct ncp_mount_data_kernel {
24 unsigned long flags; /* NCP_MOUNT_* flags */
25 unsigned int int_flags; /* internal flags */
26#define NCP_IMOUNT_LOGGEDIN_POSSIBLE 0x0001
Eric W. Biederman1ac7fd8192012-02-07 16:28:28 -080027 kuid_t mounted_uid; /* Who may umount() this filesystem? */
Al Viro32c419d2011-01-12 17:37:47 -050028 struct pid *wdog_pid; /* Who cares for our watchdog packets? */
29 unsigned int ncp_fd; /* The socket to the ncp port */
30 unsigned int time_out; /* How long should I wait after
31 sending a NCP request? */
32 unsigned int retry_count; /* And how often should I retry? */
33 unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
Eric W. Biederman1ac7fd8192012-02-07 16:28:28 -080034 kuid_t uid;
35 kgid_t gid;
Al Viro16767652012-05-19 09:54:29 -040036 umode_t file_mode;
37 umode_t dir_mode;
Al Viro32c419d2011-01-12 17:37:47 -050038 int info_fd;
39};
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041struct ncp_server {
Al Viro1dcddd42013-10-03 13:22:44 -040042 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 struct ncp_mount_data_kernel m; /* Nearly all of the mount data is of
44 interest for us later, so we store
45 it completely. */
46
47 __u8 name_space[NCP_NUMBER_OF_VOLUMES + 2];
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 struct socket *ncp_sock;/* ncp socket */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 struct socket *info_sock;
51
52 u8 sequence;
53 u8 task;
54 u16 connection; /* Remote connection number */
55
56 u8 completion; /* Status message from server */
57 u8 conn_status; /* Bit 4 = 1 ==> Server going down, no
58 requests allowed anymore.
59 Bit 0 = 1 ==> Server is down. */
60
61 int buffer_size; /* Negotiated bufsize */
62
63 int reply_size; /* Size of last reply */
64
65 int packet_size;
66 unsigned char *packet; /* Here we prepare requests and
67 receive replies */
Pierre Ossmanc5f93cf2007-02-19 11:34:43 +010068 unsigned char *txbuf; /* Storage for current request */
69 unsigned char *rxbuf; /* Storage for reply to current request */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 int lock; /* To prevent mismatch in protocols. */
Ingo Molnar8e3f9042006-03-23 03:00:43 -080072 struct mutex mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 int current_size; /* for packet preparation */
75 int has_subfunction;
76 int ncp_reply_size;
77
78 int root_setuped;
Petr Vandrovec2e54eb92010-09-27 01:47:33 +020079 struct mutex root_setup_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81 /* info for packet signing */
82 int sign_wanted; /* 1=Server needs signed packets */
83 int sign_active; /* 0=don't do signing, 1=do */
84 char sign_root[8]; /* generated from password and encr. key */
85 char sign_last[16];
86
87 /* Authentication info: NDS or BINDERY, username */
88 struct {
89 int auth_type;
90 size_t object_name_len;
91 void* object_name;
92 int object_type;
93 } auth;
94 /* Password info */
95 struct {
96 size_t len;
97 void* data;
98 } priv;
Petr Vandrovec2e54eb92010-09-27 01:47:33 +020099 struct rw_semaphore auth_rwsem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 /* nls info: codepage for volume and charset for I/O */
102 struct nls_table *nls_vol;
103 struct nls_table *nls_io;
104
105 /* maximum age in jiffies */
Petr Vandrovec2e54eb92010-09-27 01:47:33 +0200106 atomic_t dentry_ttl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* miscellaneous */
109 unsigned int flags;
110
111 spinlock_t requests_lock; /* Lock accesses to tx.requests, tx.creq and rcv.creq when STREAM mode */
112
David S. Miller676d2362014-04-11 16:15:36 -0400113 void (*data_ready)(struct sock* sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 void (*error_report)(struct sock* sk);
115 void (*write_space)(struct sock* sk); /* STREAM mode only */
116 struct {
117 struct work_struct tq; /* STREAM/DGRAM: data/error ready */
118 struct ncp_request_reply* creq; /* STREAM/DGRAM: awaiting reply from this request */
Ingo Molnar8e3f9042006-03-23 03:00:43 -0800119 struct mutex creq_mutex; /* DGRAM only: lock accesses to rcv.creq */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 unsigned int state; /* STREAM only: receiver state */
122 struct {
Eric Dumazetbc105022010-06-03 03:21:52 -0700123 __u32 magic __packed;
124 __u32 len __packed;
125 __u16 type __packed;
126 __u16 p1 __packed;
127 __u16 p2 __packed;
128 __u16 p3 __packed;
129 __u16 type2 __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 } buf; /* STREAM only: temporary buffer */
131 unsigned char* ptr; /* STREAM only: pointer to data */
132 size_t len; /* STREAM only: length of data to receive */
133 } rcv;
134 struct {
135 struct list_head requests; /* STREAM only: queued requests */
136 struct work_struct tq; /* STREAM only: transmitter ready */
137 struct ncp_request_reply* creq; /* STREAM only: currently transmitted entry */
138 } tx;
139 struct timer_list timeout_tm; /* DGRAM only: timeout timer */
140 struct work_struct timeout_tq; /* DGRAM only: associated queue, we run timers from process context */
141 int timeout_last; /* DGRAM only: current timeout length */
142 int timeout_retries; /* DGRAM only: retries left */
143 struct {
144 size_t len;
145 __u8 data[128];
146 } unexpected_packet;
147};
148
David Howellsc4028952006-11-22 14:57:56 +0000149extern void ncp_tcp_rcv_proc(struct work_struct *work);
150extern void ncp_tcp_tx_proc(struct work_struct *work);
151extern void ncpdgram_rcv_proc(struct work_struct *work);
152extern void ncpdgram_timeout_proc(struct work_struct *work);
Kees Cook9b5dfbd2017-08-29 21:00:21 -0700153extern void ncpdgram_timeout_call(struct timer_list *t);
David S. Miller676d2362014-04-11 16:15:36 -0400154extern void ncp_tcp_data_ready(struct sock* sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155extern void ncp_tcp_write_space(struct sock* sk);
156extern void ncp_tcp_error_report(struct sock* sk);
157
158#define NCP_FLAG_UTF8 1
159
160#define NCP_CLR_FLAG(server, flag) ((server)->flags &= ~(flag))
161#define NCP_SET_FLAG(server, flag) ((server)->flags |= (flag))
162#define NCP_IS_FLAG(server, flag) ((server)->flags & (flag))
163
164static inline int ncp_conn_valid(struct ncp_server *server)
165{
166 return ((server->conn_status & 0x11) == 0);
167}
168
169static inline void ncp_invalidate_conn(struct ncp_server *server)
170{
171 server->conn_status |= 0x01;
172}
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#endif