Skip to content

Commit 09f0e8a

Browse files
ftehlardmarion
authored andcommitted
ipsec: fix incorrect return types
The x_encode() functions claim to return an enum type, but sometimes also return VNET_API_ERRORs. This change brings it in alignment with x_decode() functions: return an int, and return the output through an argument. Type: fix Change-Id: Ieb50c2b925485fa4b2233c84970c520c016e5cb8 Signed-off-by: Filip Tehlar <ftehlar@meter.com> Signed-off-by: Ram Subramanian <ram@meter.com>
1 parent 1576b35 commit 09f0e8a

3 files changed

Lines changed: 40 additions & 35 deletions

File tree

src/vnet/ipsec/ipsec_api.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -976,13 +976,13 @@ send_ipsec_sa_details (ipsec_sa_t * sa, void *arg)
976976

977977
mp->entry.sad_id = htonl (sa->id);
978978
mp->entry.spi = htonl (sa->spi);
979-
mp->entry.protocol = ipsec_proto_encode (sa->protocol);
979+
ipsec_proto_encode (sa->protocol, &mp->entry.protocol);
980980
mp->entry.tx_table_id = htonl (sa->tunnel.t_table_id);
981981

982-
mp->entry.crypto_algorithm = ipsec_crypto_algo_encode (sa->crypto_alg);
982+
ipsec_crypto_algo_encode (sa->crypto_alg, &mp->entry.crypto_algorithm);
983983
ipsec_key_encode (&sa->crypto_key, &mp->entry.crypto_key);
984984

985-
mp->entry.integrity_algorithm = ipsec_integ_algo_encode (sa->integ_alg);
985+
ipsec_integ_algo_encode (sa->integ_alg, &mp->entry.integrity_algorithm);
986986
ipsec_key_encode (&sa->integ_key, &mp->entry.integrity_key);
987987

988988
mp->entry.flags = ipsec_sad_flags_encode (sa);
@@ -1058,13 +1058,13 @@ send_ipsec_sa_v2_details (ipsec_sa_t * sa, void *arg)
10581058

10591059
mp->entry.sad_id = htonl (sa->id);
10601060
mp->entry.spi = htonl (sa->spi);
1061-
mp->entry.protocol = ipsec_proto_encode (sa->protocol);
1061+
ipsec_proto_encode (sa->protocol, &mp->entry.protocol);
10621062
mp->entry.tx_table_id = htonl (sa->tunnel.t_table_id);
10631063

1064-
mp->entry.crypto_algorithm = ipsec_crypto_algo_encode (sa->crypto_alg);
1064+
ipsec_crypto_algo_encode (sa->crypto_alg, &mp->entry.crypto_algorithm);
10651065
ipsec_key_encode (&sa->crypto_key, &mp->entry.crypto_key);
10661066

1067-
mp->entry.integrity_algorithm = ipsec_integ_algo_encode (sa->integ_alg);
1067+
ipsec_integ_algo_encode (sa->integ_alg, &mp->entry.integrity_algorithm);
10681068
ipsec_key_encode (&sa->integ_key, &mp->entry.integrity_key);
10691069

10701070
mp->entry.flags = ipsec_sad_flags_encode (sa);
@@ -1144,12 +1144,12 @@ send_ipsec_sa_v3_details (ipsec_sa_t *sa, void *arg)
11441144

11451145
mp->entry.sad_id = htonl (sa->id);
11461146
mp->entry.spi = htonl (sa->spi);
1147-
mp->entry.protocol = ipsec_proto_encode (sa->protocol);
1147+
ipsec_proto_encode (sa->protocol, &mp->entry.protocol);
11481148

1149-
mp->entry.crypto_algorithm = ipsec_crypto_algo_encode (sa->crypto_alg);
1149+
ipsec_crypto_algo_encode (sa->crypto_alg, &mp->entry.crypto_algorithm);
11501150
ipsec_key_encode (&sa->crypto_key, &mp->entry.crypto_key);
11511151

1152-
mp->entry.integrity_algorithm = ipsec_integ_algo_encode (sa->integ_alg);
1152+
ipsec_integ_algo_encode (sa->integ_alg, &mp->entry.integrity_algorithm);
11531153
ipsec_key_encode (&sa->integ_key, &mp->entry.integrity_key);
11541154

11551155
mp->entry.flags = ipsec_sad_flags_encode (sa);
@@ -1225,12 +1225,12 @@ send_ipsec_sa_v4_details (ipsec_sa_t *sa, void *arg)
12251225

12261226
mp->entry.sad_id = htonl (sa->id);
12271227
mp->entry.spi = htonl (sa->spi);
1228-
mp->entry.protocol = ipsec_proto_encode (sa->protocol);
1228+
ipsec_proto_encode (sa->protocol, &mp->entry.protocol);
12291229

1230-
mp->entry.crypto_algorithm = ipsec_crypto_algo_encode (sa->crypto_alg);
1230+
ipsec_crypto_algo_encode (sa->crypto_alg, &mp->entry.crypto_algorithm);
12311231
ipsec_key_encode (&sa->crypto_key, &mp->entry.crypto_key);
12321232

1233-
mp->entry.integrity_algorithm = ipsec_integ_algo_encode (sa->integ_alg);
1233+
ipsec_integ_algo_encode (sa->integ_alg, &mp->entry.integrity_algorithm);
12341234
ipsec_key_encode (&sa->integ_key, &mp->entry.integrity_key);
12351235

12361236
mp->entry.flags = ipsec_sad_flags_encode (sa);
@@ -1312,12 +1312,12 @@ send_ipsec_sa_v5_details (ipsec_sa_t *sa, void *arg)
13121312

13131313
mp->entry.sad_id = htonl (sa->id);
13141314
mp->entry.spi = htonl (sa->spi);
1315-
mp->entry.protocol = ipsec_proto_encode (sa->protocol);
1315+
ipsec_proto_encode (sa->protocol, &mp->entry.protocol);
13161316

1317-
mp->entry.crypto_algorithm = ipsec_crypto_algo_encode (sa->crypto_alg);
1317+
ipsec_crypto_algo_encode (sa->crypto_alg, &mp->entry.crypto_algorithm);
13181318
ipsec_key_encode (&sa->crypto_key, &mp->entry.crypto_key);
13191319

1320-
mp->entry.integrity_algorithm = ipsec_integ_algo_encode (sa->integ_alg);
1320+
ipsec_integ_algo_encode (sa->integ_alg, &mp->entry.integrity_algorithm);
13211321
ipsec_key_encode (&sa->integ_key, &mp->entry.integrity_key);
13221322

13231323
mp->entry.flags = ipsec_sad_flags_encode (sa);

src/vnet/ipsec/ipsec_types_api.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ ipsec_proto_decode (vl_api_ipsec_proto_t in, ipsec_protocol_t * out)
2323
return (VNET_API_ERROR_INVALID_PROTOCOL);
2424
}
2525

26-
vl_api_ipsec_proto_t
27-
ipsec_proto_encode (ipsec_protocol_t p)
26+
int
27+
ipsec_proto_encode (ipsec_protocol_t p, vl_api_ipsec_proto_t *out)
2828
{
2929
switch (p)
3030
{
3131
case IPSEC_PROTOCOL_ESP:
32-
return clib_host_to_net_u32 (IPSEC_API_PROTO_ESP);
32+
*out = clib_host_to_net_u32 (IPSEC_API_PROTO_ESP);
33+
return (0);
3334
case IPSEC_PROTOCOL_AH:
34-
return clib_host_to_net_u32 (IPSEC_API_PROTO_AH);
35+
*out = clib_host_to_net_u32 (IPSEC_API_PROTO_AH);
36+
return (0);
3537
}
3638
ASSERT (0);
3739
return clib_host_to_net_u32 (IPSEC_API_PROTO_ESP);
@@ -54,16 +56,18 @@ ipsec_crypto_algo_decode (vl_api_ipsec_crypto_alg_t in,
5456
return (VNET_API_ERROR_INVALID_ALGORITHM);
5557
}
5658

57-
vl_api_ipsec_crypto_alg_t
58-
ipsec_crypto_algo_encode (ipsec_crypto_alg_t c)
59+
int
60+
ipsec_crypto_algo_encode (ipsec_crypto_alg_t c, vl_api_ipsec_crypto_alg_t *out)
5961
{
6062
switch (c)
6163
{
62-
#define _(v,f,s) case IPSEC_CRYPTO_ALG_##f: \
63-
return clib_host_to_net_u32(IPSEC_API_CRYPTO_ALG_##f);
64-
foreach_ipsec_crypto_alg
64+
#define _(v, f, s) \
65+
case IPSEC_CRYPTO_ALG_##f: \
66+
*out = clib_host_to_net_u32 (IPSEC_API_CRYPTO_ALG_##f); \
67+
return 0;
68+
foreach_ipsec_crypto_alg
6569
#undef _
66-
case IPSEC_CRYPTO_N_ALG:
70+
case IPSEC_CRYPTO_N_ALG:
6771
break;
6872
}
6973
ASSERT (0);
@@ -86,16 +90,18 @@ ipsec_integ_algo_decode (vl_api_ipsec_integ_alg_t in, ipsec_integ_alg_t * out)
8690
return (VNET_API_ERROR_INVALID_ALGORITHM);
8791
}
8892

89-
vl_api_ipsec_integ_alg_t
90-
ipsec_integ_algo_encode (ipsec_integ_alg_t i)
93+
int
94+
ipsec_integ_algo_encode (ipsec_integ_alg_t i, vl_api_ipsec_integ_alg_t *out)
9195
{
9296
switch (i)
9397
{
94-
#define _(v,f,s) case IPSEC_INTEG_ALG_##f: \
95-
return (clib_host_to_net_u32(IPSEC_API_INTEG_ALG_##f));
96-
foreach_ipsec_integ_alg
98+
#define _(v, f, s) \
99+
case IPSEC_INTEG_ALG_##f: \
100+
*out = (clib_host_to_net_u32 (IPSEC_API_INTEG_ALG_##f)); \
101+
return 0;
102+
foreach_ipsec_integ_alg
97103
#undef _
98-
case IPSEC_INTEG_N_ALG:
104+
case IPSEC_INTEG_N_ALG:
99105
break;
100106
}
101107
ASSERT (0);

src/vnet/ipsec/ipsec_types_api.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414

1515
extern int ipsec_proto_decode (vl_api_ipsec_proto_t in,
1616
ipsec_protocol_t * out);
17-
extern vl_api_ipsec_proto_t ipsec_proto_encode (ipsec_protocol_t p);
17+
extern int ipsec_proto_encode (ipsec_protocol_t p, vl_api_ipsec_proto_t *out);
1818

1919
extern int ipsec_crypto_algo_decode (vl_api_ipsec_crypto_alg_t in,
2020
ipsec_crypto_alg_t * out);
21-
extern vl_api_ipsec_crypto_alg_t ipsec_crypto_algo_encode (ipsec_crypto_alg_t
22-
c);
21+
extern int ipsec_crypto_algo_encode (ipsec_crypto_alg_t c, vl_api_ipsec_crypto_alg_t *out);
2322

2423
extern int ipsec_integ_algo_decode (vl_api_ipsec_integ_alg_t in,
2524
ipsec_integ_alg_t * out);
26-
extern vl_api_ipsec_integ_alg_t ipsec_integ_algo_encode (ipsec_integ_alg_t i);
25+
extern int ipsec_integ_algo_encode (ipsec_integ_alg_t i, vl_api_ipsec_integ_alg_t *out);
2726

2827
extern void ipsec_key_decode (const vl_api_key_t * key, ipsec_key_t * out);
2928
extern void ipsec_key_encode (const ipsec_key_t * in, vl_api_key_t * out);

0 commit comments

Comments
 (0)