Fix VLAN modification action in kernel switch.
authorJustin Pettit <jpettit@nicira.com>
Thu, 26 Jun 2008 06:22:39 +0000 (23:22 -0700)
committerJustin Pettit <jpettit@nicira.com>
Thu, 26 Jun 2008 06:22:39 +0000 (23:22 -0700)
A number of errors were uncovered when we actually tried playing with VLAN tags on real traffic.  This fixes endian, sk_buff, and other issues.  Unrelated to VLAN tagging, this also protects some printk calls with net_ratelimit.

datapath/datapath.c
datapath/forward.c

index 00dbac7c2249a508f88ac09855ce12cfb2607c69..840364480a5d7ed8755f5fc6daa5caaeb8765054 100644 (file)
@@ -443,10 +443,7 @@ static void
 do_port_input(struct net_bridge_port *p, struct sk_buff *skb) 
 {
        /* Push the Ethernet header back on. */
-       if (skb->protocol == htons(ETH_P_8021Q))
-               skb_push(skb, VLAN_ETH_HLEN);
-       else
-               skb_push(skb, ETH_HLEN);
+       skb_push(skb, ETH_HLEN);
        fwd_port_input(p->dp->chain, skb, p->port_no);
 }
 
index 4496720326b8792636a0bca95a3a1a97f87964f7..e0b07011fce42d6ba8deefc176ed7caff9ac6685 100644 (file)
@@ -87,10 +87,16 @@ void execute_actions(struct datapath *dp, struct sk_buff *skb,
                        max_len = ntohs(a->arg.output.max_len);
                } else {
                        if (!make_writable(&skb)) {
-                               printk("make_writable failed\n");
+                               if (net_ratelimit())
+                                   printk("make_writable failed\n");
                                break;
                        }
                        skb = execute_setter(skb, eth_proto, key, a);
+                       if (!skb) {
+                               if (net_ratelimit())
+                                       printk("execute_setter lost skb\n");
+                               return;
+                       }
                }
        }
        if (prev_port != -1)
@@ -199,17 +205,23 @@ static struct sk_buff *vlan_pull_tag(struct sk_buff *skb)
 static struct sk_buff *modify_vlan(struct sk_buff *skb, 
                const struct sw_flow_key *key, const struct ofp_action *a)
 {
-       uint16_t new_id = a->arg.vlan_id;
+       uint16_t new_id = ntohs(a->arg.vlan_id);
 
        if (new_id != OFP_VLAN_NONE) {
                if (key->dl_vlan != htons(OFP_VLAN_NONE)) {
                        /* Modify vlan id, but maintain other TCI values */
                        struct vlan_ethhdr *vh = vlan_eth_hdr(skb);
                        vh->h_vlan_TCI = (vh->h_vlan_TCI 
-                                       & ~(htons(VLAN_VID_MASK))) | htons(new_id);
+                                       & ~(htons(VLAN_VID_MASK))) | a->arg.vlan_id;
                } else  {
                        /* Add vlan header */
-                       skb = vlan_put_tag(skb, new_id);
+
+                       /* xxx The vlan_put_tag function, doesn't seem to work
+                        * xxx reliably when it attempts to use the hardware-accelerated
+                        * xxx version.  We'll directly use the software version
+                        * xxx until the problem can be diagnosed.
+                        */
+                       skb = __vlan_put_tag(skb, new_id);
                }
        } else  {
                /* Remove an existing vlan header if it exists */
@@ -603,7 +615,7 @@ make_writable(struct sk_buff **pskb)
        if (skb_shared(*pskb) || skb_cloned(*pskb))
                goto copy_skb;
 
-       return pskb_may_pull(*pskb, 64); /* FIXME? */
+       return pskb_may_pull(*pskb, 40); /* FIXME? */
 
 copy_skb:
        nskb = skb_copy(*pskb, GFP_ATOMIC);