get_skb_csum_pointers(skb, &csum_start, &csum_offset);
csum_start -= skb_headroom(skb);
- BUG_ON(csum_start >= skb_headlen(skb));
skb_copy_bits(skb, 0, to, csum_start);
}
}
- return queue_control_packets(dp, skb, upcall_info);
+ err = queue_control_packets(dp, skb, upcall_info);
+ if (err)
+ goto err;
+
+ return 0;
err_kfree_skb:
kfree_skb(skb);
if (unlikely(err))
goto err_kfree_skbs;
+ if (nla_attr_size(skb->len) > USHRT_MAX)
+ goto err_kfree_skbs;
+
len = sizeof(struct odp_header);
len += nla_total_size(skb->len);
len += nla_total_size(FLOW_BUFSIZE);
struct datapath *dp;
struct ethhdr *eth;
bool is_frag;
+ int len;
int err;
err = -EINVAL;
if (!a[ODP_PACKET_ATTR_PACKET] || !a[ODP_PACKET_ATTR_ACTIONS] ||
nla_len(a[ODP_PACKET_ATTR_PACKET]) < ETH_HLEN)
- goto exit;
+ goto err;
err = validate_actions(a[ODP_PACKET_ATTR_ACTIONS]);
if (err)
- goto exit;
+ goto err;
- packet = skb_clone(skb, GFP_KERNEL);
+ len = nla_len(a[ODP_PACKET_ATTR_PACKET]);
+ packet = __dev_alloc_skb(NET_IP_ALIGN + len, GFP_KERNEL);
err = -ENOMEM;
if (!packet)
- goto exit;
- packet->data = nla_data(a[ODP_PACKET_ATTR_PACKET]);
- packet->len = nla_len(a[ODP_PACKET_ATTR_PACKET]);
+ goto err;
+ skb_reserve(packet, NET_IP_ALIGN);
+
+ memcpy(__skb_put(packet, len), nla_data(a[ODP_PACKET_ATTR_PACKET]), len);
skb_reset_mac_header(packet);
eth = eth_hdr(packet);
else
packet->protocol = htons(ETH_P_802_2);
+ /* Initialize OVS_CB (it came from Netlink so might not be zeroed). */
+ memset(OVS_CB(packet), 0, sizeof(struct ovs_skb_cb));
+
err = flow_extract(packet, -1, &key, &is_frag);
if (err)
- goto exit;
-
- /* Initialize OVS_CB (it came from Netlink so might not be zeroed). */
- OVS_CB(packet)->vport = NULL;
- OVS_CB(packet)->flow = NULL;
- /* execute_actions() will reset tun_id to 0 anyhow. */
-#ifdef NEED_CSUM_NORMALIZE
- OVS_CB(packet)->ip_summed = OVS_CSUM_NONE;
-#endif
- vlan_copy_skb_tci(packet);
+ goto err_kfree_skb;
rcu_read_lock();
dp = get_dp(odp_header->dp_ifindex);
err = -ENODEV;
- if (dp)
- err = execute_actions(dp, packet, &key,
- nla_data(a[ODP_PACKET_ATTR_ACTIONS]),
- nla_len(a[ODP_PACKET_ATTR_ACTIONS]));
+ if (!dp)
+ goto err_unlock;
+ err = execute_actions(dp, packet, &key,
+ nla_data(a[ODP_PACKET_ATTR_ACTIONS]),
+ nla_len(a[ODP_PACKET_ATTR_ACTIONS]));
rcu_read_unlock();
+ return err;
-exit:
+err_unlock:
+ rcu_read_unlock();
+err_kfree_skb:
+ kfree_skb(packet);
+err:
return err;
}
return -EINVAL;
}
- return VERIFY_NUL_STRING(a[ODP_DP_ATTR_NAME], IFNAMSIZ - 1);
+ return CHECK_NUL_STRING(a[ODP_DP_ATTR_NAME], IFNAMSIZ - 1);
}
/* Called with genl_mutex and optionally with RTNL lock also. */
list_del(&dp->list_node);
dp_detach_port(get_vport_protected(dp, ODPP_LOCAL));
+ /* rtnl_unlock() will wait until all the references to devices that
+ * are pending unregistration have been dropped. We do it here to
+ * ensure that any internal devices (which contain DP pointers) are
+ * fully destroyed before freeing the datapath.
+ */
+ rtnl_unlock();
+
call_rcu(&dp->rcu, destroy_dp_rcu);
module_put(THIS_MODULE);
genl_notify(reply, genl_info_net(info), info->snd_pid,
dp_datapath_multicast_group.id, info->nlhdr, GFP_KERNEL);
- err = 0;
+
+ return 0;
exit_unlock:
rtnl_unlock();
static int odp_vport_cmd_validate(struct nlattr *a[ODP_VPORT_ATTR_MAX + 1])
{
- return VERIFY_NUL_STRING(a[ODP_VPORT_ATTR_NAME], IFNAMSIZ - 1);
+ return CHECK_NUL_STRING(a[ODP_VPORT_ATTR_NAME], IFNAMSIZ - 1);
}
/* Called with RTNL lock or RCU read lock. */