Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Quagga: Dev

[PATCH 3/5] ripd: code simplification for redistribution.

 

 

Quagga dev RSS feed   Index | Next | Previous | View Threaded


boutier at pps

Jul 20, 2012, 9:30 AM

Post #1 of 1 (135 views)
Permalink
[PATCH 3/5] ripd: code simplification for redistribution.

From: Matthieu Boutier <boutier [at] pps>

Use loops and variables instead of doing each cases by hand.
Use boolean instead of having 2 almost identical functions.
---
ripd/ripd.c | 119 ++++++++++++++----------------------------------------------
1 file changed, 27 insertions(+), 92 deletions(-)

diff --git a/ripd/ripd.c b/ripd/ripd.c
index 6a58723..5155263 100644
--- a/ripd/ripd.c
+++ b/ripd/ripd.c
@@ -162,32 +162,36 @@ rip_timeout_update (struct rip_info *rinfo)
}

static int
-rip_incoming_filter (struct prefix_ipv4 *p, struct rip_interface *ri)
+rip_filter (int output, struct prefix_ipv4 *p, struct rip_interface *ri)
{
struct distribute *dist;
struct access_list *alist;
struct prefix_list *plist;
+ int distribute = output ? DISTRIBUTE_OUT : DISTRIBUTE_IN;
+ int rip_distribute = output ? RIP_FILTER_OUT : RIP_FILTER_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,
+ output ? "out" : "in");
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,
+ output ? "out" : "in");
return -1;
}
}
@@ -196,104 +200,35 @@ rip_incoming_filter (struct prefix_ipv4 *p, struct rip_interface *ri)
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]);
-
- if (alist)
- {
- 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);
- return -1;
- }
- }
- }
- if (dist->prefix[DISTRIBUTE_IN])
- {
- plist = prefix_list_lookup (AFI_IP, dist->prefix[DISTRIBUTE_IN]);
-
- 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;
-}
+ alist = access_list_lookup (AFI_IP, dist->list[distribute]);

-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 (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);
+ zlog_debug ("%s/%d filtered by distribute %s",
+ inet_ntoa (p->prefix), p->prefixlen,
+ output ? "out" : "in");
return -1;
}
}
}
- if (dist->prefix[DISTRIBUTE_OUT])
+ if (dist->prefix[distribute])
{
- plist = prefix_list_lookup (AFI_IP, dist->prefix[DISTRIBUTE_OUT]);
-
+ 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 out",
- inet_ntoa (p->prefix), p->prefixlen);
+ zlog_debug ("%s/%d filtered by prefix-list %s",
+ inet_ntoa (p->prefix), p->prefixlen,
+ output ? "out" : "in");
return -1;
}
}
@@ -356,7 +291,7 @@ rip_rte_process (struct rte *rte, struct sockaddr_in *from,
/* Apply input filters. */
ri = ifp->info;

- ret = rip_incoming_filter (&p, ri);
+ ret = rip_filter (0, &p, ri);
if (ret < 0)
return;

@@ -1832,7 +1767,7 @@ rip_output_process (struct connected *ifc, struct sockaddr_in *to,
p = (struct prefix_ipv4 *) &rp->p;

/* Apply output filters. */
- ret = rip_outgoing_filter (p, ri);
+ ret = rip_filter (1, p, ri);
if (ret < 0)
continue;

--
1.7.11.1

_______________________________________________
Quagga-dev mailing list
Quagga-dev [at] lists
http://lists.quagga.net/mailman/listinfo/quagga-dev

Quagga dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.