2014-11-11 11:53:47 -08:00
|
|
|
/*
|
2016-04-22 16:51:03 -07:00
|
|
|
* Copyright (c) 2014, 2015, 2016 Nicira, Inc.
|
2014-11-11 11:53:47 -08:00
|
|
|
*
|
|
|
|
* 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 <config.h>
|
2015-10-22 15:28:56 -02:00
|
|
|
|
2015-11-30 16:24:49 -02:00
|
|
|
#include "tnl-neigh-cache.h"
|
2015-10-22 15:28:56 -02:00
|
|
|
|
2014-11-11 11:53:47 -08:00
|
|
|
#include <inttypes.h>
|
2015-10-14 04:50:15 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netinet/in.h>
|
2015-09-29 19:10:57 -03:00
|
|
|
#include <netinet/icmp6.h>
|
2014-11-11 11:53:47 -08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "bitmap.h"
|
|
|
|
#include "cmap.h"
|
|
|
|
#include "coverage.h"
|
|
|
|
#include "dpif-netdev.h"
|
2016-03-03 10:20:46 -08:00
|
|
|
#include "openvswitch/dynamic-string.h"
|
2014-11-11 11:53:47 -08:00
|
|
|
#include "errno.h"
|
|
|
|
#include "flow.h"
|
|
|
|
#include "netdev.h"
|
2021-11-27 00:12:45 +01:00
|
|
|
#include "ovs-atomic.h"
|
2014-11-11 11:53:47 -08:00
|
|
|
#include "ovs-thread.h"
|
|
|
|
#include "packets.h"
|
2017-11-03 13:53:53 +08:00
|
|
|
#include "openvswitch/poll-loop.h"
|
2014-11-11 11:53:47 -08:00
|
|
|
#include "seq.h"
|
2015-07-21 16:19:54 -07:00
|
|
|
#include "socket-util.h"
|
2014-11-11 11:53:47 -08:00
|
|
|
#include "timeval.h"
|
|
|
|
#include "unaligned.h"
|
|
|
|
#include "unixctl.h"
|
|
|
|
#include "util.h"
|
2014-12-15 14:10:38 +01:00
|
|
|
#include "openvswitch/vlog.h"
|
2014-11-11 11:53:47 -08:00
|
|
|
|
|
|
|
|
2021-11-27 00:12:45 +01:00
|
|
|
#define NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS (15 * 60 * 1000)
|
2021-11-27 00:12:51 +01:00
|
|
|
#define NEIGH_ENTRY_MAX_AGING_TIME_S 3600
|
2014-11-11 11:53:47 -08:00
|
|
|
|
2015-11-30 16:24:49 -02:00
|
|
|
struct tnl_neigh_entry {
|
2014-11-11 11:53:47 -08:00
|
|
|
struct cmap_node cmap_node;
|
2015-09-29 19:10:57 -03:00
|
|
|
struct in6_addr ip;
|
2015-08-28 14:55:11 -07:00
|
|
|
struct eth_addr mac;
|
2021-11-27 00:12:45 +01:00
|
|
|
atomic_llong expires; /* Expiration time in ms. */
|
2014-11-11 11:53:47 -08:00
|
|
|
char br_name[IFNAMSIZ];
|
|
|
|
};
|
|
|
|
|
2016-04-22 16:51:03 -07:00
|
|
|
static struct cmap table = CMAP_INITIALIZER;
|
2014-11-11 11:53:47 -08:00
|
|
|
static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER;
|
2021-11-27 00:12:51 +01:00
|
|
|
static atomic_uint32_t neigh_aging;
|
2014-11-11 11:53:47 -08:00
|
|
|
|
2015-09-29 19:10:57 -03:00
|
|
|
static uint32_t
|
2015-11-30 16:24:49 -02:00
|
|
|
tnl_neigh_hash(const struct in6_addr *ip)
|
2015-09-29 19:10:57 -03:00
|
|
|
{
|
|
|
|
return hash_bytes(ip->s6_addr, 16, 0);
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:12:45 +01:00
|
|
|
static bool
|
|
|
|
tnl_neigh_expired(struct tnl_neigh_entry *neigh)
|
|
|
|
{
|
|
|
|
long long expires;
|
|
|
|
|
|
|
|
atomic_read_explicit(&neigh->expires, &expires, memory_order_acquire);
|
|
|
|
|
|
|
|
return expires <= time_msec();
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:12:51 +01:00
|
|
|
static uint32_t
|
|
|
|
tnl_neigh_get_aging(void)
|
|
|
|
{
|
|
|
|
unsigned int aging;
|
|
|
|
|
|
|
|
atomic_read_explicit(&neigh_aging, &aging, memory_order_acquire);
|
|
|
|
return aging;
|
|
|
|
}
|
|
|
|
|
2015-11-30 16:24:49 -02:00
|
|
|
static struct tnl_neigh_entry *
|
|
|
|
tnl_neigh_lookup__(const char br_name[IFNAMSIZ], const struct in6_addr *dst)
|
2014-11-11 11:53:47 -08:00
|
|
|
{
|
2015-11-30 16:24:49 -02:00
|
|
|
struct tnl_neigh_entry *neigh;
|
2015-09-29 19:10:57 -03:00
|
|
|
uint32_t hash;
|
2014-11-11 11:53:47 -08:00
|
|
|
|
2015-11-30 16:24:49 -02:00
|
|
|
hash = tnl_neigh_hash(dst);
|
|
|
|
CMAP_FOR_EACH_WITH_HASH (neigh, cmap_node, hash, &table) {
|
|
|
|
if (ipv6_addr_equals(&neigh->ip, dst) && !strcmp(neigh->br_name, br_name)) {
|
2021-11-27 00:12:45 +01:00
|
|
|
if (tnl_neigh_expired(neigh)) {
|
2016-04-25 15:58:33 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:12:45 +01:00
|
|
|
atomic_store_explicit(&neigh->expires, time_msec() +
|
2021-11-27 00:12:51 +01:00
|
|
|
tnl_neigh_get_aging(),
|
2021-11-27 00:12:45 +01:00
|
|
|
memory_order_release);
|
2015-11-30 16:24:49 -02:00
|
|
|
return neigh;
|
2014-11-11 11:53:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-29 19:10:57 -03:00
|
|
|
int
|
2015-11-30 16:24:49 -02:00
|
|
|
tnl_neigh_lookup(const char br_name[IFNAMSIZ], const struct in6_addr *dst,
|
|
|
|
struct eth_addr *mac)
|
2015-09-29 19:10:57 -03:00
|
|
|
{
|
2015-11-30 16:24:49 -02:00
|
|
|
struct tnl_neigh_entry *neigh;
|
2015-09-29 19:10:57 -03:00
|
|
|
int res = ENOENT;
|
|
|
|
|
2015-11-30 16:24:49 -02:00
|
|
|
neigh = tnl_neigh_lookup__(br_name, dst);
|
|
|
|
if (neigh) {
|
|
|
|
*mac = neigh->mac;
|
2015-09-29 19:10:57 -03:00
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-11-11 11:53:47 -08:00
|
|
|
static void
|
2015-11-30 16:24:49 -02:00
|
|
|
neigh_entry_free(struct tnl_neigh_entry *neigh)
|
2014-11-11 11:53:47 -08:00
|
|
|
{
|
2015-11-30 16:24:49 -02:00
|
|
|
free(neigh);
|
2014-11-11 11:53:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-11-30 16:24:49 -02:00
|
|
|
tnl_neigh_delete(struct tnl_neigh_entry *neigh)
|
2014-11-11 11:53:47 -08:00
|
|
|
{
|
2015-11-30 16:24:49 -02:00
|
|
|
uint32_t hash = tnl_neigh_hash(&neigh->ip);
|
|
|
|
cmap_remove(&table, &neigh->cmap_node, hash);
|
|
|
|
ovsrcu_postpone(neigh_entry_free, neigh);
|
2014-11-11 11:53:47 -08:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:13:04 +01:00
|
|
|
void
|
|
|
|
tnl_neigh_set(const char name[IFNAMSIZ], const struct in6_addr *dst,
|
|
|
|
const struct eth_addr mac)
|
2014-11-11 11:53:47 -08:00
|
|
|
{
|
|
|
|
ovs_mutex_lock(&mutex);
|
2015-11-30 16:24:49 -02:00
|
|
|
struct tnl_neigh_entry *neigh = tnl_neigh_lookup__(name, dst);
|
|
|
|
if (neigh) {
|
|
|
|
if (eth_addr_equals(neigh->mac, mac)) {
|
2021-11-27 00:12:45 +01:00
|
|
|
atomic_store_relaxed(&neigh->expires, time_msec() +
|
2021-11-27 00:12:51 +01:00
|
|
|
tnl_neigh_get_aging());
|
2014-11-11 11:53:47 -08:00
|
|
|
ovs_mutex_unlock(&mutex);
|
2015-07-21 16:19:54 -07:00
|
|
|
return;
|
2014-11-11 11:53:47 -08:00
|
|
|
}
|
2015-11-30 16:24:49 -02:00
|
|
|
tnl_neigh_delete(neigh);
|
2014-11-11 11:53:47 -08:00
|
|
|
}
|
2017-01-20 09:27:38 -08:00
|
|
|
seq_change(tnl_conf_seq);
|
2014-11-11 11:53:47 -08:00
|
|
|
|
2015-11-30 16:24:49 -02:00
|
|
|
neigh = xmalloc(sizeof *neigh);
|
2014-11-11 11:53:47 -08:00
|
|
|
|
2015-11-30 16:24:49 -02:00
|
|
|
neigh->ip = *dst;
|
|
|
|
neigh->mac = mac;
|
2021-11-27 00:12:45 +01:00
|
|
|
atomic_store_relaxed(&neigh->expires, time_msec() +
|
2021-11-27 00:12:51 +01:00
|
|
|
tnl_neigh_get_aging());
|
2015-11-30 16:24:49 -02:00
|
|
|
ovs_strlcpy(neigh->br_name, name, sizeof neigh->br_name);
|
|
|
|
cmap_insert(&table, &neigh->cmap_node, tnl_neigh_hash(&neigh->ip));
|
2014-11-11 11:53:47 -08:00
|
|
|
ovs_mutex_unlock(&mutex);
|
2015-07-21 16:19:54 -07:00
|
|
|
}
|
|
|
|
|
2015-09-29 19:10:57 -03:00
|
|
|
static void
|
|
|
|
tnl_arp_set(const char name[IFNAMSIZ], ovs_be32 dst,
|
|
|
|
const struct eth_addr mac)
|
|
|
|
{
|
2015-12-03 13:00:38 -08:00
|
|
|
struct in6_addr dst6 = in6_addr_mapped_ipv4(dst);
|
2021-11-27 00:13:04 +01:00
|
|
|
tnl_neigh_set(name, &dst6, mac);
|
2015-09-29 19:10:57 -03:00
|
|
|
}
|
|
|
|
|
2015-11-30 16:24:49 -02:00
|
|
|
static int
|
2015-07-21 16:19:54 -07:00
|
|
|
tnl_arp_snoop(const struct flow *flow, struct flow_wildcards *wc,
|
2021-11-27 00:12:58 +01:00
|
|
|
const char name[IFNAMSIZ], bool allow_update)
|
2015-07-21 16:19:54 -07:00
|
|
|
{
|
2018-04-05 12:20:27 +00:00
|
|
|
/* Snoop normal ARP replies and gratuitous ARP requests/replies only */
|
|
|
|
if (!is_arp(flow)
|
|
|
|
|| (!is_garp(flow, wc) &&
|
|
|
|
FLOW_WC_GET_AND_MASK_WC(flow, wc, nw_proto) != ARP_OP_REPLY)
|
2016-05-24 17:13:29 -07:00
|
|
|
|| eth_addr_is_zero(FLOW_WC_GET_AND_MASK_WC(flow, wc, arp_sha))) {
|
2015-07-21 16:19:54 -07:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:12:58 +01:00
|
|
|
memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
|
|
|
|
|
|
|
|
if (allow_update) {
|
|
|
|
tnl_arp_set(name, flow->nw_src, flow->arp_sha);
|
|
|
|
}
|
2015-09-29 19:10:57 -03:00
|
|
|
return 0;
|
|
|
|
}
|
2015-07-21 16:19:54 -07:00
|
|
|
|
2015-11-30 16:24:49 -02:00
|
|
|
static int
|
2015-09-29 19:10:57 -03:00
|
|
|
tnl_nd_snoop(const struct flow *flow, struct flow_wildcards *wc,
|
2021-11-27 00:12:58 +01:00
|
|
|
const char name[IFNAMSIZ], bool allow_update)
|
2015-09-29 19:10:57 -03:00
|
|
|
{
|
2016-05-24 17:13:29 -07:00
|
|
|
if (!is_nd(flow, wc) || flow->tp_src != htons(ND_NEIGHBOR_ADVERT)) {
|
2015-09-29 19:10:57 -03:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2016-03-24 09:30:57 -07:00
|
|
|
/* - RFC4861 says Neighbor Advertisements sent in response to unicast Neighbor
|
|
|
|
* Solicitations SHOULD include the Target link-layer address. However, Linux
|
|
|
|
* doesn't. So, the response to Solicitations sent by OVS will include the
|
|
|
|
* TLL address and other Advertisements not including it can be ignored.
|
|
|
|
* - OVS flow extract can set this field to zero in case of packet parsing errors.
|
|
|
|
* For details refer miniflow_extract()*/
|
2016-05-24 17:13:29 -07:00
|
|
|
if (eth_addr_is_zero(FLOW_WC_GET_AND_MASK_WC(flow, wc, arp_tha))) {
|
2016-03-24 09:30:57 -07:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2015-09-29 19:10:57 -03:00
|
|
|
|
|
|
|
memset(&wc->masks.ipv6_src, 0xff, sizeof wc->masks.ipv6_src);
|
|
|
|
memset(&wc->masks.ipv6_dst, 0xff, sizeof wc->masks.ipv6_dst);
|
|
|
|
memset(&wc->masks.nd_target, 0xff, sizeof wc->masks.nd_target);
|
|
|
|
|
2021-11-27 00:12:58 +01:00
|
|
|
if (allow_update) {
|
2021-11-27 00:13:04 +01:00
|
|
|
tnl_neigh_set(name, &flow->nd_target, flow->arp_tha);
|
2021-11-27 00:12:58 +01:00
|
|
|
}
|
2014-11-11 11:53:47 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-30 16:24:49 -02:00
|
|
|
int
|
|
|
|
tnl_neigh_snoop(const struct flow *flow, struct flow_wildcards *wc,
|
2021-11-27 00:12:58 +01:00
|
|
|
const char name[IFNAMSIZ], bool allow_update)
|
2015-11-30 16:24:49 -02:00
|
|
|
{
|
|
|
|
int res;
|
2021-11-27 00:12:58 +01:00
|
|
|
res = tnl_arp_snoop(flow, wc, name, allow_update);
|
2015-11-30 16:24:49 -02:00
|
|
|
if (res != EINVAL) {
|
|
|
|
return res;
|
|
|
|
}
|
2021-11-27 00:12:58 +01:00
|
|
|
return tnl_nd_snoop(flow, wc, name, allow_update);
|
2015-11-30 16:24:49 -02:00
|
|
|
}
|
|
|
|
|
2014-11-11 11:53:47 -08:00
|
|
|
void
|
2015-11-30 16:24:49 -02:00
|
|
|
tnl_neigh_cache_run(void)
|
2014-11-11 11:53:47 -08:00
|
|
|
{
|
2015-11-30 16:24:49 -02:00
|
|
|
struct tnl_neigh_entry *neigh;
|
2014-11-11 11:53:47 -08:00
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
ovs_mutex_lock(&mutex);
|
2015-11-30 16:24:49 -02:00
|
|
|
CMAP_FOR_EACH(neigh, cmap_node, &table) {
|
2021-11-27 00:12:45 +01:00
|
|
|
if (tnl_neigh_expired(neigh)) {
|
2015-11-30 16:24:49 -02:00
|
|
|
tnl_neigh_delete(neigh);
|
2015-07-21 16:03:49 -07:00
|
|
|
changed = true;
|
2014-11-11 11:53:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ovs_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
seq_change(tnl_conf_seq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-16 10:54:31 -04:00
|
|
|
void
|
|
|
|
tnl_neigh_flush(const char br_name[IFNAMSIZ])
|
|
|
|
{
|
|
|
|
struct tnl_neigh_entry *neigh;
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
ovs_mutex_lock(&mutex);
|
|
|
|
CMAP_FOR_EACH (neigh, cmap_node, &table) {
|
|
|
|
if (!strcmp(neigh->br_name, br_name)) {
|
|
|
|
tnl_neigh_delete(neigh);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ovs_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
seq_change(tnl_conf_seq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-11 11:53:47 -08:00
|
|
|
static void
|
2015-11-30 16:24:49 -02:00
|
|
|
tnl_neigh_cache_flush(struct unixctl_conn *conn, int argc OVS_UNUSED,
|
2014-11-11 11:53:47 -08:00
|
|
|
const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
|
|
|
|
{
|
2015-11-30 16:24:49 -02:00
|
|
|
struct tnl_neigh_entry *neigh;
|
2014-11-11 11:53:47 -08:00
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
ovs_mutex_lock(&mutex);
|
2015-11-30 16:24:49 -02:00
|
|
|
CMAP_FOR_EACH(neigh, cmap_node, &table) {
|
|
|
|
tnl_neigh_delete(neigh);
|
2015-07-21 16:03:49 -07:00
|
|
|
changed = true;
|
2014-11-11 11:53:47 -08:00
|
|
|
}
|
|
|
|
ovs_mutex_unlock(&mutex);
|
|
|
|
if (changed) {
|
|
|
|
seq_change(tnl_conf_seq);
|
|
|
|
}
|
|
|
|
unixctl_command_reply(conn, "OK");
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:12:51 +01:00
|
|
|
static void
|
|
|
|
tnl_neigh_cache_aging(struct unixctl_conn *conn, int argc,
|
|
|
|
const char *argv[], void *aux OVS_UNUSED)
|
|
|
|
{
|
|
|
|
long long int new_exp, curr_exp;
|
|
|
|
struct tnl_neigh_entry *neigh;
|
|
|
|
uint32_t aging;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
struct ds ds = DS_EMPTY_INITIALIZER;
|
|
|
|
ds_put_format(&ds, "%"PRIu32, tnl_neigh_get_aging() / 1000);
|
|
|
|
unixctl_command_reply(conn, ds_cstr(&ds));
|
|
|
|
ds_destroy(&ds);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ovs_scan(argv[1], "%"SCNu32, &aging) ||
|
|
|
|
!aging || aging > NEIGH_ENTRY_MAX_AGING_TIME_S) {
|
|
|
|
unixctl_command_reply_error(conn, "bad aging value");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aging *= 1000;
|
|
|
|
atomic_store_explicit(&neigh_aging, aging, memory_order_release);
|
|
|
|
new_exp = time_msec() + aging;
|
|
|
|
|
|
|
|
CMAP_FOR_EACH (neigh, cmap_node, &table) {
|
|
|
|
atomic_read_explicit(&neigh->expires, &curr_exp,
|
|
|
|
memory_order_acquire);
|
|
|
|
if (new_exp < curr_exp) {
|
|
|
|
atomic_store_explicit(&neigh->expires, new_exp,
|
|
|
|
memory_order_release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unixctl_command_reply(conn, "OK");
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:28:55 -02:00
|
|
|
static int
|
|
|
|
lookup_any(const char *host_name, struct in6_addr *address)
|
|
|
|
{
|
|
|
|
if (addr_is_ipv6(host_name)) {
|
|
|
|
return lookup_ipv6(host_name, address);
|
|
|
|
} else {
|
|
|
|
int r;
|
|
|
|
struct in_addr ip;
|
|
|
|
r = lookup_ip(host_name, &ip);
|
|
|
|
if (r == 0) {
|
|
|
|
in6_addr_set_mapped_ipv4(address, ip.s_addr);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
|
2015-07-21 16:19:54 -07:00
|
|
|
static void
|
2015-11-30 16:24:49 -02:00
|
|
|
tnl_neigh_cache_add(struct unixctl_conn *conn, int argc OVS_UNUSED,
|
|
|
|
const char *argv[], void *aux OVS_UNUSED)
|
2015-07-21 16:19:54 -07:00
|
|
|
{
|
|
|
|
const char *br_name = argv[1];
|
|
|
|
struct eth_addr mac;
|
2015-09-29 19:10:57 -03:00
|
|
|
struct in6_addr ip6;
|
2015-07-21 16:19:54 -07:00
|
|
|
|
2015-10-22 15:28:55 -02:00
|
|
|
if (lookup_any(argv[2], &ip6) != 0) {
|
2015-07-21 16:19:54 -07:00
|
|
|
unixctl_command_reply_error(conn, "bad IP address");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eth_addr_from_string(argv[3], &mac)) {
|
|
|
|
unixctl_command_reply_error(conn, "bad MAC address");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:13:04 +01:00
|
|
|
tnl_neigh_set(br_name, &ip6, mac);
|
2015-07-21 16:19:54 -07:00
|
|
|
unixctl_command_reply(conn, "OK");
|
|
|
|
}
|
|
|
|
|
2014-11-11 11:53:47 -08:00
|
|
|
static void
|
2015-11-30 16:24:49 -02:00
|
|
|
tnl_neigh_cache_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
|
|
|
|
const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
|
2014-11-11 11:53:47 -08:00
|
|
|
{
|
|
|
|
struct ds ds = DS_EMPTY_INITIALIZER;
|
2015-11-30 16:24:49 -02:00
|
|
|
struct tnl_neigh_entry *neigh;
|
2014-11-11 11:53:47 -08:00
|
|
|
|
2015-09-29 19:10:57 -03:00
|
|
|
ds_put_cstr(&ds, "IP MAC Bridge\n");
|
|
|
|
ds_put_cstr(&ds, "==========================================================================\n");
|
2014-11-11 11:53:47 -08:00
|
|
|
ovs_mutex_lock(&mutex);
|
2015-11-30 16:24:49 -02:00
|
|
|
CMAP_FOR_EACH(neigh, cmap_node, &table) {
|
2014-11-11 11:53:47 -08:00
|
|
|
int start_len, need_ws;
|
|
|
|
|
|
|
|
start_len = ds.length;
|
2015-11-30 16:24:49 -02:00
|
|
|
ipv6_format_mapped(&neigh->ip, &ds);
|
2014-11-11 11:53:47 -08:00
|
|
|
|
2015-09-29 19:10:57 -03:00
|
|
|
need_ws = INET6_ADDRSTRLEN - (ds.length - start_len);
|
2014-11-11 11:53:47 -08:00
|
|
|
ds_put_char_multiple(&ds, ' ', need_ws);
|
|
|
|
|
2016-04-25 15:58:33 -07:00
|
|
|
ds_put_format(&ds, ETH_ADDR_FMT" %s",
|
2015-11-30 16:24:49 -02:00
|
|
|
ETH_ADDR_ARGS(neigh->mac), neigh->br_name);
|
2021-11-27 00:12:45 +01:00
|
|
|
if (tnl_neigh_expired(neigh)) {
|
2016-04-25 15:58:33 -07:00
|
|
|
ds_put_format(&ds, " STALE");
|
|
|
|
}
|
|
|
|
ds_put_char(&ds, '\n');
|
2014-11-11 11:53:47 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
ovs_mutex_unlock(&mutex);
|
|
|
|
unixctl_command_reply(conn, ds_cstr(&ds));
|
|
|
|
ds_destroy(&ds);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-11-30 16:24:49 -02:00
|
|
|
tnl_neigh_cache_init(void)
|
2014-11-11 11:53:47 -08:00
|
|
|
{
|
2021-11-27 00:12:51 +01:00
|
|
|
atomic_init(&neigh_aging, NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS);
|
|
|
|
unixctl_command_register("tnl/arp/show", "", 0, 0,
|
|
|
|
tnl_neigh_cache_show, NULL);
|
|
|
|
unixctl_command_register("tnl/arp/set", "BRIDGE IP MAC", 3, 3,
|
|
|
|
tnl_neigh_cache_add, NULL);
|
|
|
|
unixctl_command_register("tnl/arp/flush", "", 0, 0,
|
|
|
|
tnl_neigh_cache_flush, NULL);
|
|
|
|
unixctl_command_register("tnl/arp/aging", "[SECS]", 0, 1,
|
|
|
|
tnl_neigh_cache_aging, NULL);
|
|
|
|
unixctl_command_register("tnl/neigh/show", "", 0, 0,
|
|
|
|
tnl_neigh_cache_show, NULL);
|
|
|
|
unixctl_command_register("tnl/neigh/set", "BRIDGE IP MAC", 3, 3,
|
|
|
|
tnl_neigh_cache_add, NULL);
|
|
|
|
unixctl_command_register("tnl/neigh/flush", "", 0, 0,
|
|
|
|
tnl_neigh_cache_flush, NULL);
|
|
|
|
unixctl_command_register("tnl/neigh/aging", "[SECS]", 0, 1,
|
|
|
|
tnl_neigh_cache_aging, NULL);
|
2014-11-11 11:53:47 -08:00
|
|
|
}
|