Skip to content
Snippets Groups Projects
Commit 36840b90 authored by Michael Tüxen's avatar Michael Tüxen
Browse files

Add print support for HMAC_ALGO parameter.

parent 5fec2a7a
No related branches found
No related tags found
No related merge requests found
......@@ -445,6 +445,15 @@ struct sctp_chunks_parameter {
__u8 chunk_type[];
} __packed;
#define SCTP_HMAC_ID_SHA_1 1
#define SCTP_HMAC_ID_SHA_256 3
struct sctp_hmac_algo_parameter {
__be16 type;
__be16 length;
__be16 hmac_id[];
} __packed;
struct sctp_supported_extensions_parameter {
__be16 type;
__be16 length;
......
......@@ -511,6 +511,44 @@ static int sctp_chunks_parameter_to_string(
return STATUS_OK;
}
static int sctp_hmac_algo_parameter_to_string(
FILE *s,
struct sctp_hmac_algo_parameter *parameter,
char **error)
{
u16 i, length, nr_hmac_algos;
length = ntohs(parameter->length);
if ((length < sizeof(struct sctp_hmac_algo_parameter)) ||
((length & 0x0001) != 0)) {
asprintf(error,
"HMAC_ALGO parameter illegal (length=%u)",
length);
return STATUS_ERR;
}
nr_hmac_algos =
(length - sizeof(struct sctp_hmac_algo_parameter))
/ sizeof(u16);
fputs("HMAC_ALGO[types=[", s);
for (i = 0; i < nr_hmac_algos; i++) {
if (i > 0)
fputs(", ", s);
switch (ntohs(parameter->hmac_id[i])) {
case SCTP_HMAC_ID_SHA_1:
fputs("SHA-1", s);
break;
case SCTP_HMAC_ID_SHA_256:
fputs("SHA-256", s);
break;
default:
fprintf(s, "0x%04x", ntohs(parameter->hmac_id[i]));
break;
}
}
fputs("]]", s);
return STATUS_OK;
}
static int sctp_supported_extensions_parameter_to_string(
FILE *s,
struct sctp_supported_extensions_parameter *parameter,
......@@ -765,6 +803,11 @@ static int sctp_parameter_to_string(FILE *s,
(struct sctp_chunks_parameter *)parameter,
error);
break;
case SCTP_HMAC_ALGO_PARAMETER_TYPE:
result = sctp_hmac_algo_parameter_to_string(s,
(struct sctp_hmac_algo_parameter *)parameter,
error);
break;
case SCTP_SUPPORTED_EXTENSIONS_PARAMETER_TYPE:
result = sctp_supported_extensions_parameter_to_string(s,
(struct sctp_supported_extensions_parameter *)parameter,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment