Skip to content

Commit 00498b9

Browse files
committed
libceph: introduce connection modes and ms_mode option
msgr2 supports two connection modes: crc (plain) and secure (on-wire encryption). Connection mode is picked by server based on input from client. Introduce ms_mode option: ms_mode=legacy - msgr1 (default) ms_mode=crc - crc mode, if denied fail ms_mode=secure - secure mode, if denied fail ms_mode=prefer-crc - crc mode, if denied agree to secure mode ms_mode=prefer-secure - secure mode, if denied agree to crc mode ms_mode affects all connections, we don't separate connections to mons like it's done in userspace with ms_client_mode vs ms_mon_client_mode. For now the default is legacy, to be flipped to prefer-crc after some time. Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 313771e commit 00498b9

File tree

7 files changed

+100
-8
lines changed

7 files changed

+100
-8
lines changed

include/linux/ceph/auth.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ struct ceph_auth_client {
9898
const struct ceph_crypto_key *key; /* our secret key */
9999
unsigned want_keys; /* which services we want */
100100

101+
int preferred_mode; /* CEPH_CON_MODE_* */
102+
int fallback_mode; /* ditto */
103+
101104
struct mutex mutex;
102105
};
103106

104-
extern struct ceph_auth_client *ceph_auth_init(const char *name,
105-
const struct ceph_crypto_key *key);
107+
struct ceph_auth_client *ceph_auth_init(const char *name,
108+
const struct ceph_crypto_key *key,
109+
const int *con_modes);
106110
extern void ceph_auth_destroy(struct ceph_auth_client *ac);
107111

108112
extern void ceph_auth_reset(struct ceph_auth_client *ac);

include/linux/ceph/ceph_fs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,15 @@ struct ceph_dir_layout {
9393
#define CEPH_AUTH_NONE 0x1
9494
#define CEPH_AUTH_CEPHX 0x2
9595

96+
/* msgr2 protocol modes */
97+
#define CEPH_CON_MODE_UNKNOWN 0x0
98+
#define CEPH_CON_MODE_CRC 0x1
99+
#define CEPH_CON_MODE_SECURE 0x2
100+
96101
#define CEPH_AUTH_UID_DEFAULT ((__u64) -1)
97102

98103
const char *ceph_auth_proto_name(int proto);
104+
const char *ceph_con_mode_name(int mode);
99105

100106
/*********************************************
101107
* message layer

include/linux/ceph/libceph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct ceph_options {
5353
unsigned long osd_keepalive_timeout; /* jiffies */
5454
unsigned long osd_request_timeout; /* jiffies */
5555
u32 read_from_replica; /* CEPH_OSD_FLAG_BALANCE/LOCALIZE_READS */
56+
int con_modes[2]; /* CEPH_CON_MODE_* */
5657

5758
/*
5859
* any type that can't be simply compared or doesn't need

net/ceph/auth.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ static int init_protocol(struct ceph_auth_client *ac, int proto)
3939
/*
4040
* setup, teardown.
4141
*/
42-
struct ceph_auth_client *ceph_auth_init(const char *name, const struct ceph_crypto_key *key)
42+
struct ceph_auth_client *ceph_auth_init(const char *name,
43+
const struct ceph_crypto_key *key,
44+
const int *con_modes)
4345
{
4446
struct ceph_auth_client *ac;
4547
int ret;
4648

47-
dout("auth_init name '%s'\n", name);
48-
4949
ret = -ENOMEM;
5050
ac = kzalloc(sizeof(*ac), GFP_NOFS);
5151
if (!ac)
@@ -57,8 +57,12 @@ struct ceph_auth_client *ceph_auth_init(const char *name, const struct ceph_cryp
5757
ac->name = name;
5858
else
5959
ac->name = CEPH_AUTH_NAME_DEFAULT;
60-
dout("auth_init name %s\n", ac->name);
6160
ac->key = key;
61+
ac->preferred_mode = con_modes[0];
62+
ac->fallback_mode = con_modes[1];
63+
64+
dout("%s name '%s' preferred_mode %d fallback_mode %d\n", __func__,
65+
ac->name, ac->preferred_mode, ac->fallback_mode);
6266
return ac;
6367

6468
out:

net/ceph/ceph_common.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ enum {
265265
Opt_ip,
266266
Opt_crush_location,
267267
Opt_read_from_replica,
268+
Opt_ms_mode,
268269
/* string args above */
269270
Opt_share,
270271
Opt_crc,
@@ -287,6 +288,23 @@ static const struct constant_table ceph_param_read_from_replica[] = {
287288
{}
288289
};
289290

291+
enum ceph_ms_mode {
292+
Opt_ms_mode_legacy,
293+
Opt_ms_mode_crc,
294+
Opt_ms_mode_secure,
295+
Opt_ms_mode_prefer_crc,
296+
Opt_ms_mode_prefer_secure
297+
};
298+
299+
static const struct constant_table ceph_param_ms_mode[] = {
300+
{"legacy", Opt_ms_mode_legacy},
301+
{"crc", Opt_ms_mode_crc},
302+
{"secure", Opt_ms_mode_secure},
303+
{"prefer-crc", Opt_ms_mode_prefer_crc},
304+
{"prefer-secure", Opt_ms_mode_prefer_secure},
305+
{}
306+
};
307+
290308
static const struct fs_parameter_spec ceph_parameters[] = {
291309
fsparam_flag ("abort_on_full", Opt_abort_on_full),
292310
fsparam_flag_no ("cephx_require_signatures", Opt_cephx_require_signatures),
@@ -305,6 +323,8 @@ static const struct fs_parameter_spec ceph_parameters[] = {
305323
fs_param_deprecated, NULL),
306324
fsparam_enum ("read_from_replica", Opt_read_from_replica,
307325
ceph_param_read_from_replica),
326+
fsparam_enum ("ms_mode", Opt_ms_mode,
327+
ceph_param_ms_mode),
308328
fsparam_string ("secret", Opt_secret),
309329
fsparam_flag_no ("share", Opt_share),
310330
fsparam_flag_no ("tcp_nodelay", Opt_tcp_nodelay),
@@ -333,6 +353,8 @@ struct ceph_options *ceph_alloc_options(void)
333353
opt->osd_idle_ttl = CEPH_OSD_IDLE_TTL_DEFAULT;
334354
opt->osd_request_timeout = CEPH_OSD_REQUEST_TIMEOUT_DEFAULT;
335355
opt->read_from_replica = CEPH_READ_FROM_REPLICA_DEFAULT;
356+
opt->con_modes[0] = CEPH_CON_MODE_UNKNOWN;
357+
opt->con_modes[1] = CEPH_CON_MODE_UNKNOWN;
336358
return opt;
337359
}
338360
EXPORT_SYMBOL(ceph_alloc_options);
@@ -503,6 +525,32 @@ int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
503525
BUG();
504526
}
505527
break;
528+
case Opt_ms_mode:
529+
switch (result.uint_32) {
530+
case Opt_ms_mode_legacy:
531+
opt->con_modes[0] = CEPH_CON_MODE_UNKNOWN;
532+
opt->con_modes[1] = CEPH_CON_MODE_UNKNOWN;
533+
break;
534+
case Opt_ms_mode_crc:
535+
opt->con_modes[0] = CEPH_CON_MODE_CRC;
536+
opt->con_modes[1] = CEPH_CON_MODE_UNKNOWN;
537+
break;
538+
case Opt_ms_mode_secure:
539+
opt->con_modes[0] = CEPH_CON_MODE_SECURE;
540+
opt->con_modes[1] = CEPH_CON_MODE_UNKNOWN;
541+
break;
542+
case Opt_ms_mode_prefer_crc:
543+
opt->con_modes[0] = CEPH_CON_MODE_CRC;
544+
opt->con_modes[1] = CEPH_CON_MODE_SECURE;
545+
break;
546+
case Opt_ms_mode_prefer_secure:
547+
opt->con_modes[0] = CEPH_CON_MODE_SECURE;
548+
opt->con_modes[1] = CEPH_CON_MODE_CRC;
549+
break;
550+
default:
551+
BUG();
552+
}
553+
break;
506554

507555
case Opt_osdtimeout:
508556
warn_plog(&log, "Ignoring osdtimeout");
@@ -616,6 +664,21 @@ int ceph_print_client_options(struct seq_file *m, struct ceph_client *client,
616664
} else if (opt->read_from_replica == CEPH_OSD_FLAG_LOCALIZE_READS) {
617665
seq_puts(m, "read_from_replica=localize,");
618666
}
667+
if (opt->con_modes[0] != CEPH_CON_MODE_UNKNOWN) {
668+
if (opt->con_modes[0] == CEPH_CON_MODE_CRC &&
669+
opt->con_modes[1] == CEPH_CON_MODE_UNKNOWN) {
670+
seq_puts(m, "ms_mode=crc,");
671+
} else if (opt->con_modes[0] == CEPH_CON_MODE_SECURE &&
672+
opt->con_modes[1] == CEPH_CON_MODE_UNKNOWN) {
673+
seq_puts(m, "ms_mode=secure,");
674+
} else if (opt->con_modes[0] == CEPH_CON_MODE_CRC &&
675+
opt->con_modes[1] == CEPH_CON_MODE_SECURE) {
676+
seq_puts(m, "ms_mode=prefer-crc,");
677+
} else if (opt->con_modes[0] == CEPH_CON_MODE_SECURE &&
678+
opt->con_modes[1] == CEPH_CON_MODE_CRC) {
679+
seq_puts(m, "ms_mode=prefer-secure,");
680+
}
681+
}
619682

620683
if (opt->flags & CEPH_OPT_FSID)
621684
seq_printf(m, "fsid=%pU,", &opt->fsid);

net/ceph/ceph_strings.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ const char *ceph_auth_proto_name(int proto)
3232
}
3333
}
3434

35+
const char *ceph_con_mode_name(int mode)
36+
{
37+
switch (mode) {
38+
case CEPH_CON_MODE_UNKNOWN:
39+
return "unknown";
40+
case CEPH_CON_MODE_CRC:
41+
return "crc";
42+
case CEPH_CON_MODE_SECURE:
43+
return "secure";
44+
default:
45+
return "???";
46+
}
47+
}
48+
3549
const char *ceph_osd_op_name(int op)
3650
{
3751
switch (op) {

net/ceph/mon_client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,8 +1156,8 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
11561156

11571157
/* connection */
11581158
/* authentication */
1159-
monc->auth = ceph_auth_init(cl->options->name,
1160-
cl->options->key);
1159+
monc->auth = ceph_auth_init(cl->options->name, cl->options->key,
1160+
cl->options->con_modes);
11611161
if (IS_ERR(monc->auth)) {
11621162
err = PTR_ERR(monc->auth);
11631163
goto out_monmap;

0 commit comments

Comments
 (0)