From 353729f513aa6a1f9e7f66083a0f9d2117fe2be5 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Thu, 11 Feb 2010 10:23:35 +0100 Subject: Temporary OSPF commit - socket changes. --- proto/ospf/iface.c | 217 +++++++++++++++++++++++++++-------------------------- 1 file changed, 109 insertions(+), 108 deletions(-) (limited to 'proto/ospf/iface.c') diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index 927b8da..3f1e74d 100644 --- a/proto/ospf/iface.c +++ b/proto/ospf/iface.c @@ -58,15 +58,15 @@ rxbufsize(struct ospf_iface *ifa) } } -static sock * -ospf_open_socket(struct ospf_iface *ifa, int mc) +static int +ospf_sk_open(struct ospf_iface *ifa, int mc) { - sock *ipsk; + sock *sk; struct proto *p = &ifa->oa->po->proto; - ipsk = sk_new(p->pool); - ipsk->type = SK_IP; - ipsk->dport = OSPF_PROTO; + sk = sk_new(p->pool); + sk->type = SK_IP; + sk->dport = OSPF_PROTO; #ifdef OSPFv2 /* @@ -76,45 +76,93 @@ ospf_open_socket(struct ospf_iface *ifa, int mc) * * We want such filter in the vlink (non-mc) socket. */ - ipsk->saddr = mc ? IPA_NONE : ifa->iface->addr->ip; + sk->saddr = mc ? IPA_NONE : ifa->addr->ip; #else /* OSPFv3 */ - ipsk->saddr = ifa->lladdr; + sk->saddr = ifa->addr->ip; /* link-local addr */ #endif - ipsk->tos = IP_PREC_INTERNET_CONTROL; - ipsk->ttl = 1; + sk->tos = IP_PREC_INTERNET_CONTROL; + sk->ttl = 1; if (ifa->type == OSPF_IT_VLINK) - ipsk->ttl = 255; - ipsk->rx_hook = ospf_rx_hook; - ipsk->tx_hook = ospf_tx_hook; - ipsk->err_hook = ospf_err_hook; - ipsk->iface = ifa->iface; - ipsk->rbsize = rxbufsize(ifa); - ipsk->tbsize = ifa->iface->mtu; - ipsk->data = (void *) ifa; - if (sk_open(ipsk) != 0) + sk->ttl = 255; + sk->rx_hook = ospf_rx_hook; + sk->tx_hook = ospf_tx_hook; + sk->err_hook = ospf_err_hook; + sk->iface = ifa->iface; + sk->rbsize = rxbufsize(ifa); + sk->tbsize = ifa->iface->mtu; + sk->data = (void *) ifa; + sk->flags = SKF_LADDR_RX; + + if (sk_open(sk) != 0) goto err; #ifdef OSPFv3 /* 12 is an offset of the checksum in an OSPF packet */ - if (sk_set_ipv6_checksum(ipsk, 12) < 0) + if (sk_set_ipv6_checksum(sk, 12) < 0) goto err; #endif - if (mc) - { - if (sk_setup_multicast(ipsk) < 0) - goto err; - - if (sk_join_group(ipsk, AllSPFRouters) < 0) - goto err; - } + if (mc && (sk_setup_multicast(sk) < 0)) + goto err; - return ipsk; + ifa->sk = sk; + ifa->sk_spf = 0; + ifa->sk_dr = 0; + return 1; err: - rfree(ipsk); - return NULL; + rfree(sk); + return 0; +} + +static inline void +ospf_sk_join_spf(struct ospf_iface *ifa) +{ + if (ifa->sk_spf) + return; + + sk_join_group(ifa->sk, AllSPFRouters); + ifa->sk_spf = 1; +} + +static inline void +ospf_sk_join_dr(struct ospf_iface *ifa) +{ + if (ifa->sk_dr) + return; + + sk_join_group(ifa->sk, AllDRouters); + ifa->sk_dr = 1; +} + +static inline void +ospf_sk_leave_spf(struct ospf_iface *ifa) +{ + if (!ifa->sk_spf) + return; + + sk_leave_group(ifa->sk, AllSPFRouters); + ifa->sk_spf = 0; +} + +static inline void +ospf_sk_leave_dr(struct ospf_iface *ifa) +{ + if (!ifa->sk_dr) + return; + + sk_leave_group(ifa->sk, AllDRouters); + ifa->sk_dr = 0; +} + +static inline void +ospf_sk_close(struct ospf_iface *ifa) +{ + ASSERT(ifa->sk); + + rfree(ifa->sk); + ifa->sk = NULL; } @@ -144,9 +192,9 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state) "Changing state of virtual link %R from \"%s\" into \"%s\".", ifa->vid, ospf_is[oldstate], ospf_is[state]); if (state == OSPF_IS_PTP) - { - ifa->sk = ospf_open_socket(ifa, 0); - } + ospf_sk_open(ifa, 0); + if (state == OSPF_IS_DOWN) + ospf_sk_close(ifa); } else { @@ -157,19 +205,10 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state) { if ((ifa->type != OSPF_IT_NBMA) && (ifa->ioprob == OSPF_I_OK) && ((state == OSPF_IS_BACKUP) || (state == OSPF_IS_DR))) - { - if (!ifa->dr_up == 0) - { - /* FIXME some error handing ? */ - sk_join_group(ifa->sk, AllDRouters); - ifa->dr_up = 1; - } - } - else if (ifa->dr_up) - { - sk_leave_group(ifa->sk, AllDRouters); - ifa->dr_up = 0; - } + ospf_sk_join_dr(ifa); + else + ospf_sk_leave_dr(ifa); + if ((oldstate == OSPF_IS_DR) && (ifa->net_lsa != NULL)) { ifa->net_lsa->lsa.age = LSA_MAXAGE; @@ -182,6 +221,7 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state) ifa->net_lsa = NULL; } } + // FIXME flushling of link LSA } } } @@ -194,13 +234,15 @@ ospf_iface_down(struct ospf_iface *ifa) struct proto *p = &po->proto; struct ospf_iface *iff; + OSPF_TRACE(D_EVENTS, "Removing interface %s", ifa->iface->name); + /* First of all kill all the related vlinks */ if (ifa->type != OSPF_IT_VLINK) { WALK_LIST(iff, po->iface_list) { if ((iff->type == OSPF_IT_VLINK) && (iff->iface == ifa->iface)) - ospf_iface_down(iff); + ospf_iface_sm(iff, ISM_DOWN); } } @@ -210,9 +252,6 @@ ospf_iface_down(struct ospf_iface *ifa) ospf_neigh_remove(n); } - rfree(ifa->sk); - ifa->sk = NULL; - if (ifa->type == OSPF_IT_VLINK) { ifa->iface = NULL; @@ -220,6 +259,7 @@ ospf_iface_down(struct ospf_iface *ifa) } else { + ospf_sk_close(ifa); rfree(ifa->wait_timer); rfree(ifa->hello_timer); rfree(ifa->poll_timer); @@ -294,18 +334,16 @@ ospf_iface_sm(struct ospf_iface *ifa, int event) case ISM_DOWN: ospf_iface_chstate(ifa, OSPF_IS_DOWN); ospf_iface_down(ifa); - schedule_link_lsa(ifa); schedule_rt_lsa(oa); break; - case ISM_LOOP: /* Useless? */ + /* + case ISM_LOOP: ospf_iface_chstate(ifa, OSPF_IS_LOOP); - ospf_iface_down(ifa); - schedule_rt_lsa(ifa->oa); break; case ISM_UNLOOP: ospf_iface_chstate(ifa, OSPF_IS_DOWN); - schedule_rt_lsa(ifa->oa); break; + */ default: bug("OSPF_I_SM - Unknown event?"); break; @@ -313,45 +351,6 @@ ospf_iface_sm(struct ospf_iface *ifa, int event) } -#if 0 -static sock * -ospf_open_mc_socket(struct ospf_iface *ifa) -{ - sock *mcsk; - struct proto *p = &ifa->oa->po->proto; - - mcsk = sk_new(p->pool); - mcsk->type = SK_IP_MC; - mcsk->sport = 0; - mcsk->dport = OSPF_PROTO; - -#ifdef OSPFv2 - mcsk->saddr = AllSPFRouters; -#else /* OSPFv3 */ - // mcsk->saddr = AllSPFRouters; - mcsk->saddr = ifa->lladdr; -#endif - - mcsk->daddr = AllSPFRouters; - mcsk->tos = IP_PREC_INTERNET_CONTROL; - mcsk->ttl = 1; - mcsk->rx_hook = ospf_rx_hook; - mcsk->tx_hook = ospf_tx_hook; - mcsk->err_hook = ospf_err_hook; - mcsk->iface = ifa->iface; - mcsk->rbsize = rxbufsize(ifa); - mcsk->tbsize = ifa->iface->mtu; - mcsk->data = (void *) ifa; - if (sk_open(mcsk) != 0) - { - DBG("%s: SK_OPEN: mc open failed.\n", p->name); - return (NULL); - } - DBG("%s: SK_OPEN: mc opened.\n", p->name); - return (mcsk); -} -#endif - u8 ospf_iface_clasify(struct iface * ifa) { @@ -390,12 +389,15 @@ ospf_iface_add(struct object_lock *lock) ifa->ioprob = OSPF_I_OK; - ifa->sk = ospf_open_socket(ifa, ifa->type != OSPF_IT_NBMA); - if (ifa->sk == NULL) + ospf_sk_open(ifa, 1); + if (ifa->type != OSPF_IT_NBMA) + ospf_sk_join_spf(ifa); + + if (0) { - log("%s: Huh? could not open ip socket on interface %s?", p->name, + log(L_ERR "%s: Huh? could not open ip socket on interface %s?", p->name, iface->name); - log("%s: Declaring as stub.", p->name); + log(L_ERR "%s: Declaring as stub.", p->name); ifa->stub = 1; ifa->ioprob += OSPF_I_IP; } @@ -414,6 +416,9 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface, struct object_lock *lock; struct ospf_area *oa; + if (ip->type != OSPF_IT_VLINK) + OSPF_TRACE(D_EVENTS, "Adding interface %s", iface->name); + ifa = mb_allocz(p->pool, sizeof(struct ospf_iface)); ifa->iface = iface; @@ -431,12 +436,13 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface, #ifdef OSPFv2 ifa->autype = ip->autype; ifa->passwords = ip->passwords; + ifa->addr = iface->addr; #endif #ifdef OSPFv3 ifa->instance_id = ip->instance_id; - ifa->lladdr = IPA_NONE; + ifa->addr = NULL; /* Find link-local address */ if (ifa->type != OSPF_IT_VLINK) @@ -445,11 +451,11 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface, WALK_LIST(a, iface->addrs) if (a->scope == SCOPE_LINK) { - ifa->lladdr = a->ip; + ifa->addr = a; break; } - if (! ipa_nonzero(ifa->lladdr)) + if (! ifa->addr) log(L_WARN "%s: Missing link local address on interface %s", p->name, iface->name); } #endif @@ -594,19 +600,13 @@ ospf_iface_notify(struct proto *p, unsigned flags, struct iface *iface) } if (ip) - { - OSPF_TRACE(D_EVENTS, "Using interface %s.", iface->name); ospf_iface_new(po, iface, ac, ip); - } } if (flags & IF_CHANGE_DOWN) { if ((ifa = ospf_iface_find((struct proto_ospf *) p, iface)) != NULL) - { - OSPF_TRACE(D_EVENTS, "Killing interface %s.", iface->name); ospf_iface_sm(ifa, ISM_DOWN); - } } if (flags & IF_CHANGE_MTU) @@ -666,4 +666,5 @@ ospf_iface_shutdown(struct ospf_iface *ifa) { init_list(&ifa->neigh_list); hello_timer_hook(ifa->hello_timer); + ospf_sk_close(ifa); } -- cgit v1.2.3 From e7b76b976084006e430543f4b872f624326dbfe6 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Thu, 11 Mar 2010 18:07:24 +0100 Subject: Temoporary OSPF commit - socket changes. --- proto/ospf/iface.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'proto/ospf/iface.c') diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index 3f1e74d..a99ceb1 100644 --- a/proto/ospf/iface.c +++ b/proto/ospf/iface.c @@ -82,9 +82,6 @@ ospf_sk_open(struct ospf_iface *ifa, int mc) #endif sk->tos = IP_PREC_INTERNET_CONTROL; - sk->ttl = 1; - if (ifa->type == OSPF_IT_VLINK) - sk->ttl = 255; sk->rx_hook = ospf_rx_hook; sk->tx_hook = ospf_tx_hook; sk->err_hook = ospf_err_hook; @@ -191,10 +188,12 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state) OSPF_TRACE(D_EVENTS, "Changing state of virtual link %R from \"%s\" into \"%s\".", 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 { -- cgit v1.2.3 From 0aad2b9292f8e5ff32d048378faf80d2d0bfbb80 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Sun, 14 Mar 2010 16:36:59 +0100 Subject: Temporary OSPF commit - sockets. --- proto/ospf/iface.c | 276 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 212 insertions(+), 64 deletions(-) (limited to 'proto/ospf/iface.c') diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index a99ceb1..987698e 100644 --- a/proto/ospf/iface.c +++ b/proto/ospf/iface.c @@ -21,7 +21,6 @@ char *ospf_it[] = { "broadcast", "nbma", "point-to-point", "virtual link" }; static void poll_timer_hook(timer * timer) { - log("POLL!"); ospf_hello_send(timer, 1, NULL); } @@ -59,7 +58,7 @@ rxbufsize(struct ospf_iface *ifa) } static int -ospf_sk_open(struct ospf_iface *ifa, int mc) +ospf_sk_open(struct ospf_iface *ifa) { sock *sk; 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 * that the socket does not receive multicast packets, as they have * 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 */ sk->saddr = ifa->addr->ip; /* link-local addr */ #endif @@ -100,7 +97,8 @@ ospf_sk_open(struct ospf_iface *ifa, int mc) goto err; #endif - if (mc && (sk_setup_multicast(sk) < 0)) + sk->saddr = ifa->addr->ip; + if (sk_setup_multicast(sk) < 0) goto err; ifa->sk = sk; @@ -188,12 +186,6 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state) OSPF_TRACE(D_EVENTS, "Changing state of virtual link %R from \"%s\" into \"%s\".", 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 { @@ -240,7 +232,7 @@ ospf_iface_down(struct ospf_iface *ifa) { 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); } } @@ -253,7 +245,11 @@ ospf_iface_down(struct ospf_iface *ifa) if (ifa->type == OSPF_IT_VLINK) { + ifa->vifa = NULL; ifa->iface = NULL; + ifa->addr = NULL; + ifa->sk = NULL; + ifa->vip = IPA_NONE; return; } else @@ -351,9 +347,9 @@ ospf_iface_sm(struct ospf_iface *ifa, int event) } 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; 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 proto_ospf *po = ifa->oa->po; struct proto *p = &po->proto; - struct iface *iface = lock->iface; ifa->lock = lock; - ifa->ioprob = OSPF_I_OK; - - ospf_sk_open(ifa, 1); - if (ifa->type != OSPF_IT_NBMA) - ospf_sk_join_spf(ifa); - - if (0) + if (ospf_sk_open(ifa)) { - log(L_ERR "%s: Huh? could not open ip socket on interface %s?", p->name, - iface->name); - log(L_ERR "%s: Declaring as stub.", p->name); + if (ifa->type != OSPF_IT_NBMA) + ospf_sk_join_spf(ifa); + } + 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->ioprob += OSPF_I_IP; } ifa->state = OSPF_IS_DOWN; @@ -406,7 +398,7 @@ ospf_iface_add(struct object_lock *lock) } 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 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->iface = iface; + ifa->addr = addr; ifa->cost = ip->cost; ifa->rxmtint = ip->rxmtint; @@ -431,44 +424,47 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface, ifa->waitint = ip->waitint; ifa->dead = (ip->dead == 0) ? ip->deadc * ifa->helloint : ip->dead; ifa->stub = ip->stub; + ifa->ioprob = OSPF_I_OK; + ifa->rxbuf = ip->rxbuf; #ifdef OSPFv2 ifa->autype = ip->autype; ifa->passwords = ip->passwords; - ifa->addr = iface->addr; #endif #ifdef OSPFv3 ifa->instance_id = ip->instance_id; - ifa->addr = NULL; - - /* Find link-local address */ + /* + addr = NULL; if (ifa->type != OSPF_IT_VLINK) { struct ifa *a; WALK_LIST(a, iface->addrs) if (a->scope == SCOPE_LINK) { - ifa->addr = a; + addr = a; break; } - if (! ifa->addr) - log(L_WARN "%s: Missing link local address on interface %s", p->name, iface->name); + if (!addr) + { + 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 - ifa->rxbuf = ip->rxbuf; - if (ip->type == OSPF_IT_UNDEF) - ifa->type = ospf_iface_clasify(ifa->iface); + ifa->type = ospf_iface_clasify(iface, addr); else ifa->type = ip->type; #ifdef OSPFv2 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", 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 */ } + /* + * 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->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->port = OSPF_PROTO; lock->iface = iface; @@ -549,6 +556,150 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface, 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 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) { 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); if (iface->flags & IF_IGNORE) 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 ((ifa = ospf_iface_find((struct proto_ospf *) p, iface)) != NULL) - ospf_iface_sm(ifa, ISM_DOWN); + struct ospf_iface *ifa, *ifx; + 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 ((ifa = ospf_iface_find((struct proto_ospf *) p, iface)) != NULL) - ospf_iface_change_mtu(po, ifa); + struct ospf_iface *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 { - cli_msg(-1015, "Interface \"%s\":", - (ifa->iface ? ifa->iface->name : "(none)")); +#ifdef OSPFv2 + 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, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid); } -- cgit v1.2.3 From af157fa3dbe2bba0674eb7634efd3ade6c89d604 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Fri, 26 Mar 2010 14:48:01 +0100 Subject: Disable multiple OSPF pseudointerfaces on BSD. --- proto/ospf/iface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'proto/ospf/iface.c') diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index 987698e..b30a811 100644 --- a/proto/ospf/iface.c +++ b/proto/ospf/iface.c @@ -423,7 +423,7 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface, struct ifa *addr, ifa->strictnbma = ip->strictnbma; ifa->waitint = ip->waitint; ifa->dead = (ip->dead == 0) ? ip->deadc * ifa->helloint : ip->dead; - ifa->stub = ip->stub; + ifa->stub = ospf_iface_stubby(ip, addr); ifa->ioprob = OSPF_I_OK; ifa->rxbuf = ip->rxbuf; -- cgit v1.2.3 From 48cff379a718998cd984d60fb6f8b48cb961c0f1 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Fri, 26 Mar 2010 16:21:29 +0100 Subject: Added some comments. --- proto/ospf/iface.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'proto/ospf/iface.c') diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index b30a811..83d591b 100644 --- a/proto/ospf/iface.c +++ b/proto/ospf/iface.c @@ -97,6 +97,27 @@ ospf_sk_open(struct ospf_iface *ifa) goto err; #endif + /* + * For OSPFv2: When sending a packet, it is important to have a + * proper source address. We expect that when we send one-hop + * unicast packets, OS chooses a source address according to the + * destination address (to be in the same prefix). We also expect + * that when we send multicast packets, OS uses the source address + * from sk->saddr registered to OS by sk_setup_multicast(). This + * behavior is needed to implement multiple virtual ifaces (struct + * ospf_iface) on one physical iface and is signalized by + * CONFIG_MC_PROPER_SRC. + * + * If this behavior is not available (for example on BSD), we create + * non-stub iface just for the primary IP address (see + * ospf_iface_stubby()) and we expect OS to use primary IP address + * as a source address for both unicast and multicast packets. + * + * FIXME: the primary IP address is currently just the + * lexicographically smallest address on an interface, it should be + * signalized by sysdep code which one is really the primary. + */ + sk->saddr = ifa->addr->ip; if (sk_setup_multicast(sk) < 0) goto err; -- cgit v1.2.3