From patchwork Wed Jul 24 18:00:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pravin B Shelar X-Patchwork-Id: 261487 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 656162C007C for ; Thu, 25 Jul 2013 04:00:45 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752733Ab3GXSAl (ORCPT ); Wed, 24 Jul 2013 14:00:41 -0400 Received: from na3sys009aog111.obsmtp.com ([74.125.149.205]:37982 "HELO na3sys009aog111.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752646Ab3GXSAk (ORCPT ); Wed, 24 Jul 2013 14:00:40 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]) (using TLSv1) by na3sys009aob111.postini.com ([74.125.148.12]) with SMTP ID DSNKUfAWR9l+UzjLet6u9kCKxxQnPSfShcdz@postini.com; Wed, 24 Jul 2013 11:00:40 PDT Received: by mail-pd0-f172.google.com with SMTP id z10so664966pdj.31 for ; Wed, 24 Jul 2013 11:00:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=PVFNcTb0B0YQG658TybEFxlXPvSKaWnjfRtgltSpjC4=; b=SDmvv/qIHCIqeA3WeG7jR70Uf7uBzFTEoXaRUpEWkjwjZEQJtRCZzOEEzlF0mO5IZi y/pbFIUTe0F/3qVq98tzs6Huf/iC5J4o+M+nCO7GwPXJDjt2X8gZ0RHfq8+HH3I5vNVc wBLqNvVJn0viBmD/yyBVST1rlkgoVK2fhFpDdGocoMJHVaRQxJGQK7+qAm0SX8Izwels oJBgEWECRprl0vuAOVfdEOMV0kmvxxFFI/a3kXFB3MYZqp4won41SLYcKMGDr6iZEU74 xch6ckBzvmS1QcK8HyEJQe/SCh8qNSorTmfRN0k3ISss1MBp+MmF568C1+S9G9ZJUQxI LPKQ== X-Received: by 10.68.114.131 with SMTP id jg3mr39738126pbb.111.1374688839705; Wed, 24 Jul 2013 11:00:39 -0700 (PDT) X-Received: by 10.68.114.131 with SMTP id jg3mr39738122pbb.111.1374688839632; Wed, 24 Jul 2013 11:00:39 -0700 (PDT) Received: from localhost ([75.98.92.113]) by mx.google.com with ESMTPSA id bb1sm39325536pbc.10.2013.07.24.11.00.38 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Wed, 24 Jul 2013 11:00:39 -0700 (PDT) From: Pravin B Shelar To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, Pravin B Shelar Subject: [PATCH net-next v3 2/6] vxlan: Extend vxlan handlers for openvswitch. Date: Wed, 24 Jul 2013 11:00:37 -0700 Message-Id: <1374688837-14275-1-git-send-email-pshelar@nicira.com> X-Mailer: git-send-email 1.8.2.135.g7b592fa X-Gm-Message-State: ALoCoQnpA9g2QGizHy0tgGEvd0HNzlc2UTrYEgBDOnI0jflAhds3uFl5eTHNIml3wLl0/B4lQMPgsbo8XoYQ82q9zGGtJhsQw6SUqa6vJtjOxPynjhfU3jAulBS7Zf5iAtSOYFGPPVeV0YssyP6R/sw858/B1r9rMGEgmJaSvrS4rAie0iUkW14= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Following patch adds data and priority fields to vxlan handlers and export vxlan handler api. vh->data is required to store private data per vxlan handler. vh->priority allows ovs to assign lower priority for ovs vxlan handler. So that vxlan device modules gets to look at vxlan packet before ovs. Signed-off-by: Pravin B Shelar --- drivers/net/vxlan.c | 83 +++++++++++++++++++++++++-------------------------- include/net/vxlan.h | 40 ++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 include/net/vxlan.h diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index f351b7c..9deb86e 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -41,13 +41,12 @@ #include #include #include +#include #define VXLAN_VERSION "0.1" #define PORT_HASH_BITS 8 #define PORT_HASH_SIZE (1<dst_port, vxlan_rcv); + vh = vs_handler_add(vs, vxlan->dst_port, vxlan_rcv, NULL, 0, false); vxlan_vh_add_dev(vh, vxlan); } else { /* otherwise make new socket outside of RTNL */ @@ -1660,34 +1640,51 @@ static void vh_del_work(struct work_struct *work) static struct vxlan_handler *vs_handler_add(struct vxlan_sock *vs, __be16 portno, - vxlan_rcv_t *rcv) + vxlan_rcv_t *rcv, + void *data, + int priority, + bool force_create) { - struct vxlan_handler *vh; + struct vxlan_handler *vh, *new; /* Try existing vxlan hanlders for this socket. */ list_for_each_entry(vh, &vs->handler_list, node) { if (vh->rcv == rcv) { + if (force_create) + return ERR_PTR(-EEXIST); + atomic_inc(&vh->refcnt); return vh; } } - vh = kzalloc(sizeof(*vh), GFP_KERNEL); - if (!vh) { + new = kzalloc(sizeof(*new), GFP_KERNEL); + if (!new) { vxlan_socket_del(vs); return ERR_PTR(-ENOMEM); } - vh->rcv = rcv; - vh->vs = vs; - atomic_set(&vh->refcnt, 1); - INIT_WORK(&vh->del_work, vh_del_work); + new->rcv = rcv; + new->vs = vs; + atomic_set(&new->refcnt, 1); + INIT_WORK(&new->del_work, vh_del_work); + new->data = data; + new->priority = priority; - list_add_rcu(&vh->node, &vs->handler_list); - return vh; + list_for_each_entry(vh, &vs->handler_list, node) { + if (vh->priority > priority) { + list_add_tail_rcu(&new->node, &vh->node); + return new; + } + } + + list_add_tail_rcu(&new->node, &vs->handler_list); + + return new; } -static struct vxlan_handler *vxlan_handler_add(struct net *net, - __be16 portno, vxlan_rcv_t *rcv) +struct vxlan_handler *vxlan_handler_add(struct net *net, + __be16 portno, vxlan_rcv_t *rcv, + void *data, int priority, bool force_create) { struct vxlan_net *vn = net_generic(net, vxlan_net_id); struct vxlan_handler *vh; @@ -1704,25 +1701,27 @@ static struct vxlan_handler *vxlan_handler_add(struct net *net, vh = ERR_PTR(-ENOENT); goto out; } - vh = vs_handler_add(vs, portno, rcv); + vh = vs_handler_add(vs, portno, rcv, data, priority, force_create); out: mutex_unlock(&vn->sock_lock); return vh; } +EXPORT_SYMBOL_GPL(vxlan_handler_add); static void vxlan_handler_hold(struct vxlan_handler *vh) { atomic_inc(&vh->refcnt); } -static void vxlan_handler_put(struct vxlan_handler *vh) +void vxlan_handler_put(struct vxlan_handler *vh) { BUG_ON(!vh->vs); if (atomic_dec_and_test(&vh->refcnt)) queue_work(vxlan_wq, &vh->del_work); } +EXPORT_SYMBOL_GPL(vxlan_handler_put); static void vxlan_vh_add_dev(struct vxlan_handler *vh, struct vxlan_dev *vxlan) { @@ -1746,7 +1745,7 @@ static void vxlan_handler_work(struct work_struct *work) __be16 port = vxlan->dst_port; struct vxlan_handler *vh = NULL; - vh = vxlan_handler_add(net, port, vxlan_rcv); + vh = vxlan_handler_add(net, port, vxlan_rcv, NULL, 0, false); vxlan_vh_add_dev(vh, vxlan); dev_put(dev); } diff --git a/include/net/vxlan.h b/include/net/vxlan.h new file mode 100644 index 0000000..5794bf7 --- /dev/null +++ b/include/net/vxlan.h @@ -0,0 +1,40 @@ +#ifndef __NET_VXLAN_H +#define __NET_VXLAN_H 1 + +#include +#include +#include + +#define VNI_HASH_BITS 10 +#define VNI_HASH_SIZE (1<