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"
20 " --add-mark Add value of skb->mark to skb->priority (PlanetLab specific)\n");
23 static const struct option CLASSIFY_opts[] = {
24 { "set-class", 1, NULL, '1' },
25 { "add-mark", 0, 0, '2' },
29 static int CLASSIFY_string_to_priority(const char *s, unsigned int *p)
33 if (sscanf(s, "%x:%x", &i, &j) != 2)
36 *p = TC_H_MAKE(i<<16, j);
40 /* Function which parses command options; returns true if it
43 CLASSIFY_parse(int c, char **argv, int invert, unsigned int *flags,
45 struct xt_entry_target **target)
47 struct xt_classify_target_info *clinfo
48 = (struct xt_classify_target_info *)(*target)->data;
54 if (CLASSIFY_string_to_priority(optarg, &clinfo->priority))
55 exit_error(PARAMETER_PROBLEM,
56 "Bad class value `%s'", optarg);
58 exit_error(PARAMETER_PROBLEM,
59 "CLASSIFY: Can't specify --set-class twice");
75 CLASSIFY_final_check(unsigned int flags)
78 exit_error(PARAMETER_PROBLEM,
79 "CLASSIFY: Parameter --set-class is required");
83 CLASSIFY_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 CLASSIFY_print(const void *ip,
91 const struct xt_entry_target *target,
94 const struct xt_classify_target_info *clinfo =
95 (const struct xt_classify_target_info *)target->data;
96 printf("CLASSIFY set ");
97 CLASSIFY_print_class(clinfo->priority, numeric);
100 printf ("add-mark ");
103 /* Saves the union ipt_targinfo in parsable form to stdout. */
105 CLASSIFY_save(const void *ip, const struct xt_entry_target *target)
107 const struct xt_classify_target_info *clinfo =
108 (const struct xt_classify_target_info *)target->data;
110 printf("--set-class %.4x:%.4x ",
111 TC_H_MAJ(clinfo->priority)>>16, TC_H_MIN(clinfo->priority));
113 if (clinfo->add_mark)
114 printf("--add-mark ");
117 static struct xtables_target classify_target = {
120 .version = XTABLES_VERSION,
121 .size = XT_ALIGN(sizeof(struct xt_classify_target_info)),
122 .userspacesize = XT_ALIGN(sizeof(struct xt_classify_target_info)),
123 .help = CLASSIFY_help,
124 .parse = CLASSIFY_parse,
125 .final_check = CLASSIFY_final_check,
126 .print = CLASSIFY_print,
127 .save = CLASSIFY_save,
128 .extra_opts = CLASSIFY_opts,
133 xtables_register_target(&classify_target);