/* *------------------------------------------------------------------ * interface_api.c - vnet interface api * * Copyright (c) 2016 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *------------------------------------------------------------------ */ #include #include #include #include #include #include #include #include #include #include #include #include #define vl_typedefs /* define message structures */ #include #undef vl_typedefs #define vl_endianfun /* define message structures */ #include #undef vl_endianfun /* instantiate all the print functions we know about */ #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) #define vl_printfun #include #undef vl_printfun #include vpe_api_main_t vpe_api_main; #define foreach_vpe_api_msg \ _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \ _(HW_INTERFACE_SET_MTU, hw_interface_set_mtu) \ _(SW_INTERFACE_SET_MTU, sw_interface_set_mtu) \ _(WANT_INTERFACE_EVENTS, want_interface_events) \ _(SW_INTERFACE_DUMP, sw_interface_dump) \ _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \ _(SW_INTERFACE_SET_RX_MODE, sw_interface_set_rx_mode) \ _(SW_INTERFACE_RX_PLACEMENT_DUMP, sw_interface_rx_placement_dump) \ _(SW_INTERFACE_SET_RX_PLACEMENT, sw_interface_set_rx_placement) \ _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \ _(SW_INTERFACE_GET_TABLE, sw_interface_get_table) \ _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \ _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \ _(SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del) \ _(SW_INTERFACE_SET_MAC_ADDRESS, sw_interface_set_mac_address) \ _(SW_INTERFACE_GET_MAC_ADDRESS, sw_interface_get_mac_address) \ _(CREATE_VLAN_SUBIF, create_vlan_subif) \ _(CREATE_SUBIF, create_subif) \ _(DELETE_SUBIF, delete_subif) \ _(CREATE_LOOPBACK, create_loopback) \ _(CREATE_LOOPBACK_INSTANCE, create_loopback_instance) \ _(DELETE_LOOPBACK, delete_loopback) \ _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \ _(COLLECT_DETAILED_INTERFACE_STATS, collect_detailed_interface_stats) \ _(SW_INTERFACE_SET_IP_DIRECTED_BROADCAST, \ sw_interface_set_ip_directed_broadcast) static void vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp) { vl_api_sw_interface_set_flags_reply_t *rmp; vnet_main_t *vnm = vnet_get_main (); int rv = 0; clib_error_t *error; u16 flags; VALIDATE_SW_IF_INDEX (mp); flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0; error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags); if (error) { rv = -1; clib_error_report (error); } BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY); } static void vl_api_hw_interface_set_mtu_t_handler (vl_api_hw_interface_set_mtu_t * mp) { vl_api_hw_interface_set_mtu_reply_t *rmp; vnet_main_t *vnm = vnet_get_main (); u32 sw_if_index = ntohl (mp->sw_if_index); u16 mtu = ntohs (mp->mtu); ethernet_main_t *em = ðernet_main; int rv = 0; VALIDATE_SW_IF_INDEX (mp); vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) { rv = VNET_API_ERROR_INVALID_VALUE; goto bad_sw_if_index; } vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, si->hw_if_index); ethernet_interface_t *eif = ethernet_get_interface (em, si->hw_if_index); if (!eif) { rv = VNET_API_ERROR_FEATURE_DISABLED; goto bad_sw_if_index; } if (mtu < hi->min_supported_packet_bytes) { rv = VNET_API_ERROR_INVALID_VALUE; goto bad_sw_if_index; } if (mtu > hi->max_supported_packet_bytes) { rv = VNET_API_ERROR_INVALID_VALUE; goto bad_sw_if_index; } vnet_hw_interface_set_mtu (vnm, si->hw_if_index, mtu); BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_HW_INTERFACE_SET_MTU_REPLY); } static void vl_api_sw_interface_set_mtu_t_handler (vl_api_sw_interface_set_mtu_t * mp) { vl_api_sw_interface_set_mtu_reply_t *rmp; vnet_main_t *vnm = vnet_get_main (); u32 sw_if_index = ntohl (mp->sw_if_index); int rv = 0; int i; u32 per_protocol_mtu[VNET_N_MTU]; VALIDATE_SW_IF_INDEX (mp); for (i = 0; i < VNET_N_MTU; i++) per_protocol_mtu[i] = ntohl (mp->mtu[i]); vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, per_protocol_mtu); BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_SW_INTERFACE_SET_MTU_REPLY); } static void vl_api_sw_interface_set_ip_directed_broadcast_t_handler (vl_api_sw_interface_set_ip_directed_broadcast_t * mp) { vl_api_sw_interface_set_ip_directed_broadcast_reply_t *rmp; u32 sw_if_index = ntohl (mp->sw_if_index); int rv = 0; VALIDATE_SW_IF_INDEX (mp); vnet_sw_interface_ip_directed_broadcast (vnet_get_main (), sw_if_index, mp->enable); BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_SW_INTERFACE_SET_IP_DIRECTED_BROADCAST_REPLY); } static void send_sw_interface_details (vpe_api_main_t * am, vl_api_registration_t * rp, vnet_sw_interface_t * swif, u8 * interface_name, u32 context) { vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index); vl_api_sw_interface_details_t *mp = vl_msg_api_alloc (sizeof (*mp)); clib_memset (mp, 0, sizeof (*mp)); mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS); mp->sw_if_index = ntohl (swif->sw_if_index); mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index); mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0; mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0; mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >> VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT); mp->link_speed = ntohl (hi->link_speed); mp->link_mtu = ntohs (hi->max_packet_bytes); mp->mtu[VNET_MTU_L3] = ntohl (swif->mtu[VNET_MTU_L3]); mp->mtu[VNET_MTU_IP4] = ntohl (swif->mtu[VNET_MTU_IP4]); mp->mtu[VNET_MTU_IP6] = ntohl (swif->mtu[VNET_MTU_IP6]); mp->mtu[VNET_MTU_MPLS] = ntohl (swif->mtu[VNET_MTU_MPLS]); mp->context = context; strncpy ((char *) mp->interface_name, (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1); /* Send the L2 address for ethernet physical intfcs */ if (swif->sup_sw_if_index == swif->sw_if_index && hi->hw_class_index == ethernet_hw_interface_class.index) { ethernet_main_t *em = ethernet_get_main (am->vlib_main); ethernet_interface_t *ei; ei = pool_elt_at_index (em->interfaces, hi->hw_instance); ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address)); clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address)); mp->l2_address_length = ntohl (sizeof (ei->address)); } else if (swif->sup_sw_if_index != swif->sw_if_index) { vnet_sub_interface_t *sub = &swif->sub; mp->sub_id = ntohl (sub->id); mp->sub_dot1ad = sub->eth.flags.dot1ad; mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2; mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id); mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id); mp->sub_exact_match = sub->eth.flags.exact_match; mp->sub_default = sub->eth.flags.default_sub; mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any; mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any; /* vlan tag rewrite data */ u32 vtr_op = L2_VTR_DISABLED; u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0; if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index, &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) { // error - default to disabled mp->vtr_op = ntohl (L2_VTR_DISABLED); clib_warning ("cannot get vlan tag rewrite for sw_if_index %d", swif->sw_if_index); } else { mp->vtr_op = ntohl (vtr_op); mp->vtr_push_dot1q = ntohl (vtr_push_dot1q); mp->vtr_tag1 = ntohl (vtr_tag1); mp->vtr_tag2 = ntohl (vtr_tag2); } } /* pbb tag rewrite data */ ethernet_header_t eth_hdr; u32 vtr_op = L2_VTR_DISABLED; u16 outer_tag = 0; u16 b_vlanid = 0; u32 i_sid = 0; clib_memset (ð_hdr, 0, sizeof (eth_hdr)); if (!l2pbb_get (am->vlib_main, am->vnet_main, swif->sw_if_index, &vtr_op, &outer_tag, ð_hdr, &b_vlanid, &i_sid)) { mp->sub_dot1ah = 1; clib_memcpy (mp->b_dmac, eth_hdr.dst_address, sizeof (eth_hdr.dst_address)); clib_memcpy (mp->b_smac, eth_hdr.src_address, sizeof (eth_hdr.src_address)); mp->b_vlanid = b_vlanid; mp->i_sid = i_sid; } u8 *tag = vnet_get_sw_interface_tag (vnet_get_main (), swif->sw_if_index); if (tag) strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1); vl_api_send_msg (rp, (u8 *) mp); } static void vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp) { vpe_api_main_t *am = &vpe_api_main; vnet_sw_interface_t *swif; vnet_interface_main_t *im = &am->vnet_main->interface_main; vl_api_registration_t *rp; rp = vl_api_client_index_to_registration (mp->client_index); if (rp == 0) { clib_warning ("Client %d AWOL", mp->client_index); return; } u8 *filter = 0, *name = 0; if (mp->name_filter_valid) { mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0; filter = format (0, "%s%c", mp->name_filter, 0); } char *strcasestr (char *, char *); /* lnx hdr file botch */ /* *INDENT-OFF* */ pool_foreach (swif, im->sw_interfaces, ({ if (!vnet_swif_is_api_visible (swif)) continue; vec_reset_length(name); name = format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main, swif, 0); if (filter && !strcasestr((char *) name, (char *) filter)) continue; send_sw_interface_details (am, rp, swif, name, mp->context); })); /* *INDENT-ON* */ vec_free (name); vec_free (filter); } static void vl_api_sw_interface_add_del_address_t_handler (vl_api_sw_interface_add_del_address_t * mp) { vlib_main_t *vm = vlib_get_main (); vnet_main_t *vnm = vnet_get_main (); vl_api_sw_interface_add_del_address_reply_t *rmp; int rv = 0; u32 is_del; clib_error_t *error = 0; VALIDATE_SW_IF_INDEX (mp); is_del = mp->is_add == 0; vnm->api_errno = 0; if (mp->del_all) ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index)); else if (mp->is_ipv6) error = ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index), (void *) mp->address, mp->address_length, is_del); else error = ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index), (void *) mp->address, mp->address_length, is_del); if (error) { rv = vnm->api_errno; clib_error_report (error); goto done; } BAD_SW_IF_INDEX_LABEL; done: REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY); } void stats_dslock_with_hint (int hint, int tag) __attribute__ ((weak)); void stats_dslock_with_hint (int hint, int tag) { } void stats_dsunlock (void) __attribute__ ((weak)); void stats_dsunlock (void) { } static void vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_ta
Feature Arcs
============

A significant number of vpp features are configurable on a per-interface
or per-system basis. Rather than ask feature coders to manually
construct the required graph arcs, we built a general mechanism to
manage these mechanics.

Specifically, feature arcs comprise ordered sets of graph nodes. Each
feature node in an arc is independently controlled. Feature arc nodes
are generally unaware of each other. Handing a packet to "the next
feature node" is quite inexpensive.

The feature arc implementation solves the problem of creating graph arcs
used for steering.

At the beginning of a feature arc, a bit of setup work is needed, but
only if at least one feature is enabled on the arc.

On a per-arc basis, individual feature definitions create a set of
ordering dependencies. Feature infrastructure performs a topological
sort of the ordering dependencies, to determine the actual feature
order. Missing dependencies **will** lead to runtime disorder. See
<https://gerrit.fd.io/r/#/c/12753> for an example.

If no partial order exists, vpp will refuse to run. Circular dependency
loops of the form "a then b, b then c, c then a" are impossible to
satisfy.

Adding a feature to an existing feature arc
-------------------------------------------

To nobody's great surprise, we set up feature arcs using the typical
"macro -> constructor function -> list of declarations" pattern:

```c
    VNET_FEATURE_INIT (mactime, static) =
    {
      .arc_name = "device-input",
      .node_name = "mactime",
      .runs_before = VNET_FEATURES ("ethernet-input"),
    };  
```

This creates a "mactime" feature on the "device-input" arc.

Once per frame, dig up the vnet\_feature\_config\_main\_t corresponding
to the "device-input" feature arc:

```c
    vnet_main_t *vnm = vnet_get_main ();
    vnet_interface_main_t *im = &vnm->interface_main;
    u8 arc = im->output_feature_arc_index;
    vnet_feature_config_main_t *fcm;

    fcm = vnet_feature_get_config_main (arc);
```

Note that in this case, we've stored the required arc index - assigned
by the feature infrastructure - in the vnet\_interface\_main\_t. Where
to put the arc index is a programmer's decision when creating a feature
arc.

Per packet, set next0 to steer packets to the next node they should
visit:

```c
    vnet_get_config_data (&fcm->config_main,
                          &b0->current_config_index /* value-result */, 
                          &next0, 0 /* # bytes of config data */);
```

Configuration data is per-feature arc, and is often unused. Note that
it's normal to reset next0 to divert packets elsewhere; often, to drop
them for cause:

```c
    next0 = MACTIME_NEXT_DROP;
    b0->error = node->errors[DROP_CAUSE];
```

Creating a feature arc
----------------------

Once again, we create feature arcs using constructor macros:

```c
    VNET_FEATURE_ARC_INIT (ip4_unicast, static) =
    {
      .arc_name = "ip4-unicast",
      .start_nodes = VNET_FEATURES ("ip4-input", "ip4-input-no-checksum"),
      .arc_index_ptr = &ip4_main.lookup_main.ucast_feature_arc_index,
    };  
```

In this case, we configure two arc start nodes to handle the
"hardware-verified ip checksum or not" cases. During initialization,
the feature infrastructure stores the arc index as shown.

In the head-of-arc node, do the following to send packets along the
feature arc:

```c
    ip_lookup_main_t *lm = &im->lookup_main;
    arc = lm->ucast_feature_arc_index;
```

Once per packet, initialize packet metadata to walk the feature arc:

```c
vnet_feature_arc_start (arc, sw_if_index0, &next, b0);
```

Enabling / Disabling features
-----------------------------

Simply call vnet_feature_enable_disable to enable or disable a specific
feature:

```c
    vnet_feature_enable_disable ("device-input", /* arc name */
                                 "mactime",      /* feature name */
           		             sw_if_index,    /* Interface sw_if_index */
                                 enable_disable, /* 1 => enable */
                                 0 /* (void *) feature_configuration */, 
                                 0 /* feature_configuration_nbytes */);
```

The feature_configuration opaque is seldom used. 

If you wish to make a feature a _de facto_ system-level concept, pass
sw_if_index=0 at all times. Sw_if_index 0 is always valid, and
corresponds to the "local" interface.

Related "show" commands
-----------------------

To display the entire set of features, use "show features [verbose]". The
verbose form displays arc indices, and feature indicies within the arcs

```
$ vppctl show features verbose
Available feature paths
<snip>
[14] ip4-unicast:
  [ 0]: nat64-out2in-handoff
  [ 1]: nat64-out2in
  [ 2]: nat44-ed-hairpin-dst
  [ 3]: nat44-hairpin-dst
  [ 4]: ip4-dhcp-client-detect
  [ 5]: nat44-out2in-fast
  [ 6]: nat44-in2out-fast
  [ 7]: nat44-handoff-classify
  [ 8]: nat44-out2in-worker-handoff
  [ 9]: nat44-in2out-worker-handoff
  [10]: nat44-ed-classify
  [11]: nat44-ed-out2in
  [12]: nat44-ed-in2out
  [13]: nat44-det-classify
  [14]: nat44-det-out2in
  [15]: nat44-det-in2out
  [16]: nat44-classify
  [17]: nat44-out2in
  [18]: nat44-in2out
  [19]: ip4-qos-record
  [20]: ip4-vxlan-gpe-bypass
  [21]: ip4-reassembly-feature
  [22]: ip4-not-enabled
  [23]: ip4-source-and-port-range-check-rx
  [24]: ip4-flow-classify
  [25]: ip4-inacl
  [26]: ip4-source-check-via-rx
  [27]: ip4-source-check-via-any
  [28]: ip4-policer-classify
  [29]: ipsec-input-ip4
  [30]: vpath-input-ip4
  [31]: ip4-vxlan-bypass
  [32]: ip4-lookup
<snip>
```

Here, we learn that the ip4-unicast feature arc has index 14, and that
e.g. ip4-inacl is the 25th feature in the generated partial order.

To display the features currently active on a specific interface,
use "show interface <name> features":

```
$ vppctl show interface GigabitEthernet3/0/0 features
Feature paths configured on GigabitEthernet3/0/0...
<snip>
ip4-unicast:
  nat44-out2in
<snip>
```

Table of Feature Arcs
---------------------

Simply search for name-strings to track down the arc definition, location of
the arc index, etc.

```
            |    Arc Name      |
            |------------------|
            | device-input     |
            | ethernet-output  |
            | interface-output |
            | ip4-drop         |
            | ip4-local        |
            | ip4-multicast    |
            | ip4-output       |
            | ip4-punt         |
            | ip4-unicast      |
            | ip6-drop         |
            | ip6-local        |
            | ip6-multicast    |
            | ip6-output       |
            | ip6-punt         |
            | ip6-unicast      |
            | mpls-input       |
            | mpls-output      |
            | nsh-output       |
```
rmp->context = mp->context; rmp->retval = htonl (rv); rmp->sw_if_index = htonl (sw_if_index); vl_api_send_msg (reg, (u8 *) rmp); } static void vl_api_create_subif_t_handler (vl_api_create_subif_t * mp) { vl_api_create_subif_reply_t *rmp; vnet_main_t *vnm = vnet_get_main (); u32 sw_if_index = ~0; int rv = 0; u32 sub_id; vnet_sw_interface_t *si; vnet_hw_interface_t *hi; vnet_sw_interface_t template; uword *p; vnet_interface_main_t *im = &vnm->interface_main; u64 sup_and_sub_key; clib_error_t *error; VALIDATE_SW_IF_INDEX (mp); si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index)); hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index)); if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) { rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED; goto out; } sw_if_index = si->sw_if_index; sub_id = ntohl (mp->sub_id); sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id; p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key); if (p) { if (CLIB_DEBUG > 0) clib_warning ("sup sw_if_index %d, sub id %d already exists\n", sw_if_index, sub_id); rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS; goto out; } clib_memset (&template, 0, sizeof (template)); template.type = VNET_SW_INTERFACE_TYPE_SUB; template.sup_sw_if_index = sw_if_index; template.sub.id = sub_id; template.sub.eth.flags.no_tags = mp->no_tags; template.sub.eth.flags.one_tag = mp->one_tag; template.sub.eth.flags.two_tags = mp->two_tags; template.sub.eth.flags.dot1ad = mp->dot1ad; template.sub.eth.flags.exact_match = mp->exact_match; template.sub.eth.flags.default_sub = mp->default_sub; template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any; template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any; template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id); template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id); error = vnet_create_sw_interface (vnm, &template, &sw_if_index); if (error) { clib_error_report (error); rv = VNET_API_ERROR_SUBIF_CREATE_FAILED; goto out; } u64 *kp = clib_mem_alloc (sizeof (*kp)); *kp = sup_and_sub_key; hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index); hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index); BAD_SW_IF_INDEX_LABEL; out: /* *INDENT-OFF* */ REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY, ({ rmp->sw_if_index = ntohl(sw_if_index); })); /* *INDENT-ON* */ } static void vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp) { vl_api_delete_subif_reply_t *rmp; int rv; rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index)); REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY); } static void vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t * mp) { vl_api_interface_name_renumber_reply_t *rmp; int rv = 0; VALIDATE_SW_IF_INDEX (mp); rv = vnet_interface_name_renumber (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance)); BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY); } static void vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp) { vl_api_create_loopback_reply_t *rmp; u32 sw_if_index; int rv; rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address, 0, 0); /* *INDENT-OFF* */ REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY, ({ rmp->sw_if_index = ntohl (sw_if_index); })); /* *INDENT-ON* */ } static void vl_api_create_loopback_instance_t_handler (vl_api_create_loopback_instance_t * mp) { vl_api_create_loopback_instance_reply_t *rmp; u32 sw_if_index; u8 is_specified = mp->is_specified; u32 user_instance = ntohl (mp->user_instance); int rv; rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address, is_specified, user_instance); /* *INDENT-OFF* */ REPLY_MACRO2(VL_API_CREATE_LOOPBACK_INSTANCE_REPLY, ({ rmp->sw_if_index = ntohl (sw_if_index); })); /* *INDENT-ON* */ } static void vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp) { vl_api_delete_loopback_reply_t *rmp; u32 sw_if_index; int rv; sw_if_index = ntohl (mp->sw_if_index); rv = vnet_delete_loopback_interface (sw_if_index); REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY); } static void vl_api_collect_detailed_interface_stats_t_handler (vl_api_collect_detailed_interface_stats_t * mp) { vl_api_collect_detailed_interface_stats_reply_t *rmp; int rv = 0; rv = vnet_sw_interface_stats_collect_enable_disable (ntohl (mp->sw_if_index), mp->enable_disable); REPLY_MACRO (VL_API_COLLECT_DETAILED_INTERFACE_STATS_REPLY); } /* * vpe_api_hookup * Add vpe's API message handlers to the table. * vlib has already mapped shared memory and * added the client registration handlers. * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() */ #define vl_msg_name_crc_list #include #undef vl_msg_name_crc_list static void setup_message_id_table (api_main_t * am) { #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); foreach_vl_msg_name_crc_interface; #undef _ } pub_sub_handler (interface_events, INTERFACE_EVENTS); static clib_error_t * interface_api_hookup (vlib_main_t * vm) { api_main_t *am = &api_main; #define _(N,n) \ vl_msg_api_set_handlers(VL_API_##N, #n, \ vl_api_##n##_t_handler, \ vl_noop_handler, \ vl_api_##n##_t_endian, \ vl_api_##n##_t_print, \ sizeof(vl_api_##n##_t), 1); foreach_vpe_api_msg; #undef _ /* * Set up the (msg_name, crc, message-id) table */ setup_message_id_table (am); return 0; } VLIB_API_INIT_FUNCTION (interface_api_hookup); /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */