[PtP over ethernet] New peer flag allows much more addressing flexibility

2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>

	* if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating
	  whether a peer address has been configured.  Comment now shows
	  the new interpretation of the destination addr: if ZEBRA_IFA_PEER
	  is set, then it must contain the destination address, otherwise
	  it may contain the broadcast address or be NULL.
	  (CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete
	  macros that were specific to IPv4 and not fully general.
	  (CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag.
	  (CONNECTED_PREFIX) New macro giving the prefix to insert into
	  the RIB: if CONNECTED_PEER, then use the destination (peer) address,
	  else use the address field.
	  (CONNECTED_ID) New macro to come up with an identifying address
	  for the struct connected.
	* if.c: (if_lookup_address, connected_lookup_address) Streamline
	  logic with new CONNECTED_PREFIX macro.
	* prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros
	  for better performance than the general prefix_copy function.
	* zclient.c: (zebra_interface_address_read) For non-null destination
	  addresses, set prefixlen to equal the address prefixlen.  This
	  is needed to get the new CONNECTED_PREFIX macro to work properly.
	* connected.c: (connected_up_ipv4, connected_down_ipv4,
	  connected_up_ipv6, connected_down_ipv6) Simplify logic using the
	  new CONNECTED_PREFIX macro.
	  (connected_add_ipv4) Set prefixlen in destination addresses (required
	  by the CONNECTED_PREFIX macro).  Use CONNECTED_PEER macro instead
	  of testing for IFF_POINTOPOINT.  Delete invalid warning message.
	  Warn about cases where the ZEBRA_IFA_PEER is set but no
	  destination address has been supplied (and turn off the flag).
	  (connected_add_ipv6) Add new flags argument so callers may set
	  the ZEBRA_IFA_PEER flag.  If peer/broadcast address satisfies
	  IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning.
	  Set prefixlen in destination address so CONNECTED_PREFIX will work.
	* connected.h: (connected_add_ipv6) Add new flags argument so
	  callers may set the ZEBRA_IFA_PEER flag.
	* interface.c: (connected_dump_vty) Use CONNECTED_PEER macro
	  to decide whether the destination address is a peer or broadcast
	  address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT).
	* if_ioctl.c: (if_getaddrs) Instead of setting a peer address
	  only when the IFF_POINTOPOINT is set, we now accept a peer
	  address whenever it is available and not the same as the local
	  address.  Otherwise (no peer address assigned), we check
	  for a broadcast address (regardless of the IFF_BROADCAST flag).
	  And must now pass a flags value of ZEBRA_IFA_PEER to
	  connected_add_ipv4 when a peer address is assigned.
	  The same new logic is used with the IPv6 code as well (and we
	  pass the new flags argument to connected_add_ipv6).
	  (if_get_addr) Do not bother to check IFF_POINTOPOINT: just
	  issue the SIOCGIFDSTADDR ioctl and see if we get back
	  a peer address not matching the local address (and set
	  the ZEBRA_IFA_PEER in that case).  If there's no peer address,
	  try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set.
	* if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl
	  without bothering to check the IFF_POINTOPOINT flag.  And if
	  no peer address was found, just try the SIOCGLIFBRDADDR ioctl
	  without checking the IFF_BROADCAST flag.  Call connected_add_ipv4
	  and connected_add_ipv6 with appropriate flags.
	* if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to
	  connected_add_ipv6.
	* kernel_socket.c: (ifam_read) Must pass new flags argument to
	  connected_add_ipv6.
	* rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2
	  to determine local and possible peer address (so there's no longer
	  a test for IFF_POINTOPOINT).  Set ZEBRA_IFA_PEER flag appropriately.
	  Pass new flags argument to connected_add_ipv6.
	  (netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast
	  to determine whether the connected destination address is a
	  broadcast address.
	* bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete)
	  Simplify logic by using new CONNECTED_PREFIX macro.
	* ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix,
	  ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX
	  macro.
	* ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX
	  macro, both options collapse into the same code.
	* ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new
	  CONNECTED_ID macro.
	  (ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX
	  macro.
	* ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro
	  instead of testing the IFF_POINTOPOINT flag.
	* ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro
	  instead of testing with if_is_pointopoint.  And add commented-out
	  code to implement alternative (in my opinion) more elegant behavior
	  that has no special-case treatment for PtP addresses.
	  (ospf_network_run) Use new CONNECTED_ID macro to simplify logic.
	* rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID
	  macro to simplify logic.
	  (rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does
	  not give a useful result if prefixlen is 32 (we require a peer
	  address in such cases).
	* ripd.c: (rip_update_interface) Fix same bug as above.
diff --git a/zebra/ChangeLog b/zebra/ChangeLog
index 3ea4f57..6b50cf0 100644
--- a/zebra/ChangeLog
+++ b/zebra/ChangeLog
@@ -1,3 +1,53 @@
+2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+	* connected.c: (connected_up_ipv4, connected_down_ipv4,
+	  connected_up_ipv6, connected_down_ipv6) Simplify logic using the
+	  new CONNECTED_PREFIX macro.
+	  (connected_add_ipv4) Set prefixlen in destination addresses (required
+	  by the CONNECTED_PREFIX macro).  Use CONNECTED_PEER macro instead
+	  of testing for IFF_POINTOPOINT.  Delete invalid warning message.
+	  Warn about cases where the ZEBRA_IFA_PEER is set but no
+	  destination address has been supplied (and turn off the flag).
+	  (connected_add_ipv6) Add new flags argument so callers may set
+	  the ZEBRA_IFA_PEER flag.  If peer/broadcast address satisfies
+	  IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning.
+	  Set prefixlen in destination address so CONNECTED_PREFIX will work.
+	* connected.h: (connected_add_ipv6) Add new flags argument so
+	  callers may set the ZEBRA_IFA_PEER flag.
+	* interface.c: (connected_dump_vty) Use CONNECTED_PEER macro
+	  to decide whether the destination address is a peer or broadcast
+	  address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT).
+	* if_ioctl.c: (if_getaddrs) Instead of setting a peer address
+	  only when the IFF_POINTOPOINT is set, we now accept a peer
+	  address whenever it is available and not the same as the local
+	  address.  Otherwise (no peer address assigned), we check
+	  for a broadcast address (regardless of the IFF_BROADCAST flag).
+	  And must now pass a flags value of ZEBRA_IFA_PEER to 
+	  connected_add_ipv4 when a peer address is assigned.
+	  The same new logic is used with the IPv6 code as well (and we
+	  pass the new flags argument to connected_add_ipv6).
+	  (if_get_addr) Do not bother to check IFF_POINTOPOINT: just
+	  issue the SIOCGIFDSTADDR ioctl and see if we get back
+	  a peer address not matching the local address (and set
+	  the ZEBRA_IFA_PEER in that case).  If there's no peer address,
+	  try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set.
+	* if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl
+	  without bothering to check the IFF_POINTOPOINT flag.  And if
+	  no peer address was found, just try the SIOCGLIFBRDADDR ioctl
+	  without checking the IFF_BROADCAST flag.  Call connected_add_ipv4
+	  and connected_add_ipv6 with appropriate flags.
+	* if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to
+	  connected_add_ipv6.
+	* kernel_socket.c: (ifam_read) Must pass new flags argument to
+	  connected_add_ipv6.
+	* rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2
+	  to determine local and possible peer address (so there's no longer
+	  a test for IFF_POINTOPOINT).  Set ZEBRA_IFA_PEER flag appropriately.
+	  Pass new flags argument to connected_add_ipv6.
+	  (netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast
+	  to determine whether the connected destination address is a
+	  broadcast address.
+
 2006-12-08 Piotr Chytla <pch@packetconsulting.pl>
 
 	* zebra_rib.c: (static_install_ipv{4,6}) Case where existing
diff --git a/zebra/connected.c b/zebra/connected.c
index 44002e7..3fe9717 100644
--- a/zebra/connected.c
+++ b/zebra/connected.c
@@ -173,24 +173,11 @@
 connected_up_ipv4 (struct interface *ifp, struct connected *ifc)
 {
   struct prefix_ipv4 p;
-  struct prefix_ipv4 *addr;
-  struct prefix_ipv4 *dest;
 
   if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
     return;
 
-  addr = (struct prefix_ipv4 *) ifc->address;
-  dest = (struct prefix_ipv4 *) ifc->destination;
-
-  memset (&p, 0, sizeof (struct prefix_ipv4));
-  p.family = AF_INET;
-  p.prefixlen = addr->prefixlen;
-
-  /* Point-to-point check. */
-  if (CONNECTED_POINTOPOINT_HOST(ifc))
-    p.prefix = dest->prefix;
-  else
-    p.prefix = addr->prefix;
+  PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc));
 
   /* Apply mask to the network. */
   apply_mask_ipv4 (&p);
@@ -227,33 +214,22 @@
   p->prefixlen = prefixlen;
   ifc->address = (struct prefix *) p;
   
-  /* If there is broadcast or pointopoint address. */
+  /* If there is broadcast or peer address. */
   if (broad)
     {
       p = prefix_ipv4_new ();
       p->family = AF_INET;
       p->prefix = *broad;
+      p->prefixlen = prefixlen;
       ifc->destination = (struct prefix *) p;
 
       /* validate the destination address */
-      if (ifp->flags & IFF_POINTOPOINT)
+      if (CONNECTED_PEER(ifc))
         {
 	  if (IPV4_ADDR_SAME(addr,broad))
-	    zlog_warn("warning: PtP interface %s has same local and peer "
+	    zlog_warn("warning: 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
         {
@@ -273,10 +249,20 @@
 
     }
   else
-    /* no broadcast or destination address was supplied */
-    if ((prefixlen == IPV4_MAX_PREFIXLEN) && if_is_pointopoint(ifp))
-      zlog_warn("warning: PtP interface %s with addr %s/%d needs a "
-      		"peer address",ifp->name,inet_ntoa(*addr),prefixlen);
+    {
+      if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER))
+        {
+	  zlog_warn("warning: %s called for interface %s "
+		    "with peer flag set, but no peer address supplied",
+		    __func__, ifp->name);
+	  UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
+	}
+
+      /* no broadcast or destination address was supplied */
+      if ((prefixlen == IPV4_MAX_PREFIXLEN) && if_is_pointopoint(ifp))
+	zlog_warn("warning: PtP interface %s with addr %s/%d needs a "
+		  "peer address",ifp->name,inet_ntoa(*addr),prefixlen);
+    }
 
   /* Label of this address. */
   if (label)
@@ -293,24 +279,11 @@
 connected_down_ipv4 (struct interface *ifp, struct connected *ifc)
 {
   struct prefix_ipv4 p;
-  struct prefix_ipv4 *addr;
-  struct prefix_ipv4 *dest;
 
   if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
     return;
 
-  addr = (struct prefix_ipv4 *)ifc->address;
-  dest = (struct prefix_ipv4 *)ifc->destination;
-
-  memset (&p, 0, sizeof (struct prefix_ipv4));
-  p.family = AF_INET;
-  p.prefixlen = addr->prefixlen;
-
-  /* Point-to-point check. */
-  if (CONNECTED_POINTOPOINT_HOST(ifc))
-    p.prefix = dest->prefix;
-  else
-    p.prefix = addr->prefix;
+  PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc));
 
   /* Apply mask to the network. */
   apply_mask_ipv4 (&p);
@@ -350,28 +323,11 @@
 connected_up_ipv6 (struct interface *ifp, struct connected *ifc)
 {
   struct prefix_ipv6 p;
-  struct prefix_ipv6 *addr;
-  struct prefix_ipv6 *dest;
 
   if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
     return;
 
-  addr = (struct prefix_ipv6 *) ifc->address;
-  dest = (struct prefix_ipv6 *) ifc->destination;
-
-  memset (&p, 0, sizeof (struct prefix_ipv6));
-  p.family = AF_INET6;
-  p.prefixlen = addr->prefixlen;
-
-  if (if_is_pointopoint (ifp) && dest)
-    {
-      if (IN6_IS_ADDR_UNSPECIFIED (&dest->prefix))
-	p.prefix = addr->prefix;
-      else
-	p.prefix = dest->prefix;
-    }
-  else
-    p.prefix = addr->prefix;
+  PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc));
 
   /* Apply mask to the network. */
   apply_mask_ipv6 (&p);
@@ -390,7 +346,7 @@
 
 /* Add connected IPv6 route to the interface. */
 void
-connected_add_ipv6 (struct interface *ifp, struct in6_addr *addr,
+connected_add_ipv6 (struct interface *ifp, int flags, struct in6_addr *addr,
 		    u_char prefixlen, struct in6_addr *broad,
 		    const char *label)
 {
@@ -400,6 +356,7 @@
   /* Make connected structure. */
   ifc = connected_new ();
   ifc->ifp = ifp;
+  ifc->flags = flags;
 
   /* Allocate new connected address. */
   p = prefix_ipv6_new ();
@@ -408,13 +365,27 @@
   p->prefixlen = prefixlen;
   ifc->address = (struct prefix *) p;
 
-  /* If there is broadcast or pointopoint address. */
+  /* If there is broadcast or peer address. */
   if (broad)
     {
-      p = prefix_ipv6_new ();
-      p->family = AF_INET6;
-      IPV6_ADDR_COPY (&p->prefix, broad);
-      ifc->destination = (struct prefix *) p;
+      if (IN6_IS_ADDR_UNSPECIFIED(broad))
+	zlog_warn("warning: %s called for interface %s with unspecified "
+		  "destination address; ignoring!", __func__, ifp->name);
+      else
+	{
+	  p = prefix_ipv6_new ();
+	  p->family = AF_INET6;
+	  IPV6_ADDR_COPY (&p->prefix, broad);
+	  p->prefixlen = prefixlen;
+	  ifc->destination = (struct prefix *) p;
+	}
+    }
+  if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER) && !ifc->destination)
+    {
+      zlog_warn("warning: %s called for interface %s "
+		"with peer flag set, but no peer address supplied",
+		__func__, ifp->name);
+      UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
     }
 
   /* Label of this address. */
@@ -431,28 +402,11 @@
 connected_down_ipv6 (struct interface *ifp, struct connected *ifc)
 {
   struct prefix_ipv6 p;
-  struct prefix_ipv6 *addr;
-  struct prefix_ipv6 *dest;
 
   if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
     return;
 
-  addr = (struct prefix_ipv6 *) ifc->address;
-  dest = (struct prefix_ipv6 *) ifc->destination;
-
-  memset (&p, 0, sizeof (struct prefix_ipv6));
-  p.family = AF_INET6;
-  p.prefixlen = addr->prefixlen;
-
-  if (if_is_pointopoint (ifp) && dest)
-    {
-      if (IN6_IS_ADDR_UNSPECIFIED (&dest->prefix))
-	p.prefix = addr->prefix;
-      else
-	p.prefix = dest->prefix;
-    }
-  else
-    p.prefix = addr->prefix;
+  PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc));
 
   apply_mask_ipv6 (&p);
 
diff --git a/zebra/connected.h b/zebra/connected.h
index 28387e9..9595ddb 100644
--- a/zebra/connected.h
+++ b/zebra/connected.h
@@ -40,7 +40,7 @@
 
 #ifdef HAVE_IPV6
 extern void
-connected_add_ipv6 (struct interface *ifp, struct in6_addr *address,
+connected_add_ipv6 (struct interface *ifp, int flags, struct in6_addr *address,
 		    u_char prefixlen, struct in6_addr *broad,
 		    const char *label);
 extern void
diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c
index 788184f..f357e15 100644
--- a/zebra/if_ioctl.c
+++ b/zebra/if_ioctl.c
@@ -249,6 +249,7 @@
 	  struct sockaddr_in *mask;
 	  struct sockaddr_in *dest;
 	  struct in_addr *dest_pnt;
+	  int flags = 0;
 
 	  addr = (struct sockaddr_in *) ifap->ifa_addr;
 	  mask = (struct sockaddr_in *) ifap->ifa_netmask;
@@ -256,19 +257,25 @@
 
 	  dest_pnt = NULL;
 
-	  if (ifap->ifa_flags & IFF_POINTOPOINT) 
+	  if (ifap->ifa_dstaddr &&
+	      !IPV4_ADDR_SAME(&addr->sin_addr,
+			      &((struct sockaddr_in *)
+			      	ifap->ifa_dstaddr)->sin_addr))
 	    {
 	      dest = (struct sockaddr_in *) ifap->ifa_dstaddr;
 	      dest_pnt = &dest->sin_addr;
+	      flags = ZEBRA_IFA_PEER;
 	    }
-
-	  if (ifap->ifa_flags & IFF_BROADCAST)
+	  else if (ifap->ifa_broadaddr &&
+		   !IPV4_ADDR_SAME(&addr->sin_addr,
+				   &((struct sockaddr_in *)
+				     ifap->ifa_broadaddr)->sin_addr))
 	    {
 	      dest = (struct sockaddr_in *) ifap->ifa_broadaddr;
 	      dest_pnt = &dest->sin_addr;
 	    }
 
-	  connected_add_ipv4 (ifp, 0, &addr->sin_addr,
+	  connected_add_ipv4 (ifp, flags, &addr->sin_addr,
 			      prefixlen, dest_pnt, NULL);
 	}
 #ifdef HAVE_IPV6
@@ -278,6 +285,7 @@
 	  struct sockaddr_in6 *mask;
 	  struct sockaddr_in6 *dest;
 	  struct in6_addr *dest_pnt;
+	  int flags = 0;
 
 	  addr = (struct sockaddr_in6 *) ifap->ifa_addr;
 	  mask = (struct sockaddr_in6 *) ifap->ifa_netmask;
@@ -285,22 +293,22 @@
 
 	  dest_pnt = NULL;
 
-	  if (ifap->ifa_flags & IFF_POINTOPOINT) 
+	  if (ifap->ifa_dstaddr &&
+	      !IPV6_ADDR_SAME(&addr->sin6_addr,
+			      &((struct sockaddr_in6 *)
+			      	ifap->ifa_dstaddr)->sin6_addr))
 	    {
-	      if (ifap->ifa_dstaddr)
-		{
-		  dest = (struct sockaddr_in6 *) ifap->ifa_dstaddr;
-		  dest_pnt = &dest->sin6_addr;
-		}
+	      dest = (struct sockaddr_in6 *) ifap->ifa_dstaddr;
+	      dest_pnt = &dest->sin6_addr;
+	      flags = ZEBRA_IFA_PEER;
 	    }
-
-	  if (ifap->ifa_flags & IFF_BROADCAST)
+	  else if (ifap->ifa_broadaddr &&
+		   !IPV6_ADDR_SAME(&addr->sin6_addr,
+				   &((struct sockaddr_in6 *)
+				     ifap->ifa_broadaddr)->sin6_addr))
 	    {
-	      if (ifap->ifa_broadaddr)
-		{
-		  dest = (struct sockaddr_in6 *) ifap->ifa_broadaddr;
-		  dest_pnt = &dest->sin6_addr;
-		}
+	      dest = (struct sockaddr_in6 *) ifap->ifa_broadaddr;
+	      dest_pnt = &dest->sin6_addr;
 	    }
 
 #if defined(KAME)
@@ -312,7 +320,7 @@
 	    }	
 #endif          
 
-	  connected_add_ipv6 (ifp, &addr->sin6_addr, prefixlen, 
+	  connected_add_ipv6 (ifp, flags, &addr->sin6_addr, prefixlen, 
 	                      dest_pnt, NULL);
 	}
 #endif /* HAVE_IPV6 */
@@ -335,6 +343,7 @@
   struct sockaddr_in dest;
   struct in_addr *dest_pnt;
   u_char prefixlen;
+  int flags = 0;
 
   /* Interface's name and address family. */
   strncpy (ifreq.ifr_name, ifp->name, IFNAMSIZ);
@@ -374,40 +383,36 @@
   /* Point to point or borad cast address pointer init. */
   dest_pnt = NULL;
 
-  if (ifp->flags & IFF_POINTOPOINT) 
+  ret = if_ioctl (SIOCGIFDSTADDR, (caddr_t) &ifreq);
+  if (ret < 0) 
     {
-      ret = if_ioctl (SIOCGIFDSTADDR, (caddr_t) &ifreq);
-      if (ret < 0) 
-	{
-	  if (errno != EADDRNOTAVAIL) 
-	    {
-	      zlog_warn ("SIOCGIFDSTADDR fail: %s", safe_strerror (errno));
-	      return ret;
-	    }
-	  return 0;
-	}
+      if (errno != EADDRNOTAVAIL) 
+	zlog_warn ("SIOCGIFDSTADDR fail: %s", safe_strerror (errno));
+    }
+  else if (!IPV4_ADDR_SAME(&addr.sin_addr, &ifreq.ifr_dstaddr.sin_addr))
+    {
       memcpy (&dest, &ifreq.ifr_dstaddr, sizeof (struct sockaddr_in));
       dest_pnt = &dest.sin_addr;
+      flags = ZEBRA_IFA_PEER;
     }
-  if (ifp->flags & IFF_BROADCAST)
+  if (!dest_pnt)
     {
       ret = if_ioctl (SIOCGIFBRDADDR, (caddr_t) &ifreq);
       if (ret < 0) 
 	{
 	  if (errno != EADDRNOTAVAIL) 
-	    {
-	      zlog_warn ("SIOCGIFBRDADDR fail: %s", safe_strerror (errno));
-	      return ret;
-	    }
-	  return 0;
+	    zlog_warn ("SIOCGIFBRDADDR fail: %s", safe_strerror (errno));
 	}
-      memcpy (&dest, &ifreq.ifr_broadaddr, sizeof (struct sockaddr_in));
-      dest_pnt = &dest.sin_addr;
+      else if (!IPV4_ADDR_SAME(&addr.sin_addr, &ifreq.ifr_broadaddr.sin_addr))
+        {
+	  memcpy (&dest, &ifreq.ifr_broadaddr, sizeof (struct sockaddr_in));
+	  dest_pnt = &dest.sin_addr;
+        }
     }
 
 
   /* Set address to the interface. */
-  connected_add_ipv4 (ifp, 0, &addr.sin_addr, prefixlen, dest_pnt, NULL);
+  connected_add_ipv4 (ifp, flags, &addr.sin_addr, prefixlen, dest_pnt, NULL);
 
   return 0;
 }
diff --git a/zebra/if_ioctl_solaris.c b/zebra/if_ioctl_solaris.c
index 095bcab..4cb16c7 100644
--- a/zebra/if_ioctl_solaris.c
+++ b/zebra/if_ioctl_solaris.c
@@ -258,6 +258,7 @@
   char *dest_pnt = NULL;
   u_char prefixlen = 0;
   afi_t af;
+  int flags = 0;
 
   /* Interface's name and address family.
    * We need to use the logical interface name / label, if we've been
@@ -272,21 +273,14 @@
   /* Point to point or broad cast address pointer init. */
   dest_pnt = NULL;
 
-  if (ifp->flags & IFF_POINTOPOINT)
+  if (AF_IOCTL (af, SIOCGLIFDSTADDR, (caddr_t) & lifreq) >= 0)
     {
-      ret = AF_IOCTL (af, SIOCGLIFDSTADDR, (caddr_t) & lifreq);
-        
-      if (ret < 0)
-        {
-          zlog_warn ("SIOCGLIFDSTADDR (%s) fail: %s",
-                     ifp->name, safe_strerror (errno));
-          return ret;
-        }
       memcpy (&dest, &lifreq.lifr_dstaddr, ADDRLEN (addr));
       if (af == AF_INET)
         dest_pnt = (char *) &(SIN (&dest)->sin_addr);
       else
         dest_pnt = (char *) &(SIN6 (&dest)->sin6_addr);
+      flags = ZEBRA_IFA_PEER;
     }
 
   if (af == AF_INET)
@@ -306,19 +300,8 @@
       memcpy (&mask, &lifreq.lifr_addr, ADDRLEN (addr));
 
       prefixlen = ip_masklen (SIN (&mask)->sin_addr);
-      if (ifp->flags & IFF_BROADCAST)
-        {
-          ret = if_ioctl (SIOCGLIFBRDADDR, (caddr_t) & lifreq);
-          if (ret < 0)
-            {
-              if (errno != EADDRNOTAVAIL)
-                {
-                  zlog_warn ("SIOCGLIFBRDADDR (%s) fail: %s",
-                             ifp->name, safe_strerror (errno));
-                  return ret;
-                }
-              return 0;
-            }
+      if (!dest_pnt && (if_ioctl (SIOCGLIFBRDADDR, (caddr_t) & lifreq) >= 0))
+	{
           memcpy (&dest, &lifreq.lifr_broadaddr, sizeof (struct sockaddr_in));
           dest_pnt = (char *) &SIN (&dest)->sin_addr;
         }
@@ -348,11 +331,11 @@
 
   /* Set address to the interface. */
   if (af == AF_INET)
-    connected_add_ipv4 (ifp, 0, &SIN (addr)->sin_addr, prefixlen,
+    connected_add_ipv4 (ifp, flags, &SIN (addr)->sin_addr, prefixlen,
                         (struct in_addr *) dest_pnt, label);
 #ifdef HAVE_IPV6
   else if (af == AF_INET6)
-    connected_add_ipv6 (ifp, &SIN6 (addr)->sin6_addr, prefixlen,
+    connected_add_ipv6 (ifp, flags, &SIN6 (addr)->sin6_addr, prefixlen,
                         (struct in6_addr *) dest_pnt, label);
 #endif /* HAVE_IPV6 */
 
diff --git a/zebra/if_proc.c b/zebra/if_proc.c
index 367b0d6..3aec530 100644
--- a/zebra/if_proc.c
+++ b/zebra/if_proc.c
@@ -240,7 +240,7 @@
       str2in6_addr (addr, &p.prefix);
       p.prefixlen = plen;
 
-      connected_add_ipv6 (ifp, &p.prefix, p.prefixlen, NULL, ifname);
+      connected_add_ipv6 (ifp, 0, &p.prefix, p.prefixlen, NULL, ifname);
     }
   fclose (fp);
   return 0;
diff --git a/zebra/interface.c b/zebra/interface.c
index 69124b3..ceee0e2 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -564,10 +564,6 @@
 connected_dump_vty (struct vty *vty, struct connected *connected)
 {
   struct prefix *p;
-  struct interface *ifp;
-
-  /* Set interface pointer. */
-  ifp = connected->ifp;
 
   /* Print interface address. */
   p = connected->address;
@@ -576,21 +572,10 @@
   vty_out (vty, "/%d", p->prefixlen);
 
   /* If there is destination address, print it. */
-  p = connected->destination;
-  if (p)
+  if (connected->destination)
     {
-      if (p->family == AF_INET)
-	if (ifp->flags & IFF_BROADCAST)
-	  {
-	    vty_out (vty, " broadcast ");
-	    prefix_vty_out (vty, p);
-	  }
-
-      if (ifp->flags & IFF_POINTOPOINT)
-	{
-	  vty_out (vty, " pointopoint ");
-	  prefix_vty_out (vty, p);
-	}
+      vty_out (vty, (CONNECTED_PEER(connected) ? " peer " : " broadcast "));
+      prefix_vty_out (vty, connected->destination);
     }
 
   if (CHECK_FLAG (connected->flags, ZEBRA_IFA_SECONDARY))
diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c
index f384e97..ac06566 100644
--- a/zebra/kernel_socket.c
+++ b/zebra/kernel_socket.c
@@ -609,7 +609,7 @@
 	SET_IN6_LINKLOCAL_IFINDEX (addr.sin6.sin6_addr, 0);
 
       if (ifam->ifam_type == RTM_NEWADDR)
-	connected_add_ipv6 (ifp,
+	connected_add_ipv6 (ifp, 0,
 			    &addr.sin6.sin6_addr, 
 			    ip6_masklen (mask.sin6.sin6_addr),
 			    &brd.sin6.sin6_addr,
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index 216625e..e2f1f9d 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -577,8 +577,8 @@
   struct ifaddrmsg *ifa;
   struct rtattr *tb[IFA_MAX + 1];
   struct interface *ifp;
-  void *addr = NULL;
-  void *broad = NULL;
+  void *addr;
+  void *broad;
   u_char flags = 0;
   char *label = NULL;
 
@@ -637,41 +637,29 @@
         }
     }
   
+  /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
+  if (tb[IFA_LOCAL] == NULL)
+    tb[IFA_LOCAL] = tb[IFA_ADDRESS];
   if (tb[IFA_ADDRESS] == NULL)
     tb[IFA_ADDRESS] = tb[IFA_LOCAL];
   
-  if (ifp->flags & IFF_POINTOPOINT)
+  /* local interface address */
+  addr = (tb[IFA_LOCAL] ? RTA_DATA(tb[IFA_LOCAL]) : NULL);
+
+  /* is there a peer address? */
+  /* N.B. I do not understand why the memcmp compares 4 bytes regardless
+     of address family, but this is exactly how it appears in
+     print_addrinfo.  I wonder if it should be RTA_PAYLOAD(tb[IFA_ADDRESS])
+     instead of 4... */
+  if (tb[IFA_ADDRESS] &&
+      memcmp(RTA_DATA(tb[IFA_ADDRESS]), RTA_DATA(tb[IFA_LOCAL]), 4))
     {
-      if (tb[IFA_LOCAL])
-        {
-          addr = RTA_DATA (tb[IFA_LOCAL]);
-          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;
-        }
-      else
-        {
-          if (tb[IFA_ADDRESS])
-            addr = RTA_DATA (tb[IFA_ADDRESS]);
-          else
-            addr = NULL;
-        }
+      broad = RTA_DATA(tb[IFA_ADDRESS]);
+      SET_FLAG (flags, ZEBRA_IFA_PEER);
     }
   else
-    {
-      if (tb[IFA_ADDRESS])
-        addr = RTA_DATA (tb[IFA_ADDRESS]);
-      else
-        addr = NULL;
-      
-      if (tb[IFA_BROADCAST])
-        broad = RTA_DATA(tb[IFA_BROADCAST]);
-      else
-        broad = NULL;
-    }
+    /* seeking a broadcast address */
+    broad = (tb[IFA_BROADCAST] ? RTA_DATA(tb[IFA_BROADCAST]) : NULL);
 
   /* addr is primary key, SOL if we don't have one */
   if (addr == NULL)
@@ -707,7 +695,7 @@
   if (ifa->ifa_family == AF_INET6)
     {
       if (h->nlmsg_type == RTM_NEWADDR)
-        connected_add_ipv6 (ifp,
+        connected_add_ipv6 (ifp, flags,
                             (struct in6_addr *) addr, ifa->ifa_prefixlen,
                             (struct in6_addr *) broad, label);
       else
@@ -1849,7 +1837,7 @@
 
   if (family == AF_INET && cmd == RTM_NEWADDR)
     {
-      if (if_is_broadcast (ifp) && ifc->destination)
+      if (!CONNECTED_PEER(ifc) && ifc->destination)
         {
           p = ifc->destination;
           addattr_l (&req.n, sizeof req, IFA_BROADCAST, &p->u.prefix,