1 /* Shared library add-on to iptables for FTOS
3 * (C) 2000 by Matthew G. Marsh <mgm@paktronix.com>
5 * This program is distributed under the terms of GNU GPL v2, 1991
7 * libipt_FTOS.c borrowed heavily from libipt_TOS.c 11/09/2000
16 #include <linux/netfilter_ipv4/ip_tables.h>
17 #include <linux/netfilter_ipv4/ipt_FTOS.h>
20 struct ipt_entry_target t;
24 static void init(struct ipt_entry_target *t, unsigned int *nfcache)
28 static void help(void)
31 "FTOS target options\n"
32 " --set-ftos value Set TOS field in packet header to value\n"
33 " This value can be in decimal (ex: 32)\n"
34 " or in hex (ex: 0x20)\n"
38 static struct option opts[] = {
39 { "set-ftos", 1, 0, 'F' },
44 parse_ftos(const unsigned char *s, struct ipt_FTOS_info *finfo)
48 if (string_to_number(s, 0, 255, &ftos) == -1)
49 exit_error(PARAMETER_PROBLEM,
50 "Invalid ftos `%s'\n", s);
51 finfo->ftos = (u_int8_t )ftos;
56 parse(int c, char **argv, int invert, unsigned int *flags,
57 const struct ipt_entry *entry,
58 struct ipt_entry_target **target)
60 struct ipt_FTOS_info *finfo
61 = (struct ipt_FTOS_info *)(*target)->data;
66 exit_error(PARAMETER_PROBLEM,
67 "FTOS target: Only use --set-ftos ONCE!");
68 parse_ftos(optarg, finfo);
80 final_check(unsigned int flags)
83 exit_error(PARAMETER_PROBLEM,
84 "FTOS target: Parameter --set-ftos is required");
88 print_ftos(u_int8_t ftos, int numeric)
90 printf("0x%02x ", ftos);
93 /* Prints out the targinfo. */
95 print(const struct ipt_ip *ip,
96 const struct ipt_entry_target *target,
99 const struct ipt_FTOS_info *finfo =
100 (const struct ipt_FTOS_info *)target->data;
102 print_ftos(finfo->ftos, numeric);
105 /* Saves the union ipt_targinfo in parsable form to stdout. */
107 save(const struct ipt_ip *ip, const struct ipt_entry_target *target)
109 const struct ipt_FTOS_info *finfo =
110 (const struct ipt_FTOS_info *)target->data;
112 printf("--set-ftos 0x%02x ", finfo->ftos);
115 static struct iptables_target ftos = {
118 .version = IPTABLES_VERSION,
119 .size = IPT_ALIGN(sizeof(struct ipt_FTOS_info)),
120 .userspacesize = IPT_ALIGN(sizeof(struct ipt_FTOS_info)),
124 .final_check = &final_check,
132 register_target(&ftos);