1 /* Shared library add-on to iptables to add CLASSIFY target support. */
8 #include <linux/netfilter_ipv4/ip_tables.h>
9 #include <linux/netfilter_ipv4/ipt_CLASSIFY.h>
10 #include <linux/types.h>
11 #include <linux/pkt_sched.h>
13 /* Function which prints out usage message. */
18 "CLASSIFY target v%s options:\n"
19 " --set-class [MAJOR:MINOR] Set skb->priority value\n"
24 static struct option opts[] = {
25 { "set-class", 1, 0, '1' },
29 /* Initialize the target. */
31 init(struct ipt_entry_target *t, unsigned int *nfcache)
35 int string_to_priority(const char *s, unsigned int *p)
39 if (sscanf(s, "%x:%x", &i, &j) != 2)
42 *p = TC_H_MAKE(i<<16, j);
46 /* Function which parses command options; returns true if it
49 parse(int c, char **argv, int invert, unsigned int *flags,
50 const struct ipt_entry *entry,
51 struct ipt_entry_target **target)
53 struct ipt_classify_target_info *clinfo
54 = (struct ipt_classify_target_info *)(*target)->data;
58 if (string_to_priority(optarg, &clinfo->priority))
59 exit_error(PARAMETER_PROBLEM,
60 "Bad class value `%s'", optarg);
62 exit_error(PARAMETER_PROBLEM,
63 "CLASSIFY: Can't specify --set-class twice");
75 final_check(unsigned int flags)
78 exit_error(PARAMETER_PROBLEM,
79 "CLASSIFY: Parameter --set-class is required");
83 print_class(unsigned int priority, int numeric)
85 printf("%x:%x ", TC_H_MAJ(priority)>>16, TC_H_MIN(priority));
88 /* Prints out the targinfo. */
90 print(const struct ipt_ip *ip,
91 const struct ipt_entry_target *target,
94 const struct ipt_classify_target_info *clinfo =
95 (const struct ipt_classify_target_info *)target->data;
96 printf("CLASSIFY set ");
97 print_class(clinfo->priority, numeric);
100 /* Saves the union ipt_targinfo in parsable form to stdout. */
102 save(const struct ipt_ip *ip, const struct ipt_entry_target *target)
104 const struct ipt_classify_target_info *clinfo =
105 (const struct ipt_classify_target_info *)target->data;
107 printf("--set-class %.4x:%.4x ",
108 TC_H_MAJ(clinfo->priority)>>16, TC_H_MIN(clinfo->priority));
111 static struct iptables_target classify = {
114 .version = IPTABLES_VERSION,
115 .size = IPT_ALIGN(sizeof(struct ipt_classify_target_info)),
116 .userspacesize = IPT_ALIGN(sizeof(struct ipt_classify_target_info)),
120 .final_check = &final_check,
128 register_target(&classify);