-static int
-api_sr_tunnel_add_del (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_sr_tunnel_add_del_t *mp;
- f64 timeout;
- int is_del = 0;
- int pl_index;
- ip6_address_t src_address;
- int src_address_set = 0;
- ip6_address_t dst_address;
- u32 dst_mask_width;
- int dst_address_set = 0;
- u16 flags = 0;
- u32 rx_table_id = 0;
- u32 tx_table_id = 0;
- ip6_address_t *segments = 0;
- ip6_address_t *this_seg;
- ip6_address_t *tags = 0;
- ip6_address_t *this_tag;
- ip6_address_t next_address, tag;
- u8 *name = 0;
- u8 *policy_name = 0;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "del"))
- is_del = 1;
- else if (unformat (i, "name %s", &name))
- ;
- else if (unformat (i, "policy %s", &policy_name))
- ;
- else if (unformat (i, "rx_fib_id %d", &rx_table_id))
- ;
- else if (unformat (i, "tx_fib_id %d", &tx_table_id))
- ;
- else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
- src_address_set = 1;
- else if (unformat (i, "dst %U/%d",
- unformat_ip6_address, &dst_address, &dst_mask_width))
- dst_address_set = 1;
- else if (unformat (i, "next %U", unformat_ip6_address, &next_address))
- {
- vec_add2 (segments, this_seg, 1);
- clib_memcpy (this_seg->as_u8, next_address.as_u8,
- sizeof (*this_seg));
- }
- else if (unformat (i, "tag %U", unformat_ip6_address, &tag))
- {
- vec_add2 (tags, this_tag, 1);
- clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
- }
- else if (unformat (i, "clean"))
- flags |= IP6_SR_HEADER_FLAG_CLEANUP;
- else if (unformat (i, "protected"))
- flags |= IP6_SR_HEADER_FLAG_PROTECTED;
- else if (unformat (i, "InPE %d", &pl_index))
- {
- if (pl_index <= 0 || pl_index > 4)
- {
- pl_index_range_error:
- errmsg ("pl index %d out of range", pl_index);
- return -99;
- }
- flags |=
- IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3 * (pl_index - 1));
- }
- else if (unformat (i, "EgPE %d", &pl_index))
- {
- if (pl_index <= 0 || pl_index > 4)
- goto pl_index_range_error;
- flags |=
- IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3 * (pl_index - 1));
- }
- else if (unformat (i, "OrgSrc %d", &pl_index))
- {
- if (pl_index <= 0 || pl_index > 4)
- goto pl_index_range_error;
- flags |=
- IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3 * (pl_index - 1));
- }
- else
- break;
- }
-
- if (!src_address_set)
- {
- errmsg ("src address required");
- return -99;
- }
-
- if (!dst_address_set)
- {
- errmsg ("dst address required");
- return -99;
- }
-
- if (!segments)
- {
- errmsg ("at least one sr segment required");
- return -99;
- }
-
- M2 (SR_TUNNEL_ADD_DEL, mp,
- vec_len (segments) * sizeof (ip6_address_t)
- + vec_len (tags) * sizeof (ip6_address_t));
-
- clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
- clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
- mp->dst_mask_width = dst_mask_width;
- mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
- mp->n_segments = vec_len (segments);
- mp->n_tags = vec_len (tags);
- mp->is_add = is_del == 0;
- clib_memcpy (mp->segs_and_tags, segments,
- vec_len (segments) * sizeof (ip6_address_t));
- clib_memcpy (mp->segs_and_tags +
- vec_len (segments) * sizeof (ip6_address_t), tags,
- vec_len (tags) * sizeof (ip6_address_t));
-
- mp->outer_vrf_id = ntohl (rx_table_id);
- mp->inner_vrf_id = ntohl (tx_table_id);
- memcpy (mp->name, name, vec_len (name));
- memcpy (mp->policy_name, policy_name, vec_len (policy_name));
-
- vec_free (segments);
- vec_free (tags);
-
- S (mp);
- W;
- /* NOTREACHED */
-}
-
-static int
-api_sr_policy_add_del (vat_main_t * vam)
-{
- unformat_input_t *input = vam->input;
- vl_api_sr_policy_add_del_t *mp;
- f64 timeout;
- int is_del = 0;
- u8 *name = 0;
- u8 *tunnel_name = 0;
- u8 **tunnel_names = 0;
-
- int name_set = 0;
- int tunnel_set = 0;
- int j = 0;
- int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
- int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "del"))
- is_del = 1;
- else if (unformat (input, "name %s", &name))
- name_set = 1;
- else if (unformat (input, "tunnel %s", &tunnel_name))
- {
- if (tunnel_name)
- {
- vec_add1 (tunnel_names, tunnel_name);
- /* For serializer:
- - length = #bytes to store in serial vector
- - +1 = byte to store that length
- */
- tunnel_names_length += (vec_len (tunnel_name) + 1);
- tunnel_set = 1;
- tunnel_name = 0;
- }
- }
- else
- break;
- }
-
- if (!name_set)
- {
- errmsg ("policy name required");
- return -99;
- }
-
- if ((!tunnel_set) && (!is_del))
- {
- errmsg ("tunnel name required");
- return -99;
- }
-
- M2 (SR_POLICY_ADD_DEL, mp, tunnel_names_length);
-
-
-
- mp->is_add = !is_del;
-
- memcpy (mp->name, name, vec_len (name));
- // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
- u8 *serial_orig = 0;
- vec_validate (serial_orig, tunnel_names_length);
- *serial_orig = vec_len (tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
- serial_orig += 1; // Move along one byte to store the length of first tunnel_name
-
- for (j = 0; j < vec_len (tunnel_names); j++)
- {
- tun_name_len = vec_len (tunnel_names[j]);
- *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
- serial_orig += 1; // Move along one byte to store the actual tunnel name
- memcpy (serial_orig, tunnel_names[j], tun_name_len);
- serial_orig += tun_name_len; // Advance past the copy
- }
- memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
-
- vec_free (tunnel_names);
- vec_free (tunnel_name);
-
- S (mp);
- W;
- /* NOTREACHED */
-}
-
-static int
-api_sr_multicast_map_add_del (vat_main_t * vam)
-{
- unformat_input_t *input = vam->input;
- vl_api_sr_multicast_map_add_del_t *mp;
- f64 timeout;
- int is_del = 0;
- ip6_address_t multicast_address;
- u8 *policy_name = 0;
- int multicast_address_set = 0;
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "del"))
- is_del = 1;
- else
- if (unformat
- (input, "address %U", unformat_ip6_address, &multicast_address))
- multicast_address_set = 1;
- else if (unformat (input, "sr-policy %s", &policy_name))
- ;
- else
- break;
- }
-
- if (!is_del && !policy_name)
- {
- errmsg ("sr-policy name required");
- return -99;
- }
-
-
- if (!multicast_address_set)
- {
- errmsg ("address required");
- return -99;
- }
-
- M (SR_MULTICAST_MAP_ADD_DEL, mp);
-
- mp->is_add = !is_del;
- memcpy (mp->policy_name, policy_name, vec_len (policy_name));
- clib_memcpy (mp->multicast_address, &multicast_address,
- sizeof (mp->multicast_address));
-
-
- vec_free (policy_name);
-
- S (mp);
- W;
- /* NOTREACHED */
-}
-
-
-#define foreach_tcp_proto_field \
-_(src_port) \
-_(dst_port)