summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/md5.c3
-rw-r--r--lib/prefix.h10
-rw-r--r--lib/table.c62
-rw-r--r--lib/table.h12
-rw-r--r--lib/vty.c6
5 files changed, 34 insertions, 59 deletions
diff --git a/lib/md5.c b/lib/md5.c
index f1bd0668..894de648 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -232,7 +232,7 @@ static void md5_calc(const uint8_t *b64, md5_ctxt * ctxt)
const uint32_t *X = (const uint32_t *)b64;
#elif (BYTE_ORDER == BIG_ENDIAN)
uint32_t X[16];
-#endif
+
if (BYTE_ORDER == BIG_ENDIAN)
{
/* 4 byte words */
@@ -255,6 +255,7 @@ static void md5_calc(const uint8_t *b64, md5_ctxt * ctxt)
y[56] = b64[59]; y[57] = b64[58]; y[58] = b64[57]; y[59] = b64[56];
y[60] = b64[63]; y[61] = b64[62]; y[62] = b64[61]; y[63] = b64[60];
}
+#endif
ROUND1(A, B, C, D, 0, Sa, 1); ROUND1(D, A, B, C, 1, Sb, 2);
ROUND1(C, D, A, B, 2, Sc, 3); ROUND1(B, C, D, A, 3, Sd, 4);
diff --git a/lib/prefix.h b/lib/prefix.h
index 9cfc1556..d3707209 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -127,6 +127,16 @@ struct prefix_rd
/* Prefix's family member. */
#define PREFIX_FAMILY(p) ((p)->family)
+/* Check bit of the prefix. */
+static inline unsigned int
+prefix_bit (const u_char *prefix, const u_char prefixlen)
+{
+ unsigned int offset = prefixlen / 8;
+ unsigned int shift = 7 - (prefixlen % 8);
+
+ return (prefix[offset] >> shift) & 1;
+}
+
/* Prototypes. */
extern int afi2family (int);
extern int family2afi (int);
diff --git a/lib/table.c b/lib/table.c
index 2ade71b8..04df3af5 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
};
@@ -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 (u_char *prefix, u_char prefixlen)
-{
- int offset;
- int shift;
- u_char *p = (u_char *)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;
@@ -219,26 +192,9 @@ 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)
+route_node_match (const struct route_table *table, const struct prefix *p)
{
struct route_node *node;
struct route_node *matched;
@@ -253,7 +209,7 @@ route_node_match (struct route_table *table, 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. */
@@ -264,7 +220,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;
@@ -278,7 +235,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;
@@ -305,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;
@@ -330,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)
diff --git a/lib/table.h b/lib/table.h
index 45ec6067..41d1fa70 100644
--- a/lib/table.h
+++ b/lib/table.h
@@ -66,13 +66,13 @@ extern struct route_node *route_node_get (struct route_table *,
extern struct route_node *route_node_lookup (struct route_table *,
struct prefix *);
extern struct route_node *route_lock_node (struct route_node *node);
-extern struct route_node *route_node_match (struct route_table *,
- struct prefix *);
-extern struct route_node *route_node_match_ipv4 (struct route_table *,
- struct in_addr *);
+extern struct route_node *route_node_match (const struct route_table *,
+ const struct prefix *);
+extern struct route_node *route_node_match_ipv4 (const struct route_table *,
+ const struct in_addr *);
#ifdef HAVE_IPV6
-extern struct route_node *route_node_match_ipv6 (struct route_table *,
- struct in6_addr *);
+extern struct route_node *route_node_match_ipv6 (const struct route_table *,
+ const struct in6_addr *);
#endif /* HAVE_IPV6 */
#endif /* _ZEBRA_TABLE_H */
diff --git a/lib/vty.c b/lib/vty.c
index 6a307c6b..6b627a30 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -1955,6 +1955,7 @@ uty_accept (int accept_sock)
unsigned int on;
struct prefix *p = NULL;
struct access_list *acl = NULL;
+ char *bufp;
/* We continue hearing vty socket. */
vty_event (VTY_SERV, accept_sock, NULL);
@@ -2023,6 +2024,11 @@ uty_accept (int accept_sock)
uzlog (NULL, LOG_INFO, "can't set sockopt to vty_sock : %s",
safe_strerror (errno));
+ zlog (NULL, LOG_INFO, "Vty connection from %s",
+ (bufp = sockunion_su2str (&su)));
+ if (bufp)
+ XFREE (MTYPE_TMP, bufp);
+
vty = vty_create (vty_sock, &su);
return 0;