blob: 27db8cdf35739ff4109b977210f03a0cc8a6d8d8 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 * libxt_tsreputation - iptables part for xt_tsreputation
3 * Copyright © Paul Dale 2009
4 * Contact: <Paul_Dale@McAfee.com>
5 *
6 * libxt_tsreputation.c is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 or 3 of the License.
9 */
10#include <sys/types.h>
11#include <getopt.h>
12#include <stdbool.h>
13#include <stdint.h>
14#include <stdio.h>
15#include <string.h>
16#include <stdlib.h>
17#include <stddef.h>
18#include <limits.h>
19
20#include <linux/netfilter/xt_tsreputation.h>
21#include <xtables.h>
22
23#define XT_TSREP_DEFINED 1
24
25
26static const struct option tsreputation_opts[] = {
27 { "reputation", true, NULL, 'R'},
28 { .name = NULL }
29};
30
31
32static void tsreputation_help(void)
33{
34 printf(
35"tsreputation match options:\n"
36" --reputation rep Reputation threshold (signed integer)\n");
37}
38
39static void tsreputation_init(struct xt_entry_match *m)
40{
41 struct xt_tsreputation_info *info = (void *)m->data;
42
43 info->reputation = 0;
44}
45
46
47static int tsreputation_parse(int c, char **argv, int invert, unsigned int *flags,
48 const void *entry, struct xt_entry_match **match)
49{
50 struct xt_tsreputation_info *info = (void *)(*match)->data;
51 char *end;
52
53 switch (c) {
54 case 'R': /* --reputation */
55 if (*flags & XT_TSREP_DEFINED)
56 xtables_error(PARAMETER_PROBLEM, "xt_tsreputation: "
57 "Only use \"--reputation\" once!");
58 *flags |= XT_TSREP_DEFINED;
59 info->reputation = strtol(optarg, &end, 10);
60 if (end == optarg || *end != '\0')
61 xtables_error(PARAMETER_PROBLEM,
62 "No integer argument specified");
63 info->invert = invert?1:0;
64 return 1;
65 }
66 return 0;
67}
68
69static void tsreputation_print(const void *ip, const struct xt_entry_match *match,
70 int numeric)
71{
72 struct xt_tsreputation_info *info = (void *)match->data;
73
74 printf("TSREPUTATION %d ", info->reputation);
75}
76
77static void tsreputation_save(const void *ip, const struct xt_entry_match *match)
78{
79 const struct xt_tsreputation_info *info = (const void *)match->data;
80
81 printf("--reputation %d ", info->reputation);
82}
83
84static struct xtables_match tsreputation_match = {
85 .name = "tsreputation",
86 .family = AF_UNSPEC,
87 .version = XTABLES_VERSION,
88 .size = XT_ALIGN(sizeof(struct xt_tsreputation_info)),
89 .userspacesize = XT_ALIGN(sizeof(struct xt_tsreputation_info)),
90 .help = tsreputation_help,
91 .init = tsreputation_init,
92 .parse = tsreputation_parse,
93 .print = tsreputation_print,
94 .save = tsreputation_save,
95 .extra_opts = tsreputation_opts,
96};
97
98void _init(void)
99{
100 xtables_register_match(&tsreputation_match);
101}