summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2020-10-02 14:12:37 +0000
committerDamjan Marion <dmarion@me.com>2020-10-02 22:20:59 +0000
commit149fd3fbd069a5f7be86e68472578ee7af229cb6 (patch)
tree9c815f7e1edf9f7cbb2c86e93459e4989ba21f00 /src/plugins
parent1c556d19d0b7a0f9d130ddfb07041cb2cafb8a8d (diff)
lldp: set interface MAC address when enabled
Type: improvement Change-Id: I4f2dc4e4c1c467fb9acd0fed231c56fcd54c8da9 Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/lldp/lldp.h2
-rw-r--r--src/plugins/lldp/lldp_cli.c15
-rw-r--r--src/plugins/lldp/lldp_output.c21
3 files changed, 28 insertions, 10 deletions
diff --git a/src/plugins/lldp/lldp.h b/src/plugins/lldp/lldp.h
index df03dcea6ce..e0550dad96d 100644
--- a/src/plugins/lldp/lldp.h
+++ b/src/plugins/lldp/lldp.h
@@ -24,11 +24,13 @@ typedef enum lldp_cfg_err
lldp_ok,
lldp_not_supported,
lldp_invalid_arg,
+ lldp_internal_error,
} lldp_cfg_err_t;
lldp_cfg_err_t lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc,
u8 **mgmt_ip4, u8 **mgmt_ip6, u8 **mgmt_oid, int enable);
lldp_cfg_err_t lldp_cfg_set (u8 ** host, int hold_time, int tx_interval);
+extern const u8 lldp_mac_addr[6];
#endif /* __included_lldp_h__ */
diff --git a/src/plugins/lldp/lldp_cli.c b/src/plugins/lldp/lldp_cli.c
index 0d196f4e394..da45ba3043b 100644
--- a/src/plugins/lldp/lldp_cli.c
+++ b/src/plugins/lldp/lldp_cli.c
@@ -39,6 +39,8 @@ lldp_cfg_err_to_clib_err (lldp_cfg_err_t e)
return clib_error_return (0, "not supported");
case lldp_invalid_arg:
return clib_error_return (0, "invalid argument");
+ case lldp_internal_error:
+ return clib_error_return (0, "internal error");
}
return 0;
}
@@ -99,6 +101,13 @@ lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, u8 ** mgmt_ip4,
*mgmt_oid = NULL;
}
+ if (!vnet_hw_interface_add_del_mac_address (lm->vnet_main, hw_if_index,
+ lldp_mac_addr,
+ 1 /* is_add */ ))
+ {
+ return lldp_internal_error;
+ }
+
const vnet_sw_interface_t *sw =
vnet_get_sw_interface (lm->vnet_main, hi->sw_if_index);
if (sw->flags & (VNET_SW_INTERFACE_FLAG_ADMIN_UP))
@@ -110,6 +119,12 @@ lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, u8 ** mgmt_ip4,
{
lldp_intf_t *n = lldp_get_intf (lm, hi->sw_if_index);
lldp_delete_intf (lm, n);
+ if (n)
+ {
+ vnet_hw_interface_add_del_mac_address (lm->vnet_main, hw_if_index,
+ lldp_mac_addr,
+ 0 /* is_add */ );
+ }
}
return lldp_ok;
diff --git a/src/plugins/lldp/lldp_output.c b/src/plugins/lldp/lldp_output.c
index dc03faf4d5c..deff723b4b3 100644
--- a/src/plugins/lldp/lldp_output.c
+++ b/src/plugins/lldp/lldp_output.c
@@ -263,6 +263,11 @@ lldp_delete_intf (lldp_main_t * lm, lldp_intf_t * n)
}
}
+
+/* 01:80:C2:00:00:0E - propagation constrained to a single
+ * physical link - stopped by all type of bridge */
+const u8 lldp_mac_addr[6] = { 0x01, 0x80, 0xC3, 0x00, 0x00, 0x0E };
+
static clib_error_t *
lldp_template_init (vlib_main_t * vm)
{
@@ -274,16 +279,12 @@ lldp_template_init (vlib_main_t * vm)
clib_memset (&h, 0, sizeof (h));
- /*
- * Send to 01:80:C2:00:00:0E - propagation constrained to a single
- * physical link - stopped by all type of bridge
- */
- h.dst_address[0] = 0x01;
- h.dst_address[1] = 0x80;
- h.dst_address[2] = 0xC2;
- /* h.dst_address[3] = 0x00; (clib_memset) */
- /* h.dst_address[4] = 0x00; (clib_memset) */
- h.dst_address[5] = 0x0E;
+ h.dst_address[0] = lldp_mac_addr[0];
+ h.dst_address[1] = lldp_mac_addr[1];
+ h.dst_address[2] = lldp_mac_addr[2];
+ h.dst_address[3] = lldp_mac_addr[3];
+ h.dst_address[4] = lldp_mac_addr[4];
+ h.dst_address[5] = lldp_mac_addr[5];
/* leave src address blank (fill in at send time) */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2015 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.
 */
/*
 * misc.c: vnet misc
 *
 * Copyright (c) 2012 Eliot Dresselhaus
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <vnet/vnet.h>
#include <vnet/ip/ip.h>

vnet_main_t vnet_main;
vnet_main_t **vnet_mains;

vnet_main_t *
vnet_get_main (void)
{
  return &vnet_main;
}

static uword
vnet_local_interface_tx (vlib_main_t * vm,
			 vlib_node_runtime_t * node, vlib_frame_t * f)
{
  ASSERT (0);
  return f->n_vectors;
}

/* *INDENT-OFF* */
VNET_DEVICE_CLASS (vnet_local_interface_device_class) = {
  .name = "local",
  .tx_function = vnet_local_interface_tx,
};
/* *INDENT-ON* */

/* *INDENT-OFF* */
VNET_HW_INTERFACE_CLASS (vnet_local_interface_hw_class,static) = {
  .name = "local",
};
/* *INDENT-ON* */

clib_error_t *
vnet_main_init (vlib_main_t * vm)
{
  vnet_main_t *vnm = vnet_get_main ();
  clib_error_t *error;
  u32 hw_if_index;
  vnet_hw_interface_t *hw;

  if ((error = vlib_call_init_function (vm, vnet_interface_init)))
    return error;

  if ((error = vlib_call_init_function (vm, fib_module_init)))
    return error;

  if ((error = vlib_call_init_function (vm, mfib_module_init)))
    return error;

  if ((error = vlib_call_init_function (vm, ip_main_init)))
    return error;

  if ((error = vlib_call_init_function (vm, ip4_lookup_init)))
    return error;

  if ((error = vlib_call_init_function (vm, ip6_lookup_init)))
    return error;

  if ((error = vlib_call_init_function (vm, mpls_init)))
    return error;

  vnm->vlib_main = vm;

  hw_if_index = vnet_register_interface
    (vnm, vnet_local_interface_device_class.index, /* instance */ 0,
     vnet_local_interface_hw_class.index, /* instance */ 0);
  hw = vnet_get_hw_interface (vnm, hw_if_index);

  vnm->local_interface_hw_if_index = hw_if_index;
  vnm->local_interface_sw_if_index = hw->sw_if_index;

  /* the local interface is used as an input interface when decapping from
   * an IPSEC tunnel. so it needs to be IP enabled */
  ip4_sw_interface_enable_disable (hw->sw_if_index, 1);
  ip6_sw_interface_enable_disable (hw->sw_if_index, 1);

  return 0;
}

VLIB_INIT_FUNCTION (vnet_main_init);

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */