Use IP and MAC API types for neighbors
use address_t and mac_address_t for IPv6 and ARP entries and all other API calls in ip.api aprat from the route ones, that will follow in a separate commit Change-Id: I67161737c2184d3f8fc1e79ebd2b55121c5b0191 Signed-off-by: Neale Ranns <nranns@cisco.com>
This commit is contained in:
committed by
Damjan Marion
parent
13b2ba2ad5
commit
37029305c6
@@ -17,6 +17,17 @@
|
||||
|
||||
namespace VOM {
|
||||
|
||||
void
|
||||
to_api(const boost::asio::ip::address_v4& a, vapi_type_ip4_address& v)
|
||||
{
|
||||
std::copy_n(std::begin(a.to_bytes()), a.to_bytes().size(), v);
|
||||
}
|
||||
void
|
||||
to_api(const boost::asio::ip::address_v6& a, vapi_type_ip6_address& v)
|
||||
{
|
||||
std::copy_n(std::begin(a.to_bytes()), a.to_bytes().size(), v);
|
||||
}
|
||||
|
||||
void
|
||||
to_api(const ip_address_t& a, vapi_type_address& v)
|
||||
{
|
||||
@@ -43,10 +54,24 @@ to_api(const ip_address_t& a,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
to_api(const boost::asio::ip::address& a, vapi_type_ip4_address& v)
|
||||
boost::asio::ip::address_v6
|
||||
from_api(const vapi_type_ip6_address& v)
|
||||
{
|
||||
memcpy(v, a.to_v4().to_bytes().data(), 4);
|
||||
std::array<uint8_t, 16> a;
|
||||
std::copy(v, v + 16, std::begin(a));
|
||||
boost::asio::ip::address_v6 v6(a);
|
||||
|
||||
return v6;
|
||||
}
|
||||
|
||||
boost::asio::ip::address_v4
|
||||
from_api(const vapi_type_ip4_address& v)
|
||||
{
|
||||
std::array<uint8_t, 4> a;
|
||||
std::copy(v, v + 4, std::begin(a));
|
||||
boost::asio::ip::address_v4 v4(a);
|
||||
|
||||
return v4;
|
||||
}
|
||||
|
||||
ip_address_t
|
||||
|
||||
@@ -24,13 +24,15 @@ namespace VOM {
|
||||
typedef boost::asio::ip::address ip_address_t;
|
||||
|
||||
void to_api(const ip_address_t& a, vapi_type_address& v);
|
||||
void to_api(const boost::asio::ip::address& a, vapi_type_ip4_address& v);
|
||||
void to_api(const boost::asio::ip::address_v4& a, vapi_type_ip4_address& v);
|
||||
void to_api(const boost::asio::ip::address_v6& a, vapi_type_ip6_address& v);
|
||||
void to_api(const boost::asio::ip::address& a,
|
||||
vapi_union_address_union& u,
|
||||
vapi_enum_address_family& af);
|
||||
|
||||
boost::asio::ip::address_v4 from_api(const vapi_type_ip4_address& v);
|
||||
boost::asio::ip::address_v6 from_api(const vapi_type_ip6_address& v);
|
||||
ip_address_t from_api(const vapi_type_address& v);
|
||||
ip_address_t from_api(const vapi_type_ip4_address& v);
|
||||
ip_address_t from_api(const vapi_union_address_union& u,
|
||||
vapi_enum_address_family af);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "vom/arp_proxy_config.hpp"
|
||||
#include "vom/api_types.hpp"
|
||||
#include "vom/arp_proxy_config_cmds.hpp"
|
||||
#include "vom/prefix.hpp"
|
||||
#include "vom/singular_db_funcs.hpp"
|
||||
@@ -125,8 +126,8 @@ arp_proxy_config::event_handler::handle_populate(const client_db::key_t& key)
|
||||
for (auto& record : *cmd) {
|
||||
auto& payload = record.get_payload();
|
||||
|
||||
boost::asio::ip::address lo = from_bytes(0, payload.proxy.low_address);
|
||||
boost::asio::ip::address hi = from_bytes(0, payload.proxy.hi_address);
|
||||
boost::asio::ip::address lo = from_api(payload.proxy.low);
|
||||
boost::asio::ip::address hi = from_api(payload.proxy.hi);
|
||||
|
||||
arp_proxy_config ap(lo.to_v4(), hi.to_v4());
|
||||
OM::commit(key, ap);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "vom/arp_proxy_config_cmds.hpp"
|
||||
#include "vom/api_types.hpp"
|
||||
|
||||
namespace VOM {
|
||||
namespace arp_proxy_config_cmds {
|
||||
@@ -41,10 +42,8 @@ config_cmd::issue(connection& con)
|
||||
auto& payload = req.get_request().get_payload();
|
||||
payload.is_add = 1;
|
||||
|
||||
std::copy_n(std::begin(m_low.to_bytes()), m_low.to_bytes().size(),
|
||||
payload.proxy.low_address);
|
||||
std::copy_n(std::begin(m_high.to_bytes()), m_high.to_bytes().size(),
|
||||
payload.proxy.hi_address);
|
||||
to_api(m_low, payload.proxy.low);
|
||||
to_api(m_high, payload.proxy.hi);
|
||||
|
||||
VAPI_CALL(req.execute());
|
||||
|
||||
@@ -86,10 +85,8 @@ unconfig_cmd::issue(connection& con)
|
||||
auto& payload = req.get_request().get_payload();
|
||||
payload.is_add = 0;
|
||||
|
||||
std::copy_n(std::begin(m_low.to_bytes()), m_low.to_bytes().size(),
|
||||
payload.proxy.low_address);
|
||||
std::copy_n(std::begin(m_high.to_bytes()), m_high.to_bytes().size(),
|
||||
payload.proxy.hi_address);
|
||||
to_api(m_low, payload.proxy.low);
|
||||
to_api(m_high, payload.proxy.hi);
|
||||
|
||||
VAPI_CALL(req.execute());
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "vom/neighbour.hpp"
|
||||
#include "vom/api_types.hpp"
|
||||
#include "vom/neighbour_cmds.hpp"
|
||||
#include "vom/singular_db_funcs.hpp"
|
||||
|
||||
@@ -165,9 +166,8 @@ neighbour::populate_i(const client_db::key_t& key,
|
||||
*/
|
||||
auto& payload = record.get_payload();
|
||||
|
||||
mac_address_t mac(payload.mac_address);
|
||||
boost::asio::ip::address ip_addr =
|
||||
from_bytes(payload.is_ipv6, payload.ip_address);
|
||||
mac_address_t mac = from_api(payload.neighbor.mac_address);
|
||||
boost::asio::ip::address ip_addr = from_api(payload.neighbor.ip_address);
|
||||
neighbour n(*itf, ip_addr, mac);
|
||||
|
||||
VOM_LOG(log_level_t::DEBUG) << "neighbour-dump: " << itf->to_string()
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "vom/neighbour_cmds.hpp"
|
||||
#include "vom/api_types.hpp"
|
||||
|
||||
namespace VOM {
|
||||
namespace neighbour_cmds {
|
||||
@@ -41,11 +42,12 @@ create_cmd::issue(connection& con)
|
||||
msg_t req(con.ctx(), std::ref(*this));
|
||||
|
||||
auto& payload = req.get_request().get_payload();
|
||||
payload.sw_if_index = m_itf.value();
|
||||
payload.is_add = 1;
|
||||
payload.is_static = 1;
|
||||
m_mac.to_bytes(payload.mac_address, 6);
|
||||
to_bytes(m_ip_addr, &payload.is_ipv6, payload.dst_address);
|
||||
payload.neighbor.sw_if_index = m_itf.value();
|
||||
payload.neighbor.flags = IP_API_NEIGHBOR_FLAG_STATIC;
|
||||
|
||||
to_api(m_mac, payload.neighbor.mac_address);
|
||||
to_api(m_ip_addr, payload.neighbor.ip_address);
|
||||
|
||||
VAPI_CALL(req.execute());
|
||||
|
||||
@@ -87,11 +89,12 @@ delete_cmd::issue(connection& con)
|
||||
msg_t req(con.ctx(), std::ref(*this));
|
||||
|
||||
auto& payload = req.get_request().get_payload();
|
||||
payload.sw_if_index = m_itf.value();
|
||||
payload.is_add = 0;
|
||||
payload.is_static = 1;
|
||||
m_mac.to_bytes(payload.mac_address, 6);
|
||||
to_bytes(m_ip_addr, &payload.is_ipv6, payload.dst_address);
|
||||
payload.neighbor.sw_if_index = m_itf.value();
|
||||
payload.neighbor.flags = IP_API_NEIGHBOR_FLAG_STATIC;
|
||||
|
||||
to_api(m_mac, payload.neighbor.mac_address);
|
||||
to_api(m_ip_addr, payload.neighbor.ip_address);
|
||||
|
||||
VAPI_CALL(req.execute());
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "vom/api_types.hpp"
|
||||
#include "vom/ra_prefix.hpp"
|
||||
|
||||
namespace VOM {
|
||||
@@ -37,9 +38,7 @@ ra_prefix::ra_prefix(const route::prefix_t& pfx,
|
||||
void
|
||||
ra_prefix::to_vpp(vapi_payload_sw_interface_ip6nd_ra_prefix& ra_prefix) const
|
||||
{
|
||||
uint8_t is_ipv6 = 0;
|
||||
|
||||
m_pfx.to_vpp(&is_ipv6, ra_prefix.address, &ra_prefix.address_length);
|
||||
ra_prefix.prefix = to_api(m_pfx);
|
||||
|
||||
ra_prefix.use_default = m_use_default;
|
||||
ra_prefix.no_advertise = m_no_advertise;
|
||||
|
||||
@@ -111,7 +111,7 @@ static void
|
||||
gbp_endpoint_extract_key_mac_itf (const clib_bihash_kv_16_8_t * key,
|
||||
mac_address_t * mac, u32 * sw_if_index)
|
||||
{
|
||||
mac_address_from_u64 (key->key[0], mac);
|
||||
mac_address_from_u64 (mac, key->key[0]);
|
||||
*sw_if_index = key->key[1];
|
||||
}
|
||||
|
||||
|
||||
@@ -553,8 +553,7 @@ show_mactime_command_fn (vlib_main_t * vm,
|
||||
for (j = 0; j < vec_len (mm->arp_cache_copy); j++)
|
||||
{
|
||||
n = mm->arp_cache_copy + j;
|
||||
if (!memcmp (dp->mac_address, n->ethernet_address,
|
||||
sizeof (n->ethernet_address)))
|
||||
if (!memcmp (dp->mac_address, n->mac.bytes, sizeof (n->mac)))
|
||||
{
|
||||
vlib_cli_output (vm, "%17s%U", " ", format_ip4_address,
|
||||
&n->ip4_address);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <vnet/vnet.h>
|
||||
#include <vnet/ip/ip.h>
|
||||
#include <vnet/ethernet/ethernet.h>
|
||||
#include <vnet/ethernet/arp_packet.h>
|
||||
#include <vnet/ethernet/arp.h>
|
||||
#include <vlib/counter.h>
|
||||
|
||||
#include <vppinfra/hash.h>
|
||||
|
||||
+71
-129
File diff suppressed because it is too large
Load Diff
+113
-113
File diff suppressed because it is too large
Load Diff
+56
-2
@@ -19,6 +19,29 @@
|
||||
#include <vnet/ethernet/ethernet.h>
|
||||
#include <vnet/ethernet/arp_packet.h>
|
||||
#include <vnet/ip/ip.h>
|
||||
#include <vnet/ip/ip_neighbor.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 sw_if_index;
|
||||
ip4_address_t ip4_address;
|
||||
|
||||
mac_address_t mac;
|
||||
|
||||
ip_neighbor_flags_t flags;
|
||||
|
||||
f64 time_last_updated;
|
||||
|
||||
/**
|
||||
* The index of the adj-fib entry created
|
||||
*/
|
||||
fib_node_index_t fib_entry_index;
|
||||
} ethernet_arp_ip4_entry_t;
|
||||
|
||||
extern u8 *format_ethernet_arp_ip4_entry (u8 * s, va_list * va);
|
||||
|
||||
ethernet_arp_ip4_entry_t *ip4_neighbors_pool (void);
|
||||
ethernet_arp_ip4_entry_t *ip4_neighbor_entries (u32 sw_if_index);
|
||||
|
||||
extern int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
|
||||
ip4_address_t * hi_addr,
|
||||
@@ -28,8 +51,7 @@ extern int vnet_arp_set_ip4_over_ethernet (vnet_main_t * vnm,
|
||||
u32 sw_if_index,
|
||||
const
|
||||
ethernet_arp_ip4_over_ethernet_address_t
|
||||
* a, int is_static,
|
||||
int is_no_fib_entry);
|
||||
* a, ip_neighbor_flags_t flags);
|
||||
|
||||
extern int vnet_arp_unset_ip4_over_ethernet (vnet_main_t * vnm,
|
||||
u32 sw_if_index,
|
||||
@@ -39,6 +61,38 @@ extern int vnet_arp_unset_ip4_over_ethernet (vnet_main_t * vnm,
|
||||
|
||||
extern int vnet_proxy_arp_fib_reset (u32 fib_id);
|
||||
|
||||
void vnet_register_ip4_arp_resolution_event (vnet_main_t * vnm,
|
||||
void *address_arg,
|
||||
uword node_index,
|
||||
uword type_opaque, uword data);
|
||||
|
||||
typedef int (*arp_change_event_cb_t) (u32 pool_index,
|
||||
const mac_address_t * mac,
|
||||
u32 sw_if_index,
|
||||
const ip4_address_t * address);
|
||||
|
||||
int vnet_add_del_ip4_arp_change_event (vnet_main_t * vnm,
|
||||
arp_change_event_cb_t data_callback,
|
||||
u32 pid,
|
||||
void *address_arg,
|
||||
uword node_index,
|
||||
uword type_opaque,
|
||||
uword data, int is_add);
|
||||
|
||||
void wc_arp_set_publisher_node (uword inode_index, uword event_type);
|
||||
|
||||
void ethernet_arp_change_mac (u32 sw_if_index);
|
||||
void ethernet_ndp_change_mac (u32 sw_if_index);
|
||||
|
||||
void arp_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 sw_if_index;
|
||||
ip4_address_t ip;
|
||||
mac_address_t mac;
|
||||
} wc_arp_report_t;
|
||||
|
||||
/**
|
||||
* call back function when walking the DB of proxy ARPs
|
||||
* @return 0 to stop the walk !0 to continue
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#ifndef included_ethernet_arp_packet_h
|
||||
#define included_ethernet_arp_packet_h
|
||||
|
||||
#include <vnet/ethernet/mac_address.h>
|
||||
|
||||
#define foreach_ethernet_arp_hardware_type \
|
||||
_ (0, reserved) \
|
||||
_ (1, ethernet) \
|
||||
@@ -119,11 +121,14 @@ typedef enum
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
typedef CLIB_PACKED (struct {
|
||||
u8 ethernet[6];
|
||||
mac_address_t mac;
|
||||
ip4_address_t ip4;
|
||||
}) ethernet_arp_ip4_over_ethernet_address_t;
|
||||
/* *INDENT-ON* */
|
||||
|
||||
STATIC_ASSERT (sizeof (ethernet_arp_ip4_over_ethernet_address_t) == 10,
|
||||
"Packet ethernet address and IP4 address too big");
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u16 l2_type;
|
||||
@@ -140,34 +145,6 @@ typedef struct
|
||||
};
|
||||
} ethernet_arp_header_t;
|
||||
|
||||
typedef enum ethernet_arp_entry_flags_t_
|
||||
{
|
||||
ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC = (1 << 0),
|
||||
ETHERNET_ARP_IP4_ENTRY_FLAG_DYNAMIC = (1 << 1),
|
||||
ETHERNET_ARP_IP4_ENTRY_FLAG_NO_FIB_ENTRY = (1 << 2),
|
||||
} __attribute__ ((packed)) ethernet_arp_entry_flags_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 sw_if_index;
|
||||
ip4_address_t ip4_address;
|
||||
|
||||
u8 ethernet_address[6];
|
||||
|
||||
ethernet_arp_entry_flags_t flags;
|
||||
|
||||
f64 time_last_updated;
|
||||
|
||||
/**
|
||||
* The index of the adj-fib entry created
|
||||
*/
|
||||
fib_node_index_t fib_entry_index;
|
||||
} ethernet_arp_ip4_entry_t;
|
||||
|
||||
ethernet_arp_ip4_entry_t *ip4_neighbors_pool (void);
|
||||
ethernet_arp_ip4_entry_t *ip4_neighbor_entries (u32 sw_if_index);
|
||||
u8 *format_ethernet_arp_ip4_entry (u8 * s, va_list * va);
|
||||
|
||||
void send_ip4_garp (vlib_main_t * vm, u32 sw_if_index);
|
||||
void send_ip4_garp_w_addr (vlib_main_t * vm,
|
||||
const ip4_address_t * ip4_addr, u32 sw_if_index);
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include <vnet/vnet.h>
|
||||
#include <vnet/ethernet/packet.h>
|
||||
#include <vnet/ethernet/mac_address.h>
|
||||
#include <vnet/pg/pg.h>
|
||||
#include <vnet/feature/feature.h>
|
||||
|
||||
@@ -59,40 +60,6 @@ typedef struct
|
||||
u32 hw_if_index;
|
||||
} ethernet_input_frame_t;
|
||||
|
||||
always_inline u64
|
||||
ethernet_mac_address_u64 (const u8 * a)
|
||||
{
|
||||
return (((u64) a[0] << (u64) (5 * 8))
|
||||
| ((u64) a[1] << (u64) (4 * 8))
|
||||
| ((u64) a[2] << (u64) (3 * 8))
|
||||
| ((u64) a[3] << (u64) (2 * 8))
|
||||
| ((u64) a[4] << (u64) (1 * 8)) | ((u64) a[5] << (u64) (0 * 8)));
|
||||
}
|
||||
|
||||
always_inline void
|
||||
ethernet_mac_address_from_u64 (u64 u, u8 * a)
|
||||
{
|
||||
i8 ii;
|
||||
|
||||
for (ii = 5; ii >= 0; ii--)
|
||||
{
|
||||
a[ii] = u & 0xFF;
|
||||
u = u >> 8;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
ethernet_mac_address_is_multicast_u64 (u64 a)
|
||||
{
|
||||
return (a & (1ULL << (5 * 8))) != 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
ethernet_mac_address_is_zero (const u8 * mac)
|
||||
{
|
||||
return ((*((u32 *) mac) == 0) && (*((u16 *) (mac + 4)) == 0));
|
||||
}
|
||||
|
||||
#ifdef CLIB_HAVE_VEC128
|
||||
static const u16x8 tagged_ethertypes = {
|
||||
(u16) ETHERNET_TYPE_VLAN,
|
||||
@@ -565,42 +532,12 @@ matched:
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Compare two ethernet macs. Return 1 if they are the same, 0 if different
|
||||
always_inline u32
|
||||
eth_mac_equal (const u8 * mac1, const u8 * mac2)
|
||||
{
|
||||
return (*((u32 *) (mac1 + 0)) == *((u32 *) (mac2 + 0)) &&
|
||||
*((u32 *) (mac1 + 2)) == *((u32 *) (mac2 + 2)));
|
||||
}
|
||||
|
||||
|
||||
always_inline ethernet_main_t *
|
||||
vnet_get_ethernet_main (void)
|
||||
{
|
||||
return ðernet_main;
|
||||
}
|
||||
|
||||
void vnet_register_ip4_arp_resolution_event (vnet_main_t * vnm,
|
||||
void *address_arg,
|
||||
uword node_index,
|
||||
uword type_opaque, uword data);
|
||||
|
||||
|
||||
int vnet_add_del_ip4_arp_change_event (vnet_main_t * vnm,
|
||||
void *data_callback,
|
||||
u32 pid,
|
||||
void *address_arg,
|
||||
uword node_index,
|
||||
uword type_opaque,
|
||||
uword data, int is_add);
|
||||
|
||||
void wc_arp_set_publisher_node (uword inode_index, uword event_type);
|
||||
|
||||
void ethernet_arp_change_mac (u32 sw_if_index);
|
||||
void ethernet_ndp_change_mac (u32 sw_if_index);
|
||||
|
||||
void arp_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai);
|
||||
|
||||
void ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai);
|
||||
u8 *ethernet_build_rewrite (vnet_main_t * vnm,
|
||||
u32 sw_if_index,
|
||||
@@ -610,13 +547,6 @@ const u8 *ethernet_ip6_mcast_dst_addr (void);
|
||||
|
||||
extern vlib_node_registration_t ethernet_input_node;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 sw_if_index;
|
||||
u32 ip4;
|
||||
u8 mac[6];
|
||||
} wc_arp_report_t;
|
||||
|
||||
#endif /* included_ethernet_h */
|
||||
|
||||
/*
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <vnet/ip/ip.h>
|
||||
#include <vnet/pg/pg.h>
|
||||
#include <vnet/ethernet/ethernet.h>
|
||||
#include <vnet/ethernet/arp.h>
|
||||
#include <vnet/l2/l2_input.h>
|
||||
#include <vnet/l2/l2_bd.h>
|
||||
#include <vnet/adj/adj.h>
|
||||
|
||||
@@ -37,13 +37,28 @@ uword
|
||||
unformat_mac_address_t (unformat_input_t * input, va_list * args)
|
||||
{
|
||||
mac_address_t *mac = va_arg (*args, mac_address_t *);
|
||||
u32 i, a[3];
|
||||
|
||||
if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
|
||||
&mac->bytes[0], &mac->bytes[1], &mac->bytes[2],
|
||||
&mac->bytes[3], &mac->bytes[4], &mac->bytes[5]))
|
||||
return 0;
|
||||
if (unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
|
||||
&mac->bytes[0], &mac->bytes[1], &mac->bytes[2],
|
||||
&mac->bytes[3], &mac->bytes[4], &mac->bytes[5]))
|
||||
return (1);
|
||||
else if (unformat (input, "%_%x.%x.%x%_", &a[0], &a[1], &a[2]))
|
||||
{
|
||||
for (i = 0; i < ARRAY_LEN (a); i++)
|
||||
if (a[i] >= (1 << 16))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
mac->bytes[0] = (a[0] >> 8) & 0xff;
|
||||
mac->bytes[1] = (a[0] >> 0) & 0xff;
|
||||
mac->bytes[2] = (a[1] >> 8) & 0xff;
|
||||
mac->bytes[3] = (a[1] >> 0) & 0xff;
|
||||
mac->bytes[4] = (a[2] >> 8) & 0xff;
|
||||
mac->bytes[5] = (a[2] >> 0) & 0xff;
|
||||
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#ifndef __MAC_ADDRESS_H__
|
||||
#define __MAC_ADDRESS_H__
|
||||
|
||||
#include <vnet/ethernet/ethernet.h>
|
||||
#include <vlib/vlib.h>
|
||||
|
||||
typedef struct mac_address_t_
|
||||
{
|
||||
@@ -36,18 +36,59 @@ STATIC_ASSERT ((sizeof (mac_address_t) == 6),
|
||||
|
||||
extern const mac_address_t ZERO_MAC_ADDRESS;
|
||||
|
||||
always_inline u64
|
||||
ethernet_mac_address_u64 (const u8 * a)
|
||||
{
|
||||
return (((u64) a[0] << (u64) (5 * 8))
|
||||
| ((u64) a[1] << (u64) (4 * 8))
|
||||
| ((u64) a[2] << (u64) (3 * 8))
|
||||
| ((u64) a[3] << (u64) (2 * 8))
|
||||
| ((u64) a[4] << (u64) (1 * 8)) | ((u64) a[5] << (u64) (0 * 8)));
|
||||
}
|
||||
|
||||
always_inline void
|
||||
ethernet_mac_address_from_u64 (u64 u, u8 * a)
|
||||
{
|
||||
i8 ii;
|
||||
|
||||
for (ii = 5; ii >= 0; ii--)
|
||||
{
|
||||
a[ii] = u & 0xFF;
|
||||
u = u >> 8;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
ethernet_mac_address_is_multicast_u64 (u64 a)
|
||||
{
|
||||
return (a & (1ULL << (5 * 8))) != 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
ethernet_mac_address_is_zero (const u8 * mac)
|
||||
{
|
||||
return ((*((u32 *) mac) == 0) && (*((u16 *) (mac + 4)) == 0));
|
||||
}
|
||||
|
||||
static inline int
|
||||
ethernet_mac_address_equal (const u8 * a, const u8 * b)
|
||||
{
|
||||
return ((*((u32 *) a) == (*((u32 *) b))) &&
|
||||
(*((u16 *) (a + 4)) == (*((u16 *) (b + 4)))));
|
||||
}
|
||||
|
||||
static_always_inline void
|
||||
mac_address_from_bytes (mac_address_t * mac, const u8 * bytes)
|
||||
{
|
||||
/* zero out the last 2 bytes, then copy over only 6 */
|
||||
clib_memcpy (mac->bytes, bytes, 6);
|
||||
clib_memcpy_fast (mac->bytes, bytes, 6);
|
||||
}
|
||||
|
||||
static_always_inline void
|
||||
mac_address_to_bytes (const mac_address_t * mac, u8 * bytes)
|
||||
{
|
||||
/* zero out the last 2 bytes, then copy over only 6 */
|
||||
clib_memcpy (bytes, mac->bytes, 6);
|
||||
clib_memcpy_fast (bytes, mac->bytes, 6);
|
||||
}
|
||||
|
||||
static_always_inline int
|
||||
@@ -67,7 +108,7 @@ mac_address_as_u64 (const mac_address_t * mac)
|
||||
}
|
||||
|
||||
static_always_inline void
|
||||
mac_address_from_u64 (u64 u, mac_address_t * mac)
|
||||
mac_address_from_u64 (mac_address_t * mac, u64 u)
|
||||
{
|
||||
clib_memcpy (mac->bytes, &u, 6);
|
||||
}
|
||||
@@ -78,6 +119,25 @@ mac_address_copy (mac_address_t * dst, const mac_address_t * src)
|
||||
mac_address_from_bytes (dst, src->bytes);
|
||||
}
|
||||
|
||||
static_always_inline int
|
||||
mac_address_cmp (const mac_address_t * a, const mac_address_t * b)
|
||||
{
|
||||
return (memcmp (a->bytes, b->bytes, 6));
|
||||
}
|
||||
|
||||
static_always_inline int
|
||||
mac_address_equal (const mac_address_t * a, const mac_address_t * b)
|
||||
{
|
||||
return (a->u.last_2 == b->u.last_2 && a->u.first_4 == b->u.first_4);
|
||||
}
|
||||
|
||||
static_always_inline void
|
||||
mac_address_set_zero (mac_address_t * mac)
|
||||
{
|
||||
mac->u.first_4 = 0;
|
||||
mac->u.last_2 = 0;
|
||||
}
|
||||
|
||||
extern uword unformat_mac_address_t (unformat_input_t * input,
|
||||
va_list * args);
|
||||
extern u8 *format_mac_address_t (u8 * s, va_list * args);
|
||||
|
||||
@@ -223,7 +223,7 @@ identify_subint (vnet_hw_interface_t * hi,
|
||||
|
||||
if (!(ethernet_address_cast (e0->dst_address)))
|
||||
{
|
||||
if (!eth_mac_equal ((u8 *) e0, hi->hw_address))
|
||||
if (!ethernet_mac_address_equal ((u8 *) e0, hi->hw_address))
|
||||
{
|
||||
*error0 = ETHERNET_ERROR_L3_MAC_MISMATCH;
|
||||
}
|
||||
@@ -1123,11 +1123,11 @@ ethernet_input_inline (vlib_main_t * vm,
|
||||
{
|
||||
if (!ethernet_address_cast (e0->dst_address) &&
|
||||
(hi->hw_address != 0) &&
|
||||
!eth_mac_equal ((u8 *) e0, hi->hw_address))
|
||||
!ethernet_mac_address_equal ((u8 *) e0, hi->hw_address))
|
||||
error0 = ETHERNET_ERROR_L3_MAC_MISMATCH;
|
||||
if (!ethernet_address_cast (e1->dst_address) &&
|
||||
(hi->hw_address != 0) &&
|
||||
!eth_mac_equal ((u8 *) e1, hi->hw_address))
|
||||
!ethernet_mac_address_equal ((u8 *) e1, hi->hw_address))
|
||||
error1 = ETHERNET_ERROR_L3_MAC_MISMATCH;
|
||||
vlib_buffer_advance (b0, sizeof (ethernet_header_t));
|
||||
determine_next_node (em, variant, 0, type0, b0,
|
||||
@@ -1347,7 +1347,7 @@ ethernet_input_inline (vlib_main_t * vm,
|
||||
{
|
||||
if (!ethernet_address_cast (e0->dst_address) &&
|
||||
(hi->hw_address != 0) &&
|
||||
!eth_mac_equal ((u8 *) e0, hi->hw_address))
|
||||
!ethernet_mac_address_equal ((u8 *) e0, hi->hw_address))
|
||||
error0 = ETHERNET_ERROR_L3_MAC_MISMATCH;
|
||||
vlib_buffer_advance (b0, sizeof (ethernet_header_t));
|
||||
determine_next_node (em, variant, 0, type0, b0,
|
||||
|
||||
+87
-93
File diff suppressed because it is too large
Load Diff
@@ -948,10 +948,6 @@ ip4_lookup_init (vlib_main_t * vm)
|
||||
|
||||
clib_memset (&h, 0, sizeof (h));
|
||||
|
||||
/* Set target ethernet address to all zeros. */
|
||||
clib_memset (h.ip4_over_ethernet[1].ethernet, 0,
|
||||
sizeof (h.ip4_over_ethernet[1].ethernet));
|
||||
|
||||
#define _16(f,v) h.f = clib_host_to_net_u16 (v);
|
||||
#define _8(f,v) h.f = v;
|
||||
_16 (l2_type, ETHERNET_ARP_HARDWARE_TYPE_ethernet);
|
||||
@@ -1872,9 +1868,8 @@ ip4_arp_inline (vlib_main_t * vm,
|
||||
hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
|
||||
|
||||
/* Src ethernet address in ARP header. */
|
||||
clib_memcpy_fast (h0->ip4_over_ethernet[0].ethernet,
|
||||
hw_if0->hw_address,
|
||||
sizeof (h0->ip4_over_ethernet[0].ethernet));
|
||||
mac_address_from_bytes (&h0->ip4_over_ethernet[0].mac,
|
||||
hw_if0->hw_address);
|
||||
if (is_glean)
|
||||
{
|
||||
/* The interface's source address is stashed in the Glean Adj */
|
||||
@@ -2046,8 +2041,7 @@ ip4_probe_neighbor (vlib_main_t * vm, ip4_address_t * dst, u32 sw_if_index,
|
||||
sw_if_index);
|
||||
}
|
||||
|
||||
clib_memcpy_fast (h->ip4_over_ethernet[0].ethernet, hi->hw_address,
|
||||
sizeof (h->ip4_over_ethernet[0].ethernet));
|
||||
mac_address_from_bytes (&h->ip4_over_ethernet[0].mac, hi->hw_address);
|
||||
|
||||
h->ip4_over_ethernet[0].ip4 = src[0];
|
||||
h->ip4_over_ethernet[1].ip4 = dst[0];
|
||||
|
||||
+7
-1
@@ -42,6 +42,7 @@
|
||||
|
||||
#include <vlib/buffer.h>
|
||||
#include <vnet/ethernet/packet.h>
|
||||
#include <vnet/ethernet/mac_address.h>
|
||||
#include <vnet/ip/ip6_packet.h>
|
||||
#include <vnet/ip/ip6_hop_by_hop_packet.h>
|
||||
#include <vnet/ip/lookup.h>
|
||||
@@ -415,8 +416,13 @@ clib_error_t *set_ip6_link_local_address (vlib_main_t * vm,
|
||||
u32 sw_if_index,
|
||||
ip6_address_t * address);
|
||||
|
||||
typedef int (*ip6_nd_change_event_cb_t) (u32 pool_index,
|
||||
const mac_address_t * new_mac,
|
||||
u32 sw_if_index,
|
||||
const ip6_address_t * address);
|
||||
|
||||
int vnet_add_del_ip6_nd_change_event (vnet_main_t * vnm,
|
||||
void *data_callback,
|
||||
ip6_nd_change_event_cb_t data_callback,
|
||||
u32 pid,
|
||||
void *address_arg,
|
||||
uword node_index,
|
||||
|
||||
+64
-79
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,8 @@
|
||||
#define included_ip6_neighbor_h
|
||||
|
||||
#include <vnet/fib/fib_types.h>
|
||||
#include <vnet/ethernet/mac_address.h>
|
||||
#include <vnet/ip/ip_neighbor.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -28,18 +30,11 @@ typedef struct
|
||||
u32 pad;
|
||||
} ip6_neighbor_key_t;
|
||||
|
||||
typedef enum ip6_neighbor_flags_t_
|
||||
{
|
||||
IP6_NEIGHBOR_FLAG_STATIC = (1 << 0),
|
||||
IP6_NEIGHBOR_FLAG_DYNAMIC = (1 << 1),
|
||||
IP6_NEIGHBOR_FLAG_NO_FIB_ENTRY = (1 << 2),
|
||||
} __attribute__ ((packed)) ip6_neighbor_flags_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ip6_neighbor_key_t key;
|
||||
u8 link_layer_address[8];
|
||||
ip6_neighbor_flags_t flags;
|
||||
mac_address_t mac;
|
||||
ip_neighbor_flags_t flags;
|
||||
f64 time_last_updated;
|
||||
fib_node_index_t fib_entry_index;
|
||||
} ip6_neighbor_t;
|
||||
@@ -81,10 +76,8 @@ extern void vnet_register_ip6_neighbor_resolution_event (vnet_main_t * vnm,
|
||||
extern int vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
|
||||
u32 sw_if_index,
|
||||
const ip6_address_t * a,
|
||||
const u8 * link_layer_address,
|
||||
uword n_bytes_link_layer_address,
|
||||
int is_static,
|
||||
int is_no_fib_entry);
|
||||
const mac_address_t * mac,
|
||||
ip_neighbor_flags_t flags);
|
||||
|
||||
extern int vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm,
|
||||
u32 sw_if_index,
|
||||
@@ -99,7 +92,7 @@ typedef struct
|
||||
{
|
||||
u32 sw_if_index;
|
||||
ip6_address_t ip6;
|
||||
u8 mac[6];
|
||||
mac_address_t mac;
|
||||
} wc_nd_report_t;
|
||||
|
||||
void wc_nd_set_publisher_node (uword node_index, uword event_type);
|
||||
@@ -119,8 +112,7 @@ void icmp6_send_router_solicitation (vlib_main_t * vm, u32 sw_if_index,
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ip6_address_t dst_address;
|
||||
u8 dst_address_length;
|
||||
fib_prefix_t prefix;
|
||||
u8 flags;
|
||||
u32 valid_time;
|
||||
u32 preferred_time;
|
||||
@@ -129,7 +121,7 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
u32 sw_if_index;
|
||||
u8 router_address[16];
|
||||
ip6_address_t router_address;
|
||||
u8 current_hop_limit;
|
||||
u8 flags;
|
||||
u16 router_lifetime_in_sec;
|
||||
|
||||
@@ -181,6 +181,13 @@ ip46_address_is_multicast (const ip46_address_t * a)
|
||||
ip6_address_is_multicast (&a->ip6);
|
||||
}
|
||||
|
||||
always_inline void
|
||||
ip6_address_copy (ip6_address_t * dst, const ip6_address_t * src)
|
||||
{
|
||||
dst->as_u64[0] = src->as_u64[0];
|
||||
dst->as_u64[1] = src->as_u64[1];
|
||||
}
|
||||
|
||||
always_inline void
|
||||
ip6_set_reserved_multicast_address (ip6_address_t * a,
|
||||
ip6_multicast_address_scope_t scope,
|
||||
|
||||
+183
-142
File diff suppressed because it is too large
Load Diff
+17
-22
@@ -49,8 +49,8 @@ static ip_neighbor_scan_config_t ip_neighbor_scan_conf;
|
||||
|
||||
int
|
||||
ip_neighbor_add (const ip46_address_t * ip,
|
||||
u8 is_ip6,
|
||||
const u8 * mac,
|
||||
ip46_type_t type,
|
||||
const mac_address_t * mac,
|
||||
u32 sw_if_index,
|
||||
ip_neighbor_flags_t flags, u32 * stats_index)
|
||||
{
|
||||
@@ -63,13 +63,10 @@ ip_neighbor_add (const ip46_address_t * ip,
|
||||
* The expectation is that the FIB will ensure that nothing bad
|
||||
* will come of adding bogus entries.
|
||||
*/
|
||||
if (is_ip6)
|
||||
if (IP46_TYPE_IP6 == type)
|
||||
{
|
||||
rv = vnet_set_ip6_ethernet_neighbor (vlib_get_main (),
|
||||
sw_if_index, &ip->ip6, mac, 6,
|
||||
(flags & IP_NEIGHBOR_FLAG_STATIC),
|
||||
(flags &
|
||||
IP_NEIGHBOR_FLAG_NO_ADJ_FIB));
|
||||
sw_if_index, &ip->ip6, mac, flags);
|
||||
fproto = FIB_PROTOCOL_IP6;
|
||||
linkt = VNET_LINK_IP6;
|
||||
}
|
||||
@@ -77,16 +74,12 @@ ip_neighbor_add (const ip46_address_t * ip,
|
||||
{
|
||||
ethernet_arp_ip4_over_ethernet_address_t a = {
|
||||
.ip4 = ip->ip4,
|
||||
.mac = *mac,
|
||||
};
|
||||
|
||||
clib_memcpy (&a.ethernet, mac, 6);
|
||||
|
||||
rv = vnet_arp_set_ip4_over_ethernet (vnet_get_main (),
|
||||
sw_if_index,
|
||||
&a,
|
||||
(flags & IP_NEIGHBOR_FLAG_STATIC),
|
||||
(flags &
|
||||
IP_NEIGHBOR_FLAG_NO_ADJ_FIB));
|
||||
rv =
|
||||
vnet_arp_set_ip4_over_ethernet (vnet_get_main (), sw_if_index, &a,
|
||||
flags);
|
||||
fproto = FIB_PROTOCOL_IP4;
|
||||
linkt = VNET_LINK_IP4;
|
||||
}
|
||||
@@ -98,11 +91,11 @@ ip_neighbor_add (const ip46_address_t * ip,
|
||||
}
|
||||
|
||||
int
|
||||
ip_neighbor_del (const ip46_address_t * ip, u8 is_ip6, u32 sw_if_index)
|
||||
ip_neighbor_del (const ip46_address_t * ip, ip46_type_t type, u32 sw_if_index)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (is_ip6)
|
||||
if (IP46_TYPE_IP6 == type)
|
||||
{
|
||||
rv = vnet_unset_ip6_ethernet_neighbor (vlib_get_main (),
|
||||
sw_if_index, &ip->ip6);
|
||||
@@ -180,14 +173,14 @@ ip_neighbor_scan (vlib_main_t * vm, f64 start_time, u32 start_idx,
|
||||
if (!is_ip6)
|
||||
{
|
||||
n4 = pool_elt_at_index (np4, curr_idx);
|
||||
if (n4->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC)
|
||||
if (n4->flags & IP_NEIGHBOR_FLAG_STATIC)
|
||||
goto next_neighbor;
|
||||
update_time = n4->time_last_updated;
|
||||
}
|
||||
else
|
||||
{
|
||||
n6 = pool_elt_at_index (np6, curr_idx);
|
||||
if (n6->flags & IP6_NEIGHBOR_FLAG_STATIC)
|
||||
if (n6->flags & IP_NEIGHBOR_FLAG_STATIC)
|
||||
goto next_neighbor;
|
||||
update_time = n6->time_last_updated;
|
||||
}
|
||||
@@ -199,9 +192,11 @@ ip_neighbor_scan (vlib_main_t * vm, f64 start_time, u32 start_idx,
|
||||
/* delete stale neighbor */
|
||||
if (!is_ip6)
|
||||
{
|
||||
ethernet_arp_ip4_over_ethernet_address_t delme;
|
||||
clib_memcpy (&delme.ethernet, n4->ethernet_address, 6);
|
||||
delme.ip4.as_u32 = n4->ip4_address.as_u32;
|
||||
ethernet_arp_ip4_over_ethernet_address_t delme = {
|
||||
.ip4.as_u32 = n4->ip4_address.as_u32,
|
||||
.mac = n4->mac,
|
||||
};
|
||||
|
||||
vnet_arp_unset_ip4_over_ethernet (vnm, n4->sw_if_index, &delme);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -37,19 +37,22 @@ void ip_neighbor_scan_enable_disable (ip_neighbor_scan_arg_t * arg);
|
||||
|
||||
typedef enum ip_neighbor_flags_t_
|
||||
{
|
||||
IP_NEIGHBOR_FLAG_NODE = 0,
|
||||
IP_NEIGHBOR_FLAG_NONE = 0,
|
||||
IP_NEIGHBOR_FLAG_STATIC = (1 << 0),
|
||||
IP_NEIGHBOR_FLAG_NO_ADJ_FIB = (1 << 1),
|
||||
} ip_neighbor_flags_t;
|
||||
IP_NEIGHBOR_FLAG_DYNAMIC = (1 << 1),
|
||||
IP_NEIGHBOR_FLAG_NO_FIB_ENTRY = (1 << 2),
|
||||
} __attribute__ ((packed)) ip_neighbor_flags_t;
|
||||
|
||||
extern u8 *format_ip_neighbor_flags (u8 * s, va_list * args);
|
||||
|
||||
extern int ip_neighbor_add (const ip46_address_t * ip,
|
||||
u8 is_ip6,
|
||||
const u8 * mac,
|
||||
ip46_type_t type,
|
||||
const mac_address_t * mac,
|
||||
u32 sw_if_index,
|
||||
ip_neighbor_flags_t flags, u32 * stats_index);
|
||||
|
||||
extern int ip_neighbor_del (const ip46_address_t * ip,
|
||||
u8 is_ip6, u32 sw_if_index);
|
||||
ip46_type_t type, u32 sw_if_index);
|
||||
|
||||
#endif /* included_ip_neighbor_h */
|
||||
|
||||
|
||||
@@ -29,6 +29,30 @@
|
||||
#include <vnet/vnet_all_api_h.h>
|
||||
#undef vl_printfun
|
||||
|
||||
void
|
||||
ip6_address_encode (const ip6_address_t * in, vl_api_ip6_address_t out)
|
||||
{
|
||||
clib_memcpy (out, in, sizeof (*in));
|
||||
}
|
||||
|
||||
void
|
||||
ip6_address_decode (const vl_api_ip6_address_t in, ip6_address_t * out)
|
||||
{
|
||||
clib_memcpy (out, in, sizeof (*out));
|
||||
}
|
||||
|
||||
void
|
||||
ip4_address_encode (const ip4_address_t * in, vl_api_ip4_address_t out)
|
||||
{
|
||||
clib_memcpy (out, in, sizeof (*in));
|
||||
}
|
||||
|
||||
void
|
||||
ip4_address_decode (const vl_api_ip4_address_t in, ip4_address_t * out)
|
||||
{
|
||||
clib_memcpy (out, in, sizeof (*out));
|
||||
}
|
||||
|
||||
static ip46_type_t
|
||||
ip_address_union_decode (const vl_api_address_union_t * in,
|
||||
vl_api_address_family_t af, ip46_address_t * out)
|
||||
@@ -67,9 +91,9 @@ ip_address_union_encode (const ip46_address_t * in,
|
||||
vl_api_address_union_t * out)
|
||||
{
|
||||
if (ADDRESS_IP6 == clib_net_to_host_u32 (af))
|
||||
memcpy (&out->ip6, &in->ip6, sizeof (out->ip6));
|
||||
ip6_address_encode (&in->ip6, out->ip6);
|
||||
else
|
||||
memcpy (&out->ip4, &in->ip4, sizeof (out->ip4));
|
||||
ip4_address_encode (&in->ip4, out->ip4);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
/**
|
||||
* Forward declarations so we need not #include the API definitions here
|
||||
*/
|
||||
typedef u8 vl_api_ip6_address_t[16];
|
||||
typedef u8 vl_api_ip4_address_t[4];
|
||||
struct _vl_api_address;
|
||||
struct _vl_api_prefix;
|
||||
struct _vl_api_mprefix;
|
||||
@@ -35,6 +37,14 @@ extern ip46_type_t ip_address_decode (const struct _vl_api_address *in,
|
||||
ip46_address_t * out);
|
||||
extern void ip_address_encode (const ip46_address_t * in,
|
||||
ip46_type_t type, struct _vl_api_address *out);
|
||||
extern void ip6_address_encode (const ip6_address_t * in,
|
||||
vl_api_ip6_address_t out);
|
||||
extern void ip6_address_decode (const vl_api_ip6_address_t in,
|
||||
ip6_address_t * out);
|
||||
extern void ip4_address_encode (const ip4_address_t * in,
|
||||
vl_api_ip4_address_t out);
|
||||
extern void ip4_address_decode (const vl_api_ip4_address_t in,
|
||||
ip4_address_t * out);
|
||||
|
||||
extern void ip_prefix_decode (const struct _vl_api_prefix *in,
|
||||
fib_prefix_t * out);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user