diff options
Diffstat (limited to 'zebra/zebra_fpm.c')
| -rw-r--r-- | zebra/zebra_fpm.c | 198 |
1 files changed, 97 insertions, 101 deletions
diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c index 5920cde29e..37068c1fae 100644 --- a/zebra/zebra_fpm.c +++ b/zebra/zebra_fpm.c @@ -16,19 +16,20 @@ * 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. + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include <zebra.h> #include "log.h" +#include "libfrr.h" #include "stream.h" #include "thread.h" #include "network.h" #include "command.h" +#include "version.h" #include "zebra/rib.h" #include "zebra/zserv.h" @@ -36,7 +37,6 @@ #include "zebra/zebra_vrf.h" #include "fpm/fpm.h" -#include "zebra_fpm.h" #include "zebra_fpm_private.h" /* @@ -254,6 +254,8 @@ typedef struct zfpm_glob_t_ static zfpm_glob_t zfpm_glob_space; static zfpm_glob_t *zfpm_g = &zfpm_glob_space; +static int zfpm_trigger_update (struct route_node *rn, const char *reason); + static int zfpm_read_cb (struct thread *thread); static int zfpm_write_cb (struct thread *thread); @@ -297,20 +299,6 @@ zfpm_state_to_str (zfpm_state_t state) } /* - * zfpm_get_time - */ -static time_t -zfpm_get_time (void) -{ - struct timeval tv; - - if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &tv) < 0) - zlog_warn ("FPM: quagga_gettime failed!!"); - - return tv.tv_sec; -} - -/* * zfpm_get_elapsed_time * * Returns the time elapsed (in seconds) since the given time. @@ -320,7 +308,7 @@ zfpm_get_elapsed_time (time_t reference) { time_t now; - now = zfpm_get_time (); + now = monotime(NULL); if (now < reference) { @@ -498,8 +486,8 @@ zfpm_read_on (void) assert (!zfpm_g->t_read); assert (zfpm_g->sock >= 0); - THREAD_READ_ON (zfpm_g->master, zfpm_g->t_read, zfpm_read_cb, 0, - zfpm_g->sock); + thread_add_read(zfpm_g->master, zfpm_read_cb, 0, zfpm_g->sock, + &zfpm_g->t_read); } /* @@ -511,8 +499,8 @@ zfpm_write_on (void) assert (!zfpm_g->t_write); assert (zfpm_g->sock >= 0); - THREAD_WRITE_ON (zfpm_g->master, zfpm_g->t_write, zfpm_write_cb, 0, - zfpm_g->sock); + thread_add_write(zfpm_g->master, zfpm_write_cb, 0, zfpm_g->sock, + &zfpm_g->t_write); } /* @@ -546,7 +534,6 @@ zfpm_conn_up_thread_cb (struct thread *thread) zfpm_rnodes_iter_t *iter; rib_dest_t *dest; - assert (zfpm_g->t_conn_up); zfpm_g->t_conn_up = NULL; iter = &zfpm_g->t_conn_up_state.iter; @@ -576,9 +563,9 @@ zfpm_conn_up_thread_cb (struct thread *thread) zfpm_g->stats.t_conn_up_yields++; zfpm_rnodes_iter_pause (iter); - zfpm_g->t_conn_up = thread_add_background (zfpm_g->master, - zfpm_conn_up_thread_cb, - 0, 0); + zfpm_g->t_conn_up = NULL; + thread_add_background(zfpm_g->master, zfpm_conn_up_thread_cb, 0, 0, + &zfpm_g->t_conn_up); return 0; } @@ -610,8 +597,9 @@ zfpm_connection_up (const char *detail) zfpm_rnodes_iter_init (&zfpm_g->t_conn_up_state.iter); zfpm_debug ("Starting conn_up thread"); - zfpm_g->t_conn_up = thread_add_background (zfpm_g->master, - zfpm_conn_up_thread_cb, 0, 0); + zfpm_g->t_conn_up = NULL; + thread_add_background(zfpm_g->master, zfpm_conn_up_thread_cb, 0, 0, + &zfpm_g->t_conn_up); zfpm_g->stats.t_conn_up_starts++; } @@ -665,7 +653,6 @@ zfpm_conn_down_thread_cb (struct thread *thread) assert (zfpm_g->state == ZFPM_STATE_IDLE); - assert (zfpm_g->t_conn_down); zfpm_g->t_conn_down = NULL; iter = &zfpm_g->t_conn_down_state.iter; @@ -700,9 +687,9 @@ zfpm_conn_down_thread_cb (struct thread *thread) zfpm_g->stats.t_conn_down_yields++; zfpm_rnodes_iter_pause (iter); - zfpm_g->t_conn_down = thread_add_background (zfpm_g->master, - zfpm_conn_down_thread_cb, - 0, 0); + zfpm_g->t_conn_down = NULL; + thread_add_background(zfpm_g->master, zfpm_conn_down_thread_cb, 0, 0, + &zfpm_g->t_conn_down); return 0; } @@ -748,8 +735,9 @@ zfpm_connection_down (const char *detail) assert (!zfpm_g->t_conn_down); zfpm_debug ("Starting conn_down thread"); zfpm_rnodes_iter_init (&zfpm_g->t_conn_down_state.iter); - zfpm_g->t_conn_down = thread_add_background (zfpm_g->master, - zfpm_conn_down_thread_cb, 0, 0); + zfpm_g->t_conn_down = NULL; + thread_add_background(zfpm_g->master, zfpm_conn_down_thread_cb, 0, 0, + &zfpm_g->t_conn_down); zfpm_g->stats.t_conn_down_starts++; zfpm_set_state (ZFPM_STATE_IDLE, detail); @@ -767,7 +755,6 @@ zfpm_read_cb (struct thread *thread) fpm_msg_hdr_t *hdr; zfpm_g->stats.read_cb_calls++; - assert (zfpm_g->t_read); zfpm_g->t_read = NULL; /* @@ -879,11 +866,13 @@ zfpm_writes_pending (void) * value indicates an error. */ static inline int -zfpm_encode_route (rib_dest_t *dest, struct rib *rib, char *in_buf, +zfpm_encode_route (rib_dest_t *dest, struct route_entry *re, char *in_buf, size_t in_buf_len, fpm_msg_type_e *msg_type) { size_t len; +#ifdef HAVE_NETLINK int cmd; +#endif len = 0; *msg_type = FPM_MSG_TYPE_NONE; @@ -892,7 +881,7 @@ zfpm_encode_route (rib_dest_t *dest, struct rib *rib, char *in_buf, case ZFPM_MSG_FORMAT_PROTOBUF: #ifdef HAVE_PROTOBUF - len = zfpm_protobuf_encode_route (dest, rib, (uint8_t *) in_buf, + len = zfpm_protobuf_encode_route (dest, re, (uint8_t *) in_buf, in_buf_len); *msg_type = FPM_MSG_TYPE_PROTOBUF; #endif @@ -901,8 +890,8 @@ zfpm_encode_route (rib_dest_t *dest, struct rib *rib, char *in_buf, case ZFPM_MSG_FORMAT_NETLINK: #ifdef HAVE_NETLINK *msg_type = FPM_MSG_TYPE_NETLINK; - cmd = rib ? RTM_NEWROUTE : RTM_DELROUTE; - len = zfpm_netlink_encode_route (cmd, dest, rib, in_buf, in_buf_len); + cmd = re ? RTM_NEWROUTE : RTM_DELROUTE; + len = zfpm_netlink_encode_route (cmd, dest, re, in_buf, in_buf_len); assert(fpm_msg_align(len) == len); *msg_type = FPM_MSG_TYPE_NETLINK; #endif /* HAVE_NETLINK */ @@ -919,19 +908,19 @@ zfpm_encode_route (rib_dest_t *dest, struct rib *rib, char *in_buf, /* * zfpm_route_for_update * - * Returns the rib that is to be sent to the FPM for a given dest. + * Returns the re that is to be sent to the FPM for a given dest. */ -struct rib * +struct route_entry * zfpm_route_for_update (rib_dest_t *dest) { - struct rib *rib; + struct route_entry *re; - RIB_DEST_FOREACH_ROUTE (dest, rib) + RE_DEST_FOREACH_ROUTE (dest, re) { - if (!CHECK_FLAG (rib->status, RIB_ENTRY_SELECTED_FIB)) + if (!CHECK_FLAG (re->status, ROUTE_ENTRY_SELECTED_FIB)) continue; - return rib; + return re; } /* @@ -955,7 +944,7 @@ zfpm_build_updates (void) size_t msg_len; size_t data_len; fpm_msg_hdr_t *hdr; - struct rib *rib; + struct route_entry *re; int is_add, write_msg; fpm_msg_type_e msg_type; @@ -985,8 +974,8 @@ zfpm_build_updates (void) data = fpm_msg_data (hdr); - rib = zfpm_route_for_update (dest); - is_add = rib ? 1 : 0; + re = zfpm_route_for_update (dest); + is_add = re ? 1 : 0; write_msg = 1; @@ -1001,7 +990,7 @@ zfpm_build_updates (void) } if (write_msg) { - data_len = zfpm_encode_route (dest, rib, (char *) data, buf_end - data, + data_len = zfpm_encode_route (dest, re, (char *) data, buf_end - data, &msg_type); assert (data_len); @@ -1054,7 +1043,6 @@ zfpm_write_cb (struct thread *thread) int num_writes; zfpm_g->stats.write_cb_calls++; - assert (zfpm_g->t_write); zfpm_g->t_write = NULL; /* @@ -1146,7 +1134,6 @@ zfpm_connect_cb (struct thread *t) int sock, ret; struct sockaddr_in serv; - assert (zfpm_g->t_connect); zfpm_g->t_connect = NULL; assert (zfpm_g->state == ZFPM_STATE_ACTIVE); @@ -1177,7 +1164,7 @@ zfpm_connect_cb (struct thread *t) */ zfpm_g->connect_calls++; zfpm_g->stats.connect_calls++; - zfpm_g->last_connect_call_time = zfpm_get_time (); + zfpm_g->last_connect_call_time = monotime(NULL); ret = connect (sock, (struct sockaddr *) &serv, sizeof (serv)); if (ret >= 0) @@ -1303,12 +1290,11 @@ zfpm_start_connect_timer (const char *reason) delay_secs = zfpm_calc_connect_delay(); zfpm_debug ("scheduling connect in %ld seconds", delay_secs); - THREAD_TIMER_ON (zfpm_g->master, zfpm_g->t_connect, zfpm_connect_cb, 0, - delay_secs); + thread_add_timer(zfpm_g->master, zfpm_connect_cb, 0, delay_secs, + &zfpm_g->t_connect); zfpm_set_state (ZFPM_STATE_ACTIVE, reason); } -#if defined (HAVE_FPM) /* * zfpm_is_enabled * @@ -1319,7 +1305,6 @@ zfpm_is_enabled (void) { return zfpm_g->enabled; } -#endif /* * zfpm_conn_is_up @@ -1343,7 +1328,7 @@ zfpm_conn_is_up (void) * The zebra code invokes this function to indicate that we should * send an update to the FPM about the given route_node. */ -void +static int zfpm_trigger_update (struct route_node *rn, const char *reason) { rib_dest_t *dest; @@ -1354,7 +1339,7 @@ zfpm_trigger_update (struct route_node *rn, const char *reason) * all destinations once the connection comes up. */ if (!zfpm_conn_is_up ()) - return; + return 0; dest = rib_dest_from_rnode (rn); @@ -1365,12 +1350,12 @@ zfpm_trigger_update (struct route_node *rn, const char *reason) if (!zfpm_is_table_for_fpm (rib_dest_table (dest))) { zfpm_g->stats.non_fpm_table_triggers++; - return; + return 0; } if (CHECK_FLAG (dest->flags, RIB_DEST_UPDATE_FPM)) { zfpm_g->stats.redundant_triggers++; - return; + return 0; } if (reason) @@ -1387,9 +1372,10 @@ zfpm_trigger_update (struct route_node *rn, const char *reason) * Make sure that writes are enabled. */ if (zfpm_g->t_write) - return; + return 0; zfpm_write_on (); + return 0; } /* @@ -1398,7 +1384,6 @@ zfpm_trigger_update (struct route_node *rn, const char *reason) static int zfpm_stats_timer_cb (struct thread *t) { - assert (zfpm_g->t_stats); zfpm_g->t_stats = NULL; /* @@ -1423,7 +1408,6 @@ zfpm_stats_timer_cb (struct thread *t) return 0; } -#if defined (HAVE_FPM) /* * zfpm_stop_stats_timer */ @@ -1436,7 +1420,6 @@ zfpm_stop_stats_timer (void) zfpm_debug ("Stopping existing stats timer"); THREAD_TIMER_OFF (zfpm_g->t_stats); } -#endif /* * zfpm_start_stats_timer @@ -1446,8 +1429,8 @@ zfpm_start_stats_timer (void) { assert (!zfpm_g->t_stats); - THREAD_TIMER_ON (zfpm_g->master, zfpm_g->t_stats, zfpm_stats_timer_cb, 0, - ZFPM_STATS_IVL_SECS); + thread_add_timer(zfpm_g->master, zfpm_stats_timer_cb, 0, + ZFPM_STATS_IVL_SECS, &zfpm_g->t_stats); } /* @@ -1459,7 +1442,6 @@ zfpm_start_stats_timer (void) zfpm_g->last_ivl_stats.counter, VTY_NEWLINE); \ } while (0) -#if defined (HAVE_FPM) /* * zfpm_show_stats */ @@ -1531,7 +1513,7 @@ zfpm_clear_stats (struct vty *vty) zfpm_stop_stats_timer (); zfpm_start_stats_timer (); - zfpm_g->last_stats_clear_time = zfpm_get_time(); + zfpm_g->last_stats_clear_time = monotime(NULL); vty_out (vty, "Cleared FPM stats%s", VTY_NEWLINE); } @@ -1569,9 +1551,9 @@ DEFUN (clear_zebra_fpm_stats, /* * update fpm connection information */ -DEFUN ( fpm_remote_ip, - fpm_remote_ip_cmd, - "fpm connection ip A.B.C.D port <1-65535>", +DEFUN ( fpm_remote_ip, + fpm_remote_ip_cmd, + "fpm connection ip A.B.C.D port (1-65535)", "fpm connection remote ip and port\n" "Remote fpm server ip A.B.C.D\n" "Enter ip ") @@ -1580,11 +1562,11 @@ DEFUN ( fpm_remote_ip, in_addr_t fpm_server; uint32_t port_no; - fpm_server = inet_addr (argv[0]); + fpm_server = inet_addr (argv[3]->arg); if (fpm_server == INADDR_NONE) return CMD_ERR_INCOMPLETE; - port_no = atoi (argv[1]); + port_no = atoi (argv[5]->arg); if (port_no < TCP_MIN_PORT || port_no > TCP_MAX_PORT) return CMD_ERR_INCOMPLETE; @@ -1595,16 +1577,16 @@ DEFUN ( fpm_remote_ip, return CMD_SUCCESS; } -DEFUN ( no_fpm_remote_ip, - no_fpm_remote_ip_cmd, - "no fpm connection ip A.B.C.D port <1-65535>", +DEFUN ( no_fpm_remote_ip, + no_fpm_remote_ip_cmd, + "no fpm connection ip A.B.C.D port (1-65535)", "fpm connection remote ip and port\n" "Connection\n" "Remote fpm server ip A.B.C.D\n" "Enter ip ") { - if (zfpm_g->fpm_server != inet_addr (argv[0]) || - zfpm_g->fpm_port != atoi (argv[1])) + if (zfpm_g->fpm_server != inet_addr (argv[4]->arg) || + zfpm_g->fpm_port != atoi (argv[6]->arg)) return CMD_ERR_NO_MATCH; zfpm_g->fpm_server = FPM_DEFAULT_IP; @@ -1612,7 +1594,6 @@ DEFUN ( no_fpm_remote_ip, return CMD_SUCCESS; } -#endif /* * zfpm_init_message_format @@ -1622,14 +1603,16 @@ zfpm_init_message_format (const char *format) { int have_netlink, have_protobuf; - have_netlink = have_protobuf = 0; - #ifdef HAVE_NETLINK have_netlink = 1; +#else + have_netlink = 0; #endif #ifdef HAVE_PROTOBUF have_protobuf = 1; +#else + have_protobuf = 0; #endif zfpm_g->message_format = ZFPM_MSG_FORMAT_NONE; @@ -1680,7 +1663,7 @@ zfpm_init_message_format (const char *format) * Returns ZERO on success. */ -int fpm_remote_srv_write (struct vty *vty ) +static int fpm_remote_srv_write (struct vty *vty) { struct in_addr in; @@ -1694,6 +1677,15 @@ int fpm_remote_srv_write (struct vty *vty ) } +/* Zebra node */ +static struct cmd_node zebra_node = +{ + ZEBRA_NODE, + "", + 1 +}; + + /** * zfpm_init * @@ -1705,17 +1697,12 @@ int fpm_remote_srv_write (struct vty *vty ) * * Returns TRUE on success. */ -int -zfpm_init (struct thread_master *master, int enable, uint16_t port, - const char *format) +static int +zfpm_init (struct thread_master *master) { - static int initialized = 0; - - if (initialized) { - return 1; - } - - initialized = 1; + int enable = 1; + uint16_t port = 0; + const char *format = THIS_MODULE->load_args; memset (zfpm_g, 0, sizeof (*zfpm_g)); zfpm_g->master = master; @@ -1727,12 +1714,11 @@ zfpm_init (struct thread_master *master, int enable, uint16_t port, zfpm_stats_init (&zfpm_g->last_ivl_stats); zfpm_stats_init (&zfpm_g->cumulative_stats); -#if defined (HAVE_FPM) + install_node (&zebra_node, fpm_remote_srv_write); install_element (ENABLE_NODE, &show_zebra_fpm_stats_cmd); install_element (ENABLE_NODE, &clear_zebra_fpm_stats_cmd); install_element (CONFIG_NODE, &fpm_remote_ip_cmd); install_element (CONFIG_NODE, &no_fpm_remote_ip_cmd); -#endif zfpm_init_message_format(format); @@ -1744,10 +1730,6 @@ zfpm_init (struct thread_master *master, int enable, uint16_t port, zfpm_g->enabled = enable; - if (!enable) { - return 1; - } - if (!zfpm_g->fpm_server) zfpm_g->fpm_server = FPM_DEFAULT_IP; @@ -1761,6 +1743,20 @@ zfpm_init (struct thread_master *master, int enable, uint16_t port, zfpm_start_stats_timer (); zfpm_start_connect_timer ("initialized"); + return 0; +} - return 1; +static int +zebra_fpm_module_init (void) +{ + hook_register(rib_update, zfpm_trigger_update); + hook_register(frr_late_init, zfpm_init); + return 0; } + +FRR_MODULE_SETUP( + .name = "zebra_fpm", + .version = FRR_VERSION, + .description = "zebra FPM (Forwarding Plane Manager) module", + .init = zebra_fpm_module_init, +) |
