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>
17 "CLASSIFY target options:\n"
18 "--set-class MAJOR:MINOR Set skb->priority value (always hexadecimal!)\n");
21 static const struct option CLASSIFY_opts[] = {
22 { "set-class", 1, NULL, '1' },
26 static int CLASSIFY_string_to_priority(const char *s, unsigned int *p)
30 if (sscanf(s, "%x:%x", &i, &j) != 2)
33 *p = TC_H_MAKE(i<<16, j);
38 CLASSIFY_parse(int c, char **argv, int invert, unsigned int *flags,
40 struct xt_entry_target **target)
42 struct xt_classify_target_info *clinfo
43 = (struct xt_classify_target_info *)(*target)->data;
47 if (CLASSIFY_string_to_priority(optarg, &clinfo->priority))
48 xtables_error(PARAMETER_PROBLEM,
49 "Bad class value `%s'", optarg);
51 xtables_error(PARAMETER_PROBLEM,
52 "CLASSIFY: Can't specify --set-class twice");
64 CLASSIFY_final_check(unsigned int flags)
67 xtables_error(PARAMETER_PROBLEM,
68 "CLASSIFY: Parameter --set-class is required");
72 CLASSIFY_print_class(unsigned int priority, int numeric)
74 printf("%x:%x ", TC_H_MAJ(priority)>>16, TC_H_MIN(priority));
78 CLASSIFY_print(const void *ip,
79 const struct xt_entry_target *target,
82 const struct xt_classify_target_info *clinfo =
83 (const struct xt_classify_target_info *)target->data;
84 printf("CLASSIFY set ");
85 CLASSIFY_print_class(clinfo->priority, numeric);
89 CLASSIFY_save(const void *ip, const struct xt_entry_target *target)
91 const struct xt_classify_target_info *clinfo =
92 (const struct xt_classify_target_info *)target->data;
94 printf("--set-class %.4x:%.4x ",
95 TC_H_MAJ(clinfo->priority)>>16, TC_H_MIN(clinfo->priority));
98 static struct xtables_target classify_target = {
99 .family = NFPROTO_UNSPEC,
101 .version = XTABLES_VERSION,
102 .size = XT_ALIGN(sizeof(struct xt_classify_target_info)),
103 .userspacesize = XT_ALIGN(sizeof(struct xt_classify_target_info)),
104 .help = CLASSIFY_help,
105 .parse = CLASSIFY_parse,
106 .final_check = CLASSIFY_final_check,
107 .print = CLASSIFY_print,
108 .save = CLASSIFY_save,
109 .extra_opts = CLASSIFY_opts,
114 xtables_register_target(&classify_target);