47 u32 max_zero_run = 0, this_zero_run = 0;
48 int max_zero_run_index = -1, this_zero_run_index = 0;
49 int in_zero_run = 0,
i;
50 int last_double_colon = 0;
63 this_zero_run_index =
i;
71 if (this_zero_run > max_zero_run && this_zero_run > 1)
73 max_zero_run_index = this_zero_run_index;
74 max_zero_run = this_zero_run;
84 if (this_zero_run > max_zero_run && this_zero_run > 1)
86 max_zero_run_index = this_zero_run_index;
87 max_zero_run = this_zero_run;
93 if (
i == max_zero_run_index)
96 i += max_zero_run - 1;
97 last_double_colon = 1;
102 (last_double_colon ||
i == 0) ?
"" :
":",
103 clib_net_to_host_u16 (a->
as_u16[
i]));
104 last_double_colon = 0;
116 u8 l = va_arg (*args,
u32);
126 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
127 uword c, n_colon, double_colon_index;
129 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
130 double_colon_index =
ARRAY_LEN (hex_quads);
134 if (c >=
'0' && c <=
'9')
136 else if (c >=
'a' && c <=
'f')
137 hex_digit = c + 10 -
'a';
138 else if (c >=
'A' && c <=
'F')
139 hex_digit = c + 10 -
'A';
140 else if (c ==
':' && n_colon < 2)
149 if (n_hex_quads >=
ARRAY_LEN (hex_quads))
154 hex_quad = (hex_quad << 4) | hex_digit;
157 if (n_hex_digits >= 4)
168 if (double_colon_index <
ARRAY_LEN (hex_quads))
170 double_colon_index = n_hex_quads;
173 if (n_colon > 0 && n_hex_digits > 0)
175 hex_quads[n_hex_quads++] = hex_quad;
181 if (n_hex_digits > 0)
182 hex_quads[n_hex_quads++] = hex_quad;
188 if (double_colon_index <
ARRAY_LEN (hex_quads))
192 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
193 hex_quads[n_zero + i] = hex_quads[i];
195 for (i = 0; i < n_zero; i++)
198 hex_quads[double_colon_index +
i] = 0;
208 for (i = 0; i <
ARRAY_LEN (hex_quads); i++)
209 result->
as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
220 u32 max_header_bytes = va_arg (*args,
u32);
221 u32 i, ip_version, traffic_class, flow_label;
225 if (max_header_bytes <
sizeof (ip[0]))
226 return format (s,
"IP header truncated");
231 s =
format (s,
"%U: %U -> %U",
237 ip_version = (i >> 28);
238 traffic_class = (i >> 20) & 0xff;
246 "\n%Utos 0x%02x, flow label 0x%x, hop limit %d, payload length %d",
251 if (max_header_bytes != 0 &&
sizeof (ip[0]) < max_header_bytes)
260 max_header_bytes - sizeof (ip[0]));
270 u8 **result = va_arg (*args,
u8 **);
278 old_length =
vec_len (*result);
279 vec_add2 (*result, p,
sizeof (ip[0]));
283 memset (ip, 0,
sizeof (ip[0]));
285 clib_host_to_net_u32 (6 << 28);
287 if (!
unformat (input,
"%U: %U -> %U",
300 clib_host_to_net_u32 ((i & 0xff) << 20);
321 ip = (
void *) *result + old_length;
326 clib_host_to_net_u16 (
vec_len (*result) - (old_length +
sizeof (ip[0])));
335 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
355 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
static uword pow2_mask(uword x)
#define ip46_address_mask_ip4(ip46)
static ip_protocol_info_t * ip_get_protocol_info(ip_main_t *im, u32 protocol)
format_function_t * format_header
#define ip46_address_is_ip4(ip46)
unformat_function_t * unformat_header
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)