Skip to content

Commit 23db65f

Browse files
jtlaytonSteve French
authored andcommitted
cifs: add a smb_version_operations/values structures and a smb_version enum
We need a way to dispatch different operations for different versions. Behold the smb_version_operations/values structures. For now, those structures just hold the version enum value and nothing uses them. Eventually, we'll expand them to cover other operations/values as we change the callers to dispatch from here. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru>
1 parent 5249af3 commit 23db65f

5 files changed

Lines changed: 89 additions & 2 deletions

File tree

‎fs/cifs/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ obj-$(CONFIG_CIFS) += cifs.o
66
cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
77
link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \
88
cifs_unicode.o nterr.o xattr.o cifsencrypt.o \
9-
readdir.o ioctl.o sess.o export.o
9+
readdir.o ioctl.o sess.o export.o smb1ops.o
1010

1111
cifs-$(CONFIG_CIFS_ACL) += cifsacl.o
1212

‎fs/cifs/cifsfs.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
354354
struct sockaddr *srcaddr;
355355
srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
356356

357+
seq_printf(s, ",vers=%s", tcon->ses->server->vals->version_string);
357358
cifs_show_security(s, tcon->ses->server);
358359
cifs_show_cache_flavor(s, cifs_sb);
359360

‎fs/cifs/cifsglob.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ struct cifs_cred {
150150
*****************************************************************
151151
*/
152152

153+
enum smb_version {
154+
Smb_1 = 1,
155+
};
156+
157+
struct smb_version_operations {
158+
};
159+
160+
struct smb_version_values {
161+
char *version_string;
162+
};
163+
153164
struct smb_vol {
154165
char *username;
155166
char *password;
@@ -205,6 +216,8 @@ struct smb_vol {
205216
bool sockopt_tcp_nodelay:1;
206217
unsigned short int port;
207218
unsigned long actimeo; /* attribute cache timeout (jiffies) */
219+
struct smb_version_operations *ops;
220+
struct smb_version_values *vals;
208221
char *prepath;
209222
struct sockaddr_storage srcaddr; /* allow binding to a local IP */
210223
struct nls_table *local_nls;
@@ -242,6 +255,8 @@ struct TCP_Server_Info {
242255
int srv_count; /* reference counter */
243256
/* 15 character server name + 0x20 16th byte indicating type = srv */
244257
char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
258+
struct smb_version_operations *ops;
259+
struct smb_version_values *vals;
245260
enum statusEnum tcpStatus; /* what we think the status is */
246261
char *hostname; /* hostname portion of UNC string */
247262
struct socket *ssocket;
@@ -1069,4 +1084,8 @@ void cifs_oplock_break(struct work_struct *work);
10691084
extern const struct slow_work_ops cifs_oplock_break_ops;
10701085
extern struct workqueue_struct *cifsiod_wq;
10711086

1087+
/* Operations for different SMB versions */
1088+
#define SMB1_VERSION_STRING "1.0"
1089+
extern struct smb_version_operations smb1_operations;
1090+
extern struct smb_version_values smb1_values;
10721091
#endif /* _CIFS_GLOB_H */

‎fs/cifs/connect.c‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ enum {
102102
Opt_srcaddr, Opt_prefixpath,
103103
Opt_iocharset, Opt_sockopt,
104104
Opt_netbiosname, Opt_servern,
105-
Opt_ver, Opt_sec, Opt_cache,
105+
Opt_ver, Opt_vers, Opt_sec, Opt_cache,
106106

107107
/* Mount options to be ignored */
108108
Opt_ignore,
@@ -210,6 +210,7 @@ static const match_table_t cifs_mount_option_tokens = {
210210
{ Opt_netbiosname, "netbiosname=%s" },
211211
{ Opt_servern, "servern=%s" },
212212
{ Opt_ver, "ver=%s" },
213+
{ Opt_vers, "vers=%s" },
213214
{ Opt_sec, "sec=%s" },
214215
{ Opt_cache, "cache=%s" },
215216

@@ -275,6 +276,10 @@ static const match_table_t cifs_cacheflavor_tokens = {
275276
{ Opt_cache_err, NULL }
276277
};
277278

279+
static const match_table_t cifs_smb_version_tokens = {
280+
{ Smb_1, SMB1_VERSION_STRING },
281+
};
282+
278283
static int ip_connect(struct TCP_Server_Info *server);
279284
static int generic_ip_connect(struct TCP_Server_Info *server);
280285
static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
@@ -1224,6 +1229,23 @@ cifs_parse_cache_flavor(char *value, struct smb_vol *vol)
12241229
return 0;
12251230
}
12261231

1232+
static int
1233+
cifs_parse_smb_version(char *value, struct smb_vol *vol)
1234+
{
1235+
substring_t args[MAX_OPT_ARGS];
1236+
1237+
switch (match_token(value, cifs_smb_version_tokens, args)) {
1238+
case Smb_1:
1239+
vol->ops = &smb1_operations;
1240+
vol->vals = &smb1_values;
1241+
break;
1242+
default:
1243+
cERROR(1, "Unknown vers= option specified: %s", value);
1244+
return 1;
1245+
}
1246+
return 0;
1247+
}
1248+
12271249
static int
12281250
cifs_parse_mount_options(const char *mountdata, const char *devname,
12291251
struct smb_vol *vol)
@@ -1277,6 +1299,10 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
12771299

12781300
vol->actimeo = CIFS_DEF_ACTIMEO;
12791301

1302+
/* FIXME: add autonegotiation -- for now, SMB1 is default */
1303+
vol->ops = &smb1_operations;
1304+
vol->vals = &smb1_values;
1305+
12801306
if (!mountdata)
12811307
goto cifs_parse_mount_err;
12821308

@@ -1880,6 +1906,14 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
18801906
printk(KERN_WARNING "CIFS: Invalid version"
18811907
" specified\n");
18821908
goto cifs_parse_mount_err;
1909+
case Opt_vers:
1910+
string = match_strdup(args);
1911+
if (string == NULL)
1912+
goto out_nomem;
1913+
1914+
if (cifs_parse_smb_version(string, vol) != 0)
1915+
goto cifs_parse_mount_err;
1916+
break;
18831917
case Opt_sec:
18841918
string = match_strdup(args);
18851919
if (string == NULL)
@@ -2108,6 +2142,9 @@ match_security(struct TCP_Server_Info *server, struct smb_vol *vol)
21082142
static int match_server(struct TCP_Server_Info *server, struct sockaddr *addr,
21092143
struct smb_vol *vol)
21102144
{
2145+
if ((server->vals != vol->vals) || (server->ops != vol->ops))
2146+
return 0;
2147+
21112148
if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns))
21122149
return 0;
21132150

@@ -2230,6 +2267,8 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
22302267
goto out_err;
22312268
}
22322269

2270+
tcp_ses->ops = volume_info->ops;
2271+
tcp_ses->vals = volume_info->vals;
22332272
cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns));
22342273
tcp_ses->hostname = extract_hostname(volume_info->UNC);
22352274
if (IS_ERR(tcp_ses->hostname)) {
@@ -3636,6 +3675,7 @@ cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
36363675
if (cifs_parse_mount_options(mount_data, devname, volume_info))
36373676
return -EINVAL;
36383677

3678+
36393679
if (volume_info->nullauth) {
36403680
cFYI(1, "Anonymous login");
36413681
kfree(volume_info->username);

‎fs/cifs/smb1ops.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* SMB1 (CIFS) version specific operations
3+
*
4+
* Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
5+
*
6+
* This library is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License v2 as published
8+
* by the Free Software Foundation.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13+
* the GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
*/
19+
20+
#include "cifsglob.h"
21+
22+
struct smb_version_operations smb1_operations = {
23+
};
24+
25+
struct smb_version_values smb1_values = {
26+
.version_string = SMB1_VERSION_STRING,
27+
};

0 commit comments

Comments
 (0)