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.
diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c
index 88636f1..7e32195 100644
--- a/ospfd/ospf_abr.c
+++ b/ospfd/ospf_abr.c
@@ -814,15 +814,12 @@
{
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;
}
diff --git a/ospfd/ospf_ase.c b/ospfd/ospf_ase.c
index 044f97c..7bddf3f 100644
--- a/ospfd/ospf_ase.c
+++ b/ospfd/ospf_ase.c
@@ -135,6 +135,7 @@
{
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 @@
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;
diff --git a/ospfd/ospf_route.c b/ospfd/ospf_route.c
index 0829e8e..267237b 100644
--- a/ospfd/ospf_route.c
+++ b/ospfd/ospf_route.c
@@ -165,7 +165,7 @@
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 @@
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 @@
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 @@
{
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 @@
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;
}
diff --git a/ospfd/ospf_route.h b/ospfd/ospf_route.h
index 0d37436..17ab68e 100644
--- a/ospfd/ospf_route.h
+++ b/ospfd/ospf_route.h
@@ -39,7 +39,7 @@
{
struct in_addr nexthop;
struct in_addr adv_router;
- struct ospf_interface *oi;
+ unsigned int ifindex;
};
/* Below is the structure linked to every
diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c
index 12afe5d..9566843 100644
--- a/ospfd/ospf_spf.c
+++ b/ospfd/ospf_spf.c
@@ -1077,13 +1077,14 @@
{
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));
}
}
}
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 2e4b607..7c3dec8 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -7138,15 +7138,15 @@
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 @@
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 @@
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);
}
}
diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c
index 8f624a4..52b23fe 100644
--- a/ospfd/ospf_zebra.c
+++ b/ospfd/ospf_zebra.c
@@ -378,8 +378,8 @@
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 @@
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) )
{