ripd: code simplification for redistribution.
Use loops and variables instead of doing each cases by hand.
Use boolean instead of having 2 almost identical functions.
diff --git a/ripd/ripd.c b/ripd/ripd.c
index 1d3eb4c..990db60 100644
--- a/ripd/ripd.c
+++ b/ripd/ripd.c
@@ -315,32 +315,35 @@
}
static int
-rip_incoming_filter (struct prefix_ipv4 *p, struct rip_interface *ri)
+rip_filter (int rip_distribute, struct prefix_ipv4 *p, struct rip_interface *ri)
{
struct distribute *dist;
struct access_list *alist;
struct prefix_list *plist;
+ int distribute = rip_distribute == RIP_FILTER_OUT ?
+ DISTRIBUTE_OUT : DISTRIBUTE_IN;
+ const char *inout = rip_distribute == RIP_FILTER_OUT ? "out" : "in";
/* Input distribute-list filtering. */
- if (ri->list[RIP_FILTER_IN])
+ if (ri->list[rip_distribute])
{
- if (access_list_apply (ri->list[RIP_FILTER_IN],
+ if (access_list_apply (ri->list[rip_distribute],
(struct prefix *) p) == FILTER_DENY)
{
if (IS_RIP_DEBUG_PACKET)
- zlog_debug ("%s/%d filtered by distribute in",
- inet_ntoa (p->prefix), p->prefixlen);
+ zlog_debug ("%s/%d filtered by distribute %s",
+ inet_ntoa (p->prefix), p->prefixlen, inout);
return -1;
}
}
- if (ri->prefix[RIP_FILTER_IN])
+ if (ri->prefix[rip_distribute])
{
- if (prefix_list_apply (ri->prefix[RIP_FILTER_IN],
+ if (prefix_list_apply (ri->prefix[rip_distribute],
(struct prefix *) p) == PREFIX_DENY)
{
if (IS_RIP_DEBUG_PACKET)
- zlog_debug ("%s/%d filtered by prefix-list in",
- inet_ntoa (p->prefix), p->prefixlen);
+ zlog_debug ("%s/%d filtered by prefix-list %s",
+ inet_ntoa (p->prefix), p->prefixlen, inout);
return -1;
}
}
@@ -349,104 +352,33 @@
dist = distribute_lookup (NULL);
if (dist)
{
- if (dist->list[DISTRIBUTE_IN])
+ if (dist->list[distribute])
{
- alist = access_list_lookup (AFI_IP, dist->list[DISTRIBUTE_IN]);
-
+ alist = access_list_lookup (AFI_IP, dist->list[distribute]);
+
if (alist)
{
- if (access_list_apply (alist,
- (struct prefix *) p) == FILTER_DENY)
+ if (access_list_apply (alist, (struct prefix *) p) == FILTER_DENY)
{
if (IS_RIP_DEBUG_PACKET)
- zlog_debug ("%s/%d filtered by distribute in",
- inet_ntoa (p->prefix), p->prefixlen);
+ zlog_debug ("%s/%d filtered by distribute %s",
+ inet_ntoa (p->prefix), p->prefixlen, inout);
return -1;
}
}
}
- if (dist->prefix[DISTRIBUTE_IN])
+ if (dist->prefix[distribute])
{
- plist = prefix_list_lookup (AFI_IP, dist->prefix[DISTRIBUTE_IN]);
-
+ plist = prefix_list_lookup (AFI_IP, dist->prefix[distribute]);
+
if (plist)
{
if (prefix_list_apply (plist,
(struct prefix *) p) == PREFIX_DENY)
{
if (IS_RIP_DEBUG_PACKET)
- zlog_debug ("%s/%d filtered by prefix-list in",
- inet_ntoa (p->prefix), p->prefixlen);
- return -1;
- }
- }
- }
- }
- return 0;
-}
-
-static int
-rip_outgoing_filter (struct prefix_ipv4 *p, struct rip_interface *ri)
-{
- struct distribute *dist;
- struct access_list *alist;
- struct prefix_list *plist;
-
- if (ri->list[RIP_FILTER_OUT])
- {
- if (access_list_apply (ri->list[RIP_FILTER_OUT],
- (struct prefix *) p) == FILTER_DENY)
- {
- if (IS_RIP_DEBUG_PACKET)
- zlog_debug ("%s/%d is filtered by distribute out",
- inet_ntoa (p->prefix), p->prefixlen);
- return -1;
- }
- }
- if (ri->prefix[RIP_FILTER_OUT])
- {
- if (prefix_list_apply (ri->prefix[RIP_FILTER_OUT],
- (struct prefix *) p) == PREFIX_DENY)
- {
- if (IS_RIP_DEBUG_PACKET)
- zlog_debug ("%s/%d is filtered by prefix-list out",
- inet_ntoa (p->prefix), p->prefixlen);
- return -1;
- }
- }
-
- /* All interface filter check. */
- dist = distribute_lookup (NULL);
- if (dist)
- {
- if (dist->list[DISTRIBUTE_OUT])
- {
- alist = access_list_lookup (AFI_IP, dist->list[DISTRIBUTE_OUT]);
-
- if (alist)
- {
- if (access_list_apply (alist,
- (struct prefix *) p) == FILTER_DENY)
- {
- if (IS_RIP_DEBUG_PACKET)
- zlog_debug ("%s/%d filtered by distribute out",
- inet_ntoa (p->prefix), p->prefixlen);
- return -1;
- }
- }
- }
- if (dist->prefix[DISTRIBUTE_OUT])
- {
- plist = prefix_list_lookup (AFI_IP, dist->prefix[DISTRIBUTE_OUT]);
-
- if (plist)
- {
- if (prefix_list_apply (plist,
- (struct prefix *) p) == PREFIX_DENY)
- {
- if (IS_RIP_DEBUG_PACKET)
- zlog_debug ("%s/%d filtered by prefix-list out",
- inet_ntoa (p->prefix), p->prefixlen);
+ zlog_debug ("%s/%d filtered by prefix-list %s",
+ inet_ntoa (p->prefix), p->prefixlen, inout);
return -1;
}
}
@@ -509,7 +441,7 @@
/* Apply input filters. */
ri = ifp->info;
- ret = rip_incoming_filter (&p, ri);
+ ret = rip_filter (RIP_FILTER_IN, &p, ri);
if (ret < 0)
return;
@@ -2294,7 +2226,7 @@
p = (struct prefix_ipv4 *) &rp->p;
/* Apply output filters. */
- ret = rip_outgoing_filter (p, ri);
+ ret = rip_filter (RIP_FILTER_OUT, p, ri);
if (ret < 0)
continue;