ovsdb-idl: Improve check in ovsdb_idl_row_is_orphan().
[openvswitch] / datapath / datapath.c
index 6a3b9ec70e4a42b39387d7c96af929be6c851573..b6aefe892156fb3cbc887bd3d897c78140574bb4 100644 (file)
@@ -71,6 +71,7 @@ static DEFINE_MUTEX(dp_mutex);
 #define MAINT_SLEEP_MSECS 1000
 
 static int new_nbp(struct datapath *, struct net_device *, int port_no);
+static void compute_ip_summed(struct sk_buff *skb);
 
 /* Must be called with rcu_read_lock or dp_mutex. */
 struct datapath *get_dp(int dp_idx)
@@ -81,7 +82,7 @@ struct datapath *get_dp(int dp_idx)
 }
 EXPORT_SYMBOL_GPL(get_dp);
 
-struct datapath *get_dp_locked(int dp_idx)
+static struct datapath *get_dp_locked(int dp_idx)
 {
        struct datapath *dp;
 
@@ -176,7 +177,7 @@ static void release_dp(struct kobject *kobj)
        kfree(dp);
 }
 
-struct kobj_type dp_ktype = {
+static struct kobj_type dp_ktype = {
        .release = release_dp
 };
 
@@ -325,7 +326,7 @@ static void release_nbp(struct kobject *kobj)
        kfree(p);
 }
 
-struct kobj_type brport_ktype = {
+static struct kobj_type brport_ktype = {
 #ifdef CONFIG_SYSFS
        .sysfs_ops = &brport_sysfs_ops,
 #endif
@@ -423,7 +424,7 @@ got_port_no:
        set_dp_devs_mtu(dp, dev);
        dp_sysfs_add_if(dp->ports[port_no]);
 
-       err = __put_user(port_no, &port.port);
+       err = __put_user(port_no, &portp->port);
 
 out_put:
        dev_put(dev);
@@ -529,6 +530,8 @@ void dp_process_received_packet(struct sk_buff *skb, struct net_bridge_port *p)
 
        WARN_ON_ONCE(skb_shared(skb));
 
+       compute_ip_summed(skb);
+
        /* BHs are off so we don't have to use get_cpu()/put_cpu() here. */
        stats = percpu_ptr(dp->stats_percpu, smp_processor_id());
 
@@ -606,7 +609,7 @@ int vswitch_skb_checksum_setup(struct sk_buff *skb)
        if (skb->protocol != htons(ETH_P_IP))
                goto out;
 
-       if (!skb_pull_up_to(skb, skb_network_header(skb) + 1))
+       if (!skb_pull_up_to(skb, skb_network_header(skb) + sizeof(struct iphdr)))
                goto out;
 
        iph = ip_hdr(skb);
@@ -670,7 +673,7 @@ out:
  * 4. CHECKSUM_UNNECESSARY (with proto_csum_blank true): This packet was
  *     generated locally by a Xen DomU and has a partial checksum.  If it is
  *     handled on this machine (Dom0 or DomU), then the checksum will not be
- *     computed.  If it goes off box, the checksum in the packet needs to
+ *     computed.  If it goes off box, the checksum in the packet needs to be
  *     completed.  Calling skb_checksum_setup converts this to CHECKSUM_HW
  *     (CHECKSUM_PARTIAL) so that the checksum can be completed.  In later
  *     kernels, this combination is replaced with CHECKSUM_PARTIAL.
@@ -696,11 +699,33 @@ out:
  * skb_forward_csum().  It is slightly different because we are only concerned
  * with bridging and not other types of forwarding and can get away with
  * slightly more optimal behavior.*/
+static void
+compute_ip_summed(struct sk_buff *skb)
+{
+       OVS_CB(skb)->ip_summed = skb->ip_summed;
+
+#ifdef CHECKSUM_HW
+       /* In theory this could be either CHECKSUM_PARTIAL or CHECKSUM_COMPLETE.
+        * However, we should only get CHECKSUM_PARTIAL packets from Xen, which
+        * uses some special fields to represent this (see below).  Since we
+        * can only make one type work, pick the one that actually happens in
+        * practice. */
+       if (skb->ip_summed == CHECKSUM_HW)
+               OVS_CB(skb)->ip_summed = CSUM_COMPLETE;
+#endif
+#if defined(CONFIG_XEN) && defined(HAVE_PROTO_DATA_VALID)
+       /* Xen has a special way of representing CHECKSUM_PARTIAL on older
+        * kernels. */
+       if (skb->proto_csum_blank)
+               OVS_CB(skb)->ip_summed = CSUM_PARTIAL;
+#endif
+}
+
 void
 forward_ip_summed(struct sk_buff *skb)
 {
 #ifdef CHECKSUM_HW
-       if (skb->ip_summed == CHECKSUM_HW)
+       if (OVS_CB(skb)->ip_summed == CSUM_COMPLETE)
                skb->ip_summed = CHECKSUM_NONE;
 #endif
 }
@@ -940,7 +965,7 @@ static int put_flow(struct datapath *dp, struct odp_flow_put __user *ufp)
        error = -EFAULT;
        if (copy_from_user(&uf, ufp, sizeof(struct odp_flow_put)))
                goto error;
-       uf.flow.key.reserved = 0;
+       memset(uf.flow.key.reserved, 0, sizeof uf.flow.key.reserved);
 
        table = rcu_dereference(dp->table);
        flow = dp_table_lookup(table, &uf.flow.key);
@@ -1085,7 +1110,7 @@ static int del_flow(struct datapath *dp, struct odp_flow __user *ufp)
        error = -EFAULT;
        if (copy_from_user(&uf, ufp, sizeof uf))
                goto error;
-       uf.key.reserved = 0;
+       memset(uf.key.reserved, 0, sizeof uf.key.reserved);
 
        flow = dp_table_lookup(table, &uf.key);
        error = -ENOENT;
@@ -1121,7 +1146,7 @@ static int query_flows(struct datapath *dp, const struct odp_flowvec *flowvec)
 
                if (__copy_from_user(&uf, ufp, sizeof uf))
                        return -EFAULT;
-               uf.key.reserved = 0;
+               memset(uf.key.reserved, 0, sizeof uf.key.reserved);
 
                flow = dp_table_lookup(table, &uf.key);
                if (!flow)