• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Shared library add-on to iptables to add ULOG support.
2  *
3  * (C) 2000 by Harald Welte <laforge@gnumonks.org>
4  *
5  * multipart netlink support based on ideas by Sebastian Zander
6  * 						<zander@fokus.gmd.de>
7  *
8  * This software is released under the terms of GNU GPL
9  *
10  * libipt_ULOG.c,v 1.7 2001/01/30 11:55:02 laforge Exp
11  */
12 #include <stdio.h>
13 #include <string.h>
14 #include <strings.h>
15 #include <xtables.h>
16 /* For 64bit kernel / 32bit userspace */
17 #include <linux/netfilter_ipv4/ipt_ULOG.h>
18 
19 enum {
20 	O_ULOG_NLGROUP = 0,
21 	O_ULOG_PREFIX,
22 	O_ULOG_CPRANGE,
23 	O_ULOG_QTHR,
24 };
25 
ULOG_help(void)26 static void ULOG_help(void)
27 {
28 	printf("ULOG target options:\n"
29 	       " --ulog-nlgroup nlgroup		NETLINK group used for logging\n"
30 	       " --ulog-cprange size		Bytes of each packet to be passed\n"
31 	       " --ulog-qthreshold		Threshold of in-kernel queue\n"
32 	       " --ulog-prefix prefix		Prefix log messages with this prefix.\n");
33 }
34 
35 static const struct xt_option_entry ULOG_opts[] = {
36 	{.name = "ulog-nlgroup", .id = O_ULOG_NLGROUP, .type = XTTYPE_UINT8,
37 	 .min = 1, .max = 32},
38 	{.name = "ulog-prefix", .id = O_ULOG_PREFIX, .type = XTTYPE_STRING,
39 	 .flags = XTOPT_PUT, XTOPT_POINTER(struct ipt_ulog_info, prefix),
40 	 .min = 1},
41 	{.name = "ulog-cprange", .id = O_ULOG_CPRANGE, .type = XTTYPE_UINT64},
42 	{.name = "ulog-qthreshold", .id = O_ULOG_QTHR, .type = XTTYPE_UINT64,
43 	 .min = 1, .max = ULOG_MAX_QLEN},
44 	XTOPT_TABLEEND,
45 };
46 
ULOG_init(struct xt_entry_target * t)47 static void ULOG_init(struct xt_entry_target *t)
48 {
49 	struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) t->data;
50 
51 	loginfo->nl_group = ULOG_DEFAULT_NLGROUP;
52 	loginfo->qthreshold = ULOG_DEFAULT_QTHRESHOLD;
53 
54 }
55 
ULOG_parse(struct xt_option_call * cb)56 static void ULOG_parse(struct xt_option_call *cb)
57 {
58 	struct ipt_ulog_info *loginfo = cb->data;
59 
60 	xtables_option_parse(cb);
61 	switch (cb->entry->id) {
62 	case O_ULOG_NLGROUP:
63 		loginfo->nl_group = 1 << (cb->val.u8 - 1);
64 		break;
65 	case O_ULOG_PREFIX:
66 		if (strchr(cb->arg, '\n') != NULL)
67 			xtables_error(PARAMETER_PROBLEM,
68 				   "Newlines not allowed in --ulog-prefix");
69 		break;
70 	case O_ULOG_CPRANGE:
71 		loginfo->copy_range = cb->val.u64;
72 		break;
73 	case O_ULOG_QTHR:
74 		loginfo->qthreshold = cb->val.u64;
75 		break;
76 	}
77 }
78 
ULOG_save(const void * ip,const struct xt_entry_target * target)79 static void ULOG_save(const void *ip, const struct xt_entry_target *target)
80 {
81 	const struct ipt_ulog_info *loginfo
82 	    = (const struct ipt_ulog_info *) target->data;
83 
84 	if (strcmp(loginfo->prefix, "") != 0) {
85 		fputs(" --ulog-prefix", stdout);
86 		xtables_save_string(loginfo->prefix);
87 	}
88 
89 	if (loginfo->nl_group != ULOG_DEFAULT_NLGROUP)
90 		printf(" --ulog-nlgroup %d", ffs(loginfo->nl_group));
91 	if (loginfo->copy_range)
92 		printf(" --ulog-cprange %u", (unsigned int)loginfo->copy_range);
93 
94 	if (loginfo->qthreshold != ULOG_DEFAULT_QTHRESHOLD)
95 		printf(" --ulog-qthreshold %u", (unsigned int)loginfo->qthreshold);
96 }
97 
ULOG_print(const void * ip,const struct xt_entry_target * target,int numeric)98 static void ULOG_print(const void *ip, const struct xt_entry_target *target,
99                        int numeric)
100 {
101 	const struct ipt_ulog_info *loginfo
102 	    = (const struct ipt_ulog_info *) target->data;
103 
104 	printf(" ULOG ");
105 	printf("copy_range %u nlgroup %d", (unsigned int)loginfo->copy_range,
106 	       ffs(loginfo->nl_group));
107 	if (strcmp(loginfo->prefix, "") != 0)
108 		printf(" prefix \"%s\"", loginfo->prefix);
109 	printf(" queue_threshold %u", (unsigned int)loginfo->qthreshold);
110 }
111 
112 static struct xtables_target ulog_tg_reg = {
113 	.name		= "ULOG",
114 	.version	= XTABLES_VERSION,
115 	.family		= NFPROTO_IPV4,
116 	.size		= XT_ALIGN(sizeof(struct ipt_ulog_info)),
117 	.userspacesize	= XT_ALIGN(sizeof(struct ipt_ulog_info)),
118 	.help		= ULOG_help,
119 	.init		= ULOG_init,
120 	.print		= ULOG_print,
121 	.save		= ULOG_save,
122 	.x6_parse	= ULOG_parse,
123 	.x6_options	= ULOG_opts,
124 };
125 
_init(void)126 void _init(void)
127 {
128 	xtables_register_target(&ulog_tg_reg);
129 }
130