From 571ab20d1da227fb66d52ed52cce0cbd4591e1c9 Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Wed, 22 Aug 2018 04:27:15 -0700 Subject: Consolidate the [un]format_mac_address implementations Change-Id: Ic4c42c5610a827234e6582501f0ddcba47aa34ee Signed-off-by: Neale Ranns --- src/examples/sample-plugin/sample/node.c | 8 +------- src/plugins/mactime/mactime.h | 8 -------- src/plugins/mactime/mactime_test.c | 17 +---------------- src/vnet/ethernet/ethernet.h | 2 ++ src/vnet/ethernet/format.c | 13 +++++++++++++ src/vnet/lisp-cp/lisp_types.c | 16 ---------------- src/vnet/lisp-cp/lisp_types.h | 2 -- 7 files changed, 17 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/examples/sample-plugin/sample/node.c b/src/examples/sample-plugin/sample/node.c index 1b512090469..7f34be56168 100644 --- a/src/examples/sample-plugin/sample/node.c +++ b/src/examples/sample-plugin/sample/node.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -26,13 +27,6 @@ typedef struct u8 new_dst_mac[6]; } sample_trace_t; -static u8 * -format_mac_address (u8 * s, va_list * args) -{ - u8 *a = va_arg (*args, u8 *); - return format (s, "%02x:%02x:%02x:%02x:%02x:%02x", - a[0], a[1], a[2], a[3], a[4], a[5]); -} /* packet trace format function */ static u8 * diff --git a/src/plugins/mactime/mactime.h b/src/plugins/mactime/mactime.h index 2166d4a6735..1a13e41f606 100644 --- a/src/plugins/mactime/mactime.h +++ b/src/plugins/mactime/mactime.h @@ -104,14 +104,6 @@ extern vlib_node_registration_t mactime_tx_node; void mactime_send_create_entry_message (u8 * mac_address); -static inline u8 * -format_mac_address (u8 * s, va_list * args) -{ - u8 *a = va_arg (*args, u8 *); - return format (s, "%02x:%02x:%02x:%02x:%02x:%02x", - a[0], a[1], a[2], a[3], a[4], a[5]); -} - /* Periodic function events */ #define MACTIME_EVENT1 1 #define MACTIME_EVENT2 2 diff --git a/src/plugins/mactime/mactime_test.c b/src/plugins/mactime/mactime_test.c index 9ba28da2fc3..309b101bad9 100644 --- a/src/plugins/mactime/mactime_test.c +++ b/src/plugins/mactime/mactime_test.c @@ -19,6 +19,7 @@ #include #include #include +#include uword vat_unformat_sw_if_index (unformat_input_t * input, va_list * args); @@ -79,22 +80,6 @@ _(mactime_add_del_range_reply) foreach_standard_reply_retval_handler; #undef _ -static u8 * -format_mac_address (u8 * s, va_list * args) -{ - u8 *a = va_arg (*args, u8 *); - return format (s, "%02x:%02x:%02x:%02x:%02x:%02x", - a[0], a[1], a[2], a[3], a[4], a[5]); -} - -static uword -unformat_mac_address (unformat_input_t * input, va_list * args) -{ - u8 *a = va_arg (*args, u8 *); - return unformat (input, "%x:%x:%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3], - &a[4], &a[5]); -} - /* * Table of message reply handlers, must include boilerplate handlers * we just generated diff --git a/src/vnet/ethernet/ethernet.h b/src/vnet/ethernet/ethernet.h index 79ae7e6e909..0bfd48723e2 100644 --- a/src/vnet/ethernet/ethernet.h +++ b/src/vnet/ethernet/ethernet.h @@ -339,6 +339,7 @@ void ethernet_register_l2_input (vlib_main_t * vm, u32 node_index); void ethernet_register_l3_redirect (vlib_main_t * vm, u32 node_index); /* Formats ethernet address X:X:X:X:X:X */ +u8 *format_mac_address (u8 * s, va_list * args); u8 *format_ethernet_address (u8 * s, va_list * args); u8 *format_ethernet_type (u8 * s, va_list * args); u8 *format_ethernet_vlan_tci (u8 * s, va_list * va); @@ -347,6 +348,7 @@ u8 *format_ethernet_header_with_length (u8 * s, va_list * args); /* Parse ethernet address in either X:X:X:X:X:X unix or X.X.X cisco format. */ uword unformat_ethernet_address (unformat_input_t * input, va_list * args); +uword unformat_mac_address (unformat_input_t * input, va_list * args); /* Parse ethernet type as 0xXXXX or type name from ethernet/types.def. In either host or network byte order. */ diff --git a/src/vnet/ethernet/format.c b/src/vnet/ethernet/format.c index 13a209fb684..1ca1bce8f2a 100644 --- a/src/vnet/ethernet/format.c +++ b/src/vnet/ethernet/format.c @@ -54,6 +54,12 @@ format_ethernet_address (u8 * s, va_list * args) a[0], a[1], a[2], a[3], a[4], a[5]); } +u8 * +format_mac_address (u8 * s, va_list * args) +{ + return (format_ethernet_address (s, args)); +} + u8 * format_ethernet_type (u8 * s, va_list * args) { @@ -231,6 +237,13 @@ unformat_ethernet_address (unformat_input_t * input, va_list * args) || unformat_user (input, unformat_ethernet_address_cisco, result)); } +uword +unformat_mac_address (unformat_input_t * input, va_list * args) +{ + return (unformat_ethernet_address (input, args)); +} + + /* Returns ethernet type as an int in host byte order. */ uword unformat_ethernet_type_host_byte_order (unformat_input_t * input, diff --git a/src/vnet/lisp-cp/lisp_types.c b/src/vnet/lisp-cp/lisp_types.c index 05f046fa541..d118717ae10 100644 --- a/src/vnet/lisp-cp/lisp_types.c +++ b/src/vnet/lisp-cp/lisp_types.c @@ -203,22 +203,6 @@ unformat_ip_prefix (unformat_input_t * input, va_list * args) return 1; } -uword -unformat_mac_address (unformat_input_t * input, va_list * args) -{ - u8 *a = va_arg (*args, u8 *); - return unformat (input, "%x:%x:%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3], - &a[4], &a[5]); -} - -u8 * -format_mac_address (u8 * s, va_list * args) -{ - u8 *a = va_arg (*args, u8 *); - return format (s, "%02x:%02x:%02x:%02x:%02x:%02x", - a[0], a[1], a[2], a[3], a[4], a[5]); -} - uword unformat_nsh_address (unformat_input_t * input, va_list * args) { diff --git a/src/vnet/lisp-cp/lisp_types.h b/src/vnet/lisp-cp/lisp_types.h index 4a919e7988e..ff7880bff12 100644 --- a/src/vnet/lisp-cp/lisp_types.h +++ b/src/vnet/lisp-cp/lisp_types.h @@ -220,8 +220,6 @@ u8 *format_ip_address (u8 * s, va_list * args); uword unformat_ip_address (unformat_input_t * input, va_list * args); u8 *format_ip_prefix (u8 * s, va_list * args); uword unformat_ip_prefix (unformat_input_t * input, va_list * args); -u8 *format_mac_address (u8 * s, va_list * args); -uword unformat_mac_address (unformat_input_t * input, va_list * args); u16 ip4_address_size_to_put (); u16 ip6_address_size_to_put (); -- cgit 1.2.3-korg