Ok, sorry for the long delay.

I have checked the values against the IANA registry and they all seem correct (post 27 
Mar update)

So here is the patch again against 1.2.6a. Attached and inline


Iain






--- libipt_DSCP.c.orig  Wed Apr 10 15:50:48 2002
+++ libipt_DSCP.c       Wed Apr 10 16:12:39 2002
@@ -6,7 +6,7 @@
  * This program is distributed under the terms of GNU GPL v2, 1991
  *
  * libipt_DSCP.c borrowed heavily from libipt_TOS.c
- *
+ * --set-class added by Iain Barnes
  */
 #include <stdio.h>
 #include <string.h>
@@ -17,6 +17,32 @@
 #include <linux/netfilter_ipv4/ip_tables.h>
 #include <linux/netfilter_ipv4/ipt_DSCP.h>
 
+
+#define EF     46
+#define BE     0
+
+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 +54,17 @@
 "  --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 class           Set the DSCP field in packet header to the value\n"
+"                              represented by the DiffServ class value.\n"
+"                              This class may be EF,BE or any of the AFxx classes.\n"
+"\n"
+"                              These two options are mutually exclusive !\n"
 );
 }
 
 static struct option opts[] = {
        { "set-dscp", 1, 0, 'F' },
+       { "set-class", 1, 0, 'G' },
        { 0 }
 };
 
@@ -53,6 +85,29 @@
        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)EF;
+       } else if (strncasecmp(s, "BE", 2) == 0) {
+               dinfo->dscp = (u_int8_t)BE;
+       } 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,6 +124,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;


Attachment: dscp.diff
Description: Binary data

Reply via email to