combined use_in and use_fwd
authorAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 10 Jan 2007 08:17:48 +0000 (08:17 -0000)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 10 Jan 2007 08:17:48 +0000 (08:17 -0000)
src/charon/sa/child_sa.c

index 182da86..1174714 100644 (file)
@@ -769,7 +769,8 @@ static int print(FILE *stream, const struct printf_info *info,
        private_child_sa_t *this = *((private_child_sa_t**)(args[0]));
        iterator_t *iterator;
        sa_policy_t *policy;
-       u_int32_t now, rekeying, use;
+       u_int32_t now, rekeying;
+       u_int32_t use, use_in, use_fwd;
        status_t status;
        size_t written = 0;
        
@@ -832,36 +833,35 @@ static int print(FILE *stream, const struct printf_info *info,
                written += fprintf(stream, "\n%12s:   %R===%R, last use: ",
                                                   this->name, policy->my_ts, policy->other_ts);
                
-               /* query policy times */
+               /* query time of last policy use */
+
+               /* inbound: POLICY_IN or POLICY_FWD */
                status = charon->kernel_interface->query_policy(charon->kernel_interface,
-                                                       policy->other_ts, policy->my_ts, POLICY_IN, &use);
-               if (status == SUCCESS && use)
-               {
-                       written += fprintf(stream, "%ds_in ", now - use);
-               }
-               else
-               {
-                       written += fprintf(stream, "no_in ");
-               }
+                                                       policy->other_ts, policy->my_ts, POLICY_IN, &use_in);
+               use_in = (status == SUCCESS)? use_in : 0;
                status = charon->kernel_interface->query_policy(charon->kernel_interface,
-                                                       policy->my_ts, policy->other_ts, POLICY_OUT, &use);
-               if (status == SUCCESS && use)
+                               policy->other_ts, policy->my_ts, POLICY_FWD, &use_fwd);
+               use_fwd = (status == SUCCESS)? use_fwd : 0;
+               use = max(use_in, use_fwd);
+               if (use)
                {
-                       written += fprintf(stream, "%ds_out ", now - use);
+                       written += fprintf(stream, "%ds_i ", now - use);
                }
                else
                {
-                       written += fprintf(stream, "no_out ");
+                       written += fprintf(stream, "no_i ");
                }
+
+               /* outbound: POLICY_OUT */
                status = charon->kernel_interface->query_policy(charon->kernel_interface,
-                               policy->other_ts, policy->my_ts, POLICY_FWD, &use);
+                                                       policy->my_ts, policy->other_ts, POLICY_OUT, &use);
                if (status == SUCCESS && use)
                {
-                       written += fprintf(stream, "%ds_fwd", now - use);
+                       written += fprintf(stream, "%ds_", now - use);
                }
                else
                {
-                       written += fprintf(stream, "no_fwd");
+                       written += fprintf(stream, "no_");
                }
        }
        iterator->destroy(iterator);