From 580e01b5a313596c7d2f58c4a4081602e676c670 Mon Sep 17 00:00:00 2001 From: Jan Moskyto Matejka Date: Tue, 11 Jul 2017 14:35:20 +0200 Subject: [PATCH] Flowspec: portability fixes in action formatting --- lib/flowspec.c | 20 +++++++++----------- lib/printf.c | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/flowspec.c b/lib/flowspec.c index cdf80ba3..387a2715 100644 --- a/lib/flowspec.c +++ b/lib/flowspec.c @@ -83,16 +83,14 @@ flow_type_str(enum flow_type type, int ipv6) const char * flow_action_str(uint action) { -#define C(c, s) case c: return s switch(action) { - C(FLOW_ACTION_TRAFFIC_BYTERATE, "byterate"); - C(FLOW_ACTION_TRAFFIC_ACTION, "action"); - C(FLOW_ACTION_REDIRECT_AS2, "redirect"); - C(FLOW_ACTION_REDIRECT_AS4, "redirect"); - C(FLOW_ACTION_REDIRECT_IP4, "redirect"); - C(FLOW_ACTION_TRAFFIC_MARKING, "mark"); + case FLOW_ACTION_TRAFFIC_BYTERATE: return "byterate"; + case FLOW_ACTION_TRAFFIC_ACTION: return "action"; + case FLOW_ACTION_REDIRECT_AS2: return "redirect"; + case FLOW_ACTION_REDIRECT_AS4: return "redirect"; + case FLOW_ACTION_REDIRECT_IP4: return "redirect"; + case FLOW_ACTION_TRAFFIC_MARKING: return "mark"; } -#undef C return NULL; } @@ -1265,11 +1263,11 @@ flow_action_format_part(char *buf, uint blen, u64 ec) return total; } case FLOW_ACTION_REDIRECT_AS2: - return bsnprintf(buf, blen, "rt %d,%d;", ((ec >> 32) & 0xffff), (ec & 0xffffffff)); + return bsnprintf(buf, blen, "rt %lu,%lu;", ((ec >> 32) & 0xffff), (ec & 0xffffffff)); case FLOW_ACTION_REDIRECT_AS4: - return bsnprintf(buf, blen, "rt %d,%d;", ((ec >> 16) & 0xffffffff), (ec & 0xffff)); + return bsnprintf(buf, blen, "rt %lu,%lu;", ((ec >> 16) & 0xffffffff), (ec & 0xffff)); case FLOW_ACTION_TRAFFIC_MARKING: - return bsnprintf(buf, blen, "dscp %d;", (ec & 0x3f)); + return bsnprintf(buf, blen, "dscp %lu;", (ec & 0x3f)); default: return 0; } diff --git a/lib/printf.c b/lib/printf.c index af795c21..d160dc15 100644 --- a/lib/printf.c +++ b/lib/printf.c @@ -145,7 +145,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args) char ipbuf[NET_MAX_TEXT_LENGTH+1]; struct iface *iface; const char *percent; - char fmtbuf[strlen(fmt)]; + char fmtbuf[13]; int flags; /* flags to number() */