blob: 48f88ec50e55141b4ee21f67fa863696df2fa830 [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{
Harald Welteb4719762001-07-23 02:14:22 +000046 unsigned int ftos;
47
48 string_to_number(s, 0, 255, &ftos);
Matthew G. Marshd9c66ba2000-12-18 06:22:44 +000049 finfo->ftos = (u_int8_t )ftos;
50 return;
51}
52
53static int
54parse(int c, char **argv, int invert, unsigned int *flags,
55 const struct ipt_entry *entry,
56 struct ipt_entry_target **target)
57{
58 struct ipt_FTOS_info *finfo
59 = (struct ipt_FTOS_info *)(*target)->data;
60
61 switch (c) {
62 case 'F':
63 if (*flags)
64 exit_error(PARAMETER_PROBLEM,
65 "FTOS target: Only use --set-ftos ONCE!");
66 parse_ftos(optarg, finfo);
67 *flags = 1;
68 break;
69
70 default:
71 return 0;
72 }
73
74 return 1;
75}
76
77static void
78final_check(unsigned int flags)
79{
80 if (!flags)
81 exit_error(PARAMETER_PROBLEM,
82 "FTOS target: Parameter --set-ftos is required");
83}
84
85static void
86print_ftos(u_int8_t ftos, int numeric)
87{
88 printf("0x%02x ", ftos);
89}
90
91/* Prints out the targinfo. */
92static void
93print(const struct ipt_ip *ip,
94 const struct ipt_entry_target *target,
95 int numeric)
96{
97 const struct ipt_FTOS_info *finfo =
98 (const struct ipt_FTOS_info *)target->data;
99 printf("TOS set ");
100 print_ftos(finfo->ftos, numeric);
101}
102
103/* Saves the union ipt_targinfo in parsable form to stdout. */
104static void
105save(const struct ipt_ip *ip, const struct ipt_entry_target *target)
106{
107 const struct ipt_FTOS_info *finfo =
108 (const struct ipt_FTOS_info *)target->data;
109
110 printf("--set-ftos 0x%02x ", finfo->ftos);
111}
112
113struct iptables_target ftos
114= { NULL,
115 "FTOS",
116 NETFILTER_VERSION,
117 IPT_ALIGN(sizeof(struct ipt_FTOS_info)),
118 IPT_ALIGN(sizeof(struct ipt_FTOS_info)),
119 &help,
120 &init,
121 &parse,
122 &final_check,
123 &print,
124 &save,
125 opts
126};
127
128void _init(void)
129{
130 register_target(&ftos);
131}