diff options
author | Steven <sluong@cisco.com> | 2016-11-16 13:26:27 -0800 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2016-11-17 14:46:26 +0000 |
commit | 5858a82e761b5782ee09b29fa2365cbcfae56fda (patch) | |
tree | c8104123e5361ecc2885027dbc3ddd79891a66ba | |
parent | 6b9c6df746f3d007b3021044b67a3fc1462d1b35 (diff) |
Put address in top bytes for the nexthop in vl_api_fib_path_t (VPP-532)
VPP-500 added the API for the fib dump capability. However, it puts the address of the
nexthop in the low bytes while the top bytes are padded with 0's if the address is ipv4.
The address field is defined as 16 bytes to accommodate both ipv4 and ipv6.
This fix is to correct the issue and put the address of the nexthop in the top bytes.
Change-Id: I429dec662e32040b186dfc323801ef49b76a42a3
Signed-off-by: Steven <sluong@cisco.com>
-rw-r--r-- | vpp-api-test/vat/api_format.c | 60 | ||||
-rw-r--r-- | vpp/vpp-api/api.c | 75 |
2 files changed, 75 insertions, 60 deletions
diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c index b32c159da8f..c1701476b31 100644 --- a/vpp-api-test/vat/api_format.c +++ b/vpp-api-test/vat/api_format.c @@ -14896,12 +14896,20 @@ vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp) fp = mp->path; for (i = 0; i < count; i++) { - fformat (vam->ofp, - " weight %d, sw_if_index %d, is_local %d, is_drop %d, is_unreach %d, " - "is_prohitbit %d, afi %d, next_hop %U\n", ntohl (fp->weight), - ntohl (fp->sw_if_index), fp->is_local, fp->is_drop, - fp->is_unreach, fp->is_prohibit, fp->afi, format_ip46_address, - fp->next_hop, fp->afi); + if (fp->afi == IP46_TYPE_IP6) + fformat (vam->ofp, + " weight %d, sw_if_index %d, is_local %d, is_drop %d, " + "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n", + ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local, + fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi, + format_ip6_address, fp->next_hop); + else if (fp->afi == IP46_TYPE_IP4) + fformat (vam->ofp, + " weight %d, sw_if_index %d, is_local %d, is_drop %d, " + "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n", + ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local, + fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi, + format_ip4_address, fp->next_hop); fp++; } } @@ -14988,12 +14996,20 @@ vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp) fp = mp->path; for (i = 0; i < count; i++) { - fformat (vam->ofp, - " weight %d, sw_if_index %d, is_local %d, is_drop %d, is_unreach %d, " - "is_prohitbit %d, afi %d, next_hop %U\n", ntohl (fp->weight), - ntohl (fp->sw_if_index), fp->is_local, fp->is_drop, - fp->is_unreach, fp->is_prohibit, fp->afi, format_ip46_address, - fp->next_hop, fp->afi); + if (fp->afi == IP46_TYPE_IP6) + fformat (vam->ofp, + " weight %d, sw_if_index %d, is_local %d, is_drop %d, " + "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n", + ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local, + fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi, + format_ip6_address, fp->next_hop); + else if (fp->afi == IP46_TYPE_IP4) + fformat (vam->ofp, + " weight %d, sw_if_index %d, is_local %d, is_drop %d, " + "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n", + ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local, + fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi, + format_ip4_address, fp->next_hop); fp++; } } @@ -15081,12 +15097,20 @@ vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp) fp = mp->path; for (i = 0; i < count; i++) { - fformat (vam->ofp, - " weight %d, sw_if_index %d, is_local %d, is_drop %d, is_unreach %d, " - "is_prohitbit %d, afi %d, next_hop %U\n", ntohl (fp->weight), - ntohl (fp->sw_if_index), fp->is_local, fp->is_drop, - fp->is_unreach, fp->is_prohibit, fp->afi, format_ip46_address, - fp->next_hop, fp->afi); + if (fp->afi == IP46_TYPE_IP6) + fformat (vam->ofp, + " weight %d, sw_if_index %d, is_local %d, is_drop %d, " + "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n", + ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local, + fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi, + format_ip6_address, fp->next_hop); + else if (fp->afi == IP46_TYPE_IP4) + fformat (vam->ofp, + " weight %d, sw_if_index %d, is_local %d, is_drop %d, " + "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U\n", + ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local, + fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi, + format_ip4_address, fp->next_hop); fp++; } } diff --git a/vpp/vpp-api/api.c b/vpp/vpp-api/api.c index b29757602c9..e234df8f41a 100644 --- a/vpp/vpp-api/api.c +++ b/vpp/vpp-api/api.c @@ -7605,6 +7605,33 @@ vl_api_mpls_fib_details_t_print (vl_api_mpls_fib_details_t * mp) clib_warning ("BUG"); } + +static void +copy_fib_next_hop (fib_route_path_encode_t * api_rpath, + vl_api_fib_path_t * fp) +{ + int is_ip4; + + if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP4) + fp->afi = IP46_TYPE_IP4; + else if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP6) + fp->afi = IP46_TYPE_IP6; + else + { + is_ip4 = ip46_address_is_ip4 (&api_rpath->rpath.frp_addr); + if (is_ip4) + fp->afi = IP46_TYPE_IP4; + else + fp->afi = IP46_TYPE_IP6; + } + if (fp->afi == IP46_TYPE_IP4) + memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip4, + sizeof (api_rpath->rpath.frp_addr.ip4)); + else + memcpy (fp->next_hop, &api_rpath->rpath.frp_addr.ip6, + sizeof (api_rpath->rpath.frp_addr.ip6)); +} + static void send_mpls_fib_details (vpe_api_main_t * am, unix_shared_memory_queue_t * q, @@ -7614,7 +7641,7 @@ send_mpls_fib_details (vpe_api_main_t * am, vl_api_mpls_fib_details_t *mp; fib_route_path_encode_t *api_rpath; vl_api_fib_path_t *fp; - int is_ip4, path_count; + int path_count; path_count = vec_len (api_rpaths); mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); @@ -7635,19 +7662,7 @@ send_mpls_fib_details (vpe_api_main_t * am, memset (fp, 0, sizeof (*fp)); fp->weight = htonl (api_rpath->rpath.frp_weight); fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index); - memcpy (fp->next_hop, &api_rpath->rpath.frp_addr, sizeof (fp->next_hop)); - if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP4) - fp->afi = IP46_TYPE_IP4; - else if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP6) - fp->afi = IP46_TYPE_IP6; - else - { - is_ip4 = ip46_address_is_ip4 (&api_rpath->rpath.frp_addr); - if (is_ip4) - fp->afi = IP46_TYPE_IP4; - else - fp->afi = IP46_TYPE_IP6; - } + copy_fib_next_hop (api_rpath, fp); fp++; } @@ -7727,7 +7742,7 @@ send_ip_fib_details (vpe_api_main_t * am, vl_api_ip_fib_details_t *mp; fib_route_path_encode_t *api_rpath; vl_api_fib_path_t *fp; - int is_ip4, path_count; + int path_count; path_count = vec_len(api_rpaths); mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); @@ -7775,19 +7790,7 @@ send_ip_fib_details (vpe_api_main_t * am, } fp->weight = htonl(api_rpath->rpath.frp_weight); fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index); - memcpy(fp->next_hop, &api_rpath->rpath.frp_addr, sizeof(fp->next_hop)); - if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP4) - fp->afi = IP46_TYPE_IP4; - else if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP6) - fp->afi = IP46_TYPE_IP6; - else - { - is_ip4 = ip46_address_is_ip4 (&api_rpath->rpath.frp_addr); - if (is_ip4) - fp->afi = IP46_TYPE_IP4; - else - fp->afi = IP46_TYPE_IP6; - } + copy_fib_next_hop (api_rpath, fp); fp++; } @@ -7871,7 +7874,7 @@ send_ip6_fib_details (vpe_api_main_t * am, vl_api_ip6_fib_details_t *mp; fib_route_path_encode_t *api_rpath; vl_api_fib_path_t *fp; - int is_ip4, path_count; + int path_count; path_count = vec_len(api_rpaths); mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); @@ -7919,19 +7922,7 @@ send_ip6_fib_details (vpe_api_main_t * am, } fp->weight = htonl(api_rpath->rpath.frp_weight); fp->sw_if_index = htonl(api_rpath->rpath.frp_sw_if_index); - memcpy(fp->next_hop, &api_rpath->rpath.frp_addr, sizeof(fp->next_hop)); - if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP4) - fp->afi = IP46_TYPE_IP4; - else if (api_rpath->rpath.frp_proto == FIB_PROTOCOL_IP6) - fp->afi = IP46_TYPE_IP6; - else - { - is_ip4 = ip46_address_is_ip4 (&api_rpath->rpath.frp_addr); - if (is_ip4) - fp->afi = IP46_TYPE_IP4; - else - fp->afi = IP46_TYPE_IP6; - } + copy_fib_next_hop (api_rpath, fp); fp++; } |