suricata
app-layer-protos.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
23  */
24 
25 #include "suricata-common.h"
26 #include "app-layer-protos.h"
27 
28 typedef struct AppProtoStringTuple {
30  const char *str;
32 
34  { ALPROTO_UNKNOWN, "unknown" },
35  { ALPROTO_HTTP1, "http1" },
36  { ALPROTO_FTP, "ftp" },
37  { ALPROTO_SMTP, "smtp" },
38  { ALPROTO_TLS, "tls" },
39  { ALPROTO_SSH, "ssh" },
40  { ALPROTO_IMAP, "imap" },
41  { ALPROTO_JABBER, "jabber" },
42  { ALPROTO_SMB, "smb" },
43  { ALPROTO_DCERPC, "dcerpc" },
44  { ALPROTO_IRC, "irc" },
45  { ALPROTO_DNS, "dns" },
46  { ALPROTO_MODBUS, "modbus" },
47  { ALPROTO_ENIP, "enip" },
48  { ALPROTO_DNP3, "dnp3" },
49  { ALPROTO_NFS, "nfs" },
50  { ALPROTO_NTP, "ntp" },
51  { ALPROTO_FTPDATA, "ftp-data" },
52  { ALPROTO_TFTP, "tftp" },
53  { ALPROTO_IKE, "ike" },
54  { ALPROTO_KRB5, "krb5" },
55  { ALPROTO_QUIC, "quic" },
56  { ALPROTO_DHCP, "dhcp" },
57  { ALPROTO_SNMP, "snmp" },
58  { ALPROTO_SIP, "sip" },
59  { ALPROTO_RFB, "rfb" },
60  { ALPROTO_MQTT, "mqtt" },
61  { ALPROTO_PGSQL, "pgsql" },
62  { ALPROTO_TELNET, "telnet" },
63  { ALPROTO_WEBSOCKET, "websocket" },
64  { ALPROTO_LDAP, "ldap" },
65  { ALPROTO_DOH2, "doh2" },
66  { ALPROTO_TEMPLATE, "template" },
67  { ALPROTO_RDP, "rdp" },
68  { ALPROTO_HTTP2, "http2" },
69  { ALPROTO_BITTORRENT_DHT, "bittorrent-dht" },
70  { ALPROTO_POP3, "pop3" },
71  { ALPROTO_HTTP, "http" },
72  { ALPROTO_FAILED, "failed" },
73 };
74 
75 const char *AppProtoToString(AppProto alproto)
76 {
77  const char *proto_name = NULL;
78  switch (alproto) {
79  // special cases
80  case ALPROTO_HTTP1:
81  proto_name = "http";
82  break;
83  case ALPROTO_HTTP:
84  proto_name = "http_any";
85  break;
86  default:
87  if (alproto < ARRAY_SIZE(AppProtoStrings)) {
88  BUG_ON(AppProtoStrings[alproto].alproto != alproto);
89  proto_name = AppProtoStrings[alproto].str;
90  }
91  }
92  return proto_name;
93 }
94 
95 AppProto StringToAppProto(const char *proto_name)
96 {
97  if (proto_name == NULL)
98  return ALPROTO_UNKNOWN;
99 
100  // We could use a Multi Pattern Matcher
101  for (size_t i = 0; i < ARRAY_SIZE(AppProtoStrings); i++) {
102  if (strcmp(proto_name, AppProtoStrings[i].str) == 0)
103  return AppProtoStrings[i].alproto;
104  }
105 
106  return ALPROTO_UNKNOWN;
107 }
AppProtoStrings
const AppProtoStringTuple AppProtoStrings[ALPROTO_MAX]
Definition: app-layer-protos.c:33
ALPROTO_IKE
@ ALPROTO_IKE
Definition: app-layer-protos.h:49
ALPROTO_DCERPC
@ ALPROTO_DCERPC
Definition: app-layer-protos.h:38
ALPROTO_DNS
@ ALPROTO_DNS
Definition: app-layer-protos.h:41
ALPROTO_ENIP
@ ALPROTO_ENIP
Definition: app-layer-protos.h:43
AppProtoStringTuple
Definition: app-layer-protos.c:28
ALPROTO_TLS
@ ALPROTO_TLS
Definition: app-layer-protos.h:33
AppProtoStringTuple::alproto
AppProto alproto
Definition: app-layer-protos.c:29
ALPROTO_MODBUS
@ ALPROTO_MODBUS
Definition: app-layer-protos.h:42
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:81
ALPROTO_QUIC
@ ALPROTO_QUIC
Definition: app-layer-protos.h:51
ALPROTO_POP3
@ ALPROTO_POP3
Definition: app-layer-protos.h:66
ALPROTO_JABBER
@ ALPROTO_JABBER
Definition: app-layer-protos.h:36
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
Definition: app-layer-protos.c:75
ALPROTO_IRC
@ ALPROTO_IRC
Definition: app-layer-protos.h:39
ALPROTO_SIP
@ ALPROTO_SIP
Definition: app-layer-protos.h:54
ALPROTO_LDAP
@ ALPROTO_LDAP
Definition: app-layer-protos.h:60
ALPROTO_FTP
@ ALPROTO_FTP
Definition: app-layer-protos.h:31
ALPROTO_SSH
@ ALPROTO_SSH
Definition: app-layer-protos.h:34
ALPROTO_DHCP
@ ALPROTO_DHCP
Definition: app-layer-protos.h:52
ALPROTO_MAX
@ ALPROTO_MAX
Definition: app-layer-protos.h:76
ALPROTO_KRB5
@ ALPROTO_KRB5
Definition: app-layer-protos.h:50
ALPROTO_SNMP
@ ALPROTO_SNMP
Definition: app-layer-protos.h:53
ALPROTO_DNP3
@ ALPROTO_DNP3
Definition: app-layer-protos.h:44
ALPROTO_SMTP
@ ALPROTO_SMTP
Definition: app-layer-protos.h:32
StringToAppProto
AppProto StringToAppProto(const char *proto_name)
Maps a string to its ALPROTO_* equivalent.
Definition: app-layer-protos.c:95
AppProtoStringTuple::str
const char * str
Definition: app-layer-protos.c:30
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:300
ALPROTO_IMAP
@ ALPROTO_IMAP
Definition: app-layer-protos.h:35
ALPROTO_RDP
@ ALPROTO_RDP
Definition: app-layer-protos.h:63
ALPROTO_TELNET
@ ALPROTO_TELNET
Definition: app-layer-protos.h:58
ALPROTO_DOH2
@ ALPROTO_DOH2
Definition: app-layer-protos.h:61
ALPROTO_TFTP
@ ALPROTO_TFTP
Definition: app-layer-protos.h:48
ALPROTO_HTTP2
@ ALPROTO_HTTP2
Definition: app-layer-protos.h:64
ARRAY_SIZE
#define ARRAY_SIZE(arr)
Definition: suricata-common.h:545
suricata-common.h
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:30
ALPROTO_PGSQL
@ ALPROTO_PGSQL
Definition: app-layer-protos.h:57
ALPROTO_FTPDATA
@ ALPROTO_FTPDATA
Definition: app-layer-protos.h:47
AppProtoStringTuple
struct AppProtoStringTuple AppProtoStringTuple
ALPROTO_WEBSOCKET
@ ALPROTO_WEBSOCKET
Definition: app-layer-protos.h:59
str
#define str(s)
Definition: suricata-common.h:291
ALPROTO_MQTT
@ ALPROTO_MQTT
Definition: app-layer-protos.h:56
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition: app-layer-protos.h:70
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
ALPROTO_FAILED
@ ALPROTO_FAILED
Definition: app-layer-protos.h:74
ALPROTO_TEMPLATE
@ ALPROTO_TEMPLATE
Definition: app-layer-protos.h:62
app-layer-protos.h
ALPROTO_RFB
@ ALPROTO_RFB
Definition: app-layer-protos.h:55
ALPROTO_BITTORRENT_DHT
@ ALPROTO_BITTORRENT_DHT
Definition: app-layer-protos.h:65
ALPROTO_NTP
@ ALPROTO_NTP
Definition: app-layer-protos.h:46
ALPROTO_SMB
@ ALPROTO_SMB
Definition: app-layer-protos.h:37
ALPROTO_NFS
@ ALPROTO_NFS
Definition: app-layer-protos.h:45