1999-11-17 23:50:41 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2005-03-14 19:24:56 +08:00
|
|
|
* (c) 1999--2005 Ondrej Filip <feela@network.cz>
|
2014-06-26 17:58:57 +08:00
|
|
|
* (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org>
|
|
|
|
* (c) 2009--2014 CZ.NIC z.s.p.o.
|
1999-11-17 23:50:41 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
2016-10-28 02:58:21 +08:00
|
|
|
#include "nest/password.h"
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
const char *ospf_is_names[] = {
|
|
|
|
"Down", "Loopback", "Waiting", "PtP", "DROther", "Backup", "DR"
|
2004-06-06 16:55:33 +08:00
|
|
|
};
|
2000-04-19 01:54:06 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
const char *ospf_ism_names[] = {
|
|
|
|
"InterfaceUp", "WaitTimer", "BackupSeen", "NeighborChange",
|
|
|
|
"LoopInd", "UnloopInd", "InterfaceDown"
|
2004-06-06 16:55:33 +08:00
|
|
|
};
|
2000-04-19 03:22:49 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
const char *ospf_it[] = { "broadcast", "nbma", "ptp", "ptmp", "virtual link" };
|
2000-06-02 01:52:21 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-05 17:58:23 +08:00
|
|
|
static void
|
2004-06-06 16:55:33 +08:00
|
|
|
poll_timer_hook(timer * timer)
|
2004-06-04 20:53:10 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_send_hello(timer->data, OHS_POLL, NULL);
|
2004-06-04 20:53:10 +08:00
|
|
|
}
|
|
|
|
|
2004-06-05 17:58:23 +08:00
|
|
|
static void
|
2004-06-06 16:55:33 +08:00
|
|
|
hello_timer_hook(timer * timer)
|
2004-06-04 20:53:10 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_send_hello(timer->data, OHS_HELLO, NULL);
|
2004-06-04 20:53:10 +08:00
|
|
|
}
|
|
|
|
|
2004-06-05 17:58:23 +08:00
|
|
|
static void
|
2004-06-06 16:55:33 +08:00
|
|
|
wait_timer_hook(timer * timer)
|
2004-06-04 20:53:10 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
struct ospf_iface *ifa = (struct ospf_iface *) timer->data;
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
2004-06-04 20:53:10 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Wait timer fired on %s", ifa->ifname);
|
2004-06-06 16:55:33 +08:00
|
|
|
ospf_iface_sm(ifa, ISM_WAITF);
|
2004-06-04 20:53:10 +08:00
|
|
|
}
|
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
static inline uint
|
|
|
|
ifa_tx_length(struct ospf_iface *ifa)
|
|
|
|
{
|
2014-07-19 23:28:38 +08:00
|
|
|
return ifa->cf->tx_length ?: ifa->iface->mtu;
|
2014-02-07 00:46:01 +08:00
|
|
|
}
|
2011-03-17 22:53:36 +08:00
|
|
|
|
2016-10-28 02:58:21 +08:00
|
|
|
static inline uint
|
|
|
|
ifa_tx_hdrlen(struct ospf_iface *ifa)
|
|
|
|
{
|
2016-11-09 02:27:58 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
|
|
|
|
|
|
|
uint hlen = ospf_is_v2(p) ? IP4_HEADER_LENGTH : IP6_HEADER_LENGTH;
|
2016-10-28 02:58:21 +08:00
|
|
|
|
|
|
|
/* Relevant just for OSPFv2 */
|
|
|
|
if (ifa->autype == OSPF_AUTH_CRYPT)
|
|
|
|
hlen += max_mac_length(ifa->passwords);
|
|
|
|
|
|
|
|
return hlen;
|
|
|
|
}
|
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
static inline uint
|
|
|
|
ifa_bufsize(struct ospf_iface *ifa)
|
2005-03-16 06:06:36 +08:00
|
|
|
{
|
2014-02-07 00:46:01 +08:00
|
|
|
uint bsize = ifa->cf->rx_buffer ?: ifa->iface->mtu;
|
|
|
|
return MAX(bsize, ifa->tx_length);
|
2005-03-16 06:06:36 +08:00
|
|
|
}
|
|
|
|
|
2014-11-03 17:42:55 +08:00
|
|
|
static inline uint
|
|
|
|
ifa_flood_queue_size(struct ospf_iface *ifa)
|
|
|
|
{
|
|
|
|
return ifa->tx_length / 24;
|
|
|
|
}
|
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
int
|
|
|
|
ospf_iface_assure_bufsize(struct ospf_iface *ifa, uint plen)
|
|
|
|
{
|
2016-10-28 02:58:21 +08:00
|
|
|
plen += ifa->tx_hdrlen;
|
2014-02-07 00:46:01 +08:00
|
|
|
|
|
|
|
if (plen <= ifa->sk->tbsize)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ifa->cf->rx_buffer || (plen > 0xffff))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
plen = BIRD_ALIGN(plen, 1024);
|
|
|
|
plen = MIN(plen, 0xffff);
|
|
|
|
sk_set_tbsize(ifa->sk, plen);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-25 01:08:07 +08:00
|
|
|
struct nbma_node *
|
2014-06-26 17:58:57 +08:00
|
|
|
find_nbma_node_(list *nnl, ip_addr ip)
|
2010-12-25 01:08:07 +08:00
|
|
|
{
|
|
|
|
struct nbma_node *nn;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2010-12-25 01:08:07 +08:00
|
|
|
WALK_LIST(nn, *nnl)
|
|
|
|
if (ipa_equal(nn->ip, ip))
|
|
|
|
return nn;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2010-12-25 01:08:07 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
|
2010-02-11 17:23:35 +08:00
|
|
|
static int
|
2011-07-06 09:10:02 +08:00
|
|
|
ospf_sk_open(struct ospf_iface *ifa)
|
2004-07-15 05:46:20 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
2014-05-18 17:42:26 +08:00
|
|
|
|
2010-11-13 21:19:23 +08:00
|
|
|
sock *sk = sk_new(ifa->pool);
|
2010-02-11 17:23:35 +08:00
|
|
|
sk->type = SK_IP;
|
2016-05-17 21:21:49 +08:00
|
|
|
sk->subtype = ospf_is_v2(p) ? SK_IPV4 : SK_IPV6;
|
2010-02-11 17:23:35 +08:00
|
|
|
sk->dport = OSPF_PROTO;
|
2014-02-07 00:46:01 +08:00
|
|
|
sk->saddr = ifa->addr->ip;
|
|
|
|
sk->iface = ifa->iface;
|
2009-08-28 00:25:46 +08:00
|
|
|
|
2013-06-24 22:37:30 +08:00
|
|
|
sk->tos = ifa->cf->tx_tos;
|
|
|
|
sk->priority = ifa->cf->tx_priority;
|
2010-02-11 17:23:35 +08:00
|
|
|
sk->rx_hook = ospf_rx_hook;
|
2014-02-07 00:46:01 +08:00
|
|
|
// sk->tx_hook = ospf_tx_hook;
|
2010-02-11 17:23:35 +08:00
|
|
|
sk->err_hook = ospf_err_hook;
|
2014-02-07 00:46:01 +08:00
|
|
|
sk->rbsize = sk->tbsize = ifa_bufsize(ifa);
|
2010-02-11 17:23:35 +08:00
|
|
|
sk->data = (void *) ifa;
|
2013-06-25 21:33:00 +08:00
|
|
|
sk->flags = SKF_LADDR_RX | (ifa->check_ttl ? SKF_TTL_RX : 0);
|
2014-02-07 00:46:01 +08:00
|
|
|
sk->ttl = ifa->cf->ttl_security ? 255 : 1;
|
2010-02-11 17:23:35 +08:00
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
if (sk_open(sk) < 0)
|
2009-09-04 17:06:51 +08:00
|
|
|
goto err;
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* 12 is an offset of the checksum in an OSPFv3 packet */
|
|
|
|
if (ospf_is_v3(p))
|
|
|
|
if (sk_set_ipv6_checksum(sk, 12) < 0)
|
|
|
|
goto err;
|
2009-11-10 06:22:53 +08:00
|
|
|
|
2011-07-06 09:10:02 +08:00
|
|
|
if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_PTP))
|
2010-12-25 01:08:07 +08:00
|
|
|
{
|
2012-05-14 17:47:41 +08:00
|
|
|
if (ifa->cf->real_bcast)
|
|
|
|
{
|
|
|
|
ifa->all_routers = ifa->addr->brd;
|
2014-06-26 17:58:57 +08:00
|
|
|
ifa->des_routers = IPA_NONE;
|
2012-05-14 17:47:41 +08:00
|
|
|
|
2014-05-18 17:42:26 +08:00
|
|
|
if (sk_setup_broadcast(sk) < 0)
|
2014-07-19 23:28:38 +08:00
|
|
|
goto err;
|
2012-05-14 17:47:41 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
ifa->all_routers = ospf_is_v2(p) ? IP4_OSPF_ALL_ROUTERS : IP6_OSPF_ALL_ROUTERS;
|
|
|
|
ifa->des_routers = ospf_is_v2(p) ? IP4_OSPF_DES_ROUTERS : IP6_OSPF_DES_ROUTERS;
|
2012-03-15 20:12:00 +08:00
|
|
|
|
2012-05-14 17:47:41 +08:00
|
|
|
if (sk_setup_multicast(sk) < 0)
|
2014-07-19 23:28:38 +08:00
|
|
|
goto err;
|
2010-12-25 01:08:07 +08:00
|
|
|
|
2012-05-14 17:47:41 +08:00
|
|
|
if (sk_join_group(sk, ifa->all_routers) < 0)
|
2014-07-19 23:28:38 +08:00
|
|
|
goto err;
|
2012-05-14 17:47:41 +08:00
|
|
|
}
|
2010-12-25 01:08:07 +08:00
|
|
|
}
|
2009-09-04 17:06:51 +08:00
|
|
|
|
2010-02-11 17:23:35 +08:00
|
|
|
ifa->sk = sk;
|
|
|
|
ifa->sk_dr = 0;
|
|
|
|
return 1;
|
2009-09-04 17:06:51 +08:00
|
|
|
|
|
|
|
err:
|
2014-06-26 17:58:57 +08:00
|
|
|
sk_log_error(sk, p->p.name);
|
2010-02-11 17:23:35 +08:00
|
|
|
rfree(sk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
ospf_sk_join_dr(struct ospf_iface *ifa)
|
|
|
|
{
|
|
|
|
if (ifa->sk_dr)
|
|
|
|
return;
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (sk_join_group(ifa->sk, ifa->des_routers) < 0)
|
|
|
|
sk_log_error(ifa->sk, ifa->oa->po->p.name);
|
2014-05-18 17:42:26 +08:00
|
|
|
|
2010-02-11 17:23:35 +08:00
|
|
|
ifa->sk_dr = 1;
|
|
|
|
}
|
2011-07-06 09:10:02 +08:00
|
|
|
|
2010-02-11 17:23:35 +08:00
|
|
|
static inline void
|
|
|
|
ospf_sk_leave_dr(struct ospf_iface *ifa)
|
|
|
|
{
|
|
|
|
if (!ifa->sk_dr)
|
|
|
|
return;
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (sk_leave_group(ifa->sk, ifa->des_routers) < 0)
|
|
|
|
sk_log_error(ifa->sk, ifa->oa->po->p.name);
|
2014-05-18 17:42:26 +08:00
|
|
|
|
2010-02-11 17:23:35 +08:00
|
|
|
ifa->sk_dr = 0;
|
|
|
|
}
|
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_open_vlink_sk(struct ospf_proto *p)
|
2014-02-07 00:46:01 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
sock *sk = sk_new(p->p.pool);
|
2014-02-07 00:46:01 +08:00
|
|
|
sk->type = SK_IP;
|
2016-05-17 21:21:49 +08:00
|
|
|
sk->subtype = ospf_is_v2(p) ? SK_IPV4 : SK_IPV6;
|
2014-02-07 00:46:01 +08:00
|
|
|
sk->dport = OSPF_PROTO;
|
|
|
|
|
|
|
|
/* FIXME: configurable tos/priority ? */
|
|
|
|
sk->tos = IP_PREC_INTERNET_CONTROL;
|
|
|
|
sk->priority = sk_priority_control;
|
|
|
|
sk->err_hook = ospf_verr_hook;
|
|
|
|
|
|
|
|
sk->rbsize = 0;
|
2014-06-26 17:58:57 +08:00
|
|
|
sk->tbsize = ospf_is_v2(p) ? IP4_MIN_MTU : IP6_MIN_MTU;
|
|
|
|
sk->data = (void *) p;
|
2014-02-07 00:46:01 +08:00
|
|
|
sk->flags = 0;
|
|
|
|
|
|
|
|
if (sk_open(sk) < 0)
|
|
|
|
goto err;
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* 12 is an offset of the checksum in an OSPFv3 packet */
|
|
|
|
if (ospf_is_v3(p))
|
|
|
|
if (sk_set_ipv6_checksum(sk, 12) < 0)
|
|
|
|
goto err;
|
2014-02-07 00:46:01 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
p->vlink_sk = sk;
|
2014-02-07 00:46:01 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
2014-06-26 17:58:57 +08:00
|
|
|
sk_log_error(sk, p->p.name);
|
|
|
|
log(L_ERR "%s: Cannot open virtual link socket", p->p.name);
|
2014-02-07 00:46:01 +08:00
|
|
|
rfree(sk);
|
|
|
|
}
|
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
static void
|
|
|
|
ospf_iface_down(struct ospf_iface *ifa)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
2004-06-06 16:55:33 +08:00
|
|
|
struct ospf_neighbor *n, *nx;
|
2004-06-26 00:39:53 +08:00
|
|
|
struct ospf_iface *iff;
|
2000-05-17 07:59:38 +08:00
|
|
|
|
2004-07-15 05:46:20 +08:00
|
|
|
if (ifa->type != OSPF_IT_VLINK)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
if (ospf_is_v3(ifa->oa->po))
|
|
|
|
OSPF_TRACE(D_EVENTS, "Removing interface %s (IID %d) from area %R",
|
|
|
|
ifa->ifname, ifa->instance_id, ifa->oa->areaid);
|
|
|
|
else if (ifa->addr->flags & IA_PEER)
|
|
|
|
OSPF_TRACE(D_EVENTS, "Removing interface %s (peer %I) from area %R",
|
|
|
|
ifa->ifname, ifa->addr->opposite, ifa->oa->areaid);
|
|
|
|
else
|
2015-11-12 09:03:59 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Removing interface %s (%N) from area %R",
|
|
|
|
ifa->ifname, &ifa->addr->prefix, ifa->oa->areaid);
|
2010-05-03 01:58:34 +08:00
|
|
|
|
|
|
|
/* First of all kill all the related vlinks */
|
2014-06-26 17:58:57 +08:00
|
|
|
WALK_LIST(iff, p->iface_list)
|
2004-07-15 05:46:20 +08:00
|
|
|
{
|
2010-03-14 23:36:59 +08:00
|
|
|
if ((iff->type == OSPF_IT_VLINK) && (iff->vifa == ifa))
|
2010-02-11 17:23:35 +08:00
|
|
|
ospf_iface_sm(iff, ISM_DOWN);
|
2004-07-15 05:46:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
WALK_LIST_DELSAFE(n, nx, ifa->neigh_list)
|
2014-10-24 16:27:21 +08:00
|
|
|
ospf_neigh_sm(n, INM_KILLNBR);
|
2009-09-04 17:06:51 +08:00
|
|
|
|
2010-11-13 21:19:23 +08:00
|
|
|
if (ifa->hello_timer)
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_stop(ifa->hello_timer);
|
2010-11-13 21:19:23 +08:00
|
|
|
|
|
|
|
if (ifa->poll_timer)
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_stop(ifa->poll_timer);
|
2010-11-13 21:19:23 +08:00
|
|
|
|
|
|
|
if (ifa->wait_timer)
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_stop(ifa->wait_timer);
|
2010-11-13 21:19:23 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_flush2_lsa(p, &ifa->link_lsa);
|
|
|
|
ospf_flush2_lsa(p, &ifa->net_lsa);
|
|
|
|
ospf_flush2_lsa(p, &ifa->pxn_lsa);
|
|
|
|
|
2004-07-15 05:46:20 +08:00
|
|
|
if (ifa->type == OSPF_IT_VLINK)
|
2004-06-26 00:39:53 +08:00
|
|
|
{
|
2010-03-14 23:36:59 +08:00
|
|
|
ifa->vifa = NULL;
|
|
|
|
ifa->addr = NULL;
|
2010-04-22 03:50:38 +08:00
|
|
|
ifa->cost = 0;
|
2010-03-14 23:36:59 +08:00
|
|
|
ifa->vip = IPA_NONE;
|
2004-06-26 00:39:53 +08:00
|
|
|
}
|
2010-12-28 08:43:07 +08:00
|
|
|
|
|
|
|
ifa->rt_pos_beg = 0;
|
|
|
|
ifa->rt_pos_end = 0;
|
|
|
|
ifa->px_pos_beg = 0;
|
|
|
|
ifa->px_pos_end = 0;
|
2010-11-13 21:19:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
void
|
2010-11-13 21:19:23 +08:00
|
|
|
ospf_iface_remove(struct ospf_iface *ifa)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
2014-11-04 03:35:25 +08:00
|
|
|
int i;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
if (ifa->type == OSPF_IT_VLINK)
|
|
|
|
OSPF_TRACE(D_EVENTS, "Removing vlink to %R via area %R", ifa->vid, ifa->voa->areaid);
|
|
|
|
|
2014-11-04 03:35:25 +08:00
|
|
|
/* Release LSAs from flood queue */
|
|
|
|
if (!ifa->stub)
|
|
|
|
for (i = 0; i < ifa->flood_queue_used; i++)
|
|
|
|
ifa->flood_queue[i]->ret_count--;
|
|
|
|
|
2010-11-13 21:19:23 +08:00
|
|
|
ospf_iface_sm(ifa, ISM_DOWN);
|
|
|
|
rem_node(NODE ifa);
|
|
|
|
rfree(ifa->pool);
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
void
|
|
|
|
ospf_iface_shutdown(struct ospf_iface *ifa)
|
|
|
|
{
|
|
|
|
if (ifa->state > OSPF_IS_DOWN)
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_send_hello(ifa, OHS_SHUTDOWN, NULL);
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
|
|
|
|
2010-11-13 21:19:23 +08:00
|
|
|
/**
|
|
|
|
* ospf_iface_chstate - handle changes of interface state
|
|
|
|
* @ifa: OSPF interface
|
|
|
|
* @state: new state
|
|
|
|
*
|
|
|
|
* Many actions must be taken according to interface state changes. New network
|
|
|
|
* LSAs must be originated, flushed, new multicast sockets to listen for messages for
|
|
|
|
* %ALLDROUTERS have to be opened, etc.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
2010-11-13 21:19:23 +08:00
|
|
|
u8 oldstate = ifa->state;
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (state == oldstate)
|
2010-11-13 21:19:23 +08:00
|
|
|
return;
|
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Interface %s changed state from %s to %s",
|
|
|
|
ifa->ifname, ospf_is_names[oldstate], ospf_is_names[state]);
|
2010-11-13 21:19:23 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ifa->state = state;
|
2010-11-13 21:19:23 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if ((ifa->type == OSPF_IT_BCAST) && ipa_nonzero(ifa->des_routers) && ifa->sk)
|
2010-11-13 21:19:23 +08:00
|
|
|
{
|
|
|
|
if ((state == OSPF_IS_BACKUP) || (state == OSPF_IS_DR))
|
|
|
|
ospf_sk_join_dr(ifa);
|
|
|
|
else
|
|
|
|
ospf_sk_leave_dr(ifa);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((oldstate > OSPF_IS_LOOP) && (state <= OSPF_IS_LOOP))
|
|
|
|
ospf_iface_down(ifa);
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* RFC 2328 12.4 Event 2 - iface state change */
|
|
|
|
ospf_notify_rt_lsa(ifa->oa);
|
|
|
|
|
|
|
|
/* RFC 5340 4.4.3 Event 1 - iface state change */
|
|
|
|
ospf_notify_link_lsa(ifa);
|
|
|
|
|
|
|
|
/* RFC 2328 12.4 Event 3 - iface enters/leaves DR state */
|
|
|
|
ospf_notify_net_lsa(ifa);
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
|
2000-06-08 06:10:46 +08:00
|
|
|
/**
|
2004-06-06 16:55:33 +08:00
|
|
|
* ospf_iface_sm - OSPF interface state machine
|
2000-06-08 06:10:46 +08:00
|
|
|
* @ifa: OSPF interface
|
|
|
|
* @event: event comming to state machine
|
|
|
|
*
|
2010-11-13 21:19:23 +08:00
|
|
|
* This fully respects 9.3 of RFC 2328 except we have slightly
|
|
|
|
* different handling of %DOWN and %LOOP state. We remove intefaces
|
|
|
|
* that are %DOWN. %DOWN state is used when an interface is waiting
|
|
|
|
* for a lock. %LOOP state is used when an interface does not have a
|
|
|
|
* link.
|
2000-06-08 06:10:46 +08:00
|
|
|
*/
|
1999-11-17 23:50:41 +08:00
|
|
|
void
|
2004-06-06 16:55:33 +08:00
|
|
|
ospf_iface_sm(struct ospf_iface *ifa, int event)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
DBG("SM on %s. Event is '%s'\n", ifa->ifname, ospf_ism_names[event]);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
switch (event)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
case ISM_UP:
|
2010-11-13 21:19:23 +08:00
|
|
|
if (ifa->state <= OSPF_IS_LOOP)
|
2004-06-06 16:55:33 +08:00
|
|
|
{
|
|
|
|
/* Now, nothing should be adjacent */
|
2014-06-26 17:58:57 +08:00
|
|
|
if ((ifa->type == OSPF_IT_PTP) ||
|
|
|
|
(ifa->type == OSPF_IT_PTMP) ||
|
|
|
|
(ifa->type == OSPF_IT_VLINK))
|
2004-07-15 05:46:20 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_PTP);
|
2004-07-15 05:46:20 +08:00
|
|
|
}
|
2004-06-06 16:55:33 +08:00
|
|
|
else
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
if (ifa->priority == 0)
|
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_DROTHER);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_WAITING);
|
2011-07-07 23:43:39 +08:00
|
|
|
if (ifa->wait_timer)
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_start(ifa->wait_timer, ifa->waitint S);
|
2004-06-06 16:55:33 +08:00
|
|
|
}
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
2004-07-15 05:46:20 +08:00
|
|
|
|
2011-07-07 23:43:39 +08:00
|
|
|
if (ifa->hello_timer)
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_start(ifa->hello_timer, ifa->helloint S);
|
2004-07-15 05:46:20 +08:00
|
|
|
|
|
|
|
if (ifa->poll_timer)
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_start(ifa->poll_timer, ifa->pollint S);
|
2004-07-15 05:46:20 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_send_hello(ifa, OHS_HELLO, NULL);
|
2004-06-06 16:55:33 +08:00
|
|
|
}
|
|
|
|
break;
|
2010-11-13 21:19:23 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
case ISM_BACKS:
|
|
|
|
case ISM_WAITF:
|
|
|
|
if (ifa->state == OSPF_IS_WAITING)
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_dr_election(ifa);
|
2004-06-06 16:55:33 +08:00
|
|
|
break;
|
2010-11-13 21:19:23 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
case ISM_NEICH:
|
2014-06-26 17:58:57 +08:00
|
|
|
if (ifa->state >= OSPF_IS_DROTHER)
|
|
|
|
ospf_dr_election(ifa);
|
2004-06-06 16:55:33 +08:00
|
|
|
break;
|
2010-11-13 21:19:23 +08:00
|
|
|
|
2010-02-11 17:23:35 +08:00
|
|
|
case ISM_LOOP:
|
2011-07-06 09:10:02 +08:00
|
|
|
if ((ifa->state > OSPF_IS_LOOP) && ifa->check_link)
|
2010-11-13 21:19:23 +08:00
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_LOOP);
|
2004-06-06 16:55:33 +08:00
|
|
|
break;
|
2010-11-13 21:19:23 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
case ISM_UNLOOP:
|
2010-11-13 21:19:23 +08:00
|
|
|
/* Immediate go UP */
|
|
|
|
if (ifa->state == OSPF_IS_LOOP)
|
|
|
|
ospf_iface_sm(ifa, ISM_UP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISM_DOWN:
|
2004-06-06 16:55:33 +08:00
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_DOWN);
|
|
|
|
break;
|
2010-11-13 21:19:23 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
default:
|
|
|
|
bug("OSPF_I_SM - Unknown event?");
|
|
|
|
break;
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
2004-06-06 16:55:33 +08:00
|
|
|
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
|
2010-12-25 01:08:07 +08:00
|
|
|
static u8
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_classify_(struct iface *ifa, struct ifa *addr)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2010-04-28 06:39:57 +08:00
|
|
|
if (ipa_nonzero(addr->opposite))
|
2010-12-25 01:08:07 +08:00
|
|
|
return (ifa->flags & IF_MULTICAST) ? OSPF_IT_PTP : OSPF_IT_PTMP;
|
2010-02-07 16:49:34 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) ==
|
|
|
|
(IF_MULTIACCESS | IF_MULTICAST))
|
|
|
|
return OSPF_IT_BCAST;
|
|
|
|
|
|
|
|
if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) == IF_MULTIACCESS)
|
1999-11-17 23:50:41 +08:00
|
|
|
return OSPF_IT_NBMA;
|
2004-06-06 16:55:33 +08:00
|
|
|
|
1999-11-17 23:50:41 +08:00
|
|
|
return OSPF_IT_PTP;
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
static inline u8
|
|
|
|
ospf_iface_classify(u8 type, struct ifa *addr)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
return (type != OSPF_IT_UNDEF) ? type : ospf_iface_classify_(addr->iface, addr);
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
struct ospf_iface *
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_find(struct ospf_proto *p, struct iface *what)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_iface *ifa;
|
|
|
|
|
|
|
|
WALK_LIST(ifa, p->iface_list)
|
|
|
|
if ((ifa->iface == what) && (ifa->type != OSPF_IT_VLINK))
|
|
|
|
return ifa;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
static void
|
|
|
|
ospf_iface_add(struct object_lock *lock)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa = lock->data;
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
2004-06-06 16:55:33 +08:00
|
|
|
|
2011-07-06 09:10:02 +08:00
|
|
|
/* Open socket if interface is not stub */
|
|
|
|
if (! ifa->stub && ! ospf_sk_open(ifa))
|
2010-03-14 23:36:59 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
log(L_ERR "%s: Cannot open socket for %s, declaring as stub", p->p.name, ifa->ifname);
|
2010-03-14 23:36:59 +08:00
|
|
|
ifa->ioprob = OSPF_I_SK;
|
2004-06-06 16:55:33 +08:00
|
|
|
ifa->stub = 1;
|
|
|
|
}
|
|
|
|
|
2011-07-07 23:43:39 +08:00
|
|
|
if (! ifa->stub)
|
|
|
|
{
|
2017-11-29 00:43:20 +08:00
|
|
|
ifa->hello_timer = tm_new_init(ifa->pool, hello_timer_hook, ifa, ifa->helloint S, 0);
|
2011-07-07 23:43:39 +08:00
|
|
|
|
|
|
|
if (ifa->type == OSPF_IT_NBMA)
|
2017-11-29 00:43:20 +08:00
|
|
|
ifa->poll_timer = tm_new_init(ifa->pool, poll_timer_hook, ifa, ifa->pollint S, 0);
|
2011-07-07 23:43:39 +08:00
|
|
|
|
|
|
|
if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA))
|
2017-11-29 00:43:20 +08:00
|
|
|
ifa->wait_timer = tm_new_init(ifa->pool, wait_timer_hook, ifa, 0, 0);
|
2014-11-03 17:42:55 +08:00
|
|
|
|
|
|
|
ifa->flood_queue_size = ifa_flood_queue_size(ifa);
|
|
|
|
ifa->flood_queue = mb_allocz(ifa->pool, ifa->flood_queue_size * sizeof(void *));
|
2011-07-07 23:43:39 +08:00
|
|
|
}
|
|
|
|
|
2015-08-19 17:16:23 +08:00
|
|
|
/* Do iface UP, unless there is no link (then wait in LOOP state) */
|
|
|
|
if (!ifa->check_link || (ifa->iface->flags & IF_LINK_UP))
|
|
|
|
ospf_iface_sm(ifa, ISM_UP);
|
|
|
|
else
|
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_LOOP);
|
2004-06-06 16:55:33 +08:00
|
|
|
}
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
static inline void
|
|
|
|
add_nbma_node(struct ospf_iface *ifa, struct nbma_node *src, int found)
|
|
|
|
{
|
|
|
|
struct nbma_node *n = mb_alloc(ifa->pool, sizeof(struct nbma_node));
|
|
|
|
add_tail(&ifa->nbma_list, NODE n);
|
|
|
|
n->ip = src->ip;
|
|
|
|
n->eligible = src->eligible;
|
|
|
|
n->found = found;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ospf_iface_stubby(struct ospf_iface_patt *ip, struct ifa *addr)
|
|
|
|
{
|
2013-11-25 05:12:51 +08:00
|
|
|
/* a host address */
|
2011-03-29 04:46:18 +08:00
|
|
|
if (addr->flags & IA_HOST)
|
|
|
|
return 1;
|
|
|
|
|
2013-11-25 05:12:51 +08:00
|
|
|
/* a loopback iface */
|
|
|
|
if (addr->iface->flags & IF_LOOPBACK)
|
|
|
|
return 1;
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
return ip->stub;
|
|
|
|
}
|
|
|
|
|
2004-06-26 00:39:53 +08:00
|
|
|
void
|
2011-03-17 22:53:36 +08:00
|
|
|
ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *ip)
|
2004-06-26 00:39:53 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = oa->po;
|
2014-02-07 00:46:01 +08:00
|
|
|
struct iface *iface = addr->iface;
|
2004-06-26 00:39:53 +08:00
|
|
|
struct ospf_iface *ifa;
|
2014-02-07 00:46:01 +08:00
|
|
|
struct pool *pool;
|
2004-06-26 00:39:53 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (ospf_is_v3(p))
|
|
|
|
OSPF_TRACE(D_EVENTS, "Adding interface %s (IID %d) to area %R",
|
|
|
|
iface->name, ip->instance_id, oa->areaid);
|
|
|
|
else if (addr->flags & IA_PEER)
|
|
|
|
OSPF_TRACE(D_EVENTS, "Adding interface %s (peer %I) to area %R",
|
|
|
|
iface->name, addr->opposite, oa->areaid);
|
|
|
|
else
|
2015-11-12 09:03:59 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Adding interface %s (%N) to area %R",
|
|
|
|
iface->name, &addr->prefix, oa->areaid);
|
2010-02-11 17:23:35 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
pool = rp_new(p->p.pool, "OSPF Interface");
|
2010-11-13 21:19:23 +08:00
|
|
|
ifa = mb_allocz(pool, sizeof(struct ospf_iface));
|
2004-06-26 00:39:53 +08:00
|
|
|
ifa->iface = iface;
|
2010-03-14 23:36:59 +08:00
|
|
|
ifa->addr = addr;
|
2011-03-17 22:53:36 +08:00
|
|
|
ifa->oa = oa;
|
|
|
|
ifa->cf = ip;
|
2010-11-13 21:19:23 +08:00
|
|
|
ifa->pool = pool;
|
2004-06-26 00:39:53 +08:00
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
ifa->iface_id = iface->index;
|
|
|
|
ifa->ifname = iface->name;
|
|
|
|
|
2004-06-26 00:39:53 +08:00
|
|
|
ifa->cost = ip->cost;
|
|
|
|
ifa->rxmtint = ip->rxmtint;
|
|
|
|
ifa->inftransdelay = ip->inftransdelay;
|
|
|
|
ifa->priority = ip->priority;
|
|
|
|
ifa->helloint = ip->helloint;
|
|
|
|
ifa->pollint = ip->pollint;
|
|
|
|
ifa->strictnbma = ip->strictnbma;
|
|
|
|
ifa->waitint = ip->waitint;
|
2011-03-17 22:53:36 +08:00
|
|
|
ifa->deadint = ip->deadint;
|
2010-03-26 21:48:01 +08:00
|
|
|
ifa->stub = ospf_iface_stubby(ip, addr);
|
2010-03-14 23:36:59 +08:00
|
|
|
ifa->ioprob = OSPF_I_OK;
|
2014-02-07 00:46:01 +08:00
|
|
|
ifa->tx_length = ifa_tx_length(ifa);
|
2016-10-28 02:58:21 +08:00
|
|
|
ifa->tx_hdrlen = ifa_tx_hdrlen(ifa);
|
2010-11-19 20:46:21 +08:00
|
|
|
ifa->check_link = ip->check_link;
|
2010-12-08 06:35:39 +08:00
|
|
|
ifa->ecmp_weight = ip->ecmp_weight;
|
2013-06-25 21:33:00 +08:00
|
|
|
ifa->check_ttl = (ip->ttl_security == 1);
|
2013-11-20 05:33:48 +08:00
|
|
|
ifa->bfd = ip->bfd;
|
2004-06-26 00:39:53 +08:00
|
|
|
ifa->autype = ip->autype;
|
2004-06-27 04:15:34 +08:00
|
|
|
ifa->passwords = ip->passwords;
|
2014-06-26 17:58:57 +08:00
|
|
|
ifa->instance_id = ip->instance_id;
|
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
ifa->ptp_netmask = !(addr->flags & IA_PEER);
|
2013-04-17 19:06:40 +08:00
|
|
|
if (ip->ptp_netmask < 2)
|
|
|
|
ifa->ptp_netmask = ip->ptp_netmask;
|
2009-08-21 15:27:52 +08:00
|
|
|
|
2015-12-24 22:52:03 +08:00
|
|
|
ifa->drip = ifa->bdrip = ospf_is_v2(p) ? IPA_NONE4 : IPA_NONE6;
|
2014-02-07 00:46:01 +08:00
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
ifa->type = ospf_iface_classify(ip->type, addr);
|
2010-05-26 22:09:22 +08:00
|
|
|
|
2010-12-25 01:08:07 +08:00
|
|
|
/* Check validity of interface type */
|
|
|
|
int old_type = ifa->type;
|
2012-05-14 17:47:41 +08:00
|
|
|
u32 if_multi_flag = ip->real_bcast ? IF_BROADCAST : IF_MULTICAST;
|
2010-12-25 01:08:07 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (ospf_is_v2(p) && (ifa->type == OSPF_IT_BCAST) && (addr->flags & IA_PEER))
|
2010-02-07 16:49:34 +08:00
|
|
|
ifa->type = OSPF_IT_PTP;
|
2010-12-25 01:08:07 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (ospf_is_v2(p) && (ifa->type == OSPF_IT_NBMA) && (addr->flags & IA_PEER))
|
2010-12-25 01:08:07 +08:00
|
|
|
ifa->type = OSPF_IT_PTMP;
|
2010-02-07 16:49:34 +08:00
|
|
|
|
2016-02-26 01:16:59 +08:00
|
|
|
if ((ifa->type == OSPF_IT_BCAST) && !(iface->flags & if_multi_flag) && !ifa->stub)
|
2010-12-25 01:08:07 +08:00
|
|
|
ifa->type = OSPF_IT_NBMA;
|
|
|
|
|
2016-02-26 01:16:59 +08:00
|
|
|
if ((ifa->type == OSPF_IT_PTP) && !(iface->flags & if_multi_flag) && !ifa->stub)
|
2010-12-25 01:08:07 +08:00
|
|
|
ifa->type = OSPF_IT_PTMP;
|
|
|
|
|
|
|
|
if (ifa->type != old_type)
|
|
|
|
log(L_WARN "%s: Cannot use interface %s as %s, forcing %s",
|
2014-06-26 17:58:57 +08:00
|
|
|
p->p.name, iface->name, ospf_it[old_type], ospf_it[ifa->type]);
|
|
|
|
|
2010-12-25 01:08:07 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if ((ifa->type == OSPF_IT_PTP) || (ifa->type == OSPF_IT_PTMP))
|
|
|
|
ifa->link_lsa_suppression = ip->link_lsa_suppression;
|
2010-12-25 01:08:07 +08:00
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
ifa->state = OSPF_IS_DOWN;
|
2004-06-26 00:39:53 +08:00
|
|
|
init_list(&ifa->neigh_list);
|
|
|
|
init_list(&ifa->nbma_list);
|
2004-07-15 05:46:20 +08:00
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
struct nbma_node *nb;
|
2004-06-26 00:39:53 +08:00
|
|
|
WALK_LIST(nb, ip->nbma_list)
|
2013-04-16 22:22:31 +08:00
|
|
|
{
|
|
|
|
/* In OSPFv3, addr is link-local while configured neighbors could
|
|
|
|
have global IP (although RFC 5340 C.5 says link-local addresses
|
|
|
|
should be used). Because OSPFv3 iface is not subnet-specific,
|
|
|
|
there is no need for ipa_in_net() check */
|
|
|
|
|
2015-11-12 09:03:59 +08:00
|
|
|
if (ospf_is_v2(p) && !ipa_in_netX(nb->ip, &addr->prefix))
|
2013-04-16 22:22:31 +08:00
|
|
|
continue;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
|
|
|
if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip))
|
2014-10-24 16:27:21 +08:00
|
|
|
log(L_WARN "%s: Configured neighbor address (%I) should be link-local",
|
|
|
|
p->p.name, nb->ip);
|
2013-04-16 22:22:31 +08:00
|
|
|
|
|
|
|
add_nbma_node(ifa, nb, 0);
|
|
|
|
}
|
2004-06-26 00:39:53 +08:00
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
add_tail(&oa->po->iface_list, NODE ifa);
|
2004-06-26 00:39:53 +08:00
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
struct object_lock *lock = olock_new(pool);
|
2015-11-12 09:03:59 +08:00
|
|
|
lock->addr = ospf_is_v2(p) ? ipa_from_ip4(net4_prefix(&ifa->addr->prefix)) : IPA_NONE;
|
2004-06-26 00:39:53 +08:00
|
|
|
lock->type = OBJLOCK_IP;
|
|
|
|
lock->port = OSPF_PROTO;
|
2014-07-19 00:24:12 +08:00
|
|
|
lock->inst = ifa->instance_id;
|
2004-06-26 00:39:53 +08:00
|
|
|
lock->iface = iface;
|
|
|
|
lock->data = ifa;
|
|
|
|
lock->hook = ospf_iface_add;
|
|
|
|
|
|
|
|
olock_acquire(lock);
|
|
|
|
}
|
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_new_vlink(struct ospf_proto *p, struct ospf_iface_patt *ip)
|
2014-02-07 00:46:01 +08:00
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
struct pool *pool;
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (!p->vlink_sk)
|
2014-02-07 00:46:01 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
OSPF_TRACE(D_EVENTS, "Adding vlink to %R via area %R", ip->vid, ip->voa);
|
|
|
|
|
|
|
|
/* Vlink ifname is stored just after the ospf_iface structure */
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
pool = rp_new(p->p.pool, "OSPF Vlink");
|
2014-02-07 00:46:01 +08:00
|
|
|
ifa = mb_allocz(pool, sizeof(struct ospf_iface) + 16);
|
2014-06-26 17:58:57 +08:00
|
|
|
ifa->oa = p->backbone;
|
2014-02-07 00:46:01 +08:00
|
|
|
ifa->cf = ip;
|
|
|
|
ifa->pool = pool;
|
|
|
|
|
|
|
|
/* Assign iface ID, for vlinks, this is ugly hack */
|
2014-06-26 17:58:57 +08:00
|
|
|
u32 vlink_id = p->last_vlink_id++;
|
2014-02-07 00:46:01 +08:00
|
|
|
ifa->iface_id = vlink_id + OSPF_VLINK_ID_OFFSET;
|
|
|
|
ifa->ifname = (void *) (ifa + 1);
|
|
|
|
bsprintf(ifa->ifname, "vlink%d", vlink_id);
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ifa->voa = ospf_find_area(p, ip->voa);
|
2014-02-07 00:46:01 +08:00
|
|
|
ifa->vid = ip->vid;
|
2014-06-26 17:58:57 +08:00
|
|
|
ifa->sk = p->vlink_sk;
|
2014-02-07 00:46:01 +08:00
|
|
|
|
|
|
|
ifa->helloint = ip->helloint;
|
|
|
|
ifa->rxmtint = ip->rxmtint;
|
|
|
|
ifa->waitint = ip->waitint;
|
|
|
|
ifa->deadint = ip->deadint;
|
|
|
|
ifa->inftransdelay = ip->inftransdelay;
|
2014-06-26 17:58:57 +08:00
|
|
|
ifa->tx_length = ospf_is_v2(p) ? IP4_MIN_MTU : IP6_MIN_MTU;
|
2016-10-28 02:58:21 +08:00
|
|
|
ifa->tx_hdrlen = ifa_tx_hdrlen(ifa);
|
2014-02-07 00:46:01 +08:00
|
|
|
ifa->autype = ip->autype;
|
|
|
|
ifa->passwords = ip->passwords;
|
|
|
|
ifa->instance_id = ip->instance_id;
|
|
|
|
|
|
|
|
ifa->type = OSPF_IT_VLINK;
|
|
|
|
|
|
|
|
ifa->state = OSPF_IS_DOWN;
|
|
|
|
init_list(&ifa->neigh_list);
|
|
|
|
init_list(&ifa->nbma_list);
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
add_tail(&p->iface_list, NODE ifa);
|
2014-02-07 00:46:01 +08:00
|
|
|
|
2017-11-29 00:43:20 +08:00
|
|
|
ifa->hello_timer = tm_new_init(ifa->pool, hello_timer_hook, ifa, ifa->helloint S, 0);
|
2014-11-03 17:42:55 +08:00
|
|
|
|
|
|
|
ifa->flood_queue_size = ifa_flood_queue_size(ifa);
|
|
|
|
ifa->flood_queue = mb_allocz(ifa->pool, ifa->flood_queue_size * sizeof(void *));
|
2014-02-07 00:46:01 +08:00
|
|
|
}
|
|
|
|
|
2011-07-07 23:43:39 +08:00
|
|
|
static void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_change_timer(timer *tm, uint val)
|
2011-07-07 23:43:39 +08:00
|
|
|
{
|
|
|
|
if (!tm)
|
|
|
|
return;
|
|
|
|
|
2017-06-01 18:33:20 +08:00
|
|
|
tm->recurrent = val S;
|
2011-07-07 23:43:39 +08:00
|
|
|
|
2017-11-29 00:43:20 +08:00
|
|
|
if (tm_active(tm))
|
|
|
|
tm_start(tm, val S);
|
2011-07-07 23:43:39 +08:00
|
|
|
}
|
|
|
|
|
2014-11-03 17:42:55 +08:00
|
|
|
static inline void
|
|
|
|
ospf_iface_update_flood_queue_size(struct ospf_iface *ifa)
|
|
|
|
{
|
|
|
|
uint old_size = ifa->flood_queue_size;
|
|
|
|
uint new_size = ifa_flood_queue_size(ifa);
|
|
|
|
|
|
|
|
if (new_size <= old_size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ifa->flood_queue_size = new_size;
|
|
|
|
ifa->flood_queue = mb_realloc(ifa->flood_queue, new_size * sizeof(void *));
|
|
|
|
bzero(ifa->flood_queue + old_size, (new_size - old_size) * sizeof(void *));
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
int
|
|
|
|
ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
2014-02-07 00:46:01 +08:00
|
|
|
struct ospf_iface_patt *old = ifa->cf;
|
|
|
|
char *ifname = ifa->ifname;
|
2011-03-17 22:53:36 +08:00
|
|
|
|
|
|
|
/* Type could be changed in ospf_iface_new(),
|
|
|
|
but if config values are same then also results are same */
|
2014-07-19 23:28:38 +08:00
|
|
|
int old_type = ospf_iface_classify(old->type, ifa->addr);
|
2011-03-17 22:53:36 +08:00
|
|
|
int new_type = ospf_iface_classify(new->type, ifa->addr);
|
|
|
|
if (old_type != new_type)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int new_stub = ospf_iface_stubby(new, ifa->addr);
|
|
|
|
if (ifa->stub != new_stub)
|
|
|
|
return 0;
|
|
|
|
|
2013-06-24 22:37:30 +08:00
|
|
|
/* Change of these options would require to reset the iface socket */
|
2014-02-07 00:46:01 +08:00
|
|
|
if ((new->real_bcast != old->real_bcast) ||
|
|
|
|
(new->tx_tos != old->tx_tos) ||
|
|
|
|
(new->tx_priority != old->tx_priority) ||
|
|
|
|
(new->ttl_security != old->ttl_security))
|
2012-05-14 17:47:41 +08:00
|
|
|
return 0;
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
ifa->cf = new;
|
|
|
|
ifa->marked = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* HELLO TIMER */
|
|
|
|
if (ifa->helloint != new->helloint)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing hello interval of %s from %d to %d",
|
2011-03-17 22:53:36 +08:00
|
|
|
ifname, ifa->helloint, new->helloint);
|
|
|
|
|
|
|
|
ifa->helloint = new->helloint;
|
2011-07-07 23:43:39 +08:00
|
|
|
ospf_iface_change_timer(ifa->hello_timer, ifa->helloint);
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RXMT TIMER */
|
|
|
|
if (ifa->rxmtint != new->rxmtint)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing retransmit interval of %s from %d to %d",
|
2011-03-17 22:53:36 +08:00
|
|
|
ifname, ifa->rxmtint, new->rxmtint);
|
|
|
|
|
|
|
|
ifa->rxmtint = new->rxmtint;
|
2014-11-03 17:42:55 +08:00
|
|
|
/* FIXME: Update neighbors' timers */
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* POLL TIMER */
|
|
|
|
if (ifa->pollint != new->pollint)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing poll interval of %s from %d to %d",
|
2011-03-17 22:53:36 +08:00
|
|
|
ifname, ifa->pollint, new->pollint);
|
|
|
|
|
2011-07-07 23:43:39 +08:00
|
|
|
ifa->pollint = new->pollint;
|
|
|
|
ospf_iface_change_timer(ifa->poll_timer, ifa->pollint);
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* WAIT TIMER */
|
|
|
|
if (ifa->waitint != new->waitint)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing wait interval of %s from %d to %d",
|
2011-03-17 22:53:36 +08:00
|
|
|
ifname, ifa->waitint, new->waitint);
|
|
|
|
|
|
|
|
ifa->waitint = new->waitint;
|
2017-11-29 00:43:20 +08:00
|
|
|
if (ifa->wait_timer && tm_active(ifa->wait_timer))
|
|
|
|
tm_start(ifa->wait_timer, ifa->waitint S);
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DEAD TIMER */
|
|
|
|
if (ifa->deadint != new->deadint)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing dead interval of %s from %d to %d",
|
2011-03-17 22:53:36 +08:00
|
|
|
ifname, ifa->deadint, new->deadint);
|
|
|
|
ifa->deadint = new->deadint;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* INFTRANS */
|
|
|
|
if (ifa->inftransdelay != new->inftransdelay)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing transmit delay of %s from %d to %d",
|
2011-03-17 22:53:36 +08:00
|
|
|
ifname, ifa->inftransdelay, new->inftransdelay);
|
|
|
|
ifa->inftransdelay = new->inftransdelay;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AUTHENTICATION */
|
|
|
|
if (ifa->autype != new->autype)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing authentication type of %s", ifname);
|
2011-03-17 22:53:36 +08:00
|
|
|
ifa->autype = new->autype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update passwords */
|
|
|
|
ifa->passwords = new->passwords;
|
|
|
|
|
2016-10-28 02:58:21 +08:00
|
|
|
/* Update header length */
|
|
|
|
ifa->tx_hdrlen = ifa_tx_hdrlen(ifa);
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
/* Remaining options are just for proper interfaces */
|
|
|
|
if (ifa->type == OSPF_IT_VLINK)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* COST */
|
|
|
|
if (ifa->cost != new->cost)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing cost of %s from %d to %d",
|
2011-03-17 22:53:36 +08:00
|
|
|
ifname, ifa->cost, new->cost);
|
|
|
|
|
|
|
|
ifa->cost = new->cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PRIORITY */
|
|
|
|
if (ifa->priority != new->priority)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing priority of %s from %d to %d",
|
2011-03-17 22:53:36 +08:00
|
|
|
ifname, ifa->priority, new->priority);
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
ifa->priority = new->priority;
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_notify_link_lsa(ifa);
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* STRICT NBMA */
|
|
|
|
if (ifa->strictnbma != new->strictnbma)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing NBMA strictness of %s from %d to %d",
|
|
|
|
ifname, ifa->strictnbma, new->strictnbma);
|
2011-03-17 22:53:36 +08:00
|
|
|
ifa->strictnbma = new->strictnbma;
|
|
|
|
}
|
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
struct nbma_node *nb, *nbx;
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
/* NBMA LIST - remove or update old */
|
|
|
|
WALK_LIST_DELSAFE(nb, nbx, ifa->nbma_list)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct nbma_node *nb2 = find_nbma_node_(&new->nbma_list, nb->ip);
|
2011-03-17 22:53:36 +08:00
|
|
|
if (nb2)
|
|
|
|
{
|
|
|
|
if (nb->eligible != nb2->eligible)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing eligibility of NBMA neighbor %I on %s",
|
2011-03-17 22:53:36 +08:00
|
|
|
nb->ip, ifname);
|
|
|
|
nb->eligible = nb2->eligible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Removing NBMA neighbor %I on %s",
|
2011-03-17 22:53:36 +08:00
|
|
|
nb->ip, ifname);
|
|
|
|
rem_node(NODE nb);
|
|
|
|
mb_free(nb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NBMA LIST - add new */
|
|
|
|
WALK_LIST(nb, new->nbma_list)
|
|
|
|
{
|
2013-04-16 22:22:31 +08:00
|
|
|
/* See related note in ospf_iface_new() */
|
2015-11-12 09:03:59 +08:00
|
|
|
if (ospf_is_v2(p) && !ipa_in_netX(nb->ip, &ifa->addr->prefix))
|
2011-03-17 22:53:36 +08:00
|
|
|
continue;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
|
|
|
if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip))
|
2014-10-24 16:27:21 +08:00
|
|
|
log(L_WARN "%s: Configured neighbor address (%I) should be link-local",
|
|
|
|
p->p.name, nb->ip);
|
2011-03-17 22:53:36 +08:00
|
|
|
|
|
|
|
if (! find_nbma_node(ifa, nb->ip))
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Adding NBMA neighbor %I on %s",
|
2011-03-17 22:53:36 +08:00
|
|
|
nb->ip, ifname);
|
|
|
|
add_nbma_node(ifa, nb, !!find_neigh_by_ip(ifa, nb->ip));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
int update_buffers = 0;
|
|
|
|
|
|
|
|
/* TX LENGTH */
|
|
|
|
if (old->tx_length != new->tx_length)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing TX length of %s from %d to %d",
|
2014-02-07 00:46:01 +08:00
|
|
|
ifname, old->tx_length, new->tx_length);
|
|
|
|
|
|
|
|
/* ifa cannot be vlink */
|
|
|
|
ifa->tx_length = ifa_tx_length(ifa);
|
|
|
|
update_buffers = 1;
|
2014-11-03 17:42:55 +08:00
|
|
|
|
|
|
|
if (!ifa->stub)
|
|
|
|
ospf_iface_update_flood_queue_size(ifa);
|
2014-02-07 00:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RX BUFFER */
|
|
|
|
if (old->rx_buffer != new->rx_buffer)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing buffer size of %s from %d to %d",
|
2014-02-07 00:46:01 +08:00
|
|
|
ifname, old->rx_buffer, new->rx_buffer);
|
|
|
|
|
|
|
|
/* ifa cannot be vlink */
|
|
|
|
update_buffers = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Buffer size depends on both tx_length and rx_buffer options */
|
|
|
|
if (update_buffers && ifa->sk)
|
2011-03-17 22:53:36 +08:00
|
|
|
{
|
2014-02-07 00:46:01 +08:00
|
|
|
uint bsize = ifa_bufsize(ifa);
|
|
|
|
sk_set_rbsize(ifa->sk, bsize);
|
|
|
|
sk_set_tbsize(ifa->sk, bsize);
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* LINK */
|
|
|
|
if (ifa->check_link != new->check_link)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "%s link check for %s",
|
2011-03-17 22:53:36 +08:00
|
|
|
new->check_link ? "Enabling" : "Disabling", ifname);
|
|
|
|
ifa->check_link = new->check_link;
|
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
/* ifa cannot be vlink */
|
2011-03-17 22:53:36 +08:00
|
|
|
if (!(ifa->iface->flags & IF_LINK_UP))
|
|
|
|
ospf_iface_sm(ifa, ifa->check_link ? ISM_LOOP : ISM_UNLOOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMP weight */
|
|
|
|
if (ifa->ecmp_weight != new->ecmp_weight)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Changing ECMP weight of %s from %d to %d",
|
2011-03-17 22:53:36 +08:00
|
|
|
ifname, (int)ifa->ecmp_weight + 1, (int)new->ecmp_weight + 1);
|
|
|
|
ifa->ecmp_weight = new->ecmp_weight;
|
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* Link LSA suppression */
|
|
|
|
if (((ifa->type == OSPF_IT_PTP) || (ifa->type == OSPF_IT_PTMP)) &&
|
|
|
|
(ifa->link_lsa_suppression != new->link_lsa_suppression))
|
|
|
|
{
|
|
|
|
OSPF_TRACE(D_EVENTS, "Changing link LSA suppression of %s from %d to %d",
|
|
|
|
ifname, ifa->link_lsa_suppression, new->link_lsa_suppression);
|
|
|
|
|
|
|
|
ifa->link_lsa_suppression = new->link_lsa_suppression;
|
|
|
|
ospf_notify_link_lsa(ifa);
|
|
|
|
}
|
|
|
|
|
2013-11-20 05:33:48 +08:00
|
|
|
/* BFD */
|
|
|
|
if (ifa->bfd != new->bfd)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "%s BFD for %s",
|
2013-11-20 05:33:48 +08:00
|
|
|
new->bfd ? "Enabling" : "Disabling", ifname);
|
|
|
|
ifa->bfd = new->bfd;
|
|
|
|
|
|
|
|
struct ospf_neighbor *n;
|
|
|
|
WALK_LIST(n, ifa->neigh_list)
|
|
|
|
ospf_neigh_update_bfd(n, ifa->bfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
/* instance_id is not updated - it is part of key */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-03-14 23:36:59 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/*
|
|
|
|
* State for matching iface pattterns walk
|
|
|
|
*
|
|
|
|
* This is significantly different in OSPFv2 and OSPFv3.
|
|
|
|
* In OSPFv2, OSPF ifaces are created for each IP prefix (struct ifa)
|
|
|
|
* In OSPFv3, OSPF ifaces are created based on real iface (struct iface)
|
|
|
|
* We support instance_id for both OSPFv2 (RFC 6549) and OSPFv3.
|
|
|
|
*
|
|
|
|
* We process one ifa/iface and match it for all configured instance IDs. We
|
|
|
|
* maintain bitfields to track whether given instance ID was already matched.
|
|
|
|
* We have two bitfields, one global (active) and one per area (ignore), to
|
|
|
|
* detect misconfigured cases where one iface with one instance ID matches in
|
|
|
|
* multiple areas.
|
|
|
|
*/
|
2010-03-14 23:36:59 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_mip_walk {
|
|
|
|
u32 active[8]; /* Bitfield of active instance IDs */
|
|
|
|
u32 ignore[8]; /* Bitfield of instance IDs matched in current area */
|
|
|
|
struct ospf_area *oa; /* Current area */
|
|
|
|
struct ospf_iface_patt *ip; /* Current iface pattern */
|
|
|
|
struct iface *iface; /* Specified iface (input) */
|
|
|
|
struct ifa *a; /* Specified ifa (input) */
|
|
|
|
int warn; /* Whether iface matched in multiple areas */
|
|
|
|
};
|
2011-03-17 22:53:36 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
static int
|
|
|
|
ospf_walk_matching_iface_patts(struct ospf_proto *p, struct ospf_mip_walk *s)
|
2010-03-14 23:36:59 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
int id;
|
2010-03-14 23:36:59 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (s->ip)
|
|
|
|
goto step;
|
2010-03-14 23:36:59 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
WALK_LIST(s->oa, p->area_list)
|
2010-03-14 23:36:59 +08:00
|
|
|
{
|
2014-11-03 21:53:59 +08:00
|
|
|
if (s->oa->marked)
|
|
|
|
continue;
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
WALK_LIST(s->ip, s->oa->ac->patt_list)
|
2010-03-14 23:36:59 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
id = s->ip->instance_id;
|
|
|
|
if (BIT32_TEST(s->ignore, id))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (iface_patt_match(&s->ip->i, s->iface, s->a))
|
2010-03-14 23:36:59 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
/* Now we matched ifa/iface/instance_id for the first time in current area */
|
|
|
|
BIT32_SET(s->ignore, id);
|
2010-03-14 23:36:59 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* If we already found it in previous areas, ignore it and add warning */
|
2014-07-19 00:24:12 +08:00
|
|
|
if (BIT32_TEST(s->active, id))
|
2014-06-26 17:58:57 +08:00
|
|
|
{ s->warn = 1; continue; }
|
2010-03-14 23:36:59 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
BIT32_SET(s->active, id);
|
|
|
|
return 1;
|
|
|
|
step:
|
|
|
|
;
|
|
|
|
}
|
2010-03-14 23:36:59 +08:00
|
|
|
}
|
2014-06-26 17:58:57 +08:00
|
|
|
BIT32_ZERO(s->ignore, 256);
|
2010-03-14 23:36:59 +08:00
|
|
|
}
|
2014-06-26 17:58:57 +08:00
|
|
|
|
|
|
|
if (s->warn)
|
|
|
|
log(L_WARN "%s: Interface %s matches for multiple areas", p->p.name, s->iface->name);
|
|
|
|
|
|
|
|
return 0;
|
2010-03-14 23:36:59 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
static struct ospf_iface *
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_find_by_key(struct ospf_proto *p, struct ifa *a, int instance_id)
|
2011-03-17 22:53:36 +08:00
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
|
|
|
WALK_LIST(ifa, p->iface_list)
|
|
|
|
if ((ifa->addr == a) && (ifa->instance_id == instance_id) &&
|
|
|
|
(ifa->type != OSPF_IT_VLINK))
|
2011-03-17 22:53:36 +08:00
|
|
|
return ifa;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-03-14 23:36:59 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_ifa_notify2(struct proto *P, uint flags, struct ifa *a)
|
2010-03-14 23:36:59 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = (struct ospf_proto *) P;
|
2012-11-10 23:18:12 +08:00
|
|
|
|
2015-11-12 09:03:59 +08:00
|
|
|
if (a->prefix.type != NET_IP4)
|
|
|
|
return;
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (a->flags & IA_SECONDARY)
|
|
|
|
return;
|
2011-03-17 22:53:36 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (a->scope <= SCOPE_LINK)
|
|
|
|
return;
|
2011-03-17 22:53:36 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* In OSPFv2, we create OSPF iface for each address. */
|
|
|
|
if (flags & IF_CHANGE_UP)
|
|
|
|
{
|
|
|
|
struct ospf_mip_walk s = { .iface = a->iface, .a = a };
|
|
|
|
while (ospf_walk_matching_iface_patts(p, &s))
|
2014-07-19 00:24:12 +08:00
|
|
|
ospf_iface_new(s.oa, a, s.ip);
|
2012-11-10 23:18:12 +08:00
|
|
|
}
|
2011-03-17 22:53:36 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (flags & IF_CHANGE_DOWN)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa, *ifx;
|
|
|
|
WALK_LIST_DELSAFE(ifa, ifx, p->iface_list)
|
|
|
|
if ((ifa->type != OSPF_IT_VLINK) && (ifa->addr == a))
|
|
|
|
ospf_iface_remove(ifa);
|
|
|
|
/* See a note in ospf_iface_notify() */
|
|
|
|
}
|
2010-03-14 23:36:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_ifa_notify3(struct proto *P, uint flags, struct ifa *a)
|
2010-03-14 23:36:59 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = (struct ospf_proto *) P;
|
2010-03-14 23:36:59 +08:00
|
|
|
|
|
|
|
if (a->flags & IA_SECONDARY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (a->scope < SCOPE_LINK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* In OSPFv3, we create OSPF iface for link-local address,
|
|
|
|
other addresses are used for link-LSA. */
|
|
|
|
if (a->scope == SCOPE_LINK)
|
|
|
|
{
|
2017-10-09 07:16:29 +08:00
|
|
|
if (a->prefix.type != NET_IP6)
|
|
|
|
return;
|
|
|
|
|
2010-03-14 23:36:59 +08:00
|
|
|
if (flags & IF_CHANGE_UP)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_mip_walk s = { .iface = a->iface };
|
|
|
|
while (ospf_walk_matching_iface_patts(p, &s))
|
2014-07-19 00:24:12 +08:00
|
|
|
ospf_iface_new(s.oa, a, s.ip);
|
2010-03-14 23:36:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & IF_CHANGE_DOWN)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa, *ifx;
|
2014-06-26 17:58:57 +08:00
|
|
|
WALK_LIST_DELSAFE(ifa, ifx, p->iface_list)
|
|
|
|
if ((ifa->addr == a) && (ifa->type != OSPF_IT_VLINK))
|
2010-11-13 21:19:23 +08:00
|
|
|
ospf_iface_remove(ifa);
|
2010-03-14 23:36:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-09 07:16:29 +08:00
|
|
|
if (a->prefix.type != ospf_get_af(p))
|
|
|
|
return;
|
|
|
|
|
2010-03-14 23:36:59 +08:00
|
|
|
struct ospf_iface *ifa;
|
2014-06-26 17:58:57 +08:00
|
|
|
WALK_LIST(ifa, p->iface_list)
|
2010-03-14 23:36:59 +08:00
|
|
|
if (ifa->iface == a->iface)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
/* RFC 5340 4.4.3 Event 5 - prefix added/deleted */
|
|
|
|
ospf_notify_link_lsa(ifa);
|
|
|
|
ospf_notify_rt_lsa(ifa->oa);
|
2010-03-14 23:36:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
ospf_reconfigure_ifaces2(struct ospf_proto *p)
|
2011-03-17 22:53:36 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct iface *iface;
|
|
|
|
struct ifa *a;
|
2011-03-17 22:53:36 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
WALK_LIST(iface, iface_list)
|
|
|
|
{
|
|
|
|
if (! (iface->flags & IF_UP))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
WALK_LIST(a, iface->addrs)
|
|
|
|
{
|
2015-11-12 09:03:59 +08:00
|
|
|
if (a->prefix.type != NET_IP4)
|
|
|
|
continue;
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (a->flags & IA_SECONDARY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (a->scope <= SCOPE_LINK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
struct ospf_mip_walk s = { .iface = iface, .a = a };
|
|
|
|
while (ospf_walk_matching_iface_patts(p, &s))
|
|
|
|
{
|
|
|
|
/* Main inner loop */
|
|
|
|
struct ospf_iface *ifa = ospf_iface_find_by_key(p, a, s.ip->instance_id);
|
|
|
|
if (ifa)
|
|
|
|
{
|
|
|
|
if ((ifa->oa == s.oa) && (ifa->marked < 2) &&
|
|
|
|
ospf_iface_reconfigure(ifa, s.ip))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Hard restart */
|
2015-11-12 09:03:59 +08:00
|
|
|
log(L_INFO "%s: Restarting interface %s (%N) in area %R",
|
|
|
|
p->p.name, ifa->ifname, &a->prefix, s.oa->areaid);
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_shutdown(ifa);
|
|
|
|
ospf_iface_remove(ifa);
|
|
|
|
}
|
2014-07-19 23:28:38 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_new(s.oa, a, s.ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
2010-03-14 23:36:59 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
static void
|
|
|
|
ospf_reconfigure_ifaces3(struct ospf_proto *p)
|
2011-03-17 22:53:36 +08:00
|
|
|
{
|
|
|
|
struct iface *iface;
|
|
|
|
struct ifa *a;
|
|
|
|
|
|
|
|
WALK_LIST(iface, iface_list)
|
2012-11-10 23:18:12 +08:00
|
|
|
{
|
|
|
|
if (! (iface->flags & IF_UP))
|
|
|
|
continue;
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
WALK_LIST(a, iface->addrs)
|
|
|
|
{
|
2015-11-12 09:03:59 +08:00
|
|
|
if (a->prefix.type != NET_IP6)
|
|
|
|
continue;
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
if (a->flags & IA_SECONDARY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (a->scope != SCOPE_LINK)
|
|
|
|
continue;
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_mip_walk s = { .iface = iface };
|
|
|
|
while (ospf_walk_matching_iface_patts(p, &s))
|
2011-03-17 22:53:36 +08:00
|
|
|
{
|
|
|
|
/* Main inner loop */
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_iface *ifa = ospf_iface_find_by_key(p, a, s.ip->instance_id);
|
2011-03-17 22:53:36 +08:00
|
|
|
if (ifa)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
if ((ifa->oa == s.oa) && (ifa->marked < 2) &&
|
|
|
|
ospf_iface_reconfigure(ifa, s.ip))
|
2011-03-17 22:53:36 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Hard restart */
|
2014-02-07 00:46:01 +08:00
|
|
|
log(L_INFO "%s: Restarting interface %s (IID %d) in area %R",
|
2014-06-26 17:58:57 +08:00
|
|
|
p->p.name, ifa->ifname, ifa->instance_id, s.oa->areaid);
|
2011-03-17 22:53:36 +08:00
|
|
|
ospf_iface_shutdown(ifa);
|
|
|
|
ospf_iface_remove(ifa);
|
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_new(s.oa, a, s.ip);
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
|
|
|
}
|
2012-11-10 23:18:12 +08:00
|
|
|
}
|
2011-03-17 22:53:36 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
void
|
|
|
|
ospf_reconfigure_ifaces(struct ospf_proto *p)
|
|
|
|
{
|
|
|
|
if (ospf_is_v2(p))
|
|
|
|
ospf_reconfigure_ifaces2(p);
|
|
|
|
else
|
|
|
|
ospf_reconfigure_ifaces3(p);
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
|
|
|
|
static void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_change_mtu(struct ospf_proto *p, struct ospf_iface *ifa)
|
2005-03-16 06:06:36 +08:00
|
|
|
{
|
2014-02-07 00:46:01 +08:00
|
|
|
/* ifa is not vlink */
|
2005-03-16 06:06:36 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Interface %s changed MTU to %d", ifa->iface->mtu);
|
2005-03-16 06:06:36 +08:00
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
ifa->tx_length = ifa_tx_length(ifa);
|
2005-03-16 06:06:36 +08:00
|
|
|
|
2014-02-07 00:46:01 +08:00
|
|
|
if (!ifa->sk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We do not shrink dynamic buffers */
|
|
|
|
uint bsize = ifa_bufsize(ifa);
|
|
|
|
if (bsize > ifa->sk->rbsize)
|
|
|
|
sk_set_rbsize(ifa->sk, bsize);
|
|
|
|
if (bsize > ifa->sk->tbsize)
|
|
|
|
sk_set_tbsize(ifa->sk, bsize);
|
2014-11-03 17:42:55 +08:00
|
|
|
|
|
|
|
if (!ifa->stub)
|
|
|
|
ospf_iface_update_flood_queue_size(ifa);
|
2005-03-16 06:06:36 +08:00
|
|
|
}
|
|
|
|
|
2010-11-13 21:19:23 +08:00
|
|
|
static void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_notify(struct ospf_proto *p, uint flags, struct ospf_iface *ifa)
|
2010-11-13 21:19:23 +08:00
|
|
|
{
|
2014-02-07 00:46:01 +08:00
|
|
|
/* ifa is not vlink */
|
|
|
|
|
2010-11-13 21:19:23 +08:00
|
|
|
if (flags & IF_CHANGE_DOWN)
|
|
|
|
{
|
|
|
|
ospf_iface_remove(ifa);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & IF_CHANGE_LINK)
|
|
|
|
ospf_iface_sm(ifa, (ifa->iface->flags & IF_LINK_UP) ? ISM_UNLOOP : ISM_LOOP);
|
|
|
|
|
|
|
|
if (flags & IF_CHANGE_MTU)
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_change_mtu(p, ifa);
|
2010-11-13 21:19:23 +08:00
|
|
|
}
|
|
|
|
|
1999-11-17 23:50:41 +08:00
|
|
|
void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_if_notify(struct proto *P, uint flags, struct iface *iface)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = (struct ospf_proto *) P;
|
2011-03-17 22:53:36 +08:00
|
|
|
|
|
|
|
/*
|
1999-11-17 23:50:41 +08:00
|
|
|
if (iface->flags & IF_IGNORE)
|
|
|
|
return;
|
2011-03-17 22:53:36 +08:00
|
|
|
*/
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2011-03-17 22:53:36 +08:00
|
|
|
/* Going up means that there are no such ifaces yet */
|
2010-11-13 21:19:23 +08:00
|
|
|
if (flags & IF_CHANGE_UP)
|
|
|
|
return;
|
2010-03-14 23:36:59 +08:00
|
|
|
|
2010-11-13 21:19:23 +08:00
|
|
|
struct ospf_iface *ifa, *ifx;
|
2014-06-26 17:58:57 +08:00
|
|
|
WALK_LIST_DELSAFE(ifa, ifx, p->iface_list)
|
2014-02-07 00:46:01 +08:00
|
|
|
if (ifa->iface == iface)
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_notify(p, flags, ifa);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2010-11-13 21:19:23 +08:00
|
|
|
/* We use here that even shutting down iface also shuts down
|
|
|
|
the vlinks, but vlinks are not freed and stays in the
|
|
|
|
iface_list even when down */
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
|
2000-06-02 01:52:21 +08:00
|
|
|
void
|
|
|
|
ospf_iface_info(struct ospf_iface *ifa)
|
|
|
|
{
|
2012-05-14 17:47:41 +08:00
|
|
|
char *more = "";
|
2010-12-25 01:08:07 +08:00
|
|
|
|
|
|
|
if (ifa->strictnbma &&
|
|
|
|
((ifa->type == OSPF_IT_NBMA) || (ifa->type == OSPF_IT_PTMP)))
|
2012-05-14 17:47:41 +08:00
|
|
|
more = " (strict)";
|
|
|
|
|
|
|
|
if (ifa->cf->real_bcast &&
|
|
|
|
((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_PTP)))
|
|
|
|
more = " (real)";
|
2004-06-06 16:55:33 +08:00
|
|
|
|
2004-07-15 05:46:20 +08:00
|
|
|
if (ifa->type == OSPF_IT_VLINK)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
cli_msg(-1015, "Virtual link %s to %R", ifa->ifname, ifa->vid);
|
2010-01-08 06:42:11 +08:00
|
|
|
cli_msg(-1015, "\tPeer IP: %I", ifa->vip);
|
2014-02-07 00:46:01 +08:00
|
|
|
cli_msg(-1015, "\tTransit area: %R (%u)", ifa->voa->areaid, ifa->voa->areaid);
|
2004-07-15 05:46:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
if (ospf_is_v3(ifa->oa->po))
|
|
|
|
cli_msg(-1015, "Interface %s (IID %d)", ifa->ifname, ifa->instance_id);
|
|
|
|
else if (ifa->addr->flags & IA_PEER)
|
2014-02-07 00:46:01 +08:00
|
|
|
cli_msg(-1015, "Interface %s (peer %I)", ifa->ifname, ifa->addr->opposite);
|
2010-03-14 23:36:59 +08:00
|
|
|
else
|
2015-12-24 22:52:03 +08:00
|
|
|
cli_msg(-1015, "Interface %s (%N)", ifa->ifname, &ifa->addr->prefix);
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2012-05-14 17:47:41 +08:00
|
|
|
cli_msg(-1015, "\tType: %s%s", ospf_it[ifa->type], more);
|
2009-07-23 22:51:28 +08:00
|
|
|
cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid);
|
2004-07-15 05:46:20 +08:00
|
|
|
}
|
2014-10-24 16:27:21 +08:00
|
|
|
cli_msg(-1015, "\tState: %s%s", ospf_is_names[ifa->state], ifa->stub ? " (stub)" : "");
|
2004-06-06 16:55:33 +08:00
|
|
|
cli_msg(-1015, "\tPriority: %u", ifa->priority);
|
|
|
|
cli_msg(-1015, "\tCost: %u", ifa->cost);
|
2010-12-08 06:35:39 +08:00
|
|
|
if (ifa->oa->po->ecmp)
|
|
|
|
cli_msg(-1015, "\tECMP weight: %d", ((int) ifa->ecmp_weight) + 1);
|
2004-06-06 16:55:33 +08:00
|
|
|
cli_msg(-1015, "\tHello timer: %u", ifa->helloint);
|
2009-07-06 01:01:54 +08:00
|
|
|
|
2004-06-06 16:55:33 +08:00
|
|
|
if (ifa->type == OSPF_IT_NBMA)
|
2000-06-06 08:46:00 +08:00
|
|
|
{
|
2004-06-06 16:55:33 +08:00
|
|
|
cli_msg(-1015, "\tPoll timer: %u", ifa->pollint);
|
2000-06-06 08:46:00 +08:00
|
|
|
}
|
2004-06-06 16:55:33 +08:00
|
|
|
cli_msg(-1015, "\tWait timer: %u", ifa->waitint);
|
2011-03-17 22:53:36 +08:00
|
|
|
cli_msg(-1015, "\tDead timer: %u", ifa->deadint);
|
2004-06-06 16:55:33 +08:00
|
|
|
cli_msg(-1015, "\tRetransmit timer: %u", ifa->rxmtint);
|
|
|
|
if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA))
|
2000-06-06 08:46:00 +08:00
|
|
|
{
|
2015-06-01 16:41:17 +08:00
|
|
|
cli_msg(-1015, "\tDesignated router (ID): %R", ifa->drid);
|
|
|
|
cli_msg(-1015, "\tDesignated router (IP): %I", ifa->drip);
|
|
|
|
cli_msg(-1015, "\tBackup designated router (ID): %R", ifa->bdrid);
|
|
|
|
cli_msg(-1015, "\tBackup designated router (IP): %I", ifa->bdrip);
|
2000-06-06 08:46:00 +08:00
|
|
|
}
|
2001-08-11 22:01:54 +08:00
|
|
|
}
|