From patchwork Fri Mar 15 17:38:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Gross X-Patchwork-Id: 228123 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B540F2C009C for ; Sat, 16 Mar 2013 04:39:19 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754248Ab3CORjP (ORCPT ); Fri, 15 Mar 2013 13:39:15 -0400 Received: from na3sys009aog104.obsmtp.com ([74.125.149.73]:35052 "HELO na3sys009aog104.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751901Ab3CORjJ (ORCPT ); Fri, 15 Mar 2013 13:39:09 -0400 Received: from mail-ob0-f200.google.com ([209.85.214.200]) (using TLSv1) by na3sys009aob104.postini.com ([74.125.148.12]) with SMTP ID DSNKUUNcvaC7Fz4bKqNj1YxG1EbVyP1vVLxG@postini.com; Fri, 15 Mar 2013 10:39:09 PDT Received: by mail-ob0-f200.google.com with SMTP id un3so18206508obb.3 for ; Fri, 15 Mar 2013 10:39:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=ZKI55VNo3wdHiGpicdUNZXDm8K3l7CGVh6boe/mdrys=; b=ZJT2a0+TmJT+vCXiPwLiuo8lZO9WhFFwh7SWSwcSmFEfWxQFUOZTahih9HvB0KihlD wScrhbFRIaQR3aeDORjezzQEFM6FqiSecRgTRQk0MQTuZFhXPEbZWD22EuT6L/aamYkN jPqbw1NKpz96Fgty6XfLob/Nz915CqlT84UWTni01tyGUvDf9jDQruuzywpZ7BZjdAbc qdU+4KT+sDBK+MhXR0fYwh6VSI9pUqPcbsWHBplUqFOhUcvFEcJtO3NgD3UMtubsu8Iz I+rMgUGZON/5VIRq32jzyKr9Miy7pQqA7WeLfF3f4pglcEU/LVlCXKsgZsK/8MtzQ6vi FHIg== X-Received: by 10.60.27.9 with SMTP id p9mr3386874oeg.72.1363369148922; Fri, 15 Mar 2013 10:39:08 -0700 (PDT) X-Received: by 10.60.27.9 with SMTP id p9mr3386867oeg.72.1363369148800; Fri, 15 Mar 2013 10:39:08 -0700 (PDT) Received: from ubuntu.localdomain (c-24-7-88-182.hsd1.ca.comcast.net. [24.7.88.182]) by mx.google.com with ESMTPS id j4sm2905572oea.3.2013.03.15.10.39.06 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Mar 2013 10:39:08 -0700 (PDT) From: Jesse Gross To: David Miller Cc: netdev@vger.kernel.org, dev@openvswitch.org, Ben Pfaff , Romain Lenglet , Jesse Gross Subject: [PATCH net-next 5/5] openvswitch: Allow OVS_USERSPACE_ATTR_USERDATA to be variable length. Date: Fri, 15 Mar 2013 10:38:51 -0700 Message-Id: <1363369131-16830-6-git-send-email-jesse@nicira.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1363369131-16830-1-git-send-email-jesse@nicira.com> References: <1363369131-16830-1-git-send-email-jesse@nicira.com> X-Gm-Message-State: ALoCoQnxk13E0BTM0Dh8lW207j+5/LpdbXBq3CtyJ4x/oQs0GnYgitE31crtI6BI6H7Y9OtpumoK95sWB9pdJjQ9nUf+yCBVdkVjfQUEFpLoqJ5rvUuv4oUVp27H5ExJP4CbpnXxqKycK822HfmRGhV1YombYbcpD2gpcXEGew52wCn2NlKJsSk= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ben Pfaff Until now, the optional OVS_USERSPACE_ATTR_USERDATA attribute had to be exactly 64 bits long, if it was present. However, 64 bits is not enough space to associate as much information with a flow as would be convenient for some userspace features now under development. This commit generalizes the attribute, allowing it to be any length. This generalization is backward-compatible: if userspace only uses 64-bit attributes, then it will not see any change in behavior. CC: Romain Lenglet Signed-off-by: Ben Pfaff Signed-off-by: Jesse Gross --- include/linux/openvswitch.h | 11 ++++++----- net/openvswitch/datapath.c | 11 ++++++----- net/openvswitch/datapath.h | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/linux/openvswitch.h b/include/linux/openvswitch.h index 99e6414..67d6c7b 100644 --- a/include/linux/openvswitch.h +++ b/include/linux/openvswitch.h @@ -127,7 +127,8 @@ enum ovs_packet_cmd { * for %OVS_PACKET_CMD_EXECUTE. It has nested %OVS_ACTION_ATTR_* attributes. * @OVS_PACKET_ATTR_USERDATA: Present for an %OVS_PACKET_CMD_ACTION * notification if the %OVS_ACTION_ATTR_USERSPACE action specified an - * %OVS_USERSPACE_ATTR_USERDATA attribute. + * %OVS_USERSPACE_ATTR_USERDATA attribute, with the same length and content + * specified there. * * These attributes follow the &struct ovs_header within the Generic Netlink * payload for %OVS_PACKET_* commands. @@ -137,7 +138,7 @@ enum ovs_packet_attr { OVS_PACKET_ATTR_PACKET, /* Packet data. */ OVS_PACKET_ATTR_KEY, /* Nested OVS_KEY_ATTR_* attributes. */ OVS_PACKET_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */ - OVS_PACKET_ATTR_USERDATA, /* u64 OVS_ACTION_ATTR_USERSPACE arg. */ + OVS_PACKET_ATTR_USERDATA, /* OVS_ACTION_ATTR_USERSPACE arg. */ __OVS_PACKET_ATTR_MAX }; @@ -389,13 +390,13 @@ enum ovs_sample_attr { * enum ovs_userspace_attr - Attributes for %OVS_ACTION_ATTR_USERSPACE action. * @OVS_USERSPACE_ATTR_PID: u32 Netlink PID to which the %OVS_PACKET_CMD_ACTION * message should be sent. Required. - * @OVS_USERSPACE_ATTR_USERDATA: If present, its u64 argument is copied to the - * %OVS_PACKET_CMD_ACTION message as %OVS_PACKET_ATTR_USERDATA, + * @OVS_USERSPACE_ATTR_USERDATA: If present, its variable-length argument is + * copied to the %OVS_PACKET_CMD_ACTION message as %OVS_PACKET_ATTR_USERDATA. */ enum ovs_userspace_attr { OVS_USERSPACE_ATTR_UNSPEC, OVS_USERSPACE_ATTR_PID, /* u32 Netlink PID to receive upcalls. */ - OVS_USERSPACE_ATTR_USERDATA, /* u64 optional user-specified cookie. */ + OVS_USERSPACE_ATTR_USERDATA, /* Optional user-specified cookie. */ __OVS_USERSPACE_ATTR_MAX }; diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index f9d2438..96cd5b2 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -370,8 +370,8 @@ static int queue_userspace_packet(struct net *net, int dp_ifindex, len = sizeof(struct ovs_header); len += nla_total_size(skb->len); len += nla_total_size(FLOW_BUFSIZE); - if (upcall_info->cmd == OVS_PACKET_CMD_ACTION) - len += nla_total_size(8); + if (upcall_info->userdata) + len += NLA_ALIGN(upcall_info->userdata->nla_len); user_skb = genlmsg_new(len, GFP_ATOMIC); if (!user_skb) { @@ -388,8 +388,9 @@ static int queue_userspace_packet(struct net *net, int dp_ifindex, nla_nest_end(user_skb, nla); if (upcall_info->userdata) - nla_put_u64(user_skb, OVS_PACKET_ATTR_USERDATA, - nla_get_u64(upcall_info->userdata)); + __nla_put(user_skb, OVS_PACKET_ATTR_USERDATA, + nla_len(upcall_info->userdata), + nla_data(upcall_info->userdata)); nla = __nla_reserve(user_skb, OVS_PACKET_ATTR_PACKET, skb->len); @@ -544,7 +545,7 @@ static int validate_userspace(const struct nlattr *attr) { static const struct nla_policy userspace_policy[OVS_USERSPACE_ATTR_MAX + 1] = { [OVS_USERSPACE_ATTR_PID] = {.type = NLA_U32 }, - [OVS_USERSPACE_ATTR_USERDATA] = {.type = NLA_U64 }, + [OVS_USERSPACE_ATTR_USERDATA] = {.type = NLA_UNSPEC }, }; struct nlattr *a[OVS_USERSPACE_ATTR_MAX + 1]; int error; diff --git a/net/openvswitch/datapath.h b/net/openvswitch/datapath.h index 031dfbf..9125ad5 100644 --- a/net/openvswitch/datapath.h +++ b/net/openvswitch/datapath.h @@ -119,7 +119,7 @@ struct ovs_skb_cb { * struct dp_upcall - metadata to include with a packet to send to userspace * @cmd: One of %OVS_PACKET_CMD_*. * @key: Becomes %OVS_PACKET_ATTR_KEY. Must be nonnull. - * @userdata: If nonnull, its u64 value is extracted and passed to userspace as + * @userdata: If nonnull, its variable-length value is passed to userspace as * %OVS_PACKET_ATTR_USERDATA. * @pid: Netlink PID to which packet should be sent. If @pid is 0 then no * packet is sent and the packet is accounted in the datapath's @n_lost