2 * Shared library add-on to iptables to add tos match support
4 * Copyright © CC Computer Consultants GmbH, 2007
5 * Contact: Jan Engelhardt <jengelh@computergmbh.de>
15 #include <linux/netfilter/xt_dscp.h>
16 #include "tos_values.c"
27 static const struct option tos_mt_opts[] = {
28 {.name = "tos", .has_arg = true, .val = 't'},
32 static void tos_mt_help(void)
34 const struct tos_symbol_info *symbol;
37 "tos match options:\n"
38 "[!] --tos value[/mask] Match Type of Service/Priority field value\n"
39 "[!] --tos symbol Match TOS field (IPv4 only) by symbol\n"
40 " Accepted symbolic names for value are:\n");
42 for (symbol = tos_symbol_names; symbol->name != NULL; ++symbol)
43 printf(" (0x%02x) %2u %s\n",
44 symbol->value, symbol->value, symbol->name);
49 static int tos_mt_parse_v0(int c, char **argv, int invert, unsigned int *flags,
50 const void *entry, struct xt_entry_match **match)
52 struct ipt_tos_info *info = (void *)(*match)->data;
53 struct tos_value_mask tvm;
57 xtables_param_act(XTF_ONLY_ONCE, "tos", "--tos", *flags & FLAG_TOS);
58 if (!tos_parse_symbolic(optarg, &tvm, 0xFF))
59 xtables_param_act(XTF_BAD_VALUE, "tos", "--tos", optarg);
61 xtables_error(PARAMETER_PROBLEM, "tos: Your kernel is "
62 "too old to support anything besides /0xFF "
64 info->tos = tvm.value;
73 static int tos_mt_parse(int c, char **argv, int invert, unsigned int *flags,
74 const void *entry, struct xt_entry_match **match)
76 struct xt_tos_match_info *info = (void *)(*match)->data;
77 struct tos_value_mask tvm = {.mask = 0xFF};
81 xtables_param_act(XTF_ONLY_ONCE, "tos", "--tos", *flags & FLAG_TOS);
82 if (!tos_parse_symbolic(optarg, &tvm, 0x3F))
83 xtables_param_act(XTF_BAD_VALUE, "tos", "--tos", optarg);
84 info->tos_value = tvm.value;
85 info->tos_mask = tvm.mask;
94 static void tos_mt_check(unsigned int flags)
97 xtables_error(PARAMETER_PROBLEM,
98 "tos: --tos parameter required");
101 static void tos_mt_print_v0(const void *ip, const struct xt_entry_match *match,
104 const struct ipt_tos_info *info = (const void *)match->data;
106 printf("tos match ");
109 if (numeric || !tos_try_print_symbolic("", info->tos, 0x3F))
110 printf("0x%02x ", info->tos);
113 static void tos_mt_print(const void *ip, const struct xt_entry_match *match,
116 const struct xt_tos_match_info *info = (const void *)match->data;
118 printf("tos match ");
122 !tos_try_print_symbolic("", info->tos_value, info->tos_mask))
123 printf("0x%02x/0x%02x ", info->tos_value, info->tos_mask);
126 static void tos_mt_save_v0(const void *ip, const struct xt_entry_match *match)
128 const struct ipt_tos_info *info = (const void *)match->data;
132 printf("--tos 0x%02x ", info->tos);
135 static void tos_mt_save(const void *ip, const struct xt_entry_match *match)
137 const struct xt_tos_match_info *info = (const void *)match->data;
141 printf("--tos 0x%02x/0x%02x ", info->tos_value, info->tos_mask);
144 static struct xtables_match tos_mt_reg[] = {
146 .version = XTABLES_VERSION,
148 .family = NFPROTO_IPV4,
150 .size = XT_ALIGN(sizeof(struct ipt_tos_info)),
151 .userspacesize = XT_ALIGN(sizeof(struct ipt_tos_info)),
153 .parse = tos_mt_parse_v0,
154 .final_check = tos_mt_check,
155 .print = tos_mt_print_v0,
156 .save = tos_mt_save_v0,
157 .extra_opts = tos_mt_opts,
160 .version = XTABLES_VERSION,
162 .family = NFPROTO_UNSPEC,
164 .size = XT_ALIGN(sizeof(struct xt_tos_match_info)),
165 .userspacesize = XT_ALIGN(sizeof(struct xt_tos_match_info)),
167 .parse = tos_mt_parse,
168 .final_check = tos_mt_check,
169 .print = tos_mt_print,
171 .extra_opts = tos_mt_opts,
177 xtables_register_matches(tos_mt_reg, ARRAY_SIZE(tos_mt_reg));