summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Hall <GMCH@hestia.halldom.com>2010-01-24 18:46:20 +0000
committerChris Hall <GMCH@hestia.halldom.com>2010-01-24 18:46:20 +0000
commitc21f7fd3e23791cb6ea8a3b0b968af8892c75931 (patch)
tree0a9ee21a4feecec514223bdb7656c8b6ee2a2668
parent0341d5ce47c301b4a4d92b77a83930da4fdc8fb3 (diff)
downloadquagga-c21f7fd3e23791cb6ea8a3b0b968af8892c75931.tar.bz2
quagga-c21f7fd3e23791cb6ea8a3b0b968af8892c75931.tar.xz
Getting BGP Engine to start and removing warnings.
Finish the wiring required to get bgp_msg_read to process OPEN messages into the connection's open_state, and be able to check for correct peer AS, etc. Removed bugs preventing messages from being written. Added BGP Id check to collision detection logic. Removed as many warnings from comilation as possible. Replaced horrible FIFO kludge in the process. (Introduced the even more horrible miyagi kludge.) modified: bgpd/bgp_advertise.c modified: bgpd/bgp_advertise.h modified: bgpd/bgp_connection.c modified: bgpd/bgp_connection.h modified: bgpd/bgp_debug.c modified: bgpd/bgp_fsm.c modified: bgpd/bgp_msg_read.c modified: bgpd/bgp_msg_write.c modified: bgpd/bgp_network.c modified: bgpd/bgp_nexthop.c modified: bgpd/bgp_notification.c modified: bgpd/bgp_open.c modified: bgpd/bgp_packet.c modified: bgpd/bgp_session.c modified: bgpd/bgp_session.h modified: bgpd/bgpd.c modified: lib/Makefile.am modified: lib/distribute.c modified: lib/if_rmap.c new file: lib/miyagi.h modified: lib/prefix.h modified: lib/sockopt.c modified: lib/stream.c modified: lib/thread.c modified: lib/vty.c modified: lib/zebra.h modified: tests/bgp_capability_test.c modified: tests/bgp_mp_attr_test.c modified: tests/ecommunity_test.c modified: tests/heavy-thread.c modified: tests/heavy-wq.c modified: tests/heavy.c modified: tests/main.c modified: tests/test-checksum.c modified: tests/test-sig.c modified: watchquagga/watchquagga.c modified: zebra/if_netlink.c modified: zebra/ioctl.c modified: zebra/rt_netlink.c modified: zebra/rtread_netlink.c
-rw-r--r--bgpd/bgp_advertise.c58
-rw-r--r--bgpd/bgp_advertise.h94
-rw-r--r--bgpd/bgp_connection.c14
-rw-r--r--bgpd/bgp_connection.h86
-rw-r--r--bgpd/bgp_debug.c20
-rw-r--r--bgpd/bgp_fsm.c401
-rw-r--r--bgpd/bgp_msg_read.c20
-rw-r--r--bgpd/bgp_msg_write.c14
-rw-r--r--bgpd/bgp_network.c3
-rw-r--r--bgpd/bgp_nexthop.c18
-rw-r--r--bgpd/bgp_notification.c12
-rw-r--r--bgpd/bgp_open.c2
-rw-r--r--bgpd/bgp_packet.c9
-rw-r--r--bgpd/bgp_session.c11
-rw-r--r--bgpd/bgp_session.h3
-rw-r--r--bgpd/bgpd.c8
-rw-r--r--lib/Makefile.am3
-rw-r--r--lib/distribute.c19
-rw-r--r--lib/if_rmap.c19
-rw-r--r--lib/miyagi.h40
-rw-r--r--lib/prefix.h24
-rw-r--r--lib/sockopt.c2
-rw-r--r--lib/stream.c6
-rw-r--r--lib/thread.c130
-rw-r--r--lib/vty.c9
-rw-r--r--lib/zebra.h32
-rw-r--r--tests/bgp_capability_test.c143
-rw-r--r--tests/bgp_mp_attr_test.c139
-rw-r--r--tests/ecommunity_test.c23
-rw-r--r--tests/heavy-thread.c26
-rw-r--r--tests/heavy-wq.c36
-rw-r--r--tests/heavy.c26
-rw-r--r--tests/main.c34
-rw-r--r--tests/test-checksum.c97
-rw-r--r--tests/test-sig.c10
-rw-r--r--watchquagga/watchquagga.c12
-rw-r--r--zebra/if_netlink.c8
-rw-r--r--zebra/ioctl.c44
-rw-r--r--zebra/rt_netlink.c44
-rw-r--r--zebra/rtread_netlink.c5
40 files changed, 913 insertions, 791 deletions
diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c
index 23740a68..90579e7c 100644
--- a/bgpd/bgp_advertise.c
+++ b/bgpd/bgp_advertise.c
@@ -35,7 +35,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_mplsvpn.h"
-
+
/* BGP advertise attribute is used for pack same attribute update into
one packet. To do that we maintain attribute hash in struct
peer. */
@@ -79,14 +79,14 @@ baa_hash_cmp (const void *p1, const void *p2)
return attrhash_cmp (baa1->attr, baa2->attr);
}
-
+
/* BGP update and withdraw information is stored in BGP advertise
structure. This structure is referred from BGP adjacency
information. */
static struct bgp_advertise *
bgp_advertise_new (void)
{
- return (struct bgp_advertise *)
+ return (struct bgp_advertise *)
XCALLOC (MTYPE_BGP_ADVERTISE, sizeof (struct bgp_advertise));
}
@@ -102,9 +102,9 @@ static void
bgp_advertise_add (struct bgp_advertise_attr *baa,
struct bgp_advertise *adv)
{
- adv->next = baa->adv;
+ adv->adv_next = baa->adv;
if (baa->adv)
- baa->adv->prev = adv;
+ baa->adv->adv_prev = adv;
baa->adv = adv;
}
@@ -112,12 +112,12 @@ static void
bgp_advertise_delete (struct bgp_advertise_attr *baa,
struct bgp_advertise *adv)
{
- if (adv->next)
- adv->next->prev = adv->prev;
- if (adv->prev)
- adv->prev->next = adv->next;
+ if (adv->adv_next)
+ adv->adv_next->adv_prev = adv->adv_prev;
+ if (adv->adv_prev)
+ adv->adv_prev->adv_next = adv->adv_next;
else
- baa->adv = adv->next;
+ baa->adv = adv->adv_next;
}
static struct bgp_advertise_attr *
@@ -151,7 +151,7 @@ bgp_advertise_unintern (struct hash *hash, struct bgp_advertise_attr *baa)
baa_free (baa);
}
}
-
+
/* BGP adjacency keeps minimal advertisement information. */
static void
bgp_adj_out_free (struct bgp_adj_out *adj)
@@ -173,7 +173,7 @@ bgp_adj_out_lookup (struct peer *peer, struct prefix *p,
if (! adj)
return 0;
- return (adj->adv
+ return (adj->adv
? (adj->adv->baa ? 1 : 0)
: (adj->attr ? 1 : 0));
}
@@ -203,7 +203,7 @@ bgp_advertise_clean (struct peer *peer, struct bgp_adj_out *adj,
}
/* Unlink myself from advertisement FIFO. */
- FIFO_DEL (adv);
+ bgp_advertise_fifo_del(adv);
/* Free memory. */
bgp_advertise_free (adj->adv);
@@ -235,7 +235,7 @@ bgp_adj_out_set (struct bgp_node *rn, struct peer *peer, struct prefix *p,
{
adj = XCALLOC (MTYPE_BGP_ADJ_OUT, sizeof (struct bgp_adj_out));
adj->peer = peer_lock (peer); /* adj_out peer reference */
-
+
if (rn)
{
BGP_ADJ_OUT_ADD (rn, adj);
@@ -245,15 +245,15 @@ bgp_adj_out_set (struct bgp_node *rn, struct peer *peer, struct prefix *p,
if (adj->adv)
bgp_advertise_clean (peer, adj, afi, safi);
-
+
adj->adv = bgp_advertise_new ();
adv = adj->adv;
adv->rn = rn;
-
+
assert (adv->binfo == NULL);
adv->binfo = bgp_info_lock (binfo); /* bgp_info adj_out reference */
-
+
if (attr)
adv->baa = bgp_advertise_intern (peer->hash[afi][safi], attr);
else
@@ -263,11 +263,11 @@ bgp_adj_out_set (struct bgp_node *rn, struct peer *peer, struct prefix *p,
/* Add new advertisement to advertisement attribute list. */
bgp_advertise_add (adv->baa, adv);
- FIFO_ADD (&peer->sync[afi][safi]->update, &adv->fifo);
+ bgp_advertise_fifo_add(&peer->sync[afi][safi]->update, adv);
}
void
-bgp_adj_out_unset (struct bgp_node *rn, struct peer *peer, struct prefix *p,
+bgp_adj_out_unset (struct bgp_node *rn, struct peer *peer, struct prefix *p,
afi_t afi, safi_t safi)
{
struct bgp_adj_out *adj;
@@ -297,7 +297,7 @@ bgp_adj_out_unset (struct bgp_node *rn, struct peer *peer, struct prefix *p,
adv->adj = adj;
/* Add to synchronization entry for withdraw announcement. */
- FIFO_ADD (&peer->sync[afi][safi]->withdraw, &adv->fifo);
+ bgp_advertise_fifo_add(&peer->sync[afi][safi]->withdraw, adv);
/* Schedule packet write. */
bgp_write(peer);
@@ -306,7 +306,7 @@ bgp_adj_out_unset (struct bgp_node *rn, struct peer *peer, struct prefix *p,
{
/* Remove myself from adjacency. */
BGP_ADJ_OUT_DEL (rn, adj);
-
+
/* Free allocated information. */
bgp_adj_out_free (adj);
@@ -315,7 +315,7 @@ bgp_adj_out_unset (struct bgp_node *rn, struct peer *peer, struct prefix *p,
}
void
-bgp_adj_out_remove (struct bgp_node *rn, struct bgp_adj_out *adj,
+bgp_adj_out_remove (struct bgp_node *rn, struct bgp_adj_out *adj,
struct peer *peer, afi_t afi, safi_t safi)
{
if (adj->attr)
@@ -327,7 +327,7 @@ bgp_adj_out_remove (struct bgp_node *rn, struct bgp_adj_out *adj,
BGP_ADJ_OUT_DEL (rn, adj);
bgp_adj_out_free (adj);
}
-
+
void
bgp_adj_in_set (struct bgp_node *rn, struct peer *peer, struct attr *attr)
{
@@ -376,7 +376,7 @@ bgp_adj_in_unset (struct bgp_node *rn, struct peer *peer)
bgp_adj_in_remove (rn, adj);
bgp_unlock_node (rn);
}
-
+
void
bgp_sync_init (struct peer *peer)
{
@@ -387,11 +387,11 @@ bgp_sync_init (struct peer *peer)
for (afi = AFI_IP; afi < AFI_MAX; afi++)
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
{
- sync = XCALLOC (MTYPE_BGP_SYNCHRONISE,
+ sync = XCALLOC (MTYPE_BGP_SYNCHRONISE,
sizeof (struct bgp_synchronize));
- FIFO_INIT (&sync->update);
- FIFO_INIT (&sync->withdraw);
- FIFO_INIT (&sync->withdraw_low);
+ bgp_advertise_fifo_init(&sync->update);
+ bgp_advertise_fifo_init(&sync->withdraw);
+ bgp_advertise_fifo_init(&sync->withdraw_low);
peer->sync[afi][safi] = sync;
peer->hash[afi][safi] = hash_create (baa_hash_key, baa_hash_cmp);
}
@@ -409,7 +409,7 @@ bgp_sync_delete (struct peer *peer)
if (peer->sync[afi][safi])
XFREE (MTYPE_BGP_SYNCHRONISE, peer->sync[afi][safi]);
peer->sync[afi][safi] = NULL;
-
+
if (peer->hash[afi][safi])
hash_free (peer->hash[afi][safi]);
peer->hash[afi][safi] = NULL;
diff --git a/bgpd/bgp_advertise.h b/bgpd/bgp_advertise.h
index 4ebde907..918e1216 100644
--- a/bgpd/bgp_advertise.h
+++ b/bgpd/bgp_advertise.h
@@ -21,11 +21,26 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#ifndef _QUAGGA_BGP_ADVERTISE_H
#define _QUAGGA_BGP_ADVERTISE_H
+#ifndef Inline
+#define Inline static inline
+#endif
+
/* BGP advertise FIFO. */
+typedef struct bgp_advertise* bgp_advertise ;
+
+typedef struct bgp_advertise_fifo_base* bgp_advertise_fifo_base ;
+
struct bgp_advertise_fifo
{
- struct bgp_advertise *next;
- struct bgp_advertise *prev;
+ bgp_advertise_fifo_base base ;
+ bgp_advertise next;
+ bgp_advertise prev;
+};
+
+struct bgp_advertise_fifo_base
+{
+ bgp_advertise head;
+ bgp_advertise tail;
};
/* BGP advertise attribute. */
@@ -47,8 +62,8 @@ struct bgp_advertise
struct bgp_advertise_fifo fifo;
/* Link list for same attribute advertise. */
- struct bgp_advertise *next;
- struct bgp_advertise *prev;
+ bgp_advertise adv_next;
+ bgp_advertise adv_prev;
/* Prefix information. */
struct bgp_node *rn;
@@ -97,11 +112,74 @@ struct bgp_adj_in
/* BGP advertisement list. */
struct bgp_synchronize
{
- struct bgp_advertise_fifo update;
- struct bgp_advertise_fifo withdraw;
- struct bgp_advertise_fifo withdraw_low;
+ struct bgp_advertise_fifo_base update;
+ struct bgp_advertise_fifo_base withdraw;
+ struct bgp_advertise_fifo_base withdraw_low;
};
+/* bgp_advertise_fifo handling
+ *
+ * Rules: base->head == NULL => empty
+ * base->tail -- only valid if base->head != NULL
+ *
+ * adv->fifo.base == NULL => not on fifo
+ *
+ * adv->fifo.next == NULL => last (if fifo.base != NULL)
+ * adv->fifo.prev == NULL => first (if fifo.base != NULL)
+ */
+Inline void
+bgp_advertise_fifo_init(bgp_advertise_fifo_base base)
+{
+ base->head = NULL ;
+} ;
+
+Inline bgp_advertise
+bgp_advertise_fifo_head(bgp_advertise_fifo_base base)
+{
+ return base->head ;
+} ;
+
+Inline void
+bgp_advertise_fifo_add(bgp_advertise_fifo_base base, bgp_advertise adv)
+{
+ adv->fifo.next = NULL ;
+ adv->fifo.base = base ;
+
+ if (base->head == NULL)
+ {
+ adv->fifo.prev = NULL ;
+ base->head = adv ;
+ }
+ else
+ {
+ adv->fifo.prev = base->tail ;
+ base->tail->fifo.next = adv ;
+ } ;
+
+ base->tail = adv ;
+} ;
+
+Inline void
+bgp_advertise_fifo_del(bgp_advertise adv)
+{
+ bgp_advertise_fifo_base base = adv->fifo.base ;
+
+ if (base != NULL)
+ {
+ if (adv->fifo.next == NULL)
+ base->tail = adv->fifo.prev ;
+ else
+ adv->fifo.next->fifo.prev = adv->fifo.prev ;
+
+ if (adv->fifo.prev == NULL)
+ base->head = adv->fifo.next ;
+ else
+ adv->fifo.prev->fifo.next = adv->fifo.next ;
+
+ adv->fifo.base = NULL ;
+ } ;
+ } ;
+
/* BGP adjacency linked list. */
#define BGP_INFO_ADD(N,A,TYPE) \
do { \
@@ -132,7 +210,7 @@ extern void bgp_adj_out_set (struct bgp_node *, struct peer *, struct prefix *,
struct attr *, afi_t, safi_t, struct bgp_info *);
extern void bgp_adj_out_unset (struct bgp_node *, struct peer *, struct prefix *,
afi_t, safi_t);
-extern void bgp_adj_out_remove (struct bgp_node *, struct bgp_adj_out *,
+extern void bgp_adj_out_remove (struct bgp_node *, struct bgp_adj_out *,
struct peer *, afi_t, safi_t);
extern int bgp_adj_out_lookup (struct peer *, struct prefix *, afi_t, safi_t,
struct bgp_node *);
diff --git a/bgpd/bgp_connection.c b/bgpd/bgp_connection.c
index 2e10eaf1..5915b57f 100644
--- a/bgpd/bgp_connection.c
+++ b/bgpd/bgp_connection.c
@@ -133,11 +133,15 @@ bgp_connection_init_new(bgp_connection connection, bgp_session session,
* * msg_size none -- set when reading message
* * notification_pending nothing pending
* * wbuff all pointers NULL -- empty buffer
+ * *except* must set limit so is not "full".
*/
- confirm(bgp_fsm_Initial == 0) ;
+ confirm(bgp_fsm_sInitial == 0) ;
confirm(bgp_fsm_null_event == 0) ;
+ connection->wbuff.limit = connection->wbuff.base +
+ bgp_write_buffer_full_threshold ;
+
/* Link back to session, point at its mutex and point session here */
connection->session = session ;
connection->p_mutex = &session->mutex ;
@@ -261,7 +265,7 @@ bgp_connection_exit(bgp_connection connection)
{
bgp_connection_close(connection, 1) ; /* make sure */
- assert( (connection->state == bgp_fsm_Stopping)
+ assert( (connection->state == bgp_fsm_sStopping)
&& (connection->session == NULL) ) ;
/* Add the connection to the connection queue, in Stopped state.
@@ -285,7 +289,7 @@ bgp_connection_exit(bgp_connection connection)
static void
bgp_connection_free(bgp_connection connection)
{
- assert( (connection->state == bgp_fsm_Stopping) &&
+ assert( (connection->state == bgp_fsm_sStopping) &&
(connection->session == NULL) ) ;
/* Make sure is closed, so no active file, no timers, pending queue is empty,
@@ -417,7 +421,7 @@ bgp_connection_queue_process(void)
bgp_connection_queue = connection->next ;
/* Reap the connection if it is now stopped. */
- if (connection->state == bgp_fsm_Stopping)
+ if (connection->state == bgp_fsm_sStopping)
{
bgp_connection_free(connection) ; /* removes from connection queue */
continue ;
@@ -834,7 +838,7 @@ bgp_connection_write_action(qps_file qf, void* file_info)
/* If waiting to send NOTIFICATION, just did it. */
/* Otherwise: is writable again -- so add to connection_queue */
if (connection->notification_pending)
- bgp_fsm_event(connection, bgp_fsm_Sent_NOTIFICATION_message) ;
+ bgp_fsm_event(connection, bgp_fsm_eSent_NOTIFICATION_message) ;
else
bgp_connection_queue_add(connection) ;
} ;
diff --git a/bgpd/bgp_connection.h b/bgpd/bgp_connection.h
index 5ce623cd..24762646 100644
--- a/bgpd/bgp_connection.h
+++ b/bgpd/bgp_connection.h
@@ -49,43 +49,43 @@
typedef enum bgp_fsm_states bgp_fsm_state_t ;
enum bgp_fsm_states
{
- bgp_fsm_first_state = 0,
+ bgp_fsm_first_state = 0,
- bgp_fsm_Initial = 0, /* extra: connection initialised */
+ bgp_fsm_sInitial = 0, /* extra: connection initialised */
- bgp_fsm_Idle = 1, /* waiting for Idle Hold time */
- bgp_fsm_Connect = 2, /* waiting for connect (may be listening) */
- bgp_fsm_Active = 3, /* listening only */
- bgp_fsm_OpenSent = 4, /* sent Open -- awaits Open */
- bgp_fsm_OpenConfirm = 5, /* sent & received Open -- awaits keepalive */
- bgp_fsm_Established = 6, /* running connection */
+ bgp_fsm_sIdle = 1, /* waiting for Idle Hold time */
+ bgp_fsm_sConnect = 2, /* waiting for connect (may be listening) */
+ bgp_fsm_sActive = 3, /* listening only */
+ bgp_fsm_sOpenSent = 4, /* sent Open -- awaits Open */
+ bgp_fsm_sOpenConfirm = 5, /* sent & received Open -- awaits keepalive */
+ bgp_fsm_sEstablished = 6, /* running connection */
- bgp_fsm_Stopping = 7, /* extra: connection shutting down */
+ bgp_fsm_sStopping = 7, /* extra: connection shutting down */
- bgp_fsm_last_state = 7,
+ bgp_fsm_last_state = 7,
} ;
typedef enum bgp_fsm_events bgp_fsm_event_t ;
enum bgp_fsm_events
{
- bgp_fsm_null_event = 0,
-
- bgp_fsm_BGP_Start = 1,
- bgp_fsm_BGP_Stop = 2,
- bgp_fsm_TCP_connection_open = 3,
- bgp_fsm_TCP_connection_closed = 4,
- bgp_fsm_TCP_connection_open_failed = 5,
- bgp_fsm_TCP_fatal_error = 6,
- bgp_fsm_ConnectRetry_timer_expired = 7,
- bgp_fsm_Hold_Timer_expired = 8,
- bgp_fsm_KeepAlive_timer_expired = 9,
- bgp_fsm_Receive_OPEN_message = 10,
- bgp_fsm_Receive_KEEPALIVE_message = 11,
- bgp_fsm_Receive_UPDATE_message = 12,
- bgp_fsm_Receive_NOTIFICATION_message = 13,
- bgp_fsm_Sent_NOTIFICATION_message = 14,
-
- bgp_fsm_last_event = 15,
+ bgp_fsm_null_event = 0,
+
+ bgp_fsm_eBGP_Start = 1,
+ bgp_fsm_eBGP_Stop = 2,
+ bgp_fsm_eTCP_connection_open = 3,
+ bgp_fsm_eTCP_connection_closed = 4,
+ bgp_fsm_eTCP_connection_open_failed = 5,
+ bgp_fsm_eTCP_fatal_error = 6,
+ bgp_fsm_eConnectRetry_timer_expired = 7,
+ bgp_fsm_eHold_Timer_expired = 8,
+ bgp_fsm_eKeepAlive_timer_expired = 9,
+ bgp_fsm_eReceive_OPEN_message = 10,
+ bgp_fsm_eReceive_KEEPALIVE_message = 11,
+ bgp_fsm_eReceive_UPDATE_message = 12,
+ bgp_fsm_eReceive_NOTIFICATION_message = 13,
+ bgp_fsm_eSent_NOTIFICATION_message = 14,
+
+ bgp_fsm_last_event = 15,
} ;
/*==============================================================================
@@ -98,6 +98,21 @@ enum bgp_fsm_events
*
*/
+/* NB: p_out == p_in => buffer is empty
+ *
+ * BUT: buffer is not allocated until required, and until then
+ * p_out == p_in == NULL -- empty does NOT imply usable !
+ *
+ * AND: when buffer is emptied, p_out and p_in will be some way down the
+ * buffer.
+ *
+ * SO: before writing, check for base != NULL and set p_out = p_in = base.
+ *
+ * NB: before buffer is allocated base == NULL, but limit is set to NULL + n,
+ * so that buffer does not appear full.
+ *
+ * SO: not full does NOT imply that p_out/p_in/base are set, either !
+ */
typedef struct bgp_wbuffer* bgp_wbuffer ;
struct bgp_wbuffer
{
@@ -108,10 +123,6 @@ struct bgp_wbuffer
uint8_t* limit ;
} ;
-/* TODO: management of the pending_queue... */
-/* need something at the Engine level to drain the pending queue */
-/* when/while obuf is not full.... */
-/* need to be able to activate and deactivate that */
struct bgp_connection
{
@@ -221,7 +232,10 @@ bgp_connection_queue_process(void) ;
/*------------------------------------------------------------------------------
- * Full if not enough room for a maximum size BGP message.
+ * See if have enough room for what want to write PLUS 1.
+ *
+ * NB: caller must ensure buffer has been allocated, which will be true if
+ * has found that the buffer is not empty !
*/
Inline int
bgp_write_buffer_can(bgp_wbuffer wb, size_t want)
@@ -231,11 +245,15 @@ bgp_write_buffer_can(bgp_wbuffer wb, size_t want)
/*------------------------------------------------------------------------------
* Full if not enough room for a maximum size BGP message + 1
+ *
+ * NB: this will be true even if the buffer has not been allocated (!).
*/
+enum { bgp_write_buffer_full_threshold = BGP_MSG_MAX_L + 1 } ;
+
Inline int
bgp_write_buffer_full(bgp_wbuffer wb)
{
- return bgp_write_buffer_can(wb, BGP_MSG_MAX_L + 1) ;
+ return bgp_write_buffer_can(wb, BGP_MSG_MAX_L) ;
} ;
/*------------------------------------------------------------------------------
diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c
index d86ddfc7..78ac799d 100644
--- a/bgpd/bgp_debug.c
+++ b/bgpd/bgp_debug.c
@@ -66,14 +66,14 @@ unsigned long term_bgp_debug_zebra;
/* messages for BGP-4 status */
const struct message bgp_status_msg[] =
{
- { bgp_fsm_Initial, "Initial" },
- { bgp_fsm_Idle, "Idle" },
- { bgp_fsm_Connect, "Connect" },
- { bgp_fsm_Active, "Active" },
- { bgp_fsm_OpenSent, "OpenSent" },
- { bgp_fsm_OpenConfirm, "OpenConfirm" },
- { bgp_fsm_Established, "Established" },
- { bgp_fsm_Stopping, "Stopping" },
+ { bgp_fsm_sInitial, "Initial" },
+ { bgp_fsm_sIdle, "Idle" },
+ { bgp_fsm_sConnect, "Connect" },
+ { bgp_fsm_sActive, "Active" },
+ { bgp_fsm_sOpenSent, "OpenSent" },
+ { bgp_fsm_sOpenConfirm, "OpenConfirm" },
+ { bgp_fsm_sEstablished, "Established" },
+ { bgp_fsm_sStopping, "Stopping" },
};
const int bgp_status_msg_max = bgp_fsm_last_state + 1 ;
@@ -280,14 +280,14 @@ bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
peer->host, bgp_notify->code, bgp_notify->subcode,
LOOKUP (bgp_notify_msg, bgp_notify->code),
subcode_str, bgp_notify->length,
- bgp_notify->size ? bgp_notify->data : "");
+ bgp_notify->size ? (const char*)bgp_notify->data : "");
else if (BGP_DEBUG (normal, NORMAL))
plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
peer ? peer->host : "",
direct, bgp_notify->code, bgp_notify->subcode,
LOOKUP (bgp_notify_msg, bgp_notify->code),
subcode_str, bgp_notify->length,
- bgp_notify->size ? bgp_notify->data : "");
+ bgp_notify->size ? (const char*)bgp_notify->data : "");
}
/* Debug option setting interface. */
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index cb899797..a3af93b7 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -23,7 +23,6 @@
*/
#include <zebra.h>
-//#include "bgpd/bgp.h"
#include "log.h"
@@ -32,6 +31,7 @@
#include "bgpd/bgp_notification.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_msg_write.h"
+#include "bgpd/bgp_msg_read.h"
#include "lib/qtimers.h"
#include "lib/sockunion.h"
@@ -411,7 +411,7 @@ bgp_fsm_enable_session(bgp_session session)
{
connection = bgp_connection_init_new(NULL, session,
bgp_connection_primary) ;
- bgp_fsm_event(connection, bgp_fsm_BGP_Start) ;
+ bgp_fsm_event(connection, bgp_fsm_eBGP_Start) ;
} ;
/* Secondary connection -- if listen allowed
@@ -420,7 +420,7 @@ bgp_fsm_enable_session(bgp_session session)
{
connection = bgp_connection_init_new(NULL, session,
bgp_connection_secondary) ;
- bgp_fsm_event(connection, bgp_fsm_BGP_Start) ;
+ bgp_fsm_event(connection, bgp_fsm_eBGP_Start) ;
} ;
} ;
@@ -479,7 +479,7 @@ bgp_fsm_disable_session(bgp_session session, bgp_notify notification)
if (connection != NULL)
bgp_fsm_throw_exception(connection, bgp_session_eDisabled, notification, 0,
- bgp_fsm_BGP_Stop) ;
+ bgp_fsm_eBGP_Stop) ;
else
bgp_notify_free(notification) ;
} ;
@@ -489,14 +489,17 @@ bgp_fsm_disable_session(bgp_session session, bgp_notify notification)
*
* Note that I/O problems are signalled by bgp_fsm_io_error().
*
- * NB: may NOT be used within the FSM.
+ * NB: can raise an exception for other connections while in the FSM.
+ *
+ * can raise an exception for the current connection while in the FSM, the
+ * fsm_active/post mechanism looks after this.
*/
extern void
bgp_fsm_raise_exception(bgp_connection connection, bgp_session_event_t except,
bgp_notify notification)
{
bgp_fsm_throw_exception(connection, except, notification, 0,
- bgp_fsm_BGP_Stop) ;
+ bgp_fsm_eBGP_Stop) ;
} ;
/*------------------------------------------------------------------------------
@@ -510,15 +513,13 @@ bgp_fsm_raise_exception(bgp_connection connection, bgp_session_event_t except,
*
* * it has reached Established state, and is snuffing out the sibling.
*
- *
- *
* NB: requires the session LOCKED
*/
static void
bgp_fsm_discard_sibling(bgp_connection sibling, bgp_notify notification)
{
bgp_fsm_throw_exception(sibling, bgp_session_eDiscard,
- notification, 0, bgp_fsm_BGP_Stop) ;
+ notification, 0, bgp_fsm_eBGP_Stop) ;
} ;
/*------------------------------------------------------------------------------
@@ -529,7 +530,7 @@ bgp_fsm_notification_exception(bgp_connection connection,
bgp_notify notification)
{
bgp_fsm_throw_exception(connection, bgp_session_eNOM_recv, notification, 0,
- bgp_fsm_Receive_NOTIFICATION_message) ;
+ bgp_fsm_eReceive_NOTIFICATION_message) ;
} ;
/*------------------------------------------------------------------------------
@@ -544,7 +545,7 @@ bgp_fsm_io_fatal_error(bgp_connection connection, int err)
connection->host, safe_strerror(err)) ;
bgp_fsm_throw_exception(connection, bgp_session_eTCP_error, NULL, err,
- bgp_fsm_TCP_fatal_error) ;
+ bgp_fsm_eTCP_fatal_error) ;
} ;
/*------------------------------------------------------------------------------
@@ -588,7 +589,7 @@ bgp_fsm_io_error(bgp_connection connection, int err)
} ;
bgp_fsm_throw_exception(connection, bgp_session_eTCP_dropped, NULL, err,
- bgp_fsm_TCP_connection_closed) ;
+ bgp_fsm_eTCP_connection_closed) ;
}
else
bgp_fsm_io_fatal_error(connection, err) ;
@@ -619,7 +620,7 @@ bgp_fsm_connect_completed(bgp_connection connection, int err,
{
if (err == 0)
{
- bgp_fsm_event(connection, bgp_fsm_TCP_connection_open) ;
+ bgp_fsm_event(connection, bgp_fsm_eTCP_connection_open) ;
sockunion_set_dup(&connection->su_local, su_local) ;
sockunion_set_dup(&connection->su_remote, su_remote) ;
@@ -629,7 +630,7 @@ bgp_fsm_connect_completed(bgp_connection connection, int err,
|| (err == EHOSTUNREACH)
|| (err == ETIMEDOUT) )
bgp_fsm_throw_exception(connection, bgp_session_eTCP_failed, NULL, err,
- bgp_fsm_TCP_connection_open_failed) ;
+ bgp_fsm_eTCP_connection_open_failed) ;
else
bgp_fsm_io_fatal_error(connection, err) ;
} ;
@@ -648,9 +649,9 @@ bgp_fsm_post_exception(bgp_connection connection, bgp_session_event_t except,
{
connection->except = except ;
- if ( (connection->state != bgp_fsm_OpenSent)
- && (connection->state != bgp_fsm_OpenConfirm)
- && (connection->state != bgp_fsm_Established) )
+ if ( (connection->state != bgp_fsm_sOpenSent)
+ && (connection->state != bgp_fsm_sOpenConfirm)
+ && (connection->state != bgp_fsm_sEstablished) )
bgp_notify_unset(&notification) ;
bgp_notify_set(&connection->notification, notification) ;
@@ -983,21 +984,21 @@ bgp_fsm[bgp_fsm_last_state + 1][bgp_fsm_last_event + 1] =
*
* All other events (other than null) are invalid (should not happen).
*/
- {bgp_fsm_null, bgp_fsm_Initial}, /* null event */
- {bgp_fsm_enter, bgp_fsm_Idle}, /* BGP_Start */
- {bgp_fsm_stop, bgp_fsm_Initial}, /* BGP_Stop */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_closed */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open_failed */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_fatal_error */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* ConnectRetry_timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Hold_Timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* KeepAlive_timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_OPEN_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_KEEPALIVE_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_UPDATE_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_NOTIFICATION_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Sent NOTIFICATION message */
+ {bgp_fsm_null, bgp_fsm_sInitial}, /* null event */
+ {bgp_fsm_enter, bgp_fsm_sIdle}, /* BGP_Start */
+ {bgp_fsm_stop, bgp_fsm_sInitial}, /* BGP_Stop */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_closed */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open_failed */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_fatal_error */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* ConnectRetry_timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Hold_Timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* KeepAlive_timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_OPEN_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_KEEPALIVE_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_UPDATE_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_NOTIFICATION_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Sent NOTIFICATION message */
},
{
/* bgp_fsm_Idle: waiting for IdleHoldTimer..................................
@@ -1045,21 +1046,21 @@ bgp_fsm[bgp_fsm_last_state + 1][bgp_fsm_last_event + 1] =
*
* All other events (other than null) are invalid (should not happen).
*/
- {bgp_fsm_null, bgp_fsm_Idle}, /* null event */
- {bgp_fsm_start, bgp_fsm_Connect}, /* BGP_Start */
- {bgp_fsm_stop, bgp_fsm_Idle}, /* BGP_Stop */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_closed */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open_failed */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_fatal_error */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* ConnectRetry_timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Hold_Timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* KeepAlive_timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_OPEN_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_KEEPALIVE_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_UPDATE_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_NOTIFICATION_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Sent NOTIFICATION message */
+ {bgp_fsm_null, bgp_fsm_sIdle}, /* null event */
+ {bgp_fsm_start, bgp_fsm_sConnect}, /* BGP_Start */
+ {bgp_fsm_stop, bgp_fsm_sIdle}, /* BGP_Stop */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_closed */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open_failed */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_fatal_error */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* ConnectRetry_timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Hold_Timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* KeepAlive_timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_OPEN_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_KEEPALIVE_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_UPDATE_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_NOTIFICATION_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Sent NOTIFICATION message */
},
{
/* bgp_fsm_Connect: waiting for connect (and listen)........................
@@ -1095,21 +1096,21 @@ bgp_fsm[bgp_fsm_last_state + 1][bgp_fsm_last_event + 1] =
*
* All other events (other than null) are invalid (should not happen).
*/
- {bgp_fsm_null, bgp_fsm_Connect}, /* null event */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* BGP_Start */
- {bgp_fsm_stop, bgp_fsm_Connect}, /* BGP_Stop */
- {bgp_fsm_send_open, bgp_fsm_OpenSent}, /* TCP_connection_open */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_closed */
- {bgp_fsm_failed, bgp_fsm_Connect}, /* TCP_connection_open_failed */
- {bgp_fsm_fatal, bgp_fsm_Connect}, /* TCP_fatal_error */
- {bgp_fsm_retry, bgp_fsm_Connect}, /* ConnectRetry_timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Hold_Timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* KeepAlive_timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_OPEN_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_KEEPALIVE_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_UPDATE_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_NOTIFICATION_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Sent NOTIFICATION message */
+ {bgp_fsm_null, bgp_fsm_sConnect}, /* null event */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* BGP_Start */
+ {bgp_fsm_stop, bgp_fsm_sConnect}, /* BGP_Stop */
+ {bgp_fsm_send_open, bgp_fsm_sOpenSent}, /* TCP_connection_open */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_closed */
+ {bgp_fsm_failed, bgp_fsm_sConnect}, /* TCP_connection_open_failed */
+ {bgp_fsm_fatal, bgp_fsm_sConnect}, /* TCP_fatal_error */
+ {bgp_fsm_retry, bgp_fsm_sConnect}, /* ConnectRetry_timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Hold_Timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* KeepAlive_timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_OPEN_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_KEEPALIVE_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_UPDATE_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_NOTIFICATION_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Sent NOTIFICATION message */
},
{
/* bgp_fsm_Active: waiting for listen (only)................................
@@ -1144,21 +1145,21 @@ bgp_fsm[bgp_fsm_last_state + 1][bgp_fsm_last_event + 1] =
*
* All other events (other than null) are invalid (should not happen).
*/
- {bgp_fsm_null, bgp_fsm_Active}, /* null event */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* BGP_Start */
- {bgp_fsm_stop, bgp_fsm_Active}, /* BGP_Stop */
- {bgp_fsm_send_open, bgp_fsm_OpenSent}, /* TCP_connection_open */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_closed */
- {bgp_fsm_failed, bgp_fsm_Active}, /* TCP_connection_open_failed */
- {bgp_fsm_fatal, bgp_fsm_Active}, /* TCP_fatal_error */
- {bgp_fsm_retry, bgp_fsm_Active}, /* ConnectRetry_timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Hold_Timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* KeepAlive_timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_OPEN_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_KEEPALIVE_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_UPDATE_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_NOTIFICATION_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Sent NOTIFICATION message */
+ {bgp_fsm_null, bgp_fsm_sActive}, /* null event */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* BGP_Start */
+ {bgp_fsm_stop, bgp_fsm_sActive}, /* BGP_Stop */
+ {bgp_fsm_send_open, bgp_fsm_sOpenSent}, /* TCP_connection_open */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_closed */
+ {bgp_fsm_failed, bgp_fsm_sActive}, /* TCP_connection_open_failed */
+ {bgp_fsm_fatal, bgp_fsm_sActive}, /* TCP_fatal_error */
+ {bgp_fsm_retry, bgp_fsm_sActive}, /* ConnectRetry_timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Hold_Timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* KeepAlive_timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_OPEN_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_KEEPALIVE_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_UPDATE_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_NOTIFICATION_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Sent NOTIFICATION message */
},
{
/* bgp_fsm_OpenSent: waiting for Open from the other end....................
@@ -1211,21 +1212,21 @@ bgp_fsm[bgp_fsm_last_state + 1][bgp_fsm_last_event + 1] =
*
* All other events (other than null) are invalid (should not happen).
*/
- {bgp_fsm_null, bgp_fsm_OpenSent}, /* null event */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* BGP_Start */
- {bgp_fsm_stop, bgp_fsm_Idle}, /* BGP_Stop */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open */
- {bgp_fsm_closed, bgp_fsm_Idle}, /* TCP_connection_closed */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open_failed */
- {bgp_fsm_fatal, bgp_fsm_Idle}, /* TCP_fatal_error */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* ConnectRetry_timer_expired */
- {bgp_fsm_expire, bgp_fsm_Idle}, /* Hold_Timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* KeepAlive_timer_expired */
- {bgp_fsm_recv_open, bgp_fsm_OpenConfirm}, /* Receive_OPEN_message */
- {bgp_fsm_error, bgp_fsm_OpenSent}, /* Receive_KEEPALIVE_message */
- {bgp_fsm_error, bgp_fsm_OpenSent}, /* Receive_UPDATE_message */
- {bgp_fsm_recv_nom, bgp_fsm_Idle}, /* Receive_NOTIFICATION_message */
- {bgp_fsm_sent_nom, bgp_fsm_OpenSent}, /* Sent NOTIFICATION message */
+ {bgp_fsm_null, bgp_fsm_sOpenSent}, /* null event */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* BGP_Start */
+ {bgp_fsm_stop, bgp_fsm_sIdle}, /* BGP_Stop */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open */
+ {bgp_fsm_closed, bgp_fsm_sIdle}, /* TCP_connection_closed */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open_failed */
+ {bgp_fsm_fatal, bgp_fsm_sIdle}, /* TCP_fatal_error */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* ConnectRetry_timer_expired */
+ {bgp_fsm_expire, bgp_fsm_sIdle}, /* Hold_Timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* KeepAlive_timer_expired */
+ {bgp_fsm_recv_open, bgp_fsm_sOpenConfirm},/* Receive_OPEN_message */
+ {bgp_fsm_error, bgp_fsm_sOpenSent}, /* Receive_KEEPALIVE_message */
+ {bgp_fsm_error, bgp_fsm_sOpenSent}, /* Receive_UPDATE_message */
+ {bgp_fsm_recv_nom, bgp_fsm_sIdle}, /* Receive_NOTIFICATION_message */
+ {bgp_fsm_sent_nom, bgp_fsm_sOpenSent}, /* Sent NOTIFICATION message */
},
{
/* bgp_fsm_OpenConfirm: Opens sent and received, waiting for KeepAlive......
@@ -1291,21 +1292,21 @@ bgp_fsm[bgp_fsm_last_state + 1][bgp_fsm_last_event + 1] =
*
* All other events (other than null) are invalid (should not happen).
*/
- {bgp_fsm_null, bgp_fsm_OpenConfirm}, /* null event */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* BGP_Start */
- {bgp_fsm_stop, bgp_fsm_Idle}, /* BGP_Stop */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open */
- {bgp_fsm_closed, bgp_fsm_Idle}, /* TCP_connection_closed */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open_failed */
- {bgp_fsm_fatal, bgp_fsm_Idle}, /* TCP_fatal_error */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* ConnectRetry_timer_expired */
- {bgp_fsm_expire, bgp_fsm_Idle}, /* Hold_Timer_expired */
- {bgp_fsm_send_kal, bgp_fsm_OpenConfirm}, /* KeepAlive_timer_expired */
- {bgp_fsm_error, bgp_fsm_OpenConfirm}, /* Receive_OPEN_message */
- {bgp_fsm_establish, bgp_fsm_Established}, /* Receive_KEEPALIVE_message */
- {bgp_fsm_error, bgp_fsm_OpenConfirm}, /* Receive_UPDATE_message */
- {bgp_fsm_recv_nom, bgp_fsm_Idle}, /* Receive_NOTIFICATION_message */
- {bgp_fsm_sent_nom, bgp_fsm_OpenConfirm}, /* Sent NOTIFICATION message */
+ {bgp_fsm_null, bgp_fsm_sOpenConfirm},/* null event */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* BGP_Start */
+ {bgp_fsm_stop, bgp_fsm_sIdle}, /* BGP_Stop */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open */
+ {bgp_fsm_closed, bgp_fsm_sIdle}, /* TCP_connection_closed */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open_failed */
+ {bgp_fsm_fatal, bgp_fsm_sIdle}, /* TCP_fatal_error */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* ConnectRetry_timer_expired */
+ {bgp_fsm_expire, bgp_fsm_sIdle}, /* Hold_Timer_expired */
+ {bgp_fsm_send_kal, bgp_fsm_sOpenConfirm},/* KeepAlive_timer_expired */
+ {bgp_fsm_error, bgp_fsm_sOpenConfirm},/* Receive_OPEN_message */
+ {bgp_fsm_establish, bgp_fsm_sEstablished},/* Receive_KEEPALIVE_message */
+ {bgp_fsm_error, bgp_fsm_sOpenConfirm},/* Receive_UPDATE_message */
+ {bgp_fsm_recv_nom, bgp_fsm_sIdle}, /* Receive_NOTIFICATION_message */
+ {bgp_fsm_sent_nom, bgp_fsm_sOpenConfirm},/* Sent NOTIFICATION message */
},
{
/* bgp_fsm_Established: session is up and running...........................
@@ -1354,21 +1355,21 @@ bgp_fsm[bgp_fsm_last_state + 1][bgp_fsm_last_event + 1] =
*
* All other events (other than null) are invalid (should not happen).
*/
- {bgp_fsm_null, bgp_fsm_Established}, /* null event */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* BGP_Start */
- {bgp_fsm_stop, bgp_fsm_Stopping}, /* BGP_Stop */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open */
- {bgp_fsm_closed, bgp_fsm_Stopping}, /* TCP_connection_closed */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open_failed */
- {bgp_fsm_fatal, bgp_fsm_Stopping}, /* TCP_fatal_error */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* ConnectRetry_timer_expired */
- {bgp_fsm_expire, bgp_fsm_Stopping}, /* Hold_Timer_expired */
- {bgp_fsm_send_kal, bgp_fsm_Established}, /* KeepAlive_timer_expired */
- {bgp_fsm_error, bgp_fsm_Stopping}, /* Receive_OPEN_message */
- {bgp_fsm_recv_kal, bgp_fsm_Established}, /* Receive_KEEPALIVE_message */
- {bgp_fsm_update, bgp_fsm_Established}, /* Receive_UPDATE_message */
- {bgp_fsm_recv_nom, bgp_fsm_Stopping}, /* Receive_NOTIFICATION_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Sent NOTIFICATION message */
+ {bgp_fsm_null, bgp_fsm_sEstablished},/* null event */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* BGP_Start */
+ {bgp_fsm_stop, bgp_fsm_sStopping}, /* BGP_Stop */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open */
+ {bgp_fsm_closed, bgp_fsm_sStopping}, /* TCP_connection_closed */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open_failed */
+ {bgp_fsm_fatal, bgp_fsm_sStopping}, /* TCP_fatal_error */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* ConnectRetry_timer_expired */
+ {bgp_fsm_expire, bgp_fsm_sStopping}, /* Hold_Timer_expired */
+ {bgp_fsm_send_kal, bgp_fsm_sEstablished},/* KeepAlive_timer_expired */
+ {bgp_fsm_error, bgp_fsm_sStopping}, /* Receive_OPEN_message */
+ {bgp_fsm_recv_kal, bgp_fsm_sEstablished},/* Receive_KEEPALIVE_message */
+ {bgp_fsm_update, bgp_fsm_sEstablished},/* Receive_UPDATE_message */
+ {bgp_fsm_recv_nom, bgp_fsm_sStopping}, /* Receive_NOTIFICATION_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Sent NOTIFICATION message */
},
{
/* bgp_fsm_Stopping: waiting (briefly) to send Notification.................
@@ -1471,21 +1472,21 @@ bgp_fsm[bgp_fsm_last_state + 1][bgp_fsm_last_event + 1] =
*
* All other events (other than null) are invalid (should not happen).
*/
- {bgp_fsm_null, bgp_fsm_Stopping}, /* null event */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* BGP_Start */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* BGP_Stop */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open */
- {bgp_fsm_exit, bgp_fsm_Stopping}, /* TCP_connection_closed */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* TCP_connection_open_failed */
- {bgp_fsm_exit, bgp_fsm_Stopping}, /* TCP_fatal_error */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* ConnectRetry_timer_expired */
- {bgp_fsm_exit, bgp_fsm_Stopping}, /* Hold_Timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* KeepAlive_timer_expired */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_OPEN_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_KEEPALIVE_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_UPDATE_message */
- {bgp_fsm_invalid, bgp_fsm_Stopping}, /* Receive_NOTIFICATION_message */
- {bgp_fsm_sent_nom, bgp_fsm_Stopping}, /* Sent NOTIFICATION message */
+ {bgp_fsm_null, bgp_fsm_sStopping}, /* null event */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* BGP_Start */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* BGP_Stop */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open */
+ {bgp_fsm_exit, bgp_fsm_sStopping}, /* TCP_connection_closed */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* TCP_connection_open_failed */
+ {bgp_fsm_exit, bgp_fsm_sStopping}, /* TCP_fatal_error */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* ConnectRetry_timer_expired */
+ {bgp_fsm_exit, bgp_fsm_sStopping}, /* Hold_Timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* KeepAlive_timer_expired */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_OPEN_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_KEEPALIVE_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_UPDATE_message */
+ {bgp_fsm_invalid, bgp_fsm_sStopping}, /* Receive_NOTIFICATION_message */
+ {bgp_fsm_sent_nom, bgp_fsm_sStopping}, /* Sent NOTIFICATION message */
},
} ;
@@ -1618,7 +1619,7 @@ bgp_fsm_event(bgp_connection connection, bgp_fsm_event_t event)
connection->notification,
connection->err,
connection->ordinal,
- (connection->state == bgp_fsm_Stopping)) ;
+ (connection->state == bgp_fsm_sStopping)) ;
/* Tidy up -- notification already cleared */
connection->except = bgp_session_null_event ;
@@ -1684,11 +1685,11 @@ static bgp_fsm_action(bgp_fsm_enter)
static bgp_fsm_action(bgp_fsm_stop)
{
if (connection->except == bgp_session_null_event)
- return bgp_fsm_invalid(connection, bgp_fsm_Stopping, event) ;
+ return bgp_fsm_invalid(connection, bgp_fsm_sStopping, event) ;
if ( (connection->except == bgp_session_eDisabled)
|| (connection->except == bgp_session_eDiscard) )
- next_state = bgp_fsm_Stopping ;
+ next_state = bgp_fsm_sStopping ;
return bgp_fsm_catch(connection, next_state) ;
} ;
@@ -1710,12 +1711,12 @@ static bgp_fsm_action(bgp_fsm_invalid)
plog_debug(connection->log, "%s [FSM] invalid event %d in state %d",
connection->host, event, connection->state) ;
- if (connection->state != bgp_fsm_Stopping)
+ if (connection->state != bgp_fsm_sStopping)
return bgp_fsm_post_catch(connection, bgp_session_eInvalid,
bgp_notify_new(BGP_NOMC_FSM, BGP_NOMS_UNSPECIFIC, 0),
- bgp_fsm_Stopping) ;
+ bgp_fsm_sStopping) ;
else
- return bgp_fsm_exit(connection, bgp_fsm_Stopping, event) ;
+ return bgp_fsm_exit(connection, bgp_fsm_sStopping, event) ;
} ;
/*------------------------------------------------------------------------------
@@ -1743,12 +1744,12 @@ static bgp_fsm_action(bgp_fsm_start)
{
if (connection->ordinal == bgp_connection_primary)
{
- next_state = bgp_fsm_Connect ;
+ next_state = bgp_fsm_sConnect ;
bgp_open_connect(connection) ;
}
else
{
- next_state = bgp_fsm_Active ;
+ next_state = bgp_fsm_sActive ;
bgp_connection_enable_accept(connection) ;
} ;
@@ -1919,26 +1920,41 @@ static bgp_fsm_action(bgp_fsm_recv_open)
/* If there is a sibling, and it is in OpenConfirm state, then now must do
* collision resolution.
*/
- if ((sibling != NULL) && (sibling->state == bgp_fsm_OpenConfirm))
+ if ((sibling != NULL) && (sibling->state == bgp_fsm_sOpenConfirm))
{
bgp_connection loser ;
+ /* Before choosing a winner, check that both have the same BGP Id.
+ *
+ * The two connections are to an address which is configured for the
+ * given peer, and both have given the right ASN. It would be
+ * astonishing (but also disturbing) to find that they had different
+ * BGP Ids !!!
+ */
+ if (connection->open_recv->bgp_id != sibling->open_recv->bgp_id)
+ {
+ bgp_fsm_raise_exception(sibling, bgp_session_eOpen_reject,
+ bgp_msg_noms_o_bad_id(NULL, sibling->open_recv->bgp_id)) ;
+
+ bgp_fsm_raise_exception(connection, bgp_session_eOpen_reject,
+ bgp_msg_noms_o_bad_id(NULL, connection->open_recv->bgp_id)) ;
+
+ return connection->state ;
+ } ;
+
/* NB: bgp_id in open_state is in *host* order */
loser = (ntohl(session->open_send->bgp_id) <
ntohl(sibling->open_recv->bgp_id))
? connection
: sibling ;
- /* Set reason for stopping */
- bgp_fsm_post_exception(loser, bgp_session_eCollision,
- bgp_notify_new(BGP_NOMC_CEASE, BGP_NOMS_C_COLLISION, 0), 0) ;
+ /* Throw exception */
+ bgp_fsm_raise_exception(loser, bgp_session_eCollision,
+ bgp_notify_new(BGP_NOMC_CEASE, BGP_NOMS_C_COLLISION, 0)) ;
- /* If self is the loser, treat this as a BGP_Stop event ! */
- /* Otherwise, issue BGP_Stop event for sibling. */
+ /* If self is the loser, exit now to process the eBGP_Stop */
if (loser == connection)
- return bgp_fsm_catch(connection, next_state) ;
- else
- bgp_fsm_event(sibling, bgp_fsm_BGP_Stop) ;
+ return connection->state ;
} ;
/* All is well: send a KEEPALIVE message to acknowledge the OPEN */
@@ -2033,6 +2049,7 @@ static bgp_fsm_action(bgp_fsm_establish)
bgp_connection_make_primary(connection) ;
/* Post exciting session event */
+ session->made = 1 ;
bgp_fsm_post_exception(connection, bgp_session_eEstablished, NULL, 0) ;
/* TODO: now would be a good time to withdraw the password from listener ? */
@@ -2074,11 +2091,11 @@ static bgp_fsm_action(bgp_fsm_update)
*/
static bgp_fsm_action(bgp_fsm_exit)
{
- assert(connection->state == bgp_fsm_Stopping) ;
+ assert(connection->state == bgp_fsm_sStopping) ;
bgp_connection_exit(connection) ;
- return bgp_fsm_Stopping ;
+ return bgp_fsm_sStopping ;
} ;
/*==============================================================================
@@ -2133,15 +2150,13 @@ bgp_fsm_catch(bgp_connection connection, bgp_fsm_state_t next_state)
*/
if ( (connection->notification != NULL)
&& (connection->except != bgp_session_eNOM_recv) )
- {
- next_state = bgp_fsm_send_notification(connection, next_state) ;
- }
+ next_state = bgp_fsm_send_notification(connection, next_state) ;
else
bgp_connection_close(connection, 0) ; /* FSM deals with timers */
/* If stopping and not eDiscard, do in any sibling */
- if ( (next_state == bgp_fsm_Stopping)
+ if ( (next_state == bgp_fsm_sStopping)
&& (connection->except != bgp_session_eDiscard) )
{
bgp_connection sibling ;
@@ -2183,7 +2198,7 @@ bgp_fsm_send_notification(bgp_connection connection, bgp_fsm_state_t next_state)
* HoldTimer expires -- either because lost patience in getting the
* notification away, or at the end of the "courtesy" time.
*/
- if (next_state != bgp_fsm_Stopping)
+ if (next_state != bgp_fsm_sStopping)
next_state = connection->state ;
/* Close for reading and flush write buffers. */
@@ -2203,7 +2218,7 @@ bgp_fsm_send_notification(bgp_connection connection, bgp_fsm_state_t next_state)
*
* Send ourselves the good news !
*/
- bgp_fsm_event(connection, bgp_fsm_Sent_NOTIFICATION_message) ;
+ bgp_fsm_event(connection, bgp_fsm_eSent_NOTIFICATION_message) ;
else if (ret == 0)
/* notification is sitting in the write buffer
@@ -2215,7 +2230,7 @@ bgp_fsm_send_notification(bgp_connection connection, bgp_fsm_state_t next_state)
* to happen in anything except Established state -- but copes. (Is
* ready to wait 20 seconds in Stopping state and 5 otherwise.)
*/
- bgp_hold_timer_set(connection, (next_state == bgp_fsm_Stopping) ? 20 : 5) ;
+ bgp_hold_timer_set(connection, (next_state == bgp_fsm_sStopping) ? 20 : 5) ;
/* Return suitable state. */
return next_state ;
@@ -2343,17 +2358,17 @@ bgp_fsm_state_change(bgp_connection connection, bgp_fsm_state_t new_state)
*
* In Idle state refuses connections.
*/
- case bgp_fsm_Idle:
+ case bgp_fsm_sIdle:
interval = session->idle_hold_timer_interval ;
sibling = bgp_connection_get_sibling(connection) ;
- if (connection->state == bgp_fsm_Initial)
+ if (connection->state == bgp_fsm_sInitial)
interval = (interval > 0) ? interval : 1 ; /* may not be zero */
else
{
if ( (sibling != NULL)
- && ( (sibling->state == bgp_fsm_OpenSent)
- || (sibling->state == bgp_fsm_OpenConfirm) ) )
+ && ( (sibling->state == bgp_fsm_sOpenSent)
+ || (sibling->state == bgp_fsm_sOpenConfirm) ) )
{
interval = 0 ; /* unset the HoldTimer */
connection->comatose = 1 ; /* so now comatose */
@@ -2398,8 +2413,8 @@ bgp_fsm_state_change(bgp_connection connection, bgp_fsm_state_t new_state)
* The ConnectRetryTimer automatically recharges, because will loop back
* round into the same state.
*/
- case bgp_fsm_Connect:
- case bgp_fsm_Active:
+ case bgp_fsm_sConnect:
+ case bgp_fsm_sActive:
bgp_timer_set(connection, &connection->hold_timer,
session->connect_retry_timer_interval, 1,
bgp_connect_retry_timer_action) ;
@@ -2419,7 +2434,7 @@ bgp_fsm_state_change(bgp_connection connection, bgp_fsm_state_t new_state)
*
* * an accept() connection, then session->accept will be false.
*/
- case bgp_fsm_OpenSent:
+ case bgp_fsm_sOpenSent:
bgp_hold_timer_set(connection, session->open_hold_timer_interval) ;
qtimer_unset(&connection->keepalive_timer) ;
break;
@@ -2446,11 +2461,11 @@ bgp_fsm_state_change(bgp_connection connection, bgp_fsm_state_t new_state)
* If the negotiated Hold Time value is zero, then the Keepalive Time
* value will also be zero, and this will unset both timers.
*/
- case bgp_fsm_OpenConfirm:
+ case bgp_fsm_sOpenConfirm:
bgp_timer_set(connection, &connection->keepalive_timer,
connection->keepalive_timer_interval, 1,
bgp_keepalive_timer_action) ;
- case bgp_fsm_Established:
+ case bgp_fsm_sEstablished:
bgp_hold_timer_set(connection, connection->hold_timer_interval) ;
break;
@@ -2460,7 +2475,7 @@ bgp_fsm_state_change(bgp_connection connection, bgp_fsm_state_t new_state)
*
* Unlink connection from session.
*/
- case bgp_fsm_Stopping:
+ case bgp_fsm_sStopping:
if (!connection->notification_pending)
qtimer_unset(&connection->hold_timer) ;
@@ -2539,7 +2554,7 @@ bgp_idle_hold_timer_action(qtimer qtr, void* timer_info, qtime_mono_t when)
BGP_FSM_DEBUG(connection, "Timer (start timer expire)") ;
- bgp_fsm_event(connection, bgp_fsm_BGP_Start) ;
+ bgp_fsm_event(connection, bgp_fsm_eBGP_Start) ;
} ;
/*------------------------------------------------------------------------------
@@ -2558,7 +2573,7 @@ bgp_connect_retry_timer_action(qtimer qtr, void* timer_info, qtime_mono_t when)
bgp_timer_set(connection, &connection->hold_timer,
connection->session->connect_retry_timer_interval, 1, NULL) ;
- bgp_fsm_event(connection, bgp_fsm_ConnectRetry_timer_expired) ;
+ bgp_fsm_event(connection, bgp_fsm_eConnectRetry_timer_expired) ;
} ;
/*------------------------------------------------------------------------------
@@ -2573,7 +2588,7 @@ bgp_hold_timer_action(qtimer qtr, void* timer_info, qtime_mono_t when)
BGP_FSM_DEBUG(connection, "Timer (holdtime timer expire)") ;
- bgp_fsm_event(connection, bgp_fsm_Hold_Timer_expired) ;
+ bgp_fsm_event(connection, bgp_fsm_eHold_Timer_expired) ;
} ;
/*------------------------------------------------------------------------------
@@ -2592,37 +2607,5 @@ bgp_keepalive_timer_action(qtimer qtr, void* timer_info, qtime_mono_t when)
bgp_timer_set(connection, &connection->keepalive_timer,
connection->session->keepalive_timer_interval, 1, NULL) ;
- bgp_fsm_event(connection, bgp_fsm_KeepAlive_timer_expired) ;
+ bgp_fsm_event(connection, bgp_fsm_eKeepAlive_timer_expired) ;
} ;
-
-/*============================================================================*/
-/* BGP Peer Down Cause */
-/* TODO: this is also defined in bgp_peer.c */
-#if 0
-const char *peer_down_str[] =
-{
- "",
- "Router ID changed",
- "Remote AS changed",
- "Local AS change",
- "Cluster ID changed",
- "Confederation identifier changed",
- "Confederation peer changed",
- "RR client config change",
- "RS client config change",
- "Update source change",
- "Address family activated",
- "Admin. shutdown",
- "User reset",
- "BGP Notification received",
- "BGP Notification send",
- "Peer closed the session",
- "Neighbor deleted",
- "Peer-group add member",
- "Peer-group delete member",
- "Capability changed",
- "Passive config change",
- "Multihop config change",
- "NSF peer closed the session"
-};
-#endif
diff --git a/bgpd/bgp_msg_read.c b/bgpd/bgp_msg_read.c
index 58a80485..aa6ee64d 100644
--- a/bgpd/bgp_msg_read.c
+++ b/bgpd/bgp_msg_read.c
@@ -187,11 +187,9 @@ bgp_msg_check_header(bgp_connection connection)
void
bgp_msg_dispatch(bgp_connection connection)
{
- uint8_t type = connection->msg_size ;
- bgp_size_t size = connection->msg_type ;
+ bgp_size_t size = connection->msg_size ;
- /* Read rest of the packet and call each sort of packet routine */
- switch (type)
+ switch (connection->msg_type)
{
case BGP_MT_OPEN:
bgp_msg_open_receive (connection, size);
@@ -304,10 +302,10 @@ bgp_msg_open_receive (bgp_connection connection, bgp_size_t size)
}
/* Remote bgp_id may not be multicast, or the same as here */
- if (IN_MULTICAST(open_recv->bgp_id) ||
+ if (IN_MULTICAST(ntohl(open_recv->bgp_id)) ||
(open_recv->bgp_id == connection->session->open_send->bgp_id))
{
- zlog_debug ("%s rcv OPEN, *multicast* id %s",
+ zlog_debug ("%s rcv OPEN, multicast or our id %s",
connection->host, inet_ntoa (remote_id)) ;
bgp_msg_noms_o_bad_id(notification, open_recv->bgp_id) ;
goto reject ;
@@ -409,12 +407,12 @@ bgp_msg_open_receive (bgp_connection connection, bgp_size_t size)
} ;
/* Finally -- require the AS to be the configured AS */
- if (open_recv->my_as != connection->session->as_expected)
+ if (open_recv->my_as != connection->session->as_peer)
{
if (BGP_DEBUG (normal, NORMAL))
zlog_debug ("%s bad OPEN, remote AS is %u, expected %u",
connection->host, open_recv->my_as,
- connection->session->as_expected) ;
+ connection->session->as_peer) ;
bgp_msg_open_error(notification, BGP_NOMS_O_BAD_AS) ;
if (open_recv->can_as4)
@@ -444,7 +442,7 @@ bgp_msg_open_receive (bgp_connection connection, bgp_size_t size)
connection->route_refresh_pre = open_recv->can_r_refresh == bgp_cap_form_old;
connection->orf_prefix_pre = open_recv->can_orf_prefix == bgp_cap_form_old;
- bgp_fsm_event(connection, bgp_fsm_Receive_OPEN_message) ;
+ bgp_fsm_event(connection, bgp_fsm_eReceive_OPEN_message) ;
return 0;
@@ -1285,7 +1283,7 @@ static int
bgp_msg_update_receive (bgp_connection connection, bgp_size_t size)
{
bgp_session_update_recv(connection->session, connection->ibuf, size);
- bgp_fsm_event(connection, bgp_fsm_Receive_UPDATE_message);
+ bgp_fsm_event(connection, bgp_fsm_eReceive_UPDATE_message);
return 0;
}
@@ -1301,7 +1299,7 @@ bgp_msg_keepalive_receive (bgp_connection connection, bgp_size_t size)
if (size != 0)
return bgp_msg_header_bad_len(connection, BGP_MT_KEEPALIVE, size) ;
- bgp_fsm_event(connection, bgp_fsm_Receive_KEEPALIVE_message);
+ bgp_fsm_event(connection, bgp_fsm_eReceive_KEEPALIVE_message);
return 0;
}
diff --git a/bgpd/bgp_msg_write.c b/bgpd/bgp_msg_write.c
index ce4bf1b3..87bd41be 100644
--- a/bgpd/bgp_msg_write.c
+++ b/bgpd/bgp_msg_write.c
@@ -76,7 +76,7 @@
*
* Returns: 2 => written to TCP -- it's gone
* 1 => written to wbuff -- waiting for socket
- * 0 => nothing written -- wbuff was not empty !
+ * 0 => nothing written -- insufficient space in wbuff
* -1 => failed -- error event generated
*/
extern int
@@ -111,8 +111,8 @@ bgp_msg_write_notification(bgp_connection connection, bgp_notify notification)
{
bgp_notify text_form ;
const char* form ;
- char c[4] ;
- char* p ;
+ char c[4] ;
+ uint8_t* p ;
length = bgp_notify_get_length(notification) ;
p = bgp_notify_get_data(notification) ;
@@ -126,7 +126,7 @@ bgp_msg_write_notification(bgp_connection connection, bgp_notify notification)
form = "%02x" ;
while (length--)
{
- sprintf (c, form, *p++) ;
+ snprintf (c, 4, form, *p++) ;
bgp_notify_append_data(text_form, c, strlen(c)) ;
form = " %02x" ;
} ;
@@ -154,7 +154,7 @@ bgp_msg_write_notification(bgp_connection connection, bgp_notify notification)
*
* Returns: 2 => written to TCP -- it's gone
* 1 => written to wbuff -- waiting for socket
- * 0 => nothing written -- wbuff was not empty !
+ * 0 => nothing written -- insufficient space in wbuff
* -1 => failed -- error event generated
*/
extern int
@@ -763,7 +763,7 @@ bgp_msg_orf_prefix(struct stream* s, uint8_t common,
*
* Returns: 2 => written to TCP -- it's gone
* 1 => written to wbuff -- waiting for socket
- * 0 => nothing written -- wbuff was not empty !
+ * 0 => nothing written -- insufficient space in wbuff
* -1 => failed -- error event generated
*/
extern int
@@ -786,7 +786,7 @@ bgp_msg_send_update(bgp_connection connection, struct stream* s)
*
* Returns: 2 => written to TCP -- it's gone
* 1 => written to wbuff -- waiting for socket
- * 0 => nothing written -- wbuff was not empty !
+ * 0 => nothing written -- insufficient space in wbuff
* -1 => failed -- error event generated
*/
extern int
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c
index 5fa8cda2..b5d66679 100644
--- a/bgpd/bgp_network.c
+++ b/bgpd/bgp_network.c
@@ -767,7 +767,8 @@ bgp_update_source (bgp_connection connection)
if (peer->update_source)
sockunion_bind (peer->fd, peer->update_source, 0, peer->update_source);
#else
- return 0 ;
+ return bgp_bind_address(0, bgp_update_address (NULL)) ;
+ /* returns 0 -- avoid warnings */
#endif
} ;
diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c
index dde0cd04..b5b36a79 100644
--- a/bgpd/bgp_nexthop.c
+++ b/bgpd/bgp_nexthop.c
@@ -557,7 +557,7 @@ bgp_connected_add (struct connected *ifc)
if (addr->family == AF_INET)
{
- PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc));
+ prefix_copy_ipv4(&p, CONNECTED_PREFIX(ifc));
apply_mask_ipv4 ((struct prefix_ipv4 *) &p);
if (prefix_ipv4_any ((struct prefix_ipv4 *) &p))
@@ -579,7 +579,7 @@ bgp_connected_add (struct connected *ifc)
#ifdef HAVE_IPV6
else if (addr->family == AF_INET6)
{
- PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc));
+ prefix_copy_ipv6(&p, CONNECTED_PREFIX(ifc));
apply_mask_ipv6 ((struct prefix_ipv6 *) &p);
if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6))
@@ -622,7 +622,7 @@ bgp_connected_delete (struct connected *ifc)
if (addr->family == AF_INET)
{
- PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc));
+ prefix_copy_ipv4(&p, CONNECTED_PREFIX(ifc));
apply_mask_ipv4 ((struct prefix_ipv4 *) &p);
if (prefix_ipv4_any ((struct prefix_ipv4 *) &p))
@@ -645,7 +645,7 @@ bgp_connected_delete (struct connected *ifc)
#ifdef HAVE_IPV6
else if (addr->family == AF_INET6)
{
- PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc));
+ prefix_copy_ipv6(&p, CONNECTED_PREFIX(ifc));
apply_mask_ipv6 ((struct prefix_ipv6 *) &p);
if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6))
@@ -1283,10 +1283,12 @@ bgp_scan_init (void)
zlookup->sock = -1;
/* TODO: reinstate zebra interface when ready */
-#if 0
- zlookup->enable = 1 ;
- zlookup->t_connect = thread_add_event (master, zlookup_connect, zlookup, 0);
-#endif
+ if (0)
+ {
+ zlookup->enable = 1 ;
+ zlookup->t_connect = thread_add_event (master, zlookup_connect,
+ zlookup, 0);
+ } ;
bgp_scan_interval = BGP_SCAN_INTERVAL_DEFAULT;
bgp_import_interval = BGP_IMPORT_INTERVAL_DEFAULT;
diff --git a/bgpd/bgp_notification.c b/bgpd/bgp_notification.c
index 2dc6952e..2343c785 100644
--- a/bgpd/bgp_notification.c
+++ b/bgpd/bgp_notification.c
@@ -108,16 +108,15 @@ bgp_notify_dup(bgp_notify notification)
duplicate = XMALLOC(MTYPE_BGP_NOTIFY, sizeof(struct bgp_notify)) ;
*duplicate = *notification ;
- if (notification->length == 0)
+ if (duplicate->length == 0)
{
duplicate->size = 0 ;
duplicate->data = NULL ;
}
else
{
- bgp_size_t size = bgp_notify_size(duplicate->length) ;
- duplicate->size = size ;
- duplicate->data = XCALLOC(MTYPE_TMP, size) ;
+ duplicate->size = bgp_notify_size(duplicate->length) ;
+ duplicate->data = XCALLOC(MTYPE_TMP, duplicate->size) ;
memcpy(duplicate->data, notification->data, duplicate->length) ;
} ;
@@ -216,13 +215,12 @@ bgp_notify_append_data(bgp_notify notification, const void* data,
else
notification->data = XREALLOC(MTYPE_TMP, notification->data, size) ;
- memset((char*)notification + notification->size, 0,
- size - notification->size) ;
+ memset(notification->data + new_length, 0, size - new_length) ;
notification->size = size ;
} ;
if (len > 0)
- memcpy((char*)(notification->data) + notification->length, data, len) ;
+ memcpy(notification->data + notification->length, data, len) ;
notification->length = new_length ;
} ;
diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c
index ce86db4d..9e878784 100644
--- a/bgpd/bgp_open.c
+++ b/bgpd/bgp_open.c
@@ -58,7 +58,7 @@ bgp_capability_vty_out (struct vty *vty, struct peer *peer)
struct capability_mp_data mpc;
struct capability_header *hdr;
- pnt = peer->notify->data;
+ pnt = (char*)peer->notify->data;
end = pnt + peer->notify->length;
while (pnt < end)
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index 2456706f..8b42de78 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -165,7 +165,7 @@ bgp_update_packet (struct peer *peer, afi_t afi, safi_t safi)
s = peer->work;
stream_reset (s);
- adv = FIFO_HEAD (&peer->sync[afi][safi]->update);
+ adv = bgp_advertise_fifo_head(&peer->sync[afi][safi]->update);
while (adv)
{
@@ -306,7 +306,8 @@ bgp_withdraw_packet (struct peer *peer, afi_t afi, safi_t safi)
s = peer->work;
stream_reset (s);
- while ((adv = FIFO_HEAD (&peer->sync[afi][safi]->withdraw)) != NULL)
+ while ((adv = bgp_advertise_fifo_head(&peer->sync[afi][safi]->withdraw))
+ != NULL)
{
assert (adv->rn);
adj = adv->adj;
@@ -535,7 +536,7 @@ bgp_write_packet (struct peer *peer)
for (afi = AFI_IP; afi < AFI_MAX; afi++)
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
{
- adv = FIFO_HEAD (&peer->sync[afi][safi]->withdraw);
+ adv = bgp_advertise_fifo_head(&peer->sync[afi][safi]->withdraw);
if (adv)
{
s = bgp_withdraw_packet (peer, afi, safi);
@@ -547,7 +548,7 @@ bgp_write_packet (struct peer *peer)
for (afi = AFI_IP; afi < AFI_MAX; afi++)
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
{
- adv = FIFO_HEAD (&peer->sync[afi][safi]->update);
+ adv = bgp_advertise_fifo_head(&peer->sync[afi][safi]->update);
if (adv)
{
if (adv->binfo && adv->binfo->uptime < peer->synctime)
diff --git a/bgpd/bgp_session.c b/bgpd/bgp_session.c
index a863ecbe..aa8d4933 100644
--- a/bgpd/bgp_session.c
+++ b/bgpd/bgp_session.c
@@ -145,6 +145,7 @@ bgp_session_init_new(bgp_session session, bgp_peer peer)
*
* ttl -- unset
* port -- unset
+ * as_peer -- unset
* su_peer -- NULL -- none
*
* log -- NULL -- none
@@ -236,8 +237,9 @@ bgp_session_enable(bgp_peer peer)
/* Initialise what we need to make and run connections */
session->state = bgp_session_sIdle;
- session->made = 0;
session->defer_enable = 0;
+ session->made = 0;
+ session->flow_control = 0;
session->event = bgp_session_null_event;
bgp_notify_unset(&session->notification);
session->err = 0;
@@ -252,6 +254,7 @@ bgp_session_enable(bgp_peer peer)
session->ttl = peer->ttl ;
session->port = peer->port ;
+ session->as_peer = peer->as ;
session->su_peer = sockunion_dup(&peer->su) ;
session->log = peer->log ;
@@ -517,7 +520,7 @@ bgp_session_do_update_send(mqueue_block mqb, mqb_flag_t flag)
assert( (args->pending == connection) && (mqb == head) ) ;
/* If established, try and send. */
- if (connection->state == bgp_fsm_Established)
+ if (connection->state == bgp_fsm_sEstablished)
{
int ret = 0 ;
@@ -621,7 +624,7 @@ bgp_session_do_route_refresh_send(mqueue_block mqb, mqb_flag_t flag)
assert( (args->pending == connection) && (mqb == head) ) ;
/* If established, try and send. */
- if (connection->state == bgp_fsm_Established)
+ if (connection->state == bgp_fsm_sEstablished)
{
int ret = 0 ;
@@ -705,7 +708,7 @@ bgp_session_do_end_of_rib_send(mqueue_block mqb, mqb_flag_t flag)
assert( (args->pending == connection) && (mqb == head) ) ;
/* If established, try and send. */
- if (connection->state == bgp_fsm_Established)
+ if (connection->state == bgp_fsm_sEstablished)
{
int ret = 0 ;
diff --git a/bgpd/bgp_session.h b/bgpd/bgp_session.h
index 236f6d0d..82304916 100644
--- a/bgpd/bgp_session.h
+++ b/bgpd/bgp_session.h
@@ -132,7 +132,6 @@ struct bgp_session
* will not touch it thereafter.
*/
bgp_open_state open_send ; /* how to open the session */
- as_t as_expected ; /* who to open with */
bgp_open_state open_recv ; /* set when session Established */
/* The following are set by the Routeing Engine before a session is
@@ -146,6 +145,8 @@ struct bgp_session
int ttl ; /* TTL to set, if not zero */
unsigned short port ; /* destination port for peer */
+
+ as_t as_peer ; /* ASN of the peer */
union sockunion* su_peer ; /* Sockunion address of the peer */
struct zlog* log ; /* where to log to */
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 27a35cff..2f50e419 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -2270,8 +2270,8 @@ peer_af_flag_unset (struct peer *peer, afi_t afi, safi_t safi, u_int32_t flag)
int
peer_ebgp_multihop_set (struct peer *peer, int ttl)
{
- struct peer_group *group;
- struct listnode *node, *nnode;
+//struct peer_group *group;
+//struct listnode *node, *nnode;
if (peer_sort (peer) == BGP_PEER_IBGP)
return 0;
@@ -2306,8 +2306,8 @@ peer_ebgp_multihop_set (struct peer *peer, int ttl)
int
peer_ebgp_multihop_unset (struct peer *peer)
{
- struct peer_group *group;
- struct listnode *node, *nnode;
+//struct peer_group *group;
+//struct listnode *node, *nnode;
if (peer_sort (peer) == BGP_PEER_IBGP)
return 0;
diff --git a/lib/Makefile.am b/lib/Makefile.am
index c11d1959..7d97bfcb 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -31,7 +31,8 @@ pkginclude_HEADERS = \
privs.h sigevent.h pqueue.h jhash.h zassert.h memtypes.h \
workqueue.h route_types.h symtab.h heap.h \
qtime.h qpthreads.h mqueue.h qpselect.h qtimers.h qpnexus.h \
- command_queue.h qlib_init.h qafi_safi.h confirm.h
+ command_queue.h qlib_init.h qafi_safi.h \
+ confirm.h miyagi.h
EXTRA_DIST = regex.c regex-gnu.h memtypes.awk route_types.awk route_types.txt
diff --git a/lib/distribute.c b/lib/distribute.c
index 6e7ccc67..0e1c9458 100644
--- a/lib/distribute.c
+++ b/lib/distribute.c
@@ -20,6 +20,7 @@
*/
#include <zebra.h>
+#include "miyagi.h"
#include "hash.h"
#include "if.h"
@@ -68,15 +69,8 @@ distribute_lookup (const char *ifname)
struct distribute key;
struct distribute *dist;
- union {
- const char* waxon ;
- char* waxoff ;
- } miyagi ;
-
- miyagi.waxon = ifname ;
-
/* temporary reference */
- key.ifname = miyagi.waxoff ;
+ key.ifname = miyagi(ifname) ;
dist = hash_lookup (disthash, &key);
@@ -114,15 +108,8 @@ distribute_get (const char *ifname)
{
struct distribute key;
- union {
- const char* waxon ;
- char* waxoff ;
- } miyagi ;
-
- miyagi.waxon = ifname ;
-
/* temporary reference */
- key.ifname = miyagi.waxoff ;
+ key.ifname = miyagi(ifname) ;
return hash_get (disthash, &key, (void * (*) (void *))distribute_hash_alloc);
}
diff --git a/lib/if_rmap.c b/lib/if_rmap.c
index dfb66260..9ef5ed94 100644
--- a/lib/if_rmap.c
+++ b/lib/if_rmap.c
@@ -20,6 +20,7 @@
*/
#include <zebra.h>
+#include "miyagi.h"
#include "hash.h"
#include "command.h"
@@ -63,15 +64,8 @@ if_rmap_lookup (const char *ifname)
struct if_rmap key;
struct if_rmap *if_rmap;
- union {
- const char* waxon ;
- char* waxoff ;
- } miyagi ;
-
- miyagi.waxon = ifname ;
-
/* temporary reference */
- key.ifname = miyagi.waxoff ;
+ key.ifname = miyagi(ifname) ;
if_rmap = hash_lookup (ifrmaphash, &key);
@@ -107,15 +101,8 @@ if_rmap_get (const char *ifname)
{
struct if_rmap key;
- union {
- const char* waxon ;
- char* waxoff ;
- } miyagi ;
-
- miyagi.waxon = ifname ;
-
/* temporary reference */
- key.ifname = miyagi.waxoff ;
+ key.ifname = miyagi(ifname) ;
return (struct if_rmap *) hash_get (ifrmaphash, &key, if_rmap_hash_alloc);
}
diff --git a/lib/miyagi.h b/lib/miyagi.h
new file mode 100644
index 00000000..569d2da9
--- /dev/null
+++ b/lib/miyagi.h
@@ -0,0 +1,40 @@
+/* Kludge to discard "const" from pointer
+ * Copyright (C) 2009 Chris Hall (GMCH), Highwayman
+ *.
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _ZEBRA_MIYAGI_H
+#define _ZEBRA_MIYAGI_H
+
+#ifndef Inline
+#define Inline static inline
+#endif
+
+/*==============================================================================
+ * Ghastly kludge to discard "const" from pointer
+ */
+Inline void*
+miyagi(const void* ptr)
+{
+ union {
+ const void* waxon ;
+ void* waxoff ;
+ } shuffle ;
+
+ shuffle.waxon = ptr ;
+
+ return shuffle.waxoff ;
+} ;
+
+#endif /* _ZEBRA_MIYAGI_H */
diff --git a/lib/prefix.h b/lib/prefix.h
index a7598b7e..1ccd4dd6 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with GNU Zebra; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#ifndef _ZEBRA_PREFIX_H
@@ -25,6 +25,10 @@
#include "sockunion.h"
+#ifndef Inline
+#define Inline static inline
+#endif
+
/*
* A struct prefix contains an address family, a prefix length, and an
* address. This can represent either a 'network prefix' as defined
@@ -39,14 +43,14 @@ struct prefix
{
u_char family;
u_char prefixlen;
- union
+ union
{
u_char prefix;
struct in_addr prefix4;
#ifdef HAVE_IPV6
struct in6_addr prefix6;
#endif /* HAVE_IPV6 */
- struct
+ struct
{
struct in_addr id;
struct in_addr adv_router;
@@ -171,6 +175,12 @@ extern void apply_mask_ipv4 (struct prefix_ipv4 *);
#define PREFIX_COPY_IPV4(DST, SRC) \
*((struct prefix_ipv4 *)(DST)) = *((const struct prefix_ipv4 *)(SRC));
+Inline void
+prefix_copy_ipv4(struct prefix* dst, struct prefix* src)
+{
+ *dst = *src ;
+} ;
+
extern int prefix_ipv4_any (const struct prefix_ipv4 *);
extern void apply_classful_mask_ipv4 (struct prefix_ipv4 *);
@@ -193,7 +203,13 @@ extern int str2prefix_ipv6 (const char *, struct prefix_ipv6 *);
extern void apply_mask_ipv6 (struct prefix_ipv6 *);
#define PREFIX_COPY_IPV6(DST, SRC) \
- *((struct prefix_ipv6 *)(DST)) = *((const struct prefix_ipv6 *)(SRC));
+ *((struct prefix_ipv6 *)(DST)) = *((const struct prefix_ipv6 *)(SRC));
+
+Inline void
+prefix_copy_ipv6(struct prefix* dst, struct prefix* src)
+{
+ *dst = *src ;
+} ;
extern int ip6_masklen (struct in6_addr);
extern void masklen2ip6 (int, struct in6_addr *);
diff --git a/lib/sockopt.c b/lib/sockopt.c
index 1f84aaca..3e4580ac 100644
--- a/lib/sockopt.c
+++ b/lib/sockopt.c
@@ -624,7 +624,7 @@ sockopt_tcp_signature (int sock, union sockunion *su, const char *password)
int
sockopt_ttl (int family, int sock, int ttl)
{
- char* msg ;
+ const char* msg ;
int ret ;
ret = 0 ;
diff --git a/lib/stream.c b/lib/stream.c
index 79ce1791..14c7c589 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -158,7 +158,7 @@ struct stream *
stream_dup_pending (struct stream *s)
{
struct stream *new;
- int new_endp ;
+ size_t new_endp ;
STREAM_VERIFY_SANE (s);
@@ -1050,13 +1050,13 @@ stream_transfer(void* p, struct stream* s, void* limit)
size_t have = s->endp ;
STREAM_VERIFY_SANE(s);
- assert((p + have) <= limit) ;
+ assert(((uint8_t*)p + have) <= (uint8_t*)limit) ;
memcpy(p, s->data, have) ;
s->getp = s->endp = 0;
- return p + have ;
+ return (uint8_t*)p + have ;
} ;
/* Stream first in first out queue. */
diff --git a/lib/thread.c b/lib/thread.c
index 09a082cf..e581dd6f 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -16,12 +16,13 @@
* You should have received a copy of the GNU General Public License
* along with GNU Zebra; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
/* #define DEBUG */
#include <zebra.h>
+#include "miyagi.h"
#include "thread.h"
#include "memory.h"
@@ -30,7 +31,7 @@
#include "command.h"
#include "sigevent.h"
#include "qpthreads.h"
-
+
/* Recent absolute time of day */
struct timeval recent_time;
static struct timeval last_recent_time;
@@ -39,7 +40,7 @@ static struct timeval relative_time;
static struct timeval relative_time_base;
/* init flag */
static unsigned short timers_inited;
-
+
/* cpu stats needs to be qpthread safe. */
static qpt_mutex_t thread_mutex;
#define LOCK qpt_mutex_lock(&thread_mutex);
@@ -52,7 +53,7 @@ static struct hash *cpu_record = NULL;
#include "qpnexus.h"
static sigset_t newmask;
#endif
-
+
/* Struct timeval's tv_usec one second value. */
#define TIMER_SECOND_MICRO 1000000L
@@ -104,7 +105,7 @@ timeval_elapsed (struct timeval a, struct timeval b)
return (((a.tv_sec - b.tv_sec) * TIMER_SECOND_MICRO)
+ (a.tv_usec - b.tv_usec));
}
-
+
#ifndef HAVE_CLOCK_MONOTONIC
static void
quagga_gettimeofday_relative_adjust (void)
@@ -131,9 +132,9 @@ static int
quagga_gettimeofday (struct timeval *tv)
{
int ret;
-
+
assert (tv);
-
+
if (!(ret = gettimeofday (&recent_time, NULL)))
{
/* init... */
@@ -208,7 +209,7 @@ quagga_gettime (enum quagga_clkid clkid, struct timeval *tv)
}
}
-/* time_t value in terms of stabilised absolute time.
+/* time_t value in terms of stabilised absolute time.
* replacement for POSIX time()
*/
time_t
@@ -227,14 +228,14 @@ recent_relative_time (void)
{
return relative_time;
}
-
+
static unsigned int
cpu_record_hash_key (struct cpu_thread_history *a)
{
return (uintptr_t) a->func;
}
-static int
+static int
cpu_record_hash_cmp (const struct cpu_thread_history *a,
const struct cpu_thread_history *b)
{
@@ -255,12 +256,13 @@ static void
cpu_record_hash_free (void *a)
{
struct cpu_thread_history *hist = a;
-
- XFREE (MTYPE_THREAD_FUNCNAME, hist->funcname);
+ char* funcname = miyagi(hist->funcname) ;
+
+ XFREE (MTYPE_THREAD_FUNCNAME, funcname);
XFREE (MTYPE_THREAD_STATS, hist);
}
-static inline void
+static inline void
vty_out_cpu_thread_history(struct vty* vty,
struct cpu_thread_history *a)
{
@@ -285,14 +287,14 @@ vty_out_cpu_thread_history(struct vty* vty,
}
static void
-cpu_record_hash_print(struct hash_backet *bucket,
+cpu_record_hash_print(struct hash_backet *bucket,
void *args[])
{
struct cpu_thread_history *totals = args[0];
struct vty *vty = args[1];
thread_type *filter = args[2];
struct cpu_thread_history *a = bucket->data;
-
+
a = bucket->data;
if ( !(a->types & *filter) )
return;
@@ -398,7 +400,7 @@ DEFUN_CALL(show_thread_cpu,
cpu_record_print(vty, filter);
return CMD_SUCCESS;
}
-
+
/* List allocation and head/tail print out. */
static void
thread_list_debug (struct thread_list *list)
@@ -427,7 +429,7 @@ thread_master_debug (struct thread_master *m)
printf ("total alloc: [%ld]\n", m->alloc);
printf ("-----------\n");
}
-
+
/* Allocate new thread master. */
struct thread_master *
thread_master_create ()
@@ -437,11 +439,11 @@ thread_master_create ()
sigdelset (&newmask, SIGMQUEUE);
#endif
- if (cpu_record == NULL)
- cpu_record
- = hash_create_size (1011, (unsigned int (*) (void *))cpu_record_hash_key,
+ if (cpu_record == NULL)
+ cpu_record
+ = hash_create_size (1011, (unsigned int (*) (void *))cpu_record_hash_key,
(int (*) (const void *, const void *))cpu_record_hash_cmp);
-
+
return (struct thread_master *) XCALLOC (MTYPE_THREAD_MASTER,
sizeof (struct thread_master));
}
@@ -462,8 +464,8 @@ thread_list_add (struct thread_list *list, struct thread *thread)
/* Add a new thread just before the point. */
static void
-thread_list_add_before (struct thread_list *list,
- struct thread *point,
+thread_list_add_before (struct thread_list *list,
+ struct thread *point,
struct thread *thread)
{
thread->next = point;
@@ -534,7 +536,7 @@ thread_master_free (struct thread_master *m)
thread_list_free (m, &m->ready);
thread_list_free (m, &m->unuse);
thread_list_free (m, &m->background);
-
+
XFREE (MTYPE_THREAD_MASTER, m);
LOCK
@@ -568,7 +570,7 @@ unsigned long
thread_timer_remain_second (struct thread *thread)
{
quagga_get_relative (NULL);
-
+
if (thread->u.sands.tv_sec - relative_time.tv_sec > 0)
return thread->u.sands.tv_sec - relative_time.tv_sec;
else
@@ -577,7 +579,7 @@ thread_timer_remain_second (struct thread *thread)
/* Trim blankspace and "()"s */
static char *
-strip_funcname (const char *funcname)
+strip_funcname (const char *funcname)
{
char buff[100];
char tmp, *ret, *e, *b = buff;
@@ -625,7 +627,7 @@ thread_get (struct thread_master *m, u_char type,
thread->master = m;
thread->func = func;
thread->arg = arg;
-
+
thread->funcname = strip_funcname(funcname);
return thread;
@@ -633,7 +635,7 @@ thread_get (struct thread_master *m, u_char type,
/* Add new read thread. */
struct thread *
-funcname_thread_add_read (struct thread_master *m,
+funcname_thread_add_read (struct thread_master *m,
int (*func) (struct thread *), void *arg, int fd, const char* funcname)
{
struct thread *thread;
@@ -679,10 +681,10 @@ funcname_thread_add_write (struct thread_master *m,
static struct thread *
funcname_thread_add_timer_timeval (struct thread_master *m,
- int (*func) (struct thread *),
+ int (*func) (struct thread *),
int type,
- void *arg,
- struct timeval *time_relative,
+ void *arg,
+ struct timeval *time_relative,
const char* funcname)
{
struct thread *thread;
@@ -694,7 +696,7 @@ funcname_thread_add_timer_timeval (struct thread_master *m,
assert (type == THREAD_TIMER || type == THREAD_BACKGROUND);
assert (time_relative);
-
+
list = ((type == THREAD_TIMER) ? &m->timer : &m->background);
thread = thread_get (m, type, func, arg, funcname);
@@ -721,7 +723,7 @@ funcname_thread_add_timer_timeval (struct thread_master *m,
/* Add timer event thread. */
struct thread *
funcname_thread_add_timer (struct thread_master *m,
- int (*func) (struct thread *),
+ int (*func) (struct thread *),
void *arg, long timer, const char* funcname)
{
struct timeval trel;
@@ -731,14 +733,14 @@ funcname_thread_add_timer (struct thread_master *m,
trel.tv_sec = timer;
trel.tv_usec = 0;
- return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg,
+ return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg,
&trel, funcname);
}
/* Add timer event thread with "millisecond" resolution */
struct thread *
funcname_thread_add_timer_msec (struct thread_master *m,
- int (*func) (struct thread *),
+ int (*func) (struct thread *),
void *arg, long timer, const char* funcname)
{
struct timeval trel;
@@ -748,7 +750,7 @@ funcname_thread_add_timer_msec (struct thread_master *m,
trel.tv_sec = timer / 1000;
trel.tv_usec = 1000*(timer % 1000);
- return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER,
+ return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER,
arg, &trel, funcname);
}
@@ -756,13 +758,13 @@ funcname_thread_add_timer_msec (struct thread_master *m,
struct thread *
funcname_thread_add_background (struct thread_master *m,
int (*func) (struct thread *),
- void *arg, long delay,
+ void *arg, long delay,
const char *funcname)
{
struct timeval trel;
-
+
assert (m != NULL);
-
+
if (delay)
{
trel.tv_sec = delay / 1000;
@@ -799,7 +801,7 @@ void
thread_cancel (struct thread *thread)
{
struct thread_list *list;
-
+
switch (thread->type)
{
case THREAD_READ:
@@ -887,9 +889,9 @@ thread_process_fd (struct thread_list *list, fd_set *fdset, fd_set *mfdset)
struct thread *thread;
struct thread *next;
int ready = 0;
-
+
assert (list);
-
+
for (thread = list->head; thread; thread = next)
{
next = thread->next;
@@ -913,7 +915,7 @@ thread_timer_process (struct thread_list *list, struct timeval *timenow)
{
struct thread *thread;
unsigned int ready = 0;
-
+
for (thread = list->head; thread; thread = thread->next)
{
if (timeval_cmp (*timenow, thread->u.sands) < 0)
@@ -942,38 +944,44 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
while (1)
{
int num = 0;
-
+
/* Signals are highest priority */
if (!qpthreads_enabled)
quagga_sigevent_process ();
-
+
/* Normal event are the next highest priority. */
if ((thread = thread_trim_head (&m->event)) != NULL)
return thread_run (m, thread, fetch);
-
+
/* If there are any ready threads from previous scheduler runs,
- * process top of them.
+ * process top of them.
*/
if ((thread = thread_trim_head (&m->ready)) != NULL)
return thread_run (m, thread, fetch);
-
+
/* Structure copy. */
readfd = m->readfd;
writefd = m->writefd;
exceptfd = m->exceptfd;
-
+
/* Calculate select wait timer if nothing else to do */
quagga_get_relative (NULL);
timer_wait = thread_timer_wait (&m->timer, &timer_val);
timer_wait_bg = thread_timer_wait (&m->background, &timer_val_bg);
-
+
if (timer_wait_bg &&
(!timer_wait || (timeval_cmp (*timer_wait, *timer_wait_bg) > 0)))
timer_wait = timer_wait_bg;
-
+
/* TODO: remove this */
#ifdef USE_MQUEUE
- num = pselect (FD_SETSIZE, &readfd, &writefd, &exceptfd, timer_wait, &newmask);
+ {
+ struct timespec spec ;
+ spec.tv_sec = timer_wait->tv_sec ;
+ spec.tv_nsec = timer_wait->tv_usec * 1000 ;
+ num = pselect (FD_SETSIZE, &readfd, &writefd, &exceptfd, &spec,
+ &newmask);
+ } ;
#else
num = select (FD_SETSIZE, &readfd, &writefd, &exceptfd, timer_wait);
#endif
@@ -1001,7 +1009,7 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
list in front of the I/O threads. */
quagga_get_relative (NULL);
thread_timer_process (&m->timer, &relative_time);
-
+
/* Got IO, process it */
if (num > 0)
{
@@ -1022,7 +1030,7 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
/* Background timer/events, lowest priority */
thread_timer_process (&m->background, &relative_time);
-
+
if ((thread = thread_trim_head (&m->ready)) != NULL)
return thread_run (m, thread, fetch);
}
@@ -1093,13 +1101,13 @@ thread_consumed_time (RUSAGE_T *now, RUSAGE_T *start, unsigned long *cputime)
return timeval_elapsed (now->real, start->real);
}
-/* We should aim to yield after THREAD_YIELD_TIME_SLOT milliseconds.
+/* We should aim to yield after THREAD_YIELD_TIME_SLOT milliseconds.
Note: we are using real (wall clock) time for this calculation.
It could be argued that CPU time may make more sense in certain
contexts. The things to consider are whether the thread may have
blocked (in which case wall time increases, but CPU time does not),
or whether the system is heavily loaded with other processes competing
- for CPU time. On balance, wall clock time seems to make sense.
+ for CPU time. On balance, wall clock time seems to make sense.
Plus it has the added benefit that gettimeofday should be faster
than calling getrusage. */
int
@@ -1146,12 +1154,12 @@ thread_call (struct thread *thread)
if (!thread->hist)
{
struct cpu_thread_history tmp;
-
+
tmp.func = thread->func;
tmp.funcname = thread->funcname;
-
+
LOCK
- thread->hist = hash_get (cpu_record, &tmp,
+ thread->hist = hash_get (cpu_record, &tmp,
(void * (*) (void *))cpu_record_hash_alloc);
UNLOCK
}
@@ -1199,12 +1207,12 @@ thread_call (struct thread *thread)
/* Execute thread */
struct thread *
funcname_thread_execute (struct thread_master *m,
- int (*func)(struct thread *),
+ int (*func)(struct thread *),
void *arg,
int val,
const char* funcname)
{
- struct thread dummy;
+ struct thread dummy;
memset (&dummy, 0, sizeof (struct thread));
diff --git a/lib/vty.c b/lib/vty.c
index fdc36925..e154a575 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -21,6 +21,7 @@
*/
#include <zebra.h>
+#include "miyagi.h"
#include "linklist.h"
#include "thread.h"
@@ -2931,10 +2932,10 @@ vty_log_fixed (const char *buf, size_t len)
if (!vtyvec)
return;
- iov[0].iov_base = (void *)buf;
- iov[0].iov_len = len;
- iov[1].iov_base = (void *)"\r\n";
- iov[1].iov_len = 2;
+ iov[0].iov_base = miyagi(buf) ;
+ iov[0].iov_len = len;
+ iov[1].iov_base = miyagi("\r\n") ;
+ iov[1].iov_len = 2;
for (i = 0; i < vector_active (vtyvec); i++)
{
diff --git a/lib/zebra.h b/lib/zebra.h
index 65aad161..799cfc3d 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -525,28 +525,6 @@ extern const char *zserv_command_string (unsigned int command);
typedef u_int16_t zebra_size_t;
typedef u_int16_t zebra_command_t;
-/* FIFO -- first in first out structure and macros. */
-struct fifo
-{
- struct fifo *next;
- struct fifo *prev;
-};
-
-#define FIFO_INIT(F) \
- do { \
- struct fifo *Xfifo = (struct fifo *)(F); \
- Xfifo->next = Xfifo->prev = Xfifo; \
- } while (0)
-
-#define FIFO_ADD(F,N) \
- do { \
- struct fifo *Xfifo = (struct fifo *)(F); \
- struct fifo *Xnode = (struct fifo *)(N); \
- Xnode->next = Xfifo; \
- Xnode->prev = Xfifo->prev; \
- Xfifo->prev = Xfifo->prev->next = Xnode; \
- } while (0)
-
#define FIFO_DEL(N) \
do { \
struct fifo *Xnode = (struct fifo *)(N); \
@@ -554,14 +532,4 @@ struct fifo
Xnode->next->prev = Xnode->prev; \
} while (0)
-#define FIFO_HEAD(F) \
- ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
- ? NULL : (F)->next)
-
-#define FIFO_EMPTY(F) \
- (((struct fifo *)(F))->next == (struct fifo *)(F))
-
-#define FIFO_TOP(F) \
- (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
-
#endif /* _ZEBRA_H */
diff --git a/tests/bgp_capability_test.c b/tests/bgp_capability_test.c
index 0dbf4fb9..78142009 100644
--- a/tests/bgp_capability_test.c
+++ b/tests/bgp_capability_test.c
@@ -1,4 +1,5 @@
#include <zebra.h>
+#include "miyagi.h"
#include "vty.h"
#include "stream.h"
@@ -36,7 +37,7 @@ static struct test_segment {
#define SHOULD_ERR -1
int parses; /* whether it should parse or not */
int peek_for; /* what peek_for_as4_capability should say */
-
+
/* AFI/SAFI validation */
int validate_afi;
afi_t afi;
@@ -44,10 +45,10 @@ static struct test_segment {
#define VALID_AFI 1
#define INVALID_AFI 0
int afi_valid;
-} test_segments [] =
+} test_segments [] =
{
/* 0 */
- { "caphdr",
+ { "caphdr",
"capability header, and no more",
{ CAPABILITY_CODE_REFRESH, 0x0 },
2, SHOULD_PARSE,
@@ -114,7 +115,7 @@ static struct test_segment mp_segments[] =
{ CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x80 },
6, SHOULD_PARSE, 0,
1, AFI_IP, BGP_SAFI_VPNV4, VALID_AFI,
- },
+ },
/* 9 */
{ "MP7",
"MP IP4/VPNv6",
@@ -150,9 +151,9 @@ static struct test_segment misc_segments[] =
/* 13 */
{ "ORF",
"ORF, simple, single entry, single tuple",
- { /* hdr */ CAPABILITY_CODE_ORF, 0x7,
- /* mpc */ 0x0, 0x1, 0x0, 0x1,
- /* num */ 0x1,
+ { /* hdr */ CAPABILITY_CODE_ORF, 0x7,
+ /* mpc */ 0x0, 0x1, 0x0, 0x1,
+ /* num */ 0x1,
/* tuples */ 0x40, 0x3
},
9, SHOULD_PARSE,
@@ -161,18 +162,18 @@ static struct test_segment misc_segments[] =
{ "ORF-many",
"ORF, multi entry/tuple",
{ /* hdr */ CAPABILITY_CODE_ORF, 0x21,
- /* mpc */ 0x0, 0x1, 0x0, 0x1,
- /* num */ 0x3,
+ /* mpc */ 0x0, 0x1, 0x0, 0x1,
+ /* num */ 0x3,
/* tuples */ 0x40, ORF_MODE_BOTH,
0x80, ORF_MODE_RECEIVE,
0x80, ORF_MODE_SEND,
- /* mpc */ 0x0, 0x2, 0x0, 0x1,
- /* num */ 0x3,
+ /* mpc */ 0x0, 0x2, 0x0, 0x1,
+ /* num */ 0x3,
/* tuples */ 0x40, ORF_MODE_BOTH,
0x80, ORF_MODE_RECEIVE,
0x80, ORF_MODE_SEND,
/* mpc */ 0x0, 0x2, 0x0, 0x2,
- /* num */ 0x3,
+ /* num */ 0x3,
/* tuples */ 0x40, ORF_MODE_RECEIVE,
0x80, ORF_MODE_SEND,
0x80, ORF_MODE_BOTH,
@@ -183,18 +184,18 @@ static struct test_segment misc_segments[] =
{ "ORFlo",
"ORF, multi entry/tuple, hdr length too short",
{ /* hdr */ CAPABILITY_CODE_ORF, 0x15,
- /* mpc */ 0x0, 0x1, 0x0, 0x1,
- /* num */ 0x3,
+ /* mpc */ 0x0, 0x1, 0x0, 0x1,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
- /* mpc */ 0x0, 0x1, 0x0, 0x1,
- /* num */ 0x3,
+ /* mpc */ 0x0, 0x1, 0x0, 0x1,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
/* mpc */ 0x0, 0x2, 0x0, 0x2,
- /* num */ 0x3,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
@@ -205,18 +206,18 @@ static struct test_segment misc_segments[] =
{ "ORFlu",
"ORF, multi entry/tuple, length too long",
{ /* hdr */ 0x3, 0x22,
- /* mpc */ 0x0, 0x1, 0x0, 0x1,
- /* num */ 0x3,
+ /* mpc */ 0x0, 0x1, 0x0, 0x1,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
- /* mpc */ 0x0, 0x2, 0x0, 0x1,
- /* num */ 0x3,
+ /* mpc */ 0x0, 0x2, 0x0, 0x1,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
/* mpc */ 0x0, 0x2, 0x0, 0x2,
- /* num */ 0x3,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
@@ -227,18 +228,18 @@ static struct test_segment misc_segments[] =
{ "ORFnu",
"ORF, multi entry/tuple, entry number too long",
{ /* hdr */ 0x3, 0x21,
- /* mpc */ 0x0, 0x1, 0x0, 0x1,
- /* num */ 0x3,
+ /* mpc */ 0x0, 0x1, 0x0, 0x1,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
- /* mpc */ 0x0, 0x2, 0x0, 0x1,
- /* num */ 0x4,
+ /* mpc */ 0x0, 0x2, 0x0, 0x1,
+ /* num */ 0x4,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
/* mpc */ 0x0, 0x2, 0x0, 0x2,
- /* num */ 0x3,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
@@ -249,13 +250,13 @@ static struct test_segment misc_segments[] =
{ "ORFno",
"ORF, multi entry/tuple, entry number too short",
{ /* hdr */ 0x3, 0x21,
- /* mpc */ 0x0, 0x1, 0x0, 0x1,
- /* num */ 0x3,
+ /* mpc */ 0x0, 0x1, 0x0, 0x1,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
- /* mpc */ 0x0, 0x2, 0x0, 0x1,
- /* num */ 0x1,
+ /* mpc */ 0x0, 0x2, 0x0, 0x1,
+ /* num */ 0x1,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
@@ -271,18 +272,18 @@ static struct test_segment misc_segments[] =
{ "ORFpad",
"ORF, multi entry/tuple, padded to align",
{ /* hdr */ 0x3, 0x22,
- /* mpc */ 0x0, 0x1, 0x0, 0x1,
- /* num */ 0x3,
+ /* mpc */ 0x0, 0x1, 0x0, 0x1,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
- /* mpc */ 0x0, 0x2, 0x0, 0x1,
- /* num */ 0x3,
+ /* mpc */ 0x0, 0x2, 0x0, 0x1,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
/* mpc */ 0x0, 0x2, 0x0, 0x2,
- /* num */ 0x3,
+ /* num */ 0x3,
/* tuples */ 0x40, 0x3,
0x80, 0x1,
0x80, 0x2,
@@ -401,7 +402,7 @@ static struct test_segment misc_segments[] =
};
/* DYNAMIC message */
-struct test_segment dynamic_cap_msgs[] =
+struct test_segment dynamic_cap_msgs[] =
{
{ "DynCap",
"Dynamic Capability Message, IP/Multicast",
@@ -439,7 +440,7 @@ struct test_segment opt_params[] =
{ 0x02, 0x06, 0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
0x02, 0x06, 0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
0x02, 0x02, 0x80, 0x00, /* RR (old) */
- 0x02, 0x02, 0x02, 0x00, /* RR */
+ 0x02, 0x02, 0x02, 0x00, /* RR */
},
24, SHOULD_PARSE,
},
@@ -449,7 +450,7 @@ struct test_segment opt_params[] =
0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
0x80, 0x00, /* RR (old) */
- 0x02, 0x00, /* RR */
+ 0x02, 0x00, /* RR */
},
18, SHOULD_PARSE,
},
@@ -469,7 +470,7 @@ struct test_segment opt_params[] =
0x01, 0x04, 0x00, 0x01, 0x00, 0x01, /* MP IPv4/Uni */
0x01, 0x04, 0x00, 0x02, 0x00, 0x01, /* MP IPv6/Uni */
0x80, 0x00, /* RR (old) */
- 0x02, 0x00, /* RR */
+ 0x02, 0x00, /* RR */
0x41, 0x04, 0x00, 0x03, 0x00, 0x06 /* AS4: 1996614 */
},
24, SHOULD_PARSE, 196614,
@@ -503,6 +504,8 @@ struct test_segment opt_params[] =
{ NULL, NULL, {0}, 0, 0}
};
+extern int bgp_capability_receive(struct peer*, bgp_size_t) ;
+
/* basic parsing test */
static void
parse_test (struct peer *peer, struct test_segment *t, int type)
@@ -513,11 +516,11 @@ parse_test (struct peer *peer, struct test_segment *t, int type)
int oldfailed = failed;
int len = t->len;
#define RANDOM_FUZZ 35
-
+
stream_reset (peer->ibuf);
stream_put (peer->ibuf, NULL, RANDOM_FUZZ);
stream_set_getp (peer->ibuf, RANDOM_FUZZ);
-
+
switch (type)
{
case CAPABILITY:
@@ -532,7 +535,7 @@ parse_test (struct peer *peer, struct test_segment *t, int type)
break;
}
stream_write (peer->ibuf, t->data, t->len);
-
+
printf ("%s: %s\n", t->name, t->desc);
switch (type)
@@ -546,7 +549,7 @@ parse_test (struct peer *peer, struct test_segment *t, int type)
printf ("peek_for_as4: as4 is %u\n", as4);
/* and it should leave getp as it found it */
assert (stream_get_getp (peer->ibuf) == RANDOM_FUZZ);
-
+
ret = bgp_open_option_parse (peer, len, &capability);
break;
case DYNCAP:
@@ -556,49 +559,49 @@ parse_test (struct peer *peer, struct test_segment *t, int type)
printf ("unknown type %u\n", type);
exit(1);
}
-
+
if (!ret && t->validate_afi)
{
safi_t safi = t->safi;
-
+
if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid)
failed++;
-
+
printf ("MP: %u/%u (%u): recv %u, nego %u\n",
t->afi, t->safi, safi,
peer->afc_recv[t->afi][safi],
peer->afc_nego[t->afi][safi]);
-
+
if (t->afi_valid == VALID_AFI)
{
-
+
if (!peer->afc_recv[t->afi][safi])
failed++;
if (!peer->afc_nego[t->afi][safi])
failed++;
}
}
-
- if (as4 != t->peek_for)
+
+ if (as4 != (uint32_t)t->peek_for)
{
printf ("as4 %u != %u\n", as4, t->peek_for);
failed++;
}
-
+
printf ("parsed?: %s\n", ret ? "no" : "yes");
-
+
if (ret != t->parses)
failed++;
-
+
if (tty)
- printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET
+ printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET
: VT100_GREEN "OK" VT100_RESET);
else
printf ("%s", (failed > oldfailed) ? "failed!" : "OK" );
-
+
if (failed)
printf (" (%u)", failed);
-
+
printf ("\n\n");
}
@@ -610,7 +613,7 @@ main (void)
{
struct peer *peer;
int i, j;
-
+
conf_bgp_debug_fsm = -1UL;
conf_bgp_debug_events = -1UL;
conf_bgp_debug_packet = -1UL;
@@ -621,26 +624,26 @@ main (void)
term_bgp_debug_packet = -1UL;
term_bgp_debug_normal = -1UL;
term_bgp_debug_as4 = -1UL;
-
+
master = thread_master_create ();
bgp_master_init ();
-
- if (fileno (stdout) >= 0)
+
+ if (fileno (stdout) >= 0)
tty = isatty (fileno (stdout));
-
+
if (bgp_get (&bgp, &asn, NULL))
return -1;
-
+
peer = peer_create_accept (bgp);
- peer->host = "foo";
-
+ peer->host = miyagi("foo");
+
for (i = AFI_IP; i < AFI_MAX; i++)
for (j = SAFI_UNICAST; j < SAFI_MAX; j++)
{
peer->afc[i][j] = 1;
peer->afc_adv[i][j] = 1;
}
-
+
i = 0;
while (mp_segments[i].name)
parse_test (peer, &mp_segments[i++], CAPABILITY);
@@ -649,9 +652,9 @@ main (void)
* one of the afc_nego's
*/
i = 0;
- while (test_segments[i].name)
+ while (test_segments[i].name)
parse_test (peer, &test_segments[i++], CAPABILITY);
-
+
i = 0;
while (misc_segments[i].name)
parse_test (peer, &misc_segments[i++], CAPABILITY);
@@ -662,11 +665,11 @@ main (void)
SET_FLAG (peer->cap, PEER_CAP_DYNAMIC_ADV);
peer->status = Established;
-
+
i = 0;
while (dynamic_cap_msgs[i].name)
parse_test (peer, &dynamic_cap_msgs[i++], DYNCAP);
-
+
printf ("failures: %d\n", failed);
return failed;
}
diff --git a/tests/bgp_mp_attr_test.c b/tests/bgp_mp_attr_test.c
index dde0df2f..6a445acf 100644
--- a/tests/bgp_mp_attr_test.c
+++ b/tests/bgp_mp_attr_test.c
@@ -1,4 +1,5 @@
#include <zebra.h>
+#include "miyagi.h"
#include "vty.h"
#include "stream.h"
@@ -36,17 +37,17 @@ static struct test_segment {
#define SHOULD_PARSE 0
#define SHOULD_ERR -1
int parses; /* whether it should parse or not */
-
+
/* AFI/SAFI validation */
afi_t afi;
safi_t safi;
#define VALID_AFI 1
#define INVALID_AFI 0
int afi_valid;
-} mp_reach_segments [] =
+} mp_reach_segments [] =
{
{ "IPv6",
- "IPV6 MP Reach, global nexthop, 1 NLRI",
+ "IPV6 MP Reach, global nexthop, 1 NLRI",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
/* nexthop bytes */ 16,
@@ -57,12 +58,12 @@ static struct test_segment {
/* SNPA (defunct, MBZ) */ 0x0,
/* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
},
- (4 + 16 + 1 + 5),
+ (4 + 16 + 1 + 5),
SHOULD_PARSE,
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-2",
- "IPV6 MP Reach, global nexthop, 2 NLRIs",
+ "IPV6 MP Reach, global nexthop, 2 NLRIs",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
/* nexthop bytes */ 16,
@@ -71,18 +72,18 @@ static struct test_segment {
0x3, 0x4, 0x5, 0x6,
0xa1, 0xa2, 0xa3, 0xa4,
/* SNPA (defunct, MBZ) */ 0x0,
- /* NLRI tuples */ 32,
+ /* NLRI tuples */ 32,
0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
64,
0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
0x0, 0x2, 0x0, 0x3,
},
- (4 + 16 + 1 + 5 + 9),
+ (4 + 16 + 1 + 5 + 9),
SHOULD_PARSE,
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-default",
- "IPV6 MP Reach, global nexthop, 2 NLRIs + default",
+ "IPV6 MP Reach, global nexthop, 2 NLRIs + default",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
/* nexthop bytes */ 16,
@@ -91,7 +92,7 @@ static struct test_segment {
0x3, 0x4, 0x5, 0x6,
0xa1, 0xa2, 0xa3, 0xa4,
/* SNPA (defunct, MBZ) */ 0x0,
- /* NLRI tuples */ 32,
+ /* NLRI tuples */ 32,
0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
64,
0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
@@ -103,7 +104,7 @@ static struct test_segment {
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-lnh",
- "IPV6 MP Reach, global+local nexthops, 2 NLRIs + default",
+ "IPV6 MP Reach, global+local nexthops, 2 NLRIs + default",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
/* nexthop bytes */ 32,
@@ -116,7 +117,7 @@ static struct test_segment {
0x2, 0x10, 0x2, 0xff,
0x1, 0x2, 0x3, 0x4,
/* SNPA (defunct, MBZ) */ 0x0,
- /* NLRI tuples */ 32,
+ /* NLRI tuples */ 32,
0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
64,
0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
@@ -128,7 +129,7 @@ static struct test_segment {
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-nhlen",
- "IPV6 MP Reach, inappropriate nexthop length",
+ "IPV6 MP Reach, inappropriate nexthop length",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
/* nexthop bytes */ 4,
@@ -141,7 +142,7 @@ static struct test_segment {
0x2, 0x10, 0x2, 0xff,
0x1, 0x2, 0x3, 0x4,
/* SNPA (defunct, MBZ) */ 0x0,
- /* NLRI tuples */ 32,
+ /* NLRI tuples */ 32,
0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
64,
0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
@@ -153,7 +154,7 @@ static struct test_segment {
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-nhlen2",
- "IPV6 MP Reach, invalid nexthop length",
+ "IPV6 MP Reach, invalid nexthop length",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
/* nexthop bytes */ 5,
@@ -166,7 +167,7 @@ static struct test_segment {
0x2, 0x10, 0x2, 0xff,
0x1, 0x2, 0x3, 0x4,
/* SNPA (defunct, MBZ) */ 0x0,
- /* NLRI tuples */ 32,
+ /* NLRI tuples */ 32,
0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
64,
0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
@@ -178,7 +179,7 @@ static struct test_segment {
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-nhlen3",
- "IPV6 MP Reach, nexthop length overflow",
+ "IPV6 MP Reach, nexthop length overflow",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
/* nexthop bytes */ 32,
@@ -192,7 +193,7 @@ static struct test_segment {
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-nhlen4",
- "IPV6 MP Reach, nexthop length short",
+ "IPV6 MP Reach, nexthop length short",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
/* nexthop bytes */ 16,
@@ -205,7 +206,7 @@ static struct test_segment {
0x2, 0x10, 0x2, 0xff,
0x1, 0x2, 0x3, 0x4,
/* SNPA (defunct, MBZ) */ 0x0,
- /* NLRI tuples */ 32,
+ /* NLRI tuples */ 32,
0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
64,
0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
@@ -217,7 +218,7 @@ static struct test_segment {
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-nlri",
- "IPV6 MP Reach, NLRI bitlen overflow",
+ "IPV6 MP Reach, NLRI bitlen overflow",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
/* nexthop bytes */ 32,
@@ -230,7 +231,7 @@ static struct test_segment {
0x2, 0x10, 0x2, 0xff,
0x1, 0x2, 0x3, 0x4,
/* SNPA (defunct, MBZ) */ 0x0,
- /* NLRI tuples */ 120,
+ /* NLRI tuples */ 120,
0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
64,
0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
@@ -242,11 +243,11 @@ static struct test_segment {
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv4",
- "IPv4 MP Reach, 2 NLRIs + default",
+ "IPv4 MP Reach, 2 NLRIs + default",
{
/* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
/* nexthop bytes */ 4,
- /* Nexthop */ 192, 168, 0, 1,
+ /* Nexthop */ 192, 168, 0, 1,
/* SNPA (defunct, MBZ) */ 0x0,
/* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
17, 10, 2, 3, /* 10.2.3/17 */
@@ -257,11 +258,11 @@ static struct test_segment {
AFI_IP, SAFI_UNICAST, VALID_AFI,
},
{ "IPv4-nhlen",
- "IPv4 MP Reach, nexthop lenth overflow",
+ "IPv4 MP Reach, nexthop lenth overflow",
{
/* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
/* nexthop bytes */ 32,
- /* Nexthop */ 192, 168, 0, 1,
+ /* Nexthop */ 192, 168, 0, 1,
/* SNPA (defunct, MBZ) */ 0x0,
/* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
17, 10, 2, 3, /* 10.2.3/17 */
@@ -272,14 +273,14 @@ static struct test_segment {
AFI_IP, SAFI_UNICAST, VALID_AFI,
},
{ "IPv4-nlrilen",
- "IPv4 MP Reach, nlri lenth overflow",
+ "IPv4 MP Reach, nlri lenth overflow",
{
/* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
/* nexthop bytes */ 4,
- /* Nexthop */ 192, 168, 0, 1,
+ /* Nexthop */ 192, 168, 0, 1,
/* SNPA (defunct, MBZ) */ 0x0,
/* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
- 30, 10,
+ 30, 10,
0, /* 0/0 */
},
(4 + 4 + 1 + 3 + 2 + 1),
@@ -287,13 +288,13 @@ static struct test_segment {
AFI_IP, SAFI_UNICAST, VALID_AFI,
},
{ "IPv4-vpnv4",
- "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs",
+ "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs",
{
/* AFI / SAFI */ 0x0, AFI_IP, BGP_SAFI_VPNV4,
/* nexthop bytes */ 12,
/* RD */ 0, 0, 1, 2,
0, 0xff, 3, 4,
- /* Nexthop */ 192, 168, 0, 1,
+ /* Nexthop */ 192, 168, 0, 1,
/* SNPA (defunct, MBZ) */ 0x0,
/* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
17, 10, 2, 3, /* 10.2.3/17 */
@@ -305,17 +306,17 @@ static struct test_segment {
},
/* From bug #385 */
{ "IPv6-bug",
- "IPv6, global nexthop, 1 default NLRI",
+ "IPv6, global nexthop, 1 default NLRI",
{
/* AFI / SAFI */ 0x0, 0x2, 0x1,
/* nexthop bytes */ 0x20,
- /* Nexthop (global) */ 0x20, 0x01, 0x04, 0x70,
+ /* Nexthop (global) */ 0x20, 0x01, 0x04, 0x70,
0x00, 0x01, 0x00, 0x06,
0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01,
- /* Nexthop (local) */ 0xfe, 0x80, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01,
+ /* Nexthop (local) */ 0xfe, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
- 0x02, 0x0c, 0xdb, 0xff,
+ 0x02, 0x0c, 0xdb, 0xff,
0xfe, 0xfe, 0xeb, 0x00,
/* SNPA (defunct, MBZ) */ 0,
/* NLRI tuples */ /* Should have 0 here for ::/0, but dont */
@@ -324,7 +325,7 @@ static struct test_segment {
SHOULD_ERR,
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
-
+
{ NULL, NULL, {0}, 0, 0}
};
@@ -332,34 +333,34 @@ static struct test_segment {
static struct test_segment mp_unreach_segments [] =
{
{ "IPv6-unreach",
- "IPV6 MP Unreach, 1 NLRI",
+ "IPV6 MP Unreach, 1 NLRI",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
/* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
},
- (3 + 5),
+ (3 + 5),
SHOULD_PARSE,
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-unreach2",
- "IPV6 MP Unreach, 2 NLRIs",
+ "IPV6 MP Unreach, 2 NLRIs",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
- /* NLRI tuples */ 32,
+ /* NLRI tuples */ 32,
0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
64,
0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
0x0, 0x2, 0x0, 0x3,
},
- (3 + 5 + 9),
+ (3 + 5 + 9),
SHOULD_PARSE,
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-unreach-default",
- "IPV6 MP Unreach, 2 NLRIs + default",
+ "IPV6 MP Unreach, 2 NLRIs + default",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
- /* NLRI tuples */ 32,
+ /* NLRI tuples */ 32,
0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
64,
0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
@@ -371,10 +372,10 @@ static struct test_segment mp_unreach_segments [] =
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv6-unreach-nlri",
- "IPV6 MP Unreach, NLRI bitlen overflow",
+ "IPV6 MP Unreach, NLRI bitlen overflow",
{
/* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
- /* NLRI tuples */ 120,
+ /* NLRI tuples */ 120,
0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
64,
0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
@@ -386,7 +387,7 @@ static struct test_segment mp_unreach_segments [] =
AFI_IP6, SAFI_UNICAST, VALID_AFI,
},
{ "IPv4-unreach",
- "IPv4 MP Unreach, 2 NLRIs + default",
+ "IPv4 MP Unreach, 2 NLRIs + default",
{
/* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
/* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
@@ -398,11 +399,11 @@ static struct test_segment mp_unreach_segments [] =
AFI_IP, SAFI_UNICAST, VALID_AFI,
},
{ "IPv4-unreach-nlrilen",
- "IPv4 MP Unreach, nlri length overflow",
+ "IPv4 MP Unreach, nlri length overflow",
{
/* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
/* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
- 30, 10,
+ 30, 10,
0, /* 0/0 */
},
(3 + 3 + 2 + 1),
@@ -410,13 +411,13 @@ static struct test_segment mp_unreach_segments [] =
AFI_IP, SAFI_UNICAST, VALID_AFI,
},
{ "IPv4-unreach-vpnv4",
- "IPv4/VPNv4 MP Unreach, RD, 3 NLRIs",
+ "IPv4/VPNv4 MP Unreach, RD, 3 NLRIs",
{
/* AFI / SAFI */ 0x0, AFI_IP, BGP_SAFI_VPNV4,
/* nexthop bytes */ 12,
/* RD */ 0, 0, 1, 2,
0, 0xff, 3, 4,
- /* Nexthop */ 192, 168, 0, 1,
+ /* Nexthop */ 192, 168, 0, 1,
/* SNPA (defunct, MBZ) */ 0x0,
/* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
17, 10, 2, 3, /* 10.2.3/17 */
@@ -439,13 +440,13 @@ parse_test (struct peer *peer, struct test_segment *t, int type)
struct attr attr;
struct bgp_nlri nlri;
#define RANDOM_FUZZ 35
-
+
stream_reset (peer->ibuf);
stream_put (peer->ibuf, NULL, RANDOM_FUZZ);
stream_set_getp (peer->ibuf, RANDOM_FUZZ);
-
+
stream_write (peer->ibuf, t->data, t->len);
-
+
printf ("%s: %s\n", t->name, t->desc);
if (type == BGP_ATTR_MP_REACH_NLRI)
@@ -456,30 +457,30 @@ parse_test (struct peer *peer, struct test_segment *t, int type)
if (!ret)
{
safi_t safi = t->safi;
-
+
if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid)
failed++;
-
+
printf ("MP: %u/%u (%u): recv %u, nego %u\n",
t->afi, t->safi, safi,
peer->afc_recv[t->afi][safi],
peer->afc_nego[t->afi][safi]);
}
-
+
printf ("parsed?: %s\n", ret ? "no" : "yes");
-
+
if (ret != t->parses)
failed++;
-
+
if (tty)
- printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET
+ printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET
: VT100_GREEN "OK" VT100_RESET);
else
printf ("%s", (failed > oldfailed) ? "failed!" : "OK" );
-
+
if (failed)
printf (" (%u)", failed);
-
+
printf ("\n\n");
}
@@ -491,7 +492,7 @@ main (void)
{
struct peer *peer;
int i, j;
-
+
conf_bgp_debug_fsm = -1UL;
conf_bgp_debug_events = -1UL;
conf_bgp_debug_packet = -1UL;
@@ -502,26 +503,26 @@ main (void)
term_bgp_debug_packet = -1UL;
term_bgp_debug_normal = -1UL;
term_bgp_debug_as4 = -1UL;
-
+
master = thread_master_create ();
bgp_master_init ();
-
- if (fileno (stdout) >= 0)
+
+ if (fileno (stdout) >= 0)
tty = isatty (fileno (stdout));
-
+
if (bgp_get (&bgp, &asn, NULL))
return -1;
-
+
peer = peer_create_accept (bgp);
- peer->host = "foo";
-
+ peer->host = miyagi("foo") ;
+
for (i = AFI_IP; i < AFI_MAX; i++)
for (j = SAFI_UNICAST; j < SAFI_MAX; j++)
{
peer->afc[i][j] = 1;
peer->afc_adv[i][j] = 1;
}
-
+
i = 0;
while (mp_reach_segments[i].name)
parse_test (peer, &mp_reach_segments[i++], BGP_ATTR_MP_REACH_NLRI);
diff --git a/tests/ecommunity_test.c b/tests/ecommunity_test.c
index 418f659f..da48865c 100644
--- a/tests/ecommunity_test.c
+++ b/tests/ecommunity_test.c
@@ -1,4 +1,5 @@
#include <zebra.h>
+#include "miyagi.h"
#include "vty.h"
#include "stream.h"
@@ -15,7 +16,7 @@ struct thread_master *master = NULL;
static int failed = 0;
/* specification for a test - what the results should be */
-struct test_spec
+struct test_spec
{
const char *shouldbe; /* the string the path should parse to */
};
@@ -28,7 +29,7 @@ static struct test_segment {
const u_char data[1024];
int len;
struct test_spec sp;
-} test_segments [] =
+} test_segments [] =
{
{ /* 0 */
"ipaddr",
@@ -73,7 +74,7 @@ validate (struct ecommunity *ecom, const struct test_spec *sp)
int fails = 0;
struct ecommunity *etmp;
char *str1, *str2;
-
+
printf ("got:\n %s\n", ecommunity_str (ecom));
str1 = ecommunity_ecom2str (ecom, ECOMMUNITY_FORMAT_COMMUNITY_LIST);
etmp = ecommunity_str2com (str1, 0, 1);
@@ -81,7 +82,7 @@ validate (struct ecommunity *ecom, const struct test_spec *sp)
str2 = ecommunity_ecom2str (etmp, ECOMMUNITY_FORMAT_COMMUNITY_LIST);
else
str2 = NULL;
-
+
if (strcmp (sp->shouldbe, str1))
{
failed++;
@@ -94,13 +95,13 @@ validate (struct ecommunity *ecom, const struct test_spec *sp)
fails++;
printf ("dogfood: in %s\n"
" in->out %s\n",
- str1,
+ str1,
(etmp && str2) ? str2 : "NULL");
}
ecommunity_free (etmp);
XFREE (MTYPE_ECOMMUNITY_STR, str1);
XFREE (MTYPE_ECOMMUNITY_STR, str2);
-
+
return fails;
}
@@ -109,10 +110,10 @@ static void
parse_test (struct test_segment *t)
{
struct ecommunity *ecom;
-
+
printf ("%s: %s\n", t->name, t->desc);
- ecom = ecommunity_parse (t->data, t->len);
+ ecom = ecommunity_parse (miyagi(t->data), t->len);
printf ("ecom: %s\nvalidating...:\n", ecommunity_str (ecom));
@@ -120,12 +121,12 @@ parse_test (struct test_segment *t)
printf ("OK\n");
else
printf ("failed\n");
-
+
printf ("\n");
ecommunity_unintern (ecom);
}
-
+
int
main (void)
{
@@ -133,7 +134,7 @@ main (void)
ecommunity_init();
while (test_segments[i].name)
parse_test (&test_segments[i++]);
-
+
printf ("failures: %d\n", failed);
//printf ("aspath count: %ld\n", aspath_count());
return failed;
diff --git a/tests/heavy-thread.c b/tests/heavy-thread.c
index cd3a3b9d..f7a99cc5 100644
--- a/tests/heavy-thread.c
+++ b/tests/heavy-thread.c
@@ -59,17 +59,17 @@ slow_func (struct vty *vty, const char *str, const int i)
{
double x = 1;
int j;
-
+
for (j = 0; j < 300; j++)
x += sin(x)*j;
-
+
if ((i % ITERS_LATER) == 0)
printf ("%s: %d, temporary error, save this somehow and do it later..\n",
__func__, i);
-
+
if ((i % ITERS_ERR) == 0)
printf ("%s: hard error\n", __func__);
-
+
if ((i % ITERS_PRINT) == 0)
printf ("%s did %d, x = %g\n", str, i, x);
}
@@ -78,8 +78,8 @@ static int
clear_something (struct thread *thread)
{
struct work_state *ws = THREAD_ARG(thread);
-
- /* this could be like iterating through 150k of route_table
+
+ /* this could be like iterating through 150k of route_table
* or worse, iterating through a list of peers, to bgp_stop them with
* each having 150k route tables to process...
*/
@@ -93,7 +93,7 @@ clear_something (struct thread *thread)
return 0;
}
}
-
+
/* All done! */
XFREE (MTYPE_TMP, ws->str);
XFREE (MTYPE_TMP, ws);
@@ -114,22 +114,22 @@ DEFUN (clear_foo,
vty_out (vty, "%% string argument required%s", VTY_NEWLINE);
return CMD_WARNING;
}
-
+
str = argv_concat (argv, argc, 0);
-
+
if ((ws = XMALLOC(MTYPE_TMP, sizeof(*ws))) == NULL)
{
zlog_err ("%s: unable to allocate work_state", __func__);
return CMD_WARNING;
}
-
+
if (!(ws->str = XSTRDUP (MTYPE_TMP, str)))
{
zlog_err ("%s: unable to xstrdup", __func__);
XFREE (MTYPE_TMP, ws);
return CMD_WARNING;
}
-
+
ws->vty = vty;
ws->i = ITERS_FIRST;
@@ -138,8 +138,10 @@ DEFUN (clear_foo,
return CMD_SUCCESS;
}
+extern void test_init(void) ;
+
void
-test_init()
+test_init(void)
{
install_element (VIEW_NODE, &clear_foo_cmd);
}
diff --git a/tests/heavy-wq.c b/tests/heavy-wq.c
index a2c609d4..4cd499a5 100644
--- a/tests/heavy-wq.c
+++ b/tests/heavy-wq.c
@@ -66,7 +66,7 @@ heavy_wq_add (struct vty *vty, const char *str, int i)
zlog_err ("%s: unable to allocate hn", __func__);
return;
}
-
+
hn->i = i;
if (!(hn->str = XSTRDUP (MTYPE_PREFIX_LIST_STR, str)))
{
@@ -74,9 +74,9 @@ heavy_wq_add (struct vty *vty, const char *str, int i)
XFREE (MTYPE_PREFIX_LIST, hn);
return;
}
-
+
work_queue_add (heavy_wq, hn);
-
+
return;
}
@@ -93,7 +93,7 @@ slow_func_del (struct work_queue *wq, void *data)
assert (hn && hn->str);
printf ("%s: %s\n", __func__, hn->str);
XFREE (MTYPE_PREFIX_LIST_STR, hn->str);
- hn->str = NULL;
+ hn->str = NULL;
XFREE(MTYPE_PREFIX_LIST, hn);
}
@@ -103,18 +103,18 @@ slow_func (struct work_queue *wq, void *data)
struct heavy_wq_node *hn = data;
double x = 1;
int j;
-
+
assert (hn && hn->str);
-
+
for (j = 0; j < 300; j++)
x += sin(x)*j;
-
+
if ((hn->i % ITERS_LATER) == 0)
return WQ_RETRY_LATER;
-
+
if ((hn->i % ITERS_ERR) == 0)
return WQ_RETRY_NOW;
-
+
if ((hn->i % ITERS_PRINT) == 0)
printf ("%s did %d, x = %g\n", hn->str, hn->i, x);
@@ -125,8 +125,8 @@ static void
clear_something (struct vty *vty, const char *str)
{
int i;
-
- /* this could be like iterating through 150k of route_table
+
+ /* this could be like iterating through 150k of route_table
* or worse, iterating through a list of peers, to bgp_stop them with
* each having 150k route tables to process...
*/
@@ -146,9 +146,9 @@ DEFUN (clear_foo,
vty_out (vty, "%% string argument required%s", VTY_NEWLINE);
return CMD_WARNING;
}
-
+
str = argv_concat (argv, argc, 0);
-
+
clear_something (vty, str);
XFREE (MTYPE_TMP, str);
return CMD_SUCCESS;
@@ -162,18 +162,20 @@ heavy_wq_init ()
zlog_err ("%s: could not get new work queue!", __func__);
return -1;
}
-
+
heavy_wq->spec.workfunc = &slow_func;
heavy_wq->spec.errorfunc = &slow_func_err;
heavy_wq->spec.del_item_data = &slow_func_del;
heavy_wq->spec.max_retries = 3;
heavy_wq->spec.hold = 1000;
-
+
return 0;
}
-void
-test_init()
+extern void test_init(void) ;
+
+extern void
+test_init(void)
{
install_element (VIEW_NODE, &clear_foo_cmd);
heavy_wq_init();
diff --git a/tests/heavy.c b/tests/heavy.c
index 577a4816..901fb10f 100644
--- a/tests/heavy.c
+++ b/tests/heavy.c
@@ -50,27 +50,27 @@ slow_func (struct vty *vty, const char *str, const int i)
{
double x = 1;
int j;
-
+
for (j = 0; j < 300; j++)
x += sin(x)*j;
-
+
if ((i % ITERS_LATER) == 0)
- printf ("%s: %d, temporary error, save this somehow and do it later..\n",
+ printf ("%s: %d, temporary error, save this somehow and do it later..\n",
__func__, i);
-
+
if ((i % ITERS_ERR) == 0)
printf ("%s: hard error\n", __func__);
-
+
if ((i % ITERS_PRINT) == 0)
- printf ("%s did %d, x = %g%s", str, i, x, VTY_NEWLINE);
+ printf ("%s did %d, x = %g%s", str, i, x, VTY_NEWLINE);
}
static void
clear_something (struct vty *vty, const char *str)
{
int i;
-
- /* this could be like iterating through 150k of route_table
+
+ /* this could be like iterating through 150k of route_table
* or worse, iterating through a list of peers, to bgp_stop them with
* each having 150k route tables to process...
*/
@@ -90,9 +90,9 @@ DEFUN (clear_foo,
vty_out (vty, "%% string argument required%s", VTY_NEWLINE);
return CMD_WARNING;
}
-
+
str = argv_concat (argv, argc, 0);
-
+
clear_something (vty, str);
XFREE (MTYPE_TMP, str);
return CMD_SUCCESS;
@@ -104,8 +104,10 @@ slow_vty_init()
install_element (VIEW_NODE, &clear_foo_cmd);
}
-void
-test_init()
+extern void test_init(void) ;
+
+extern void
+test_init(void)
{
slow_vty_init();
}
diff --git a/tests/main.c b/tests/main.c
index e0fbb4d5..f735e1e1 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -32,7 +32,7 @@ extern void test_init();
struct thread_master *master;
-struct option longopts[] =
+struct option longopts[] =
{
{ "daemon", no_argument, NULL, 'd'},
{ "config_file", required_argument, NULL, 'f'},
@@ -51,12 +51,14 @@ DEFUN (daemon_exit,
exit(0);
}
+extern int test_timer (struct thread *thread) ;
+
static int timer_count;
-int
+extern int
test_timer (struct thread *thread)
{
int *count = THREAD_ARG(thread);
-
+
printf ("run %d of timer\n", (*count)++);
thread_add_timer (master, test_timer, count, 5);
return 0;
@@ -81,7 +83,7 @@ usage (char *progname, int status)
if (status != 0)
fprintf (stderr, "Try `%s --help' for more information.\n", progname);
else
- {
+ {
printf ("Usage : %s [OPTION...]\n\
Daemon which does 'slow' things.\n\n\
-d, --daemon Runs in daemon mode\n\
@@ -95,8 +97,8 @@ Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
}
exit (status);
}
-
-
+
+
/* main routine. */
int
main (int argc, char **argv)
@@ -108,7 +110,7 @@ main (int argc, char **argv)
char *progname;
struct thread thread;
char *config_file = NULL;
-
+
/* Set umask before anything for security */
umask (0027);
@@ -118,16 +120,16 @@ main (int argc, char **argv)
/* master init. */
master = thread_master_create ();
- while (1)
+ while (1)
{
int opt;
opt = getopt_long (argc, argv, "dhf:A:P:v", longopts, 0);
-
+
if (opt == EOF)
break;
- switch (opt)
+ switch (opt)
{
case 0:
break;
@@ -146,7 +148,7 @@ main (int argc, char **argv)
{
vty_port = 0;
break;
- }
+ }
vty_port = atoi (optarg);
vty_port = (vty_port ? vty_port : 4000);
break;
@@ -182,16 +184,16 @@ main (int argc, char **argv)
/* Create VTY socket */
vty_serv_sock (vty_addr, vty_port, "/tmp/.heavy.sock");
-
+
/* Configuration file read*/
if (!config_file)
usage (progname, 1);
vty_read_config (config_file, NULL);
-
+
test_timer_init();
-
- test_init();
-
+
+ test_init();
+
/* Fetch next active thread. */
while (thread_fetch (master, &thread))
thread_call (&thread);
diff --git a/tests/test-checksum.c b/tests/test-checksum.c
index bd156baa..5fb5d0dd 100644
--- a/tests/test-checksum.c
+++ b/tests/test-checksum.c
@@ -13,7 +13,7 @@ struct acc_vals {
struct csum_vals {
struct acc_vals a;
- int x;
+ int x;
int y;
};
@@ -24,9 +24,9 @@ typedef uint16_t testoff_t;
/* Fletcher Checksum -- Refer to RFC1008. */
#define MODX 4102
-
+
/* Accumulator phase of checksum */
-static
+static
struct acc_vals
accumulate (u_char *buffer, testsz_t len, testoff_t off)
{
@@ -34,15 +34,15 @@ accumulate (u_char *buffer, testsz_t len, testoff_t off)
u_int16_t *csum;
int i, init_len, partial_len;
struct acc_vals ret;
-
+
csum = (u_int16_t *) (buffer + off);
*(csum) = 0;
-
+
p = buffer;
ret.c0 = 0;
ret.c1 = 0;
init_len = len;
-
+
while (len != 0)
{
partial_len = MIN(len, MODX);
@@ -62,9 +62,9 @@ accumulate (u_char *buffer, testsz_t len, testoff_t off)
}
/* The final reduction phase.
- * This one should be the original ospfd version
+ * This one should be the original ospfd version
*/
-static u_int16_t
+static u_int16_t
reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off)
{
#define x vals->x
@@ -73,7 +73,7 @@ reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off)
#define c1 vals->a.c1
x = ((len - off - 1) * c0 - c1) % 255;
-
+
if (x <= 0)
x += 255;
y = 510 - c0 - x;
@@ -81,7 +81,7 @@ reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off)
y -= 255;
/* take care endian issue. */
- return htons ((x << 8) + y);
+ return htons ((x << 8) + y);
#undef x
#undef y
#undef c0
@@ -89,7 +89,7 @@ reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off)
}
/* slightly different concatenation */
-static u_int16_t
+static u_int16_t
reduce_ospfd1 (struct csum_vals *vals, testsz_t len, testoff_t off)
{
#define x vals->x
@@ -105,7 +105,7 @@ reduce_ospfd1 (struct csum_vals *vals, testsz_t len, testoff_t off)
y -= 255;
/* take care endian issue. */
- return htons ((x << 8) | (y & 0xff));
+ return htons ((x << 8) | (y & 0xff));
#undef x
#undef y
#undef c0
@@ -113,7 +113,7 @@ reduce_ospfd1 (struct csum_vals *vals, testsz_t len, testoff_t off)
}
/* original isisd version */
-static u_int16_t
+static u_int16_t
reduce_isisd (struct csum_vals *vals, testsz_t len, testoff_t off)
{
#define x vals->x
@@ -121,7 +121,7 @@ reduce_isisd (struct csum_vals *vals, testsz_t len, testoff_t off)
#define c0 vals->a.c0
#define c1 vals->a.c1
u_int32_t mul;
-
+
mul = (len - off)*(c0);
x = mul - c0 - c1;
y = c1 - mul - 1;
@@ -148,7 +148,7 @@ reduce_isisd (struct csum_vals *vals, testsz_t len, testoff_t off)
}
/* Is the -1 in y wrong perhaps? */
-static u_int16_t
+static u_int16_t
reduce_isisd_yfix (struct csum_vals *vals, testsz_t len, testoff_t off)
{
#define x vals->x
@@ -156,7 +156,7 @@ reduce_isisd_yfix (struct csum_vals *vals, testsz_t len, testoff_t off)
#define c0 vals->a.c0
#define c1 vals->a.c1
u_int32_t mul;
-
+
mul = (len - off)*(c0);
x = mul - c0 - c1;
y = c1 - mul;
@@ -183,7 +183,7 @@ reduce_isisd_yfix (struct csum_vals *vals, testsz_t len, testoff_t off)
}
/* Move the mods yp */
-static u_int16_t
+static u_int16_t
reduce_isisd_mod (struct csum_vals *vals, testsz_t len, testoff_t off)
{
#define x vals->x
@@ -191,7 +191,7 @@ reduce_isisd_mod (struct csum_vals *vals, testsz_t len, testoff_t off)
#define c0 vals->a.c0
#define c1 vals->a.c1
u_int32_t mul;
-
+
mul = (len - off)*(c0);
x = mul - c1 - c0;
y = c1 - mul - 1;
@@ -218,7 +218,7 @@ reduce_isisd_mod (struct csum_vals *vals, testsz_t len, testoff_t off)
}
/* Move the mods up + fix y */
-static u_int16_t
+static u_int16_t
reduce_isisd_mody (struct csum_vals *vals, testsz_t len, testoff_t off)
{
#define x vals->x
@@ -226,7 +226,7 @@ reduce_isisd_mody (struct csum_vals *vals, testsz_t len, testoff_t off)
#define c0 vals->a.c0
#define c1 vals->a.c1
u_int32_t mul;
-
+
mul = (len - off)*(c0);
x = mul - c0 - c1;
y = c1 - mul;
@@ -264,7 +264,7 @@ struct reductions_t {
{ .name = "isisd-mody", .f = reduce_isisd_mody },
{ NULL, NULL },
};
-
+
/* The original ospfd checksum */
static u_int16_t
ospfd_checksum (u_char *buffer, testsz_t len, testoff_t off)
@@ -276,7 +276,7 @@ ospfd_checksum (u_char *buffer, testsz_t len, testoff_t off)
csum = (u_int16_t *) (buffer + off);
*(csum) = 0;
-
+
sp = buffer;
for (ep = sp + len; sp < ep; sp = q)
@@ -292,27 +292,27 @@ ospfd_checksum (u_char *buffer, testsz_t len, testoff_t off)
c0 %= 255;
c1 %= 255;
}
-
+
ospfd_vals.a.c0 = c0;
ospfd_vals.a.c1 = c1;
-
+
//printf ("%s: len %u, off %u, c0 %d, c1 %d\n",
// __func__, len, off, c0, c1);
x = ((int)(len - off - 1) * (int)c0 - (int)c1) % 255;
-
+
if (x <= 0)
x += 255;
y = 510 - c0 - x;
if (y > 255)
y -= 255;
-
+
ospfd_vals.x = x;
ospfd_vals.y = y;
-
+
buffer[off] = x;
buffer[off + 1] = y;
-
+
/* take care endian issue. */
checksum = htons ((x << 8) | (y & 0xff));
@@ -334,15 +334,15 @@ iso_csum_create (u_char * buffer, testsz_t len, testoff_t off)
int i, init_len, partial_len;
checksum = 0;
-
+
csum = (u_int16_t *) (buffer + off);
*(csum) = checksum;
-
+
p = buffer;
c0 = 0;
c1 = 0;
init_len = len;
-
+
while (len != 0)
{
partial_len = MIN(len, MODX);
@@ -361,7 +361,7 @@ iso_csum_create (u_char * buffer, testsz_t len, testoff_t off)
isisd_vals.a.c0 = c0;
isisd_vals.a.c1 = c1;
-
+
mul = (init_len - off) * c0;
x = mul - c1 - c0;
@@ -379,14 +379,14 @@ iso_csum_create (u_char * buffer, testsz_t len, testoff_t off)
x = 255;
if (y == 0)
y = 1;
-
+
isisd_vals.x = x;
isisd_vals.y = y;
-
+
checksum = htons((x << 8) | (y & 0xFF));
-
+
*(csum) = checksum;
-
+
/* return the checksum for user usage */
return checksum;
}
@@ -399,7 +399,7 @@ verify (u_char * buffer, testsz_t len)
u_int32_t c1;
u_int16_t checksum;
int i, partial_len;
-
+
p = buffer;
checksum = 0;
@@ -427,6 +427,8 @@ verify (u_char * buffer, testsz_t len)
return 1;
}
+extern int in_cksum_optimized(void *parg, int nbytes) ;
+
int /* return checksum in low-order 16 bits */
in_cksum_optimized(void *parg, int nbytes)
{
@@ -458,6 +460,7 @@ in_cksum_optimized(void *parg, int nbytes)
return(answer);
}
+extern int in_cksum_rfc(void *parg, int count) ;
int /* return checksum in low-order 16 bits */
in_cksum_rfc(void *parg, int count)
@@ -495,29 +498,29 @@ main(int argc, char **argv)
u_char buffer[BUFSIZE];
int exercise = 0;
#define EXERCISESTEP 257
-
+
srandom (time (NULL));
-
+
while (1) {
u_int16_t ospfd, isisd, lib, in_csum, in_csum_res, in_csum_rfc;
int i,j;
exercise += EXERCISESTEP;
exercise %= MAXDATALEN;
-
+
for (i = 0; i < exercise; i += sizeof (long int)) {
long int rand = random ();
-
+
for (j = sizeof (long int); j > 0; j--)
buffer[i + (sizeof (long int) - j)] = (rand >> (j * 8)) & 0xff;
}
-
+
in_csum = in_cksum(buffer, exercise);
in_csum_res = in_cksum_optimized(buffer, exercise);
in_csum_rfc = in_cksum_rfc(buffer, exercise);
if (in_csum_res != in_csum || in_csum != in_csum_rfc)
printf ("verify: in_chksum failed in_csum:%x, in_csum_res:%x,"
- "in_csum_rfc %x, len:%d\n",
+ "in_csum_rfc %x, len:%d\n",
in_csum, in_csum_res, in_csum_rfc, exercise);
ospfd = ospfd_checksum (buffer, exercise + sizeof(u_int16_t), exercise);
@@ -529,7 +532,7 @@ main(int argc, char **argv)
lib = fletcher_checksum (buffer, exercise + sizeof(u_int16_t), exercise);
if (verify (buffer, exercise + sizeof(u_int16_t)))
printf ("verify: lib failed\n");
-
+
if (ospfd != lib) {
printf ("Mismatch in values at size %u\n"
"ospfd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n"
@@ -540,12 +543,12 @@ main(int argc, char **argv)
isisd, isisd_vals.a.c0, isisd_vals.a.c1, isisd_vals.x, isisd_vals.y,
lib
);
-
+
/* Investigate reduction phase discrepencies */
if (ospfd_vals.a.c0 == isisd_vals.a.c0
&& ospfd_vals.a.c1 == isisd_vals.a.c1) {
printf ("\n");
- for (i = 0; reducts[i].name != NULL; i++) {
+ for (i = 0; reducts[i].name != NULL; i++) {
ospfd = reducts[i].f (&ospfd_vals,
exercise + sizeof (u_int16_t),
exercise);
@@ -553,7 +556,7 @@ main(int argc, char **argv)
reducts[i].name, ospfd_vals.x & 0xff, ospfd_vals.y & 0xff, ospfd);
}
}
-
+
printf ("\n u_char testdata [] = {\n ");
for (i = 0; i < exercise; i++) {
printf ("0x%02x,%s",
diff --git a/tests/test-sig.c b/tests/test-sig.c
index 63aab6f0..d9eb24f0 100644
--- a/tests/test-sig.c
+++ b/tests/test-sig.c
@@ -2,6 +2,10 @@
#include <sigevent.h>
#include "lib/log.h"
+extern void sighup (void) ;
+extern void sigusr1 (void) ;
+extern void sigusr2 (void) ;
+
void
sighup (void)
{
@@ -20,7 +24,7 @@ sigusr2 (void)
printf ("processed usr2\n");
}
-struct quagga_signal_t sigs[] =
+struct quagga_signal_t sigs[] =
{
{
.signal = SIGHUP,
@@ -44,13 +48,13 @@ main (void)
{
master = thread_master_create ();
signal_init (master, Q_SIGC(sigs), sigs);
-
+
zlog_default = openzlog("testsig", ZLOG_NONE,
LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG);
zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED);
-
+
while (thread_fetch (master, &t))
thread_call (&t);
diff --git a/watchquagga/watchquagga.c b/watchquagga/watchquagga.c
index fb628acc..d4416224 100644
--- a/watchquagga/watchquagga.c
+++ b/watchquagga/watchquagga.c
@@ -180,7 +180,7 @@ struct daemon {
struct restart_info restart;
};
-static const struct option longopts[] =
+static const struct option longopts[] =
{
{ "daemon", no_argument, NULL, 'd'},
{ "statedir", required_argument, NULL, 'S'},
@@ -346,8 +346,8 @@ run_background(const char *shell_cmd)
if (setpgid(0,0) < 0)
zlog_warn("warning: setpgid(0,0) failed: %s",safe_strerror(errno));
{
- const char *argv[4] = { "sh", "-c", shell_cmd, NULL};
- execv("/bin/sh",(char *const *)argv);
+ const char *const argv[4] = { "sh", "-c", shell_cmd, NULL};
+ execv("/bin/sh",(char *const *)argv);
zlog_err("execv(/bin/sh -c '%s') failed: %s",
shell_cmd,safe_strerror(errno));
_exit(127);
@@ -420,7 +420,7 @@ sigchild(void)
const char *what;
struct restart_info *restart;
- switch (child = waitpid(-1,&status,WNOHANG))
+ switch (child = waitpid(-1,&status,WNOHANG))
{
case -1:
zlog_err("waitpid failed: %s",safe_strerror(errno));
@@ -1232,7 +1232,7 @@ main(int argc, char **argv)
return usage(progname,1);
}
}
-
+
if (gs.unresponsive_restart && (gs.mode == MODE_MONITOR))
{
fputs("Option -z requires a -r or -R restart option.\n",stderr);
@@ -1278,7 +1278,7 @@ main(int argc, char **argv)
if (gs.stop_command)
gs.stop_command = translate_blanks(gs.stop_command,blankstr);
}
-
+
gs.restart.interval = gs.min_restart_interval;
master = thread_master_create();
signal_init (master, Q_SIGC(my_signals), my_signals);
diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c
index 701c81b6..013dd811 100644
--- a/zebra/if_netlink.c
+++ b/zebra/if_netlink.c
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with GNU Zebra; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include <zebra.h>
@@ -25,8 +25,10 @@
extern int interface_lookup_netlink (void);
/* Interface information read by netlink. */
-void
+extern void interface_list (void) ;
+
+extern void
interface_list (void)
{
- interface_lookup_netlink ();
+ interface_lookup_netlink ();
}
diff --git a/zebra/ioctl.c b/zebra/ioctl.c
index d783b0a3..7c51e91b 100644
--- a/zebra/ioctl.c
+++ b/zebra/ioctl.c
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with GNU Zebra; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include <zebra.h>
@@ -52,7 +52,7 @@ if_ioctl (u_long request, caddr_t buffer)
{
int sock;
int ret;
- int err;
+ int err = 0 ; /* initialise to avoid warning */
if (zserv_privs.change(ZPRIVS_RAISE))
zlog (NULL, LOG_ERR, "Can't raise privileges");
@@ -70,8 +70,8 @@ if_ioctl (u_long request, caddr_t buffer)
if (zserv_privs.change(ZPRIVS_LOWER))
zlog (NULL, LOG_ERR, "Can't lower privileges");
close (sock);
-
- if (ret < 0)
+
+ if (ret < 0)
{
errno = err;
return ret;
@@ -85,7 +85,7 @@ if_ioctl_ipv6 (u_long request, caddr_t buffer)
{
int sock;
int ret;
- int err;
+ int err = 0 ; /* initialise to avoid warning */
if (zserv_privs.change(ZPRIVS_RAISE))
zlog (NULL, LOG_ERR, "Can't raise privileges");
@@ -105,8 +105,8 @@ if_ioctl_ipv6 (u_long request, caddr_t buffer)
if (zserv_privs.change(ZPRIVS_LOWER))
zlog (NULL, LOG_ERR, "Can't lower privileges");
close (sock);
-
- if (ret < 0)
+
+ if (ret < 0)
{
errno = err;
return ret;
@@ -127,7 +127,7 @@ if_get_metric (struct interface *ifp)
ifreq_set_name (&ifreq, ifp);
- if (if_ioctl (SIOCGIFMETRIC, (caddr_t) &ifreq) < 0)
+ if (if_ioctl (SIOCGIFMETRIC, (caddr_t) &ifreq) < 0)
return;
ifp->metric = ifreq.ifr_metric;
if (ifp->metric == 0)
@@ -146,7 +146,7 @@ if_get_mtu (struct interface *ifp)
ifreq_set_name (&ifreq, ifp);
#if defined(SIOCGIFMTU)
- if (if_ioctl (SIOCGIFMTU, (caddr_t) & ifreq) < 0)
+ if (if_ioctl (SIOCGIFMTU, (caddr_t) & ifreq) < 0)
{
zlog_info ("Can't lookup mtu by ioctl(SIOCGIFMTU)");
ifp->mtu6 = ifp->mtu = -1;
@@ -216,7 +216,7 @@ if_set_prefix (struct interface *ifp, struct connected *ifc)
mask.sin_len = sizeof (struct sockaddr_in);
#endif
memcpy (&addreq.ifra_mask, &mask, sizeof (struct sockaddr_in));
-
+
ret = if_ioctl (SIOCAIFADDR, (caddr_t) &addreq);
if (ret < 0)
return ret;
@@ -254,7 +254,7 @@ if_unset_prefix (struct interface *ifp, struct connected *ifc)
mask.sin_len = sizeof (struct sockaddr_in);
#endif
memcpy (&addreq.ifra_mask, &mask, sizeof (struct sockaddr_in));
-
+
ret = if_ioctl (SIOCDIFADDR, (caddr_t) &addreq);
if (ret < 0)
return ret;
@@ -286,7 +286,7 @@ if_set_prefix (struct interface *ifp, struct connected *ifc)
ret = if_ioctl (SIOCSIFADDR, (caddr_t) &ifreq);
if (ret < 0)
return ret;
-
+
/* We need mask for make broadcast addr. */
masklen2ip (p->prefixlen, &mask.sin_addr);
@@ -356,7 +356,7 @@ if_get_flags (struct interface *ifp)
ifreq_set_name (&ifreq, ifp);
ret = if_ioctl (SIOCGIFFLAGS, (caddr_t) &ifreq);
- if (ret < 0)
+ if (ret < 0)
{
zlog_err("if_ioctl(SIOCGIFFLAGS) failed: %s", safe_strerror(errno));
return;
@@ -368,12 +368,12 @@ if_get_flags (struct interface *ifp)
* following practice on Linux and Solaris kernels
*/
SET_FLAG(ifreq.ifr_flags, IFF_RUNNING);
-
+
if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
{
(void) memset(&ifmr, 0, sizeof(ifmr));
strncpy (ifmr.ifm_name, ifp->name, IFNAMSIZ);
-
+
/* Seems not all interfaces implement this ioctl */
if (if_ioctl(SIOCGIFMEDIA, (caddr_t) &ifmr) < 0)
zlog_err("if_ioctl(SIOCGIFMEDIA) failed: %s", safe_strerror(errno));
@@ -441,7 +441,7 @@ if_unset_flags (struct interface *ifp, uint64_t flags)
#ifdef LINUX_IPV6
#ifndef _LINUX_IN6_H
/* linux/include/net/ipv6.h */
-struct in6_ifreq
+struct in6_ifreq
{
struct in6_addr ifr6_addr;
u_int32_t ifr6_prefixlen;
@@ -526,10 +526,10 @@ if_prefix_add_ipv6 (struct interface *ifp, struct connected *ifc)
addreq.ifra_lifetime.ia6t_vltime = 0xffffffff;
addreq.ifra_lifetime.ia6t_pltime = 0xffffffff;
-
-#ifdef HAVE_STRUCT_IF6_ALIASREQ_IFRA_LIFETIME
- addreq.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
- addreq.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
+
+#ifdef HAVE_STRUCT_IF6_ALIASREQ_IFRA_LIFETIME
+ addreq.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
+ addreq.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
#endif
ret = if_ioctl_ipv6 (SIOCAIFADDR_IN6, (caddr_t) &addreq);
@@ -569,8 +569,8 @@ if_prefix_delete_ipv6 (struct interface *ifp, struct connected *ifc)
memcpy (&addreq.ifra_prefixmask, &mask, sizeof (struct sockaddr_in6));
#ifdef HAVE_STRUCT_IF6_ALIASREQ_IFRA_LIFETIME
- addreq.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
- addreq.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
+ addreq.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
+ addreq.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
#endif
ret = if_ioctl_ipv6 (SIOCDIFADDR_IN6, (caddr_t) &addreq);
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index 7652f80a..b5fe0ec8 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with GNU Zebra; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include <zebra.h>
@@ -104,7 +104,7 @@ set_ifindex(struct interface *ifp, unsigned int ifi_index)
ifi_index, oifp->name, ifp->name);
if (if_is_up(oifp))
zlog_err("interface rename detected on up interface: index %d "
- "was renamed from %s to %s, results are uncertain!",
+ "was renamed from %s to %s, results are uncertain!",
ifi_index, oifp->name, ifp->name);
if_delete_update(oifp);
}
@@ -242,7 +242,7 @@ netlink_request (int family, int type, struct nlsock *nl)
req.nlh.nlmsg_seq = ++nl->seq;
req.g.rtgen_family = family;
- /* linux appears to check capabilities on every message
+ /* linux appears to check capabilities on every message
* have to raise caps for every message sent
*/
if (zserv_privs.change (ZPRIVS_RAISE))
@@ -310,7 +310,7 @@ netlink_parse_info (int (*filter) (struct sockaddr_nl *, struct nlmsghdr *),
nl->name, msg.msg_namelen);
return -1;
}
-
+
for (h = (struct nlmsghdr *) buf; NLMSG_OK (h, (unsigned int) status);
h = NLMSG_NEXT (h, status))
{
@@ -450,7 +450,7 @@ netlink_interface (struct sockaddr_nl *snl, struct nlmsghdr *h)
/* Looking up interface name. */
memset (tb, 0, sizeof tb);
netlink_parse_rtattr (tb, IFLA_MAX, IFLA_RTA (ifi), len);
-
+
#ifdef IFLA_WIRELESS
/* check for wireless messages to ignore */
if ((tb[IFLA_WIRELESS] != NULL) && (ifi->ifi_change == 0))
@@ -563,7 +563,7 @@ netlink_interface_addr (struct sockaddr_nl *snl, struct nlmsghdr *h)
buf, BUFSIZ), ifa->ifa_prefixlen);
if (tb[IFA_LABEL] && strcmp (ifp->name, RTA_DATA (tb[IFA_LABEL])))
zlog_debug (" IFA_LABEL %s", (char *)RTA_DATA (tb[IFA_LABEL]));
-
+
if (tb[IFA_CACHEINFO])
{
struct ifa_cacheinfo *ci = RTA_DATA (tb[IFA_CACHEINFO]);
@@ -571,13 +571,13 @@ netlink_interface_addr (struct sockaddr_nl *snl, struct nlmsghdr *h)
ci->ifa_prefered, ci->ifa_valid);
}
}
-
+
/* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
if (tb[IFA_LOCAL] == NULL)
tb[IFA_LOCAL] = tb[IFA_ADDRESS];
if (tb[IFA_ADDRESS] == NULL)
tb[IFA_ADDRESS] = tb[IFA_LOCAL];
-
+
/* local interface address */
addr = (tb[IFA_LOCAL] ? RTA_DATA(tb[IFA_LOCAL]) : NULL);
@@ -934,7 +934,7 @@ netlink_link_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
return 0;
}
#endif /* IFLA_WIRELESS */
-
+
if (tb[IFLA_IFNAME] == NULL)
return -1;
name = (char *) RTA_DATA (tb[IFLA_IFNAME]);
@@ -1037,7 +1037,9 @@ netlink_information_fetch (struct sockaddr_nl *snl, struct nlmsghdr *h)
}
/* Interface lookup by netlink socket. */
-int
+extern int interface_lookup_netlink (void) ;
+
+extern int
interface_lookup_netlink (void)
{
int ret;
@@ -1073,7 +1075,9 @@ interface_lookup_netlink (void)
/* Routing table read function using netlink interface. Only called
bootstrap time. */
-int
+extern int netlink_route_read (void) ;
+
+extern int
netlink_route_read (void)
{
int ret;
@@ -1099,7 +1103,7 @@ netlink_route_read (void)
return 0;
}
-/* Utility function comes from iproute2.
+/* Utility function comes from iproute2.
Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> */
static int
addattr_l (struct nlmsghdr *n, int maxlen, int type, void *data, int alen)
@@ -1109,7 +1113,7 @@ addattr_l (struct nlmsghdr *n, int maxlen, int type, void *data, int alen)
len = RTA_LENGTH (alen);
- if (NLMSG_ALIGN (n->nlmsg_len) + len > maxlen)
+ if (NLMSG_ALIGN (n->nlmsg_len) + len > (unsigned)maxlen)
return -1;
rta = (struct rtattr *) (((char *) n) + NLMSG_ALIGN (n->nlmsg_len));
@@ -1141,7 +1145,7 @@ rta_addattr_l (struct rtattr *rta, int maxlen, int type, void *data, int alen)
return 0;
}
-/* Utility function comes from iproute2.
+/* Utility function comes from iproute2.
Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> */
static int
addattr32 (struct nlmsghdr *n, int maxlen, int type, int data)
@@ -1151,7 +1155,7 @@ addattr32 (struct nlmsghdr *n, int maxlen, int type, int data)
len = RTA_LENGTH (4);
- if (NLMSG_ALIGN (n->nlmsg_len) + len > maxlen)
+ if (NLMSG_ALIGN (n->nlmsg_len) + len > (unsigned)maxlen)
return -1;
rta = (struct rtattr *) (((char *) n) + NLMSG_ALIGN (n->nlmsg_len));
@@ -1209,8 +1213,8 @@ netlink_talk (struct nlmsghdr *n, struct nlsock *nl)
}
- /*
- * Get reply from netlink socket.
+ /*
+ * Get reply from netlink socket.
* The reply should either be an acknowlegement or an error.
*/
return netlink_parse_info (netlink_talk_filter, nl);
@@ -1379,7 +1383,7 @@ netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib,
#else
inet_ntoa (p->u.prefix4),
#endif /* HAVE_IPV6 */
-
+
p->prefixlen, nexthop_types_desc[nexthop->rtype]);
}
@@ -1648,7 +1652,7 @@ netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib,
if (nexthop->type == NEXTHOP_TYPE_IPV6
|| nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME
|| nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX)
- {
+ {
rta_addattr_l (rta, 4096, RTA_GATEWAY,
&nexthop->gate.ipv6, bytelen);
@@ -1751,7 +1755,7 @@ kernel_delete_ipv6_old (struct prefix_ipv6 *dest, struct in6_addr *gate,
dest->prefixlen, gate, index, flags, table);
}
#endif /* HAVE_IPV6 */
-
+
/* Interface address modification. */
static int
netlink_address (int cmd, int family, struct interface *ifp,
diff --git a/zebra/rtread_netlink.c b/zebra/rtread_netlink.c
index 44715d94..800e552b 100644
--- a/zebra/rtread_netlink.c
+++ b/zebra/rtread_netlink.c
@@ -17,13 +17,14 @@
* You should have received a copy of the GNU General Public License
* along with GNU Zebra; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include <zebra.h>
extern void netlink_route_read (void);
+extern void route_read (void) ;
-void route_read (void)
+extern void route_read (void)
{
netlink_route_read ();
}