1
/* Shared library add-on to iptables for DSCP
3
* (C) 2000- 2002 by Matthew G. Marsh <mgm@paktronix.com>,
4
* Harald Welte <laforge@gnumonks.org>
6
* This program is distributed under the terms of GNU GPL v2, 1991
8
* libipt_DSCP.c borrowed heavily from libipt_TOS.c
10
* --set-class added by Iain Barnes
18
#include <linux/netfilter/x_tables.h>
19
#include <linux/netfilter/xt_DSCP.h>
21
/* This is evil, but it's my code - HW*/
22
#include "libipt_dscp_helper.c"
24
static void DSCP_help(void)
27
"DSCP target options\n"
28
" --set-dscp value Set DSCP field in packet header to value\n"
29
" This value can be in decimal (ex: 32)\n"
30
" or in hex (ex: 0x20)\n"
31
" --set-dscp-class class Set the DSCP field in packet header to the\n"
32
" value represented by the DiffServ class value.\n"
33
" This class may be EF,BE or any of the CSxx\n"
36
" These two options are mutually exclusive !\n"
40
static const struct option DSCP_opts[] = {
41
{ "set-dscp", 1, NULL, 'F' },
42
{ "set-dscp-class", 1, NULL, 'G' },
47
parse_dscp(const char *s, struct xt_DSCP_info *dinfo)
51
if (string_to_number(s, 0, 255, &dscp) == -1)
52
exit_error(PARAMETER_PROBLEM,
53
"Invalid dscp `%s'\n", s);
55
if (dscp > XT_DSCP_MAX)
56
exit_error(PARAMETER_PROBLEM,
57
"DSCP `%d` out of range\n", dscp);
59
dinfo->dscp = (u_int8_t )dscp;
65
parse_class(const char *s, struct xt_DSCP_info *dinfo)
67
unsigned int dscp = class_to_dscp(s);
69
/* Assign the value */
70
dinfo->dscp = (u_int8_t)dscp;
74
static int DSCP_parse(int c, char **argv, int invert, unsigned int *flags,
75
const void *entry, struct xt_entry_target **target)
77
struct xt_DSCP_info *dinfo
78
= (struct xt_DSCP_info *)(*target)->data;
83
exit_error(PARAMETER_PROBLEM,
84
"DSCP target: Only use --set-dscp ONCE!");
85
parse_dscp(optarg, dinfo);
90
exit_error(PARAMETER_PROBLEM,
91
"DSCP target: Only use --set-dscp-class ONCE!");
92
parse_class(optarg, dinfo);
103
static void DSCP_check(unsigned int flags)
106
exit_error(PARAMETER_PROBLEM,
107
"DSCP target: Parameter --set-dscp is required");
111
print_dscp(u_int8_t dscp, int numeric)
113
printf("0x%02x ", dscp);
116
/* Prints out the targinfo. */
117
static void DSCP_print(const void *ip, const struct xt_entry_target *target,
120
const struct xt_DSCP_info *dinfo =
121
(const struct xt_DSCP_info *)target->data;
123
print_dscp(dinfo->dscp, numeric);
126
/* Saves the union ipt_targinfo in parsable form to stdout. */
127
static void DSCP_save(const void *ip, const struct xt_entry_target *target)
129
const struct xt_DSCP_info *dinfo =
130
(const struct xt_DSCP_info *)target->data;
132
printf("--set-dscp 0x%02x ", dinfo->dscp);
135
static struct xtables_target dscp_target = {
138
.version = IPTABLES_VERSION,
139
.size = XT_ALIGN(sizeof(struct xt_DSCP_info)),
140
.userspacesize = XT_ALIGN(sizeof(struct xt_DSCP_info)),
143
.final_check = DSCP_check,
146
.extra_opts = DSCP_opts,
149
static struct xtables_target dscp_target6 = {
152
.version = IPTABLES_VERSION,
153
.size = XT_ALIGN(sizeof(struct xt_DSCP_info)),
154
.userspacesize = XT_ALIGN(sizeof(struct xt_DSCP_info)),
157
.final_check = DSCP_check,
160
.extra_opts = DSCP_opts,
165
xtables_register_target(&dscp_target);
166
xtables_register_target(&dscp_target6);