1 /* Provides a NETLINK target, identical to that of the ipchains -o flag */
2 /* AUTHOR: Gianni Tedesco <gianni@ecsc.co.uk> */
10 #include <linux/netfilter_ipv4/ip_tables.h>
11 #include <linux/netfilter_ipv4/ipt_NETLINK.h>
13 static void help(void)
15 printf("NETLINK v%s options:\n"
16 " --nldrop Drop the packet too\n"
17 " --nlmark <number> Mark the packet\n"
18 " --nlsize <bytes> Limit packet size\n",
22 static struct option opts[] = {
23 {"nldrop", 0, 0, 'd'},
24 {"nlmark", 1, 0, 'm'},
25 {"nlsize", 1, 0, 's'},
29 static void init(struct ipt_entry_target *t, unsigned int *nfcache)
31 struct ipt_nldata *nld = (struct ipt_nldata *) t->data;
35 *nfcache |= NFC_UNKNOWN;
38 /* Parse command options */
39 static int parse(int c, char **argv, int invert, unsigned int *flags,
40 const struct ipt_entry *entry,
41 struct ipt_entry_target **target)
43 struct ipt_nldata *nld=(struct ipt_nldata *)(*target)->data;
47 if (MASK(*flags, USE_DROP))
48 exit_error(PARAMETER_PROBLEM,
49 "Can't specify --nldrop twice");
51 if ( check_inverse(optarg, &invert, NULL, 0) ) {
52 MASK_UNSET(nld->flags, USE_DROP);
54 MASK_SET(nld->flags, USE_DROP);
57 MASK_SET(*flags, USE_DROP);
61 if (MASK(*flags, USE_MARK))
62 exit_error(PARAMETER_PROBLEM,
63 "Can't specify --nlmark twice");
65 if (check_inverse(optarg, &invert, NULL, 0)) {
66 MASK_UNSET(nld->flags, USE_MARK);
68 MASK_SET(nld->flags, USE_MARK);
69 nld->mark=atoi(optarg);
72 MASK_SET(*flags, USE_MARK);
75 if (MASK(*flags, USE_SIZE))
76 exit_error(PARAMETER_PROBLEM,
77 "Can't specify --nlsize twice");
79 if ( atoi(optarg) <= 0 )
80 exit_error(PARAMETER_PROBLEM,
81 "--nlsize must be larger than zero");
84 if (check_inverse(optarg, &invert, NULL, 0)) {
85 MASK_UNSET(nld->flags, USE_SIZE);
87 MASK_SET(nld->flags, USE_SIZE);
88 nld->size=atoi(optarg);
90 MASK_SET(*flags, USE_SIZE);
99 static void final_check(unsigned int flags)
104 /* Saves the union ipt_targinfo in parsable form to stdout. */
105 static void save(const struct ipt_ip *ip,
106 const struct ipt_entry_target *target)
108 const struct ipt_nldata *nld
109 = (const struct ipt_nldata *) target->data;
111 if ( MASK(nld->flags, USE_DROP) )
114 if ( MASK(nld->flags, USE_MARK) )
115 printf("--nlmark %i ", nld->mark);
117 if ( MASK(nld->flags, USE_SIZE) )
118 printf("--nlsize %i ", nld->size);
121 /* Prints out the targinfo. */
123 print(const struct ipt_ip *ip,
124 const struct ipt_entry_target *target, int numeric)
126 const struct ipt_nldata *nld
127 = (const struct ipt_nldata *) target->data;
129 if ( MASK(nld->flags, USE_DROP) )
132 if ( MASK(nld->flags, USE_MARK) )
133 printf("nlmark %i ", nld->mark);
135 if ( MASK(nld->flags, USE_SIZE) )
136 printf("nlsize %i ", nld->size);
140 struct iptables_target netlink = { NULL,
143 IPT_ALIGN(sizeof(struct ipt_nldata)),
144 IPT_ALIGN(sizeof(struct ipt_nldata)),
156 register_target(&netlink);