-#undef _
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (0);
-#define _(a) else if (unformat (input, #a)) a=1;
- foreach_tcp_proto_field
-#undef _
- else
- break;
- }
-
-#define _(a) found_something += a;
- foreach_tcp_proto_field;
-#undef _
-
- if (found_something == 0)
- return 0;
-
- vec_validate (mask, sizeof (*tcp) - 1);
-
- tcp = (tcp_header_t *) mask;
-
-#define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
- foreach_tcp_proto_field;
-#undef _
-
- *maskp = mask;
- return 1;
-}
-
-uword
-unformat_udp_mask (unformat_input_t * input, va_list * args)
-{
- u8 **maskp = va_arg (*args, u8 **);
- u8 *mask = 0;
- u8 found_something = 0;
- udp_header_t *udp;
-
-#define _(a) u8 a=0;
- foreach_udp_proto_field;
-#undef _
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (0);
-#define _(a) else if (unformat (input, #a)) a=1;
- foreach_udp_proto_field
-#undef _
- else
- break;
- }
-
-#define _(a) found_something += a;
- foreach_udp_proto_field;
-#undef _
-
- if (found_something == 0)
- return 0;
-
- vec_validate (mask, sizeof (*udp) - 1);
-
- udp = (udp_header_t *) mask;
-
-#define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
- foreach_udp_proto_field;
-#undef _
-
- *maskp = mask;
- return 1;
-}
-
-uword
-unformat_l4_mask (unformat_input_t * input, va_list * args)
-{
- u8 **maskp = va_arg (*args, u8 **);
- u16 src_port = 0, dst_port = 0;
- tcpudp_header_t *tcpudp;
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
- return 1;
- else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
- return 1;
- else if (unformat (input, "src_port"))
- src_port = 0xFFFF;
- else if (unformat (input, "dst_port"))
- dst_port = 0xFFFF;
- else
- return 0;
- }
-
- if (!src_port && !dst_port)
- return 0;
-
- u8 *mask = 0;
- vec_validate (mask, sizeof (tcpudp_header_t) - 1);
-
- tcpudp = (tcpudp_header_t *) mask;
- tcpudp->src_port = src_port;
- tcpudp->dst_port = dst_port;
-
- *maskp = mask;
-
- return 1;
-}
-
-uword
-unformat_ip4_mask (unformat_input_t * input, va_list * args)
-{
- u8 **maskp = va_arg (*args, u8 **);
- u8 *mask = 0;
- u8 found_something = 0;
- ip4_header_t *ip;
-
-#define _(a) u8 a=0;
- foreach_ip4_proto_field;
-#undef _
- u8 version = 0;
- u8 hdr_length = 0;
-
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "version"))
- version = 1;
- else if (unformat (input, "hdr_length"))
- hdr_length = 1;
- else if (unformat (input, "src"))
- src_address = 1;
- else if (unformat (input, "dst"))
- dst_address = 1;
- else if (unformat (input, "proto"))
- protocol = 1;
-
-#define _(a) else if (unformat (input, #a)) a=1;
- foreach_ip4_proto_field
-#undef _
- else
- break;
- }
-
-#define _(a) found_something += a;
- foreach_ip4_proto_field;
-#undef _
-
- if (found_something == 0)
- return 0;
-
- vec_validate (mask, sizeof (*ip) - 1);
-
- ip = (ip4_header_t *) mask;
-
-#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
- foreach_ip4_proto_field;
-#undef _
-
- ip->ip_version_and_header_length = 0;
-
- if (version)
- ip->ip_version_and_header_length |= 0xF0;
-
- if (hdr_length)
- ip->ip_version_and_header_length |= 0x0F;
-
- *maskp = mask;
- return 1;
-}
-
-#define foreach_ip6_proto_field \
-_(src_address) \
-_(dst_address) \
-_(payload_length) \
-_(hop_limit) \
-_(protocol)
-
-uword
-unformat_ip6_mask (unformat_input_t * input, va_list * args)
-{
- u8 **maskp = va_arg (*args, u8 **);
- u8 *mask = 0;
- u8 found_something = 0;
- ip6_header_t *ip;
- u32 ip_version_traffic_class_and_flow_label;
-
-#define _(a) u8 a=0;
- foreach_ip6_proto_field;
-#undef _
- u8 version = 0;
- u8 traffic_class = 0;
- u8 flow_label = 0;
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "version"))
- version = 1;
- else if (unformat (input, "traffic-class"))
- traffic_class = 1;
- else if (unformat (input, "flow-label"))
- flow_label = 1;
- else if (unformat (input, "src"))
- src_address = 1;
- else if (unformat (input, "dst"))
- dst_address = 1;
- else if (unformat (input, "proto"))
- protocol = 1;
-
-#define _(a) else if (unformat (input, #a)) a=1;
- foreach_ip6_proto_field
-#undef _
- else
- break;
- }
-
-#define _(a) found_something += a;
- foreach_ip6_proto_field;
-#undef _
-
- if (found_something == 0)
- return 0;
-
- vec_validate (mask, sizeof (*ip) - 1);
-
- ip = (ip6_header_t *) mask;
-
-#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
- foreach_ip6_proto_field;
-#undef _
-
- ip_version_traffic_class_and_flow_label = 0;
-
- if (version)
- ip_version_traffic_class_and_flow_label |= 0xF0000000;
-
- if (traffic_class)
- ip_version_traffic_class_and_flow_label |= 0x0FF00000;
-
- if (flow_label)
- ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
-
- ip->ip_version_traffic_class_and_flow_label =
- clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
-
- *maskp = mask;
- return 1;
-}
-
-uword
-unformat_l3_mask (unformat_input_t * input, va_list * args)
-{
- u8 **maskp = va_arg (*args, u8 **);
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
- return 1;
- else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
- return 1;
- else
- break;
- }
- return 0;
-}
-
-uword
-unformat_l2_mask (unformat_input_t * input, va_list * args)
-{
- u8 **maskp = va_arg (*args, u8 **);
- u8 *mask = 0;
- u8 src = 0;
- u8 dst = 0;
- u8 proto = 0;
- u8 tag1 = 0;
- u8 tag2 = 0;
- u8 ignore_tag1 = 0;
- u8 ignore_tag2 = 0;
- u8 cos1 = 0;
- u8 cos2 = 0;
- u8 dot1q = 0;
- u8 dot1ad = 0;
- int len = 14;
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "src"))
- src = 1;
- else if (unformat (input, "dst"))
- dst = 1;
- else if (unformat (input, "proto"))
- proto = 1;
- else if (unformat (input, "tag1"))
- tag1 = 1;
- else if (unformat (input, "tag2"))
- tag2 = 1;
- else if (unformat (input, "ignore-tag1"))
- ignore_tag1 = 1;
- else if (unformat (input, "ignore-tag2"))
- ignore_tag2 = 1;
- else if (unformat (input, "cos1"))
- cos1 = 1;
- else if (unformat (input, "cos2"))
- cos2 = 1;
- else if (unformat (input, "dot1q"))
- dot1q = 1;
- else if (unformat (input, "dot1ad"))
- dot1ad = 1;
- else
- break;
- }
- if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
- ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
- return 0;
-
- if (tag1 || ignore_tag1 || cos1 || dot1q)
- len = 18;
- if (tag2 || ignore_tag2 || cos2 || dot1ad)
- len = 22;
-
- vec_validate (mask, len - 1);
-
- if (dst)
- clib_memset (mask, 0xff, 6);
-
- if (src)
- clib_memset (mask + 6, 0xff, 6);
-
- if (tag2 || dot1ad)
- {
- /* inner vlan tag */
- if (tag2)
- {
- mask[19] = 0xff;
- mask[18] = 0x0f;
- }
- if (cos2)
- mask[18] |= 0xe0;
- if (proto)
- mask[21] = mask[20] = 0xff;
- if (tag1)
- {
- mask[15] = 0xff;
- mask[14] = 0x0f;
- }
- if (cos1)
- mask[14] |= 0xe0;
- *maskp = mask;
- return 1;
- }
- if (tag1 | dot1q)
- {
- if (tag1)
- {
- mask[15] = 0xff;
- mask[14] = 0x0f;
- }
- if (cos1)
- mask[14] |= 0xe0;
- if (proto)
- mask[16] = mask[17] = 0xff;
-
- *maskp = mask;
- return 1;
- }
- if (cos2)
- mask[18] |= 0xe0;
- if (cos1)
- mask[14] |= 0xe0;
- if (proto)
- mask[12] = mask[13] = 0xff;
-
- *maskp = mask;
- return 1;
-}
-
-uword
-unformat_classify_mask (unformat_input_t * input, va_list * args)
-{
- u8 **maskp = va_arg (*args, u8 **);
- u32 *skipp = va_arg (*args, u32 *);
- u32 *matchp = va_arg (*args, u32 *);
- u32 match;
- u8 *mask = 0;
- u8 *l2 = 0;
- u8 *l3 = 0;
- u8 *l4 = 0;
- int i;
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "hex %U", unformat_hex_string, &mask))
- ;
- else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
- ;
- else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
- ;
- else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
- ;
- else
- break;
- }
-
- if (l4 && !l3)
- {
- vec_free (mask);
- vec_free (l2);
- vec_free (l4);
- return 0;
- }
-
- if (mask || l2 || l3 || l4)
- {
- if (l2 || l3 || l4)
- {
- /* "With a free Ethernet header in every package" */
- if (l2 == 0)
- vec_validate (l2, 13);
- mask = l2;
- if (vec_len (l3))
- {
- vec_append (mask, l3);
- vec_free (l3);
- }
- if (vec_len (l4))
- {
- vec_append (mask, l4);
- vec_free (l4);
- }
- }
-
- /* Scan forward looking for the first significant mask octet */
- for (i = 0; i < vec_len (mask); i++)
- if (mask[i])
- break;
-
- /* compute (skip, match) params */
- *skipp = i / sizeof (u32x4);
- vec_delete (mask, *skipp * sizeof (u32x4), 0);
-
- /* Pad mask to an even multiple of the vector size */
- while (vec_len (mask) % sizeof (u32x4))
- vec_add1 (mask, 0);
-
- match = vec_len (mask) / sizeof (u32x4);
-
- for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
- {
- u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
- if (*tmp || *(tmp + 1))
- break;
- match--;
- }
- if (match == 0)
- clib_warning ("BUG: match 0");
-
- _vec_len (mask) = match * sizeof (u32x4);
-
- *matchp = match;
- *maskp = mask;
-
- return 1;
- }
-
- return 0;
-}
-#endif /* VPP_API_TEST_BUILTIN */
-
-#define foreach_l2_next \
-_(drop, DROP) \
-_(ethernet, ETHERNET_INPUT) \
-_(ip4, IP4_INPUT) \
-_(ip6, IP6_INPUT)
-
-uword
-unformat_l2_next_index (unformat_input_t * input, va_list * args)
-{
- u32 *miss_next_indexp = va_arg (*args, u32 *);
- u32 next_index = 0;
- u32 tmp;
-
-#define _(n,N) \
- if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
- foreach_l2_next;
-#undef _
-
- if (unformat (input, "%d", &tmp))
- {
- next_index = tmp;
- goto out;
- }
-
- return 0;
-
-out:
- *miss_next_indexp = next_index;
- return 1;
-}
-
-#define foreach_ip_next \
-_(drop, DROP) \
-_(local, LOCAL) \
-_(rewrite, REWRITE)
-
-uword
-api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
-{
- u32 *miss_next_indexp = va_arg (*args, u32 *);
- u32 next_index = 0;
- u32 tmp;
-
-#define _(n,N) \
- if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
- foreach_ip_next;
-#undef _
-
- if (unformat (input, "%d", &tmp))
- {
- next_index = tmp;
- goto out;
- }
-
- return 0;
-
-out:
- *miss_next_indexp = next_index;
- return 1;
-}
-
-#define foreach_acl_next \
-_(deny, DENY)
-
-uword
-api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
-{
- u32 *miss_next_indexp = va_arg (*args, u32 *);
- u32 next_index = 0;
- u32 tmp;
-
-#define _(n,N) \
- if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
- foreach_acl_next;
-#undef _
-
- if (unformat (input, "permit"))
- {
- next_index = ~0;
- goto out;
- }
- else if (unformat (input, "%d", &tmp))