1cb9cadadSEd Warnicke/*
2cb9cadadSEd Warnicke * Copyright (c) 2015 Cisco and/or its affiliates.
3cb9cadadSEd Warnicke * Licensed under the Apache License, Version 2.0 (the "License");
4cb9cadadSEd Warnicke * you may not use this file except in compliance with the License.
5cb9cadadSEd Warnicke * You may obtain a copy of the License at:
6cb9cadadSEd Warnicke *
7cb9cadadSEd Warnicke *     http://www.apache.org/licenses/LICENSE-2.0
8cb9cadadSEd Warnicke *
9cb9cadadSEd Warnicke * Unless required by applicable law or agreed to in writing, software
10cb9cadadSEd Warnicke * distributed under the License is distributed on an "AS IS" BASIS,
11cb9cadadSEd Warnicke * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cb9cadadSEd Warnicke * See the License for the specific language governing permissions and
13cb9cadadSEd Warnicke * limitations under the License.
14cb9cadadSEd Warnicke */
15cb9cadadSEd Warnicke/*
16cb9cadadSEd Warnicke * interface_funcs.h: VNET interfaces/sub-interfaces exported functions
17cb9cadadSEd Warnicke *
18cb9cadadSEd Warnicke * Copyright (c) 2008 Eliot Dresselhaus
19cb9cadadSEd Warnicke *
20cb9cadadSEd Warnicke * Permission is hereby granted, free of charge, to any person obtaining
21cb9cadadSEd Warnicke * a copy of this software and associated documentation files (the
22cb9cadadSEd Warnicke * "Software"), to deal in the Software without restriction, including
23cb9cadadSEd Warnicke * without limitation the rights to use, copy, modify, merge, publish,
24cb9cadadSEd Warnicke * distribute, sublicense, and/or sell copies of the Software, and to
25cb9cadadSEd Warnicke * permit persons to whom the Software is furnished to do so, subject to
26cb9cadadSEd Warnicke * the following conditions:
27cb9cadadSEd Warnicke *
28cb9cadadSEd Warnicke * The above copyright notice and this permission notice shall be
29cb9cadadSEd Warnicke * included in all copies or substantial portions of the Software.
30cb9cadadSEd Warnicke *
31cb9cadadSEd Warnicke *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32cb9cadadSEd Warnicke *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33cb9cadadSEd Warnicke *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34cb9cadadSEd Warnicke *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35cb9cadadSEd Warnicke *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36cb9cadadSEd Warnicke *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37cb9cadadSEd Warnicke *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38cb9cadadSEd Warnicke */
39cb9cadadSEd Warnicke
40cb9cadadSEd Warnicke#ifndef included_vnet_interface_funcs_h
41cb9cadadSEd Warnicke#define included_vnet_interface_funcs_h
42cb9cadadSEd Warnicke
43cb9cadadSEd Warnickealways_inline vnet_hw_interface_t *
44cb9cadadSEd Warnickevnet_get_hw_interface (vnet_main_t * vnm, u32 hw_if_index)
45ba868bb7SDave Barach{
46ba868bb7SDave Barach  return pool_elt_at_index (vnm->interface_main.hw_interfaces, hw_if_index);
47ba868bb7SDave Barach}
48cb9cadadSEd Warnicke
49a35cc14dSDamjan Marionalways_inline vnet_hw_interface_t *
503940de36SDave Barachvnet_get_hw_interface_or_null (vnet_main_t * vnm, u32 hw_if_index)
51a35cc14dSDamjan Marion{
52a35cc14dSDamjan Marion  if (!pool_is_free_index (vnm->interface_main.hw_interfaces, hw_if_index))
53a35cc14dSDamjan Marion    return pool_elt_at_index (vnm->interface_main.hw_interfaces, hw_if_index);
54a35cc14dSDamjan Marion  return (NULL);
55a35cc14dSDamjan Marion}
56a35cc14dSDamjan Marion
57cb9cadadSEd Warnickealways_inline vnet_sw_interface_t *
58cb9cadadSEd Warnickevnet_get_sw_interface (vnet_main_t * vnm, u32 sw_if_index)
59ba868bb7SDave Barach{
60ba868bb7SDave Barach  return pool_elt_at_index (vnm->interface_main.sw_interfaces, sw_if_index);
61ba868bb7SDave Barach}
62cb9cadadSEd Warnicke
6375152289SNeale Rannsalways_inline vnet_sw_interface_t *
643940de36SDave Barachvnet_get_sw_interface_or_null (vnet_main_t * vnm, u32 sw_if_index)
6575152289SNeale Ranns{
6675152289SNeale Ranns  if (!pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
6775152289SNeale Ranns    return pool_elt_at_index (vnm->interface_main.sw_interfaces, sw_if_index);
6875152289SNeale Ranns  return (NULL);
6975152289SNeale Ranns}
7075152289SNeale Ranns
71cb9cadadSEd Warnickealways_inline vnet_sw_interface_t *
72cb9cadadSEd Warnickevnet_get_hw_sw_interface (vnet_main_t * vnm, u32 hw_if_index)
73cb9cadadSEd Warnicke{
74ba868bb7SDave Barach  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
75ba868bb7SDave Barach  vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, hw->sw_if_index);
76cb9cadadSEd Warnicke  ASSERT (sw->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
77cb9cadadSEd Warnicke  return sw;
78cb9cadadSEd Warnicke}
79cb9cadadSEd Warnicke
80cb9cadadSEd Warnickealways_inline vnet_sw_interface_t *
81cb9cadadSEd Warnickevnet_get_sup_sw_interface (vnet_main_t * vnm, u32 sw_if_index)
82cb9cadadSEd Warnicke{
83ba868bb7SDave Barach  vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, sw_if_index);
8415ac81c1SPavel Kotucek  if (sw->type == VNET_SW_INTERFACE_TYPE_SUB ||
8517ff3c1fSNeale Ranns      sw->type == VNET_SW_INTERFACE_TYPE_PIPE ||
8615ac81c1SPavel Kotucek      sw->type == VNET_SW_INTERFACE_TYPE_P2P)
87cb9cadadSEd Warnicke    sw = vnet_get_sw_interface (vnm, sw->sup_sw_if_index);
88cb9cadadSEd Warnicke  return sw;
89cb9cadadSEd Warnicke}
90cb9cadadSEd Warnicke
91cb9cadadSEd Warnickealways_inline vnet_hw_interface_t *
92cb9cadadSEd Warnickevnet_get_sup_hw_interface (vnet_main_t * vnm, u32 sw_if_index)
93cb9cadadSEd Warnicke{
94ba868bb7SDave Barach  vnet_sw_interface_t *sw = vnet_get_sup_sw_interface (vnm, sw_if_index);
9517ff3c1fSNeale Ranns  ASSERT ((sw->type == VNET_SW_INTERFACE_TYPE_HARDWARE) ||
9617ff3c1fSNeale Ranns	  (sw->type == VNET_SW_INTERFACE_TYPE_PIPE));
97cb9cadadSEd Warnicke  return vnet_get_hw_interface (vnm, sw->hw_if_index);
98cb9cadadSEd Warnicke}
99cb9cadadSEd Warnicke
1003940de36SDave Barachalways_inline vnet_hw_interface_t *
1013940de36SDave Barachvnet_get_sup_hw_interface_api_visible_or_null (vnet_main_t * vnm,
1023940de36SDave Barach					       u32 sw_if_index)
1033940de36SDave Barach{
1043940de36SDave Barach  vnet_sw_interface_t *si;
1053940de36SDave Barach  if (PREDICT_FALSE (pool_is_free_index (vnm->interface_main.sw_interfaces,
1063940de36SDave Barach					 sw_if_index)))
1073940de36SDave Barach    return NULL;
1083940de36SDave Barach  si = vnet_get_sup_sw_interface (vnm, sw_if_index);
1093940de36SDave Barach  if (PREDICT_FALSE (si->flags & VNET_SW_INTERFACE_FLAG_HIDDEN))
1103940de36SDave Barach    return NULL;
1113940de36SDave Barach  ASSERT ((si->type == VNET_SW_INTERFACE_TYPE_HARDWARE) ||
1123940de36SDave Barach	  (si->type == VNET_SW_INTERFACE_TYPE_PIPE));
1133940de36SDave Barach  return vnet_get_hw_interface (vnm, si->hw_if_index);
1143940de36SDave Barach}
1153940de36SDave Barach
116cb9cadadSEd Warnickealways_inline vnet_hw_interface_class_t *
117cb9cadadSEd Warnickevnet_get_hw_interface_class (vnet_main_t * vnm, u32 hw_class_index)
118ba868bb7SDave Barach{
119ba868bb7SDave Barach  return vec_elt_at_index (vnm->interface_main.hw_interface_classes,
120ba868bb7SDave Barach			   hw_class_index);
121ba868bb7SDave Barach}
122cb9cadadSEd Warnicke
123cb9cadadSEd Warnickealways_inline vnet_device_class_t *
124cb9cadadSEd Warnickevnet_get_device_class (vnet_main_t * vnm, u32 dev_class_index)
125ba868bb7SDave Barach{
126ba868bb7SDave Barach  return vec_elt_at_index (vnm->interface_main.device_classes,
127ba868bb7SDave Barach			   dev_class_index);
128ba868bb7SDave Barach}
129cb9cadadSEd Warnicke
1307be864adSDave Barachstatic inline u8 *
1317be864adSDave Barachvnet_get_sw_interface_tag (vnet_main_t * vnm, u32 sw_if_index)
1327be864adSDave Barach{
1337be864adSDave Barach  uword *p;
1347be864adSDave Barach  p = hash_get (vnm->interface_tag_by_sw_if_index, sw_if_index);
1357be864adSDave Barach  if (p)
1367be864adSDave Barach    return ((u8 *) p[0]);
1377be864adSDave Barach  return 0;
1387be864adSDave Barach}
1397be864adSDave Barach
1407be864adSDave Barachstatic inline void
1417be864adSDave Barachvnet_set_sw_interface_tag (vnet_main_t * vnm, u8 * tag, u32 sw_if_index)
1427be864adSDave Barach{
1437be864adSDave Barach  uword *p;
1447be864adSDave Barach  p = hash_get (vnm->interface_tag_by_sw_if_index, sw_if_index);
1457be864adSDave Barach  if (p)
1467be864adSDave Barach    {
1477be864adSDave Barach      u8 *oldtag = (u8 *) p[0];
1487be864adSDave Barach      hash_unset (vnm->interface_tag_by_sw_if_index, sw_if_index);
1497be864adSDave Barach      vec_free (oldtag);
1507be864adSDave Barach    }
1517be864adSDave Barach
1527be864adSDave Barach  hash_set (vnm->interface_tag_by_sw_if_index, sw_if_index, tag);
1537be864adSDave Barach}
1547be864adSDave Barach
1557be864adSDave Barachstatic inline void
1567be864adSDave Barachvnet_clear_sw_interface_tag (vnet_main_t * vnm, u32 sw_if_index)
1577be864adSDave Barach{
1587be864adSDave Barach  uword *p;
1597be864adSDave Barach  p = hash_get (vnm->interface_tag_by_sw_if_index, sw_if_index);
1607be864adSDave Barach  if (p)
1617be864adSDave Barach    {
1627be864adSDave Barach      u8 *oldtag = (u8 *) p[0];
1637be864adSDave Barach      hash_unset (vnm->interface_tag_by_sw_if_index, sw_if_index);
1647be864adSDave Barach      vec_free (oldtag);
1657be864adSDave Barach    }
1667be864adSDave Barach}
1677be864adSDave Barach
1680053de63SNeale Ranns/**
1690053de63SNeale Ranns * Walk return code
1700053de63SNeale Ranns */
1710053de63SNeale Rannstypedef enum walk_rc_t_
1720053de63SNeale Ranns{
1730053de63SNeale Ranns  WALK_STOP,
1740053de63SNeale Ranns  WALK_CONTINUE,
1750053de63SNeale Ranns} walk_rc_t;
1760053de63SNeale Ranns
1778b37b873SNeale Ranns/**
1788b37b873SNeale Ranns * Call back walk type for walking SW indices on a HW interface
1798b37b873SNeale Ranns */
1800053de63SNeale Rannstypedef walk_rc_t (*vnet_hw_sw_interface_walk_t) (vnet_main_t * vnm,
1810053de63SNeale Ranns						  u32 sw_if_index, void *ctx);
1828b37b873SNeale Ranns
1838b37b873SNeale Ranns/**
1848b37b873SNeale Ranns * @brief
1858b37b873SNeale Ranns * Walk the SW interfaces on a HW interface - this is the super
1868b37b873SNeale Ranns * interface and any sub-interfaces.
1878b37b873SNeale Ranns */
1888b37b873SNeale Rannsvoid vnet_hw_interface_walk_sw (vnet_main_t * vnm,
1898b37b873SNeale Ranns				u32 hw_if_index,
1908b37b873SNeale Ranns				vnet_hw_sw_interface_walk_t fn, void *ctx);
1918b37b873SNeale Ranns
1920053de63SNeale Ranns/**
1930053de63SNeale Ranns * Call back walk type for walking SW indices on a HW interface
1940053de63SNeale Ranns */
1950053de63SNeale Rannstypedef walk_rc_t (*vnet_sw_interface_walk_t) (vnet_main_t * vnm,
1960053de63SNeale Ranns					       vnet_sw_interface_t * si,
1970053de63SNeale Ranns					       void *ctx);
1980053de63SNeale Ranns
1990053de63SNeale Ranns/**
2000053de63SNeale Ranns * @brief
2010053de63SNeale Ranns * Walk all the SW interfaces in the system.
2020053de63SNeale Ranns */
2030053de63SNeale Rannsvoid vnet_sw_interface_walk (vnet_main_t * vnm,
2040053de63SNeale Ranns			     vnet_sw_interface_walk_t fn, void *ctx);
2050053de63SNeale Ranns
20617ff3c1fSNeale Ranns
20717ff3c1fSNeale Ranns/**
20817ff3c1fSNeale Ranns * Call back walk type for walking all HW indices
20917ff3c1fSNeale Ranns */
21017ff3c1fSNeale Rannstypedef walk_rc_t (*vnet_hw_interface_walk_t) (vnet_main_t * vnm,
21117ff3c1fSNeale Ranns					       u32 hw_if_index, void *ctx);
21217ff3c1fSNeale Ranns
21317ff3c1fSNeale Ranns/**
21417ff3c1fSNeale Ranns * @brief
21517ff3c1fSNeale Ranns * Walk all the HW interface
21617ff3c1fSNeale Ranns */
21717ff3c1fSNeale Rannsvoid vnet_hw_interface_walk (vnet_main_t * vnm,
21817ff3c1fSNeale Ranns			     vnet_hw_interface_walk_t fn, void *ctx);
21917ff3c1fSNeale Ranns
220cb9cadadSEd Warnicke/* Register a hardware interface instance. */
221cb9cadadSEd Warnickeu32 vnet_register_interface (vnet_main_t * vnm,
222cb9cadadSEd Warnicke			     u32 dev_class_index,
223cb9cadadSEd Warnicke			     u32 dev_instance,
224ba868bb7SDave Barach			     u32 hw_class_index, u32 hw_instance);
225cb9cadadSEd Warnicke
226e5453d0fSJohn Lo/**
227e5453d0fSJohn Lo * Set interface output node - for interface registered without its output/tx
228e5453d0fSJohn Lo * nodes created because its VNET_DEVICE_CLASS did not specify any tx_function.
229e5453d0fSJohn Lo * This is typically the case for tunnel interfaces.
230e5453d0fSJohn Lo */
231e5453d0fSJohn Lovoid vnet_set_interface_output_node (vnet_main_t * vnm,
232e5453d0fSJohn Lo				     u32 hw_if_index, u32 node_index);
233e5453d0fSJohn Lo
234cb9cadadSEd Warnicke/* Creates a software interface given template. */
235ba868bb7SDave Barachclib_error_t *vnet_create_sw_interface (vnet_main_t * vnm,
236ba868bb7SDave Barach					vnet_sw_interface_t * template,
237ba868bb7SDave Barach					u32 * sw_if_index);
238cb9cadadSEd Warnicke
239cb9cadadSEd Warnickevoid vnet_delete_hw_interface (vnet_main_t * vnm, u32 hw_if_index);
240cb9cadadSEd Warnickevoid vnet_delete_sw_interface (vnet_main_t * vnm, u32 sw_if_index);
2410bfe5d8cSNeale Rannsint vnet_sw_interface_is_p2p (vnet_main_t * vnm, u32 sw_if_index);
2425f8f6173SNeale Rannsint vnet_sw_interface_is_nbma (vnet_main_t * vnm, u32 sw_if_index);
243cb9cadadSEd Warnicke
2441855b8e4SNeale Rannsalways_inline vnet_sw_interface_flags_t
245cb9cadadSEd Warnickevnet_sw_interface_get_flags (vnet_main_t * vnm, u32 sw_if_index)
246cb9cadadSEd Warnicke{
247ba868bb7SDave Barach  vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, sw_if_index);
248cb9cadadSEd Warnicke  return sw->flags;
249cb9cadadSEd Warnicke}
250cb9cadadSEd Warnicke
251a35cc14dSDamjan Marionalways_inline uword
252a35cc14dSDamjan Marionvnet_sw_interface_is_valid (vnet_main_t * vnm, u32 sw_if_index)
253a35cc14dSDamjan Marion{
254a35cc14dSDamjan Marion  return !pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index);
255a35cc14dSDamjan Marion}
256a35cc14dSDamjan Marion
257a35cc14dSDamjan Marionalways_inline uword
258a35cc14dSDamjan Marionvnet_hw_interface_is_valid (vnet_main_t * vnm, u32 hw_if_index)
259a35cc14dSDamjan Marion{
260a35cc14dSDamjan Marion  return !pool_is_free_index (vnm->interface_main.hw_interfaces, hw_if_index);
261a35cc14dSDamjan Marion}
262a35cc14dSDamjan Marion
263a35cc14dSDamjan Marion
264cb9cadadSEd Warnickealways_inline uword
265cb9cadadSEd Warnickevnet_sw_interface_is_admin_up (vnet_main_t * vnm, u32 sw_if_index)
266ba868bb7SDave Barach{
267ba868bb7SDave Barach  return (vnet_sw_interface_get_flags (vnm, sw_if_index) &
268ba868bb7SDave Barach	  VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
269ba868bb7SDave Barach}
270cb9cadadSEd Warnicke
2713212c570SEyal Barialways_inline uword
2723212c570SEyal Barivnet_swif_is_api_visible (vnet_sw_interface_t * si)
2733212c570SEyal Bari{
2743212c570SEyal Bari  return !(si->flags & VNET_SW_INTERFACE_FLAG_HIDDEN);
2753212c570SEyal Bari}
2763212c570SEyal Bari
2773212c570SEyal Barialways_inline uword
2783212c570SEyal Barivnet_sw_interface_is_api_visible (vnet_main_t * vnm, u32 sw_if_index)
2793212c570SEyal Bari{
2803212c570SEyal Bari  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
2813212c570SEyal Bari  return vnet_swif_is_api_visible (si);
2823212c570SEyal Bari}
2833212c570SEyal Bari
2843212c570SEyal Barialways_inline uword
2853212c570SEyal Barivnet_sw_interface_is_api_valid (vnet_main_t * vnm, u32 sw_if_index)
2863212c570SEyal Bari{
2873212c570SEyal Bari  return !pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)
2883212c570SEyal Bari    && vnet_sw_interface_is_api_visible (vnm, sw_if_index);
2893212c570SEyal Bari}
2903212c570SEyal Bari
29193cc3ee3SNeale Rannsalways_inline const u8 *
29293cc3ee3SNeale Rannsvnet_sw_interface_get_hw_address (vnet_main_t * vnm, u32 sw_if_index)
29393cc3ee3SNeale Ranns{
29493cc3ee3SNeale Ranns  vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
29593cc3ee3SNeale Ranns  return hw->hw_address;
29693cc3ee3SNeale Ranns}
29793cc3ee3SNeale Ranns
298cb9cadadSEd Warnickealways_inline uword
299cb9cadadSEd Warnickevnet_hw_interface_get_flags (vnet_main_t * vnm, u32 hw_if_index)
300cb9cadadSEd Warnicke{
301ba868bb7SDave Barach  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
302cb9cadadSEd Warnicke  return hw->flags;
303cb9cadadSEd Warnicke}
304cb9cadadSEd Warnicke
305d723161eSOle Troanalways_inline u32
306d723161eSOle Troanvnet_hw_interface_get_mtu (vnet_main_t * vnm, u32 hw_if_index)
307fe7d4a2eSDamjan Marion{
308fe7d4a2eSDamjan Marion  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
309d723161eSOle Troan  return hw->max_packet_bytes;
310fe7d4a2eSDamjan Marion}
311fe7d4a2eSDamjan Marion
312d723161eSOle Troanalways_inline u32
313d723161eSOle Troanvnet_sw_interface_get_mtu (vnet_main_t * vnm, u32 sw_if_index, vnet_mtu_t af)
314b80c536eSNeale Ranns{
315d723161eSOle Troan  vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, sw_if_index);
316d723161eSOle Troan  u32 mtu;
317d723161eSOle Troan  mtu = sw->mtu[af] > 0 ? sw->mtu[af] : sw->mtu[VNET_MTU_L3];
318d723161eSOle Troan  if (mtu == 0)
319d723161eSOle Troan    return 9000;		/* $$$ Deal with interface-types not setting MTU */
320d723161eSOle Troan  return mtu;
321b80c536eSNeale Ranns}
322b80c536eSNeale Ranns
323cb9cadadSEd Warnickealways_inline uword
324cb9cadadSEd Warnickevnet_hw_interface_is_link_up (vnet_main_t * vnm, u32 hw_if_index)
325ba868bb7SDave Barach{
3263e2e1907SNeale Ranns  return ((vnet_hw_interface_get_flags (vnm, hw_if_index) &
3273e2e1907SNeale Ranns	   VNET_HW_INTERFACE_FLAG_LINK_UP) != 0);
3283e2e1907SNeale Ranns}
3293e2e1907SNeale Ranns
3303e2e1907SNeale Rannsalways_inline uword
3313e2e1907SNeale Rannsvnet_sw_interface_is_link_up (vnet_main_t * vnm, u32 sw_if_index)
3323e2e1907SNeale Ranns{
3333e2e1907SNeale Ranns  vnet_sw_interface_t *sw = vnet_get_sup_sw_interface (vnm, sw_if_index);
3343e2e1907SNeale Ranns
3353e2e1907SNeale Ranns  return (vnet_hw_interface_is_link_up (vnm, sw->hw_if_index));
3363e2e1907SNeale Ranns}
3373e2e1907SNeale Ranns
3383e2e1907SNeale Rannsalways_inline uword
3393e2e1907SNeale Rannsvnet_sw_interface_is_up (vnet_main_t * vnm, u32 sw_if_index)
3403e2e1907SNeale Ranns{
3413e2e1907SNeale Ranns  return (vnet_sw_interface_is_admin_up (vnm, sw_if_index) &&
3423e2e1907SNeale Ranns	  vnet_sw_interface_is_link_up (vnm, sw_if_index));
343ba868bb7SDave Barach}
344cb9cadadSEd Warnicke
345cb9cadadSEd Warnickealways_inline vlib_frame_t *
346cb9cadadSEd Warnickevnet_get_frame_to_sw_interface (vnet_main_t * vnm, u32 sw_if_index)
347cb9cadadSEd Warnicke{
348ba868bb7SDave Barach  vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
349ac0932d2SSteven  return vlib_get_frame_to_node (vlib_get_main (), hw->output_node_index);
350cb9cadadSEd Warnicke}
351cb9cadadSEd Warnicke
352cb9cadadSEd Warnickealways_inline void
353ba868bb7SDave Barachvnet_put_frame_to_sw_interface (vnet_main_t * vnm, u32 sw_if_index,
354ba868bb7SDave Barach				vlib_frame_t * f)
355cb9cadadSEd Warnicke{
356ba868bb7SDave Barach  vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
357ac0932d2SSteven  return vlib_put_frame_to_node (vlib_get_main (), hw->output_node_index, f);
358cb9cadadSEd Warnicke}
359cb9cadadSEd Warnicke
3605100aa9cSDamjan Marionalways_inline void
3615100aa9cSDamjan Marionvnet_hw_interface_set_link_speed (vnet_main_t * vnm, u32 hw_if_index,
3625100aa9cSDamjan Marion				  u32 link_speed)
3635100aa9cSDamjan Marion{
3645100aa9cSDamjan Marion  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
3655100aa9cSDamjan Marion  hw->link_speed = link_speed;
3665100aa9cSDamjan Marion}
3675100aa9cSDamjan Marion
368cb9cadadSEd Warnicke/* Change interface flags (e.g. up, down, enable, disable). */
369ba868bb7SDave Barachclib_error_t *vnet_hw_interface_set_flags (vnet_main_t * vnm, u32 hw_if_index,
3706e43e068SNeale Ranns					   vnet_hw_interface_flags_t flags);
371cb9cadadSEd Warnicke
372cb9cadadSEd Warnicke/* Change interface flags (e.g. up, down, enable, disable). */
373ba868bb7SDave Barachclib_error_t *vnet_sw_interface_set_flags (vnet_main_t * vnm, u32 sw_if_index,
3746e43e068SNeale Ranns					   vnet_sw_interface_flags_t flags);
375cb9cadadSEd Warnicke
376c87b66c8SNeale Rannsvoid vnet_sw_interface_admin_up (vnet_main_t * vnm, u32 sw_if_index);
377c87b66c8SNeale Rannsvoid vnet_sw_interface_admin_down (vnet_main_t * vnm, u32 sw_if_index);
378c87b66c8SNeale Ranns
379cb9cadadSEd Warnicke/* Change interface class. */
380ba868bb7SDave Barachclib_error_t *vnet_hw_interface_set_class (vnet_main_t * vnm, u32 hw_if_index,
381ba868bb7SDave Barach					   u32 new_hw_class_index);
382cb9cadadSEd Warnicke
383cb9cadadSEd Warnicke/* Redirect rx pkts to node */
384cb9cadadSEd Warnickeint vnet_hw_interface_rx_redirect_to_node (vnet_main_t * vnm, u32 hw_if_index,
385ba868bb7SDave Barach					   u32 node_index);
386cb9cadadSEd Warnicke
387ba868bb7SDave Barachvoid vnet_hw_interface_init_for_class (vnet_main_t * vnm, u32 hw_if_index,
388ba868bb7SDave Barach				       u32 hw_class_index, u32 hw_instance);
389cb9cadadSEd Warnicke
390608d1edfSSean Hope/* Rename interface */
391ba868bb7SDave Barachclib_error_t *vnet_rename_interface (vnet_main_t * vnm, u32 hw_if_index,
392ba868bb7SDave Barach				     char *new_name);
393608d1edfSSean Hope
394e0792fdfSMatthew Smith/* Add/delete secondary interface mac address*/
395e0792fdfSMatthew Smithclib_error_t *vnet_hw_interface_add_del_mac_address (vnet_main_t * vnm,
396e0792fdfSMatthew Smith						     u32 hw_if_index,
397e0792fdfSMatthew Smith						     const u8 * mac_address,
398e0792fdfSMatthew Smith						     u8 is_add);
399e0792fdfSMatthew Smith
400c631f2deSPavel Kotucek/* Change interface mac address*/
401c631f2deSPavel Kotucekclib_error_t *vnet_hw_interface_change_mac_address (vnet_main_t * vnm,
402c631f2deSPavel Kotucek						    u32 hw_if_index,
4038f8994adSNeale Ranns						    const u8 * mac_address);
404c631f2deSPavel Kotucek
405ad8015beSSteven/* Change rx-mode */
406ad8015beSStevenclib_error_t *set_hw_interface_change_rx_mode (vnet_main_t * vnm,
407ad8015beSSteven					       u32 hw_if_index,
408ad8015beSSteven					       u8 queue_id_valid,
409ad8015beSSteven					       u32 queue_id,
410ad8015beSSteven					       vnet_hw_interface_rx_mode
411ad8015beSSteven					       mode);
412ad8015beSSteven
41354f7c51fSMohsin Kazmi/* Set rx-placement on the interface */
41454f7c51fSMohsin Kazmiclib_error_t *set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
41554f7c51fSMohsin Kazmi					     u32 thread_index, u8 is_main);
41654f7c51fSMohsin Kazmi
417fe7d4a2eSDamjan Marion/* Set the MTU on the HW interface */
418fe7d4a2eSDamjan Marionvoid vnet_hw_interface_set_mtu (vnet_main_t * vnm, u32 hw_if_index, u32 mtu);
419ffd78d1eSNeale Ranns
420d723161eSOle Troan/* Set the MTU on the SW interface */
421d723161eSOle Troanvoid vnet_sw_interface_set_mtu (vnet_main_t * vnm, u32 sw_if_index, u32 mtu);
422d723161eSOle Troanvoid vnet_sw_interface_set_protocol_mtu (vnet_main_t * vnm, u32 sw_if_index,
423d723161eSOle Troan					 u32 mtu[]);
424d723161eSOle Troan
4252ae2bc53SNeale Ranns/* update the unnumbered state of an interface */
4262ae2bc53SNeale Rannsvoid vnet_sw_interface_update_unnumbered (u32 sw_if_index,
4272ae2bc53SNeale Ranns					  u32 ip_sw_if_index, u8 enable);
4282ae2bc53SNeale Ranns
429871dc428SNeale Rannsint vnet_sw_interface_stats_collect_enable_disable (u32 sw_if_index,
430871dc428SNeale Ranns						    u8 enable);
4311855b8e4SNeale Rannsvoid vnet_sw_interface_ip_directed_broadcast (vnet_main_t * vnm,
4321855b8e4SNeale Ranns					      u32 sw_if_index, u8 enable);
433871dc428SNeale Ranns
434cb9cadadSEd Warnicke/* Formats sw/hw interface. */
435cb9cadadSEd Warnickeformat_function_t format_vnet_hw_interface;
4364403690cSDamjan Marionformat_function_t format_vnet_hw_interface_rx_mode;
437a35cc14dSDamjan Marionformat_function_t format_vnet_hw_if_index_name;
438cb9cadadSEd Warnickeformat_function_t format_vnet_sw_interface;
439cb9cadadSEd Warnickeformat_function_t format_vnet_sw_interface_name;
440679ea795SSean Hopeformat_function_t format_vnet_sw_interface_name_override;
441cb9cadadSEd Warnickeformat_function_t format_vnet_sw_if_index_name;
442cb9cadadSEd Warnickeformat_function_t format_vnet_sw_interface_flags;
443cb9cadadSEd Warnicke
444cb9cadadSEd Warnicke/* Parses sw/hw interface name -> index. */
445cb9cadadSEd Warnickeunformat_function_t unformat_vnet_sw_interface;
446cb9cadadSEd Warnickeunformat_function_t unformat_vnet_hw_interface;
44708eb2bb2SDave Barachunformat_function_t unformat_vnet_buffer_flags;
448cb9cadadSEd Warnicke
449cb9cadadSEd Warnicke/* Parses interface flags (up, down, enable, disable, etc.) */
450cb9cadadSEd Warnickeunformat_function_t unformat_vnet_hw_interface_flags;
451cb9cadadSEd Warnickeunformat_function_t unformat_vnet_sw_interface_flags;
452cb9cadadSEd Warnicke
4539485d99bSJon Loeliger/* VLAN tag-rewrite */
4549485d99bSJon Loeligerformat_function_t format_vtr;
4559485d99bSJon Loeliger
456cb9cadadSEd Warnicke/* Node runtime for interface output function. */
457ba868bb7SDave Barachtypedef struct
458ba868bb7SDave Barach{
459cb9cadadSEd Warnicke  u32 hw_if_index;
460cb9cadadSEd Warnicke  u32 sw_if_index;
461cb9cadadSEd Warnicke  u32 dev_instance;
462cb9cadadSEd Warnicke  u32 is_deleted;
463cb9cadadSEd Warnicke} vnet_interface_output_runtime_t;
464cb9cadadSEd Warnicke
46510ae7662SDamjan Marion/* Interface output function. */
466ba868bb7SDave Barachword vnet_sw_interface_compare (vnet_main_t * vnm, uword sw_if_index0,
467ba868bb7SDave Barach				uword sw_if_index1);
468ba868bb7SDave Barachword vnet_hw_interface_compare (vnet_main_t * vnm, uword hw_if_index0,
469ba868bb7SDave Barach				uword hw_if_index1);
470cb9cadadSEd Warnicke
471ba868bb7SDave Barachtypedef enum
472ba868bb7SDave Barach{
4739c6ae5f4SDamjan Marion  VNET_INTERFACE_OUTPUT_NEXT_DROP,
474cb9cadadSEd Warnicke  VNET_INTERFACE_OUTPUT_NEXT_TX,
475cb9cadadSEd Warnicke} vnet_interface_output_next_t;
476cb9cadadSEd Warnicke
477ba868bb7SDave Barachtypedef enum
478ba868bb7SDave Barach{
479cb9cadadSEd Warnicke  VNET_INTERFACE_TX_NEXT_DROP,
480cb9cadadSEd Warnicke  VNET_INTERFACE_TX_N_NEXT,
481cb9cadadSEd Warnicke} vnet_interface_tx_next_t;
482cb9cadadSEd Warnicke
483405e41b5SJohn Lo#define VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT VNET_INTERFACE_TX_N_NEXT
484635ec3bdSDave Barach#define VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT (VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT + 1)
485405e41b5SJohn Lo
486ba868bb7SDave Barachtypedef enum
487ba868bb7SDave Barach{
488cb9cadadSEd Warnicke  VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DOWN,
489cb9cadadSEd Warnicke  VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DELETED,
4906a7cff7eSAndrew Yourtchenko  VNET_INTERFACE_OUTPUT_ERROR_NO_BUFFERS_FOR_GSO,
4916a7cff7eSAndrew Yourtchenko  VNET_INTERFACE_OUTPUT_ERROR_UNHANDLED_GSO_TYPE,
492cb9cadadSEd Warnicke} vnet_interface_output_error_t;
493cb9cadadSEd Warnicke
494cb9cadadSEd Warnicke/* Format for interface output traces. */
495ba868bb7SDave Barachu8 *format_vnet_interface_output_trace (u8 * s, va_list * va);
496cb9cadadSEd Warnicke
497ba868bb7SDave Barachserialize_function_t serialize_vnet_interface_state,
498ba868bb7SDave Barach  unserialize_vnet_interface_state;
499cb9cadadSEd Warnicke
500cb9cadadSEd Warnicke#endif /* included_vnet_interface_funcs_h */
501ba868bb7SDave Barach
502ba868bb7SDave Barach/*
503ba868bb7SDave Barach * fd.io coding-style-patch-verification: ON
504ba868bb7SDave Barach *
505ba868bb7SDave Barach * Local Variables:
506ba868bb7SDave Barach * eval: (c-set-style "gnu")
507ba868bb7SDave Barach * End:
508ba868bb7SDave Barach */
509