summaryrefslogtreecommitdiffstats
path: root/src/app-layer-protos.c
blob: 368efacd88d710ad7b12ce3e470df79fc8e2bbc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Copyright (C) 2007-2022 Open Information Security Foundation
 *
 * You can copy, redistribute or modify this Program under the terms of
 * the GNU General Public License version 2 as published by the Free
 * Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

/**
 * \file
 *
 * \author Victor Julien <victor@inliniac.net>
 * \author Anoop Saldanha <anoopsaldanha@gmail.com>
 */

#include "suricata-common.h"
#include "app-layer-protos.h"

typedef struct AppProtoStringTuple {
    AppProto alproto;
    const char *str;
} AppProtoStringTuple;

const AppProtoStringTuple AppProtoStrings[ALPROTO_MAX] = {
    { ALPROTO_UNKNOWN, "unknown" },
    { ALPROTO_HTTP1, "http1" },
    { ALPROTO_FTP, "ftp" },
    { ALPROTO_SMTP, "smtp" },
    { ALPROTO_TLS, "tls" },
    { ALPROTO_SSH, "ssh" },
    { ALPROTO_IMAP, "imap" },
    { ALPROTO_JABBER, "jabber" },
    { ALPROTO_SMB, "smb" },
    { ALPROTO_DCERPC, "dcerpc" },
    { ALPROTO_IRC, "irc" },
    { ALPROTO_DNS, "dns" },
    { ALPROTO_MODBUS, "modbus" },
    { ALPROTO_ENIP, "enip" },
    { ALPROTO_DNP3, "dnp3" },
    { ALPROTO_NFS, "nfs" },
    { ALPROTO_NTP, "ntp" },
    { ALPROTO_FTPDATA, "ftp-data" },
    { ALPROTO_TFTP, "tftp" },
    { ALPROTO_IKE, "ike" },
    { ALPROTO_KRB5, "krb5" },
    { ALPROTO_QUIC, "quic" },
    { ALPROTO_DHCP, "dhcp" },
    { ALPROTO_SNMP, "snmp" },
    { ALPROTO_SIP, "sip" },
    { ALPROTO_RFB, "rfb" },
    { ALPROTO_MQTT, "mqtt" },
    { ALPROTO_PGSQL, "pgsql" },
    { ALPROTO_TELNET, "telnet" },
    { ALPROTO_TEMPLATE, "template" },
    { ALPROTO_RDP, "rdp" },
    { ALPROTO_HTTP2, "http2" },
    { ALPROTO_BITTORRENT_DHT, "bittorrent-dht" },
    { ALPROTO_HTTP, "http" },
    { ALPROTO_FAILED, "failed" },
#ifdef UNITTESTS
    { ALPROTO_TEST, "test" },
#endif
};

const char *AppProtoToString(AppProto alproto)
{
    const char *proto_name = NULL;
    switch (alproto) {
        // special cases
        case ALPROTO_HTTP1:
            proto_name = "http";
            break;
        case ALPROTO_HTTP:
            proto_name = "http_any";
            break;
        default:
            if (alproto < ARRAY_SIZE(AppProtoStrings)) {
                BUG_ON(AppProtoStrings[alproto].alproto != alproto);
                proto_name = AppProtoStrings[alproto].str;
            }
    }
    return proto_name;
}

AppProto StringToAppProto(const char *proto_name)
{
    if (proto_name == NULL)
        return ALPROTO_UNKNOWN;

    // We could use a Multi Pattern Matcher
    for (size_t i = 0; i < ARRAY_SIZE(AppProtoStrings); i++) {
        if (strcmp(proto_name, AppProtoStrings[i].str) == 0)
            return AppProtoStrings[i].alproto;
    }

    return ALPROTO_UNKNOWN;
}