[PATCH] xfrm: Make character pointers in setters const
Thomas Egerer
thomas.egerer at secunet.com
Mon Jun 6 06:21:35 PDT 2016
All of these pointers are either strcpy'd or memcpy'd and usually const
in a calling application. Changing them to const in the header does not
break the compatibility and allows for users with const pointers to use
the library without compiler warnings.
Signed-off-by: Thomas Egerer <thomas.egerer at secunet.com>
---
Hi *,
we found our compiler nagging about discarding the const qualifier from
various char * parameters when adding states. Since keys and algorithm
names are not modified but only copied, it makes sense to add the const
qualifier to the prototype and the implementation.
Please note, that this patch is on top of [1], the version on top of the
current master can be found here: [2].
Cheers,
Thomas
[1] http://lists.infradead.org/pipermail/libnl/2016-May/002133.html
[2] https://github.com/spellingmistake/libnl/commit/36f8a7d4f2899d78a11056e48c38177b1d72ad13
include/netlink/xfrm/sa.h | 16 +++++++++-------
lib/xfrm/sa.c | 20 ++++++++++----------
2 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/include/netlink/xfrm/sa.h b/include/netlink/xfrm/sa.h
index acc7f4d..9209ab0 100644
--- a/include/netlink/xfrm/sa.h
+++ b/include/netlink/xfrm/sa.h
@@ -111,19 +111,21 @@ extern int xfrmnl_sa_set_flags (struct xfrmnl_sa*, unsigned
extern int xfrmnl_sa_get_aead_params (struct xfrmnl_sa*, char*, unsigned int*,
unsigned int*, char*);
-extern int xfrmnl_sa_set_aead_params (struct xfrmnl_sa*, char*, unsigned int,
- unsigned int, char*);
+extern int xfrmnl_sa_set_aead_params (struct xfrmnl_sa*, const char*, unsigned int,
+ unsigned int, const char*);
extern int xfrmnl_sa_get_auth_params (struct xfrmnl_sa*, char*, unsigned int*,
unsigned int*, char*);
-extern int xfrmnl_sa_set_auth_params (struct xfrmnl_sa*, char*, unsigned int,
- unsigned int, char*);
+extern int xfrmnl_sa_set_auth_params (struct xfrmnl_sa*, const char*, unsigned int,
+ unsigned int, const char*);
extern int xfrmnl_sa_get_crypto_params (struct xfrmnl_sa*, char*, unsigned int*, char*);
-extern int xfrmnl_sa_set_crypto_params (struct xfrmnl_sa*, char*, unsigned int, char*);
+extern int xfrmnl_sa_set_crypto_params (struct xfrmnl_sa*, const char*, unsigned int,
+ const char*);
extern int xfrmnl_sa_get_comp_params (struct xfrmnl_sa*, char*, unsigned int*, char*);
-extern int xfrmnl_sa_set_comp_params (struct xfrmnl_sa*, char*, unsigned int, char*);
+extern int xfrmnl_sa_set_comp_params (struct xfrmnl_sa*, const char*, unsigned int,
+ const char*);
extern int xfrmnl_sa_get_encap_tmpl (struct xfrmnl_sa*, unsigned int*, unsigned int*,
unsigned int*, struct nl_addr**);
@@ -142,7 +144,7 @@ extern int xfrmnl_sa_set_mark (struct xfrmnl_sa*, unsigned
extern int xfrmnl_sa_get_sec_ctx (struct xfrmnl_sa*, unsigned int, unsigned int,
unsigned int, unsigned int, char*);
extern int xfrmnl_sa_set_sec_ctx (struct xfrmnl_sa*, unsigned int, unsigned int,
- unsigned int, unsigned int, char*);
+ unsigned int, unsigned int, const char*);
extern int xfrmnl_sa_get_replay_maxage (struct xfrmnl_sa*);
extern int xfrmnl_sa_set_replay_maxage (struct xfrmnl_sa*, unsigned int);
diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c
index 1cd6edd..0b813c4 100644
--- a/lib/xfrm/sa.c
+++ b/lib/xfrm/sa.c
@@ -1627,7 +1627,7 @@ int xfrmnl_sa_get_aead_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
return 0;
}
-int xfrmnl_sa_set_aead_params (struct xfrmnl_sa* sa, char* alg_name, unsigned int key_len, unsigned int icv_len, char* key)
+int xfrmnl_sa_set_aead_params (struct xfrmnl_sa* sa, const char* alg_name, unsigned int key_len, unsigned int icv_len, const char* key)
{
size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
uint32_t newlen = sizeof (struct xfrmnl_algo_aead) + keysize;
@@ -1642,7 +1642,7 @@ int xfrmnl_sa_set_aead_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
strcpy (sa->aead->alg_name, alg_name);
sa->aead->alg_key_len = key_len;
sa->aead->alg_icv_len = icv_len;
- memcpy ((void *)sa->aead->alg_key, (void *)key, keysize);
+ memcpy (sa->aead->alg_key, key, keysize);
sa->ce_mask |= XFRM_SA_ATTR_ALG_AEAD;
@@ -1664,7 +1664,7 @@ int xfrmnl_sa_get_auth_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
return 0;
}
-int xfrmnl_sa_set_auth_params (struct xfrmnl_sa* sa, char* alg_name, unsigned int key_len, unsigned int trunc_len, char* key)
+int xfrmnl_sa_set_auth_params (struct xfrmnl_sa* sa, const char* alg_name, unsigned int key_len, unsigned int trunc_len, const char* key)
{
size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
uint32_t newlen = sizeof (struct xfrmnl_algo_auth) + keysize;
@@ -1679,7 +1679,7 @@ int xfrmnl_sa_set_auth_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
strcpy (sa->auth->alg_name, alg_name);
sa->auth->alg_key_len = key_len;
sa->auth->alg_trunc_len = trunc_len;
- memcpy ((void *)sa->auth->alg_key, (void *)key, keysize);
+ memcpy (sa->auth->alg_key, key, keysize);
sa->ce_mask |= XFRM_SA_ATTR_ALG_AUTH;
@@ -1700,7 +1700,7 @@ int xfrmnl_sa_get_crypto_params (struct xfrmnl_sa* sa, char* alg_name, unsigned
return 0;
}
-int xfrmnl_sa_set_crypto_params (struct xfrmnl_sa* sa, char* alg_name, unsigned int key_len, char* key)
+int xfrmnl_sa_set_crypto_params (struct xfrmnl_sa* sa, const char* alg_name, unsigned int key_len, const char* key)
{
size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
uint32_t newlen = sizeof (struct xfrmnl_algo) + keysize;
@@ -1714,7 +1714,7 @@ int xfrmnl_sa_set_crypto_params (struct xfrmnl_sa* sa, char* alg_name, unsigned
/* Save the new info */
strcpy (sa->crypt->alg_name, alg_name);
sa->crypt->alg_key_len = key_len;
- memcpy ((void *)sa->crypt->alg_key, (void *)key, keysize);
+ memcpy (sa->crypt->alg_key, key, keysize);
sa->ce_mask |= XFRM_SA_ATTR_ALG_CRYPT;
@@ -1735,7 +1735,7 @@ int xfrmnl_sa_get_comp_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
return 0;
}
-int xfrmnl_sa_set_comp_params (struct xfrmnl_sa* sa, char* alg_name, unsigned int key_len, char* key)
+int xfrmnl_sa_set_comp_params (struct xfrmnl_sa* sa, const char* alg_name, unsigned int key_len, const char* key)
{
size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
uint32_t newlen = sizeof (struct xfrmnl_algo) + keysize;
@@ -1749,7 +1749,7 @@ int xfrmnl_sa_set_comp_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
/* Save the new info */
strcpy (sa->comp->alg_name, alg_name);
sa->comp->alg_key_len = key_len;
- memcpy ((void *)sa->comp->alg_key, (void *)key, keysize);
+ memcpy (sa->comp->alg_key, key, keysize);
sa->ce_mask |= XFRM_SA_ATTR_ALG_COMP;
@@ -1869,7 +1869,7 @@ int xfrmnl_sa_get_sec_ctx (struct xfrmnl_sa* sa, unsigned int* doi, unsigned int
return 0;
}
-int xfrmnl_sa_set_sec_ctx (struct xfrmnl_sa* sa, unsigned int doi, unsigned int alg, unsigned int len, unsigned int sid, char* ctx_str)
+int xfrmnl_sa_set_sec_ctx (struct xfrmnl_sa* sa, unsigned int doi, unsigned int alg, unsigned int len, unsigned int sid, const char* ctx_str)
{
/* Free up the old context string and allocate new one */
if (sa->sec_ctx)
@@ -1882,7 +1882,7 @@ int xfrmnl_sa_set_sec_ctx (struct xfrmnl_sa* sa, unsigned int doi, unsigned int
sa->sec_ctx->ctx_alg = alg;
sa->sec_ctx->ctx_len = len;
sa->sec_ctx->ctx_sid = sid;
- memcpy ((void *)sa->sec_ctx->ctx_str, (void *)ctx_str, sizeof (uint8_t) * len);
+ memcpy (sa->sec_ctx->ctx_str, ctx_str, sizeof (uint8_t) * len);
sa->ce_mask |= XFRM_SA_ATTR_SECCTX;
--
2.6.4
More information about the libnl
mailing list