Skip to content

Commit

Permalink
cifs: add a smb_version_operations/values structures and a smb_versio…
Browse files Browse the repository at this point in the history
…n 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 <[email protected]>
Signed-off-by: Pavel Shilovsky <[email protected]>
  • Loading branch information
jtlayton authored and Steve French committed May 17, 2012
1 parent 5249af3 commit 23db65f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fs/cifs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ obj-$(CONFIG_CIFS) += cifs.o
cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \
cifs_unicode.o nterr.o xattr.o cifsencrypt.o \
readdir.o ioctl.o sess.o export.o
readdir.o ioctl.o sess.o export.o smb1ops.o

cifs-$(CONFIG_CIFS_ACL) += cifsacl.o

Expand Down
1 change: 1 addition & 0 deletions fs/cifs/cifsfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
struct sockaddr *srcaddr;
srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;

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

Expand Down
19 changes: 19 additions & 0 deletions fs/cifs/cifsglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ struct cifs_cred {
*****************************************************************
*/

enum smb_version {
Smb_1 = 1,
};

struct smb_version_operations {
};

struct smb_version_values {
char *version_string;
};

struct smb_vol {
char *username;
char *password;
Expand Down Expand Up @@ -205,6 +216,8 @@ struct smb_vol {
bool sockopt_tcp_nodelay:1;
unsigned short int port;
unsigned long actimeo; /* attribute cache timeout (jiffies) */
struct smb_version_operations *ops;
struct smb_version_values *vals;
char *prepath;
struct sockaddr_storage srcaddr; /* allow binding to a local IP */
struct nls_table *local_nls;
Expand Down Expand Up @@ -242,6 +255,8 @@ struct TCP_Server_Info {
int srv_count; /* reference counter */
/* 15 character server name + 0x20 16th byte indicating type = srv */
char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
struct smb_version_operations *ops;
struct smb_version_values *vals;
enum statusEnum tcpStatus; /* what we think the status is */
char *hostname; /* hostname portion of UNC string */
struct socket *ssocket;
Expand Down Expand Up @@ -1069,4 +1084,8 @@ void cifs_oplock_break(struct work_struct *work);
extern const struct slow_work_ops cifs_oplock_break_ops;
extern struct workqueue_struct *cifsiod_wq;

/* Operations for different SMB versions */
#define SMB1_VERSION_STRING "1.0"
extern struct smb_version_operations smb1_operations;
extern struct smb_version_values smb1_values;
#endif /* _CIFS_GLOB_H */
42 changes: 41 additions & 1 deletion fs/cifs/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ enum {
Opt_srcaddr, Opt_prefixpath,
Opt_iocharset, Opt_sockopt,
Opt_netbiosname, Opt_servern,
Opt_ver, Opt_sec, Opt_cache,
Opt_ver, Opt_vers, Opt_sec, Opt_cache,

/* Mount options to be ignored */
Opt_ignore,
Expand Down Expand Up @@ -210,6 +210,7 @@ static const match_table_t cifs_mount_option_tokens = {
{ Opt_netbiosname, "netbiosname=%s" },
{ Opt_servern, "servern=%s" },
{ Opt_ver, "ver=%s" },
{ Opt_vers, "vers=%s" },
{ Opt_sec, "sec=%s" },
{ Opt_cache, "cache=%s" },

Expand Down Expand Up @@ -275,6 +276,10 @@ static const match_table_t cifs_cacheflavor_tokens = {
{ Opt_cache_err, NULL }
};

static const match_table_t cifs_smb_version_tokens = {
{ Smb_1, SMB1_VERSION_STRING },
};

static int ip_connect(struct TCP_Server_Info *server);
static int generic_ip_connect(struct TCP_Server_Info *server);
static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
Expand Down Expand Up @@ -1224,6 +1229,23 @@ cifs_parse_cache_flavor(char *value, struct smb_vol *vol)
return 0;
}

static int
cifs_parse_smb_version(char *value, struct smb_vol *vol)
{
substring_t args[MAX_OPT_ARGS];

switch (match_token(value, cifs_smb_version_tokens, args)) {
case Smb_1:
vol->ops = &smb1_operations;
vol->vals = &smb1_values;
break;
default:
cERROR(1, "Unknown vers= option specified: %s", value);
return 1;
}
return 0;
}

static int
cifs_parse_mount_options(const char *mountdata, const char *devname,
struct smb_vol *vol)
Expand Down Expand Up @@ -1277,6 +1299,10 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,

vol->actimeo = CIFS_DEF_ACTIMEO;

/* FIXME: add autonegotiation -- for now, SMB1 is default */
vol->ops = &smb1_operations;
vol->vals = &smb1_values;

if (!mountdata)
goto cifs_parse_mount_err;

Expand Down Expand Up @@ -1880,6 +1906,14 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
printk(KERN_WARNING "CIFS: Invalid version"
" specified\n");
goto cifs_parse_mount_err;
case Opt_vers:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;

if (cifs_parse_smb_version(string, vol) != 0)
goto cifs_parse_mount_err;
break;
case Opt_sec:
string = match_strdup(args);
if (string == NULL)
Expand Down Expand Up @@ -2108,6 +2142,9 @@ match_security(struct TCP_Server_Info *server, struct smb_vol *vol)
static int match_server(struct TCP_Server_Info *server, struct sockaddr *addr,
struct smb_vol *vol)
{
if ((server->vals != vol->vals) || (server->ops != vol->ops))
return 0;

if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns))
return 0;

Expand Down Expand Up @@ -2230,6 +2267,8 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
goto out_err;
}

tcp_ses->ops = volume_info->ops;
tcp_ses->vals = volume_info->vals;
cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns));
tcp_ses->hostname = extract_hostname(volume_info->UNC);
if (IS_ERR(tcp_ses->hostname)) {
Expand Down Expand Up @@ -3636,6 +3675,7 @@ cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
if (cifs_parse_mount_options(mount_data, devname, volume_info))
return -EINVAL;


if (volume_info->nullauth) {
cFYI(1, "Anonymous login");
kfree(volume_info->username);
Expand Down
27 changes: 27 additions & 0 deletions fs/cifs/smb1ops.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* SMB1 (CIFS) version specific operations
*
* Copyright (c) 2012, Jeff Layton <[email protected]>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License v2 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "cifsglob.h"

struct smb_version_operations smb1_operations = {
};

struct smb_version_values smb1_values = {
.version_string = SMB1_VERSION_STRING,
};

0 comments on commit 23db65f

Please sign in to comment.