1998-05-26 21:42:05 +00:00
|
|
|
/*
|
1998-06-01 21:41:11 +00:00
|
|
|
* BIRD -- Management of Interfaces and Neighbor Cache
|
1998-05-26 21:42:05 +00:00
|
|
|
*
|
2000-03-01 14:51:47 +00:00
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
1998-05-26 21:42:05 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* DOC: Interfaces
|
|
|
|
*
|
|
|
|
* The interface module keeps track of all network interfaces in the
|
|
|
|
* system and their addresses.
|
|
|
|
*
|
|
|
|
* Each interface is represented by an &iface structure which carries
|
|
|
|
* interface capability flags (%IF_MULTIACCESS, %IF_BROADCAST etc.),
|
|
|
|
* MTU, interface name and index and finally a linked list of network
|
|
|
|
* prefixes assigned to the interface, each one represented by
|
|
|
|
* struct &ifa.
|
|
|
|
*
|
|
|
|
* The interface module keeps a `soft-up' state for each &iface which
|
|
|
|
* is a conjunction of link being up, the interface being of a `sane'
|
|
|
|
* type and at least one IP address assigned to it.
|
|
|
|
*/
|
|
|
|
|
2000-03-12 20:50:35 +00:00
|
|
|
#undef LOCAL_DEBUG
|
1998-06-01 21:41:11 +00:00
|
|
|
|
1998-05-26 21:42:05 +00:00
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/iface.h"
|
1998-06-01 21:41:11 +00:00
|
|
|
#include "nest/protocol.h"
|
1999-11-25 15:35:30 +00:00
|
|
|
#include "nest/cli.h"
|
1998-05-26 21:42:05 +00:00
|
|
|
#include "lib/resource.h"
|
1998-11-29 22:01:03 +00:00
|
|
|
#include "lib/string.h"
|
2023-04-04 14:41:55 +00:00
|
|
|
#include "lib/locking.h"
|
1999-02-13 18:42:00 +00:00
|
|
|
#include "conf/conf.h"
|
2017-12-07 12:06:01 +00:00
|
|
|
#include "sysdep/unix/krt.h"
|
1998-05-26 21:42:05 +00:00
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
DOMAIN(attrs) iface_domain;
|
|
|
|
|
|
|
|
#define IFACE_LOCK LOCK_DOMAIN(attrs, iface_domain)
|
|
|
|
#define IFACE_UNLOCK UNLOCK_DOMAIN(attrs, iface_domain)
|
|
|
|
#define IFACE_ASSERT_LOCKED ASSERT_DIE(DOMAIN_IS_LOCKED(attrs, iface_domain))
|
2023-01-31 12:07:46 +00:00
|
|
|
|
|
|
|
static TLIST_LIST(ifsub) iface_sub_list;
|
|
|
|
static slab *iface_sub_slab;
|
1998-05-26 21:42:05 +00:00
|
|
|
static pool *if_pool;
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
list global_iface_list;
|
2021-11-15 09:53:58 +00:00
|
|
|
struct iface default_vrf;
|
1998-06-01 21:41:11 +00:00
|
|
|
|
2017-12-07 12:06:01 +00:00
|
|
|
static void if_recalc_preferred(struct iface *i);
|
|
|
|
|
2024-01-27 18:01:34 +00:00
|
|
|
static void ifa_delete_locked(struct ifa *a);
|
|
|
|
|
2024-12-13 14:23:01 +00:00
|
|
|
static void ifa_dump_locked(struct dump_request *, struct ifa *);
|
|
|
|
static void if_dump_locked(struct dump_request *, struct iface *);
|
2023-04-04 14:41:55 +00:00
|
|
|
|
|
|
|
struct iface *
|
|
|
|
if_walk_first(void)
|
|
|
|
{
|
|
|
|
IFACE_LOCK;
|
|
|
|
struct iface *i = HEAD(global_iface_list);
|
|
|
|
return NODE_VALID(i) ? i : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iface *
|
|
|
|
if_walk_next(struct iface *i)
|
|
|
|
{
|
|
|
|
IFACE_ASSERT_LOCKED;
|
|
|
|
i = NODE_NEXT(i);
|
|
|
|
return NODE_VALID(i) ? i : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
if_walk_done(void)
|
|
|
|
{
|
|
|
|
IFACE_ASSERT_LOCKED;
|
|
|
|
IFACE_UNLOCK;
|
|
|
|
}
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* ifa_dump - dump interface address
|
|
|
|
* @a: interface address descriptor
|
|
|
|
*
|
|
|
|
* This function dumps contents of an &ifa to the debug output.
|
|
|
|
*/
|
1999-05-06 21:38:11 +00:00
|
|
|
void
|
2024-11-14 19:43:35 +00:00
|
|
|
ifa_dump(struct dump_request *dreq, struct ifa *a)
|
2023-04-04 14:41:55 +00:00
|
|
|
{
|
|
|
|
IFACE_LOCK;
|
2024-12-13 14:23:01 +00:00
|
|
|
ifa_dump_locked(dreq, a);
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_UNLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2024-12-13 14:23:01 +00:00
|
|
|
ifa_dump_locked(struct dump_request *dreq, struct ifa *a)
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP("\t%I, net %N bc %I -> %I%s%s%s%s\n", a->ip, &a->prefix, a->brd, a->opposite,
|
2017-08-21 12:14:07 +00:00
|
|
|
(a->flags & IA_PRIMARY) ? " PRIMARY" : "",
|
|
|
|
(a->flags & IA_SECONDARY) ? " SEC" : "",
|
|
|
|
(a->flags & IA_HOST) ? " HOST" : "",
|
|
|
|
(a->flags & IA_PEER) ? " PEER" : "");
|
1999-05-06 21:38:11 +00:00
|
|
|
}
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* if_dump - dump interface
|
|
|
|
* @i: interface to dump
|
|
|
|
*
|
|
|
|
* This function dumps all information associated with a given
|
|
|
|
* network interface to the debug output.
|
|
|
|
*/
|
1998-06-01 21:41:11 +00:00
|
|
|
void
|
2024-11-14 19:43:35 +00:00
|
|
|
if_dump(struct dump_request *dreq, struct iface *i)
|
2023-04-04 14:41:55 +00:00
|
|
|
{
|
|
|
|
IFACE_LOCK;
|
2024-12-13 14:23:01 +00:00
|
|
|
if_dump_locked(dreq, i);
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_UNLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2024-12-13 14:23:01 +00:00
|
|
|
if_dump_locked(struct dump_request *dreq, struct iface *i)
|
1998-06-01 21:41:11 +00:00
|
|
|
{
|
1999-05-06 21:38:11 +00:00
|
|
|
struct ifa *a;
|
|
|
|
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP("IF%d: %s", i->index, i->name);
|
2010-11-11 09:03:02 +00:00
|
|
|
if (i->flags & IF_SHUTDOWN)
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP(" SHUTDOWN");
|
1998-05-26 21:42:05 +00:00
|
|
|
if (i->flags & IF_UP)
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP(" UP");
|
1999-03-02 17:28:06 +00:00
|
|
|
else
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP(" DOWN");
|
2010-11-11 09:03:02 +00:00
|
|
|
if (i->flags & IF_ADMIN_UP)
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP(" LINK-UP");
|
1998-05-26 21:42:05 +00:00
|
|
|
if (i->flags & IF_MULTIACCESS)
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP(" MA");
|
1998-05-26 21:42:05 +00:00
|
|
|
if (i->flags & IF_BROADCAST)
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP(" BC");
|
1998-05-26 21:42:05 +00:00
|
|
|
if (i->flags & IF_MULTICAST)
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP(" MC");
|
1998-05-26 21:42:05 +00:00
|
|
|
if (i->flags & IF_LOOPBACK)
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP(" LOOP");
|
1998-05-26 21:42:05 +00:00
|
|
|
if (i->flags & IF_IGNORE)
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP(" IGN");
|
1999-05-06 21:38:11 +00:00
|
|
|
if (i->flags & IF_TMP_DOWN)
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP(" TDOWN");
|
|
|
|
RDUMP(" MTU=%d\n", i->mtu);
|
1999-05-06 21:38:11 +00:00
|
|
|
WALK_LIST(a, i->addrs)
|
|
|
|
{
|
2024-12-13 14:23:01 +00:00
|
|
|
ifa_dump_locked(dreq, a);
|
2017-12-16 15:31:43 +00:00
|
|
|
ASSERT(!!(a->flags & IA_PRIMARY) ==
|
|
|
|
((a == i->addr4) || (a == i->addr6) || (a == i->llv6)));
|
1999-05-06 21:38:11 +00:00
|
|
|
}
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* if_dump_all - dump all interfaces
|
|
|
|
*
|
|
|
|
* This function dumps information about all known network
|
|
|
|
* interfaces to the debug output.
|
|
|
|
*/
|
1998-05-26 21:42:05 +00:00
|
|
|
void
|
2024-11-14 19:43:35 +00:00
|
|
|
if_dump_all(struct dump_request *dreq)
|
1998-05-26 21:42:05 +00:00
|
|
|
{
|
2024-11-14 19:43:35 +00:00
|
|
|
RDUMP("Known network interfaces:\n");
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_WALK(i)
|
2024-12-13 14:23:01 +00:00
|
|
|
if_dump_locked(dreq, i);
|
2024-06-13 14:30:51 +00:00
|
|
|
rcu_read_lock();
|
2024-12-13 14:23:01 +00:00
|
|
|
RDUMP("Router ID: %08x\n", atomic_load_explicit(&global_runtime, memory_order_relaxed)->router_id);
|
2024-06-13 14:30:51 +00:00
|
|
|
rcu_read_unlock();
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
void
|
|
|
|
if_link(struct iface *i)
|
|
|
|
{
|
|
|
|
IFACE_ASSERT_LOCKED;
|
|
|
|
|
|
|
|
if (i)
|
|
|
|
i->uc++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
if_unlink(struct iface *i)
|
|
|
|
{
|
|
|
|
IFACE_ASSERT_LOCKED;
|
|
|
|
|
|
|
|
if (i)
|
|
|
|
i->uc--;
|
|
|
|
/* TODO: Do some interface object cleanup */
|
|
|
|
}
|
|
|
|
|
|
|
|
void ifa_link(struct ifa *a)
|
|
|
|
{
|
|
|
|
IFACE_ASSERT_LOCKED;
|
|
|
|
|
|
|
|
if (a)
|
|
|
|
{
|
2023-09-24 20:20:01 +00:00
|
|
|
// debug("ifa_link: %p %d\n", a, a->uc);
|
2023-04-04 14:41:55 +00:00
|
|
|
a->uc++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ifa_unlink(struct ifa *a)
|
|
|
|
{
|
|
|
|
IFACE_ASSERT_LOCKED;
|
|
|
|
|
|
|
|
if (!a)
|
|
|
|
return;
|
|
|
|
|
2023-09-24 20:20:01 +00:00
|
|
|
// debug("ifa_unlink: %p %d\n", a, a->uc);
|
2023-04-04 14:41:55 +00:00
|
|
|
if (--a->uc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if_unlink(a->iface);
|
|
|
|
#if DEBUGGING
|
|
|
|
memset(a, 0x5b, sizeof(struct ifa));
|
|
|
|
#endif
|
|
|
|
mb_free(a);
|
|
|
|
}
|
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
static inline unsigned
|
|
|
|
if_what_changed(struct iface *i, struct iface *j)
|
1998-05-26 21:42:05 +00:00
|
|
|
{
|
1999-05-06 21:38:11 +00:00
|
|
|
unsigned c;
|
|
|
|
|
2010-11-11 11:24:27 +00:00
|
|
|
if (((i->flags ^ j->flags) & ~(IF_UP | IF_SHUTDOWN | IF_UPDATED | IF_ADMIN_UP | IF_LINK_UP | IF_TMP_DOWN | IF_JUST_CREATED))
|
2017-09-06 15:38:48 +00:00
|
|
|
|| (i->index != j->index) || (i->master != j->master))
|
1999-05-06 21:38:11 +00:00
|
|
|
return IF_CHANGE_TOO_MUCH;
|
|
|
|
c = 0;
|
|
|
|
if ((i->flags ^ j->flags) & IF_UP)
|
|
|
|
c |= (i->flags & IF_UP) ? IF_CHANGE_DOWN : IF_CHANGE_UP;
|
2010-11-11 09:03:02 +00:00
|
|
|
if ((i->flags ^ j->flags) & IF_LINK_UP)
|
|
|
|
c |= IF_CHANGE_LINK;
|
1999-05-06 21:38:11 +00:00
|
|
|
if (i->mtu != j->mtu)
|
|
|
|
c |= IF_CHANGE_MTU;
|
|
|
|
return c;
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
1998-06-01 21:41:11 +00:00
|
|
|
if_copy(struct iface *to, struct iface *from)
|
1998-05-26 21:42:05 +00:00
|
|
|
{
|
1999-05-06 21:38:11 +00:00
|
|
|
to->flags = from->flags | (to->flags & IF_TMP_DOWN);
|
1998-06-01 21:41:11 +00:00
|
|
|
to->mtu = from->mtu;
|
2017-09-06 15:38:48 +00:00
|
|
|
to->master_index = from->master_index;
|
2023-01-31 12:07:46 +00:00
|
|
|
|
|
|
|
if_unlink(to->master);
|
|
|
|
if_link(to->master = from->master);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
if_enqueue_notify_to(struct iface_notification x, struct iface_subscription *s)
|
|
|
|
{
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_ASSERT_LOCKED;
|
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
switch (x.type) {
|
|
|
|
case IFNOT_ADDRESS:
|
|
|
|
if (!s->ifa_notify) return;
|
|
|
|
ifa_link(x.a);
|
|
|
|
break;
|
|
|
|
case IFNOT_INTERFACE:
|
|
|
|
if (!s->if_notify) return;
|
|
|
|
if_link(x.i);
|
|
|
|
break;
|
|
|
|
case IFNOT_NEIGHBOR:
|
|
|
|
if (!s->neigh_notify) return;
|
2024-11-10 12:33:22 +00:00
|
|
|
neigh_link_locked(x.n);
|
2023-01-31 12:07:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bug("Unknown interface notification type: %d", x.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iface_notification *in = sl_alloc(iface_sub_slab);
|
|
|
|
*in = x;
|
|
|
|
|
2023-09-24 20:20:01 +00:00
|
|
|
iface_trace(s, "Enqueueing interface notification (%d, %p, %p)", x.type, x.a, in);
|
2023-01-31 12:07:46 +00:00
|
|
|
ifnot_add_tail(&s->queue, in);
|
2023-04-04 14:41:55 +00:00
|
|
|
ev_send(s->target, &s->event);
|
2023-01-31 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
if_enqueue_notify(struct iface_notification x)
|
|
|
|
{
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_ASSERT_LOCKED;
|
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
WALK_TLIST(ifsub, s, &iface_sub_list)
|
|
|
|
if_enqueue_notify_to(x, s);
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
|
|
|
|
2000-03-12 20:50:35 +00:00
|
|
|
static inline void
|
2023-01-31 12:07:46 +00:00
|
|
|
ifa_send_notify(struct iface_subscription *s, unsigned c, struct ifa *a)
|
2000-03-12 20:50:35 +00:00
|
|
|
{
|
2024-04-26 10:14:33 +00:00
|
|
|
SKIP_BACK_DECLARE(struct proto, p, iface_sub, s);
|
2023-01-31 12:07:46 +00:00
|
|
|
|
|
|
|
if (s->ifa_notify &&
|
2024-11-18 21:06:50 +00:00
|
|
|
(p->proto_state != PS_DOWN_XX) &&
|
|
|
|
(p->proto_state != PS_FLUSH) &&
|
2023-10-13 09:04:39 +00:00
|
|
|
(!p->vrf || if_in_vrf(a->iface, p->vrf)))
|
2000-03-12 20:50:35 +00:00
|
|
|
{
|
|
|
|
if (p->debug & D_IFACES)
|
2017-12-07 16:41:09 +00:00
|
|
|
log(L_TRACE "%s < address %N on interface %s %s",
|
|
|
|
p->name, &a->prefix, a->iface->name,
|
2000-03-12 20:50:35 +00:00
|
|
|
(c & IF_CHANGE_UP) ? "added" : "removed");
|
2023-01-31 12:07:46 +00:00
|
|
|
s->ifa_notify(p, c, a);
|
2000-03-12 20:50:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
static void
|
2014-11-03 19:35:58 +00:00
|
|
|
ifa_notify_change_(unsigned c, struct ifa *a)
|
1998-05-26 21:42:05 +00:00
|
|
|
{
|
2000-03-12 20:50:35 +00:00
|
|
|
DBG("IFA change notification (%x) for %s:%I\n", c, a->iface->name, a->ip);
|
2011-12-11 23:24:15 +00:00
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
if_enqueue_notify((struct iface_notification) {
|
|
|
|
.type = IFNOT_ADDRESS,
|
|
|
|
.a = a,
|
|
|
|
.flags = c,
|
|
|
|
});
|
|
|
|
|
2000-03-12 20:50:35 +00:00
|
|
|
}
|
|
|
|
|
2011-12-11 23:24:15 +00:00
|
|
|
static inline void
|
|
|
|
ifa_notify_change(unsigned c, struct ifa *a)
|
|
|
|
{
|
2014-11-03 19:35:58 +00:00
|
|
|
if (c & IF_CHANGE_DOWN)
|
2020-05-11 02:29:36 +00:00
|
|
|
neigh_ifa_down(a);
|
2014-11-03 19:35:58 +00:00
|
|
|
|
|
|
|
ifa_notify_change_(c, a);
|
|
|
|
|
|
|
|
if (c & IF_CHANGE_UP)
|
2020-05-11 02:29:36 +00:00
|
|
|
neigh_ifa_up(a);
|
2011-12-11 23:24:15 +00:00
|
|
|
}
|
|
|
|
|
2000-03-12 20:50:35 +00:00
|
|
|
static inline void
|
2023-01-31 12:07:46 +00:00
|
|
|
if_send_notify(struct iface_subscription *s, unsigned c, struct iface *i)
|
2000-03-12 20:50:35 +00:00
|
|
|
{
|
2024-04-26 10:14:33 +00:00
|
|
|
SKIP_BACK_DECLARE(struct proto, p, iface_sub, s);
|
2023-01-31 12:07:46 +00:00
|
|
|
|
|
|
|
if (s->if_notify &&
|
2024-11-18 21:06:50 +00:00
|
|
|
(p->proto_state != PS_DOWN_XX) &&
|
|
|
|
(p->proto_state != PS_FLUSH) &&
|
2023-10-13 09:04:39 +00:00
|
|
|
(!p->vrf || if_in_vrf(i, p->vrf)))
|
2000-03-12 20:50:35 +00:00
|
|
|
{
|
|
|
|
if (p->debug & D_IFACES)
|
|
|
|
log(L_TRACE "%s < interface %s %s", p->name, i->name,
|
|
|
|
(c & IF_CHANGE_UP) ? "goes up" :
|
|
|
|
(c & IF_CHANGE_DOWN) ? "goes down" :
|
|
|
|
(c & IF_CHANGE_MTU) ? "changes MTU" :
|
2010-11-11 09:03:02 +00:00
|
|
|
(c & IF_CHANGE_LINK) ? "changes link" :
|
2017-12-07 12:06:01 +00:00
|
|
|
(c & IF_CHANGE_PREFERRED) ? "changes preferred address" :
|
2000-03-12 20:50:35 +00:00
|
|
|
(c & IF_CHANGE_CREATE) ? "created" :
|
|
|
|
"sends unknown event");
|
2023-01-31 12:07:46 +00:00
|
|
|
s->if_notify(p, c, i);
|
2000-03-12 20:50:35 +00:00
|
|
|
}
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-05-06 21:38:11 +00:00
|
|
|
if_notify_change(unsigned c, struct iface *i)
|
1998-05-26 21:42:05 +00:00
|
|
|
{
|
1999-05-06 21:38:11 +00:00
|
|
|
struct ifa *a;
|
1998-06-03 08:40:10 +00:00
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
if (i->flags & IF_JUST_CREATED)
|
|
|
|
{
|
|
|
|
i->flags &= ~IF_JUST_CREATED;
|
|
|
|
c |= IF_CHANGE_CREATE | IF_CHANGE_MTU;
|
|
|
|
}
|
|
|
|
|
2000-03-12 20:50:35 +00:00
|
|
|
DBG("Interface change notification (%x) for %s\n", c, i->name);
|
2000-05-04 20:52:28 +00:00
|
|
|
#ifdef LOCAL_DEBUG
|
2023-04-04 14:41:55 +00:00
|
|
|
if_dump_locked(i);
|
2000-05-04 20:52:28 +00:00
|
|
|
#endif
|
1998-06-01 21:41:11 +00:00
|
|
|
|
2014-11-03 19:35:58 +00:00
|
|
|
if (c & IF_CHANGE_DOWN)
|
|
|
|
neigh_if_down(i);
|
2011-12-11 23:24:15 +00:00
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
if (c & IF_CHANGE_DOWN)
|
|
|
|
WALK_LIST(a, i->addrs)
|
2017-12-07 12:06:01 +00:00
|
|
|
ifa_notify_change_(IF_CHANGE_DOWN, a);
|
1998-06-01 21:41:11 +00:00
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
if_enqueue_notify((struct iface_notification) {
|
|
|
|
.type = IFNOT_INTERFACE,
|
|
|
|
.i = i,
|
|
|
|
.flags = c,
|
|
|
|
});
|
1998-06-01 21:41:11 +00:00
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
if (c & IF_CHANGE_UP)
|
|
|
|
WALK_LIST(a, i->addrs)
|
2017-12-07 12:06:01 +00:00
|
|
|
ifa_notify_change_(IF_CHANGE_UP, a);
|
2010-11-11 11:24:27 +00:00
|
|
|
|
2014-11-03 19:35:58 +00:00
|
|
|
if (c & IF_CHANGE_UP)
|
|
|
|
neigh_if_up(i);
|
|
|
|
|
2010-11-11 11:24:27 +00:00
|
|
|
if ((c & (IF_CHANGE_UP | IF_CHANGE_DOWN | IF_CHANGE_LINK)) == IF_CHANGE_LINK)
|
|
|
|
neigh_if_link(i);
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 12:06:01 +00:00
|
|
|
static uint
|
|
|
|
if_recalc_flags(struct iface *i UNUSED, uint flags)
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
2017-12-07 17:35:46 +00:00
|
|
|
if ((flags & IF_ADMIN_UP) &&
|
|
|
|
!(flags & (IF_SHUTDOWN | IF_TMP_DOWN)) &&
|
2021-11-15 09:53:58 +00:00
|
|
|
!(i->master_index && i->master == &default_vrf))
|
1999-05-06 21:38:11 +00:00
|
|
|
flags |= IF_UP;
|
2017-12-07 12:06:01 +00:00
|
|
|
else
|
|
|
|
flags &= ~IF_UP;
|
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-12-07 12:06:01 +00:00
|
|
|
if_change_flags(struct iface *i, uint flags)
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
2017-12-07 12:06:01 +00:00
|
|
|
uint of = i->flags;
|
1999-05-06 21:38:11 +00:00
|
|
|
i->flags = if_recalc_flags(i, flags);
|
2017-12-07 12:06:01 +00:00
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
if ((i->flags ^ of) & IF_UP)
|
|
|
|
if_notify_change((i->flags & IF_UP) ? IF_CHANGE_UP : IF_CHANGE_DOWN, i);
|
|
|
|
}
|
|
|
|
|
2012-01-23 00:26:40 +00:00
|
|
|
/**
|
2014-11-03 19:35:58 +00:00
|
|
|
* if_delete - remove interface
|
|
|
|
* @old: interface
|
2012-01-23 00:26:40 +00:00
|
|
|
*
|
|
|
|
* This function is called by the low-level platform dependent code
|
|
|
|
* whenever it notices an interface disappears. It is just a shorthand
|
|
|
|
* for if_update().
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
if_delete(struct iface *old)
|
|
|
|
{
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
2012-01-23 00:26:40 +00:00
|
|
|
struct iface f = {};
|
|
|
|
strncpy(f.name, old->name, sizeof(f.name)-1);
|
|
|
|
f.flags = IF_SHUTDOWN;
|
2023-04-04 14:41:55 +00:00
|
|
|
if_update_locked(&f);
|
|
|
|
IFACE_UNLOCK;
|
2012-01-23 00:26:40 +00:00
|
|
|
}
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* if_update - update interface status
|
|
|
|
* @new: new interface status
|
|
|
|
*
|
|
|
|
* if_update() is called by the low-level platform dependent code
|
|
|
|
* whenever it notices an interface change.
|
|
|
|
*
|
2000-06-05 21:26:11 +00:00
|
|
|
* There exist two types of interface updates -- synchronous and asynchronous
|
2000-06-03 14:40:39 +00:00
|
|
|
* ones. In the synchronous case, the low-level code calls if_start_update(),
|
|
|
|
* scans all interfaces reported by the OS, uses if_update() and ifa_update()
|
|
|
|
* to pass them to the core and then it finishes the update sequence by
|
|
|
|
* calling if_end_update(). When working asynchronously, the sysdep code
|
|
|
|
* calls if_update() and ifa_update() whenever it notices a change.
|
|
|
|
*
|
|
|
|
* if_update() will automatically notify all other modules about the change.
|
|
|
|
*/
|
1999-05-06 21:38:11 +00:00
|
|
|
struct iface *
|
1998-05-26 21:42:05 +00:00
|
|
|
if_update(struct iface *new)
|
2023-04-04 14:41:55 +00:00
|
|
|
{
|
|
|
|
IFACE_LOCK;
|
|
|
|
struct iface *i = if_update_locked(new);
|
|
|
|
IFACE_UNLOCK;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iface *
|
|
|
|
if_update_locked(struct iface *new)
|
1998-05-26 21:42:05 +00:00
|
|
|
{
|
|
|
|
struct iface *i;
|
1998-06-01 21:41:11 +00:00
|
|
|
unsigned c;
|
1998-05-26 21:42:05 +00:00
|
|
|
|
2021-11-15 09:53:58 +00:00
|
|
|
if (!new->master)
|
|
|
|
new->master = &default_vrf;
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
WALK_LIST(i, global_iface_list)
|
1998-05-26 21:42:05 +00:00
|
|
|
if (!strcmp(new->name, i->name))
|
|
|
|
{
|
1999-05-06 21:38:11 +00:00
|
|
|
new->flags = if_recalc_flags(new, new->flags);
|
|
|
|
c = if_what_changed(i, new);
|
|
|
|
if (c & IF_CHANGE_TOO_MUCH) /* Changed a lot, convert it to down/up */
|
1998-05-26 21:42:05 +00:00
|
|
|
{
|
1998-06-01 21:41:11 +00:00
|
|
|
DBG("Interface %s changed too much -- forcing down/up transition\n", i->name);
|
1999-05-06 21:38:11 +00:00
|
|
|
if_change_flags(i, i->flags | IF_TMP_DOWN);
|
1998-05-26 21:42:05 +00:00
|
|
|
rem_node(&i->n);
|
2017-12-07 12:06:01 +00:00
|
|
|
new->addr4 = i->addr4;
|
|
|
|
new->addr6 = i->addr6;
|
|
|
|
new->llv6 = i->llv6;
|
|
|
|
new->sysdep = i->sysdep;
|
1999-05-07 13:46:16 +00:00
|
|
|
memcpy(&new->addrs, &i->addrs, sizeof(i->addrs));
|
2023-01-31 12:07:46 +00:00
|
|
|
memcpy(&new->neighbors, &i->neighbors, sizeof(i->neighbors));
|
1999-05-07 13:46:16 +00:00
|
|
|
memcpy(i, new, sizeof(*i));
|
2018-02-06 16:43:55 +00:00
|
|
|
i->flags &= ~IF_UP; /* IF_TMP_DOWN will be added later */
|
1998-06-01 21:41:11 +00:00
|
|
|
goto newif;
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
2012-01-21 21:56:16 +00:00
|
|
|
|
|
|
|
if_copy(i, new);
|
|
|
|
if (c)
|
|
|
|
if_notify_change(c, i);
|
|
|
|
|
1999-03-02 18:36:09 +00:00
|
|
|
i->flags |= IF_UPDATED;
|
1999-05-06 21:38:11 +00:00
|
|
|
return i;
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
1998-06-01 21:41:11 +00:00
|
|
|
i = mb_alloc(if_pool, sizeof(struct iface));
|
|
|
|
memcpy(i, new, sizeof(*i));
|
2023-01-31 12:07:46 +00:00
|
|
|
if_link(i->master);
|
1999-05-06 21:38:11 +00:00
|
|
|
init_list(&i->addrs);
|
2000-04-10 10:40:00 +00:00
|
|
|
init_list(&i->neighbors);
|
2023-01-31 12:07:46 +00:00
|
|
|
newif:
|
1999-05-06 21:38:11 +00:00
|
|
|
i->flags |= IF_UPDATED | IF_TMP_DOWN; /* Tmp down as we don't have addresses yet */
|
2023-04-04 14:41:55 +00:00
|
|
|
add_tail(&global_iface_list, &i->n);
|
1999-05-06 21:38:11 +00:00
|
|
|
return i;
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 18:36:09 +00:00
|
|
|
void
|
|
|
|
if_start_update(void)
|
|
|
|
{
|
1999-05-06 21:38:11 +00:00
|
|
|
struct ifa *a;
|
1999-03-02 18:36:09 +00:00
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_WALK(i)
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
|
|
|
i->flags &= ~IF_UPDATED;
|
|
|
|
WALK_LIST(a, i->addrs)
|
2017-12-07 12:06:01 +00:00
|
|
|
a->flags &= ~IA_UPDATED;
|
1999-05-06 21:38:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
static void
|
|
|
|
if_end_partial_update_locked(struct iface *i)
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
2017-12-07 12:06:01 +00:00
|
|
|
if (i->flags & IF_NEEDS_RECALC)
|
|
|
|
if_recalc_preferred(i);
|
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
if (i->flags & IF_TMP_DOWN)
|
|
|
|
if_change_flags(i, i->flags & ~IF_TMP_DOWN);
|
1999-03-02 18:36:09 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
void
|
|
|
|
if_end_partial_update(struct iface *i)
|
|
|
|
{
|
|
|
|
IFACE_LOCK;
|
|
|
|
if_end_partial_update_locked(i);
|
|
|
|
IFACE_UNLOCK;
|
|
|
|
}
|
|
|
|
|
1998-05-26 21:42:05 +00:00
|
|
|
void
|
|
|
|
if_end_update(void)
|
|
|
|
{
|
1999-05-06 21:38:11 +00:00
|
|
|
struct ifa *a, *b;
|
1998-05-26 21:42:05 +00:00
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_WALK(i)
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
|
|
|
if (!(i->flags & IF_UPDATED))
|
2010-11-11 09:03:02 +00:00
|
|
|
if_change_flags(i, (i->flags & ~IF_ADMIN_UP) | IF_SHUTDOWN);
|
1999-05-06 21:38:11 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WALK_LIST_DELSAFE(a, b, i->addrs)
|
2017-12-07 12:06:01 +00:00
|
|
|
if (!(a->flags & IA_UPDATED))
|
2024-01-27 18:01:34 +00:00
|
|
|
ifa_delete_locked(a);
|
2023-04-04 14:41:55 +00:00
|
|
|
if_end_partial_update_locked(i);
|
1999-05-06 21:38:11 +00:00
|
|
|
}
|
|
|
|
}
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
static void
|
|
|
|
iface_notify_hook(void *_s)
|
2010-02-27 15:00:07 +00:00
|
|
|
{
|
2023-01-31 12:07:46 +00:00
|
|
|
struct iface_subscription *s = _s;
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
2023-09-24 20:20:01 +00:00
|
|
|
iface_trace(s, "Processing interface notifications");
|
2023-04-04 14:41:55 +00:00
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
while (!EMPTY_TLIST(ifnot, &s->queue))
|
|
|
|
{
|
|
|
|
struct iface_notification *n = THEAD(ifnot, &s->queue);
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_UNLOCK;
|
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
switch (n->type) {
|
|
|
|
case IFNOT_ADDRESS:
|
|
|
|
ifa_send_notify(s, n->flags, n->a);
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
2023-01-31 12:07:46 +00:00
|
|
|
ifa_unlink(n->a);
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_UNLOCK;
|
2023-01-31 12:07:46 +00:00
|
|
|
break;
|
|
|
|
case IFNOT_INTERFACE:
|
|
|
|
if_send_notify(s, n->flags, n->i);
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
2023-01-31 12:07:46 +00:00
|
|
|
if_unlink(n->i);
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_UNLOCK;
|
2023-01-31 12:07:46 +00:00
|
|
|
break;
|
|
|
|
case IFNOT_NEIGHBOR:
|
|
|
|
s->neigh_notify(n->n);
|
|
|
|
neigh_unlink(n->n);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bug("Bad interface notification type: %d", n->type);
|
|
|
|
}
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
2023-01-31 12:07:46 +00:00
|
|
|
ifnot_rem_node(&s->queue, n);
|
|
|
|
sl_free(n);
|
|
|
|
}
|
2023-04-04 14:41:55 +00:00
|
|
|
|
|
|
|
IFACE_UNLOCK;
|
2010-02-27 15:00:07 +00:00
|
|
|
}
|
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
2023-01-31 12:07:46 +00:00
|
|
|
* iface_subscribe - request interface updates
|
|
|
|
* @s: subscription structure
|
2000-06-03 14:40:39 +00:00
|
|
|
*
|
|
|
|
* When a new protocol starts, this function sends it a series
|
|
|
|
* of notifications about all existing interfaces.
|
|
|
|
*/
|
1998-10-17 11:05:18 +00:00
|
|
|
void
|
2023-01-31 12:07:46 +00:00
|
|
|
iface_subscribe(struct iface_subscription *s)
|
1998-10-17 11:05:18 +00:00
|
|
|
{
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
2023-01-31 12:07:46 +00:00
|
|
|
ifsub_add_tail(&iface_sub_list, s);
|
|
|
|
s->event = (event) {
|
|
|
|
.hook = iface_notify_hook,
|
|
|
|
.data = s,
|
|
|
|
};
|
1998-10-17 11:05:18 +00:00
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
if (!s->if_notify && !s->ifa_notify) /* shortcut */
|
2023-04-04 14:41:55 +00:00
|
|
|
{
|
|
|
|
IFACE_UNLOCK;
|
1998-10-17 11:05:18 +00:00
|
|
|
return;
|
2023-04-04 14:41:55 +00:00
|
|
|
}
|
2023-01-31 12:07:46 +00:00
|
|
|
|
|
|
|
struct iface *i;
|
2000-03-12 20:50:35 +00:00
|
|
|
DBG("Announcing interfaces to new protocol %s\n", p->name);
|
2023-04-04 14:41:55 +00:00
|
|
|
WALK_LIST(i, global_iface_list)
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
2023-04-04 14:41:55 +00:00
|
|
|
if_enqueue_notify_to(
|
|
|
|
(struct iface_notification) {
|
|
|
|
.type = IFNOT_INTERFACE,
|
|
|
|
.i = i,
|
|
|
|
.flags = IF_CHANGE_CREATE | ((i->flags & IF_UP) ? IF_CHANGE_UP : 0),
|
|
|
|
}, s);
|
2023-01-31 12:07:46 +00:00
|
|
|
|
|
|
|
struct ifa *a;
|
2000-03-12 20:50:35 +00:00
|
|
|
if (i->flags & IF_UP)
|
1999-05-06 21:38:11 +00:00
|
|
|
WALK_LIST(a, i->addrs)
|
2023-04-04 14:41:55 +00:00
|
|
|
if_enqueue_notify_to(
|
|
|
|
(struct iface_notification) {
|
|
|
|
.type = IFNOT_ADDRESS,
|
|
|
|
.a = a,
|
|
|
|
.flags = IF_CHANGE_CREATE | IF_CHANGE_UP,
|
|
|
|
}, s);
|
2023-01-31 12:07:46 +00:00
|
|
|
}
|
2023-04-04 14:41:55 +00:00
|
|
|
|
|
|
|
IFACE_UNLOCK;
|
2023-01-31 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iface_unsubscribe - unsubscribe from interface updates
|
|
|
|
* @s: subscription structure
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
iface_unsubscribe(struct iface_subscription *s)
|
|
|
|
{
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
|
|
|
|
2024-04-26 10:14:33 +00:00
|
|
|
SKIP_BACK_DECLARE(struct proto, p, iface_sub, s);
|
2023-04-04 14:41:55 +00:00
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
ifsub_rem_node(&iface_sub_list, s);
|
|
|
|
ev_postpone(&s->event);
|
|
|
|
|
|
|
|
WALK_TLIST_DELSAFE(ifnot, n, &s->queue)
|
|
|
|
{
|
2023-09-24 20:20:01 +00:00
|
|
|
iface_trace(s, "Dropping interface notification (%d, %p, %p) on unsubscribe", n->type, n->a, n);
|
2023-01-31 12:07:46 +00:00
|
|
|
switch (n->type)
|
|
|
|
{
|
|
|
|
case IFNOT_ADDRESS:
|
|
|
|
ifa_unlink(n->a);
|
|
|
|
break;
|
|
|
|
case IFNOT_INTERFACE:
|
|
|
|
if_unlink(n->i);
|
|
|
|
break;
|
|
|
|
case IFNOT_NEIGHBOR:
|
2024-11-10 12:33:22 +00:00
|
|
|
neigh_unlink_locked(n->n);
|
2023-01-31 12:07:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bug("Bad interface notification type: %d", n->type);
|
1999-05-06 21:38:11 +00:00
|
|
|
}
|
2023-01-31 12:07:46 +00:00
|
|
|
|
|
|
|
ifnot_rem_node(&s->queue, n);
|
|
|
|
sl_free(n);
|
|
|
|
}
|
2023-04-04 14:41:55 +00:00
|
|
|
|
2024-11-10 12:33:22 +00:00
|
|
|
WALK_TLIST_DELSAFE(proto_neigh, n, &p->neighbors)
|
|
|
|
{
|
2024-11-13 14:45:09 +00:00
|
|
|
bug("%s: Unlinking forgotten neighbor %I", p->name, n->addr);
|
2024-11-10 12:33:22 +00:00
|
|
|
neigh_unlink_locked(n);
|
|
|
|
}
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
ASSERT_DIE(EMPTY_TLIST(proto_neigh, &p->neighbors));
|
|
|
|
|
|
|
|
IFACE_UNLOCK;
|
1998-10-17 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* if_find_by_index - find interface by ifindex
|
|
|
|
* @idx: ifindex
|
|
|
|
*
|
|
|
|
* This function finds an &iface structure corresponding to an interface
|
|
|
|
* of the given index @idx. Returns a pointer to the structure or %NULL
|
|
|
|
* if no such structure exists.
|
|
|
|
*/
|
1999-03-02 18:36:09 +00:00
|
|
|
struct iface *
|
2023-04-04 14:41:55 +00:00
|
|
|
if_find_by_index_locked(unsigned idx)
|
1999-03-02 18:36:09 +00:00
|
|
|
{
|
|
|
|
struct iface *i;
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
WALK_LIST(i, global_iface_list)
|
2012-01-23 00:26:40 +00:00
|
|
|
if (i->index == idx && !(i->flags & IF_SHUTDOWN))
|
1999-03-02 18:36:09 +00:00
|
|
|
return i;
|
2023-04-04 14:41:55 +00:00
|
|
|
|
1999-03-02 18:36:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
struct iface *
|
|
|
|
if_find_by_index(unsigned idx)
|
|
|
|
{
|
|
|
|
IFACE_LOCK;
|
|
|
|
struct iface *i = if_find_by_index_locked(idx);
|
|
|
|
IFACE_UNLOCK;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* if_find_by_name - find interface by name
|
|
|
|
* @name: interface name
|
|
|
|
*
|
|
|
|
* This function finds an &iface structure corresponding to an interface
|
|
|
|
* of the given name @name. Returns a pointer to the structure or %NULL
|
|
|
|
* if no such structure exists.
|
|
|
|
*/
|
1999-05-06 21:38:11 +00:00
|
|
|
struct iface *
|
2020-04-08 20:25:15 +00:00
|
|
|
if_find_by_name(const char *name)
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
|
|
|
struct iface *i;
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
|
|
|
WALK_LIST(i, global_iface_list)
|
2018-11-05 21:03:21 +00:00
|
|
|
if (!strcmp(i->name, name) && !(i->flags & IF_SHUTDOWN))
|
2023-04-04 14:41:55 +00:00
|
|
|
{
|
|
|
|
IFACE_UNLOCK;
|
1999-05-06 21:38:11 +00:00
|
|
|
return i;
|
2023-04-04 14:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IFACE_UNLOCK;
|
1999-05-06 21:38:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-01 11:02:20 +00:00
|
|
|
struct iface *
|
2020-04-08 20:25:15 +00:00
|
|
|
if_get_by_name(const char *name)
|
2012-01-01 11:02:20 +00:00
|
|
|
{
|
|
|
|
struct iface *i;
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
|
|
|
WALK_LIST(i, global_iface_list)
|
2018-11-05 21:03:21 +00:00
|
|
|
if (!strcmp(i->name, name))
|
2023-04-04 14:41:55 +00:00
|
|
|
{
|
|
|
|
IFACE_UNLOCK;
|
2018-11-05 21:03:21 +00:00
|
|
|
return i;
|
2023-04-04 14:41:55 +00:00
|
|
|
}
|
2012-01-01 11:02:20 +00:00
|
|
|
|
|
|
|
/* No active iface, create a dummy */
|
|
|
|
i = mb_allocz(if_pool, sizeof(struct iface));
|
|
|
|
strncpy(i->name, name, sizeof(i->name)-1);
|
|
|
|
i->flags = IF_SHUTDOWN;
|
|
|
|
init_list(&i->addrs);
|
|
|
|
init_list(&i->neighbors);
|
2023-04-04 14:41:55 +00:00
|
|
|
add_tail(&global_iface_list, &i->n);
|
|
|
|
|
|
|
|
IFACE_UNLOCK;
|
2012-01-01 11:02:20 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2017-12-07 12:06:01 +00:00
|
|
|
static inline void
|
|
|
|
if_set_preferred(struct ifa **pos, struct ifa *new)
|
|
|
|
{
|
|
|
|
if (*pos)
|
|
|
|
(*pos)->flags &= ~IA_PRIMARY;
|
|
|
|
if (new)
|
|
|
|
new->flags |= IA_PRIMARY;
|
2009-05-29 20:49:30 +00:00
|
|
|
|
2017-12-07 12:06:01 +00:00
|
|
|
*pos = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
if_recalc_preferred(struct iface *i)
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
2017-12-07 12:06:01 +00:00
|
|
|
/*
|
|
|
|
* Preferred address selection priority:
|
|
|
|
* 1) Address configured in Device protocol
|
|
|
|
* 2) Sysdep IPv4 address (BSD)
|
|
|
|
* 3) Old preferred address
|
|
|
|
* 4) First address in list
|
|
|
|
*/
|
1999-05-06 21:38:11 +00:00
|
|
|
|
2017-12-07 12:06:01 +00:00
|
|
|
struct kif_iface_config *ic = kif_get_iface_config(i);
|
|
|
|
struct ifa *a4 = i->addr4, *a6 = i->addr6, *ll = i->llv6;
|
|
|
|
ip_addr pref_v4 = ic->pref_v4;
|
|
|
|
uint change = 0;
|
|
|
|
|
|
|
|
if (kif_update_sysdep_addr(i))
|
|
|
|
change |= IF_CHANGE_SYSDEP;
|
2009-05-29 20:49:30 +00:00
|
|
|
|
2017-12-07 12:06:01 +00:00
|
|
|
/* BSD sysdep address */
|
|
|
|
if (ipa_zero(pref_v4) && ip4_nonzero(i->sysdep))
|
|
|
|
pref_v4 = ipa_from_ip4(i->sysdep);
|
2009-05-29 20:49:30 +00:00
|
|
|
|
2017-12-07 12:06:01 +00:00
|
|
|
struct ifa *a;
|
|
|
|
WALK_LIST(a, i->addrs)
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
2017-12-07 12:06:01 +00:00
|
|
|
/* Secondary address is never selected */
|
|
|
|
if (a->flags & IA_SECONDARY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ipa_is_ip4(a->ip)) {
|
|
|
|
if (!a4 || ipa_equal(a->ip, pref_v4))
|
|
|
|
a4 = a;
|
|
|
|
} else if (!ipa_is_link_local(a->ip)) {
|
|
|
|
if (!a6 || ipa_equal(a->ip, ic->pref_v6))
|
|
|
|
a6 = a;
|
|
|
|
} else {
|
|
|
|
if (!ll || ipa_equal(a->ip, ic->pref_ll))
|
|
|
|
ll = a;
|
|
|
|
}
|
1999-05-06 21:38:11 +00:00
|
|
|
}
|
2009-05-29 20:49:30 +00:00
|
|
|
|
2018-11-28 15:43:17 +00:00
|
|
|
if ((a4 != i->addr4) || (i->flags & IF_LOST_ADDR4))
|
2017-12-07 12:06:01 +00:00
|
|
|
{
|
|
|
|
if_set_preferred(&i->addr4, a4);
|
|
|
|
change |= IF_CHANGE_ADDR4;
|
|
|
|
}
|
|
|
|
|
2018-11-28 15:43:17 +00:00
|
|
|
if ((a6 != i->addr6) || (i->flags & IF_LOST_ADDR6))
|
2017-12-07 12:06:01 +00:00
|
|
|
{
|
|
|
|
if_set_preferred(&i->addr6, a6);
|
|
|
|
change |= IF_CHANGE_ADDR6;
|
|
|
|
}
|
|
|
|
|
2018-11-28 15:43:17 +00:00
|
|
|
if ((ll != i->llv6) || (i->flags & IF_LOST_LLV6))
|
2017-12-07 12:06:01 +00:00
|
|
|
{
|
|
|
|
if_set_preferred(&i->llv6, ll);
|
|
|
|
change |= IF_CHANGE_LLV6;
|
|
|
|
}
|
|
|
|
|
2018-11-28 15:43:17 +00:00
|
|
|
i->flags &= ~(IF_NEEDS_RECALC | IF_LOST_ADDR4 | IF_LOST_ADDR6 | IF_LOST_LLV6);
|
2017-12-07 12:06:01 +00:00
|
|
|
|
|
|
|
if (change)
|
2018-11-28 15:43:17 +00:00
|
|
|
if_notify_change(change, i);
|
2009-05-29 20:49:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-12-07 12:06:01 +00:00
|
|
|
if_recalc_all_preferred_addresses(void)
|
2009-05-29 20:49:30 +00:00
|
|
|
{
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_WALK(i)
|
2017-12-07 12:06:01 +00:00
|
|
|
{
|
|
|
|
if_recalc_preferred(i);
|
|
|
|
|
|
|
|
if (i->flags & IF_TMP_DOWN)
|
|
|
|
if_change_flags(i, i->flags & ~IF_TMP_DOWN);
|
|
|
|
}
|
1999-05-06 21:38:11 +00:00
|
|
|
}
|
|
|
|
|
2011-05-01 15:16:05 +00:00
|
|
|
static inline int
|
|
|
|
ifa_same(struct ifa *a, struct ifa *b)
|
|
|
|
{
|
2015-11-12 01:03:59 +00:00
|
|
|
return ipa_equal(a->ip, b->ip) && net_equal(&a->prefix, &b->prefix);
|
2011-05-01 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2009-05-29 20:49:30 +00:00
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* ifa_update - update interface address
|
|
|
|
* @a: new interface address
|
|
|
|
*
|
|
|
|
* This function adds address information to a network
|
|
|
|
* interface. It's called by the platform dependent code during
|
|
|
|
* the interface update process described under if_update().
|
|
|
|
*/
|
1999-05-06 21:38:11 +00:00
|
|
|
struct ifa *
|
|
|
|
ifa_update(struct ifa *a)
|
|
|
|
{
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
struct iface *i = a->iface;
|
|
|
|
struct ifa *b;
|
|
|
|
|
|
|
|
WALK_LIST(b, i->addrs)
|
2011-05-01 15:16:05 +00:00
|
|
|
if (ifa_same(b, a))
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
2011-05-01 15:16:05 +00:00
|
|
|
if (ipa_equal(b->brd, a->brd) &&
|
1999-05-06 21:38:11 +00:00
|
|
|
ipa_equal(b->opposite, a->opposite) &&
|
2000-02-29 23:19:52 +00:00
|
|
|
b->scope == a->scope &&
|
2021-12-17 23:58:47 +00:00
|
|
|
!((b->flags ^ a->flags) & (IA_SECONDARY | IA_PEER | IA_HOST)))
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
2017-12-07 12:06:01 +00:00
|
|
|
b->flags |= IA_UPDATED;
|
2023-04-04 14:41:55 +00:00
|
|
|
|
|
|
|
IFACE_UNLOCK;
|
1999-05-06 21:38:11 +00:00
|
|
|
return b;
|
|
|
|
}
|
2024-01-27 18:01:34 +00:00
|
|
|
ifa_delete_locked(b);
|
1999-05-06 21:38:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-02-29 23:19:52 +00:00
|
|
|
|
2015-12-21 02:27:41 +00:00
|
|
|
if ((a->prefix.type == NET_IP4) && (i->flags & IF_BROADCAST) && ipa_zero(a->brd))
|
2017-12-07 12:06:01 +00:00
|
|
|
log(L_WARN "Missing broadcast address for interface %s", i->name);
|
2000-02-29 23:19:52 +00:00
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
b = mb_alloc(if_pool, sizeof(struct ifa));
|
|
|
|
memcpy(b, a, sizeof(struct ifa));
|
2023-01-31 12:07:46 +00:00
|
|
|
ifa_link(b);
|
|
|
|
if_link(i);
|
1999-05-06 21:38:11 +00:00
|
|
|
add_tail(&i->addrs, &b->n);
|
2017-12-07 12:06:01 +00:00
|
|
|
b->flags |= IA_UPDATED;
|
|
|
|
|
|
|
|
i->flags |= IF_NEEDS_RECALC;
|
|
|
|
if (i->flags & IF_UP)
|
1999-05-06 21:38:11 +00:00
|
|
|
ifa_notify_change(IF_CHANGE_CREATE | IF_CHANGE_UP, b);
|
2023-04-04 14:41:55 +00:00
|
|
|
|
|
|
|
IFACE_UNLOCK;
|
1999-05-06 21:38:11 +00:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* ifa_delete - remove interface address
|
|
|
|
* @a: interface address
|
|
|
|
*
|
|
|
|
* This function removes address information from a network
|
|
|
|
* interface. It's called by the platform dependent code during
|
|
|
|
* the interface update process described under if_update().
|
|
|
|
*/
|
1999-05-06 21:38:11 +00:00
|
|
|
void
|
|
|
|
ifa_delete(struct ifa *a)
|
|
|
|
{
|
2024-01-27 18:01:34 +00:00
|
|
|
IFACE_LOCK;
|
|
|
|
ifa_delete_locked(a);
|
|
|
|
IFACE_UNLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ifa_delete_locked(struct ifa *a)
|
|
|
|
{
|
|
|
|
IFACE_ASSERT_LOCKED;
|
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
struct iface *i = a->iface;
|
|
|
|
struct ifa *b;
|
|
|
|
|
|
|
|
WALK_LIST(b, i->addrs)
|
2011-05-01 15:16:05 +00:00
|
|
|
if (ifa_same(b, a))
|
1999-05-06 21:38:11 +00:00
|
|
|
{
|
|
|
|
rem_node(&b->n);
|
2017-12-07 12:06:01 +00:00
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
if (b->flags & IA_PRIMARY)
|
|
|
|
{
|
2017-12-07 12:06:01 +00:00
|
|
|
/*
|
|
|
|
* We unlink deleted preferred address and mark for recalculation.
|
|
|
|
* FIXME: This could break if we make iface scan non-atomic, as
|
|
|
|
* protocols still could use the freed address until they get
|
2018-11-28 15:43:17 +00:00
|
|
|
* if_notify from preferred route recalculation. We should fix and
|
|
|
|
* simplify this in the future by having struct ifa refcounted
|
2017-12-07 12:06:01 +00:00
|
|
|
*/
|
2018-11-28 15:43:17 +00:00
|
|
|
if (b == i->addr4) { i->addr4 = NULL; i->flags |= IF_LOST_ADDR4; }
|
|
|
|
if (b == i->addr6) { i->addr6 = NULL; i->flags |= IF_LOST_ADDR6; }
|
|
|
|
if (b == i->llv6) { i->llv6 = NULL; i->flags |= IF_LOST_LLV6; }
|
2017-12-07 12:06:01 +00:00
|
|
|
i->flags |= IF_NEEDS_RECALC;
|
1999-05-06 21:38:11 +00:00
|
|
|
}
|
2017-12-07 12:06:01 +00:00
|
|
|
|
|
|
|
if (i->flags & IF_UP)
|
|
|
|
ifa_notify_change(IF_CHANGE_DOWN, b);
|
|
|
|
|
2023-01-31 12:07:46 +00:00
|
|
|
ifa_unlink(b);
|
1999-05-07 13:46:16 +00:00
|
|
|
return;
|
1999-05-06 21:38:11 +00:00
|
|
|
}
|
2023-01-31 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
2012-12-27 11:56:23 +00:00
|
|
|
u32
|
|
|
|
if_choose_router_id(struct iface_patt *mask, u32 old_id)
|
1998-10-19 18:13:36 +00:00
|
|
|
{
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_LOCK;
|
|
|
|
|
2012-12-27 11:56:23 +00:00
|
|
|
struct iface *i;
|
|
|
|
struct ifa *a, *b;
|
1998-10-19 18:13:36 +00:00
|
|
|
|
2012-12-27 11:56:23 +00:00
|
|
|
b = NULL;
|
2023-04-04 14:41:55 +00:00
|
|
|
WALK_LIST(i, global_iface_list)
|
2012-12-27 11:56:23 +00:00
|
|
|
{
|
|
|
|
if (!(i->flags & IF_ADMIN_UP) ||
|
2013-04-16 15:53:22 +00:00
|
|
|
(i->flags & IF_SHUTDOWN))
|
2012-12-27 11:56:23 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
WALK_LIST(a, i->addrs)
|
|
|
|
{
|
2015-11-12 01:03:59 +00:00
|
|
|
if (a->prefix.type != NET_IP4)
|
|
|
|
continue;
|
|
|
|
|
2012-12-27 11:56:23 +00:00
|
|
|
if (a->flags & IA_SECONDARY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (a->scope <= SCOPE_LINK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Check pattern if specified */
|
|
|
|
if (mask && !iface_patt_match(mask, i, a))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* No pattern or pattern matched */
|
|
|
|
if (!b || ipa_to_u32(a->ip) < ipa_to_u32(b->ip))
|
|
|
|
b = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_UNLOCK;
|
|
|
|
|
2012-12-27 11:56:23 +00:00
|
|
|
if (!b)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
u32 id = ipa_to_u32(b->ip);
|
|
|
|
if (id != old_id)
|
|
|
|
log(L_INFO "Chosen router ID %R according to interface %s", id, b->iface->name);
|
|
|
|
|
|
|
|
return id;
|
1998-10-19 18:13:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-03 14:40:39 +00:00
|
|
|
/**
|
|
|
|
* if_init - initialize interface module
|
|
|
|
*
|
|
|
|
* This function is called during BIRD startup to initialize
|
|
|
|
* all data structures of the interface module.
|
|
|
|
*/
|
1998-05-26 21:42:05 +00:00
|
|
|
void
|
|
|
|
if_init(void)
|
|
|
|
{
|
2023-04-24 14:10:59 +00:00
|
|
|
iface_domain = DOMAIN_NEW(attrs);
|
2023-04-21 13:26:06 +00:00
|
|
|
|
|
|
|
IFACE_LOCK;
|
|
|
|
if_pool = rp_new(&root_pool, iface_domain.attrs, "Interfaces");
|
2023-04-04 14:41:55 +00:00
|
|
|
init_list(&global_iface_list);
|
2023-01-31 12:07:46 +00:00
|
|
|
iface_sub_slab = sl_new(if_pool, sizeof(struct iface_notification));
|
2021-11-15 09:53:58 +00:00
|
|
|
strcpy(default_vrf.name, "default");
|
2000-03-01 14:51:47 +00:00
|
|
|
neigh_init(if_pool);
|
2023-04-21 13:26:06 +00:00
|
|
|
IFACE_UNLOCK;
|
1998-05-26 21:42:05 +00:00
|
|
|
}
|
1998-11-29 22:01:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface Pattern Lists
|
|
|
|
*/
|
|
|
|
|
2010-03-14 15:36:59 +00:00
|
|
|
int
|
|
|
|
iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a)
|
1998-11-29 22:01:03 +00:00
|
|
|
{
|
2009-05-06 20:02:45 +00:00
|
|
|
struct iface_patt_node *p;
|
1998-11-29 22:01:03 +00:00
|
|
|
|
2009-05-06 20:02:45 +00:00
|
|
|
WALK_LIST(p, ifp->ipn_list)
|
1998-11-29 22:01:03 +00:00
|
|
|
{
|
2020-04-08 20:25:15 +00:00
|
|
|
const char *t = p->pattern;
|
2009-05-06 20:02:45 +00:00
|
|
|
int pos = p->positive;
|
|
|
|
|
1999-08-03 19:30:49 +00:00
|
|
|
if (t)
|
1998-11-29 22:01:03 +00:00
|
|
|
{
|
1999-08-03 19:30:49 +00:00
|
|
|
if (*t == '-')
|
|
|
|
{
|
|
|
|
t++;
|
2009-05-06 20:02:45 +00:00
|
|
|
pos = !pos;
|
1999-08-03 19:30:49 +00:00
|
|
|
}
|
2009-05-06 20:02:45 +00:00
|
|
|
|
1999-08-03 19:30:49 +00:00
|
|
|
if (!patmatch(t, i->name))
|
|
|
|
continue;
|
1998-11-29 22:01:03 +00:00
|
|
|
}
|
2009-05-06 20:02:45 +00:00
|
|
|
|
2015-11-12 01:03:59 +00:00
|
|
|
if (p->prefix.pxlen == 0)
|
2010-03-19 17:46:56 +00:00
|
|
|
return pos;
|
2009-05-06 20:02:45 +00:00
|
|
|
|
2010-03-19 17:46:56 +00:00
|
|
|
if (!a)
|
|
|
|
continue;
|
|
|
|
|
2015-11-12 01:03:59 +00:00
|
|
|
if (ipa_in_netX(a->ip, &p->prefix))
|
2010-03-19 17:46:56 +00:00
|
|
|
return pos;
|
|
|
|
|
2011-03-28 20:46:18 +00:00
|
|
|
if ((a->flags & IA_PEER) &&
|
2015-11-12 01:03:59 +00:00
|
|
|
ipa_in_netX(a->opposite, &p->prefix))
|
2010-03-19 17:46:56 +00:00
|
|
|
return pos;
|
2014-11-03 19:35:58 +00:00
|
|
|
|
2010-03-19 17:46:56 +00:00
|
|
|
continue;
|
1998-11-29 22:01:03 +00:00
|
|
|
}
|
2009-05-06 20:02:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iface_patt *
|
2010-03-14 15:36:59 +00:00
|
|
|
iface_patt_find(list *l, struct iface *i, struct ifa *a)
|
2009-05-06 20:02:45 +00:00
|
|
|
{
|
|
|
|
struct iface_patt *p;
|
|
|
|
|
|
|
|
WALK_LIST(p, *l)
|
2010-03-14 15:36:59 +00:00
|
|
|
if (iface_patt_match(p, i, a))
|
2009-05-06 20:02:45 +00:00
|
|
|
return p;
|
|
|
|
|
1998-11-29 22:01:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-06 20:02:45 +00:00
|
|
|
static int
|
|
|
|
iface_plists_equal(struct iface_patt *pa, struct iface_patt *pb)
|
|
|
|
{
|
|
|
|
struct iface_patt_node *x, *y;
|
|
|
|
|
|
|
|
x = HEAD(pa->ipn_list);
|
|
|
|
y = HEAD(pb->ipn_list);
|
|
|
|
while (x->n.next && y->n.next)
|
|
|
|
{
|
|
|
|
if ((x->positive != y->positive) ||
|
|
|
|
(!x->pattern && y->pattern) || /* This nasty lines where written by me... :-( Feela */
|
|
|
|
(!y->pattern && x->pattern) ||
|
|
|
|
((x->pattern != y->pattern) && strcmp(x->pattern, y->pattern)) ||
|
2015-11-12 01:03:59 +00:00
|
|
|
!net_equal(&x->prefix, &y->prefix))
|
2009-05-06 20:02:45 +00:00
|
|
|
return 0;
|
|
|
|
x = (void *) x->n.next;
|
|
|
|
y = (void *) y->n.next;
|
|
|
|
}
|
|
|
|
return (!x->n.next && !y->n.next);
|
|
|
|
}
|
|
|
|
|
1998-11-29 22:01:03 +00:00
|
|
|
int
|
|
|
|
iface_patts_equal(list *a, list *b, int (*comp)(struct iface_patt *, struct iface_patt *))
|
|
|
|
{
|
|
|
|
struct iface_patt *x, *y;
|
|
|
|
|
|
|
|
x = HEAD(*a);
|
|
|
|
y = HEAD(*b);
|
|
|
|
while (x->n.next && y->n.next)
|
|
|
|
{
|
2009-05-06 20:02:45 +00:00
|
|
|
if (!iface_plists_equal(x, y) ||
|
|
|
|
(comp && !comp(x, y)))
|
1998-11-29 22:01:03 +00:00
|
|
|
return 0;
|
|
|
|
x = (void *) x->n.next;
|
|
|
|
y = (void *) y->n.next;
|
|
|
|
}
|
|
|
|
return (!x->n.next && !y->n.next);
|
|
|
|
}
|
1999-11-25 15:35:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CLI commands.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
if_show_addr(struct ifa *a)
|
|
|
|
{
|
2017-12-07 12:06:01 +00:00
|
|
|
byte *flg, opp[IPA_MAX_TEXT_LENGTH + 16];
|
|
|
|
|
|
|
|
flg = (a->flags & IA_PRIMARY) ? "Preferred, " : (a->flags & IA_SECONDARY) ? "Secondary, " : "";
|
1999-11-25 15:35:30 +00:00
|
|
|
|
|
|
|
if (ipa_nonzero(a->opposite))
|
2017-12-07 12:06:01 +00:00
|
|
|
bsprintf(opp, "opposite %I, ", a->opposite);
|
1999-11-25 15:35:30 +00:00
|
|
|
else
|
|
|
|
opp[0] = 0;
|
2017-12-07 12:06:01 +00:00
|
|
|
|
|
|
|
cli_msg(-1003, "\t%I/%d (%s%sscope %s)",
|
|
|
|
a->ip, a->prefix.pxlen, flg, opp, ip_scope_text(a->scope));
|
1999-11-25 15:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
if_show(void)
|
|
|
|
{
|
|
|
|
struct ifa *a;
|
|
|
|
char *type;
|
|
|
|
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_WALK(i)
|
1999-11-25 15:35:30 +00:00
|
|
|
{
|
2010-11-11 09:03:02 +00:00
|
|
|
if (i->flags & IF_SHUTDOWN)
|
|
|
|
continue;
|
|
|
|
|
2017-09-06 15:38:48 +00:00
|
|
|
char mbuf[16 + sizeof(i->name)] = {};
|
2021-11-15 09:53:58 +00:00
|
|
|
if (i->master != &default_vrf)
|
2017-09-06 15:38:48 +00:00
|
|
|
bsprintf(mbuf, " master=%s", i->master->name);
|
|
|
|
else if (i->master_index)
|
|
|
|
bsprintf(mbuf, " master=#%u", i->master_index);
|
|
|
|
|
2017-12-09 23:55:34 +00:00
|
|
|
cli_msg(-1001, "%s %s (index=%d%s)", i->name, (i->flags & IF_UP) ? "up" : "down", i->index, mbuf);
|
2000-02-29 23:19:52 +00:00
|
|
|
if (!(i->flags & IF_MULTIACCESS))
|
1999-11-25 15:35:30 +00:00
|
|
|
type = "PtP";
|
|
|
|
else
|
|
|
|
type = "MultiAccess";
|
1999-11-30 12:57:14 +00:00
|
|
|
cli_msg(-1004, "\t%s%s%s Admin%s Link%s%s%s MTU=%d",
|
1999-11-25 15:35:30 +00:00
|
|
|
type,
|
|
|
|
(i->flags & IF_BROADCAST) ? " Broadcast" : "",
|
|
|
|
(i->flags & IF_MULTICAST) ? " Multicast" : "",
|
2010-11-11 09:03:02 +00:00
|
|
|
(i->flags & IF_ADMIN_UP) ? "Up" : "Down",
|
1999-11-25 15:35:30 +00:00
|
|
|
(i->flags & IF_LINK_UP) ? "Up" : "Down",
|
|
|
|
(i->flags & IF_LOOPBACK) ? " Loopback" : "",
|
|
|
|
(i->flags & IF_IGNORE) ? " Ignored" : "",
|
|
|
|
i->mtu);
|
2017-12-07 12:06:01 +00:00
|
|
|
|
|
|
|
WALK_LIST(a, i->addrs)
|
|
|
|
if (a->prefix.type == NET_IP4)
|
|
|
|
if_show_addr(a);
|
|
|
|
|
1999-11-25 15:35:30 +00:00
|
|
|
WALK_LIST(a, i->addrs)
|
2017-12-07 12:06:01 +00:00
|
|
|
if (a->prefix.type == NET_IP6)
|
1999-11-25 15:35:30 +00:00
|
|
|
if_show_addr(a);
|
|
|
|
}
|
|
|
|
cli_msg(0, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
if_show_summary(void)
|
|
|
|
{
|
2017-12-08 14:16:47 +00:00
|
|
|
cli_msg(-2005, "%-10s %-6s %-18s %s", "Interface", "State", "IPv4 address", "IPv6 address");
|
2023-04-04 14:41:55 +00:00
|
|
|
IFACE_WALK(i)
|
1999-11-25 15:35:30 +00:00
|
|
|
{
|
2017-12-07 12:06:01 +00:00
|
|
|
byte a4[IPA_MAX_TEXT_LENGTH + 17];
|
|
|
|
byte a6[IPA_MAX_TEXT_LENGTH + 17];
|
|
|
|
|
2018-10-11 12:39:13 +00:00
|
|
|
if (i->flags & IF_SHUTDOWN)
|
|
|
|
continue;
|
|
|
|
|
2017-12-07 12:06:01 +00:00
|
|
|
if (i->addr4)
|
|
|
|
bsprintf(a4, "%I/%d", i->addr4->ip, i->addr4->prefix.pxlen);
|
1999-11-25 15:35:30 +00:00
|
|
|
else
|
2017-12-07 12:06:01 +00:00
|
|
|
a4[0] = 0;
|
|
|
|
|
|
|
|
if (i->addr6)
|
|
|
|
bsprintf(a6, "%I/%d", i->addr6->ip, i->addr6->prefix.pxlen);
|
|
|
|
else
|
|
|
|
a6[0] = 0;
|
|
|
|
|
|
|
|
cli_msg(-1005, "%-10s %-6s %-18s %s",
|
2017-12-09 23:55:34 +00:00
|
|
|
i->name, (i->flags & IF_UP) ? "up" : "down", a4, a6);
|
1999-11-25 15:35:30 +00:00
|
|
|
}
|
|
|
|
cli_msg(0, "");
|
|
|
|
}
|