printing u_int64_t caused segfault on 32-bit platforms
[strongswan.git] / src / charon / plugins / stroke / stroke_list.c
index 9c98770..7aa80dc 100644 (file)
@@ -11,8 +11,6 @@
  * 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.
- *
- * $Id$
  */
 
 #include "stroke_list.h"
@@ -74,7 +72,7 @@ static void log_ike_sa(FILE *out, ike_sa_t *ike_sa, bool all)
                fprintf(out, " %V ago", &now, &established);
        }
        
-       fprintf(out, ", %H[%D]...%H[%D]\n",
+       fprintf(out, ", %H[%Y]...%H[%Y]\n",
                        ike_sa->get_my_host(ike_sa), ike_sa->get_my_id(ike_sa),
                        ike_sa->get_other_host(ike_sa), ike_sa->get_other_id(ike_sa));
        
@@ -148,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);
        
@@ -195,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)
@@ -203,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 ");
-                       }
                }
        }
        
@@ -266,7 +266,7 @@ static void log_auth_cfgs(FILE *out, peer_cfg_t *peer_cfg, bool local)
        enumerator = peer_cfg->create_auth_cfg_enumerator(peer_cfg, local);
        while (enumerator->enumerate(enumerator, &auth))
        {
-               fprintf(out, "%12s:   %s [%D] uses ", name,     local ? "local: " : "remote:",
+               fprintf(out, "%12s:   %s [%Y] uses ", name,     local ? "local: " : "remote:",
                                auth->get(auth, AUTH_RULE_IDENTITY));
 
                auth_class = (uintptr_t)auth->get(auth, AUTH_RULE_AUTH_CLASS);
@@ -297,7 +297,7 @@ static void log_auth_cfgs(FILE *out, peer_cfg_t *peer_cfg, bool local)
                        id = auth->get(auth, AUTH_RULE_EAP_IDENTITY);
                        if (id)
                        {
-                               fprintf(out, " with EAP identity '%D'", id);
+                               fprintf(out, " with EAP identity '%Y'", id);
                        }
                        fprintf(out, "\n");
                }
@@ -305,19 +305,19 @@ static void log_auth_cfgs(FILE *out, peer_cfg_t *peer_cfg, bool local)
                cert = auth->get(auth, AUTH_RULE_CA_CERT);
                if (cert)
                {
-                       fprintf(out, "%12s:    ca:    \"%D\"\n", name, cert->get_subject(cert));
+                       fprintf(out, "%12s:    ca:    \"%Y\"\n", name, cert->get_subject(cert));
                }
 
                cert = auth->get(auth, AUTH_RULE_IM_CERT);
                if (cert)
                {
-                       fprintf(out, "%12s:    im-ca: \"%D\"\n", name, cert->get_subject(cert));
+                       fprintf(out, "%12s:    im-ca: \"%Y\"\n", name, cert->get_subject(cert));
                }
 
                cert = auth->get(auth, AUTH_RULE_SUBJECT_CERT);
                if (cert)
                {
-                       fprintf(out, "%12s:    cert:  \"%D\"\n", name,
+                       fprintf(out, "%12s:    cert:  \"%Y\"\n", name,
                                        cert->get_subject(cert));
                }
 
@@ -340,7 +340,7 @@ static void log_auth_cfgs(FILE *out, peer_cfg_t *peer_cfg, bool local)
                {
                        if (rule == AUTH_RULE_AC_GROUP)
                        {
-                               fprintf(out, "%12s:    group: %D\n", name, id);
+                               fprintf(out, "%12s:    group: %Y\n", name, id);
                        }
                }
                rules->destroy(rules);
@@ -356,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)
@@ -367,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),
@@ -388,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))
                {
@@ -400,7 +401,7 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
                                first = FALSE;
                                fprintf(out, "Virtual IP pools (size/online/offline):\n");
                        }
-                       fprintf(out, "  %s: %lu/%lu/%lu\n", pool, size, online, offline);
+                       fprintf(out, "  %s: %u/%u/%u\n", pool, size, online, offline);
                }
                enumerator->destroy(enumerator);
                
@@ -461,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)))
@@ -593,8 +606,8 @@ static void stroke_list_pubkeys(linked_list_t *list, bool utc, FILE *out)
                                        key_type_names, public->get_type(public),
                                        public->get_keysize(public) * 8,
                                        private ? ", has private key" : "");
-                       fprintf(out, "  keyid:     %D\n", keyid);
-                       fprintf(out, "  subjkey:   %D\n", id);
+                       fprintf(out, "  keyid:     %Y\n", keyid);
+                       fprintf(out, "  subjkey:   %Y\n", id);
                        DESTROY_IF(private);
                        public->destroy(public);
                }
@@ -650,7 +663,7 @@ static void stroke_list_certs(linked_list_t *list, char *label,
                                {
                                        fprintf(out, ", ");
                                }
-                               fprintf(out, "%D", altName);
+                               fprintf(out, "%Y", altName);
                        }
                        if (!first_altName)
                        {
@@ -658,8 +671,8 @@ static void stroke_list_certs(linked_list_t *list, char *label,
                        }
                        enumerator->destroy(enumerator);
 
-                       fprintf(out, "  subject:  \"%D\"\n", cert->get_subject(cert));
-                       fprintf(out, "  issuer:   \"%D\"\n", cert->get_issuer(cert));
+                       fprintf(out, "  subject:  \"%Y\"\n", cert->get_subject(cert));
+                       fprintf(out, "  issuer:   \"%Y\"\n", cert->get_issuer(cert));
                        fprintf(out, "  serial:    %#B\n", &serial);
 
                        /* list validity */
@@ -704,8 +717,8 @@ static void stroke_list_certs(linked_list_t *list, char *label,
                                                key_type_names, public->get_type(public),
                                                public->get_keysize(public) * 8,
                                                private ? ", has private key" : "");
-                               fprintf(out, "  keyid:     %D\n", keyid);
-                               fprintf(out, "  subjkey:   %D\n", id);
+                               fprintf(out, "  keyid:     %Y\n", keyid);
+                               fprintf(out, "  subjkey:   %Y\n", id);
                                DESTROY_IF(private);
                                public->destroy(public);
                        }
@@ -713,7 +726,7 @@ static void stroke_list_certs(linked_list_t *list, char *label,
                        /* list optional authorityKeyIdentifier */
                        if (authkey)
                        {
-                               fprintf(out, "  authkey:   %D\n", authkey);
+                               fprintf(out, "  authkey:   %Y\n", authkey);
                        }
                }
        }
@@ -749,17 +762,17 @@ static void stroke_list_acerts(linked_list_t *list, bool utc, FILE *out)
 
                if (entityName)
                {
-                       fprintf(out, "  holder:   \"%D\"\n", entityName);
+                       fprintf(out, "  holder:   \"%Y\"\n", entityName);
                }
                if (holderIssuer)
                {
-                       fprintf(out, "  hissuer:  \"%D\"\n", holderIssuer);
+                       fprintf(out, "  hissuer:  \"%Y\"\n", holderIssuer);
                }
                if (holderSerial.ptr)
                {
                        fprintf(out, "  hserial:   %#B\n", &holderSerial);
                }
-               fprintf(out, "  issuer:   \"%D\"\n", cert->get_issuer(cert));
+               fprintf(out, "  issuer:   \"%Y\"\n", cert->get_issuer(cert));
                fprintf(out, "  serial:    %#B\n", &serial);
 
                /* list validity */
@@ -783,7 +796,7 @@ static void stroke_list_acerts(linked_list_t *list, bool utc, FILE *out)
                /* list optional authorityKeyIdentifier */
                if (authkey)
                {
-                       fprintf(out, "  authkey:   %D\n", authkey);
+                       fprintf(out, "  authkey:   %Y\n", authkey);
                }
        }
        enumerator->destroy(enumerator);
@@ -813,7 +826,7 @@ static void stroke_list_crls(linked_list_t *list, bool utc, FILE *out)
                }
                fprintf(out, "\n");
 
-               fprintf(out, "  issuer:   \"%D\"\n", cert->get_issuer(cert));
+               fprintf(out, "  issuer:   \"%Y\"\n", cert->get_issuer(cert));
 
                /* list optional crlNumber */
                if (serial.ptr)
@@ -856,7 +869,7 @@ static void stroke_list_crls(linked_list_t *list, bool utc, FILE *out)
                /* list optional authorityKeyIdentifier */
                if (authkey)
                {
-                       fprintf(out, "  authkey:   %D\n", authkey);
+                       fprintf(out, "  authkey:   %Y\n", authkey);
                }
        }
        enumerator->destroy(enumerator);
@@ -881,7 +894,7 @@ static void stroke_list_ocsp(linked_list_t* list, bool utc, FILE *out)
                        first = FALSE;
                }
 
-               fprintf(out, "  signer:   \"%D\"\n", cert->get_issuer(cert));
+               fprintf(out, "  signer:   \"%Y\"\n", cert->get_issuer(cert));
        }
        enumerator->destroy(enumerator);
 }
@@ -1024,7 +1037,7 @@ static void pool_leases(private_stroke_list_t *this, FILE *out, char *pool,
        {
                if (!address || address->ip_equals(address, lease))
                {
-                       fprintf(out, "  %15H   %s   '%D'\n",
+                       fprintf(out, "  %15H   %s   '%Y'\n",
                                        lease, on ? "online" : "offline", id);
                        found++;
                }