• 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 <xtables.h>
15 /* For 64bit kernel / 32bit userspace */
16 #include <linux/netfilter_ipv4/ipt_ULOG.h>
17 
18 enum {
19 	O_ULOG_NLGROUP = 0,
20 	O_ULOG_PREFIX,
21 	O_ULOG_CPRANGE,
22 	O_ULOG_QTHR,
23 };
24 
ULOG_help(void)25 static void ULOG_help(void)
26 {
27 	printf("ULOG target options:\n"
28 	       " --ulog-nlgroup nlgroup		NETLINK group used for logging\n"
29 	       " --ulog-cprange size		Bytes of each packet to be passed\n"
30 	       " --ulog-qthreshold		Threshold of in-kernel queue\n"
31 	       " --ulog-prefix prefix		Prefix log messages with this prefix.\n");
32 }
33 
34 static const struct xt_option_entry ULOG_opts[] = {
35 	{.name = "ulog-nlgroup", .id = O_ULOG_NLGROUP, .type = XTTYPE_UINT8,
36 	 .min = 1, .max = 32},
37 	{.name = "ulog-prefix", .id = O_ULOG_PREFIX, .type = XTTYPE_STRING,
38 	 .flags = XTOPT_PUT, XTOPT_POINTER(struct ipt_ulog_info, prefix),
39 	 .min = 1},
40 	{.name = "ulog-cprange", .id = O_ULOG_CPRANGE, .type = XTTYPE_UINT64,
41 	 .min = 1, .max = ULOG_MAX_QLEN},
42 	{.name = "ulog-qthreshold", .id = O_ULOG_QTHR, .type = XTTYPE_UINT64},
43 	XTOPT_TABLEEND,
44 };
45 
ULOG_init(struct xt_entry_target * t)46 static void ULOG_init(struct xt_entry_target *t)
47 {
48 	struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) t->data;
49 
50 	loginfo->nl_group = ULOG_DEFAULT_NLGROUP;
51 	loginfo->qthreshold = ULOG_DEFAULT_QTHRESHOLD;
52 
53 }
54 
ULOG_parse(struct xt_option_call * cb)55 static void ULOG_parse(struct xt_option_call *cb)
56 {
57 	struct ipt_ulog_info *loginfo = cb->data;
58 
59 	xtables_option_parse(cb);
60 	switch (cb->entry->id) {
61 	case O_ULOG_NLGROUP:
62 		loginfo->nl_group = 1 << (cb->val.u8 - 1);
63 		break;
64 	case O_ULOG_PREFIX:
65 		if (strchr(cb->arg, '\n') != NULL)
66 			xtables_error(PARAMETER_PROBLEM,
67 				   "Newlines not allowed in --ulog-prefix");
68 		break;
69 	case O_ULOG_CPRANGE:
70 		loginfo->copy_range = cb->val.u64;
71 		break;
72 	case O_ULOG_QTHR:
73 		loginfo->qthreshold = cb->val.u64;
74 		break;
75 	}
76 }
77 
ULOG_save(const void * ip,const struct xt_entry_target * target)78 static void ULOG_save(const void *ip, const struct xt_entry_target *target)
79 {
80 	const struct ipt_ulog_info *loginfo
81 	    = (const struct ipt_ulog_info *) target->data;
82 
83 	if (strcmp(loginfo->prefix, "") != 0) {
84 		fputs(" --ulog-prefix", stdout);
85 		xtables_save_string(loginfo->prefix);
86 	}
87 
88 	if (loginfo->nl_group != ULOG_DEFAULT_NLGROUP)
89 		printf(" --ulog-nlgroup %d", ffs(loginfo->nl_group));
90 	if (loginfo->copy_range)
91 		printf(" --ulog-cprange %u", (unsigned int)loginfo->copy_range);
92 
93 	if (loginfo->qthreshold != ULOG_DEFAULT_QTHRESHOLD)
94 		printf(" --ulog-qthreshold %u", (unsigned int)loginfo->qthreshold);
95 }
96 
ULOG_print(const void * ip,const struct xt_entry_target * target,int numeric)97 static void ULOG_print(const void *ip, const struct xt_entry_target *target,
98                        int numeric)
99 {
100 	const struct ipt_ulog_info *loginfo
101 	    = (const struct ipt_ulog_info *) target->data;
102 
103 	printf(" ULOG ");
104 	printf("copy_range %u nlgroup %d", (unsigned int)loginfo->copy_range,
105 	       ffs(loginfo->nl_group));
106 	if (strcmp(loginfo->prefix, "") != 0)
107 		printf(" prefix \"%s\"", loginfo->prefix);
108 	printf(" queue_threshold %u", (unsigned int)loginfo->qthreshold);
109 }
110 
111 static struct xtables_target ulog_tg_reg = {
112 	.name		= "ULOG",
113 	.version	= XTABLES_VERSION,
114 	.family		= NFPROTO_IPV4,
115 	.size		= XT_ALIGN(sizeof(struct ipt_ulog_info)),
116 	.userspacesize	= XT_ALIGN(sizeof(struct ipt_ulog_info)),
117 	.help		= ULOG_help,
118 	.init		= ULOG_init,
119 	.print		= ULOG_print,
120 	.save		= ULOG_save,
121 	.x6_parse	= ULOG_parse,
122 	.x6_options	= ULOG_opts,
123 };
124 
_init(void)125 void _init(void)
126 {
127 	xtables_register_target(&ulog_tg_reg);
128 }
129