|
Packit Service |
d1fe03 |
/*
|
|
Packit Service |
d1fe03 |
* Shared library add-on to iptables to add tos match support
|
|
Packit Service |
d1fe03 |
*
|
|
Packit Service |
d1fe03 |
* Copyright © CC Computer Consultants GmbH, 2007
|
|
Packit Service |
d1fe03 |
* Contact: Jan Engelhardt <jengelh@computergmbh.de>
|
|
Packit Service |
d1fe03 |
*/
|
|
Packit Service |
d1fe03 |
#include <getopt.h>
|
|
Packit Service |
d1fe03 |
#include <netdb.h>
|
|
Packit Service |
d1fe03 |
#include <stdbool.h>
|
|
Packit Service |
d1fe03 |
#include <stdio.h>
|
|
Packit Service |
d1fe03 |
#include <stdlib.h>
|
|
Packit Service |
d1fe03 |
#include <string.h>
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
#include <xtables.h>
|
|
Packit Service |
d1fe03 |
#include <linux/netfilter/xt_dscp.h>
|
|
Packit Service |
d1fe03 |
#include "tos_values.c"
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
struct ipt_tos_info {
|
|
Packit Service |
d1fe03 |
uint8_t tos;
|
|
Packit Service |
d1fe03 |
uint8_t invert;
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
enum {
|
|
Packit Service |
d1fe03 |
O_TOS = 1 << 0,
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
static const struct xt_option_entry tos_mt_opts_v0[] = {
|
|
Packit Service |
d1fe03 |
{.name = "tos", .id = O_TOS, .type = XTTYPE_TOSMASK,
|
|
Packit Service |
d1fe03 |
.flags = XTOPT_INVERT | XTOPT_MAND, .max = 0xFF},
|
|
Packit Service |
d1fe03 |
XTOPT_TABLEEND,
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
static const struct xt_option_entry tos_mt_opts[] = {
|
|
Packit Service |
d1fe03 |
{.name = "tos", .id = O_TOS, .type = XTTYPE_TOSMASK,
|
|
Packit Service |
d1fe03 |
.flags = XTOPT_INVERT | XTOPT_MAND, .max = 0x3F},
|
|
Packit Service |
d1fe03 |
XTOPT_TABLEEND,
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
static void tos_mt_help(void)
|
|
Packit Service |
d1fe03 |
{
|
|
Packit Service |
d1fe03 |
const struct tos_symbol_info *symbol;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
printf(
|
|
Packit Service |
d1fe03 |
"tos match options:\n"
|
|
Packit Service |
d1fe03 |
"[!] --tos value[/mask] Match Type of Service/Priority field value\n"
|
|
Packit Service |
d1fe03 |
"[!] --tos symbol Match TOS field (IPv4 only) by symbol\n"
|
|
Packit Service |
d1fe03 |
" Accepted symbolic names for value are:\n");
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
for (symbol = tos_symbol_names; symbol->name != NULL; ++symbol)
|
|
Packit Service |
d1fe03 |
printf(" (0x%02x) %2u %s\n",
|
|
Packit Service |
d1fe03 |
symbol->value, symbol->value, symbol->name);
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
printf("\n");
|
|
Packit Service |
d1fe03 |
}
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
static void tos_mt_parse_v0(struct xt_option_call *cb)
|
|
Packit Service |
d1fe03 |
{
|
|
Packit Service |
d1fe03 |
struct ipt_tos_info *info = cb->data;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
xtables_option_parse(cb);
|
|
Packit Service |
d1fe03 |
if (cb->val.tos_mask != 0xFF)
|
|
Packit Service |
d1fe03 |
xtables_error(PARAMETER_PROBLEM, "tos: Your kernel is "
|
|
Packit Service |
d1fe03 |
"too old to support anything besides /0xFF "
|
|
Packit Service |
d1fe03 |
"as a mask.");
|
|
Packit Service |
d1fe03 |
info->tos = cb->val.tos_value;
|
|
Packit Service |
d1fe03 |
if (cb->invert)
|
|
Packit Service |
d1fe03 |
info->invert = true;
|
|
Packit Service |
d1fe03 |
}
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
static void tos_mt_parse(struct xt_option_call *cb)
|
|
Packit Service |
d1fe03 |
{
|
|
Packit Service |
d1fe03 |
struct xt_tos_match_info *info = cb->data;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
xtables_option_parse(cb);
|
|
Packit Service |
d1fe03 |
info->tos_value = cb->val.tos_value;
|
|
Packit Service |
d1fe03 |
info->tos_mask = cb->val.tos_mask;
|
|
Packit Service |
d1fe03 |
if (cb->invert)
|
|
Packit Service |
d1fe03 |
info->invert = true;
|
|
Packit Service |
d1fe03 |
}
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
static void tos_mt_print_v0(const void *ip, const struct xt_entry_match *match,
|
|
Packit Service |
d1fe03 |
int numeric)
|
|
Packit Service |
d1fe03 |
{
|
|
Packit Service |
d1fe03 |
const struct ipt_tos_info *info = (const void *)match->data;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
printf(" tos match ");
|
|
Packit Service |
d1fe03 |
if (info->invert)
|
|
Packit Service |
d1fe03 |
printf("!");
|
|
Packit Service |
d1fe03 |
if (numeric || !tos_try_print_symbolic("", info->tos, 0x3F))
|
|
Packit Service |
d1fe03 |
printf("0x%02x", info->tos);
|
|
Packit Service |
d1fe03 |
}
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
static void tos_mt_print(const void *ip, const struct xt_entry_match *match,
|
|
Packit Service |
d1fe03 |
int numeric)
|
|
Packit Service |
d1fe03 |
{
|
|
Packit Service |
d1fe03 |
const struct xt_tos_match_info *info = (const void *)match->data;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
printf(" tos match");
|
|
Packit Service |
d1fe03 |
if (info->invert)
|
|
Packit Service |
d1fe03 |
printf("!");
|
|
Packit Service |
d1fe03 |
if (numeric ||
|
|
Packit Service |
d1fe03 |
!tos_try_print_symbolic("", info->tos_value, info->tos_mask))
|
|
Packit Service |
d1fe03 |
printf("0x%02x/0x%02x", info->tos_value, info->tos_mask);
|
|
Packit Service |
d1fe03 |
}
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
static void tos_mt_save_v0(const void *ip, const struct xt_entry_match *match)
|
|
Packit Service |
d1fe03 |
{
|
|
Packit Service |
d1fe03 |
const struct ipt_tos_info *info = (const void *)match->data;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
if (info->invert)
|
|
Packit Service |
d1fe03 |
printf(" !");
|
|
Packit Service |
d1fe03 |
printf(" --tos 0x%02x", info->tos);
|
|
Packit Service |
d1fe03 |
}
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
static void tos_mt_save(const void *ip, const struct xt_entry_match *match)
|
|
Packit Service |
d1fe03 |
{
|
|
Packit Service |
d1fe03 |
const struct xt_tos_match_info *info = (const void *)match->data;
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
if (info->invert)
|
|
Packit Service |
d1fe03 |
printf(" !");
|
|
Packit Service |
d1fe03 |
printf(" --tos 0x%02x/0x%02x", info->tos_value, info->tos_mask);
|
|
Packit Service |
d1fe03 |
}
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
static struct xtables_match tos_mt_reg[] = {
|
|
Packit Service |
d1fe03 |
{
|
|
Packit Service |
d1fe03 |
.version = XTABLES_VERSION,
|
|
Packit Service |
d1fe03 |
.name = "tos",
|
|
Packit Service |
d1fe03 |
.family = NFPROTO_IPV4,
|
|
Packit Service |
d1fe03 |
.revision = 0,
|
|
Packit Service |
d1fe03 |
.size = XT_ALIGN(sizeof(struct ipt_tos_info)),
|
|
Packit Service |
d1fe03 |
.userspacesize = XT_ALIGN(sizeof(struct ipt_tos_info)),
|
|
Packit Service |
d1fe03 |
.help = tos_mt_help,
|
|
Packit Service |
d1fe03 |
.print = tos_mt_print_v0,
|
|
Packit Service |
d1fe03 |
.save = tos_mt_save_v0,
|
|
Packit Service |
d1fe03 |
.x6_parse = tos_mt_parse_v0,
|
|
Packit Service |
d1fe03 |
.x6_options = tos_mt_opts_v0,
|
|
Packit Service |
d1fe03 |
},
|
|
Packit Service |
d1fe03 |
{
|
|
Packit Service |
d1fe03 |
.version = XTABLES_VERSION,
|
|
Packit Service |
d1fe03 |
.name = "tos",
|
|
Packit Service |
d1fe03 |
.family = NFPROTO_UNSPEC,
|
|
Packit Service |
d1fe03 |
.revision = 1,
|
|
Packit Service |
d1fe03 |
.size = XT_ALIGN(sizeof(struct xt_tos_match_info)),
|
|
Packit Service |
d1fe03 |
.userspacesize = XT_ALIGN(sizeof(struct xt_tos_match_info)),
|
|
Packit Service |
d1fe03 |
.help = tos_mt_help,
|
|
Packit Service |
d1fe03 |
.print = tos_mt_print,
|
|
Packit Service |
d1fe03 |
.save = tos_mt_save,
|
|
Packit Service |
d1fe03 |
.x6_parse = tos_mt_parse,
|
|
Packit Service |
d1fe03 |
.x6_options = tos_mt_opts,
|
|
Packit Service |
d1fe03 |
},
|
|
Packit Service |
d1fe03 |
};
|
|
Packit Service |
d1fe03 |
|
|
Packit Service |
d1fe03 |
void _init(void)
|
|
Packit Service |
d1fe03 |
{
|
|
Packit Service |
d1fe03 |
xtables_register_matches(tos_mt_reg, ARRAY_SIZE(tos_mt_reg));
|
|
Packit Service |
d1fe03 |
}
|