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"
20 " --add-mark Add value of skb->mark to skb->priority (PlanetLab specific)\n"
25 static struct option opts[] = {
26 { "set-class", 1, 0, '1' },
27 { "add-mark", 0, 0, '2' },
31 /* Initialize the target. */
33 init(struct ipt_entry_target *t, unsigned int *nfcache)
37 int string_to_priority(const char *s, unsigned int *p)
41 if (sscanf(s, "%x:%x", &i, &j) != 2)
44 *p = TC_H_MAKE(i<<16, j);
48 /* Function which parses command options; returns true if it
51 parse(int c, char **argv, int invert, unsigned int *flags,
52 const struct ipt_entry *entry,
53 struct ipt_entry_target **target)
55 struct ipt_classify_target_info *clinfo
56 = (struct ipt_classify_target_info *)(*target)->data;
62 if (string_to_priority(optarg, &clinfo->priority))
63 exit_error(PARAMETER_PROBLEM,
64 "Bad class value `%s'", optarg);
66 exit_error(PARAMETER_PROBLEM,
67 "CLASSIFY: Can't specify --set-class twice");
83 final_check(unsigned int flags)
86 exit_error(PARAMETER_PROBLEM,
87 "CLASSIFY: Parameter --set-class is required");
91 print_class(unsigned int priority, int numeric)
93 printf("%x:%x ", TC_H_MAJ(priority)>>16, TC_H_MIN(priority));
96 /* Prints out the targinfo. */
98 print(const struct ipt_ip *ip,
99 const struct ipt_entry_target *target,
102 const struct ipt_classify_target_info *clinfo =
103 (const struct ipt_classify_target_info *)target->data;
104 printf("CLASSIFY set ");
105 print_class(clinfo->priority, numeric);
106 if (clinfo->add_mark)
107 printf ("add-mark ");
110 /* Saves the union ipt_targinfo in parsable form to stdout. */
112 save(const struct ipt_ip *ip, const struct ipt_entry_target *target)
114 const struct ipt_classify_target_info *clinfo =
115 (const struct ipt_classify_target_info *)target->data;
117 printf("--set-class %.4x:%.4x ",
118 TC_H_MAJ(clinfo->priority)>>16, TC_H_MIN(clinfo->priority));
120 if (clinfo->add_mark)
121 printf("--add-mark ");
124 static struct iptables_target classify = {
127 .version = IPTABLES_VERSION,
128 .size = IPT_ALIGN(sizeof(struct ipt_classify_target_info)),
129 .userspacesize = IPT_ALIGN(sizeof(struct ipt_classify_target_info)),
133 .final_check = &final_check,
141 register_target(&classify);