Re: Passive OS fingerprint xtables match (iptables part)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>
>#include <stdio.h>
>#include <netdb.h>
>#include <string.h>
>#include <stdlib.h>
>#include <getopt.h>
>#include <ctype.h>
>
>#include <xtables.h>
>
>typedef unsigned int __u32;
>typedef unsigned short __u16;
>typedef unsigned char __u8;

These should not done here.. it likely causes a "redefinition"
warning or compile error of sorts. Include <linux/types.h> if
in doubt.

>static void osf_help(void)
>{
>	printf("OS fingerprint match options:\n"
>		"--genre [!] string	Match a OS genre by passive fingerprinting.\n"

The syntax should be  [!] --genre string, that is what most
others use. Then the check_inverse call also be removed.

>static const struct option osf_opts[] = {
>	{ .name = "genre",	.has_arg = 1, .flag = 0, .val = '1' },
>	{ .name = "ttl",	.has_arg = 1, .flag = 0, .val = '2' },
>	{ .name = "log",	.has_arg = 1, .flag = 0, .val = '3' },
>	{ .name = "connector",	.has_arg = 0, .flag = 0, .val = '5' },
>	{ .name = NULL }
>};

.flag can be omitted; .has_arg=true

>			osf_parse_string(argv[optind-1], info);
>			if (invert)
>				info->flags |= IPT_OSF_INVERT;
>			info->len=strlen((char *)info->genre);

This cast seems unnecessary.

>		case '2': /* --ttl */
>			if (*flags & IPT_OSF_TTL)
>				exit_error(PARAMETER_PROBLEM, "Can't specify multiple ttl parameter");
>			*flags |= IPT_OSF_TTL;
>			info->flags |= IPT_OSF_TTL;
>			info->ttl = atoi(argv[optind-1]);

Make use of xtables_strtoui to do bounds checking on the TTL value.

>static void osf_save(const void *ip, const struct xt_entry_match *match)
>{
>	const struct ipt_osf_info *info = (const struct ipt_osf_info*) match->data;
>
>	printf("--genre %s%s ", (info->flags & IPT_OSF_INVERT) ? "! ": "", info->genre);
>}

Similarly, put ! before.

>static struct xtables_match osf_match = {
>    .name		= "osf",
>    .version		= XTABLES_VERSION,
>    .size		= XT_ALIGN(sizeof(struct ipt_osf_info)),
>    .userspacesize	= XT_ALIGN(sizeof(struct ipt_osf_info)),
>    .help		= &osf_help,
>    .init		= &osf_init,
>    .parse		= &osf_parse,
>    .print		= &osf_print,
>    .final_check	= &osf_final_check,
>    .save		= &osf_save,
>    .extra_opts		= osf_opts

The & for function pointers is not needed (and actually makes
macro substituion break in some cases, just in case I need
an excuse)
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux