session: improve error reporting
Type: improvement
Change-Id: I9dd850a1ce85b0adb5136233f176117e0ee38817
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/vnet/session/transport.c b/src/vnet/session/transport.c
index 6904685..29c94f3 100644
--- a/src/vnet/session/transport.c
+++ b/src/vnet/session/transport.c
@@ -480,7 +480,7 @@
return -1;
}
-static clib_error_t *
+static session_error_t
transport_get_interface_ip (u32 sw_if_index, u8 is_ip4, ip46_address_t * addr)
{
if (is_ip4)
@@ -488,9 +488,7 @@
ip4_address_t *ip4;
ip4 = ip_interface_get_first_ip (sw_if_index, 1);
if (!ip4)
- return clib_error_return (0, "no routable ip4 address on %U",
- format_vnet_sw_if_index_name,
- vnet_get_main (), sw_if_index);
+ return SESSION_E_NOIP;
addr->ip4.as_u32 = ip4->as_u32;
}
else
@@ -498,15 +496,13 @@
ip6_address_t *ip6;
ip6 = ip_interface_get_first_ip (sw_if_index, 0);
if (ip6 == 0)
- return clib_error_return (0, "no routable ip6 addresses on %U",
- format_vnet_sw_if_index_name,
- vnet_get_main (), sw_if_index);
+ return SESSION_E_NOIP;
clib_memcpy_fast (&addr->ip6, ip6, sizeof (*ip6));
}
return 0;
}
-static clib_error_t *
+static session_error_t
transport_find_local_ip_for_remote (u32 sw_if_index,
transport_endpoint_t * rmt,
ip46_address_t * lcl_addr)
@@ -526,14 +522,11 @@
/* Couldn't find route to destination. Bail out. */
if (fei == FIB_NODE_INDEX_INVALID)
- return clib_error_return (0, "no route to %U", format_ip46_address,
- &rmt->ip, (rmt->is_ip4 == 0) + 1);
+ return SESSION_E_NOROUTE;
sw_if_index = fib_entry_get_resolving_interface (fei);
if (sw_if_index == ENDPOINT_INVALID_INDEX)
- return clib_error_return (0, "no resolving interface for %U",
- format_ip46_address, &rmt->ip,
- (rmt->is_ip4 == 0) + 1);
+ return SESSION_E_NOINTF;
}
clib_memset (lcl_addr, 0, sizeof (*lcl_addr));
@@ -545,7 +538,7 @@
ip46_address_t * lcl_addr, u16 * lcl_port)
{
transport_endpoint_t *rmt = (transport_endpoint_t *) rmt_cfg;
- clib_error_t *error;
+ session_error_t error;
int port;
u32 tei;
@@ -557,10 +550,7 @@
error = transport_find_local_ip_for_remote (rmt_cfg->peer.sw_if_index,
rmt, lcl_addr);
if (error)
- {
- clib_error_report (error);
- return -1;
- }
+ return error;
}
else
{
@@ -576,10 +566,7 @@
{
port = transport_alloc_local_port (proto, lcl_addr);
if (port < 1)
- {
- clib_warning ("Failed to allocate src port");
- return -1;
- }
+ return SESSION_E_NOPORT;
*lcl_port = port;
}
else
@@ -588,7 +575,7 @@
tei = transport_endpoint_lookup (&local_endpoints_table, proto,
lcl_addr, port);
if (tei != ENDPOINT_INVALID_INDEX)
- return -1;
+ return SESSION_E_PORTINUSE;
transport_endpoint_mark_used (proto, lcl_addr, port);
*lcl_port = port;