Busybox: Upgrade to 1.21.1 (stable). lsof active.
[tomato.git] / release / src / router / iptables / extensions / libipt_FTOS.c
blob62df4cdef5532e2bb9a9aa743026d9bdf881ce84
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
9 */
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <getopt.h>
15 #include <iptables.h>
16 #include <linux/netfilter_ipv4/ip_tables.h>
17 #include <linux/netfilter_ipv4/ipt_FTOS.h>
19 struct finfo {
20 struct ipt_entry_target t;
21 u_int8_t ftos;
24 static void init(struct ipt_entry_target *t, unsigned int *nfcache)
28 static void help(void)
30 printf(
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' },
40 { 0 }
43 static void
44 parse_ftos(const unsigned char *s, struct ipt_FTOS_info *finfo)
46 unsigned int ftos;
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;
52 return;
55 static int
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;
63 switch (c) {
64 case 'F':
65 if (*flags)
66 exit_error(PARAMETER_PROBLEM,
67 "FTOS target: Only use --set-ftos ONCE!");
68 parse_ftos(optarg, finfo);
69 *flags = 1;
70 break;
72 default:
73 return 0;
76 return 1;
79 static void
80 final_check(unsigned int flags)
82 if (!flags)
83 exit_error(PARAMETER_PROBLEM,
84 "FTOS target: Parameter --set-ftos is required");
87 static void
88 print_ftos(u_int8_t ftos, int numeric)
90 printf("0x%02x ", ftos);
93 /* Prints out the targinfo. */
94 static void
95 print(const struct ipt_ip *ip,
96 const struct ipt_entry_target *target,
97 int numeric)
99 const struct ipt_FTOS_info *finfo =
100 (const struct ipt_FTOS_info *)target->data;
101 printf("TOS set ");
102 print_ftos(finfo->ftos, numeric);
105 /* Saves the union ipt_targinfo in parsable form to stdout. */
106 static void
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 = {
116 .next = NULL,
117 .name = "FTOS",
118 .version = IPTABLES_VERSION,
119 .size = IPT_ALIGN(sizeof(struct ipt_FTOS_info)),
120 .userspacesize = IPT_ALIGN(sizeof(struct ipt_FTOS_info)),
121 .help = &help,
122 .init = &init,
123 .parse = &parse,
124 .final_check = &final_check,
125 .print = &print,
126 .save = &save,
127 .extra_opts = opts
130 void _init(void)
132 register_target(&ftos);