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 xt_option_entry tos_mt_opts_v0[] = {
28 {.name = "tos", .id = O_TOS, .type = XTTYPE_TOSMASK,
29 .flags = XTOPT_INVERT | XTOPT_MAND, .max = 0xFF},
33 static const struct xt_option_entry tos_mt_opts[] = {
34 {.name = "tos", .id = O_TOS, .type = XTTYPE_TOSMASK,
35 .flags = XTOPT_INVERT | XTOPT_MAND, .max = 0x3F},
39 static void tos_mt_help(void)
41 const struct tos_symbol_info *symbol;
44 "tos match options:\n"
45 "[!] --tos value[/mask] Match Type of Service/Priority field value\n"
46 "[!] --tos symbol Match TOS field (IPv4 only) by symbol\n"
47 " Accepted symbolic names for value are:\n");
49 for (symbol = tos_symbol_names; symbol->name != NULL; ++symbol)
50 printf(" (0x%02x) %2u %s\n",
51 symbol->value, symbol->value, symbol->name);
56 static void tos_mt_parse_v0(struct xt_option_call *cb)
58 struct ipt_tos_info *info = cb->data;
60 xtables_option_parse(cb);
61 if (cb->val.tos_mask != 0xFF)
62 xtables_error(PARAMETER_PROBLEM, "tos: Your kernel is "
63 "too old to support anything besides /0xFF "
65 info->tos = cb->val.tos_value;
70 static void tos_mt_parse(struct xt_option_call *cb)
72 struct xt_tos_match_info *info = cb->data;
74 xtables_option_parse(cb);
75 info->tos_value = cb->val.tos_value;
76 info->tos_mask = cb->val.tos_mask;
81 static void tos_mt_print_v0(const void *ip, const struct xt_entry_match *match,
84 const struct ipt_tos_info *info = (const void *)match->data;
86 printf(" tos match ");
89 if (numeric || !tos_try_print_symbolic("", info->tos, 0x3F))
90 printf("0x%02x", info->tos);
93 static void tos_mt_print(const void *ip, const struct xt_entry_match *match,
96 const struct xt_tos_match_info *info = (const void *)match->data;
102 !tos_try_print_symbolic("", info->tos_value, info->tos_mask))
103 printf("0x%02x/0x%02x", info->tos_value, info->tos_mask);
106 static void tos_mt_save_v0(const void *ip, const struct xt_entry_match *match)
108 const struct ipt_tos_info *info = (const void *)match->data;
112 printf(" --tos 0x%02x", info->tos);
115 static void tos_mt_save(const void *ip, const struct xt_entry_match *match)
117 const struct xt_tos_match_info *info = (const void *)match->data;
121 printf(" --tos 0x%02x/0x%02x", info->tos_value, info->tos_mask);
124 static struct xtables_match tos_mt_reg[] = {
126 .version = XTABLES_VERSION,
128 .family = NFPROTO_IPV4,
130 .size = XT_ALIGN(sizeof(struct ipt_tos_info)),
131 .userspacesize = XT_ALIGN(sizeof(struct ipt_tos_info)),
133 .print = tos_mt_print_v0,
134 .save = tos_mt_save_v0,
135 .x6_parse = tos_mt_parse_v0,
136 .x6_options = tos_mt_opts_v0,
139 .version = XTABLES_VERSION,
141 .family = NFPROTO_UNSPEC,
143 .size = XT_ALIGN(sizeof(struct xt_tos_match_info)),
144 .userspacesize = XT_ALIGN(sizeof(struct xt_tos_match_info)),
146 .print = tos_mt_print,
148 .x6_parse = tos_mt_parse,
149 .x6_options = tos_mt_opts,
155 xtables_register_matches(tos_mt_reg, ARRAY_SIZE(tos_mt_reg));