summaryrefslogtreecommitdiffstats
path: root/src/vnet/ip
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/vnet/ip
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/vnet/ip')
-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
4 files changed, 51 insertions, 41 deletions
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);
}