0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-17 08:38:42 +00:00

Temporary OSPF commit - sockets.

This commit is contained in:
Ondrej Zajicek 2010-03-14 16:36:59 +01:00
parent 54305181f6
commit 0aad2b9292
12 changed files with 268 additions and 136 deletions

View File

@ -566,8 +566,8 @@ if_init(void)
* Interface Pattern Lists * Interface Pattern Lists
*/ */
static int int
iface_patt_match(struct iface_patt *ifp, struct iface *i) iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a)
{ {
struct iface_patt_node *p; struct iface_patt_node *p;
@ -588,8 +588,9 @@ iface_patt_match(struct iface_patt *ifp, struct iface *i)
continue; continue;
} }
// FIXME there should be check for prefix in prefix. (?)
if (p->pxlen) if (p->pxlen)
if (!i->addr || !ipa_in_net(i->addr->ip, p->prefix, p->pxlen)) if (!a || !ipa_in_net(a->ip, p->prefix, p->pxlen))
continue; continue;
return pos; return pos;
@ -599,12 +600,12 @@ iface_patt_match(struct iface_patt *ifp, struct iface *i)
} }
struct iface_patt * struct iface_patt *
iface_patt_find(list *l, struct iface *i) iface_patt_find(list *l, struct iface *i, struct ifa *a)
{ {
struct iface_patt *p; struct iface_patt *p;
WALK_LIST(p, *l) WALK_LIST(p, *l)
if (iface_patt_match(p, i)) if (iface_patt_match(p, i, a))
return p; return p;
return NULL; return NULL;

View File

@ -144,7 +144,8 @@ struct iface_patt {
/* Protocol-specific data follow after this structure */ /* Protocol-specific data follow after this structure */
}; };
struct iface_patt *iface_patt_find(list *, struct iface *); int iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a);
struct iface_patt *iface_patt_find(list *l, struct iface *i, struct ifa *a);
int iface_patts_equal(list *, list *, int (*)(struct iface_patt *, struct iface_patt *)); int iface_patts_equal(list *, list *, int (*)(struct iface_patt *, struct iface_patt *));
#endif #endif

View File

@ -30,7 +30,7 @@ dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
struct rt_dev_config *P = (void *) p->cf; struct rt_dev_config *P = (void *) p->cf;
if (!EMPTY_LIST(P->iface_list) && if (!EMPTY_LIST(P->iface_list) &&
!iface_patt_find(&P->iface_list, ad->iface)) !iface_patt_find(&P->iface_list, ad->iface, ad->iface->addr))
/* Empty list is automagically treated as "*" */ /* Empty list is automagically treated as "*" */
return; return;

View File

@ -254,8 +254,8 @@ ospf_hello_send(timer *timer, int poll, struct ospf_neighbor *dirn)
return; /* Don't send any packet on stub iface */ return; /* Don't send any packet on stub iface */
p = (struct proto *) (ifa->oa->po); p = (struct proto *) (ifa->oa->po);
DBG("%s: Hello/Poll timer fired on interface %s.\n", DBG("%s: Hello/Poll timer fired on interface %s with IP %I\n",
p->name, ifa->iface->name); p->name, ifa->iface->name, ifa->addr->ip);
/* Now we should send a hello packet */ /* Now we should send a hello packet */
pkt = ospf_tx_buffer(ifa); pkt = ospf_tx_buffer(ifa);

View File

@ -21,7 +21,6 @@ char *ospf_it[] = { "broadcast", "nbma", "point-to-point", "virtual link" };
static void static void
poll_timer_hook(timer * timer) poll_timer_hook(timer * timer)
{ {
log("POLL!");
ospf_hello_send(timer, 1, NULL); ospf_hello_send(timer, 1, NULL);
} }
@ -59,7 +58,7 @@ rxbufsize(struct ospf_iface *ifa)
} }
static int static int
ospf_sk_open(struct ospf_iface *ifa, int mc) ospf_sk_open(struct ospf_iface *ifa)
{ {
sock *sk; sock *sk;
struct proto *p = &ifa->oa->po->proto; struct proto *p = &ifa->oa->po->proto;
@ -73,10 +72,8 @@ ospf_sk_open(struct ospf_iface *ifa, int mc)
* In Linux IPv4, binding a raw socket to an IP address of an iface causes * In Linux IPv4, binding a raw socket to an IP address of an iface causes
* that the socket does not receive multicast packets, as they have * that the socket does not receive multicast packets, as they have
* different (multicast) destination IP address. * different (multicast) destination IP address.
*
* We want such filter in the vlink (non-mc) socket.
*/ */
sk->saddr = mc ? IPA_NONE : ifa->addr->ip; sk->saddr = IPA_NONE;
#else /* OSPFv3 */ #else /* OSPFv3 */
sk->saddr = ifa->addr->ip; /* link-local addr */ sk->saddr = ifa->addr->ip; /* link-local addr */
#endif #endif
@ -100,7 +97,8 @@ ospf_sk_open(struct ospf_iface *ifa, int mc)
goto err; goto err;
#endif #endif
if (mc && (sk_setup_multicast(sk) < 0)) sk->saddr = ifa->addr->ip;
if (sk_setup_multicast(sk) < 0)
goto err; goto err;
ifa->sk = sk; ifa->sk = sk;
@ -188,12 +186,6 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
OSPF_TRACE(D_EVENTS, OSPF_TRACE(D_EVENTS,
"Changing state of virtual link %R from \"%s\" into \"%s\".", "Changing state of virtual link %R from \"%s\" into \"%s\".",
ifa->vid, ospf_is[oldstate], ospf_is[state]); ifa->vid, ospf_is[oldstate], ospf_is[state]);
/*
if (state == OSPF_IS_PTP)
ospf_sk_open(ifa, 0);
if (state == OSPF_IS_DOWN)
ospf_sk_close(ifa);
*/
} }
else else
{ {
@ -240,7 +232,7 @@ ospf_iface_down(struct ospf_iface *ifa)
{ {
WALK_LIST(iff, po->iface_list) WALK_LIST(iff, po->iface_list)
{ {
if ((iff->type == OSPF_IT_VLINK) && (iff->iface == ifa->iface)) if ((iff->type == OSPF_IT_VLINK) && (iff->vifa == ifa))
ospf_iface_sm(iff, ISM_DOWN); ospf_iface_sm(iff, ISM_DOWN);
} }
} }
@ -253,7 +245,11 @@ ospf_iface_down(struct ospf_iface *ifa)
if (ifa->type == OSPF_IT_VLINK) if (ifa->type == OSPF_IT_VLINK)
{ {
ifa->vifa = NULL;
ifa->iface = NULL; ifa->iface = NULL;
ifa->addr = NULL;
ifa->sk = NULL;
ifa->vip = IPA_NONE;
return; return;
} }
else else
@ -351,9 +347,9 @@ ospf_iface_sm(struct ospf_iface *ifa, int event)
} }
u8 u8
ospf_iface_clasify(struct iface * ifa) ospf_iface_clasify(struct iface *ifa, struct ifa *addr)
{ {
if (ifa->addr->flags & IA_UNNUMBERED) if (addr->flags & IA_UNNUMBERED)
return OSPF_IT_PTP; return OSPF_IT_PTP;
if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) == if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) ==
@ -382,23 +378,19 @@ ospf_iface_add(struct object_lock *lock)
struct ospf_iface *ifa = lock->data; struct ospf_iface *ifa = lock->data;
struct proto_ospf *po = ifa->oa->po; struct proto_ospf *po = ifa->oa->po;
struct proto *p = &po->proto; struct proto *p = &po->proto;
struct iface *iface = lock->iface;
ifa->lock = lock; ifa->lock = lock;
ifa->ioprob = OSPF_I_OK; if (ospf_sk_open(ifa))
ospf_sk_open(ifa, 1);
if (ifa->type != OSPF_IT_NBMA)
ospf_sk_join_spf(ifa);
if (0)
{ {
log(L_ERR "%s: Huh? could not open ip socket on interface %s?", p->name, if (ifa->type != OSPF_IT_NBMA)
iface->name); ospf_sk_join_spf(ifa);
log(L_ERR "%s: Declaring as stub.", p->name); }
else
{
log(L_ERR "%s: Socket open failed on interface %s, declaring as stub", p->name, ifa->iface->name);
ifa->ioprob = OSPF_I_SK;
ifa->stub = 1; ifa->stub = 1;
ifa->ioprob += OSPF_I_IP;
} }
ifa->state = OSPF_IS_DOWN; ifa->state = OSPF_IS_DOWN;
@ -406,7 +398,7 @@ ospf_iface_add(struct object_lock *lock)
} }
void void
ospf_iface_new(struct proto_ospf *po, struct iface *iface, ospf_iface_new(struct proto_ospf *po, struct iface *iface, struct ifa *addr,
struct ospf_area_config *ac, struct ospf_iface_patt *ip) struct ospf_area_config *ac, struct ospf_iface_patt *ip)
{ {
struct proto *p = &po->proto; struct proto *p = &po->proto;
@ -420,6 +412,7 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface,
ifa = mb_allocz(p->pool, sizeof(struct ospf_iface)); ifa = mb_allocz(p->pool, sizeof(struct ospf_iface));
ifa->iface = iface; ifa->iface = iface;
ifa->addr = addr;
ifa->cost = ip->cost; ifa->cost = ip->cost;
ifa->rxmtint = ip->rxmtint; ifa->rxmtint = ip->rxmtint;
@ -431,44 +424,47 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface,
ifa->waitint = ip->waitint; ifa->waitint = ip->waitint;
ifa->dead = (ip->dead == 0) ? ip->deadc * ifa->helloint : ip->dead; ifa->dead = (ip->dead == 0) ? ip->deadc * ifa->helloint : ip->dead;
ifa->stub = ip->stub; ifa->stub = ip->stub;
ifa->ioprob = OSPF_I_OK;
ifa->rxbuf = ip->rxbuf;
#ifdef OSPFv2 #ifdef OSPFv2
ifa->autype = ip->autype; ifa->autype = ip->autype;
ifa->passwords = ip->passwords; ifa->passwords = ip->passwords;
ifa->addr = iface->addr;
#endif #endif
#ifdef OSPFv3 #ifdef OSPFv3
ifa->instance_id = ip->instance_id; ifa->instance_id = ip->instance_id;
ifa->addr = NULL; /*
addr = NULL;
/* Find link-local address */
if (ifa->type != OSPF_IT_VLINK) if (ifa->type != OSPF_IT_VLINK)
{ {
struct ifa *a; struct ifa *a;
WALK_LIST(a, iface->addrs) WALK_LIST(a, iface->addrs)
if (a->scope == SCOPE_LINK) if (a->scope == SCOPE_LINK)
{ {
ifa->addr = a; addr = a;
break; break;
} }
if (! ifa->addr) if (!addr)
log(L_WARN "%s: Missing link local address on interface %s", p->name, iface->name); {
log(L_ERR "%s: Missing link-local address on interface %s, declaring as stub", p->name, iface->name);
ifa->ioprob = OSPF_I_LL;
ifa->stub = 1;
}
} }
*/
#endif #endif
ifa->rxbuf = ip->rxbuf;
if (ip->type == OSPF_IT_UNDEF) if (ip->type == OSPF_IT_UNDEF)
ifa->type = ospf_iface_clasify(ifa->iface); ifa->type = ospf_iface_clasify(iface, addr);
else else
ifa->type = ip->type; ifa->type = ip->type;
#ifdef OSPFv2 #ifdef OSPFv2
if ((ifa->type != OSPF_IT_PTP) && (ifa->type != OSPF_IT_VLINK) && if ((ifa->type != OSPF_IT_PTP) && (ifa->type != OSPF_IT_VLINK) &&
(ifa->iface->addr->flags & IA_UNNUMBERED)) (addr->flags & IA_UNNUMBERED))
{ {
log(L_WARN "%s: Missing proper IP prefix on interface %s, forcing point-to-point mode", log(L_WARN "%s: Missing proper IP prefix on interface %s, forcing point-to-point mode",
p->name, iface->name); p->name, iface->name);
@ -538,8 +534,19 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface,
return; /* Don't lock, don't add sockets */ return; /* Don't lock, don't add sockets */
} }
/*
* In some cases we allow more ospf_ifaces on one physical iface.
* In OSPFv2, if they use different IP address prefix.
* In OSPFv3, if they use different instance_id.
* Therefore, we store such info to lock->addr field.
*/
lock = olock_new(p->pool); lock = olock_new(p->pool);
lock->addr = AllSPFRouters; #ifdef OSPFv2
lock->addr = ifa->addr->prefix;
#else /* OSPFv3 */
lock->addr = _MI(0,0,0,ifa->instance_id);
#endif
lock->type = OBJLOCK_IP; lock->type = OBJLOCK_IP;
lock->port = OSPF_PROTO; lock->port = OSPF_PROTO;
lock->iface = iface; lock->iface = iface;
@ -549,6 +556,150 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface,
olock_acquire(lock); olock_acquire(lock);
} }
#ifdef OSPFv2
void
ospf_ifa_notify(struct proto *p, unsigned flags, struct ifa *a)
{
struct proto_ospf *po = (struct proto_ospf *) p;
struct ospf_config *cf = (struct ospf_config *) (p->cf);
if (a->flags & IA_SECONDARY)
return;
if (a->scope <= SCOPE_LINK)
return;
/* In OSPFv2, we create OSPF iface for each address. */
if (flags & IF_CHANGE_UP)
{
int done = 0;
struct ospf_area_config *ac;
WALK_LIST(ac, cf->area_list)
{
struct ospf_iface_patt *ip = (struct ospf_iface_patt *)
iface_patt_find(&ac->patt_list, a->iface, a);
if (ip)
{
if (!done)
ospf_iface_new(po, a->iface, a, ac, ip);
done++;
}
}
if (done > 1)
log(L_WARN "%s: Interface %s (IP %I) matches for multiple areas", p->name, a->iface->name, a->ip);
}
if (flags & IF_CHANGE_DOWN)
{
struct ospf_iface *ifa, *ifx;
WALK_LIST_DELSAFE(ifa, ifx, po->iface_list)
{
if ((ifa->type != OSPF_IT_VLINK) && (ifa->addr == a))
ospf_iface_sm(ifa, ISM_DOWN);
/* See a note in ospf_iface_notify() */
}
}
}
#else /* OSPFv3 */
static inline int iflag_test(u32 *a, u8 i)
{
return a[i / 32] & (1u << (i % 32));
}
static inline void iflag_set(u32 *a, u8 i)
{
a[i / 32] |= (1u << (i % 32));
}
void
ospf_ifa_notify(struct proto *p, unsigned flags, struct ifa *a)
{
struct proto_ospf *po = (struct proto_ospf *) p;
struct ospf_config *cf = (struct ospf_config *) (p->cf);
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)
{
if (flags & IF_CHANGE_UP)
{
u32 found_all[8] = {};
struct ospf_area_config *ac;
WALK_LIST(ac, cf->area_list)
{
u32 found_new[8] = {};
struct iface_patt *p;
WALK_LIST(p, ac->patt_list)
{
if (iface_patt_match(p, i, a))
{
struct ospf_iface_patt *ip = (struct ospf_iface_patt *) p;
/* If true, we already assigned that IID and we skip
this to implement first-match behavior */
if (iflag_test(found_new, ip->instance_id))
continue;
/* If true, we already assigned that in a different area,
we log collision */
if (iflag_test(found_all, ip->instance_id))
{
log(L_WARN "%s: Interface %s (IID %d) matches for multiple areas",
p->name, a->iface->name, ip->instance_id);
continue;
}
iflag_set(found_all, ip->instance_id);
iflag_set(found_new, ip->instance_id);
ospf_iface_new(po, a->iface, a, ac, ip);
}
}
}
}
if (flags & IF_CHANGE_DOWN)
{
struct ospf_iface *ifa, *ifx;
WALK_LIST_DELSAFE(ifa, ifx, po->iface_list)
{
if ((ifa->type != OSPF_IT_VLINK) && (ifa->addr == a))
ospf_iface_sm(ifa, ISM_DOWN);
/* See a note in ospf_iface_notify() */
}
}
}
else
{
struct ospf_iface *ifa;
WALK_LIST(ifa, po->iface_list)
{
if (ifa->iface == a->iface)
{
schedule_rt_lsa(ifa->oa);
/* Event 5 from RFC5340 4.4.3. */
schedule_link_lsa(ifa);
return;
}
}
}
}
#endif
void void
ospf_iface_change_mtu(struct proto_ospf *po, struct ospf_iface *ifa) ospf_iface_change_mtu(struct proto_ospf *po, struct ospf_iface *ifa)
{ {
@ -580,38 +731,29 @@ void
ospf_iface_notify(struct proto *p, unsigned flags, struct iface *iface) ospf_iface_notify(struct proto *p, unsigned flags, struct iface *iface)
{ {
struct proto_ospf *po = (struct proto_ospf *) p; struct proto_ospf *po = (struct proto_ospf *) p;
struct ospf_config *c = (struct ospf_config *) (p->cf);
struct ospf_area_config *ac;
struct ospf_iface_patt *ip = NULL;
struct ospf_iface *ifa;
DBG("%s: If notify called\n", p->name); DBG("%s: If notify called\n", p->name);
if (iface->flags & IF_IGNORE) if (iface->flags & IF_IGNORE)
return; return;
if (flags & IF_CHANGE_UP)
{
WALK_LIST(ac, c->area_list)
{
if (ip = (struct ospf_iface_patt *)
iface_patt_find(&ac->patt_list, iface))
break;
}
if (ip)
ospf_iface_new(po, iface, ac, ip);
}
if (flags & IF_CHANGE_DOWN) if (flags & IF_CHANGE_DOWN)
{ {
if ((ifa = ospf_iface_find((struct proto_ospf *) p, iface)) != NULL) struct ospf_iface *ifa, *ifx;
ospf_iface_sm(ifa, ISM_DOWN); WALK_LIST_DELSAFE(ifa, ifx, po->iface_list)
if ((ifa->type != OSPF_IT_VLINK) && (ifa->iface == iface))
ospf_iface_sm(ifa, ISM_DOWN);
/* 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 */
} }
if (flags & IF_CHANGE_MTU) if (flags & IF_CHANGE_MTU)
{ {
if ((ifa = ospf_iface_find((struct proto_ospf *) p, iface)) != NULL) struct ospf_iface *ifa;
ospf_iface_change_mtu(po, ifa); WALK_LIST(ifa, po->iface_list)
if ((ifa->type != OSPF_IT_VLINK) && (ifa->iface == iface))
ospf_iface_change_mtu(po, ifa);
} }
} }
@ -633,8 +775,14 @@ ospf_iface_info(struct ospf_iface *ifa)
} }
else else
{ {
cli_msg(-1015, "Interface \"%s\":", #ifdef OSPFv2
(ifa->iface ? ifa->iface->name : "(none)")); if (ifa->addr->flags & IA_UNNUMBERED)
cli_msg(-1015, "Interface %s (peer %I)", ifa->iface->name, ifa->addr->opposite);
else
cli_msg(-1015, "Interface %s (%I/%d)", ifa->iface->name, ifa->addr->prefix, ifa->addr->pxlen);
#else /* OSPFv3 */
cli_msg(-1015, "Interface %s (IID %d)", ifa->iface->name, ifa->instance_id);
#endif
cli_msg(-1015, "\tType: %s %s", ospf_it[ifa->type], strict); cli_msg(-1015, "\tType: %s %s", ospf_it[ifa->type], strict);
cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid); cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid);
} }

View File

@ -14,9 +14,10 @@ void ospf_iface_chstate(struct ospf_iface *ifa, u8 state);
void ospf_iface_sm(struct ospf_iface *ifa, int event); void ospf_iface_sm(struct ospf_iface *ifa, int event);
struct ospf_iface *ospf_iface_find(struct proto_ospf *p, struct iface *what); struct ospf_iface *ospf_iface_find(struct proto_ospf *p, struct iface *what);
void ospf_iface_notify(struct proto *p, unsigned flags, struct iface *iface); void ospf_iface_notify(struct proto *p, unsigned flags, struct iface *iface);
void ospf_ifa_notify(struct proto *p, unsigned flags, struct ifa *a);
void ospf_iface_info(struct ospf_iface *ifa); void ospf_iface_info(struct ospf_iface *ifa);
void ospf_iface_shutdown(struct ospf_iface *ifa); void ospf_iface_shutdown(struct ospf_iface *ifa);
void ospf_iface_new(struct proto_ospf *po, struct iface *iface, struct ospf_area_config *ac, struct ospf_iface_patt *ip); void ospf_iface_new(struct proto_ospf *po, struct iface *iface, struct ifa *addr, struct ospf_area_config *ac, struct ospf_iface_patt *ip);
void ospf_iface_change_mtu(struct proto_ospf *po, struct ospf_iface *ifa); void ospf_iface_change_mtu(struct proto_ospf *po, struct ospf_iface *ifa);
void ospf_set_rxbuf_size(struct ospf_iface *ifa, u32 rxbuf); void ospf_set_rxbuf_size(struct ospf_iface *ifa, u32 rxbuf);

View File

@ -79,7 +79,6 @@
static int ospf_reload_routes(struct proto *p); static int ospf_reload_routes(struct proto *p);
static void ospf_rt_notify(struct proto *p, struct rtable *table UNUSED, net * n, rte * new, rte * old UNUSED, ea_list * attrs); static void ospf_rt_notify(struct proto *p, struct rtable *table UNUSED, net * n, rte * new, rte * old UNUSED, ea_list * attrs);
static void ospf_ifa_notify(struct proto *p, unsigned flags, struct ifa *a);
static int ospf_rte_better(struct rte *new, struct rte *old); static int ospf_rte_better(struct rte *new, struct rte *old);
static int ospf_rte_same(struct rte *new, struct rte *old); static int ospf_rte_same(struct rte *new, struct rte *old);
static void ospf_disp(timer *timer); static void ospf_disp(timer *timer);
@ -196,7 +195,7 @@ ospf_start(struct proto *p)
oa->options = OPT_R | OPT_E | OPT_V6; oa->options = OPT_R | OPT_E | OPT_V6;
#endif #endif
} }
ospf_iface_new(po, NULL, ac, ipatt); ospf_iface_new(po, NULL, NULL, ac, ipatt);
} }
} }
} }
@ -503,27 +502,6 @@ ospf_rt_notify(struct proto *p, rtable *tbl UNUSED, net * n, rte * new, rte * ol
flush_ext_lsa(n, po); flush_ext_lsa(n, po);
} }
static void
ospf_ifa_notify(struct proto *p, unsigned flags UNUSED, struct ifa *a)
{
struct proto_ospf *po = (struct proto_ospf *) p;
struct ospf_iface *ifa;
if ((a->flags & IA_SECONDARY) || (a->flags & IA_UNNUMBERED))
return;
WALK_LIST(ifa, po->iface_list)
{
if (ifa->iface == a->iface)
{
schedule_rt_lsa(ifa->oa);
/* Event 5 from RFC5340 4.4.3. */
schedule_link_lsa(ifa);
return;
}
}
}
static void static void
ospf_get_status(struct proto *p, byte * buf) ospf_get_status(struct proto *p, byte * buf)
{ {
@ -714,12 +692,17 @@ ospf_reconfigure(struct proto *p, struct proto_config *c)
WALK_LIST(ifa, po->iface_list) WALK_LIST(ifa, po->iface_list)
{ {
/* FIXME: better handling of vlinks */
if (ifa->iface == NULL)
continue;
/* FIXME: better matching of interface_id in OSPFv3 */
if (oldip = (struct ospf_iface_patt *) if (oldip = (struct ospf_iface_patt *)
iface_patt_find(&oldac->patt_list, ifa->iface)) iface_patt_find(&oldac->patt_list, ifa->iface, ifa->addr))
{ {
/* Now reconfigure interface */ /* Now reconfigure interface */
if (!(newip = (struct ospf_iface_patt *) if (!(newip = (struct ospf_iface_patt *)
iface_patt_find(&newac->patt_list, ifa->iface))) iface_patt_find(&newac->patt_list, ifa->iface, ifa->addr)))
return 0; return 0;
/* HELLO TIMER */ /* HELLO TIMER */
@ -785,9 +768,7 @@ ospf_reconfigure(struct proto *p, struct proto_config *c)
ifa->stub = newip->stub; ifa->stub = newip->stub;
OSPF_TRACE(D_EVENTS, "Interface %s is now stub.", ifa->iface->name); OSPF_TRACE(D_EVENTS, "Interface %s is now stub.", ifa->iface->name);
} }
if ((oldip->stub != 0) && (newip->stub == 0) && if ((oldip->stub != 0) && (newip->stub == 0) && (ifa->ioprob == OSPF_I_OK))
((ifa->ioprob & OSPF_I_IP) == 0) &&
(((ifa->ioprob & OSPF_I_MC) == 0) || (ifa->type == OSPF_IT_NBMA)))
{ {
ifa->stub = newip->stub; ifa->stub = newip->stub;
OSPF_TRACE(D_EVENTS, OSPF_TRACE(D_EVENTS,

View File

@ -171,7 +171,8 @@ struct ospf_iface
u32 dead; /* after "deadint" missing hellos is router dead */ u32 dead; /* after "deadint" missing hellos is router dead */
u32 vid; /* Id of peer of virtual link */ u32 vid; /* Id of peer of virtual link */
ip_addr vip; /* IP of peer of virtual link */ ip_addr vip; /* IP of peer of virtual link */
struct ospf_area *voa; /* Area wich the vlink goes through */ struct ospf_iface *vifa; /* OSPF iface which the vlink goes through */
struct ospf_area *voa; /* OSPF area which the vlink goes through */
u16 inftransdelay; /* The estimated number of seconds it takes to u16 inftransdelay; /* The estimated number of seconds it takes to
transmit a Link State Update Packet over this transmit a Link State Update Packet over this
interface. LSAs contained in the update */ interface. LSAs contained in the update */
@ -203,9 +204,6 @@ struct ospf_iface
#define OSPF_IT_UNDEF 4 #define OSPF_IT_UNDEF 4
u8 strictnbma; /* Can I talk with unknown neighbors? */ u8 strictnbma; /* Can I talk with unknown neighbors? */
u8 stub; /* Inactive interface */ u8 stub; /* Inactive interface */
#define OSPF_I_OK 0 /* Everything OK */
#define OSPF_I_MC 1 /* I didn't open MC socket */
#define OSPF_I_IP 2 /* I didn't open IP socet */
u8 state; /* Interface state machine */ u8 state; /* Interface state machine */
#define OSPF_IS_DOWN 0 /* Not working */ #define OSPF_IS_DOWN 0 /* Not working */
#define OSPF_IS_LOOP 1 /* Should never happen */ #define OSPF_IS_LOOP 1 /* Should never happen */
@ -239,6 +237,9 @@ struct ospf_iface
list nbma_list; list nbma_list;
u8 priority; /* A router priority for DR election */ u8 priority; /* A router priority for DR election */
u8 ioprob; u8 ioprob;
#define OSPF_I_OK 0 /* Everything OK */
#define OSPF_I_SK 1 /* Socket open failed */
#define OSPF_I_LL 2 /* Missing link-local address (OSPFv3) */
u8 sk_spf; /* Socket is a member of SPFRouters group */ u8 sk_spf; /* Socket is a member of SPFRouters group */
u8 sk_dr; /* Socket is a member of DRouters group */ u8 sk_dr; /* Socket is a member of DRouters group */
u32 rxbuf; u32 rxbuf;

View File

@ -424,12 +424,14 @@ ospf_rt_spfa(struct ospf_area *oa)
if ((tmp = ospf_hash_find_rt(po->gr, oa->areaid, iface->vid)) && if ((tmp = ospf_hash_find_rt(po->gr, oa->areaid, iface->vid)) &&
(!ipa_equal(tmp->lb, IPA_NONE))) (!ipa_equal(tmp->lb, IPA_NONE)))
{ {
if ((iface->state != OSPF_IS_PTP) || (iface->iface != tmp->nhi->iface) || (!ipa_equal(iface->vip, tmp->lb))) if ((iface->state != OSPF_IS_PTP) || (iface->vifa != tmp->nhi) || (!ipa_equal(iface->vip, tmp->lb)))
{ {
OSPF_TRACE(D_EVENTS, "Vlink peer %R found", tmp->lsa.id); OSPF_TRACE(D_EVENTS, "Vlink peer %R found", tmp->lsa.id);
ospf_iface_sm(iface, ISM_DOWN); ospf_iface_sm(iface, ISM_DOWN);
iface->vifa = tmp->nhi;
iface->iface = tmp->nhi->iface; iface->iface = tmp->nhi->iface;
iface->addr = iface->iface->addr; iface->addr = tmp->nhi->addr;
iface->sk = tmp->nhi->sk;
iface->vip = tmp->lb; iface->vip = tmp->lb;
ospf_iface_sm(iface, ISM_UP); ospf_iface_sm(iface, ISM_UP);
} }

View File

@ -272,24 +272,20 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
break; break;
} }
/* Now we will originate stub areas for interfaces addresses */ /* Now we will originate stub area if there is no primary */
struct ifa *a; if (net_lsa ||
WALK_LIST(a, ifa->iface->addrs) (ifa->type == OSPF_IT_VLINK) ||
{ (ifa->addr->flags & IA_UNNUMBERED) ||
if (((a == ifa->addr) && net_lsa) || configured_stubnet(oa, ifa->addr))
(a->flags & IA_SECONDARY) || continue;
(a->flags & IA_UNNUMBERED) ||
configured_stubnet(oa, a))
continue;
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link)); ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
ln->type = LSART_STUB; ln->type = LSART_STUB;
ln->id = ipa_to_u32(a->prefix); ln->id = ipa_to_u32(ifa->addr->prefix);
ln->data = ipa_to_u32(ipa_mkmask(a->pxlen)); ln->data = ipa_to_u32(ipa_mkmask(ifa->addr->pxlen));
ln->metric = ifa->cost; ln->metric = ifa->cost;
ln->padding = 0; ln->padding = 0;
i++; i++;
}
} }
struct ospf_stubnet_config *sn; struct ospf_stubnet_config *sn;
@ -898,6 +894,7 @@ originate_ext_lsa_body(net *n, rte *e, u16 *length, struct proto_ospf *po,
int gw = 0; int gw = 0;
int size = sizeof(struct ospf_lsa_ext); int size = sizeof(struct ospf_lsa_ext);
// FIXME check for gw should be per ifa, not per iface
if ((e->attrs->dest == RTD_ROUTER) && if ((e->attrs->dest == RTD_ROUTER) &&
!ipa_equal(e->attrs->gw, IPA_NONE) && !ipa_equal(e->attrs->gw, IPA_NONE) &&
!ipa_has_link_scope(e->attrs->gw) && !ipa_has_link_scope(e->attrs->gw) &&

View File

@ -761,7 +761,7 @@ rip_real_if_add(struct object_lock *lock)
struct iface *iface = lock->iface; struct iface *iface = lock->iface;
struct proto *p = lock->data; struct proto *p = lock->data;
struct rip_interface *rif; struct rip_interface *rif;
struct iface_patt *k = iface_patt_find(&P_CF->iface_list, iface); struct iface_patt *k = iface_patt_find(&P_CF->iface_list, iface, iface->addr);
if (!k) if (!k)
bug("This can not happen! It existed few seconds ago!" ); bug("This can not happen! It existed few seconds ago!" );
@ -790,7 +790,7 @@ rip_if_notify(struct proto *p, unsigned c, struct iface *iface)
} }
} }
if (c & IF_CHANGE_UP) { if (c & IF_CHANGE_UP) {
struct iface_patt *k = iface_patt_find(&P_CF->iface_list, iface); struct iface_patt *k = iface_patt_find(&P_CF->iface_list, iface, iface->addr);
struct object_lock *lock; struct object_lock *lock;
struct rip_patt *PATT = (struct rip_patt *) k; struct rip_patt *PATT = (struct rip_patt *) k;

View File

@ -62,18 +62,18 @@ get_inaddr(ip_addr *a, struct in_addr *ia)
#define MREQ_IFA struct in_addr #define MREQ_IFA struct in_addr
#define MREQ_GRP struct ip_mreq #define MREQ_GRP struct ip_mreq
static inline void fill_mreq_ifa(struct in_addr *m, struct iface *ifa, UNUSED ip_addr maddr) static inline void fill_mreq_ifa(struct in_addr *m, struct iface *ifa UNUSED, ip_addr saddr, ip_addr maddr UNUSED)
{ {
set_inaddr(m, ifa->addr->ip); set_inaddr(m, saddr);
} }
static inline void fill_mreq_grp(struct ip_mreq *m, struct iface *ifa, ip_addr maddr) static inline void fill_mreq_grp(struct ip_mreq *m, struct iface *ifa, ip_addr saddr, ip_addr maddr)
{ {
bzero(m, sizeof(*m)); bzero(m, sizeof(*m));
#ifdef CONFIG_LINUX_MC_MREQ_BIND #ifdef CONFIG_LINUX_MC_MREQ_BIND
m->imr_interface.s_addr = INADDR_ANY; m->imr_interface.s_addr = INADDR_ANY;
#else #else
set_inaddr(&m->imr_interface, ifa->addr->ip); set_inaddr(&m->imr_interface, saddr);
#endif #endif
set_inaddr(&m->imr_multiaddr, maddr); set_inaddr(&m->imr_multiaddr, maddr);
} }
@ -101,11 +101,11 @@ struct ip_mreqn
#define fill_mreq_ifa fill_mreq #define fill_mreq_ifa fill_mreq
#define fill_mreq_grp fill_mreq #define fill_mreq_grp fill_mreq
static inline void fill_mreq(struct ip_mreqn *m, struct iface *ifa, ip_addr maddr) static inline void fill_mreq(struct ip_mreqn *m, struct iface *ifa, ip_addr saddr, ip_addr maddr)
{ {
bzero(m, sizeof(*m)); bzero(m, sizeof(*m));
m->imr_ifindex = ifa->index; m->imr_ifindex = ifa->index;
set_inaddr(&m->imr_address, ifa->addr->ip); set_inaddr(&m->imr_address, saddr);
set_inaddr(&m->imr_multiaddr, maddr); set_inaddr(&m->imr_multiaddr, maddr);
} }
#endif #endif
@ -123,7 +123,7 @@ sysio_setup_multicast(sock *s)
return "IP_MULTICAST_TTL"; return "IP_MULTICAST_TTL";
/* This defines where should we send _outgoing_ multicasts */ /* This defines where should we send _outgoing_ multicasts */
fill_mreq_ifa(&m, s->iface, IPA_NONE); fill_mreq_ifa(&m, s->iface, s->saddr, IPA_NONE);
if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_IF, &m, sizeof(m)) < 0) if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_IF, &m, sizeof(m)) < 0)
return "IP_MULTICAST_IF"; return "IP_MULTICAST_IF";
@ -145,7 +145,7 @@ sysio_join_group(sock *s, ip_addr maddr)
MREQ_GRP m; MREQ_GRP m;
/* And this one sets interface for _receiving_ multicasts from */ /* And this one sets interface for _receiving_ multicasts from */
fill_mreq_grp(&m, s->iface, maddr); fill_mreq_grp(&m, s->iface, s->saddr, maddr);
if (setsockopt(s->fd, SOL_IP, IP_ADD_MEMBERSHIP, &m, sizeof(m)) < 0) if (setsockopt(s->fd, SOL_IP, IP_ADD_MEMBERSHIP, &m, sizeof(m)) < 0)
return "IP_ADD_MEMBERSHIP"; return "IP_ADD_MEMBERSHIP";
@ -158,7 +158,7 @@ sysio_leave_group(sock *s, ip_addr maddr)
MREQ_GRP m; MREQ_GRP m;
/* And this one sets interface for _receiving_ multicasts from */ /* And this one sets interface for _receiving_ multicasts from */
fill_mreq_grp(&m, s->iface, maddr); fill_mreq_grp(&m, s->iface, s->saddr, maddr);
if (setsockopt(s->fd, SOL_IP, IP_DROP_MEMBERSHIP, &m, sizeof(m)) < 0) if (setsockopt(s->fd, SOL_IP, IP_DROP_MEMBERSHIP, &m, sizeof(m)) < 0)
return "IP_DROP_MEMBERSHIP"; return "IP_DROP_MEMBERSHIP";