printing u_int64_t caused segfault on 32-bit platforms
[strongswan.git] / src / charon / plugins / stroke / stroke_list.c
index 72b9999..7aa80dc 100644 (file)
@@ -146,8 +146,8 @@ static void log_ike_sa(FILE *out, ike_sa_t *ike_sa, bool all)
  */
 static void log_child_sa(FILE *out, child_sa_t *child_sa, bool all)
 {
-       u_int32_t rekey, now = time(NULL);
-       u_int32_t use_in, use_out;
+       time_t use_in, use_out, rekey, now = time(NULL);
+       u_int64_t bytes_in, bytes_out;
        proposal_t *proposal;
        child_cfg_t *config = child_sa->get_config(child_sa);
        
@@ -193,7 +193,7 @@ static void log_child_sa(FILE *out, child_sa_t *child_sa, bool all)
                                        fprintf(out, "%N", encryption_algorithm_names, encr_alg);
                                        if (encr_size)
                                        {
-                                               fprintf(out, "-%d", encr_size);
+                                               fprintf(out, "_%u", encr_size);
                                        }
                                }
                                if (int_alg != AUTH_UNDEFINED)
@@ -201,41 +201,43 @@ static void log_child_sa(FILE *out, child_sa_t *child_sa, bool all)
                                        fprintf(out, "/%N", integrity_algorithm_names, int_alg);
                                        if (int_size)
                                        {
-                                               fprintf(out, "-%d", int_size);
+                                               fprintf(out, "_%u", int_size);
                                        }
                                }
                        }
+
+                       child_sa->get_usestats(child_sa, TRUE, &use_in, &bytes_in);
+                       fprintf(out, ", %u bytes_i", (u_int)bytes_in);
+                       if (use_in)
+                       {
+                               fprintf(out, " (%ds ago)", now - use_in);
+                       }
+
+                       child_sa->get_usestats(child_sa, FALSE, &use_out, &bytes_out);
+                       fprintf(out, ", %u bytes_o", (u_int)bytes_out);
+                       if (use_out)
+                       {
+                               fprintf(out, " (%ds ago)", now - use_out);
+                       }
                        fprintf(out, ", rekeying ");
                        
                        rekey = child_sa->get_lifetime(child_sa, FALSE);
                        if (rekey)
                        {
-                               fprintf(out, "in %V", &now, &rekey);
+                               if (now > rekey)
+                               {
+                                       fprintf(out, "active");
+                               }
+                               else
+                               {
+                                       fprintf(out, "in %V", &now, &rekey);
+                               }
                        }
                        else
                        {
                                fprintf(out, "disabled");
                        }
                        
-                       fprintf(out, ", last use: ");
-                       use_in = child_sa->get_usetime(child_sa, TRUE);
-                       if (use_in)
-                       {
-                               fprintf(out, "%ds_i ", now - use_in);
-                       }
-                       else
-                       {
-                               fprintf(out, "no_i ");
-                       }
-                       use_out = child_sa->get_usetime(child_sa, FALSE);
-                       if (use_out)
-                       {
-                               fprintf(out, "%ds_o ", now - use_out);
-                       }
-                       else
-                       {
-                               fprintf(out, "no_o ");
-                       }
                }
        }
        
@@ -354,8 +356,9 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
        enumerator_t *enumerator, *children;
        ike_cfg_t *ike_cfg;
        child_cfg_t *child_cfg;
+       child_sa_t *child_sa;
        ike_sa_t *ike_sa;
-       bool found = FALSE;
+       bool first, found = FALSE;
        char *name = msg->status.name;
        
        if (all)
@@ -365,10 +368,9 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
                host_t *host;
                u_int32_t dpd;
                time_t now = time(NULL);
-               bool first = TRUE;
                u_int size, online, offline;
                
-               fprintf(out, "Performance:\n");
+               fprintf(out, "Status of IKEv2 charon daemon (strongSwan "VERSION"):\n");
                fprintf(out, "  uptime: %V, since %T\n", &now, &this->uptime, &this->uptime, FALSE);
                fprintf(out, "  worker threads: %d idle of %d,",
                                charon->processor->get_idle_threads(charon->processor),
@@ -386,6 +388,7 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
                enumerator->destroy(enumerator);
                fprintf(out, "\n");
                
+               first = TRUE;
                enumerator = this->attribute->create_pool_enumerator(this->attribute);
                while (enumerator->enumerate(enumerator, &pool, &size, &online, &offline))
                {
@@ -459,13 +462,25 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
                }
                enumerator->destroy(enumerator);
        }
+
+       first = TRUE;   
+       enumerator = charon->traps->create_enumerator(charon->traps);
+       while (enumerator->enumerate(enumerator, NULL, &child_sa))
+       {
+               if (first)
+               {
+                       fprintf(out, "Routed Connections:\n");
+                       first = FALSE;
+               }
+               log_child_sa(out, child_sa, all);
+       }
+       enumerator->destroy(enumerator);
        
        fprintf(out, "Security Associations:\n");
        enumerator = charon->controller->create_ike_sa_enumerator(charon->controller);
        while (enumerator->enumerate(enumerator, &ike_sa))
        {
                bool ike_printed = FALSE;
-               child_sa_t *child_sa;
                iterator_t *children = ike_sa->create_child_sa_iterator(ike_sa);
                
                if (name == NULL || streq(name, ike_sa->get_name(ike_sa)))