summaryrefslogtreecommitdiff
path: root/ospfd
diff options
context:
space:
mode:
Diffstat (limited to 'ospfd')
-rw-r--r--ospfd/ChangeLog19
-rw-r--r--ospfd/ospf_interface.c59
-rw-r--r--ospfd/ospf_lsa.c31
-rw-r--r--ospfd/ospf_snmp.c13
-rw-r--r--ospfd/ospf_vty.c4
-rw-r--r--ospfd/ospfd.c26
6 files changed, 69 insertions, 83 deletions
diff --git a/ospfd/ChangeLog b/ospfd/ChangeLog
index 0a2b9994..c80f3b62 100644
--- a/ospfd/ChangeLog
+++ b/ospfd/ChangeLog
@@ -1,3 +1,22 @@
+2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+ * 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.
+
2006-12-04 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* ospfd.c: (ospf_network_run) Remove an offending 'break' statement.
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index b6e34746..4b6b424d 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -354,28 +354,18 @@ ospf_if_is_configured (struct ospf *ospf, struct in_addr *address)
addr.family = AF_INET;
addr.prefix = *address;
addr.prefixlen = IPV4_MAX_PREFIXLEN;
-
+
for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
{
- if (oi->type == OSPF_IFTYPE_POINTOPOINT)
+ if (oi->type == OSPF_IFTYPE_POINTOPOINT)
{
- if (CONNECTED_DEST_HOST(oi->connected))
- {
- /* match only destination addr, since local addr is most likely
- * not unique (borrowed from another interface) */
- if (IPV4_ADDR_SAME (address,
- &oi->connected->destination->u.prefix4))
- return oi;
- }
- else
- {
- /* special leniency: match if addr is anywhere on PtP subnet */
- if (prefix_match(oi->address,(struct prefix *)&addr))
- return oi;
- }
+ /* special leniency: match if addr is anywhere on peer subnet */
+ if (prefix_match(CONNECTED_PREFIX(oi->connected),
+ (struct prefix *)&addr))
+ return oi;
}
- else
+ else
{
if (IPV4_ADDR_SAME (address, &oi->address->u.prefix4))
return oi;
@@ -432,22 +422,15 @@ ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p)
{
struct listnode *node;
struct ospf_interface *oi;
- struct prefix ptmp;
/* Check each Interface. */
for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
{
if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
{
- if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
- CONNECTED_DEST_HOST(oi->connected))
- {
- prefix_copy (&ptmp, oi->connected->destination);
- ptmp.prefixlen = IPV4_MAX_BITLEN;
- }
- else
- prefix_copy (&ptmp, oi->address);
-
+ struct prefix ptmp;
+
+ prefix_copy (&ptmp, CONNECTED_PREFIX(oi->connected));
apply_mask (&ptmp);
if (prefix_same (&ptmp, (struct prefix *) p))
return oi;
@@ -477,22 +460,14 @@ ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src)
if (if_is_loopback (oi->ifp))
continue;
-
- if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
- CONNECTED_DEST_HOST(oi->connected))
- {
- if (IPV4_ADDR_SAME (&oi->connected->destination->u.prefix4, &src))
- return oi;
- }
- else
+
+ if (prefix_match (CONNECTED_PREFIX(oi->connected),
+ (struct prefix *) &addr))
{
- if (prefix_match (oi->address, (struct prefix *) &addr))
- {
- if ( (match == NULL) ||
- (match->address->prefixlen < oi->address->prefixlen)
- )
- match = oi;
- }
+ if ( (match == NULL) ||
+ (match->address->prefixlen < oi->address->prefixlen)
+ )
+ match = oi;
}
}
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c
index 05eed35e..b9a70a66 100644
--- a/ospfd/ospf_lsa.c
+++ b/ospfd/ospf_lsa.c
@@ -543,7 +543,7 @@ link_info_set (struct stream *s, struct in_addr id,
return 1;
}
-/* Describe Point-to-Point link. */
+/* Describe Point-to-Point link (Section 12.4.1.1). */
static int
lsa_link_ptop_set (struct stream *s, struct ospf_interface *oi)
{
@@ -564,28 +564,13 @@ lsa_link_ptop_set (struct stream *s, struct ospf_interface *oi)
LSA_LINK_TYPE_POINTOPOINT, 0, cost);
}
- if (CONNECTED_DEST_HOST(oi->connected))
- {
- /* Option 1:
- link_type = LSA_LINK_TYPE_STUB;
- link_id = nbr->address.u.prefix4;
- link_data.s_addr = 0xffffffff;
- link_cost = o->output_cost; */
-
- id.s_addr = oi->connected->destination->u.prefix4.s_addr;
- mask.s_addr = 0xffffffff;
- links += link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0,
- oi->output_cost);
- }
- else
- {
- /* Option 2: We need to include link to a stub
- network regardless of the state of the neighbor */
- masklen2ip (oi->address->prefixlen, &mask);
- id.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr;
- links += link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0,
- oi->output_cost);
- }
+ /* Regardless of the state of the neighboring router, we must
+ add a Type 3 link (stub network).
+ N.B. Options 1 & 2 share basically the same logic. */
+ masklen2ip (oi->address->prefixlen, &mask);
+ id.s_addr = CONNECTED_PREFIX(oi->connected)->u.prefix4.s_addr & mask.s_addr;
+ links += link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0,
+ oi->output_cost);
return links;
}
diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c
index 4a6cc159..bc594b3a 100644
--- a/ospfd/ospf_snmp.c
+++ b/ospfd/ospf_snmp.c
@@ -1439,10 +1439,7 @@ ospf_snmp_if_update (struct interface *ifp)
/* Lookup first IPv4 address entry. */
for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
{
- if (CONNECTED_POINTOPOINT_HOST(ifc))
- p = ifc->destination;
- else
- p = ifc->address;
+ p = CONNECTED_ID(ifc);
if (p->family == AF_INET)
{
@@ -1492,19 +1489,13 @@ ospf_snmp_if_update (struct interface *ifp)
int
ospf_snmp_is_if_have_addr (struct interface *ifp)
{
- struct prefix *p;
struct listnode *nn;
struct connected *ifc;
/* Is this interface having any connected IPv4 address ? */
for (ALL_LIST_ELEMENTS_RO (ifp->connected, nn, ifc))
{
- if (if_is_pointopoint (ifp))
- p = ifc->destination;
- else
- p = ifc->address;
-
- if (p->family == AF_INET)
+ if (CONNECTED_PREFIX(ifc)->family == AF_INET)
return 1;
}
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index d6da11dc..dd700b0e 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -2865,8 +2865,8 @@ show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf,
struct in_addr *dest;
const char *dstr;
- if ((ifp->flags & IFF_POINTOPOINT)
- || oi->type == OSPF_IFTYPE_VIRTUALLINK)
+ if (CONNECTED_PEER(oi->connected)
+ || oi->type == OSPF_IFTYPE_VIRTUALLINK)
dstr = "Peer";
else
dstr = "Broadcast";
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index dd5af5e9..f72295d1 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -795,6 +795,23 @@ ospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p,
int
ospf_network_match_iface(struct connected *co, struct prefix *net)
{
+#define COMPATIBILITY_MODE
+ /* The old code used to have a special case for PtP interfaces:
+
+ if (if_is_pointopoint (co->ifp) && co->destination &&
+ IPV4_ADDR_SAME ( &(co->destination->u.prefix4), &(net->u.prefix4)))
+ return 1;
+
+ The new approach is much more general. If a peer address is supplied,
+ then we are routing to that prefix, so that's the address to compare
+ against (not the local address, which may not be unique).
+ */
+#ifndef COMPATIBILITY_MODE
+ /* new approach: more elegant and conceptually clean */
+ return prefix_match(net, CONNECTED_PREFIX(co));
+#else /* COMPATIBILITY_MODE */
+ /* match old (strange?) behavior */
+
/* Behaviour to match both Cisco where:
* iface address lies within network specified -> ospf
* and zebra 0.9[2ish-3]:
@@ -806,7 +823,7 @@ ospf_network_match_iface(struct connected *co, struct prefix *net)
* exactly; this is not a test for falling within the prefix. This
* test is solely for compatibility with zebra.
*/
- if (if_is_pointopoint (co->ifp) && co->destination &&
+ if (CONNECTED_PEER(co) &&
IPV4_ADDR_SAME ( &(co->destination->u.prefix4), &(net->u.prefix4)))
return 1;
@@ -826,6 +843,8 @@ ospf_network_match_iface(struct connected *co, struct prefix *net)
return 1;
return 0; /* no match */
+
+#endif /* COMPATIBILITY_MODE */
}
void
@@ -856,10 +875,7 @@ ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area)
if (CHECK_FLAG(co->flags,ZEBRA_IFA_SECONDARY))
continue;
- if (CONNECTED_POINTOPOINT_HOST(co))
- addr = co->destination;
- else
- addr = co->address;
+ addr = CONNECTED_ID(co);
if (p->family == co->address->family
&& ! ospf_if_is_configured (ospf, &(addr->u.prefix4))