summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/if.c24
-rw-r--r--lib/if.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/if.c b/lib/if.c
index e26aa046..6348403b 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -304,6 +304,30 @@ if_lookup_address (struct in_addr src)
return match;
}
+/* Lookup interface by prefix */
+struct interface *
+if_lookup_prefix (struct prefix *prefix)
+{
+ struct listnode *node;
+ struct prefix addr;
+ int bestlen = 0;
+ struct listnode *cnode;
+ struct interface *ifp;
+ struct connected *c;
+
+ for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
+ {
+ for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c))
+ {
+ if (prefix_cmp(c->address, prefix) == 0)
+ {
+ return ifp;
+ }
+ }
+ }
+ return NULL;
+}
+
/* Get interface by name if given name interface doesn't exist create
one. */
struct interface *
diff --git a/lib/if.h b/lib/if.h
index 13cc254e..8081be87 100644
--- a/lib/if.h
+++ b/lib/if.h
@@ -245,6 +245,7 @@ extern struct interface *if_create (const char *name, int namelen);
extern struct interface *if_lookup_by_index (unsigned int);
extern struct interface *if_lookup_exact_address (struct in_addr);
extern struct interface *if_lookup_address (struct in_addr);
+extern struct interface *if_lookup_prefix (struct prefix *prefix);
/* These 2 functions are to be used when the ifname argument is terminated
by a '\0' character: */