From a1586cea00b32b401c76f17aab4121967051d883 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Tue, 14 Apr 2009 10:36:07 +0200 Subject: snprintf: remove duplicated protocol string definitions This patch merges duplicated protocol string definitions in the snprintf infrastructure. I have also fixed the size of the string array. This patch is a cleanup. Signed-off-by: Pablo Neira Ayuso --- include/internal/extern.h | 7 +++++ include/internal/internal.h | 3 +++ src/conntrack/snprintf.c | 55 ++++++++++++++++++++++++++++++++++++++++ src/conntrack/snprintf_default.c | 54 --------------------------------------- src/conntrack/snprintf_xml.c | 20 ++------------- 5 files changed, 67 insertions(+), 72 deletions(-) diff --git a/include/internal/extern.h b/include/internal/extern.h index d0b079f..e1bbc13 100644 --- a/include/internal/extern.h +++ b/include/internal/extern.h @@ -13,4 +13,11 @@ extern get_exp_attr get_exp_attr_array[]; extern uint32_t attr_grp_bitmask[ATTR_GRP_MAX][__NFCT_BITSET]; +/* for the snprintf infrastructure */ +extern const char *l3proto2str[AF_MAX]; +extern const char *proto2str[IPPROTO_MAX]; +extern const char *states[TCP_CONNTRACK_MAX]; +extern const char *sctp_states[SCTP_CONNTRACK_MAX]; +extern const char *dccp_states[DCCP_CONNTRACK_MAX]; + #endif diff --git a/include/internal/internal.h b/include/internal/internal.h index a72e071..c335afd 100644 --- a/include/internal/internal.h +++ b/include/internal/internal.h @@ -23,6 +23,9 @@ #include #include +#include +#include +#include #include "internal/object.h" #include "internal/prototypes.h" diff --git a/src/conntrack/snprintf.c b/src/conntrack/snprintf.c index cc68293..80629a7 100644 --- a/src/conntrack/snprintf.c +++ b/src/conntrack/snprintf.c @@ -7,6 +7,61 @@ #include "internal/internal.h" +/* these arrays are used by snprintf_default.c and snprintf_xml.c */ +const char *l3proto2str[AF_MAX] = { + [AF_INET] = "ipv4", + [AF_INET6] = "ipv6", +}; + +const char *proto2str[IPPROTO_MAX] = { + [IPPROTO_TCP] = "tcp", + [IPPROTO_UDP] = "udp", + [IPPROTO_UDPLITE] = "udplite", + [IPPROTO_ICMP] = "icmp", + [IPPROTO_ICMPV6] = "icmpv6", + [IPPROTO_SCTP] = "sctp", + [IPPROTO_GRE] = "gre", + [IPPROTO_UDPLITE] = "udplite", + [IPPROTO_DCCP] = "dccp", +}; + +const char *states[TCP_CONNTRACK_MAX] = { + [TCP_CONNTRACK_NONE] = "NONE", + [TCP_CONNTRACK_SYN_SENT] = "SYN_SENT", + [TCP_CONNTRACK_SYN_RECV] = "SYN_RECV", + [TCP_CONNTRACK_ESTABLISHED] = "ESTABLISHED", + [TCP_CONNTRACK_FIN_WAIT] = "FIN_WAIT", + [TCP_CONNTRACK_CLOSE_WAIT] = "CLOSE_WAIT", + [TCP_CONNTRACK_LAST_ACK] = "LAST_ACK", + [TCP_CONNTRACK_TIME_WAIT] = "TIME_WAIT", + [TCP_CONNTRACK_CLOSE] = "CLOSE", + [TCP_CONNTRACK_LISTEN] = "LISTEN", +}; + +const char *sctp_states[SCTP_CONNTRACK_MAX] = { + [SCTP_CONNTRACK_NONE] = "NONE", + [SCTP_CONNTRACK_CLOSED] = "CLOSED", + [SCTP_CONNTRACK_COOKIE_WAIT] = "COOKIE_WAIT", + [SCTP_CONNTRACK_COOKIE_ECHOED] = "COOKIE_ECHOED", + [SCTP_CONNTRACK_ESTABLISHED] = "ESTABLISHED", + [SCTP_CONNTRACK_SHUTDOWN_SENT] = "SHUTDOWN_SENT", + [SCTP_CONNTRACK_SHUTDOWN_RECD] = "SHUTDOWN_RECD", + [SCTP_CONNTRACK_SHUTDOWN_ACK_SENT] = "SHUTDOWN_ACK_SENT", +}; + +const char *dccp_states[DCCP_CONNTRACK_MAX] = { + [DCCP_CONNTRACK_NONE] = "NONE", + [DCCP_CONNTRACK_REQUEST] = "REQUEST", + [DCCP_CONNTRACK_RESPOND] = "RESPOND", + [DCCP_CONNTRACK_PARTOPEN] = "PARTOPEN", + [DCCP_CONNTRACK_OPEN] = "OPEN", + [DCCP_CONNTRACK_CLOSEREQ] = "CLOSEREQ", + [DCCP_CONNTRACK_CLOSING] = "CLOSING", + [DCCP_CONNTRACK_TIMEWAIT] = "TIMEWAIT", + [DCCP_CONNTRACK_IGNORE] = "IGNORE", + [DCCP_CONNTRACK_INVALID] = "INVALID", +}; + int __snprintf_conntrack(char *buf, unsigned int len, const struct nf_conntrack *ct, diff --git a/src/conntrack/snprintf_default.c b/src/conntrack/snprintf_default.c index 4802c47..5934306 100644 --- a/src/conntrack/snprintf_default.c +++ b/src/conntrack/snprintf_default.c @@ -7,60 +7,6 @@ #include "internal/internal.h" -static char *proto2str[IPPROTO_MAX] = { - [IPPROTO_TCP] = "tcp", - [IPPROTO_UDP] = "udp", - [IPPROTO_UDPLITE] = "udplite", - [IPPROTO_ICMP] = "icmp", - [IPPROTO_ICMPV6] = "icmpv6", - [IPPROTO_SCTP] = "sctp", - [IPPROTO_GRE] = "gre", - [IPPROTO_UDPLITE] = "udplite", - [IPPROTO_DCCP] = "dccp", -}; - -static char *l3proto2str[AF_MAX] = { - [AF_INET] = "ipv4", - [AF_INET6] = "ipv6" -}; - -static const char *states[] = { - "NONE", - "SYN_SENT", - "SYN_RECV", - "ESTABLISHED", - "FIN_WAIT", - "CLOSE_WAIT", - "LAST_ACK", - "TIME_WAIT", - "CLOSE", - "LISTEN" -}; - -static const char *sctp_states[] = { - "NONE", - "CLOSED", - "COOKIE_WAIT", - "COOKIE_ECHOED", - "ESTABLISHED", - "SHUTDOWN_SENT", - "SHUTDOWN_RECD", - "SHUTDOWN_ACK_SENT", -}; - -static const char *dccp_states[] = { - "NONE", - "REQUEST", - "RESPOND", - "PARTOPEN", - "OPEN", - "CLOSEREQ", - "CLOSING", - "TIMEWAIT", - "IGNORE", - "INVALID", -}; - static int __snprintf_l3protocol(char *buf, unsigned int len, const struct nf_conntrack *ct) diff --git a/src/conntrack/snprintf_xml.c b/src/conntrack/snprintf_xml.c index ff34e86..928fc0b 100644 --- a/src/conntrack/snprintf_xml.c +++ b/src/conntrack/snprintf_xml.c @@ -53,33 +53,17 @@ * */ -static char *proto2str[IPPROTO_MAX] = { - [IPPROTO_TCP] = "tcp", - [IPPROTO_UDP] = "udp", - [IPPROTO_UDPLITE] = "udplite", - [IPPROTO_ICMP] = "icmp", - [IPPROTO_ICMPV6] = "icmp6", - [IPPROTO_SCTP] = "sctp", - [IPPROTO_GRE] = "gre", - [IPPROTO_UDPLITE] = "udplite", - [IPPROTO_DCCP] = "dccp", -}; -static char *l3proto2str[AF_MAX] = { - [AF_INET] = "ipv4", - [AF_INET6] = "ipv6" -}; - enum { __ADDR_SRC = 0, __ADDR_DST, }; -static char *__proto2str(u_int8_t protonum) +static const char *__proto2str(u_int8_t protonum) { return proto2str[protonum] ? proto2str[protonum] : "unknown"; } -static char *__l3proto2str(u_int8_t protonum) +static const char *__l3proto2str(u_int8_t protonum) { return l3proto2str[protonum] ? l3proto2str[protonum] : "unknown"; } -- cgit v1.2.3