]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_fpm.c
*: s/TRUE/true/, s/FALSE/false/
[mirror_frr.git] / zebra / zebra_fpm.c
index 8c0700ac8b13a5152406b6a7c5a02409994991e6..3b73a285f9b62179b6523fa9bd1be0fd6ef1b6df 100644 (file)
@@ -35,6 +35,7 @@
 #include "zebra/zserv.h"
 #include "zebra/zebra_ns.h"
 #include "zebra/zebra_vrf.h"
+#include "zebra/zebra_errors.h"
 
 #include "fpm/fpm.h"
 #include "zebra_fpm_private.h"
@@ -92,7 +93,6 @@ typedef struct zfpm_stats_t_ {
 
        unsigned long updates_triggered;
        unsigned long redundant_triggers;
-       unsigned long non_fpm_table_triggers;
 
        unsigned long dests_del_after_update;
 
@@ -311,31 +311,6 @@ static time_t zfpm_get_elapsed_time(time_t reference)
        return now - reference;
 }
 
-/*
- * zfpm_is_table_for_fpm
- *
- * Returns TRUE if the the given table is to be communicated to the
- * FPM.
- */
-static inline int zfpm_is_table_for_fpm(struct route_table *table)
-{
-       rib_table_info_t *info;
-
-       info = rib_table_info(table);
-
-       /*
-        * We only send the unicast tables in the main instance to the FPM
-        * at this point.
-        */
-       if (zvrf_id(info->zvrf) != 0)
-               return 0;
-
-       if (info->safi != SAFI_UNICAST)
-               return 0;
-
-       return 1;
-}
-
 /*
  * zfpm_rnodes_iter_init
  */
@@ -371,10 +346,7 @@ static inline struct route_node *zfpm_rnodes_iter_next(zfpm_rnodes_iter_t *iter)
                 */
                route_table_iter_cleanup(&iter->iter);
 
-               while ((table = rib_tables_iter_next(&iter->tables_iter))) {
-                       if (zfpm_is_table_for_fpm(table))
-                               break;
-               }
+               table = rib_tables_iter_next(&iter->tables_iter);
 
                if (!table)
                        return NULL;
@@ -742,7 +714,14 @@ static int zfpm_read_cb(struct thread *thread)
                nbyte = stream_read_try(ibuf, zfpm_g->sock,
                                        FPM_MSG_HDR_LEN - already);
                if (nbyte == 0 || nbyte == -1) {
-                       zfpm_connection_down("closed socket in read");
+                       if (nbyte == -1) {
+                               char buffer[1024];
+
+                               sprintf(buffer, "closed socket in read(%d): %s",
+                                       errno, safe_strerror(errno));
+                               zfpm_connection_down(buffer);
+                       } else
+                               zfpm_connection_down("closed socket in read");
                        return 0;
                }
 
@@ -772,7 +751,14 @@ static int zfpm_read_cb(struct thread *thread)
                nbyte = stream_read_try(ibuf, zfpm_g->sock, msg_len - already);
 
                if (nbyte == 0 || nbyte == -1) {
-                       zfpm_connection_down("failed to read message");
+                       if (nbyte == -1) {
+                               char buffer[1024];
+
+                               sprintf(buffer, "failed to read message(%d) %s",
+                                       errno, safe_strerror(errno));
+                               zfpm_connection_down(buffer);
+                       } else
+                               zfpm_connection_down("failed to read message");
                        return 0;
                }
 
@@ -795,7 +781,7 @@ done:
 /*
  * zfpm_writes_pending
  *
- * Returns TRUE if we may have something to write to the FPM.
+ * Returns true if we may have something to write to the FPM.
  */
 static int zfpm_writes_pending(void)
 {
@@ -871,20 +857,7 @@ static inline int zfpm_encode_route(rib_dest_t *dest, struct route_entry *re,
  */
 struct route_entry *zfpm_route_for_update(rib_dest_t *dest)
 {
-       struct route_entry *re;
-
-       RE_DEST_FOREACH_ROUTE(dest, re)
-       {
-               if (!CHECK_FLAG(re->status, ROUTE_ENTRY_SELECTED_FIB))
-                       continue;
-
-               return re;
-       }
-
-       /*
-        * We have no route for this destination.
-        */
-       return NULL;
+       return dest->selected_fib;
 }
 
 /*
@@ -1026,7 +999,7 @@ static int zfpm_write_cb(struct thread *thread)
                        break;
 
                bytes_written =
-                       write(zfpm_g->sock, STREAM_PNT(s), bytes_to_write);
+                       write(zfpm_g->sock, stream_pnt(s), bytes_to_write);
                zfpm_g->stats.write_calls++;
                num_writes++;
 
@@ -1237,7 +1210,7 @@ static void zfpm_start_connect_timer(const char *reason)
 /*
  * zfpm_is_enabled
  *
- * Returns TRUE if the zebra FPM module has been enabled.
+ * Returns true if the zebra FPM module has been enabled.
  */
 static inline int zfpm_is_enabled(void)
 {
@@ -1247,7 +1220,7 @@ static inline int zfpm_is_enabled(void)
 /*
  * zfpm_conn_is_up
  *
- * Returns TRUE if the connection to the FPM is up.
+ * Returns true if the connection to the FPM is up.
  */
 static inline int zfpm_conn_is_up(void)
 {
@@ -1279,15 +1252,6 @@ static int zfpm_trigger_update(struct route_node *rn, const char *reason)
 
        dest = rib_dest_from_rnode(rn);
 
-       /*
-        * Ignore the trigger if the dest is not in a table that we would
-        * send to the FPM.
-        */
-       if (!zfpm_is_table_for_fpm(rib_dest_table(dest))) {
-               zfpm_g->stats.non_fpm_table_triggers++;
-               return 0;
-       }
-
        if (CHECK_FLAG(dest->flags, RIB_DEST_UPDATE_FPM)) {
                zfpm_g->stats.redundant_triggers++;
                return 0;
@@ -1402,7 +1366,6 @@ static void zfpm_show_stats(struct vty *vty)
        ZFPM_SHOW_STAT(route_adds);
        ZFPM_SHOW_STAT(route_dels);
        ZFPM_SHOW_STAT(updates_triggered);
-       ZFPM_SHOW_STAT(non_fpm_table_triggers);
        ZFPM_SHOW_STAT(redundant_triggers);
        ZFPM_SHOW_STAT(dests_del_after_update);
        ZFPM_SHOW_STAT(t_conn_down_starts);
@@ -1453,7 +1416,7 @@ DEFUN (show_zebra_fpm_stats,
        show_zebra_fpm_stats_cmd,
        "show zebra fpm stats",
        SHOW_STR
-       "Zebra information\n"
+       ZEBRA_STR
        "Forwarding Path Manager information\n"
        "Statistics\n")
 {
@@ -1468,7 +1431,7 @@ DEFUN (clear_zebra_fpm_stats,
        clear_zebra_fpm_stats_cmd,
        "clear zebra fpm stats",
        CLEAR_STR
-       "Zebra information\n"
+       ZEBRA_STR
        "Clear Forwarding Path Manager information\n"
        "Statistics\n")
 {
@@ -1555,7 +1518,8 @@ static inline void zfpm_init_message_format(const char *format)
 
        if (!strcmp("netlink", format)) {
                if (!have_netlink) {
-                       zlog_err("FPM netlink message format is not available");
+                       flog_err(EC_ZEBRA_NETLINK_NOT_AVAILABLE,
+                                "FPM netlink message format is not available");
                        return;
                }
                zfpm_g->message_format = ZFPM_MSG_FORMAT_NETLINK;
@@ -1564,7 +1528,8 @@ static inline void zfpm_init_message_format(const char *format)
 
        if (!strcmp("protobuf", format)) {
                if (!have_protobuf) {
-                       zlog_err(
+                       flog_err(
+                               EC_ZEBRA_PROTOBUF_NOT_AVAILABLE,
                                "FPM protobuf message format is not available");
                        return;
                }
@@ -1572,7 +1537,8 @@ static inline void zfpm_init_message_format(const char *format)
                return;
        }
 
-       zlog_warn("Unknown fpm format '%s'", format);
+       flog_warn(EC_ZEBRA_FPM_FORMAT_UNKNOWN, "Unknown fpm format '%s'",
+                 format);
 }
 
 /**
@@ -1590,9 +1556,8 @@ static int fpm_remote_srv_write(struct vty *vty)
        in.s_addr = zfpm_g->fpm_server;
 
        if ((zfpm_g->fpm_server != FPM_DEFAULT_IP
-               && zfpm_g->fpm_server != INADDR_ANY)
-           || (zfpm_g->fpm_port != FPM_DEFAULT_PORT
-               && zfpm_g->fpm_port != 0))
+            && zfpm_g->fpm_server != INADDR_ANY)
+           || (zfpm_g->fpm_port != FPM_DEFAULT_PORT && zfpm_g->fpm_port != 0))
                vty_out(vty, "fpm connection ip %s port %d\n", inet_ntoa(in),
                        zfpm_g->fpm_port);
 
@@ -1610,10 +1575,10 @@ static struct cmd_node zebra_node = {ZEBRA_NODE, "", 1};
  * One-time initialization of the Zebra FPM module.
  *
  * @param[in] port port at which FPM is running.
- * @param[in] enable TRUE if the zebra FPM module should be enabled
+ * @param[in] enable true if the zebra FPM module should be enabled
  * @param[in] format to use to talk to the FPM. Can be 'netink' or 'protobuf'.
  *
- * Returns TRUE on success.
+ * Returns true on success.
  */
 static int zfpm_init(struct thread_master *master)
 {