On Thu, Sep 13, 2012 at 2:47 PM, Alfredo Cardigliano
<[email protected]>wrote:

>
> > I would prefer the 802.1Q tags are ignored.
>
> This is not available through the API at the moment, you should manually
> change the
> hash function (hash_pkt_cluster) in kernel/pf_ring.c
>


I made it work by avoiding assignment in parse_raw_pkt() instead.  I think
this might break filtering; I tried modifying hash_pkt_cluster as you
suggested but was unsuccessful.  Can you point out what I'm missing ?  Both
patches are included at the end.


hash_pkt_cluster --> hash_pkt_header() --> hash_pkt()

According to hash_pkt_header() the last argument "mask_vlan" will prevent
using a vlan_id by providing "0" as an argument to hash_pkt() instead of
the parsed vlan_id obtained from parse_raw_pkt().


##########################################
# Inside hash_pkt_cluster(), call hash_pkt_header()
# with last argument as 1 to mask vlan.
##########################################
#
idx = hash_pkt_header(hdr, 0, 0, 0, 0, 1);  // last arg is to mask_vlan,
default 0.



###########################################
# Inside hash_pkt_header, call hash_pkt() with first argument as vlan_id.
# If mask_vlan was set then supply 0 instead of the parsed vlan_id.
###########################################
#
--------------------------------------
inline u_int32_t hash_pkt_header(struct pfring_pkthdr * hdr, u_char
mask_src, u_char mask_dst,
                                 u_int8_t mask_port, u_int8_t mask_proto,
u_int8_t mask_vlan)
{
  if(hdr->extended_hdr.pkt_hash == 0) {
    u_int8_t use_tunneled_peers =
hdr->extended_hdr.parsed_pkt.tunnel.tunnel_id == NO_TUNNEL_ID ? 0 : 1;

    hdr->extended_hdr.pkt_hash = hash_pkt(
      mask_vlan  ? 0 : hdr->extended_hdr.parsed_pkt.vlan_id,  // <---
supply zero as vlan_id to hash_pkt()
---------------------------------------


##########################################
# inside hash_pkt(),
##########################################
#
--------------------------------------
inline u_int32_t hash_pkt(u_int16_t vlan_id, u_int8_t proto,
                          ip_addr host_peer_a, ip_addr host_peer_b,
                          u_int16_t port_peer_a, u_int16_t port_peer_b)
{
  if(unlikely(enable_debug))
    printk("[PF_RING] hash_pkt(vlan_id=%u, proto=%u, port_peer_a=%u,
port_peer_b=%u)\n",
           vlan_id,proto, port_peer_a, port_peer_b);

  return(vlan_id+proto+
         host_peer_a.v6.s6_addr32[0]+host_peer_a.v6.s6_addr32[1]+
         host_peer_a.v6.s6_addr32[2]+host_peer_a.v6.s6_addr32[3]+
         host_peer_b.v6.s6_addr32[0]+host_peer_b.v6.s6_addr32[1]+
         host_peer_b.v6.s6_addr32[2]+host_peer_b.v6.s6_addr32[3]+
         port_peer_a+port_peer_b);
}
--------------------------------------






###############################################
#
# Patch to prevent vlan_id by modifying parse_raw_pkt
#
###############################################
#
--- pf_ring.c.svn-original      2012-09-13 15:20:08.968686143 -0700
+++ pf_ring.c   2012-09-13 15:26:55.864690537 -0700
@@ -330,6 +330,7 @@
 static unsigned int quick_mode = 0;
 static unsigned int enable_debug = 0;
 static unsigned int transparent_mode = standard_linux_path;
+static unsigned int disable_vlan_hash = 0;  // disable hashing with vlanid
 static atomic_t ring_id_serial = ATOMIC_INIT(0);

 #if defined(RHEL_RELEASE_CODE)
@@ -342,6 +343,7 @@
 module_param(min_num_slots, uint, 0644);
 module_param(perfect_rules_hash_size, uint, 0644);
 module_param(transparent_mode, uint, 0644);
+module_param(disable_vlan_hash, uint, 0644);  // disable hashing with
vlanid
 module_param(enable_debug, uint, 0644);
 module_param(enable_tx_capture, uint, 0644);
 module_param(enable_ip_defrag, uint, 0644);
@@ -350,6 +352,7 @@
 MODULE_PARM(min_num_slots, "i");
 MODULE_PARM(perfect_rules_hash_size, "i");
 MODULE_PARM(transparent_mode, "i");
+MODULE_PARM(disable_vlan_hash, "i"); // disable hashing with vlanid
 MODULE_PARM(enable_debug, "i");
 MODULE_PARM(enable_tx_capture, "i");
 MODULE_PARM(enable_ip_defrag, "i");
@@ -361,6 +364,8 @@
 MODULE_PARM_DESC(transparent_mode,
  "0=standard Linux, 1=direct2pfring+transparent, 2=direct2pfring+non
transparent"
  "For 1 and 2 you need to use a PF_RING aware driver");
+MODULE_PARM_DESC(disable_vlan_hash,
+               "0=include vlan_id, 1=ignore vlan_id. To ignore the vlan_id
when hashing by flow.");
 MODULE_PARM_DESC(enable_debug, "Set to 1 to enable PF_RING debug tracing
into the syslog");
 MODULE_PARM_DESC(enable_tx_capture, "Set to 1 to capture outgoing
packets");
 MODULE_PARM_DESC(enable_ip_defrag,
@@ -1332,6 +1337,8 @@
     rlen += sprintf(buf + rlen, "Transparent mode    : %s\n",
  (transparent_mode == standard_linux_path ? "Yes (mode 0)" :
  (transparent_mode == driver2pf_ring_transparent ? "Yes (mode 1)" : "No
(mode 2)")));
+    rlen += sprintf(buf + rlen, "VLAN_ID in flow hash: %s\n",
+               disable_vlan_hash ? "Disabled" : "Enabled");
     rlen += sprintf(buf + rlen, "Total rings         : %d\n",
ring_table_size);
     rlen += sprintf(buf + rlen, "Total plugins       : %d\n",
plugin_registration_size);
   } else {
@@ -1796,7 +1803,12 @@
     while (hdr->extended_hdr.parsed_pkt.eth_type == ETH_P_8021Q /* 802.1q
(VLAN) */) {
       hdr->extended_hdr.parsed_pkt.offset.vlan_offset += sizeof(struct
eth_vlan_hdr);
       vh = (struct eth_vlan_hdr *)
&data[hdr->extended_hdr.parsed_pkt.offset.vlan_offset];
-      hdr->extended_hdr.parsed_pkt.vlan_id = ntohs(vh->h_vlan_id) & 0x0fff;
+
+       // If the disable_vlan_hash flag is set ignore the VLAN ID.
+       if ( disable_vlan_hash == 0 ) {
+               hdr->extended_hdr.parsed_pkt.vlan_id = ntohs(vh->h_vlan_id)
& 0x0fff;
+       }
+
       hdr->extended_hdr.parsed_pkt.eth_type = ntohs(vh->h_proto);
       displ += sizeof(struct eth_vlan_hdr);
     }







############################################
#
# Unsuccessful attempt to patch by modifying hash_pkt_cluster.
# Modify last argument of hash_pkt_header to enable masking vlan_id.
#
############################################
#
--- pfring_svn-2012-09-14/kernel/pf_ring.c      2012-09-13
18:06:52.942351274 -0700
+++ pfring_svn-2012-09-14--vlan_patch/kernel/pf_ring.c  2012-09-13
18:04:07.002349484 -0700
@@ -330,6 +330,7 @@
 static unsigned int quick_mode = 0;
 static unsigned int enable_debug = 0;
 static unsigned int transparent_mode = standard_linux_path;
+static unsigned int disable_vlan_hash = 0;
 static atomic_t ring_id_serial = ATOMIC_INIT(0);

 #if defined(RHEL_RELEASE_CODE)
@@ -342,6 +343,7 @@
 module_param(min_num_slots, uint, 0644);
 module_param(perfect_rules_hash_size, uint, 0644);
 module_param(transparent_mode, uint, 0644);
+module_param(disable_vlan_hash, uint, 0644);
 module_param(enable_debug, uint, 0644);
 module_param(enable_tx_capture, uint, 0644);
 module_param(enable_ip_defrag, uint, 0644);
@@ -350,6 +352,7 @@
 MODULE_PARM(min_num_slots, "i");
 MODULE_PARM(perfect_rules_hash_size, "i");
 MODULE_PARM(transparent_mode, "i");
+MODULE_PARM(disable_vlan_hash, "i");
 MODULE_PARM(enable_debug, "i");
 MODULE_PARM(enable_tx_capture, "i");
 MODULE_PARM(enable_ip_defrag, "i");
@@ -361,6 +364,8 @@
 MODULE_PARM_DESC(transparent_mode,
                 "0=standard Linux, 1=direct2pfring+transparent,
2=direct2pfring+non transparent"
                 "For 1 and 2 you need to use a PF_RING aware driver");
+MODULE_PARM_DESC(disable_vlan_hash,
+               "0=Include VLAN_ID in load-balancing hash function,
1=Disable VLAN_ID");
 MODULE_PARM_DESC(enable_debug, "Set to 1 to enable PF_RING debug tracing
into the syslog");
 MODULE_PARM_DESC(enable_tx_capture, "Set to 1 to capture outgoing
packets");
 MODULE_PARM_DESC(enable_ip_defrag,
@@ -1332,6 +1337,8 @@
     rlen += sprintf(buf + rlen, "Transparent mode    : %s\n",
                    (transparent_mode == standard_linux_path ? "Yes (mode
0)" :
                     (transparent_mode == driver2pf_ring_transparent ? "Yes
(mode 1)" : "No (mode 2)")));
+    rlen += sprintf(buf + rlen, "VLAN_ID in hash     : %s\n",
+                   (disable_vlan_hash ? "No" : "Yes"));
     rlen += sprintf(buf + rlen, "Total rings         : %d\n",
ring_table_size);
     rlen += sprintf(buf + rlen, "Total plugins       : %d\n",
plugin_registration_size);
   } else {
@@ -3897,26 +3904,63 @@
       break;

     case cluster_per_flow_2_tuple:
-      idx = hash_pkt_header(hdr, 0, 0, 1, 1, 0);
+      // If flag is set, mask the VLAN_ID from hashing
+      disable_vlan_hash
+      ?
+       ( idx = hash_pkt_header(hdr, 0, 0, 1, 1, 1) )
+      :
+       ( idx = hash_pkt_header(hdr, 0, 0, 1, 1, 0) );
       break;

     case cluster_per_flow_4_tuple:
-      idx = hash_pkt_header(hdr, 0, 0, 0, 1, 0);
+      // If flag is set, mask the VLAN_ID from hashing
+      disable_vlan_hash
+      ?
+        ( idx = hash_pkt_header(hdr, 0, 0, 0, 1, 1) )
+      :
+        ( idx = hash_pkt_header(hdr, 0, 0, 0, 1, 0) );
       break;

     case cluster_per_flow_tcp_5_tuple:
       if(((hdr->extended_hdr.parsed_pkt.tunnel.tunnel_id == NO_TUNNEL_ID) ?
          hdr->extended_hdr.parsed_pkt.l3_proto :
hdr->extended_hdr.parsed_pkt.tunnel.tunneled_proto) == IPPROTO_TCP)
-       idx = hash_pkt_header(hdr, 0, 0, 0, 0, 0); /* 5 tuple */
+
+       // If flag is set, mask the VLAN_ID from hashing
+        disable_vlan_hash
+       ?
+          ( idx = hash_pkt_header(hdr, 0, 0, 0, 0, 1) ) /* 5 tuple */
+       :
+          ( idx = hash_pkt_header(hdr, 0, 0, 0, 0, 0) ); /* "5 tuple" by
VLAN_ID */
       else
-       idx = hash_pkt_header(hdr, 0, 0, 1, 1, 0);   /* 2 tuple */
+        // If flag is set, mask the VLAN_ID from hashing
+       disable_vlan_hash
+       ?
+         ( idx = hash_pkt_header(hdr, 0, 0, 1, 1, 1) )   /* 2 tuple */
+       :
+         ( idx = hash_pkt_header(hdr, 0, 0, 1, 1, 0) );   /* "2 tuple" by
VLAN_ID */
       break;

-  case cluster_per_flow:
-  case cluster_per_flow_5_tuple:
-  default:
-    idx = hash_pkt_header(hdr, 0, 0, 0, 0, 0);
-    break;
+    case cluster_per_flow:
+      // If flag is set, mask the VLAN_ID from hashing
+      disable_vlan_hash
+       ?
+          ( idx = hash_pkt_header(hdr, 0, 0, 0, 0, 1) )
+       :
+         ( idx = hash_pkt_header(hdr, 0, 0, 0, 0, 0) );
+      break;
+
+    case cluster_per_flow_5_tuple:
+      // If flag is set, mask the VLAN_ID from hashing
+      disable_vlan_hash
+        ?
+          ( idx = hash_pkt_header(hdr, 0, 0, 0, 0, 1) )
+        :
+          ( idx = hash_pkt_header(hdr, 0, 0, 0, 0, 0) );
+      break;
+
+    default:
+      idx = hash_pkt_header(hdr, 0, 0, 0, 0, 0);
+      break;
   }

   return(idx % cluster_ptr->cluster.num_cluster_elements);
@@ -8652,6 +8696,8 @@
         enable_tx_capture ? "Yes [RX+TX]" : "No [RX only]");
   printk("[PF_RING] Transparent Mode %d\n",
         transparent_mode);
+  printk("[PF_RING] Ignore VLAN_IDs %d\n",
+        disable_vlan_hash);
   printk("[PF_RING] IP Defragment    %s\n",
         enable_ip_defrag ? "Yes" : "No");
   printk("[PF_RING] Initialized correctly\n");
_______________________________________________
Ntop-misc mailing list
[email protected]
http://listgateway.unipi.it/mailman/listinfo/ntop-misc

Reply via email to