Hi, Here is a little patch which adds a small feature to the DSCP table.
It provides you with the option of using --set-class to set the codepoint. This option takes the name of a diffserv class, such as AF11,EF etc and sets the codepoint accordingly. Very simple, just saves people from having to remember codepoint values. All values are those specified in the relevant RFC's PS. This is my first netfilter hacking attempt so if i've made mistakes, can you let me know.
--- libipt_DSCP.c.orig Sat Mar 2 18:30:23 2002 +++ libipt_DSCP.c Mon Feb 25 20:44:09 2002 @@ -17,6 +17,30 @@ #include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv4/ipt_DSCP.h> + + +static struct ds_class +{ + char *class; + unsigned int dscp; +} af_classes[] = +{ + { "AF11", 10 }, + { "AF12", 12 }, + { "AF13", 14 }, + { "AF21", 18 }, + { "AF22", 20 }, + { "AF23", 22 }, + { "AF31", 26 }, + { "AF32", 28 }, + { "AF33", 30 }, + { "AF41", 34 }, + { "AF42", 36 }, + { "AF43", 38 } +}; + + + static void init(struct ipt_entry_target *t, unsigned int *nfcache) { } @@ -28,11 +52,18 @@ " --set-dscp value Set DSCP field in packet header to value\n" " This value can be in decimal (ex: 32)\n" " or in hex (ex: 0x20)\n" +" --set-class value Set the DSCP field in packet header to the value\n" +" represented by the DiffServ class value.\n" +" This class can be EF, BE or any of the AFxx classes\n" +" as defined by the RFC documents.\n" +"\n" +" The two options are mutually exclusive !\n" ); } static struct option opts[] = { { "set-dscp", 1, 0, 'F' }, + { "set-class", 1, 0, 'G' }, { 0 } }; @@ -53,6 +84,32 @@ return; } + + +static void +parse_class(const unsigned char *s, struct ipt_DSCP_info *dinfo) +{ + int i; + + if (strncasecmp(s, "EF", 2) == 0) { + dinfo->dscp = (u_int8_t)46; + return; + } else if (strncasecmp(s, "BE", 2) == 0) { + dinfo->dscp = (u_int8_t)0; + return; + } else { + for (i = 0; i < sizeof(af_classes) / sizeof(struct ds_class); i++) { + if (strncasecmp(s, af_classes[i].class, 4) == 0) { + dinfo->dscp = (u_int8_t)af_classes[i].dscp; + return; + } + } + } + + exit_error(PARAMETER_PROBLEM, "Invalid DSCP class value `%s`", s); +} + + static int parse(int c, char **argv, int invert, unsigned int *flags, const struct ipt_entry *entry, @@ -69,7 +126,13 @@ parse_dscp(optarg, dinfo); *flags = 1; break; - + case 'G': + if (*flags) + exit_error(PARAMETER_PROBLEM, + "DSCP target: Only use --set-class ONCE!"); + parse_class(optarg, dinfo); + *flags = 1; + break; default: return 0; }