summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJakub Grajciar <jgrajcia@cisco.com>2020-03-19 08:03:55 +0100
committerJakub Grajciar <jgrajcia@cisco.com>2020-03-19 12:49:55 +0100
commit7dd63e5cc1b48adc4f912778ba79d67c71f94b83 (patch)
tree8d923e3337cb7dc5666c135b4898ad6c5f7adced /src
parentf14578972a21fe10cd3ff72aaaaea43da4d74d20 (diff)
ip: change ip API enums address_family and ip_proto size to u8
Type: fix Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com> Change-Id: I73d27520726543d6375caad76a841339f68c3533 Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/svs/svs_api.c10
-rw-r--r--src/vat/api_format.c2
-rw-r--r--src/vnet/fib/fib_api.c25
-rw-r--r--src/vnet/fib/fib_api.h5
-rw-r--r--src/vnet/ip/ip_types.api4
-rw-r--r--src/vnet/ip/ip_types_api.c64
-rw-r--r--src/vnet/ip/ip_types_api.h14
-rw-r--r--src/vnet/ip/punt_api.c10
-rw-r--r--src/vnet/udp/udp_api.c8
-rw-r--r--src/vpp/api/types.c4
10 files changed, 82 insertions, 64 deletions
diff --git a/src/plugins/svs/svs_api.c b/src/plugins/svs/svs_api.c
index 654a074471d..628acd01b01 100644
--- a/src/plugins/svs/svs_api.c
+++ b/src/plugins/svs/svs_api.c
@@ -66,7 +66,9 @@ vl_api_svs_table_add_del_t_handler (vl_api_svs_table_add_del_t * mp)
fib_protocol_t fproto;
int rv = 0;
- fproto = fib_proto_from_api_address_family (mp->af);
+ rv = fib_proto_from_api_address_family (mp->af, &fproto);
+ if (rv < 0)
+ goto error;
if (mp->is_add)
{
@@ -77,6 +79,7 @@ vl_api_svs_table_add_del_t_handler (vl_api_svs_table_add_del_t * mp)
rv = svs_table_delete (fproto, ntohl (mp->table_id));
}
+error:
REPLY_MACRO (VL_API_SVS_TABLE_ADD_DEL_REPLY + svs_base_msg_id);
}
@@ -111,7 +114,9 @@ vl_api_svs_enable_disable_t_handler (vl_api_svs_enable_disable_t * mp)
VALIDATE_SW_IF_INDEX (mp);
- fproto = fib_proto_from_api_address_family (mp->af);
+ rv = fib_proto_from_api_address_family (mp->af, &fproto);
+ if (rv < 0)
+ goto error;
if (mp->is_enable)
{
@@ -124,6 +129,7 @@ vl_api_svs_enable_disable_t_handler (vl_api_svs_enable_disable_t * mp)
}
BAD_SW_IF_INDEX_LABEL;
+error:
REPLY_MACRO (VL_API_SVS_ENABLE_DISABLE_REPLY + svs_base_msg_id);
}
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index 009a0a47301..cfd2028ce19 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -17554,7 +17554,7 @@ format_fib_api_path_nh_proto (u8 * s, va_list * args)
static u8 *
format_vl_api_ip_address_union (u8 * s, va_list * args)
{
- vl_api_address_family_t af = va_arg (*args, vl_api_address_family_t);
+ vl_api_address_family_t af = va_arg (*args, int);
const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
switch (af)
diff --git a/src/vnet/fib/fib_api.c b/src/vnet/fib/fib_api.c
index 64e288761ed..d626ae24502 100644
--- a/src/vnet/fib/fib_api.c
+++ b/src/vnet/fib/fib_api.c
@@ -215,7 +215,7 @@ fib_api_path_decode (vl_api_fib_path_t *in,
break;
case FIB_API_PATH_TYPE_CLASSIFY:
out->frp_flags |= FIB_ROUTE_PATH_CLASSIFY;
-
+
if (pool_is_free_index (cm->tables, ntohl (in->nh.classify_table_index)))
{
return VNET_API_ERROR_NO_SUCH_TABLE;
@@ -537,34 +537,35 @@ format_vl_api_fib_path (u8 * s, va_list * args)
return (s);
}
-fib_protocol_t
-fib_proto_from_api_address_family (int af)
+int
+fib_proto_from_api_address_family (vl_api_address_family_t af, fib_protocol_t * out)
{
- switch (clib_net_to_host_u32 (af))
+ switch (af)
{
case ADDRESS_IP4:
- return (FIB_PROTOCOL_IP4);
+ *out = (FIB_PROTOCOL_IP4);
+ return (0);
case ADDRESS_IP6:
- return (FIB_PROTOCOL_IP6);
+ *out = (FIB_PROTOCOL_IP6);
+ return (0);
}
- ASSERT(0);
- return (FIB_PROTOCOL_IP4);
+ return (VNET_API_ERROR_INVALID_ADDRESS_FAMILY);
}
-int
+vl_api_address_family_t
fib_proto_to_api_address_family (fib_protocol_t fproto)
{
switch (fproto)
{
case FIB_PROTOCOL_IP4:
- return (clib_net_to_host_u32 (ADDRESS_IP4));
+ return (ADDRESS_IP4);
case FIB_PROTOCOL_IP6:
- return (clib_net_to_host_u32 (ADDRESS_IP6));
+ return (ADDRESS_IP6);
default:
break;
}
ASSERT(0);
- return (clib_net_to_host_u32 (ADDRESS_IP4));
+ return (ADDRESS_IP4);
}
diff --git a/src/vnet/fib/fib_api.h b/src/vnet/fib/fib_api.h
index 27335211df7..2492c899502 100644
--- a/src/vnet/fib/fib_api.h
+++ b/src/vnet/fib/fib_api.h
@@ -18,6 +18,7 @@
#include <vnet/fib/fib_types.h>
#include <vnet/fib/fib_entry.h>
+#include <vnet/ip/ip.api_types.h>
/**
* Forward declare the API type, no need to include the generated api headers
@@ -50,7 +51,7 @@ extern int fib_api_route_add_del (u8 is_add,
extern u8* format_vl_api_fib_path(u8 * s, va_list * args);
-extern fib_protocol_t fib_proto_from_api_address_family (int af);
-extern int fib_proto_to_api_address_family (fib_protocol_t fproto);
+extern int fib_proto_from_api_address_family (vl_api_address_family_t af, fib_protocol_t *out);
+extern vl_api_address_family_t fib_proto_to_api_address_family (fib_protocol_t fproto);
#endif /* __FIB_API_H__ */
diff --git a/src/vnet/ip/ip_types.api b/src/vnet/ip/ip_types.api
index 3e6149a78e7..d150050f6e2 100644
--- a/src/vnet/ip/ip_types.api
+++ b/src/vnet/ip/ip_types.api
@@ -18,7 +18,7 @@ option version = "3.0.0";
manual_print typedef u8 ip4_address[4];
manual_print typedef u8 ip6_address[16];
-enum address_family {
+enum address_family : u8 {
ADDRESS_IP4 = 0,
ADDRESS_IP6,
};
@@ -61,7 +61,7 @@ enum ip_dscp : u8 {
IP_API_DSCP_CS7 = 50,
};
-enum ip_proto {
+enum ip_proto : u8 {
IP_API_PROTO_HOPOPT = 0,
IP_API_PROTO_ICMP = 1,
IP_API_PROTO_IGMP = 2,
diff --git a/src/vnet/ip/ip_types_api.c b/src/vnet/ip/ip_types_api.c
index bcf594c70b2..98fb5280493 100644
--- a/src/vnet/ip/ip_types_api.c
+++ b/src/vnet/ip/ip_types_api.c
@@ -31,10 +31,9 @@
#undef vl_printfun
int
-ip_address_family_decode (int _af, ip_address_family_t * out)
+ip_address_family_decode (vl_api_address_family_t af,
+ ip_address_family_t * out)
{
- vl_api_address_family_t af = clib_host_to_net_u32 (_af);
-
switch (af)
{
case ADDRESS_IP4:
@@ -44,30 +43,31 @@ ip_address_family_decode (int _af, ip_address_family_t * out)
*out = AF_IP6;
return (0);
}
- return (-1);
+ return (VNET_API_ERROR_INVALID_ADDRESS_FAMILY);
}
-int
+vl_api_address_family_t
ip_address_family_encode (ip_address_family_t af)
{
switch (af)
{
case AF_IP4:
- return (clib_host_to_net_u32 (ADDRESS_IP4));
+ return (ADDRESS_IP4);
case AF_IP6:
- return (clib_host_to_net_u32 (ADDRESS_IP6));
+ return (ADDRESS_IP6);
}
ASSERT (0);
- return (clib_host_to_net_u32 (ADDRESS_IP4));
+ return (ADDRESS_IP4);
}
int
-ip_proto_decode (int _ipp, ip_protocol_t * out)
+ip_proto_decode (vl_api_ip_proto_t ipp, ip_protocol_t * out)
{
- ip_protocol_t ipp = clib_host_to_net_u32 (_ipp);
-
- switch (ipp)
+ /* Not all protocol are defined in vl_api_ip_proto_t
+ * so we must cast to a different type.
+ */
+ switch ((u8) ipp)
{
#define ip_protocol(n,s) \
case IP_PROTOCOL_##s: \
@@ -76,35 +76,35 @@ ip_proto_decode (int _ipp, ip_protocol_t * out)
#include "protocols.def"
#undef ip_protocol
}
- return (-1);
+ return (VNET_API_ERROR_INVALID_PROTOCOL);
}
-int
+vl_api_ip_proto_t
ip_proto_encode (ip_protocol_t ipp)
{
switch (ipp)
{
#define ip_protocol(n,s) \
case IP_PROTOCOL_##s: \
- return (clib_host_to_net_u32 (IP_PROTOCOL_##s));
+ return ((vl_api_ip_proto_t) IP_PROTOCOL_##s);
#include "protocols.def"
#undef ip_protocol
}
ASSERT (0);
- return (clib_host_to_net_u32 (IP_API_PROTO_TCP));
+ return (IP_API_PROTO_TCP);
}
ip_dscp_t
-ip_dscp_decode (u8 in)
+ip_dscp_decode (vl_api_ip_dscp_t in)
{
return ((ip_dscp_t) in);
}
-u8
+vl_api_ip_dscp_t
ip_dscp_encode (ip_dscp_t dscp)
{
- return (dscp);
+ return ((vl_api_ip_dscp_t) dscp);
}
void
@@ -137,7 +137,7 @@ ip_address_union_decode (const vl_api_address_union_t * in,
{
ip46_type_t type;
- switch (clib_net_to_host_u32 (af))
+ switch (af)
{
case ADDRESS_IP4:
clib_memset (out, 0, sizeof (*out));
@@ -149,7 +149,6 @@ ip_address_union_decode (const vl_api_address_union_t * in,
type = IP46_TYPE_IP6;
break;
default:
- ASSERT (!"Unknown address family in API address type");
type = IP46_TYPE_ANY;
break;
}
@@ -175,6 +174,7 @@ ip_address_decode2 (const vl_api_address_t * in, ip_address_t * out)
out->version = AF_IP6;
break;
default:
+ ;
break;
}
}
@@ -184,7 +184,7 @@ ip_address_union_encode (const ip46_address_t * in,
vl_api_address_family_t af,
vl_api_address_union_t * out)
{
- if (ADDRESS_IP6 == clib_net_to_host_u32 (af))
+ if (ADDRESS_IP6 == af)
ip6_address_encode (&in->ip6, out->ip6);
else
ip4_address_encode (&in->ip4, out->ip4);
@@ -197,16 +197,16 @@ ip_address_encode (const ip46_address_t * in,
switch (type)
{
case IP46_TYPE_IP4:
- out->af = clib_net_to_host_u32 (ADDRESS_IP4);
+ out->af = ADDRESS_IP4;
break;
case IP46_TYPE_IP6:
- out->af = clib_net_to_host_u32 (ADDRESS_IP6);
+ out->af = ADDRESS_IP6;
break;
case IP46_TYPE_ANY:
if (ip46_address_is_ip4 (in))
- out->af = clib_net_to_host_u32 (ADDRESS_IP4);
+ out->af = ADDRESS_IP4;
else
- out->af = clib_net_to_host_u32 (ADDRESS_IP6);
+ out->af = ADDRESS_IP6;
break;
}
ip_address_union_encode (in, out->af, &out->un);
@@ -218,10 +218,12 @@ ip_address_encode2 (const ip_address_t * in, vl_api_address_t * out)
switch (in->version)
{
case AF_IP4:
- out->af = clib_net_to_host_u32 (ADDRESS_IP4);
+ out->af = ADDRESS_IP4;
+ ip4_address_encode (&in->ip.ip4, out->un.ip4);
break;
case AF_IP6:
- out->af = clib_net_to_host_u32 (ADDRESS_IP6);
+ out->af = ADDRESS_IP6;
+ ip6_address_encode (&in->ip.ip6, out->un.ip6);
break;
}
ip_address_union_encode (&in->ip, out->af, &out->un);
@@ -230,7 +232,7 @@ ip_address_encode2 (const ip_address_t * in, vl_api_address_t * out)
void
ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out)
{
- switch (clib_net_to_host_u32 (in->address.af))
+ switch (in->address.af)
{
case ADDRESS_IP4:
out->fp_proto = FIB_PROTOCOL_IP4;
@@ -290,7 +292,7 @@ void
ip_mprefix_encode (const mfib_prefix_t * in, vl_api_mprefix_t * out)
{
out->af = (FIB_PROTOCOL_IP6 == in->fp_proto ? ADDRESS_IP6 : ADDRESS_IP4);
- out->af = clib_host_to_net_u32 (out->af);
+ out->af = out->af;
out->grp_address_length = clib_host_to_net_u16 (in->fp_len);
ip_address_union_encode (&in->fp_grp_addr, out->af, &out->grp_address);
@@ -300,7 +302,7 @@ ip_mprefix_encode (const mfib_prefix_t * in, vl_api_mprefix_t * out)
void
ip_mprefix_decode (const vl_api_mprefix_t * in, mfib_prefix_t * out)
{
- out->fp_proto = (ADDRESS_IP6 == clib_net_to_host_u32 (in->af) ?
+ out->fp_proto = (ADDRESS_IP6 == in->af ?
FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
out->fp_len = clib_net_to_host_u16 (in->grp_address_length);
out->___fp___pad = 0;
diff --git a/src/vnet/ip/ip_types_api.h b/src/vnet/ip/ip_types_api.h
index 600fe090613..62764e6c96e 100644
--- a/src/vnet/ip/ip_types_api.h
+++ b/src/vnet/ip/ip_types_api.h
@@ -30,12 +30,14 @@
* These enum decode/encodes use 'int' as the type for the enum because
* one cannot forward declare an enum
*/
-extern int ip_address_family_decode (int _af, ip_address_family_t * out);
-extern int ip_address_family_encode (ip_address_family_t af);
-extern int ip_proto_decode (int _af, ip_protocol_t * out);
-extern int ip_proto_encode (ip_protocol_t af);
-extern ip_dscp_t ip_dscp_decode (u8 _dscp);
-extern u8 ip_dscp_encode (ip_dscp_t dscp);
+extern int ip_address_family_decode (vl_api_address_family_t af,
+ ip_address_family_t * out);
+extern vl_api_address_family_t ip_address_family_encode (ip_address_family_t
+ af);
+extern int ip_proto_decode (vl_api_ip_proto_t ipp, ip_protocol_t * out);
+extern vl_api_ip_proto_t ip_proto_encode (ip_protocol_t ipp);
+extern ip_dscp_t ip_dscp_decode (vl_api_ip_dscp_t _dscp);
+extern vl_api_ip_dscp_t ip_dscp_encode (ip_dscp_t dscp);
/**
* Decode/Encode for struct/union types
diff --git a/src/vnet/ip/punt_api.c b/src/vnet/ip/punt_api.c
index 077b1ac3a69..2acf8265dc1 100644
--- a/src/vnet/ip/punt_api.c
+++ b/src/vnet/ip/punt_api.c
@@ -89,7 +89,11 @@ vl_api_punt_l4_decode (const vl_api_punt_l4_t * in, punt_l4_t * out)
int rv;
rv = ip_address_family_decode (in->af, &out->af);
- rv += ip_proto_decode (in->protocol, &out->protocol);
+ if (rv < 0)
+ return (rv);
+ rv = ip_proto_decode (in->protocol, &out->protocol);
+ if (rv < 0)
+ return (rv);
out->port = clib_net_to_host_u16 (in->port);
return (rv);
@@ -102,7 +106,9 @@ vl_api_punt_ip_proto_decode (const vl_api_punt_ip_proto_t * in,
int rv;
rv = ip_address_family_decode (in->af, &out->af);
- rv += ip_proto_decode (in->protocol, &out->protocol);
+ if (rv < 0)
+ return (rv);
+ rv = ip_proto_decode (in->protocol, &out->protocol);
return (rv);
}
diff --git a/src/vnet/udp/udp_api.c b/src/vnet/udp/udp_api.c
index 522b0a804ca..566acbcf35c 100644
--- a/src/vnet/udp/udp_api.c
+++ b/src/vnet/udp/udp_api.c
@@ -61,8 +61,8 @@ send_udp_encap_details (const udp_encap_t * ue, vl_api_registration_t * reg,
&ue->ue_hdrs.ip4.ue_ip4.src_address, 4);
clib_memcpy (&mp->udp_encap.dst_ip.un.ip4,
&ue->ue_hdrs.ip4.ue_ip4.dst_address, 4);
- mp->udp_encap.dst_ip.af = clib_host_to_net_u32 (ADDRESS_IP4);
- mp->udp_encap.src_ip.af = clib_host_to_net_u32 (ADDRESS_IP4);
+ mp->udp_encap.dst_ip.af = ip_address_family_encode (AF_IP4);
+ mp->udp_encap.src_ip.af = ip_address_family_encode (AF_IP4);
/* ports aren't byte swapped because they are stored in network
* byte order */
@@ -75,8 +75,8 @@ send_udp_encap_details (const udp_encap_t * ue, vl_api_registration_t * reg,
&ue->ue_hdrs.ip6.ue_ip6.src_address, 16);
clib_memcpy (&mp->udp_encap.dst_ip.un.ip6,
&ue->ue_hdrs.ip6.ue_ip6.dst_address, 16);
- mp->udp_encap.dst_ip.af = clib_host_to_net_u32 (ADDRESS_IP6);
- mp->udp_encap.src_ip.af = clib_host_to_net_u32 (ADDRESS_IP6);
+ mp->udp_encap.dst_ip.af = ip_address_family_encode (AF_IP6);
+ mp->udp_encap.src_ip.af = ip_address_family_encode (AF_IP6);
/* ports aren't byte swapped because they are stored in network
* byte order */
diff --git a/src/vpp/api/types.c b/src/vpp/api/types.c
index f2acf25ce62..92905c260d2 100644
--- a/src/vpp/api/types.c
+++ b/src/vpp/api/types.c
@@ -25,7 +25,7 @@ const vl_api_address_t VL_API_ZERO_ADDRESS;
u8 *
format_vl_api_address_family (u8 * s, va_list * args)
{
- vl_api_address_family_t af = va_arg (*args, vl_api_address_family_t);
+ vl_api_address_family_t af = va_arg (*args, int);
if (ADDRESS_IP6 == clib_net_to_host_u32 (af))
s = format (s, "ip4");
@@ -53,7 +53,7 @@ format_vl_api_address_union (u8 * s, va_list * args)
{
const vl_api_address_union_t *addr =
va_arg (*args, vl_api_address_union_t *);
- vl_api_address_family_t af = va_arg (*args, vl_api_address_family_t);
+ vl_api_address_family_t af = va_arg (*args, int);
if (ADDRESS_IP6 == af)
s = format (s, "%U", format_ip6_address, addr->ip6);