From 3fb9cd6ef456959b6eff939d5c316f6785c2dda4 Mon Sep 17 00:00:00 2001 From: hasso Date: Tue, 19 Oct 2004 19:44:43 +0000 Subject: OK. Here it is - PtP patch from Andrew J. Schorr. No problems with ospfd, ripd might need some more testing though. --- zebra/ChangeLog | 12 ++++++++++++ zebra/connected.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- zebra/interface.c | 6 ++---- zebra/rt_netlink.c | 4 +++- 4 files changed, 61 insertions(+), 7 deletions(-) (limited to 'zebra') diff --git a/zebra/ChangeLog b/zebra/ChangeLog index 506e3ae3..e3774706 100644 --- a/zebra/ChangeLog +++ b/zebra/ChangeLog @@ -1,3 +1,15 @@ +2004-10-19 Andrew J. Schorr + + * rt_netlink.c: (netlink_interface_addr) For PtP interfaces, ignore + tb[IFA_ADDRESS] if it's the same as tb[IFA_LOCAL]. + * interface.c: (ip_address_install) Use new ipv4_broadcast_addr + function. + * connected.c: (connected_up_ipv4) Use CONNECTED_POINTOPOINT_HOST + macro. + (connected_down_ipv4) ditto. + (connected_add_ipv4) Validate destination address, print warnings + if it does not make sense. + 2004-10-19 Hasso Tepper * zserv.c: Fix regression introduced with zserv cleanup. diff --git a/zebra/connected.c b/zebra/connected.c index a043ef48..9a6fd669 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -70,7 +70,7 @@ connected_up_ipv4 (struct interface *ifp, struct connected *ifc) p.prefixlen = addr->prefixlen; /* Point-to-point check. */ - if (if_is_pointopoint (ifp) && dest) + if (CONNECTED_POINTOPOINT_HOST(ifc)) p.prefix = dest->prefix; else p.prefix = addr->prefix; @@ -116,7 +116,49 @@ connected_add_ipv4 (struct interface *ifp, int flags, struct in_addr *addr, p->family = AF_INET; p->prefix = *broad; ifc->destination = (struct prefix *) p; + + /* validate the destination address */ + if (ifp->flags & IFF_POINTOPOINT) + { + if (IPV4_ADDR_SAME(addr,broad)) + zlog_warn("warning: PtP interface %s has same local and peer " + "address %s, routing protocols may malfunction", + ifp->name,inet_ntoa(*addr)); + else if ((prefixlen != IPV4_MAX_PREFIXLEN) && + (ipv4_network_addr(addr->s_addr,prefixlen) != + ipv4_network_addr(broad->s_addr,prefixlen))) + { + char buf[2][INET_ADDRSTRLEN]; + zlog_warn("warning: PtP interface %s network mismatch: local " + "%s/%d vs. peer %s, routing protocols may malfunction", + ifp->name, + inet_ntop (AF_INET, addr, buf[0], sizeof(buf[0])), + prefixlen, + inet_ntop (AF_INET, broad, buf[1], sizeof(buf[1]))); + } + } + else + { + if (broad->s_addr != ipv4_broadcast_addr(addr->s_addr,prefixlen)) + { + char buf[2][INET_ADDRSTRLEN]; + struct in_addr bcalc; + bcalc.s_addr = ipv4_broadcast_addr(addr->s_addr,prefixlen); + zlog_warn("warning: interface %s broadcast addr %s/%d != " + "calculated %s, routing protocols may malfunction", + ifp->name, + inet_ntop (AF_INET, broad, buf[0], sizeof(buf[0])), + prefixlen, + inet_ntop (AF_INET, &bcalc, buf[1], sizeof(buf[1]))); + } + } + } + else + /* no broadcast or destination address was supplied */ + if (prefixlen == IPV4_MAX_PREFIXLEN) + zlog_warn("warning: interface %s with addr %s/%d needs a peer address", + ifp->name,inet_ntoa(*addr),prefixlen); /* Label of this address. */ if (label) @@ -166,7 +208,7 @@ connected_down_ipv4 (struct interface *ifp, struct connected *ifc) p.prefixlen = addr->prefixlen; /* Point-to-point check. */ - if (dest && if_is_pointopoint (ifp)) + if (CONNECTED_POINTOPOINT_HOST(ifc)) p.prefix = dest->prefix; else p.prefix = addr->prefix; diff --git a/zebra/interface.c b/zebra/interface.c index 5664f41a..a1d0332a 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1107,7 +1107,6 @@ ip_address_install (struct vty *vty, struct interface *ifp, struct prefix_ipv4 cp; struct connected *ifc; struct prefix_ipv4 *p; - struct in_addr mask; int ret; ret = str2prefix_ipv4 (addr_str, &cp); @@ -1129,12 +1128,11 @@ ip_address_install (struct vty *vty, struct interface *ifp, ifc->address = (struct prefix *) p; /* Broadcast. */ - if (p->prefixlen <= 30) + if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2) { p = prefix_ipv4_new (); *p = cp; - masklen2ip (p->prefixlen, &mask); - p->prefix.s_addr |= ~mask.s_addr; + p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,p->prefixlen); ifc->destination = (struct prefix *) p; } diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index ee61cb27..50e83b77 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -596,7 +596,9 @@ netlink_interface_addr (struct sockaddr_nl *snl, struct nlmsghdr *h) if (tb[IFA_LOCAL]) { addr = RTA_DATA (tb[IFA_LOCAL]); - if (tb[IFA_ADDRESS]) + if (tb[IFA_ADDRESS] && + memcmp(RTA_DATA(tb[IFA_ADDRESS]),RTA_DATA(tb[IFA_LOCAL]),4)) + /* if IFA_ADDRESS != IFA_LOCAL, then it's the peer address */ broad = RTA_DATA (tb[IFA_ADDRESS]); else broad = NULL; -- cgit v1.2.1