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
;
37 /* Parse command options */
38 static int parse(int c
, char **argv
, int invert
, unsigned int *flags
,
39 const struct ipt_entry
*entry
,
40 struct ipt_entry_target
**target
)
42 struct ipt_nldata
*nld
=(struct ipt_nldata
*)(*target
)->data
;
46 if (MASK(*flags
, USE_DROP
))
47 exit_error(PARAMETER_PROBLEM
,
48 "Can't specify --nldrop twice");
50 if ( check_inverse(optarg
, &invert
, NULL
, 0) ) {
51 MASK_UNSET(nld
->flags
, USE_DROP
);
53 MASK_SET(nld
->flags
, USE_DROP
);
56 MASK_SET(*flags
, USE_DROP
);
60 if (MASK(*flags
, USE_MARK
))
61 exit_error(PARAMETER_PROBLEM
,
62 "Can't specify --nlmark twice");
64 if (check_inverse(optarg
, &invert
, NULL
, 0)) {
65 MASK_UNSET(nld
->flags
, USE_MARK
);
67 MASK_SET(nld
->flags
, USE_MARK
);
68 nld
->mark
=atoi(optarg
);
71 MASK_SET(*flags
, USE_MARK
);
74 if (MASK(*flags
, USE_SIZE
))
75 exit_error(PARAMETER_PROBLEM
,
76 "Can't specify --nlsize twice");
78 if ( atoi(optarg
) <= 0 )
79 exit_error(PARAMETER_PROBLEM
,
80 "--nlsize must be larger than zero");
83 if (check_inverse(optarg
, &invert
, NULL
, 0)) {
84 MASK_UNSET(nld
->flags
, USE_SIZE
);
86 MASK_SET(nld
->flags
, USE_SIZE
);
87 nld
->size
=atoi(optarg
);
89 MASK_SET(*flags
, USE_SIZE
);
98 static void final_check(unsigned int flags
)
103 /* Saves the union ipt_targinfo in parsable form to stdout. */
104 static void save(const struct ipt_ip
*ip
,
105 const struct ipt_entry_target
*target
)
107 const struct ipt_nldata
*nld
108 = (const struct ipt_nldata
*) target
->data
;
110 if ( MASK(nld
->flags
, USE_DROP
) )
113 if ( MASK(nld
->flags
, USE_MARK
) )
114 printf("--nlmark %i ", nld
->mark
);
116 if ( MASK(nld
->flags
, USE_SIZE
) )
117 printf("--nlsize %i ", nld
->size
);
120 /* Prints out the targinfo. */
122 print(const struct ipt_ip
*ip
,
123 const struct ipt_entry_target
*target
, int numeric
)
125 const struct ipt_nldata
*nld
126 = (const struct ipt_nldata
*) target
->data
;
128 if ( MASK(nld
->flags
, USE_DROP
) )
131 if ( MASK(nld
->flags
, USE_MARK
) )
132 printf("nlmark %i ", nld
->mark
);
134 if ( MASK(nld
->flags
, USE_SIZE
) )
135 printf("nlsize %i ", nld
->size
);
138 static struct iptables_target netlink
= {
141 .version
= IPTABLES_VERSION
,
142 .size
= IPT_ALIGN(sizeof(struct ipt_nldata
)),
143 .userspacesize
= IPT_ALIGN(sizeof(struct ipt_nldata
)),
147 .final_check
= &final_check
,
155 register_target(&netlink
);