suricata_derive/
lib.rs

1/* Copyright (C) 2020-2023 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#![deny(warnings)]
19#![allow(clippy::uninlined_format_args)]
20
21extern crate proc_macro;
22
23use proc_macro::TokenStream;
24
25mod applayerevent;
26mod applayerframetype;
27mod applayerstate;
28mod stringenum;
29
30/// The `AppLayerEvent` derive macro generates a `AppLayerEvent` trait
31/// implementation for enums that define AppLayerEvents.
32///
33/// Example usage (DNS app-layer events):
34///
35/// #[derive(AppLayerEvent)]
36/// enum {
37///     MalformedData,
38///     NotRequest,
39///     NotResponse,
40///     #[name("reserved_z_flag_set")]
41///     ZFlagSet,
42/// }
43///
44/// The enum variants must follow the naming convention of OneTwoThree
45/// for proper conversion to the name used in rules (one_tow_three) or
46/// optionally add a name attribute.
47#[proc_macro_derive(AppLayerEvent, attributes(name))]
48pub fn derive_app_layer_event(input: TokenStream) -> TokenStream {
49    applayerevent::derive_app_layer_event(input)
50}
51
52#[proc_macro_derive(AppLayerFrameType)]
53pub fn derive_app_layer_frame_type(input: TokenStream) -> TokenStream {
54    applayerframetype::derive_app_layer_frame_type(input)
55}
56
57#[proc_macro_derive(AppLayerState, attributes(suricata))]
58pub fn derive_app_layer_state(input: TokenStream) -> TokenStream {
59    applayerstate::derive_app_layer_state(input)
60}
61
62#[proc_macro_derive(EnumStringU8, attributes(name))]
63pub fn derive_enum_string_u8(input: TokenStream) -> TokenStream {
64    stringenum::derive_enum_string::<u8>(input, "u8")
65}
66
67#[proc_macro_derive(EnumStringU16, attributes(name))]
68pub fn derive_enum_string_u16(input: TokenStream) -> TokenStream {
69    stringenum::derive_enum_string::<u16>(input, "u16")
70}
71
72#[proc_macro_derive(EnumStringU32, attributes(name))]
73pub fn derive_enum_string_u32(input: TokenStream) -> TokenStream {
74    stringenum::derive_enum_string::<u32>(input, "u32")
75}