[strongSwan-dev] [PATCH 3/5] Use fixed length string buffer to prefix SA output

Thomas Egerer thomas.egerer at secunet.com
Sun Jun 6 22:53:44 CEST 2010


---
 src/libcharon/plugins/stroke/stroke_list.c |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/libcharon/plugins/stroke/stroke_list.c b/src/libcharon/plugins/stroke/stroke_list.c
index c2a98da..17f8206 100644
--- a/src/libcharon/plugins/stroke/stroke_list.c
+++ b/src/libcharon/plugins/stroke/stroke_list.c
@@ -30,6 +30,7 @@
 #define CERT_WARNING_INTERVAL  30	/* days */
 #define CRL_WARNING_INTERVAL	7	/* days */
 #define AC_WARNING_INTERVAL		1	/* day */
+#define MAX_PREFIX_LENGTH      32

 typedef struct private_stroke_list_t private_stroke_list_t;

@@ -59,11 +60,14 @@ struct private_stroke_list_t {
  */
 static void log_ike_sa(FILE *out, ike_sa_t *ike_sa, bool all)
 {
+	char prefix[MAX_PREFIX_LENGTH];
 	ike_sa_id_t *id = ike_sa->get_id(ike_sa);
 	time_t now = time_monotonic(NULL);

-	fprintf(out, "%12s[%d]: %N",
-			ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa),
+	snprintf(prefix, MAX_PREFIX_LENGTH, "%12s[%d]:", ike_sa->get_name(ike_sa),
+			ike_sa->get_unique_id(ike_sa));
+
+	fprintf(out, "%s %N", prefix,
 			ike_sa_state_names, ike_sa->get_state(ike_sa));

 	if (ike_sa->get_state(ike_sa) == IKE_ESTABLISHED)
@@ -84,8 +88,7 @@ static void log_ike_sa(FILE *out, ike_sa_t *ike_sa, bool all)

 		ike_proposal = ike_sa->get_proposal(ike_sa);

-		fprintf(out, "%12s[%d]: IKE SPIs: %.16llx_i%s %.16llx_r%s",
-				ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa),
+		fprintf(out, "%s IKE SPIs: %.16llx_i%s %.16llx_r%s", prefix,
 				id->get_initiator_spi(id), id->is_initiator(id) ? "*" : "",
 				id->get_responder_spi(id), id->is_initiator(id) ? "" : "*");

@@ -136,9 +139,7 @@ static void log_ike_sa(FILE *out, ike_sa_t *ike_sa, bool all)
 			char buf[BUF_LEN];

 			snprintf(buf, BUF_LEN, "%P", ike_proposal);
-			fprintf(out, "%12s[%d]: IKE proposal: %s\n",
-					ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa),
-					buf+4);
+			fprintf(out, "%s IKE proposal: %s\n", prefix, buf+4);
 		}
 	}
 }
@@ -148,14 +149,16 @@ 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)
 {
+	char prefix[MAX_PREFIX_LENGTH];
 	time_t use_in, use_out, rekey, now;
 	u_int64_t bytes_in, bytes_out;
 	proposal_t *proposal;
 	child_cfg_t *config = child_sa->get_config(child_sa);

+	snprintf(prefix, MAX_PREFIX_LENGTH, "%12s{%d}:",
+			child_sa->get_name(child_sa), child_sa->get_reqid(child_sa));

-	fprintf(out, "%12s{%d}:  %N, %N%s",
-			child_sa->get_name(child_sa), child_sa->get_reqid(child_sa),
+	fprintf(out, "%12s{%d}:  %N, %N%s", prefix,
 			child_sa_state_names, child_sa->get_state(child_sa),
 			ipsec_mode_names, child_sa->get_mode(child_sa),
 			config->use_proxy_mode(config) ? "_PROXY" : "");
@@ -177,8 +180,7 @@ static void log_child_sa(FILE *out, child_sa_t *child_sa, bool all)

 		if (all)
 		{
-			fprintf(out, "\n%12s{%d}:  ", child_sa->get_name(child_sa),
-					child_sa->get_reqid(child_sa));
+			fprintf(out, "\n%s  ", prefix);

 			proposal = child_sa->get_proposal(child_sa);
 			if (proposal)
@@ -245,8 +247,7 @@ static void log_child_sa(FILE *out, child_sa_t *child_sa, bool all)
 		}
 	}

-	fprintf(out, "\n%12s{%d}:   %#R=== %#R\n",
-			child_sa->get_name(child_sa), child_sa->get_reqid(child_sa),
+	fprintf(out, "\n%s   %#R=== %#R\n", prefix,
 			child_sa->get_traffic_selectors(child_sa, TRUE),
 			child_sa->get_traffic_selectors(child_sa, FALSE));
 }
-- 1.5.6.5




More information about the Dev mailing list