From: Anjali Singhai Jain <anjali.singhai@intel.com>
To: netdev@vger.kernel.org
Cc: jesse@kernel.org, Anjali Singhai Jain <anjali.singhai@intel.com>,
Kiran Patil <kiran.patil@intel.com>
Subject: [PATCH v1 5/6] net: Refactor udp_offload and add Geneve port offload support
Date: Mon, 23 Nov 2015 13:02:58 -0800 [thread overview]
Message-ID: <1448312579-159544-6-git-send-email-anjali.singhai@intel.com> (raw)
In-Reply-To: <1448312579-159544-1-git-send-email-anjali.singhai@intel.com>
This patch moves the calls to ndo_add/del ops for vxlan tunnel
into udp_add/del_offload call. This way the ndo_add/del ops get called
for not only vxlan tunnels but for any udp based tunnel.
Signed-off-by: Kiran Patil <kiran.patil@intel.com>
Signed-off-by: Anjali Singhai Jain <anjali.singhai@intel.com>
---
drivers/net/geneve.c | 18 +++++++--------
drivers/net/vxlan.c | 35 ++++------------------------
include/net/protocol.h | 4 ++--
net/ipv4/fou.c | 15 ++++++------
net/ipv4/udp_offload.c | 63 +++++++++++++++++++++++++++++++++-----------------
5 files changed, 64 insertions(+), 71 deletions(-)
diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index de5c30c..9dc513a 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -372,15 +372,12 @@ static struct socket *geneve_create_sock(struct net *net, bool ipv6,
static void geneve_notify_add_rx_port(struct geneve_sock *gs)
{
struct sock *sk = gs->sock->sk;
- sa_family_t sa_family = sk->sk_family;
+ struct net *net = sock_net(sk);
int err;
- if (sa_family == AF_INET) {
- err = udp_add_offload(&gs->udp_offloads);
- if (err)
- pr_warn("geneve: udp_add_offload failed with status %d\n",
- err);
- }
+ err = udp_add_offload(&gs->udp_offloads, net);
+ if (err)
+ pr_warn("geneve: udp_add_offload failed with status %d\n", err);
}
static int geneve_hlen(struct genevehdr *gh)
@@ -505,6 +502,8 @@ static struct geneve_sock *geneve_socket_create(struct net *net, __be16 port,
/* Initialize the geneve udp offloads structure */
gs->udp_offloads.port = port;
+ gs->udp_offloads.tunnel_type = UDP_TUNNEL_GENEVE;
+ gs->udp_offloads.family = ipv6 ? AF_INET6 : AF_INET;
gs->udp_offloads.callbacks.gro_receive = geneve_gro_receive;
gs->udp_offloads.callbacks.gro_complete = geneve_gro_complete;
geneve_notify_add_rx_port(gs);
@@ -522,10 +521,9 @@ static struct geneve_sock *geneve_socket_create(struct net *net, __be16 port,
static void geneve_notify_del_rx_port(struct geneve_sock *gs)
{
struct sock *sk = gs->sock->sk;
- sa_family_t sa_family = sk->sk_family;
+ struct net *net = sock_net(sk);
- if (sa_family == AF_INET)
- udp_del_offload(&gs->udp_offloads);
+ udp_del_offload(&gs->udp_offloads, net);
}
static void __geneve_sock_release(struct geneve_sock *gs)
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 702f9be..231c17e 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -613,49 +613,22 @@ static int vxlan_gro_complete(struct sk_buff *skb, int nhoff,
/* Notify netdevs that UDP port started listening */
static void vxlan_notify_add_rx_port(struct vxlan_sock *vs)
{
- struct net_device *dev;
struct sock *sk = vs->sock->sk;
struct net *net = sock_net(sk);
- sa_family_t sa_family = vxlan_get_sk_family(vs);
- __be16 port = inet_sk(sk)->inet_sport;
int err;
- if (sa_family == AF_INET) {
- err = udp_add_offload(&vs->udp_offloads);
- if (err)
- pr_warn("vxlan: udp_add_offload failed with status %d\n", err);
- }
-
- rcu_read_lock();
- for_each_netdev_rcu(net, dev) {
- if (dev->netdev_ops->ndo_add_udp_tunnel_port)
- dev->netdev_ops->ndo_add_udp_tunnel_port(dev, sa_family,
- port,
- UDP_TUNNEL_VXLAN);
- }
- rcu_read_unlock();
+ err = udp_add_offload(&vs->udp_offloads, net);
+ if (err)
+ pr_warn("vxlan: udp_add_offload failed with status %d\n", err);
}
/* Notify netdevs that UDP port is no more listening */
static void vxlan_notify_del_rx_port(struct vxlan_sock *vs)
{
- struct net_device *dev;
struct sock *sk = vs->sock->sk;
struct net *net = sock_net(sk);
- sa_family_t sa_family = vxlan_get_sk_family(vs);
- __be16 port = inet_sk(sk)->inet_sport;
-
- rcu_read_lock();
- for_each_netdev_rcu(net, dev) {
- if (dev->netdev_ops->ndo_del_udp_tunnel_port)
- dev->netdev_ops->ndo_del_udp_tunnel_port(dev, sa_family,
- port,
- UDP_TUNNEL_VXLAN);
- }
- rcu_read_unlock();
- if (sa_family == AF_INET)
- udp_del_offload(&vs->udp_offloads);
+ udp_del_offload(&vs->udp_offloads, net);
}
/* Add new entry to forwarding table -- assumes lock held */
diff --git a/include/net/protocol.h b/include/net/protocol.h
index 738bfc6..16ee9b5 100644
--- a/include/net/protocol.h
+++ b/include/net/protocol.h
@@ -107,8 +107,8 @@ int inet_del_offload(const struct net_offload *prot, unsigned char num);
void inet_register_protosw(struct inet_protosw *p);
void inet_unregister_protosw(struct inet_protosw *p);
-int udp_add_offload(struct udp_offload *prot);
-void udp_del_offload(struct udp_offload *prot);
+int udp_add_offload(struct udp_offload *prot, struct net *net);
+void udp_del_offload(struct udp_offload *prot, struct net *net);
void udp_offload_get_port(struct net_device *dev);
diff --git a/net/ipv4/fou.c b/net/ipv4/fou.c
index e0fcbbb..4705590 100644
--- a/net/ipv4/fou.c
+++ b/net/ipv4/fou.c
@@ -411,9 +411,9 @@ static void fou_release(struct fou *fou)
{
struct socket *sock = fou->sock;
struct sock *sk = sock->sk;
+ struct net *net = sock_net(sk);
- if (sk->sk_family == AF_INET)
- udp_del_offload(&fou->udp_offloads);
+ udp_del_offload(&fou->udp_offloads, net);
list_del(&fou->list);
udp_tunnel_sock_release(sock);
@@ -484,6 +484,9 @@ static int fou_create(struct net *net, struct fou_cfg *cfg,
goto error;
}
+ fou->udp_offloads.tunnel_type = UDP_TUNNEL_UNSPEC;
+ fou->udp_offloads.family = cfg->udp_config.family;
+
fou->type = cfg->type;
udp_sk(sk)->encap_type = 1;
@@ -496,11 +499,9 @@ static int fou_create(struct net *net, struct fou_cfg *cfg,
sk->sk_allocation = GFP_ATOMIC;
- if (cfg->udp_config.family == AF_INET) {
- err = udp_add_offload(&fou->udp_offloads);
- if (err)
- goto error;
- }
+ err = udp_add_offload(&fou->udp_offloads, net);
+ if (err)
+ goto error;
err = fou_add_to_port_list(net, fou);
if (err)
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index 8597020..cf71bd0 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -241,18 +241,28 @@ out:
return segs;
}
-int udp_add_offload(struct udp_offload *uo)
+int udp_add_offload(struct udp_offload *uo, struct net *net)
{
- struct udp_offload_priv *new_offload = kzalloc(sizeof(*new_offload), GFP_ATOMIC);
-
- if (!new_offload)
- return -ENOMEM;
-
- new_offload->offload = uo;
+ struct udp_offload_priv *new_offload = NULL;
+ struct net_device *dev;
+
+ if (uo->family == AF_INET) {
+ new_offload = kzalloc(sizeof(*new_offload), GFP_ATOMIC);
+ if (!new_offload)
+ return -ENOMEM;
+ new_offload->offload = uo;
+ }
spin_lock(&udp_offload_lock);
- new_offload->next = udp_offload_base;
- rcu_assign_pointer(udp_offload_base, new_offload);
+ if (new_offload) {
+ new_offload->next = udp_offload_base;
+ rcu_assign_pointer(udp_offload_base, new_offload);
+ }
+ for_each_netdev_rcu(net, dev) {
+ if (dev->netdev_ops->ndo_add_udp_tunnel_port)
+ dev->netdev_ops->ndo_add_udp_tunnel_port(dev,
+ uo->family, uo->port, uo->tunnel_type);
+ }
spin_unlock(&udp_offload_lock);
return 0;
@@ -265,24 +275,35 @@ static void udp_offload_free_routine(struct rcu_head *head)
kfree(ou_priv);
}
-void udp_del_offload(struct udp_offload *uo)
+void udp_del_offload(struct udp_offload *uo, struct net *net)
{
- struct udp_offload_priv __rcu **head = &udp_offload_base;
- struct udp_offload_priv *uo_priv;
+ struct udp_offload_priv __rcu **head;
+ struct udp_offload_priv *uo_priv = NULL;
+ struct net_device *dev;
spin_lock(&udp_offload_lock);
- uo_priv = udp_deref_protected(*head);
- for (; uo_priv != NULL;
- uo_priv = udp_deref_protected(*head)) {
- if (uo_priv->offload == uo) {
- rcu_assign_pointer(*head,
- udp_deref_protected(uo_priv->next));
- goto unlock;
+ for_each_netdev_rcu(net, dev) {
+ if (dev->netdev_ops->ndo_add_udp_tunnel_port)
+ dev->netdev_ops->ndo_del_udp_tunnel_port(dev,
+ uo->family, uo->port, uo->tunnel_type);
+ }
+
+ if (uo->family == AF_INET) {
+ head = &udp_offload_base;
+ uo_priv = udp_deref_protected(*head);
+ for (; uo_priv != NULL;
+ uo_priv = udp_deref_protected(*head)) {
+ if (uo_priv->offload == uo) {
+ rcu_assign_pointer(*head,
+ udp_deref_protected(uo_priv->next));
+ goto unlock;
+ }
+ head = &uo_priv->next;
}
- head = &uo_priv->next;
+ pr_warn("udp_del_offload: didn't find offload for port %d\n",
+ ntohs(uo->port));
}
- pr_warn("udp_del_offload: didn't find offload for port %d\n", ntohs(uo->port));
unlock:
spin_unlock(&udp_offload_lock);
if (uo_priv)
--
1.8.1.4
next prev parent reply other threads:[~2015-11-23 20:46 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-23 21:02 [PATCH 0/6] Generalize udp based tunnels and add geneve offload Anjali Singhai Jain
2015-11-23 21:02 ` [PATCH v1 1/6] net: Generalize udp based tunnel offload Anjali Singhai Jain
2015-11-23 20:57 ` kbuild test robot
2015-11-23 20:58 ` kbuild test robot
2015-11-23 21:53 ` Tom Herbert
2015-11-23 22:49 ` Jesse Gross
2015-11-24 0:32 ` Singhai, Anjali
2015-11-24 0:38 ` Tom Herbert
2015-11-24 1:11 ` Jesse Brandeburg
2015-11-24 17:32 ` Tom Herbert
2015-11-24 17:43 ` Hannes Frederic Sowa
2015-11-24 17:52 ` Tom Herbert
2015-11-24 18:16 ` Hannes Frederic Sowa
2015-11-24 18:37 ` David Miller
2015-11-24 18:42 ` Hannes Frederic Sowa
2015-11-24 18:43 ` Tom Herbert
2015-11-30 3:22 ` David Miller
2015-11-30 21:42 ` Singhai, Anjali
2015-11-30 21:48 ` Tom Herbert
2015-12-01 3:51 ` David Miller
2015-12-01 3:48 ` David Miller
2015-12-01 6:33 ` Alexander Duyck
2015-11-30 3:21 ` David Miller
2015-11-30 21:33 ` Singhai, Anjali
2015-12-01 0:25 ` Jesse Gross
2015-12-01 1:02 ` Tom Herbert
2015-12-01 1:28 ` Jesse Gross
2015-12-01 5:26 ` Tom Herbert
2015-12-01 15:44 ` John W. Linville
2015-12-01 15:49 ` Hannes Frederic Sowa
2015-12-01 16:08 ` John W. Linville
2015-12-02 0:40 ` Singhai, Anjali
2015-12-02 3:50 ` Tom Herbert
2015-12-02 16:35 ` Hannes Frederic Sowa
2015-12-02 19:15 ` Tom Herbert
2015-12-02 23:35 ` John Fastabend
2015-12-03 0:15 ` Tom Herbert
2015-12-08 7:33 ` John Fastabend
2015-12-08 14:23 ` Jamal Hadi Salim
2015-12-08 15:10 ` Jamal Hadi Salim
2015-12-09 1:40 ` Thomas Graf
2015-12-09 5:45 ` Alexei Starovoitov
2015-12-09 12:58 ` Thomas Graf
2015-12-09 17:38 ` Alexei Starovoitov
2015-12-09 20:03 ` David Miller
2015-12-09 22:03 ` Thomas Graf
2015-12-09 22:21 ` David Miller
2015-12-09 22:25 ` Thomas Graf
2015-12-03 2:08 ` Alexei Starovoitov
2015-12-03 15:59 ` Hannes Frederic Sowa
2015-12-03 16:35 ` Andreas Schultz
2015-12-03 16:43 ` Hannes Frederic Sowa
2015-12-04 18:28 ` Tom Herbert
2015-12-04 19:54 ` John Fastabend
2015-12-04 19:59 ` Hannes Frederic Sowa
2015-12-04 20:02 ` Hannes Frederic Sowa
2015-12-04 20:06 ` David Miller
2015-12-04 20:13 ` Tom Herbert
2015-12-04 21:37 ` David Miller
2015-12-04 20:26 ` Hannes Frederic Sowa
2015-12-04 20:43 ` Tom Herbert
2015-12-04 21:11 ` Hannes Frederic Sowa
2015-12-04 20:44 ` Jesse Gross
2015-12-04 22:44 ` Alexander Duyck
2015-12-05 0:53 ` Tom Herbert
2015-12-05 5:45 ` Alexander Duyck
2015-12-05 6:49 ` David Miller
2015-12-05 8:24 ` Alexander Duyck
2015-12-05 17:53 ` Tom Herbert
2015-12-05 19:34 ` Alexander Duyck
2015-12-05 18:03 ` David Miller
2015-12-05 19:34 ` Alexander Duyck
2015-12-05 22:27 ` David Miller
2015-12-06 2:13 ` Alexander Duyck
2015-12-06 16:31 ` Tom Herbert
2015-12-06 18:44 ` Alexander Duyck
2015-12-06 21:30 ` Tom Herbert
2015-12-07 1:20 ` Alexander Duyck
2015-12-07 3:02 ` David Ahern
2015-12-07 16:20 ` Jesse Gross
2015-12-05 4:50 ` David Miller
2015-12-05 6:50 ` Alexander Duyck
2015-11-24 5:41 ` Alexander Duyck
2015-11-30 16:35 ` Tom Herbert
2015-11-30 21:53 ` Singhai, Anjali
2015-12-01 3:52 ` David Miller
2015-11-23 21:02 ` [PATCH v1 2/6] net: Add a generic udp_offload_get_port function Anjali Singhai Jain
2015-11-24 6:08 ` Alexander Duyck
2015-11-24 6:37 ` Alexander Duyck
2015-11-24 19:35 ` Singhai, Anjali
2015-11-23 21:02 ` [PATCH v1 3/6] i40e: Generalize the flow for udp based tunnels Anjali Singhai Jain
2015-11-23 21:02 ` [PATCH v1 4/6] i40e: Remove CONFIG_I40E_VXLAN Anjali Singhai Jain
2015-11-23 21:02 ` Anjali Singhai Jain [this message]
2015-11-23 21:02 ` [PATCH v1 6/6] i40e:Add geneve tunnel offload support Anjali Singhai Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448312579-159544-6-git-send-email-anjali.singhai@intel.com \
--to=anjali.singhai@intel.com \
--cc=jesse@kernel.org \
--cc=kiran.patil@intel.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).