c4d1eee827a342d41e31671ae7c4fc551e7d2c52
1 #include "ceph_debug.h"
3 #include <linux/module.h>
11 #include "messenger.h"
14 * get protocol handler
16 static u32 supported_protocols
[] = {
20 int ceph_auth_init_protocol(struct ceph_auth_client
*ac
, int protocol
)
24 return ceph_auth_none_init(ac
);
33 struct ceph_auth_client
*ceph_auth_init(const char *name
, const char *secret
)
35 struct ceph_auth_client
*ac
;
38 dout("auth_init name '%s' secret '%s'\n", name
, secret
);
41 ac
= kzalloc(sizeof(*ac
), GFP_NOFS
);
45 ac
->negotiating
= true;
49 ac
->name
= CEPH_AUTH_NAME_DEFAULT
;
50 dout("auth_init name %s secret %s\n", ac
->name
, secret
);
58 void ceph_auth_destroy(struct ceph_auth_client
*ac
)
60 dout("auth_destroy %p\n", ac
);
67 * Reset occurs when reconnecting to the monitor.
69 void ceph_auth_reset(struct ceph_auth_client
*ac
)
71 dout("auth_reset %p\n", ac
);
72 if (ac
->ops
&& !ac
->negotiating
)
74 ac
->negotiating
= true;
77 int ceph_entity_name_encode(const char *name
, void **p
, void *end
)
79 int len
= strlen(name
);
81 if (*p
+ 2*sizeof(u32
) + len
> end
)
83 ceph_encode_32(p
, CEPH_ENTITY_TYPE_CLIENT
);
84 ceph_encode_32(p
, len
);
85 ceph_encode_copy(p
, name
, len
);
90 * Initiate protocol negotiation with monitor. Include entity name
91 * and list supported protocols.
93 int ceph_auth_build_hello(struct ceph_auth_client
*ac
, void *buf
, size_t len
)
95 struct ceph_mon_request_header
*monhdr
= buf
;
96 void *p
= monhdr
+ 1, *end
= buf
+ len
, *lenp
;
100 dout("auth_build_hello\n");
101 monhdr
->have_version
= 0;
102 monhdr
->session_mon
= cpu_to_le16(-1);
103 monhdr
->session_mon_tid
= 0;
105 ceph_encode_32(&p
, 0); /* no protocol, yet */
110 num
= ARRAY_SIZE(supported_protocols
);
111 ceph_encode_32(&p
, num
);
112 for (i
= 0; i
< num
; i
++)
113 ceph_encode_32(&p
, supported_protocols
[i
]);
115 ret
= ceph_entity_name_encode(ac
->name
, &p
, end
);
118 ceph_decode_need(&p
, end
, sizeof(u64
), bad
);
119 ceph_encode_64(&p
, ac
->global_id
);
121 ceph_encode_32(&lenp
, p
- lenp
- sizeof(u32
));
129 * Handle auth message from monitor.
131 int ceph_handle_auth_reply(struct ceph_auth_client
*ac
,
132 void *buf
, size_t len
,
133 void *reply_buf
, size_t reply_len
)
136 void *end
= buf
+ len
;
140 void *payload
, *payload_end
;
146 dout("handle_auth_reply %p %p\n", p
, end
);
147 ceph_decode_need(&p
, end
, sizeof(u32
) * 3 + sizeof(u64
), bad
);
148 protocol
= ceph_decode_32(&p
);
149 result
= ceph_decode_32(&p
);
150 global_id
= ceph_decode_64(&p
);
151 payload_len
= ceph_decode_32(&p
);
154 ceph_decode_need(&p
, end
, sizeof(u32
), bad
);
155 result_msg_len
= ceph_decode_32(&p
);
161 dout(" result %d '%.*s' gid %llu len %d\n", result
, result_msg_len
,
162 result_msg
, global_id
, payload_len
);
164 payload_end
= payload
+ payload_len
;
166 if (global_id
&& ac
->global_id
!= global_id
) {
167 dout(" set global_id %lld -> %lld\n", ac
->global_id
, global_id
);
168 ac
->global_id
= global_id
;
171 if (ac
->negotiating
) {
172 /* set up (new) protocol handler? */
173 if (ac
->protocol
&& ac
->protocol
!= protocol
) {
174 ac
->ops
->destroy(ac
);
178 if (ac
->protocol
!= protocol
) {
179 ret
= ceph_auth_init_protocol(ac
, protocol
);
181 pr_err("error %d on auth protocol %d init\n",
188 ret
= ac
->ops
->handle_reply(ac
, result
, payload
, payload_end
);
189 if (ret
== -EAGAIN
) {
190 struct ceph_mon_request_header
*monhdr
= reply_buf
;
191 void *p
= reply_buf
+ 1;
192 void *end
= reply_buf
+ reply_len
;
194 monhdr
->have_version
= 0;
195 monhdr
->session_mon
= cpu_to_le16(-1);
196 monhdr
->session_mon_tid
= 0;
198 ceph_encode_32(&p
, ac
->protocol
);
200 ret
= ac
->ops
->build_request(ac
, p
+ sizeof(u32
), end
);
202 pr_err("error %d building request\n", ret
);
205 dout(" built request %d bytes\n", ret
);
206 ceph_encode_32(&p
, ret
);
207 return p
+ ret
- reply_buf
;
209 pr_err("authentication error %d\n", ret
);
215 pr_err("failed to decode auth msg\n");
This page took 0.058326 seconds and 5 git commands to generate.