aboutsummaryrefslogtreecommitdiffstats
path: root/net/sctp/endpointola.c
diff options
context:
space:
mode:
authorVlad Yasevich <vladislav.yasevich@hp.com>2007-09-16 22:31:35 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:51:30 -0400
commita29a5bd4f5c3e8ba2e89688feab8b01c44f1654f (patch)
tree2b98f0d572fee7dff79373c64f95a61f940db7e9 /net/sctp/endpointola.c
parent1f485649f52929d9937b346a920a522a7363e202 (diff)
[SCTP]: Implement SCTP-AUTH initializations.
The patch initializes AUTH related members of the generic SCTP structures and provides a way to enable/disable auth extension. Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sctp/endpointola.c')
-rw-r--r--net/sctp/endpointola.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/net/sctp/endpointola.c b/net/sctp/endpointola.c
index 22371185efb6..c8d5023606a5 100644
--- a/net/sctp/endpointola.c
+++ b/net/sctp/endpointola.c
@@ -69,12 +69,56 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
69 struct sock *sk, 69 struct sock *sk,
70 gfp_t gfp) 70 gfp_t gfp)
71{ 71{
72 struct sctp_hmac_algo_param *auth_hmacs = NULL;
73 struct sctp_chunks_param *auth_chunks = NULL;
74 struct sctp_shared_key *null_key;
75 int err;
76
72 memset(ep, 0, sizeof(struct sctp_endpoint)); 77 memset(ep, 0, sizeof(struct sctp_endpoint));
73 78
74 ep->digest = kzalloc(SCTP_SIGNATURE_SIZE, gfp); 79 ep->digest = kzalloc(SCTP_SIGNATURE_SIZE, gfp);
75 if (!ep->digest) 80 if (!ep->digest)
76 return NULL; 81 return NULL;
77 82
83 if (sctp_auth_enable) {
84 /* Allocate space for HMACS and CHUNKS authentication
85 * variables. There are arrays that we encode directly
86 * into parameters to make the rest of the operations easier.
87 */
88 auth_hmacs = kzalloc(sizeof(sctp_hmac_algo_param_t) +
89 sizeof(__u16) * SCTP_AUTH_NUM_HMACS, gfp);
90 if (!auth_hmacs)
91 goto nomem;
92
93 auth_chunks = kzalloc(sizeof(sctp_chunks_param_t) +
94 SCTP_NUM_CHUNK_TYPES, gfp);
95 if (!auth_chunks)
96 goto nomem;
97
98 /* Initialize the HMACS parameter.
99 * SCTP-AUTH: Section 3.3
100 * Every endpoint supporting SCTP chunk authentication MUST
101 * support the HMAC based on the SHA-1 algorithm.
102 */
103 auth_hmacs->param_hdr.type = SCTP_PARAM_HMAC_ALGO;
104 auth_hmacs->param_hdr.length =
105 htons(sizeof(sctp_paramhdr_t) + 2);
106 auth_hmacs->hmac_ids[0] = htons(SCTP_AUTH_HMAC_ID_SHA1);
107
108 /* Initialize the CHUNKS parameter */
109 auth_chunks->param_hdr.type = SCTP_PARAM_CHUNKS;
110
111 /* If the Add-IP functionality is enabled, we must
112 * authenticate, ASCONF and ASCONF-ACK chunks
113 */
114 if (sctp_addip_enable) {
115 auth_chunks->chunks[0] = SCTP_CID_ASCONF;
116 auth_chunks->chunks[1] = SCTP_CID_ASCONF_ACK;
117 auth_chunks->param_hdr.length =
118 htons(sizeof(sctp_paramhdr_t) + 2);
119 }
120 }
121
78 /* Initialize the base structure. */ 122 /* Initialize the base structure. */
79 /* What type of endpoint are we? */ 123 /* What type of endpoint are we? */
80 ep->base.type = SCTP_EP_TYPE_SOCKET; 124 ep->base.type = SCTP_EP_TYPE_SOCKET;
@@ -114,7 +158,36 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
114 ep->last_key = ep->current_key = 0; 158 ep->last_key = ep->current_key = 0;
115 ep->key_changed_at = jiffies; 159 ep->key_changed_at = jiffies;
116 160
161 /* SCTP-AUTH extensions*/
162 INIT_LIST_HEAD(&ep->endpoint_shared_keys);
163 null_key = sctp_auth_shkey_create(0, GFP_KERNEL);
164 if (!null_key)
165 goto nomem;
166
167 list_add(&null_key->key_list, &ep->endpoint_shared_keys);
168
169 /* Allocate and initialize transorms arrays for suported HMACs. */
170 err = sctp_auth_init_hmacs(ep, gfp);
171 if (err)
172 goto nomem_hmacs;
173
174 /* Add the null key to the endpoint shared keys list and
175 * set the hmcas and chunks pointers.
176 */
177 ep->auth_hmacs_list = auth_hmacs;
178 ep->auth_chunk_list = auth_chunks;
179
117 return ep; 180 return ep;
181
182nomem_hmacs:
183 sctp_auth_destroy_keys(&ep->endpoint_shared_keys);
184nomem:
185 /* Free all allocations */
186 kfree(auth_hmacs);
187 kfree(auth_chunks);
188 kfree(ep->digest);
189 return NULL;
190
118} 191}
119 192
120/* Create a sctp_endpoint with all that boring stuff initialized. 193/* Create a sctp_endpoint with all that boring stuff initialized.
@@ -187,6 +260,16 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
187 /* Free the digest buffer */ 260 /* Free the digest buffer */
188 kfree(ep->digest); 261 kfree(ep->digest);
189 262
263 /* SCTP-AUTH: Free up AUTH releated data such as shared keys
264 * chunks and hmacs arrays that were allocated
265 */
266 sctp_auth_destroy_keys(&ep->endpoint_shared_keys);
267 kfree(ep->auth_hmacs_list);
268 kfree(ep->auth_chunk_list);
269
270 /* AUTH - Free any allocated HMAC transform containers */
271 sctp_auth_destroy_hmacs(ep->auth_hmacs);
272
190 /* Cleanup. */ 273 /* Cleanup. */
191 sctp_inq_free(&ep->base.inqueue); 274 sctp_inq_free(&ep->base.inqueue);
192 sctp_bind_addr_free(&ep->base.bind_addr); 275 sctp_bind_addr_free(&ep->base.bind_addr);