From 728f0c5c3820faca398de339b367c3f19b767a69 Mon Sep 17 00:00:00 2001 From: laforge Date: Fri, 21 Jun 2002 17:35:55 +0000 Subject: move DSCP name/value conversion to libipt_dscp_helper.c (Iain Barnes) --- extensions/libipt_dscp.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'extensions/libipt_dscp.c') diff --git a/extensions/libipt_dscp.c b/extensions/libipt_dscp.c index 8378815..7718112 100644 --- a/extensions/libipt_dscp.c +++ b/extensions/libipt_dscp.c @@ -6,6 +6,8 @@ * * libipt_dscp.c borrowed heavily from libipt_tos.c * + * --class support added by Iain Barnes + * * For a list of DSCP codepoints see * http://www.iana.org/assignments/dscp-registry * @@ -19,6 +21,9 @@ #include #include +/* This is evil, but it's my code - HW*/ +#include "libipt_dscp_helper.c" + static void init(struct ipt_entry_match *m, unsigned int *nfcache) { *nfcache |= NFC_IP_TOS; @@ -30,12 +35,18 @@ static void help(void) "DSCP match v%s options\n" "[!] --dscp value Match DSCP codepoint with numerical value\n" " This value can be in decimal (ex: 32)\n" -" or in hex (ex: 0x20)\n", IPTABLES_VERSION +" or in hex (ex: 0x20)\n" +"[!] --class name Match the DiffServ class. This value may\n" +" be any of the BE,EF, AFxx or CSx classes\n" +"\n" +" These two options are mutually exclusive !\n" + , IPTABLES_VERSION ); } static struct option opts[] = { { "dscp", 1, 0, 'F' }, + { "class", 1, 0, 'G' }, { 0 } }; @@ -56,6 +67,17 @@ parse_dscp(const unsigned char *s, struct ipt_dscp_info *dinfo) return; } + +static void +parse_class(const char *s, struct ipt_dscp_info *dinfo) +{ + unsigned int dscp = class_to_dscp(s); + + /* Assign the value */ + dinfo->dscp = (u_int8_t)dscp; +} + + static int parse(int c, char **argv, int invert, unsigned int *flags, const struct ipt_entry *entry, @@ -77,6 +99,17 @@ parse(int c, char **argv, int invert, unsigned int *flags, *flags = 1; break; + case 'G': + if (*flags) + exit_error(PARAMETER_PROBLEM, + "DSCP match: Only use --class ONCE!"); + check_inverse(optarg, &invert, &optind, 0); + parse_class(argv[optind - 1], dinfo); + if (invert) + dinfo->invert = 1; + *flags = 1; + break; + default: return 0; } -- cgit v1.2.3