blob: 93120385f59d6dc7d9f805d6a3101cd4c099a979 [file] [log] [blame]
Matthew G. Marshd9c66ba2000-12-18 06:22:44 +00001/* Shared library add-on to iptables for FTOS
2 *
3 * (C) 2000 by Matthew G. Marsh <mgm@paktronix.com>
4 *
5 * This program is distributed under the terms of GNU GPL v2, 1991
6 *
7 * libipt_FTOS.c borrowed heavily from libipt_TOS.c 11/09/2000
8 *
9 */
10#include <stdio.h>
11#include <string.h>
12#include <stdlib.h>
13#include <getopt.h>
14
15#include <iptables.h>
16#include <linux/netfilter_ipv4/ip_tables.h>
17#include <linux/netfilter_ipv4/ipt_FTOS.h>
18
19struct finfo {
20 struct ipt_entry_target t;
21 u_int8_t ftos;
22};
23
24static void init(struct ipt_entry_target *t, unsigned int *nfcache)
25{
26}
27
28static void help(void)
29{
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"
35);
36}
37
38static struct option opts[] = {
39 { "set-ftos", 1, 0, 'F' },
40 { 0 }
41};
42
43static void
44parse_ftos(const unsigned char *s, struct ipt_FTOS_info *finfo)
45{
46 int ftos = string_to_number(s, 0, 255);
47 finfo->ftos = (u_int8_t )ftos;
48 return;
49}
50
51static int
52parse(int c, char **argv, int invert, unsigned int *flags,
53 const struct ipt_entry *entry,
54 struct ipt_entry_target **target)
55{
56 struct ipt_FTOS_info *finfo
57 = (struct ipt_FTOS_info *)(*target)->data;
58
59 switch (c) {
60 case 'F':
61 if (*flags)
62 exit_error(PARAMETER_PROBLEM,
63 "FTOS target: Only use --set-ftos ONCE!");
64 parse_ftos(optarg, finfo);
65 *flags = 1;
66 break;
67
68 default:
69 return 0;
70 }
71
72 return 1;
73}
74
75static void
76final_check(unsigned int flags)
77{
78 if (!flags)
79 exit_error(PARAMETER_PROBLEM,
80 "FTOS target: Parameter --set-ftos is required");
81}
82
83static void
84print_ftos(u_int8_t ftos, int numeric)
85{
86 printf("0x%02x ", ftos);
87}
88
89/* Prints out the targinfo. */
90static void
91print(const struct ipt_ip *ip,
92 const struct ipt_entry_target *target,
93 int numeric)
94{
95 const struct ipt_FTOS_info *finfo =
96 (const struct ipt_FTOS_info *)target->data;
97 printf("TOS set ");
98 print_ftos(finfo->ftos, numeric);
99}
100
101/* Saves the union ipt_targinfo in parsable form to stdout. */
102static void
103save(const struct ipt_ip *ip, const struct ipt_entry_target *target)
104{
105 const struct ipt_FTOS_info *finfo =
106 (const struct ipt_FTOS_info *)target->data;
107
108 printf("--set-ftos 0x%02x ", finfo->ftos);
109}
110
111struct iptables_target ftos
112= { NULL,
113 "FTOS",
114 NETFILTER_VERSION,
115 IPT_ALIGN(sizeof(struct ipt_FTOS_info)),
116 IPT_ALIGN(sizeof(struct ipt_FTOS_info)),
117 &help,
118 &init,
119 &parse,
120 &final_check,
121 &print,
122 &save,
123 opts
124};
125
126void _init(void)
127{
128 register_target(&ftos);
129}