From 0d6388abc7a5da2a20a4854c400c8e176127e480 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Mon, 7 Dec 2009 19:19:13 +0300 Subject: lib: remove unused function: route_dump_node() --- lib/table.c | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'lib/table.c') diff --git a/lib/table.c b/lib/table.c index 2ade71b8..70fc0b24 100644 --- a/lib/table.c +++ b/lib/table.c @@ -219,23 +219,6 @@ route_unlock_node (struct route_node *node) route_node_delete (node); } -/* Dump routing table. */ -static void __attribute__ ((unused)) -route_dump_node (struct route_table *t) -{ - struct route_node *node; - char buf[46]; - - for (node = route_top (t); node != NULL; node = route_next (node)) - { - printf ("[%d] %p %s/%d\n", - node->lock, - node->info, - inet_ntop (node->p.family, &node->p.u.prefix, buf, 46), - node->p.prefixlen); - } -} - /* Find matched prefix. */ struct route_node * route_node_match (struct route_table *table, struct prefix *p) -- cgit v1.2.3 From 38cc00cd823fe945c7748de18c3e8932d98dd8f8 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 8 Dec 2009 12:00:50 +0300 Subject: lib: make match functions take const args * table.c: general type safety and compiler help: * maskbit[]: become const * route_node_match(): take const args * route_node_match_ipv4(): idem * route_node_match_ipv6(): idem * check_bit(): idem, plus adjust local vars typing --- lib/table.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lib/table.c') diff --git a/lib/table.c b/lib/table.c index 70fc0b24..06c64539 100644 --- a/lib/table.c +++ b/lib/table.c @@ -125,7 +125,7 @@ route_table_free (struct route_table *rt) } /* Utility mask array. */ -static u_char maskbit[] = +static const u_char maskbit[] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; @@ -170,11 +170,11 @@ route_common (struct prefix *n, struct prefix *p, struct prefix *new) /* Check bit of the prefix. */ static int -check_bit (u_char *prefix, u_char prefixlen) +check_bit (const u_char *prefix, u_char prefixlen) { - int offset; - int shift; - u_char *p = (u_char *)prefix; + unsigned int offset; + unsigned int shift; + const u_char *p = prefix; assert (prefixlen <= 128); @@ -221,7 +221,7 @@ route_unlock_node (struct route_node *node) /* Find matched prefix. */ struct route_node * -route_node_match (struct route_table *table, struct prefix *p) +route_node_match (const struct route_table *table, const struct prefix *p) { struct route_node *node; struct route_node *matched; @@ -247,7 +247,8 @@ route_node_match (struct route_table *table, struct prefix *p) } struct route_node * -route_node_match_ipv4 (struct route_table *table, struct in_addr *addr) +route_node_match_ipv4 (const struct route_table *table, + const struct in_addr *addr) { struct prefix_ipv4 p; @@ -261,7 +262,8 @@ route_node_match_ipv4 (struct route_table *table, struct in_addr *addr) #ifdef HAVE_IPV6 struct route_node * -route_node_match_ipv6 (struct route_table *table, struct in6_addr *addr) +route_node_match_ipv6 (const struct route_table *table, + const struct in6_addr *addr) { struct prefix_ipv6 p; -- cgit v1.2.3 From 1352ef32d70dcc102074814de63b5d08e591dd2d Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 9 Dec 2009 14:43:17 +0300 Subject: lib: move check_bit into prefix common code Make one version of check prefix bit, and put it inline with proper prototype. This gets rid of some macro's and also some assert() that can never happen on a non-broken compiler. * bgpd/bgp_table.c * CHECK_BIT(): sayonara * check_bit(): sayonara * SET_LINK(): sayonara * set_link(): make use of prefix_bit() instead of check_bit() * bgp_node_match(): idem * bgp_node_lookup(): idem * bgp_node_get(): idem * lib/prefix.h * prefix_bit(): new inline version of check_bit() * lib/table.c * CHECK_BIT(): sayonara * check_bit(): sayonara * SET_LINK(): sayonara * set_link(): make use of prefix_bit() instead of check_bit() * route_node_match(): idem * route_node_lookup(): idem * route_node_get(): idem * ospf6d/ospf6_lsdb.c * CHECK_BIT(): sayonara * ospf6_lsdb_lookup_next(): make use of prefix_bit() instead of CHECK_BIT() * ospf6_lsdb_type_router_head(): idem * ospf6_lsdb_type_head(): idem * ospf6d/ospf6_route.c * CHECK_BIT(): sayonara * ospf6_route_match_head() make use of prefix_bit() instead of * CHECK_BIT() --- lib/table.c | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) (limited to 'lib/table.c') diff --git a/lib/table.c b/lib/table.c index 06c64539..04df3af5 100644 --- a/lib/table.c +++ b/lib/table.c @@ -165,37 +165,10 @@ route_common (struct prefix *n, struct prefix *p, struct prefix *new) } } -/* Macro version of check_bit (). */ -#define CHECK_BIT(X,P) ((((u_char *)(X))[(P) / 8]) >> (7 - ((P) % 8)) & 1) - -/* Check bit of the prefix. */ -static int -check_bit (const u_char *prefix, u_char prefixlen) -{ - unsigned int offset; - unsigned int shift; - const u_char *p = prefix; - - assert (prefixlen <= 128); - - offset = prefixlen / 8; - shift = 7 - (prefixlen % 8); - - return (p[offset] >> shift & 1); -} - -/* Macro version of set_link (). */ -#define SET_LINK(X,Y) do { (X)->link[CHECK_BIT(&(Y)->p.u.prefix,(X)->p.prefixlen)] = (Y);\ - (Y)->parent = (X); } while (0) - static void set_link (struct route_node *node, struct route_node *new) { - int bit; - - bit = check_bit (&new->p.u.prefix, node->p.prefixlen); - - assert (bit == 0 || bit == 1); + unsigned int bit = prefix_bit (&new->p.u.prefix, node->p.prefixlen); node->link[bit] = new; new->parent = node; @@ -236,7 +209,7 @@ route_node_match (const struct route_table *table, const struct prefix *p) { if (node->info) matched = node; - node = node->link[check_bit(&p->u.prefix, node->p.prefixlen)]; + node = node->link[prefix_bit(&p->u.prefix, node->p.prefixlen)]; } /* If matched route found, return it. */ @@ -290,7 +263,7 @@ route_node_lookup (struct route_table *table, struct prefix *p) if (node->p.prefixlen == p->prefixlen && node->info) return route_lock_node (node); - node = node->link[check_bit(&p->u.prefix, node->p.prefixlen)]; + node = node->link[prefix_bit(&p->u.prefix, node->p.prefixlen)]; } return NULL; @@ -315,7 +288,7 @@ route_node_get (struct route_table *table, struct prefix *p) return node; } match = node; - node = node->link[check_bit(&p->u.prefix, node->p.prefixlen)]; + node = node->link[prefix_bit(&p->u.prefix, node->p.prefixlen)]; } if (node == NULL) -- cgit v1.2.3