1 /* Shared library add-on to iptables to add CLASSIFY target support. */
8 #include <linux/netfilter/x_tables.h>
9 #include <linux/netfilter/xt_CLASSIFY.h>
10 #include <linux/types.h>
11 #include <linux/pkt_sched.h>
13 /* Function which prints out usage message. */
18 "CLASSIFY target options:\n"
19 " --set-class [MAJOR:MINOR] Set skb->priority value\n");
22 static const struct option CLASSIFY_opts[] = {
23 { "set-class", 1, NULL, '1' },
27 static int CLASSIFY_string_to_priority(const char *s, unsigned int *p)
31 if (sscanf(s, "%x:%x", &i, &j) != 2)
34 *p = TC_H_MAKE(i<<16, j);
38 /* Function which parses command options; returns true if it
41 CLASSIFY_parse(int c, char **argv, int invert, unsigned int *flags,
43 struct xt_entry_target **target)
45 struct xt_classify_target_info *clinfo
46 = (struct xt_classify_target_info *)(*target)->data;
50 if (CLASSIFY_string_to_priority(optarg, &clinfo->priority))
51 exit_error(PARAMETER_PROBLEM,
52 "Bad class value `%s'", optarg);
54 exit_error(PARAMETER_PROBLEM,
55 "CLASSIFY: Can't specify --set-class twice");
67 CLASSIFY_final_check(unsigned int flags)
70 exit_error(PARAMETER_PROBLEM,
71 "CLASSIFY: Parameter --set-class is required");
75 CLASSIFY_print_class(unsigned int priority, int numeric)
77 printf("%x:%x ", TC_H_MAJ(priority)>>16, TC_H_MIN(priority));
80 /* Prints out the targinfo. */
82 CLASSIFY_print(const void *ip,
83 const struct xt_entry_target *target,
86 const struct xt_classify_target_info *clinfo =
87 (const struct xt_classify_target_info *)target->data;
88 printf("CLASSIFY set ");
89 CLASSIFY_print_class(clinfo->priority, numeric);
92 /* Saves the union ipt_targinfo in parsable form to stdout. */
94 CLASSIFY_save(const void *ip, const struct xt_entry_target *target)
96 const struct xt_classify_target_info *clinfo =
97 (const struct xt_classify_target_info *)target->data;
99 printf("--set-class %.4x:%.4x ",
100 TC_H_MAJ(clinfo->priority)>>16, TC_H_MIN(clinfo->priority));
103 static struct xtables_target classify_target = {
106 .version = XTABLES_VERSION,
107 .size = XT_ALIGN(sizeof(struct xt_classify_target_info)),
108 .userspacesize = XT_ALIGN(sizeof(struct xt_classify_target_info)),
109 .help = CLASSIFY_help,
110 .parse = CLASSIFY_parse,
111 .final_check = CLASSIFY_final_check,
112 .print = CLASSIFY_print,
113 .save = CLASSIFY_save,
114 .extra_opts = CLASSIFY_opts,
119 xtables_register_target(&classify_target);