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/hello.c | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) (limited to 'proto/ospf/hello.c') diff --git a/proto/ospf/hello.c b/proto/ospf/hello.c index 738748d8..eaf7d230 100644 --- a/proto/ospf/hello.c +++ b/proto/ospf/hello.c @@ -47,7 +47,7 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa, { struct proto_ospf *po = ifa->oa->po; struct proto *p = &po->proto; - char *beg = "Bad OSPF HELLO packet from ", *rec = " received: "; + char *beg = "OSPF: Bad HELLO packet from "; unsigned int size, i, twoway, oldpriority, eligible, peers; u32 olddr, oldbdr, oldiface_id, tmp; u32 *pnrid; @@ -55,7 +55,7 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa, size = ntohs(ps_i->length); if (size < sizeof(struct ospf_hello_packet)) { - log(L_ERR "%s%I - too short (%u B)", beg, faddr, size); + log(L_ERR "%s%I - too short (%u B)", beg, faddr, size); return; } @@ -67,38 +67,19 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa, #ifdef OSPFv2 ip_addr mask = ps->netmask; ipa_ntoh(mask); - if (ifa->type != OSPF_IT_VLINK) - { - char *msg = L_WARN "Received HELLO packet %s (%I) is inconsistent " - "with the primary address of interface %s."; - - if ((ifa->type != OSPF_IT_PTP) && - !ipa_equal(mask, ipa_mkmask(ifa->iface->addr->pxlen))) - { - if (!n) log(msg, "netmask", mask, ifa->iface->name); - return; - } - - /* This check is not specified in RFC 2328, but it is needed - * to handle the case when there is more IP networks on one - * physical network (which is not handled in RFC 2328). - * We allow OSPF on primary IP address only and ignore HELLO packets - * with secondary addresses (which are sent for example by Quagga. - */ - if ((ifa->iface->addr->flags & IA_UNNUMBERED) ? - !ipa_equal(faddr, ifa->iface->addr->opposite) : - !ipa_equal(ipa_and(faddr,mask), ifa->iface->addr->prefix)) - { - if (!n) log(msg, "address", faddr, ifa->iface->name); - return; - } - } + if ((ifa->type != OSPF_IT_VLINK) && + (ifa->type != OSPF_IT_PTP) && + !ipa_equal(mask, ipa_mkmask(ifa->addr->pxlen))) + { + log(L_ERR "%s%I - netmask mismatch (%I)", beg, faddr, mask); + return; + } #endif tmp = ntohs(ps->helloint); if (tmp != ifa->helloint) { - log(L_ERR "%s%I%shello interval mismatch (%d).", beg, faddr, rec, tmp); + log(L_ERR "%s%I - hello interval mismatch (%d)", beg, faddr, tmp); return; } @@ -109,14 +90,14 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa, #endif if (tmp != ifa->dead) { - log(L_ERR "%s%I%sdead interval mismatch (%d).", beg, faddr, rec, tmp); + log(L_ERR "%s%I - dead interval mismatch (%d)", beg, faddr, tmp); return; } tmp = !(ps->options & OPT_E); if (tmp != ifa->oa->stub) { - log(L_ERR "%s%I%sstub area flag mismatch (%d).", beg, faddr, rec, tmp); + log(L_ERR "%s%I - stub area flag mismatch (%d)", beg, faddr, tmp); return; } @@ -137,7 +118,7 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa, } if ((found == 0) && (ifa->strictnbma)) { - log(L_WARN "Ignoring new neighbor: %I on %s.", faddr, + log(L_WARN "Ignoring new neighbor: %I on %s", faddr, ifa->iface->name); return; } @@ -153,7 +134,7 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa, } } } - OSPF_TRACE(D_EVENTS, "New neighbor found: %I on %s.", faddr, + OSPF_TRACE(D_EVENTS, "New neighbor found: %I on %s", faddr, ifa->iface->name); n = ospf_neighbor_new(ifa); @@ -277,14 +258,14 @@ ospf_hello_send(timer *timer, int poll, struct ospf_neighbor *dirn) p->name, ifa->iface->name); /* Now we should send a hello packet */ - pkt = (struct ospf_hello_packet *) (ifa->sk->tbuf); - op = (struct ospf_packet *) pkt; + pkt = ospf_tx_buffer(); + op = &pkt->ospf_packet; /* Now fill ospf_hello header */ ospf_pkt_fill_hdr(ifa, pkt, HELLO_P); #ifdef OSPFv2 - pkt->netmask = ipa_mkmask(ifa->iface->addr->pxlen); + pkt->netmask = ipa_mkmask(ifa->addr->pxlen); ipa_hton(pkt->netmask); if ((ifa->type == OSPF_IT_VLINK) || (ifa->type == OSPF_IT_PTP)) pkt->netmask = IPA_NONE; -- 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. --- nest/iface.h | 9 +++ proto/ospf/dbdes.c | 4 +- proto/ospf/hello.c | 2 +- proto/ospf/iface.c | 5 +- proto/ospf/lsack.c | 2 +- proto/ospf/lsreq.c | 2 +- proto/ospf/lsupd.c | 4 +- proto/ospf/packet.c | 161 +++++++++++++++++++++++++++++++--------------------- proto/ospf/packet.h | 2 +- 9 files changed, 114 insertions(+), 77 deletions(-) (limited to 'proto/ospf/hello.c') diff --git a/nest/iface.h b/nest/iface.h index a982c17f..b7c3c19c 100644 --- a/nest/iface.h +++ b/nest/iface.h @@ -82,6 +82,15 @@ struct iface *if_find_by_index(unsigned); struct iface *if_find_by_name(char *); void ifa_recalc_all_primary_addresses(void); +static inline int +ifa_match_addr(struct ifa *ifa, ip_addr addr) +{ + if (ifa->flags & IA_UNNUMBERED) + return ipa_equal(addr, ifa->opposite); + else + return ipa_in_net(addr, ifa->prefix, ifa->pxlen); +} + /* The Neighbor Cache */ typedef struct neighbor { diff --git a/proto/ospf/dbdes.c b/proto/ospf/dbdes.c index 9f126821..8cd7c8b2 100644 --- a/proto/ospf/dbdes.c +++ b/proto/ospf/dbdes.c @@ -93,7 +93,7 @@ ospf_dbdes_send(struct ospf_neighbor *n, int next) { case NEIGHBOR_EXSTART: /* Send empty packets */ n->myimms.bit.i = 1; - pkt = ospf_tx_buffer(); + pkt = ospf_tx_buffer(ifa); op = &pkt->ospf_packet; ospf_pkt_fill_hdr(ifa, pkt, DBDES_P); pkt->iface_mtu = htons(ifa->iface->mtu); @@ -185,7 +185,7 @@ ospf_dbdes_send(struct ospf_neighbor *n, int next) } /* Copy last sent packet again */ - pkt = ospf_tx_buffer(); + pkt = ospf_tx_buffer(ifa); memcpy(pkt, n->ldbdes, length); OSPF_PACKET(ospf_dump_dbdes, pkt, "DBDES packet sent to %I via %s", n->ip, ifa->iface->name); diff --git a/proto/ospf/hello.c b/proto/ospf/hello.c index eaf7d230..9f174df8 100644 --- a/proto/ospf/hello.c +++ b/proto/ospf/hello.c @@ -258,7 +258,7 @@ ospf_hello_send(timer *timer, int poll, struct ospf_neighbor *dirn) p->name, ifa->iface->name); /* Now we should send a hello packet */ - pkt = ospf_tx_buffer(); + pkt = ospf_tx_buffer(ifa); op = &pkt->ospf_packet; /* Now fill ospf_hello header */ diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index 3f1e74dc..a99ceb12 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 { diff --git a/proto/ospf/lsack.c b/proto/ospf/lsack.c index 73d79a27..c05f0196 100644 --- a/proto/ospf/lsack.c +++ b/proto/ospf/lsack.c @@ -66,7 +66,7 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue) if (EMPTY_LIST(n->ackl[queue])) return; - pk = ospf_tx_buffer(); + pk = ospf_tx_buffer(ifa); op = &pk->ospf_packet; ospf_pkt_fill_hdr(n->ifa, pk, LSACK_P); diff --git a/proto/ospf/lsreq.c b/proto/ospf/lsreq.c index b61e0ce5..1ba4fff9 100644 --- a/proto/ospf/lsreq.c +++ b/proto/ospf/lsreq.c @@ -44,7 +44,7 @@ ospf_lsreq_send(struct ospf_neighbor *n) int i, j; struct proto *p = &n->ifa->oa->po->proto; - pk = ospf_tx_buffer(); + pk = ospf_tx_buffer(n->ifa); op = &pk->ospf_packet; ospf_pkt_fill_hdr(n->ifa, pk, LSREQ_P); diff --git a/proto/ospf/lsupd.c b/proto/ospf/lsupd.c index 133a036d..39d91b9a 100644 --- a/proto/ospf/lsupd.c +++ b/proto/ospf/lsupd.c @@ -269,7 +269,7 @@ ospf_lsupd_flood(struct proto_ospf *po, struct ospf_packet *op; struct ospf_lsa_header *lh; - pk = ospf_tx_buffer(); + pk = ospf_tx_buffer(ifa); op = &pk->ospf_packet; ospf_pkt_fill_hdr(ifa, pk, LSUPD_P); @@ -350,7 +350,7 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l) DBG("LSupd: 1st packet\n"); - pk= ospf_tx_buffer(); + pk= ospf_tx_buffer(n->ifa); op = &pk->ospf_packet; ospf_pkt_fill_hdr(n->ifa, pk, LSUPD_P); diff --git a/proto/ospf/packet.c b/proto/ospf/packet.c index 81686d25..6697057b 100644 --- a/proto/ospf/packet.c +++ b/proto/ospf/packet.c @@ -255,55 +255,6 @@ ospf_pkt_checkauth(struct ospf_neighbor *n, struct ospf_iface *ifa, struct ospf_ #endif -static struct ospf_iface * -find_matching_iface(struct ospf_packet *ps, unsigned ifindex, ip_addr faddr) -{ - u32 areaid = ntohl(ps->areaid); - u32 rid = ntohl(ps->routerid); - node *nd; - - /* First, we will try to match real ifaces */ - - WALK_LIST(nd, ospf_ifaces) - { - struct ospf_iface *ifa = SKIP_BACK(struct ospf_iface, sk_node, nd); - struct ifa *addr = ifa->addr; - - if ((ifa->iface->index == ifindex) && - (ifa->oa->areaid == areaid) && -#ifdef OSPFv2 - ((addr->flags & IA_UNNUMBERED) ? - ipa_equal(faddr, addr->opposite) : - ipa_in_net(faddr, addr->prefix, addr->pxlen)) -#else /* OSPFv3 */ - (ifa->instance_id == ps->instance_id) -#endif - ) - return ifa; - } - - /* Second, we will try to match vlinks */ - - if (areaid != 0) - return NULL; - - /* FIXME: There should be some more checks to distinquish parallel - vlinks to the same ABR. */ - - WALK_LIST(nd, ospf_vlinks) - { - struct ospf_iface *ifa = SKIP_BACK(struct ospf_iface, sk_node, nd); - - if ((ifa->vid == rid) -#ifdef OSPFv3 - && (ifa->instance_id == ps->instance_id) -#endif - ) - return ifa; - } - - return NULL; -} /** * ospf_rx_hook @@ -319,9 +270,47 @@ ospf_rx_hook(sock *sk, int size) { char *mesg = "OSPF: Bad packet from "; - DBG("OSPF: RX_Hook called (from %I)\n", sk->faddr); + /* We want just packets from sk->iface. Unfortunately, on BSD we + cannot filter out other packets at kernel level and we receive + all packets on all sockets */ + if (sk->lifindex != sk->iface->index) + return 1; + + DBG("OSPF: RX hook called (iface %s, src %I, dst %I)\n", + sk->iface->name, sk->faddr, sk->laddr); + + /* Initially, the packet is associated with the 'master' iface */ + struct ospf_iface *ifa = sk->data; + struct proto_ospf *po = ifa->oa->po; + struct proto *p = &po->proto; + + int src_local = ifa_match_addr(ifa->addr, sk->faddr); + int dst_local = ipa_equal(sk->laddr, ifa->addr->ip); + int dst_mcast = ipa_equal(sk->laddr, AllSPFRouters) || ipa_equal(sk->laddr, AllDRouters); + +#ifdef OSPFv2 + /* First, we eliminate packets with strange address combinations. + * In OSPFv2, they might be for other ospf_ifaces (with different IP + * prefix) on the same real iface, so we don't log it. We enforce + * that (src_local || dst_local), therefore we are eliminating all + * such cases. + */ + if (dst_mcast && !src_local) + return 1; + if (!dst_mcast && !dst_local) + return 1; - /* First, we check packet size, checksum, and the protocol version */ +#else /* OSPFv3 */ + + /* In OSPFv3, src_local and dst_local mean link-local. + * RFC 5340 says that local (non-vlink) packets use + * link-local src address, but does not enforce it. Strange. + */ + if (dst_mcast && !src_local) + log(L_WARN "OSPF: Received multicast packet from %I (not link-local)", sk->faddr); +#endif + + /* Second, we check packet size, checksum, and the protocol version */ struct ospf_packet *ps = (struct ospf_packet *) ip_skip_header(sk->rbuf, &size); if (ps == NULL) @@ -366,38 +355,78 @@ ospf_rx_hook(sock *sk, int size) #endif - /* Now, we would like to associate the packet with an OSPF iface */ - struct ospf_iface *ifa = find_matching_iface(ps, sk->lifindex, sk->faddr); - if (ifa == NULL) + /* Third, we resolve associated iface and handle vlinks. */ + + u32 areaid = ntohl(ps->areaid); + u32 rid = ntohl(ps->routerid); + + if ((areaid == ifa->oa->areaid) +#ifdef OSPFv3 + && (ps->instance_id != ifa->instance_id) +#endif + ) + { + /* It is real iface, source should be local (in OSPFv2) */ +#ifdef OSPFv2 + if (!src_local) + return 1; +#endif + } + else if (dst_mcast || (areaid != 0)) + { + /* Obvious mismatch */ + +#ifdef OSPFv2 + /* We ignore mismatch in OSPFv3, because there might be + other instance with different instance ID */ + log(L_ERR "%s%I - area does not match (%R vs %R)", + mesg, sk->faddr, areaid, ifa->oa->areaid); +#endif + return 1; + } + else { - /* We limit logging of unmatched packets as it may be perfectly OK */ - if (unmatched_count < 8) + /* Some vlink? */ + struct ospf_iface *iff = NULL; + + WALK_LIST(iff, po->iface_list) { - struct iface *ifc = if_find_by_index(sk->lifindex); - log(L_WARN "OSPF: Received unmatched packet (src %I, iface %s, rtid %R, area %R)", - sk->faddr, ifc ? ifc->name : "?", ntohl(ps->routerid), ntohl(ps->areaid)); - unmatched_count++; + if ((iff->type == OSPF_IT_VLINK) && + (iff->voa == ifa->oa) && +#ifdef OSPFv3 + (iff->instance_id == ps->instance_id) && +#endif + (iff->vid == rid)) + { + /* Vlink should be UP */ + if (iff->state != OSPF_IS_PTP) + return 1; + + ifa = iff; + goto found; + } } +#ifdef OSPFv2 + log(L_WARN "OSPF: Received packet for uknown vlink (ID %R, IP %I)", rid, sk->faddr); +#endif return 1; } - struct proto_ospf *po = ifa->oa->po; - struct proto *p = &po->proto; - + found: if (ifa->stub) /* This shouldn't happen */ return 1; if (ipa_equal(sk->laddr, AllDRouters) && (ifa->sk_dr == 0)) return 1; - if (ntohl(ps->routerid) == po->router_id) + if (rid == po->router_id) { log(L_ERR "%s%I - received my own router ID!", mesg, sk->faddr); return 1; } - if (ntohl(ps->routerid) == 0) + if (rid == 0) { log(L_ERR "%s%I - router id = 0.0.0.0", mesg, sk->faddr); return 1; @@ -406,7 +435,7 @@ ospf_rx_hook(sock *sk, int size) /* This is deviation from RFC 2328 - neighbours should be identified by * IP address on broadcast and NBMA networks. */ - struct ospf_neighbor *n = find_neigh(ifa, ntohl(ps->routerid)); + struct ospf_neighbor *n = find_neigh(ifa, rid); if(!n && (ps->type != HELLO_P)) { diff --git a/proto/ospf/packet.h b/proto/ospf/packet.h index 053aba3b..1c74a703 100644 --- a/proto/ospf/packet.h +++ b/proto/ospf/packet.h @@ -19,6 +19,6 @@ void ospf_send_to_agt(struct ospf_iface *ifa, u8 state); void ospf_send_to_bdr(struct ospf_iface *ifa); void ospf_send_to(struct ospf_iface *ifa, ip_addr ip); -static inline void * ospf_tx_buffer() { return ospf_socket->tbuf; } +static inline void * ospf_tx_buffer(struct ospf_iface *ifa) { return ifa->sk->tbuf; } #endif /* _BIRD_OSPF_PACKET_H_ */ -- 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. --- nest/iface.c | 11 +- nest/iface.h | 3 +- nest/rt-dev.c | 2 +- proto/ospf/hello.c | 4 +- proto/ospf/iface.c | 276 ++++++++++++++++++++++++++++++++++++++------------ proto/ospf/iface.h | 3 +- proto/ospf/ospf.c | 37 ++----- proto/ospf/ospf.h | 9 +- proto/ospf/rt.c | 6 +- proto/ospf/topology.c | 31 +++--- proto/rip/rip.c | 4 +- sysdep/linux/sysio.h | 18 ++-- 12 files changed, 268 insertions(+), 136 deletions(-) (limited to 'proto/ospf/hello.c') diff --git a/nest/iface.c b/nest/iface.c index 82dead35..a80e9736 100644 --- a/nest/iface.c +++ b/nest/iface.c @@ -566,8 +566,8 @@ if_init(void) * Interface Pattern Lists */ -static int -iface_patt_match(struct iface_patt *ifp, struct iface *i) +int +iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a) { struct iface_patt_node *p; @@ -588,8 +588,9 @@ iface_patt_match(struct iface_patt *ifp, struct iface *i) continue; } + // FIXME there should be check for prefix in prefix. (?) 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; return pos; @@ -599,12 +600,12 @@ iface_patt_match(struct iface_patt *ifp, struct iface *i) } 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; WALK_LIST(p, *l) - if (iface_patt_match(p, i)) + if (iface_patt_match(p, i, a)) return p; return NULL; diff --git a/nest/iface.h b/nest/iface.h index 873734d8..c116db8b 100644 --- a/nest/iface.h +++ b/nest/iface.h @@ -144,7 +144,8 @@ struct iface_patt { /* 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 *)); #endif diff --git a/nest/rt-dev.c b/nest/rt-dev.c index bb8eb8ee..239bd268 100644 --- a/nest/rt-dev.c +++ b/nest/rt-dev.c @@ -30,7 +30,7 @@ dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad) struct rt_dev_config *P = (void *) p->cf; 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 "*" */ return; diff --git a/proto/ospf/hello.c b/proto/ospf/hello.c index 7fe82801..fedc5236 100644 --- a/proto/ospf/hello.c +++ b/proto/ospf/hello.c @@ -254,8 +254,8 @@ ospf_hello_send(timer *timer, int poll, struct ospf_neighbor *dirn) return; /* Don't send any packet on stub iface */ p = (struct proto *) (ifa->oa->po); - DBG("%s: Hello/Poll timer fired on interface %s.\n", - p->name, ifa->iface->name); + DBG("%s: Hello/Poll timer fired on interface %s with IP %I\n", + p->name, ifa->iface->name, ifa->addr->ip); /* Now we should send a hello packet */ pkt = ospf_tx_buffer(ifa); diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index a99ceb12..987698e7 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); } diff --git a/proto/ospf/iface.h b/proto/ospf/iface.h index 55c64bf7..05f3e46e 100644 --- a/proto/ospf/iface.h +++ b/proto/ospf/iface.h @@ -14,9 +14,10 @@ void ospf_iface_chstate(struct ospf_iface *ifa, u8 state); void ospf_iface_sm(struct ospf_iface *ifa, int event); 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_ifa_notify(struct proto *p, unsigned flags, struct ifa *a); void ospf_iface_info(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_set_rxbuf_size(struct ospf_iface *ifa, u32 rxbuf); diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c index e2a3aed0..e77156b7 100644 --- a/proto/ospf/ospf.c +++ b/proto/ospf/ospf.c @@ -79,7 +79,6 @@ 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_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_same(struct rte *new, struct rte *old); static void ospf_disp(timer *timer); @@ -196,7 +195,7 @@ ospf_start(struct proto *p) oa->options = OPT_R | OPT_E | OPT_V6; #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); } -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 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) { + /* FIXME: better handling of vlinks */ + if (ifa->iface == NULL) + continue; + + /* FIXME: better matching of interface_id in OSPFv3 */ 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 */ 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; /* HELLO TIMER */ @@ -785,9 +768,7 @@ ospf_reconfigure(struct proto *p, struct proto_config *c) ifa->stub = newip->stub; OSPF_TRACE(D_EVENTS, "Interface %s is now stub.", ifa->iface->name); } - if ((oldip->stub != 0) && (newip->stub == 0) && - ((ifa->ioprob & OSPF_I_IP) == 0) && - (((ifa->ioprob & OSPF_I_MC) == 0) || (ifa->type == OSPF_IT_NBMA))) + if ((oldip->stub != 0) && (newip->stub == 0) && (ifa->ioprob == OSPF_I_OK)) { ifa->stub = newip->stub; OSPF_TRACE(D_EVENTS, diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h index cb4f53c1..9e02d758 100644 --- a/proto/ospf/ospf.h +++ b/proto/ospf/ospf.h @@ -171,7 +171,8 @@ struct ospf_iface u32 dead; /* after "deadint" missing hellos is router dead */ u32 vid; /* Id 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 transmit a Link State Update Packet over this interface. LSAs contained in the update */ @@ -203,9 +204,6 @@ struct ospf_iface #define OSPF_IT_UNDEF 4 u8 strictnbma; /* Can I talk with unknown neighbors? */ 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 */ #define OSPF_IS_DOWN 0 /* Not working */ #define OSPF_IS_LOOP 1 /* Should never happen */ @@ -239,6 +237,9 @@ struct ospf_iface list nbma_list; u8 priority; /* A router priority for DR election */ 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_dr; /* Socket is a member of DRouters group */ u32 rxbuf; diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index 9a330a83..b589459b 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -424,12 +424,14 @@ ospf_rt_spfa(struct ospf_area *oa) if ((tmp = ospf_hash_find_rt(po->gr, oa->areaid, iface->vid)) && (!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_iface_sm(iface, ISM_DOWN); + iface->vifa = tmp->nhi; iface->iface = tmp->nhi->iface; - iface->addr = iface->iface->addr; + iface->addr = tmp->nhi->addr; + iface->sk = tmp->nhi->sk; iface->vip = tmp->lb; ospf_iface_sm(iface, ISM_UP); } diff --git a/proto/ospf/topology.c b/proto/ospf/topology.c index bff9b2e8..885c39ba 100644 --- a/proto/ospf/topology.c +++ b/proto/ospf/topology.c @@ -272,24 +272,20 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length) break; } - /* Now we will originate stub areas for interfaces addresses */ - struct ifa *a; - WALK_LIST(a, ifa->iface->addrs) - { - if (((a == ifa->addr) && net_lsa) || - (a->flags & IA_SECONDARY) || - (a->flags & IA_UNNUMBERED) || - configured_stubnet(oa, a)) - continue; + /* Now we will originate stub area if there is no primary */ + if (net_lsa || + (ifa->type == OSPF_IT_VLINK) || + (ifa->addr->flags & IA_UNNUMBERED) || + configured_stubnet(oa, ifa->addr)) + continue; - ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link)); - ln->type = LSART_STUB; - ln->id = ipa_to_u32(a->prefix); - ln->data = ipa_to_u32(ipa_mkmask(a->pxlen)); - ln->metric = ifa->cost; - ln->padding = 0; - i++; - } + ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link)); + ln->type = LSART_STUB; + ln->id = ipa_to_u32(ifa->addr->prefix); + ln->data = ipa_to_u32(ipa_mkmask(ifa->addr->pxlen)); + ln->metric = ifa->cost; + ln->padding = 0; + i++; } 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 size = sizeof(struct ospf_lsa_ext); + // FIXME check for gw should be per ifa, not per iface if ((e->attrs->dest == RTD_ROUTER) && !ipa_equal(e->attrs->gw, IPA_NONE) && !ipa_has_link_scope(e->attrs->gw) && diff --git a/proto/rip/rip.c b/proto/rip/rip.c index 3b95a3ed..0e5320c8 100644 --- a/proto/rip/rip.c +++ b/proto/rip/rip.c @@ -761,7 +761,7 @@ rip_real_if_add(struct object_lock *lock) struct iface *iface = lock->iface; struct proto *p = lock->data; 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) 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) { - 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 rip_patt *PATT = (struct rip_patt *) k; diff --git a/sysdep/linux/sysio.h b/sysdep/linux/sysio.h index 94be002f..91cbdcd8 100644 --- a/sysdep/linux/sysio.h +++ b/sysdep/linux/sysio.h @@ -62,18 +62,18 @@ get_inaddr(ip_addr *a, struct in_addr *ia) #define MREQ_IFA struct in_addr #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)); #ifdef CONFIG_LINUX_MC_MREQ_BIND m->imr_interface.s_addr = INADDR_ANY; #else - set_inaddr(&m->imr_interface, ifa->addr->ip); + set_inaddr(&m->imr_interface, saddr); #endif set_inaddr(&m->imr_multiaddr, maddr); } @@ -101,11 +101,11 @@ struct ip_mreqn #define fill_mreq_ifa 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)); 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); } #endif @@ -123,7 +123,7 @@ sysio_setup_multicast(sock *s) return "IP_MULTICAST_TTL"; /* 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) return "IP_MULTICAST_IF"; @@ -145,7 +145,7 @@ sysio_join_group(sock *s, ip_addr maddr) MREQ_GRP m; /* 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) return "IP_ADD_MEMBERSHIP"; @@ -158,7 +158,7 @@ sysio_leave_group(sock *s, ip_addr maddr) MREQ_GRP m; /* 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) return "IP_DROP_MEMBERSHIP"; -- cgit v1.2.3