4 * Copyright (c) 2003 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * iptables interface for OS fingerprint matching module.
34 #include <linux/netfilter_ipv4/ipt_osf.h>
36 static void help(void)
38 printf("OS fingerprint match v%s options:\n"
39 " --genre [!] string Match a OS genre bypassive fingerprinting.\n",
44 static struct option opts[] = {
45 { .name = "genre", .has_arg = 1, .flag = 0, .val = '1' },
50 static void init(struct ipt_entry_match *m, unsigned int *nfcache)
52 *nfcache |= NFC_UNKNOWN;
56 static void parse_string(const unsigned char *s, struct ipt_osf_info *info)
58 if (strlen(s) < MAXGENRELEN)
59 strcpy(info->genre, s);
61 exit_error(PARAMETER_PROBLEM, "Genre string too long `%s' [%d], max=%d",
62 s, strlen(s), MAXGENRELEN);
65 static int parse(int c, char **argv, int invert, unsigned int *flags,
66 const struct ipt_entry *entry,
67 unsigned int *nfcache,
68 struct ipt_entry_match **match)
70 struct ipt_osf_info *info = (struct ipt_osf_info *)(*match)->data;
76 exit_error(PARAMETER_PROBLEM, "Can't specify multiple strings");
77 check_inverse(optarg, &invert, &optind, 0);
78 parse_string(argv[optind-1], info);
81 info->len=strlen((char *)info->genre);
91 static void final_check(unsigned int flags)
94 exit_error(PARAMETER_PROBLEM, "OS fingerprint match: You must specify `--genre'");
97 static void print(const struct ipt_ip *ip, const struct ipt_entry_match *match, int numeric)
99 const struct ipt_osf_info *info = (const struct ipt_osf_info*) match->data;
101 printf("OS fingerprint match %s%s ", (info->invert) ? "!" : "", info->genre);
104 static void save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
106 const struct ipt_osf_info *info = (const struct ipt_osf_info*) match->data;
108 printf("--genre %s%s ", (info->invert) ? "! ": "", info->genre);
112 static struct iptables_match osf_match = {
114 .version = IPTABLES_VERSION,
115 .size = IPT_ALIGN(sizeof(struct ipt_osf_info)),
116 .userspacesize = IPT_ALIGN(sizeof(struct ipt_osf_info)),
120 .final_check = &final_check,
129 register_match(&osf_match);