1999-11-17 23:50:41 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2004-07-01 23:01:04 +08:00
|
|
|
* (c) 1999--2004 Ondrej Filip <feela@network.cz>
|
1999-11-17 23:50:41 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
|
|
|
void
|
2004-06-05 01:12:27 +08:00
|
|
|
ospf_hello_receive(struct ospf_hello_packet *ps,
|
2004-06-07 03:53:52 +08:00
|
|
|
struct ospf_iface *ifa, struct ospf_neighbor *n, ip_addr faddr)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-07 03:53:52 +08:00
|
|
|
u32 *pnrid;
|
2004-06-05 01:12:27 +08:00
|
|
|
ip_addr olddr, oldbdr;
|
2000-06-08 10:28:04 +08:00
|
|
|
ip_addr mask;
|
2004-06-05 01:12:27 +08:00
|
|
|
char *beg = "Bad OSPF hello packet from ", *rec = " received: ";
|
|
|
|
struct proto *p = (struct proto *) ifa->proto;
|
2004-07-01 23:01:04 +08:00
|
|
|
unsigned int size = ntohs(ps->ospf_packet.length), i, twoway, oldpriority, eligible = 0, peers;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "Received hello from %I via %s", faddr,
|
|
|
|
ifa->iface->name);
|
|
|
|
mask = ps->netmask;
|
2000-06-08 10:28:04 +08:00
|
|
|
ipa_ntoh(mask);
|
2000-05-11 07:42:13 +08:00
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
if ((unsigned) ipa_mklen(mask) != ifa->iface->addr->pxlen)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-07 03:53:52 +08:00
|
|
|
log(L_ERR "%s%I%sbad netmask %I.", beg, faddr, rec, mask);
|
1999-11-17 23:50:41 +08:00
|
|
|
return;
|
|
|
|
}
|
2004-06-05 01:12:27 +08:00
|
|
|
|
|
|
|
if (ntohs(ps->helloint) != ifa->helloint)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-06 17:37:54 +08:00
|
|
|
log(L_WARN "%s%I%shello interval mismatch (%d).", beg, faddr, rec,
|
|
|
|
ntohs(ps->helloint));
|
1999-11-17 23:50:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
if (ntohl(ps->deadint) != ifa->helloint * ifa->deadc)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-06 17:37:54 +08:00
|
|
|
log(L_ERR "%s%I%sdead interval mismatch (%d).", beg, faddr, rec,
|
|
|
|
ntohl(ps->deadint));
|
1999-11-17 23:50:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-13 19:58:50 +08:00
|
|
|
if (ps->options != ifa->oa->opt.byte)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-06 16:12:42 +08:00
|
|
|
log(L_ERR "%s%I%soptions mismatch (0x%x).", beg, faddr, rec, ps->options);
|
1999-11-17 23:50:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-07 03:53:52 +08:00
|
|
|
if (!n)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-05 01:12:27 +08:00
|
|
|
if ((ifa->type == OSPF_IT_NBMA))
|
2000-09-02 08:03:36 +08:00
|
|
|
{
|
|
|
|
struct nbma_node *nn;
|
2004-06-05 01:12:27 +08:00
|
|
|
int found = 0;
|
2000-09-02 08:03:36 +08:00
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
WALK_LIST(nn, ifa->nbma_list)
|
2000-09-02 08:03:36 +08:00
|
|
|
{
|
2004-07-14 07:42:14 +08:00
|
|
|
if (ipa_equal(faddr, nn->ip))
|
2000-09-02 08:03:36 +08:00
|
|
|
{
|
2004-06-05 01:12:27 +08:00
|
|
|
found = 1;
|
2000-09-02 08:03:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-06-05 01:12:27 +08:00
|
|
|
if ((found == 0) && (ifa->strictnbma))
|
2000-09-02 08:03:36 +08:00
|
|
|
{
|
2004-06-05 01:12:27 +08:00
|
|
|
log(L_WARN "Ignoring new neighbor: %I on %s.", faddr,
|
|
|
|
ifa->iface->name);
|
2000-09-02 08:03:36 +08:00
|
|
|
return;
|
|
|
|
}
|
2004-06-05 01:12:27 +08:00
|
|
|
if (found)
|
2000-09-02 08:03:36 +08:00
|
|
|
{
|
2004-06-05 01:12:27 +08:00
|
|
|
eligible = nn->eligible;
|
|
|
|
if (((ps->priority == 0) && eligible)
|
|
|
|
|| ((ps->priority > 0) && (eligible == 0)))
|
|
|
|
{
|
|
|
|
log(L_ERR "Eligibility mismatch for neighbor: %I on %s",
|
|
|
|
faddr, ifa->iface->name);
|
2000-09-02 08:03:36 +08:00
|
|
|
return;
|
2004-06-05 01:12:27 +08:00
|
|
|
}
|
2000-09-02 08:03:36 +08:00
|
|
|
}
|
|
|
|
}
|
2000-06-06 10:34:57 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "New neighbor found: %I on %s.", faddr,
|
2004-06-05 01:12:27 +08:00
|
|
|
ifa->iface->name);
|
2004-06-04 20:53:10 +08:00
|
|
|
|
|
|
|
n = ospf_neighbor_new(ifa);
|
|
|
|
|
2004-06-07 03:53:52 +08:00
|
|
|
n->rid = ntohl(((struct ospf_packet *) ps)->routerid);
|
2004-06-05 01:12:27 +08:00
|
|
|
n->ip = faddr;
|
|
|
|
n->dr = ps->dr;
|
2000-06-08 10:28:04 +08:00
|
|
|
ipa_ntoh(n->dr);
|
2004-06-05 01:12:27 +08:00
|
|
|
n->bdr = ps->bdr;
|
2000-06-08 10:28:04 +08:00
|
|
|
ipa_ntoh(n->bdr);
|
2004-06-05 01:12:27 +08:00
|
|
|
n->priority = ps->priority;
|
|
|
|
n->options = ps->options;
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
ospf_neigh_sm(n, INM_HELLOREC);
|
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
pnrid = (u32 *) ((struct ospf_hello_packet *) (ps + 1));
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2004-07-01 23:01:04 +08:00
|
|
|
peers = (size - sizeof(struct ospf_hello_packet))/ sizeof(u32);
|
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
twoway = 0;
|
2004-07-01 23:01:04 +08:00
|
|
|
for (i = 0; i < peers; i++)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-05 01:12:27 +08:00
|
|
|
if (ntohl(*(pnrid + i)) == p->cf->global->router_id)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2000-05-11 07:42:13 +08:00
|
|
|
DBG("%s: Twoway received from %I\n", p->name, faddr);
|
1999-11-17 23:50:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_2WAYREC);
|
2004-06-05 01:12:27 +08:00
|
|
|
twoway = 1;
|
1999-11-17 23:50:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
if (!twoway)
|
|
|
|
ospf_neigh_sm(n, INM_1WAYREC);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2000-05-09 19:27:31 +08:00
|
|
|
olddr = n->dr;
|
2000-06-08 10:04:45 +08:00
|
|
|
n->dr = ipa_ntoh(ps->dr);
|
2000-05-09 19:27:31 +08:00
|
|
|
oldbdr = n->bdr;
|
2000-06-08 10:04:45 +08:00
|
|
|
n->bdr = ipa_ntoh(ps->bdr);
|
2000-05-09 19:27:31 +08:00
|
|
|
oldpriority = n->priority;
|
|
|
|
n->priority = ps->priority;
|
|
|
|
|
1999-11-17 23:50:41 +08:00
|
|
|
/* Check priority change */
|
2004-06-05 01:12:27 +08:00
|
|
|
if (n->state >= NEIGHBOR_2WAY)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-05 01:12:27 +08:00
|
|
|
if (n->priority != oldpriority)
|
2004-06-06 16:12:42 +08:00
|
|
|
ospf_iface_sm(ifa, ISM_NEICH);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2000-05-09 19:27:31 +08:00
|
|
|
/* Router is declaring itself ad DR and there is no BDR */
|
2004-07-14 07:42:14 +08:00
|
|
|
if (ipa_equal(n->ip, n->dr) && (ipa_to_u32(n->bdr) == 0)
|
2004-06-05 01:12:27 +08:00
|
|
|
&& (n->state != NEIGHBOR_FULL))
|
2004-06-06 16:12:42 +08:00
|
|
|
ospf_iface_sm(ifa, ISM_BACKS);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2000-05-09 19:27:31 +08:00
|
|
|
/* Neighbor is declaring itself as BDR */
|
2004-07-14 07:42:14 +08:00
|
|
|
if (ipa_equal(n->ip, n->bdr) && (n->state != NEIGHBOR_FULL))
|
2004-06-06 16:12:42 +08:00
|
|
|
ospf_iface_sm(ifa, ISM_BACKS);
|
2000-05-09 19:27:31 +08:00
|
|
|
|
|
|
|
/* Neighbor is newly declaring itself as DR or BDR */
|
2004-07-14 07:42:14 +08:00
|
|
|
if ((ipa_equal(n->ip, n->dr) && (!ipa_equal(n->dr, olddr)))
|
|
|
|
|| (ipa_equal(n->ip, n->bdr) && (!ipa_equal(n->bdr, oldbdr))))
|
2004-06-06 16:12:42 +08:00
|
|
|
ospf_iface_sm(ifa, ISM_NEICH);
|
2000-05-09 19:27:31 +08:00
|
|
|
|
|
|
|
/* Neighbor is no more declaring itself as DR or BDR */
|
2004-07-14 07:42:14 +08:00
|
|
|
if ((ipa_equal(n->ip, olddr) && (!ipa_equal(n->dr, olddr)))
|
|
|
|
|| (ipa_equal(n->ip, oldbdr) && (!ipa_equal(n->bdr, oldbdr))))
|
2004-06-06 16:12:42 +08:00
|
|
|
ospf_iface_sm(ifa, ISM_NEICH);
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
if (ifa->type != OSPF_IT_NBMA)
|
2000-09-02 08:03:36 +08:00
|
|
|
{
|
2004-06-05 01:12:27 +08:00
|
|
|
if ((ifa->priority == 0) && (n->priority > 0))
|
|
|
|
ospf_hello_send(NULL, 0, n);
|
2000-09-02 08:03:36 +08:00
|
|
|
}
|
1999-11-17 23:50:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_HELLOREC);
|
|
|
|
}
|
|
|
|
|
2000-09-02 08:03:36 +08:00
|
|
|
void
|
2004-06-05 01:12:27 +08:00
|
|
|
ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
struct ospf_hello_packet *pkt;
|
|
|
|
struct ospf_packet *op;
|
|
|
|
struct proto *p;
|
2004-06-26 00:39:53 +08:00
|
|
|
struct ospf_neighbor *neigh, *n1;
|
1999-11-17 23:50:41 +08:00
|
|
|
u16 length;
|
|
|
|
u32 *pp;
|
2004-06-26 00:39:53 +08:00
|
|
|
int i, send;
|
|
|
|
struct nbma_node *nb;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
if (timer == NULL)
|
|
|
|
ifa = dirn->ifa;
|
|
|
|
else
|
|
|
|
ifa = (struct ospf_iface *) timer->data;
|
2000-09-02 08:03:36 +08:00
|
|
|
|
2004-06-26 00:39:53 +08:00
|
|
|
if (ifa->state == OSPF_IS_DOWN)
|
|
|
|
return;
|
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
if (ifa->stub)
|
|
|
|
return; /* Don't send any packet on stub iface */
|
2000-09-02 16:54:40 +08:00
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
p = (struct proto *) (ifa->proto);
|
2000-09-02 08:03:36 +08:00
|
|
|
DBG("%s: Hello/Poll timer fired on interface %s.\n",
|
2004-06-05 01:12:27 +08:00
|
|
|
p->name, ifa->iface->name);
|
1999-11-17 23:50:41 +08:00
|
|
|
/* Now we should send a hello packet */
|
|
|
|
/* First a common packet header */
|
2004-06-26 00:39:53 +08:00
|
|
|
if ((ifa->type == OSPF_IT_NBMA) || (ifa->type == OSPF_IT_VLINK))
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-26 00:39:53 +08:00
|
|
|
pkt = (struct ospf_hello_packet *) (ifa->ip_sk->tbuf);
|
2000-06-06 07:44:26 +08:00
|
|
|
}
|
2004-06-05 01:12:27 +08:00
|
|
|
else
|
2000-06-06 07:44:26 +08:00
|
|
|
{
|
2004-06-26 00:39:53 +08:00
|
|
|
pkt = (struct ospf_hello_packet *) (ifa->hello_sk->tbuf);
|
2000-06-06 07:44:26 +08:00
|
|
|
}
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2000-06-06 07:44:26 +08:00
|
|
|
/* Now fill ospf_hello header */
|
2004-06-05 01:12:27 +08:00
|
|
|
op = (struct ospf_packet *) pkt;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2004-06-27 04:15:34 +08:00
|
|
|
ospf_pkt_fill_hdr(ifa, pkt, HELLO_P);
|
2000-06-06 07:44:26 +08:00
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
pkt->netmask = ipa_mkmask(ifa->iface->addr->pxlen);
|
2000-06-06 07:44:26 +08:00
|
|
|
ipa_hton(pkt->netmask);
|
2004-06-05 01:12:27 +08:00
|
|
|
pkt->helloint = ntohs(ifa->helloint);
|
2004-07-13 19:58:50 +08:00
|
|
|
pkt->options = ifa->oa->opt.byte;
|
2004-06-05 01:12:27 +08:00
|
|
|
pkt->priority = ifa->priority;
|
|
|
|
pkt->deadint = htonl(ifa->deadc * ifa->helloint);
|
|
|
|
pkt->dr = ifa->drip;
|
2000-06-08 10:28:04 +08:00
|
|
|
ipa_hton(pkt->dr);
|
2004-06-05 01:12:27 +08:00
|
|
|
pkt->bdr = ifa->bdrip;
|
2000-06-08 10:28:04 +08:00
|
|
|
ipa_hton(pkt->bdr);
|
2000-06-06 07:44:26 +08:00
|
|
|
|
|
|
|
/* Fill all neighbors */
|
2004-06-05 01:12:27 +08:00
|
|
|
i = 0;
|
|
|
|
pp = (u32 *) (((u8 *) pkt) + sizeof(struct ospf_hello_packet));
|
|
|
|
WALK_LIST(neigh, ifa->neigh_list)
|
2000-06-06 07:44:26 +08:00
|
|
|
{
|
2004-06-27 04:15:34 +08:00
|
|
|
if ((i+1) * sizeof(u32) + sizeof(struct ospf_hello_packet) > ospf_pkt_maxsize(ifa))
|
|
|
|
{
|
|
|
|
OSPF_TRACE(D_PACKETS, "Too many neighbors on the interface!");
|
|
|
|
break;
|
|
|
|
}
|
2004-06-05 01:12:27 +08:00
|
|
|
*(pp + i) = htonl(neigh->rid);
|
2000-06-06 07:44:26 +08:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2004-06-05 01:12:27 +08:00
|
|
|
length = sizeof(struct ospf_hello_packet) + i * sizeof(u32);
|
|
|
|
op->length = htons(length);
|
2000-06-06 07:44:26 +08:00
|
|
|
|
2004-06-26 00:39:53 +08:00
|
|
|
switch(ifa->type)
|
2000-06-06 07:44:26 +08:00
|
|
|
{
|
2004-06-26 00:39:53 +08:00
|
|
|
case OSPF_IT_NBMA:
|
|
|
|
if (timer == NULL) /* Response to received hello */
|
2000-06-06 07:44:26 +08:00
|
|
|
{
|
2004-06-27 04:15:34 +08:00
|
|
|
ospf_send_to(ifa->ip_sk, dirn->ip, ifa);
|
2000-06-06 07:44:26 +08:00
|
|
|
}
|
2004-06-26 00:39:53 +08:00
|
|
|
else
|
2000-09-02 08:03:36 +08:00
|
|
|
{
|
2004-06-26 00:39:53 +08:00
|
|
|
int toall = 0;
|
|
|
|
int meeli = 0;
|
|
|
|
if (ifa->state > OSPF_IS_DROTHER)
|
|
|
|
toall = 1;
|
|
|
|
if (ifa->priority > 0)
|
|
|
|
meeli = 1;
|
|
|
|
|
|
|
|
WALK_LIST(nb, ifa->nbma_list)
|
|
|
|
{
|
|
|
|
send = 1;
|
|
|
|
WALK_LIST(n1, ifa->neigh_list)
|
|
|
|
{
|
2004-07-14 07:42:14 +08:00
|
|
|
if (ipa_equal(nb->ip, n1->ip))
|
2004-06-26 00:39:53 +08:00
|
|
|
{
|
|
|
|
send = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((poll == 1) && (send))
|
|
|
|
{
|
|
|
|
if (toall || (meeli && nb->eligible))
|
2004-06-27 04:15:34 +08:00
|
|
|
ospf_send_to(ifa->ip_sk, nb->ip, ifa);
|
2004-06-26 00:39:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (poll == 0)
|
|
|
|
{
|
|
|
|
WALK_LIST(n1, ifa->neigh_list)
|
|
|
|
{
|
|
|
|
if (toall || (n1->rid == ifa->drid) || (n1->rid == ifa->bdrid) ||
|
|
|
|
(meeli && (n1->priority > 0)))
|
2004-06-27 04:15:34 +08:00
|
|
|
ospf_send_to(ifa->ip_sk, n1->ip, ifa);
|
2004-06-26 00:39:53 +08:00
|
|
|
}
|
|
|
|
}
|
2000-09-02 08:03:36 +08:00
|
|
|
}
|
2004-06-26 00:39:53 +08:00
|
|
|
break;
|
|
|
|
case OSPF_IT_VLINK:
|
2004-06-27 04:15:34 +08:00
|
|
|
ospf_send_to(ifa->ip_sk, ifa->vip, ifa);
|
2004-06-26 00:39:53 +08:00
|
|
|
break;
|
|
|
|
default:
|
2004-06-27 04:15:34 +08:00
|
|
|
ospf_send_to(ifa->hello_sk, IPA_NONE, ifa);
|
2000-06-06 07:44:26 +08:00
|
|
|
}
|
2004-06-05 01:12:27 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "Hello sent via %s", ifa->iface->name);
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|