diff options
Diffstat (limited to 'vnet/vnet/ip/ip6_format.c')
-rw-r--r-- | vnet/vnet/ip/ip6_format.c | 204 |
1 files changed, 112 insertions, 92 deletions
diff --git a/vnet/vnet/ip/ip6_format.c b/vnet/vnet/ip/ip6_format.c index 5d321894..56899b73 100644 --- a/vnet/vnet/ip/ip6_format.c +++ b/vnet/vnet/ip/ip6_format.c @@ -40,11 +40,12 @@ #include <vnet/ip/ip.h> /* Format an IP6 address. */ -u8 * format_ip6_address (u8 * s, va_list * args) +u8 * +format_ip6_address (u8 * s, va_list * args) { - ip6_address_t * a = va_arg (*args, ip6_address_t *); + ip6_address_t *a = va_arg (*args, ip6_address_t *); u32 max_zero_run = 0, this_zero_run = 0; - int max_zero_run_index = -1, this_zero_run_index=0; + int max_zero_run_index = -1, this_zero_run_index = 0; int in_zero_run = 0, i; int last_double_colon = 0; @@ -52,49 +53,49 @@ u8 * format_ip6_address (u8 * s, va_list * args) for (i = 0; i < ARRAY_LEN (a->as_u16); i++) { if (a->as_u16[i] == 0) - { - if (in_zero_run) - this_zero_run++; - else - { - in_zero_run = 1; - this_zero_run =1; - this_zero_run_index = i; - } - } + { + if (in_zero_run) + this_zero_run++; + else + { + in_zero_run = 1; + this_zero_run = 1; + this_zero_run_index = i; + } + } else - { - if (in_zero_run) - { - /* offer to compress the biggest run of > 1 zero */ - if (this_zero_run > max_zero_run && this_zero_run > 1) - { - max_zero_run_index = this_zero_run_index; - max_zero_run = this_zero_run; - } - } - in_zero_run = 0; - this_zero_run = 0; - } + { + if (in_zero_run) + { + /* offer to compress the biggest run of > 1 zero */ + if (this_zero_run > max_zero_run && this_zero_run > 1) + { + max_zero_run_index = this_zero_run_index; + max_zero_run = this_zero_run; + } + } + in_zero_run = 0; + this_zero_run = 0; + } } if (in_zero_run) { if (this_zero_run > max_zero_run && this_zero_run > 1) - { - max_zero_run_index = this_zero_run_index; - max_zero_run = this_zero_run; - } + { + max_zero_run_index = this_zero_run_index; + max_zero_run = this_zero_run; + } } - + for (i = 0; i < ARRAY_LEN (a->as_u16); i++) { if (i == max_zero_run_index) - { + { s = format (s, "::"); - i += max_zero_run - 1; - last_double_colon = 1; - } + i += max_zero_run - 1; + last_double_colon = 1; + } else { s = format (s, "%s%x", @@ -108,17 +109,19 @@ u8 * format_ip6_address (u8 * s, va_list * args) } /* Format an IP6 route destination and length. */ -u8 * format_ip6_address_and_length (u8 * s, va_list * args) +u8 * +format_ip6_address_and_length (u8 * s, va_list * args) { - ip6_address_t * a = va_arg (*args, ip6_address_t *); + ip6_address_t *a = va_arg (*args, ip6_address_t *); u8 l = va_arg (*args, u32); return format (s, "%U/%d", format_ip6_address, a, l); } /* Parse an IP6 address. */ -uword unformat_ip6_address (unformat_input_t * input, va_list * args) +uword +unformat_ip6_address (unformat_input_t * input, va_list * args) { - ip6_address_t * result = va_arg (*args, ip6_address_t *); + ip6_address_t *result = va_arg (*args, ip6_address_t *); u16 hex_quads[8]; uword hex_quad, n_hex_quads, hex_digit, n_hex_digits; uword c, n_colon, double_colon_index; @@ -157,7 +160,7 @@ uword unformat_ip6_address (unformat_input_t * input, va_list * args) n_colon = 0; n_hex_digits++; } - + /* Save position of :: */ if (n_colon == 2) { @@ -190,10 +193,10 @@ uword unformat_ip6_address (unformat_input_t * input, va_list * args) hex_quads[n_zero + i] = hex_quads[i]; for (i = 0; i < n_zero; i++) - { - ASSERT ((double_colon_index + i) < ARRAY_LEN (hex_quads)); - hex_quads[double_colon_index + i] = 0; - } + { + ASSERT ((double_colon_index + i) < ARRAY_LEN (hex_quads)); + hex_quads[double_colon_index + i] = 0; + } n_hex_quads = ARRAY_LEN (hex_quads); } @@ -210,9 +213,10 @@ uword unformat_ip6_address (unformat_input_t * input, va_list * args) } /* Format an IP6 header. */ -u8 * format_ip6_header (u8 * s, va_list * args) +u8 * +format_ip6_header (u8 * s, va_list * args) { - ip6_header_t * ip = va_arg (*args, ip6_header_t *); + ip6_header_t *ip = va_arg (*args, ip6_header_t *); u32 max_header_bytes = va_arg (*args, u32); u32 i, ip_version, traffic_class, flow_label; uword indent; @@ -235,25 +239,24 @@ u8 * format_ip6_header (u8 * s, va_list * args) flow_label = i & pow2_mask (20); if (ip_version != 6) - s = format (s, "\n%Uversion %d", - format_white_space, indent, ip_version); - - s = format (s, "\n%Utos 0x%02x, flow label 0x%x, hop limit %d, payload length %d", - format_white_space, indent, - traffic_class, flow_label, ip->hop_limit, - clib_net_to_host_u16 (ip->payload_length)); + s = format (s, "\n%Uversion %d", format_white_space, indent, ip_version); + + s = + format (s, + "\n%Utos 0x%02x, flow label 0x%x, hop limit %d, payload length %d", + format_white_space, indent, traffic_class, flow_label, + ip->hop_limit, clib_net_to_host_u16 (ip->payload_length)); /* Recurse into next protocol layer. */ if (max_header_bytes != 0 && sizeof (ip[0]) < max_header_bytes) { - ip_main_t * im = &ip_main; - ip_protocol_info_t * pi = ip_get_protocol_info (im, ip->protocol); + ip_main_t *im = &ip_main; + ip_protocol_info_t *pi = ip_get_protocol_info (im, ip->protocol); if (pi && pi->format_header) s = format (s, "\n%U%U", - format_white_space, indent - 2, - pi->format_header, - /* next protocol header */ (void*) (ip + 1), + format_white_space, indent - 2, pi->format_header, + /* next protocol header */ (void *) (ip + 1), max_header_bytes - sizeof (ip[0])); } @@ -261,15 +264,16 @@ u8 * format_ip6_header (u8 * s, va_list * args) } /* Parse an IP6 header. */ -uword unformat_ip6_header (unformat_input_t * input, va_list * args) +uword +unformat_ip6_header (unformat_input_t * input, va_list * args) { - u8 ** result = va_arg (*args, u8 **); - ip6_header_t * ip; + u8 **result = va_arg (*args, u8 **); + ip6_header_t *ip; int old_length; /* Allocate space for IP header. */ { - void * p; + void *p; old_length = vec_len (*result); vec_add2 (*result, p, sizeof (ip[0])); @@ -277,12 +281,13 @@ uword unformat_ip6_header (unformat_input_t * input, va_list * args) } memset (ip, 0, sizeof (ip[0])); - ip->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (6 << 28); + ip->ip_version_traffic_class_and_flow_label = + clib_host_to_net_u32 (6 << 28); - if (! unformat (input, "%U: %U -> %U", - unformat_ip_protocol, &ip->protocol, - unformat_ip6_address, &ip->src_address, - unformat_ip6_address, &ip->dst_address)) + if (!unformat (input, "%U: %U -> %U", + unformat_ip_protocol, &ip->protocol, + unformat_ip6_address, &ip->src_address, + unformat_ip6_address, &ip->dst_address)) return 0; /* Parse options. */ @@ -291,7 +296,8 @@ uword unformat_ip6_header (unformat_input_t * input, va_list * args) int i; if (unformat (input, "tos %U", unformat_vlib_number, &i)) - ip->ip_version_traffic_class_and_flow_label |= clib_host_to_net_u32 ((i & 0xff) << 20); + ip->ip_version_traffic_class_and_flow_label |= + clib_host_to_net_u32 ((i & 0xff) << 20); else if (unformat (input, "hop-limit %U", unformat_vlib_number, &i)) ip->hop_limit = i; @@ -303,12 +309,12 @@ uword unformat_ip6_header (unformat_input_t * input, va_list * args) /* Recurse into next protocol layer. */ { - ip_main_t * im = &ip_main; - ip_protocol_info_t * pi = ip_get_protocol_info (im, ip->protocol); + ip_main_t *im = &ip_main; + ip_protocol_info_t *pi = ip_get_protocol_info (im, ip->protocol); if (pi && pi->unformat_header) { - if (! unformat_user (input, pi->unformat_header, result)) + if (!unformat_user (input, pi->unformat_header, result)) return 0; /* Result may have moved. */ @@ -316,29 +322,35 @@ uword unformat_ip6_header (unformat_input_t * input, va_list * args) } } - ip->payload_length = clib_host_to_net_u16 (vec_len (*result) - (old_length + sizeof (ip[0]))); + ip->payload_length = + clib_host_to_net_u16 (vec_len (*result) - (old_length + sizeof (ip[0]))); return 1; } /* Parse an IP46 address. */ -uword unformat_ip46_address (unformat_input_t * input, va_list * args) +uword +unformat_ip46_address (unformat_input_t * input, va_list * args) { ip46_address_t *ip46 = va_arg (*args, ip46_address_t *); ip46_type_t type = va_arg (*args, ip46_type_t); if ((type != IP46_TYPE_IP6) && - unformat(input, "%U", unformat_ip4_address, &ip46->ip4)) { - ip46_address_mask_ip4(ip46); - return 1; - } else if ((type != IP46_TYPE_IP4) && - unformat(input, "%U", unformat_ip6_address, &ip46->ip6)) { - return 1; - } + unformat (input, "%U", unformat_ip4_address, &ip46->ip4)) + { + ip46_address_mask_ip4 (ip46); + return 1; + } + else if ((type != IP46_TYPE_IP4) && + unformat (input, "%U", unformat_ip6_address, &ip46->ip6)) + { + return 1; + } return 0; } /* Format an IP46 address. */ -u8 * format_ip46_address (u8 * s, va_list * args) +u8 * +format_ip46_address (u8 * s, va_list * args) { ip46_address_t *ip46 = va_arg (*args, ip46_address_t *); ip46_type_t type = va_arg (*args, ip46_type_t); @@ -346,18 +358,26 @@ u8 * format_ip46_address (u8 * s, va_list * args) switch (type) { - case IP46_TYPE_ANY: - is_ip4 = ip46_address_is_ip4(ip46); - break; - case IP46_TYPE_IP4: - is_ip4 = 1; - break; - case IP46_TYPE_IP6: - is_ip4 = 0; - break; + case IP46_TYPE_ANY: + is_ip4 = ip46_address_is_ip4 (ip46); + break; + case IP46_TYPE_IP4: + is_ip4 = 1; + break; + case IP46_TYPE_IP6: + is_ip4 = 0; + break; } return is_ip4 ? - format(s, "%U", format_ip4_address, &ip46->ip4): - format(s, "%U", format_ip6_address, &ip46->ip6); + format (s, "%U", format_ip4_address, &ip46->ip4) : + format (s, "%U", format_ip6_address, &ip46->ip6); } + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ |