ospfd: Change struct ospf_path *oi to ifindex.

* global: In struct ospf_path, change struct ospf_interface *oi to int
  ifindex.  It is unsafe to reference *oi as an ospf interface can be
  deleted under your feet. Use a weak reference instead.
This commit is contained in:
Joakim Tjernlund 2009-07-27 12:42:34 +02:00 committed by Paul Jakma
parent bd5403778b
commit a8ba847ff9
7 changed files with 34 additions and 31 deletions

View File

@ -814,15 +814,12 @@ ospf_abr_nexthops_belong_to_area (struct ospf_route *or,
{
struct listnode *node, *nnode;
struct ospf_path *path;
struct ospf_interface *oi;
for (ALL_LIST_ELEMENTS (or->paths, node, nnode, path))
{
struct ospf_interface *oi = path->oi;
if (oi != NULL)
if (oi->area == area)
return 1;
}
for (ALL_LIST_ELEMENTS_RO (or->paths, node, path))
for (ALL_LIST_ELEMENTS_RO (area->oiflist, nnode, oi))
if (oi->ifp && oi->ifp->ifindex == path->ifindex)
return 1;
return 0;
}

View File

@ -135,6 +135,7 @@ ospf_ase_complete_direct_routes (struct ospf_route *ro, struct in_addr nexthop)
{
struct listnode *node;
struct ospf_path *op;
struct interface *ifp;
for (ALL_LIST_ELEMENTS_RO (ro->paths, node, op))
if (op->nexthop.s_addr == 0)
@ -593,7 +594,7 @@ ospf_ase_route_match_same (struct route_table *rt, struct prefix *prefix,
if (! IPV4_ADDR_SAME (&op->nexthop, &newop->nexthop))
return 0;
if (op->oi->ifp->ifindex != newop->oi->ifp->ifindex)
if (op->ifindex != newop->ifindex)
return 0;
}
return 1;

View File

@ -165,7 +165,7 @@ ospf_route_match_same (struct route_table *rt, struct prefix_ipv4 *prefix,
if (! IPV4_ADDR_SAME (&op->nexthop, &newop->nexthop))
return 0;
if (op->oi->ifp->ifindex != newop->oi->ifp->ifindex)
if (op->ifindex != newop->ifindex)
return 0;
}
return 1;
@ -640,7 +640,7 @@ ospf_intra_add_stub (struct route_table *rt, struct router_lsa_link *link,
path = ospf_path_new ();
path->nexthop.s_addr = 0;
path->oi = oi;
path->ifindex = oi->ifp->ifindex;
listnode_add (or->paths, path);
}
else
@ -788,7 +788,8 @@ ospf_path_exist (struct list *plist, struct in_addr nexthop,
struct ospf_path *path;
for (ALL_LIST_ELEMENTS (plist, node, nnode, path))
if (IPV4_ADDR_SAME (&path->nexthop, &nexthop) && path->oi == oi)
if (IPV4_ADDR_SAME (&path->nexthop, &nexthop) &&
path->ifindex == oi->ifp->ifindex)
return 1;
return 0;
@ -815,7 +816,7 @@ ospf_route_copy_nexthops_from_vertex (struct ospf_route *to,
{
path = ospf_path_new ();
path->nexthop = nexthop->router;
path->oi = nexthop->oi;
path->ifindex = nexthop->oi->ifp->ifindex;
listnode_add (to->paths, path);
}
}
@ -834,7 +835,7 @@ ospf_path_lookup (struct list *plist, struct ospf_path *path)
continue;
if (!IPV4_ADDR_SAME (&op->adv_router, &path->adv_router))
continue;
if (op->oi->ifp->ifindex != path->oi->ifp->ifindex)
if (op->ifindex != path->ifindex)
continue;
return op;
}

View File

@ -39,7 +39,7 @@ struct ospf_path
{
struct in_addr nexthop;
struct in_addr adv_router;
struct ospf_interface *oi;
unsigned int ifindex;
};
/* Below is the structure linked to every

View File

@ -1077,13 +1077,14 @@ ospf_rtrs_print (struct route_table *rtrs)
{
if (IS_DEBUG_OSPF_EVENT)
zlog_debug (" directly attached to %s\r\n",
IF_NAME (path->oi));
ifindex2ifname (path->ifindex));
}
else
{
if (IS_DEBUG_OSPF_EVENT)
zlog_debug (" via %s, %s\r\n",
inet_ntoa (path->nexthop), IF_NAME (path->oi));
inet_ntoa (path->nexthop),
ifindex2ifname (path->ifindex));
}
}
}

View File

@ -7138,15 +7138,15 @@ show_ip_ospf_route_network (struct vty *vty, struct route_table *rt)
if (or->type == OSPF_DESTINATION_NETWORK)
for (ALL_LIST_ELEMENTS (or->paths, pnode, pnnode, path))
{
if (path->oi != NULL && ospf_if_exists(path->oi))
if (if_lookup_by_index(path->ifindex))
{
if (path->nexthop.s_addr == 0)
vty_out (vty, "%24s directly attached to %s%s",
"", path->oi->ifp->name, VTY_NEWLINE);
"", ifindex2ifname (path->ifindex), VTY_NEWLINE);
else
vty_out (vty, "%24s via %s, %s%s", "",
inet_ntoa (path->nexthop), path->oi->ifp->name,
VTY_NEWLINE);
inet_ntoa (path->nexthop),
ifindex2ifname (path->ifindex), VTY_NEWLINE);
}
}
}
@ -7188,15 +7188,17 @@ show_ip_ospf_route_router (struct vty *vty, struct route_table *rtrs)
for (ALL_LIST_ELEMENTS_RO (or->paths, pnode, path))
{
if (path->oi != NULL && ospf_if_exists(path->oi))
if (if_lookup_by_index(path->ifindex))
{
if (path->nexthop.s_addr == 0)
vty_out (vty, "%24s directly attached to %s%s",
"", path->oi->ifp->name, VTY_NEWLINE);
"", ifindex2ifname (path->ifindex),
VTY_NEWLINE);
else
vty_out (vty, "%24s via %s, %s%s", "",
inet_ntoa (path->nexthop),
path->oi->ifp->name, VTY_NEWLINE);
ifindex2ifname (path->ifindex),
VTY_NEWLINE);
}
}
}
@ -7235,14 +7237,15 @@ show_ip_ospf_route_external (struct vty *vty, struct route_table *rt)
for (ALL_LIST_ELEMENTS (er->paths, pnode, pnnode, path))
{
if (path->oi != NULL && ospf_if_exists(path->oi))
if (if_lookup_by_index(path->ifindex))
{
if (path->nexthop.s_addr == 0)
vty_out (vty, "%24s directly attached to %s%s",
"", path->oi->ifp->name, VTY_NEWLINE);
"", ifindex2ifname (path->ifindex), VTY_NEWLINE);
else
vty_out (vty, "%24s via %s, %s%s", "",
inet_ntoa (path->nexthop), path->oi->ifp->name,
inet_ntoa (path->nexthop),
ifindex2ifname (path->ifindex),
VTY_NEWLINE);
}
}

View File

@ -378,8 +378,8 @@ ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or)
else
{
stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
if (path->oi)
stream_putl (s, path->oi->ifp->ifindex);
if (path->ifindex)
stream_putl (s, path->ifindex);
else
stream_putl (s, 0);
}
@ -439,11 +439,11 @@ ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_route *or)
nexthop = &path->nexthop;
api.nexthop = &nexthop;
}
else if (ospf_if_exists(path->oi) && (path->oi->ifp))
else if (if_lookup_by_index(path->ifindex))
{
SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
api.ifindex_num = 1;
api.ifindex = &path->oi->ifp->ifindex;
api.ifindex = &path->ifindex;
}
else if ( IS_DEBUG_OSPF(zebra,ZEBRA_REDISTRIBUTE) )
{