Home | History | Annotate | Download | only in conntrack
      1 /*
      2  * (C) 2005-2011 by Pablo Neira Ayuso <pablo (at) netfilter.org>
      3  *
      4  * This program is free software; you can redistribute it and/or modify it
      5  * under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation; either version 2 of the License, or
      7  * (at your option) any later version.
      8  */
      9 
     10 #include "internal/internal.h"
     11 
     12 /* these arrays are used by snprintf_default.c and snprintf_xml.c */
     13 const char *const l3proto2str[AF_MAX] = {
     14 	[AF_INET]			= "ipv4",
     15 	[AF_INET6]			= "ipv6",
     16 };
     17 
     18 const char *const proto2str[IPPROTO_MAX] = {
     19 	[IPPROTO_TCP]			= "tcp",
     20 	[IPPROTO_UDP]			= "udp",
     21 	[IPPROTO_UDPLITE]		= "udplite",
     22 	[IPPROTO_ICMP]			= "icmp",
     23 	[IPPROTO_ICMPV6]		= "icmpv6",
     24 	[IPPROTO_SCTP]			= "sctp",
     25 	[IPPROTO_GRE]			= "gre",
     26 	[IPPROTO_DCCP]			= "dccp",
     27 };
     28 
     29 const char *const states[TCP_CONNTRACK_MAX] = {
     30 	[TCP_CONNTRACK_NONE]		= "NONE",
     31 	[TCP_CONNTRACK_SYN_SENT]	= "SYN_SENT",
     32 	[TCP_CONNTRACK_SYN_RECV]	= "SYN_RECV",
     33 	[TCP_CONNTRACK_ESTABLISHED]	= "ESTABLISHED",
     34 	[TCP_CONNTRACK_FIN_WAIT]	= "FIN_WAIT",
     35 	[TCP_CONNTRACK_CLOSE_WAIT]	= "CLOSE_WAIT",
     36 	[TCP_CONNTRACK_LAST_ACK]	= "LAST_ACK",
     37 	[TCP_CONNTRACK_TIME_WAIT]	= "TIME_WAIT",
     38 	[TCP_CONNTRACK_CLOSE]		= "CLOSE",
     39 	[TCP_CONNTRACK_SYN_SENT2]	= "SYN_SENT2",
     40 };
     41 
     42 const char *const sctp_states[SCTP_CONNTRACK_MAX] = {
     43 	[SCTP_CONNTRACK_NONE]		= "NONE",
     44 	[SCTP_CONNTRACK_CLOSED]		= "CLOSED",
     45 	[SCTP_CONNTRACK_COOKIE_WAIT]	= "COOKIE_WAIT",
     46 	[SCTP_CONNTRACK_COOKIE_ECHOED]	= "COOKIE_ECHOED",
     47 	[SCTP_CONNTRACK_ESTABLISHED]	= "ESTABLISHED",
     48 	[SCTP_CONNTRACK_SHUTDOWN_SENT]	= "SHUTDOWN_SENT",
     49 	[SCTP_CONNTRACK_SHUTDOWN_RECD]	= "SHUTDOWN_RECD",
     50 	[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT] = "SHUTDOWN_ACK_SENT",
     51 };
     52 
     53 const char *const dccp_states[DCCP_CONNTRACK_MAX] = {
     54 	[DCCP_CONNTRACK_NONE]		= "NONE",
     55 	[DCCP_CONNTRACK_REQUEST]	= "REQUEST",
     56 	[DCCP_CONNTRACK_RESPOND]	= "RESPOND",
     57 	[DCCP_CONNTRACK_PARTOPEN]	= "PARTOPEN",
     58 	[DCCP_CONNTRACK_OPEN]		= "OPEN",
     59 	[DCCP_CONNTRACK_CLOSEREQ]	= "CLOSEREQ",
     60 	[DCCP_CONNTRACK_CLOSING]	= "CLOSING",
     61 	[DCCP_CONNTRACK_TIMEWAIT]	= "TIMEWAIT",
     62 	[DCCP_CONNTRACK_IGNORE]		= "IGNORE",
     63 	[DCCP_CONNTRACK_INVALID]	= "INVALID",
     64 };
     65 
     66 int __snprintf_conntrack(char *buf,
     67 			 unsigned int len,
     68 			 const struct nf_conntrack *ct,
     69 			 unsigned int type,
     70 			 unsigned int msg_output,
     71 			 unsigned int flags,
     72 			 struct nfct_labelmap *map)
     73 {
     74 	int size;
     75 
     76 	switch(msg_output) {
     77 	case NFCT_O_DEFAULT:
     78 		size = __snprintf_conntrack_default(buf, len, ct, type, flags, map);
     79 		break;
     80 	case NFCT_O_XML:
     81 		size = __snprintf_conntrack_xml(buf, len, ct, type, flags, map);
     82 		break;
     83 	default:
     84 		errno = ENOENT;
     85 		return -1;
     86 	}
     87 
     88 	/* NULL terminated string */
     89 	buf[size+1 > len ? len-1 : size] = '\0';
     90 
     91 	return size;
     92 }
     93