Patch that I sent in in April, still applies fine.

Robert
From efca8eeb6aaf848ae70b786ea8159a752679d1c7 Mon Sep 17 00:00:00 2001
From: Robert Buchholz <[email protected]>
Date: Sun, 25 Jan 2009 19:44:38 +0100
Subject: [PATCH] Add OFFSET to CheckIP6Header

Similar to the offset parameter of CheckIPHeader, this allows specifying
a byte offset to read the IP6 header from.
---
 elements/ip6/checkip6header.cc |   27 ++++++++++++++++-----------
 elements/ip6/checkip6header.hh |   15 +++++++++++++--
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/elements/ip6/checkip6header.cc b/elements/ip6/checkip6header.cc
index 4341cc7..9f5007c 100644
--- a/elements/ip6/checkip6header.cc
+++ b/elements/ip6/checkip6header.cc
@@ -42,17 +42,21 @@ CheckIP6Header::~CheckIP6Header()
 int
 CheckIP6Header::configure(Vector<String> &conf, ErrorHandler *errh)
 {
-
-  if (conf.size() > 1)
-    return errh->error("too many arguments to `CheckIP6Header([ADDRS])'");
-
+ String badaddrs = String::make_empty();
+ _offset = 0;
  Vector<String> ips;
  // ips.push_back("0::0"); // this address is only bad if we are a router
  ips.push_back("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); // bad IP6 address
 
-  if (conf.size()) {
+  if (cp_va_kparse(conf, this, errh,
+		      "BADADDRS", cpkP, cpString, &badaddrs,
+		      "OFFSET", cpkP, cpUnsigned, &_offset,
+		      cpEnd) < 0)
+    return -1;
+
+  if (badaddrs) {
     Vector<String> words;
-    cp_spacevec(conf[0], words);
+    cp_spacevec(badaddrs, words);
     IP6Address a;
     for (int j = 0; j < words.size(); j++) {
       if (!cp_ip6_address(words[j], (unsigned char *)&a)) {
@@ -94,11 +98,12 @@ CheckIP6Header::drop_it(Packet *p)
 Packet *
 CheckIP6Header::simple_action(Packet *p)
 {
-  const click_ip6 *ip = reinterpret_cast <const click_ip6 *>( p->data());
+  const click_ip6 *ip = reinterpret_cast <const click_ip6 *>( p->data() + _offset);
+  unsigned plen = p->length() - _offset;
   struct IP6Address src;
 
   // check if the packet is smaller than ip6 header
-  if(p->length() < sizeof(click_ip6))
+  if(plen < sizeof(click_ip6))
     goto bad;
 
  // check version
@@ -106,7 +111,7 @@ CheckIP6Header::simple_action(Packet *p)
     goto bad;
 
   // check if the PayloadLength field is valid
-   if(ntohs(ip->ip6_plen) > (p->length()-40))
+   if(ntohs(ip->ip6_plen) > (plen-40))
      goto bad;
 
   /*
@@ -130,8 +135,8 @@ CheckIP6Header::simple_action(Packet *p)
   p->set_ip6_header(ip);
 
   // shorten packet according to IP6 payload length field
-  if(ntohs(ip->ip6_plen) < (p->length()-40))
-    p->take(p->length() - 40 - ip->ip6_plen);
+  if(ntohs(ip->ip6_plen) < (plen-40))
+    p->take(plen - 40 - ip->ip6_plen);
   return(p);
 
  bad:
diff --git a/elements/ip6/checkip6header.hh b/elements/ip6/checkip6header.hh
index 5ec7511..b6a5b4c 100644
--- a/elements/ip6/checkip6header.hh
+++ b/elements/ip6/checkip6header.hh
@@ -6,26 +6,37 @@ CLICK_DECLS
 
 /*
  * =c
- * CheckIP6Header([BADADDRS])
+ * CheckIP6Header([BADADDRS, OFFSET])
  * =s ip6
  *
  * =d
  *
- * Expects IP6 packets as input. Checks that the packet's length is
+ * Expects IP6 packets as input starting at OFFSET bytes. Default OFFSET
+ * is zero. Checks that the packet's length is
  * reasonable, and that the IP6 version,  length, are valid. Checks that the
  * IP6 source address is a legal unicast address. Shortens packets to the IP6
  * length, if the IP length is shorter than the nominal packet length (due to
  * Ethernet padding, for example). Pushes invalid packets out on output 1,
  * unless output 1 was unused; if so, drops invalid packets.
  *
+ * Keyword arguments are:
+ *
+ * =item BADADDRS
+ *
  * The BADADDRS argument is a space-separated list of IP6 addresses that are
  * not to be tolerated as source addresses. 0::0 is a bad address for routers,
  * for example, but okay for link local packets.
  *
+ * =item OFFSET
+ *
+ * Unsigned integer. Byte position at which the IP6 header begins. Default is 0.
+ *
  * =a MarkIP6Header */
 
 class CheckIP6Header : public Element {
 
+  int _offset;
+
   int _n_bad_src;
   IP6Address *_bad_src; // array of illegal IP6 src addresses.
 #ifdef CLICK_LINUXMODULE
-- 
1.6.3.3

_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click

Reply via email to