From e6869a8f59d779ff4d5a0984c86d80db70784962 Mon Sep 17 00:00:00 2001 From: Marc Boucher Date: Mon, 20 Mar 2000 06:03:29 +0000 Subject: reorganized tree after kernel merge --- extensions/libipt_TOS.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 extensions/libipt_TOS.c (limited to 'extensions/libipt_TOS.c') diff --git a/extensions/libipt_TOS.c b/extensions/libipt_TOS.c new file mode 100644 index 00000000..4a8e91ba --- /dev/null +++ b/extensions/libipt_TOS.c @@ -0,0 +1,173 @@ +/* Shared library add-on to iptables to add TOS target support. */ +#include +#include +#include +#include + +#include +#include +#include + +struct tosinfo { + struct ipt_entry_target t; + struct ipt_tos_target_info tos; +}; + +/* TOS names and values. */ +struct TOS_value +{ + unsigned char TOS; + const char *name; +} TOS_values[] = { + { IPTOS_LOWDELAY, "Minimize-Delay" }, + { IPTOS_THROUGHPUT, "Maximize-Throughput" }, + { IPTOS_RELIABILITY, "Maximize-Reliability" }, + { IPTOS_MINCOST, "Minimize-Cost" }, + { IPTOS_NORMALSVC, "Normal-Service" }, +}; + +/* Function which prints out usage message. */ +static void +help(void) +{ + unsigned int i; + + printf( +"TOS target v%s options:\n" +" --set-tos value Set Type of Service field to one of the\n" +" following numeric or descriptive values:\n", +NETFILTER_VERSION); + + for (i = 0; i < sizeof(TOS_values)/sizeof(struct TOS_value);i++) + printf(" %s %u (0x%02x)\n", + TOS_values[i].name, + TOS_values[i].TOS, + TOS_values[i].TOS); + fputc('\n', stdout); +} + +static struct option opts[] = { + { "set-tos", 1, 0, '1' }, + { 0 } +}; + +/* Initialize the target. */ +static void +init(struct ipt_entry_target *t, unsigned int *nfcache) +{ +} + +static void +parse_tos(const unsigned char *s, struct ipt_tos_target_info *info) +{ + unsigned int i; + int tos = string_to_number(s, 0, 255); + + if (tos != -1) { + if (tos == IPTOS_LOWDELAY + || tos == IPTOS_THROUGHPUT + || tos == IPTOS_RELIABILITY + || tos == IPTOS_MINCOST + || tos == IPTOS_NORMALSVC) { + info->tos = (u_int8_t )tos; + return; + } + } else { + for (i = 0; itos = TOS_values[i].TOS; + return; + } + } + exit_error(PARAMETER_PROBLEM, "Bad TOS value `%s'", s); +} + +/* Function which parses command options; returns true if it + ate an option */ +static int +parse(int c, char **argv, int invert, unsigned int *flags, + const struct ipt_entry *entry, + struct ipt_entry_target **target) +{ + struct ipt_tos_target_info *tosinfo + = (struct ipt_tos_target_info *)(*target)->data; + + switch (c) { + case '1': + if (*flags) + exit_error(PARAMETER_PROBLEM, + "TOS target: Cant specify --set-tos twice"); + parse_tos(optarg, tosinfo); + *flags = 1; + break; + + default: + return 0; + } + + return 1; +} + +static void +final_check(unsigned int flags) +{ + if (!flags) + exit_error(PARAMETER_PROBLEM, + "TOS target: Parameter --set-tos is required"); +} + +static void +print_tos(u_int8_t tos, int numeric) +{ + unsigned int i; + + if (!numeric) { + for (i = 0; idata; + printf("TOS set "); + print_tos(tosinfo->tos, numeric); +} + +/* Saves the union ipt_targinfo in parsable form to stdout. */ +static void +save(const struct ipt_ip *ip, const struct ipt_entry_target *target) +{ + const struct ipt_tos_target_info *tosinfo = + (const struct ipt_tos_target_info *)target->data; + + printf("--set-tos 0x%02x ", tosinfo->tos); +} + +struct iptables_target tos += { NULL, + "TOS", + NETFILTER_VERSION, + sizeof(struct ipt_tos_target_info), + &help, + &init, + &parse, + &final_check, + &print, + &save, + opts +}; + +void _init(void) +{ + register_target(&tos); +} -- cgit v1.2.3