Commit df5dba8e authored by Jesse Gross's avatar Jesse Gross Committed by David S. Miller

geneve: Remove socket hash table.

The hash table for open Geneve ports is used only on creation and
deletion time. It is not performance critical and is not likely to
grow to a large number of items. Therefore, this can be changed
to use a simple linked list.
Signed-off-by: default avatarJesse Gross <jesse@nicira.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 829a3ada
...@@ -68,7 +68,7 @@ struct geneve_sock; ...@@ -68,7 +68,7 @@ struct geneve_sock;
typedef void (geneve_rcv_t)(struct geneve_sock *gs, struct sk_buff *skb); typedef void (geneve_rcv_t)(struct geneve_sock *gs, struct sk_buff *skb);
struct geneve_sock { struct geneve_sock {
struct hlist_node hlist; struct list_head list;
geneve_rcv_t *rcv; geneve_rcv_t *rcv;
void *rcv_data; void *rcv_data;
struct socket *sock; struct socket *sock;
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
#include <linux/if_vlan.h> #include <linux/if_vlan.h>
#include <linux/hash.h>
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <net/arp.h> #include <net/arp.h>
...@@ -54,12 +53,9 @@ ...@@ -54,12 +53,9 @@
/* Protects sock_list and refcounts. */ /* Protects sock_list and refcounts. */
static DEFINE_MUTEX(geneve_mutex); static DEFINE_MUTEX(geneve_mutex);
#define PORT_HASH_BITS 8
#define PORT_HASH_SIZE (1<<PORT_HASH_BITS)
/* per-network namespace private data for this module */ /* per-network namespace private data for this module */
struct geneve_net { struct geneve_net {
struct hlist_head sock_list[PORT_HASH_SIZE]; struct list_head sock_list;
}; };
static int geneve_net_id; static int geneve_net_id;
...@@ -69,19 +65,13 @@ static inline struct genevehdr *geneve_hdr(const struct sk_buff *skb) ...@@ -69,19 +65,13 @@ static inline struct genevehdr *geneve_hdr(const struct sk_buff *skb)
return (struct genevehdr *)(udp_hdr(skb) + 1); return (struct genevehdr *)(udp_hdr(skb) + 1);
} }
static struct hlist_head *gs_head(struct net *net, __be16 port)
{
struct geneve_net *gn = net_generic(net, geneve_net_id);
return &gn->sock_list[hash_32(ntohs(port), PORT_HASH_BITS)];
}
/* Find geneve socket based on network namespace and UDP port */ /* Find geneve socket based on network namespace and UDP port */
static struct geneve_sock *geneve_find_sock(struct net *net, __be16 port) static struct geneve_sock *geneve_find_sock(struct net *net, __be16 port)
{ {
struct geneve_net *gn = net_generic(net, geneve_net_id);
struct geneve_sock *gs; struct geneve_sock *gs;
hlist_for_each_entry(gs, gs_head(net, port), hlist) { list_for_each_entry(gs, &gn->sock_list, list) {
if (inet_sk(gs->sock->sk)->inet_sport == port) if (inet_sk(gs->sock->sk)->inet_sport == port)
return gs; return gs;
} }
...@@ -339,6 +329,7 @@ static struct geneve_sock *geneve_socket_create(struct net *net, __be16 port, ...@@ -339,6 +329,7 @@ static struct geneve_sock *geneve_socket_create(struct net *net, __be16 port,
geneve_rcv_t *rcv, void *data, geneve_rcv_t *rcv, void *data,
bool ipv6) bool ipv6)
{ {
struct geneve_net *gn = net_generic(net, geneve_net_id);
struct geneve_sock *gs; struct geneve_sock *gs;
struct socket *sock; struct socket *sock;
struct udp_tunnel_sock_cfg tunnel_cfg; struct udp_tunnel_sock_cfg tunnel_cfg;
...@@ -371,7 +362,7 @@ static struct geneve_sock *geneve_socket_create(struct net *net, __be16 port, ...@@ -371,7 +362,7 @@ static struct geneve_sock *geneve_socket_create(struct net *net, __be16 port,
tunnel_cfg.encap_destroy = NULL; tunnel_cfg.encap_destroy = NULL;
setup_udp_tunnel_sock(net, sock, &tunnel_cfg); setup_udp_tunnel_sock(net, sock, &tunnel_cfg);
hlist_add_head(&gs->hlist, gs_head(net, port)); list_add(&gs->list, &gn->sock_list);
return gs; return gs;
} }
...@@ -407,7 +398,7 @@ void geneve_sock_release(struct geneve_sock *gs) ...@@ -407,7 +398,7 @@ void geneve_sock_release(struct geneve_sock *gs)
if (--gs->refcnt) if (--gs->refcnt)
goto unlock; goto unlock;
hlist_del(&gs->hlist); list_del(&gs->list);
geneve_notify_del_rx_port(gs); geneve_notify_del_rx_port(gs);
udp_tunnel_sock_release(gs->sock); udp_tunnel_sock_release(gs->sock);
kfree_rcu(gs, rcu); kfree_rcu(gs, rcu);
...@@ -420,17 +411,14 @@ EXPORT_SYMBOL_GPL(geneve_sock_release); ...@@ -420,17 +411,14 @@ EXPORT_SYMBOL_GPL(geneve_sock_release);
static __net_init int geneve_init_net(struct net *net) static __net_init int geneve_init_net(struct net *net)
{ {
struct geneve_net *gn = net_generic(net, geneve_net_id); struct geneve_net *gn = net_generic(net, geneve_net_id);
unsigned int h;
for (h = 0; h < PORT_HASH_SIZE; ++h) INIT_LIST_HEAD(&gn->sock_list);
INIT_HLIST_HEAD(&gn->sock_list[h]);
return 0; return 0;
} }
static struct pernet_operations geneve_net_ops = { static struct pernet_operations geneve_net_ops = {
.init = geneve_init_net, .init = geneve_init_net,
.exit = NULL,
.id = &geneve_net_id, .id = &geneve_net_id,
.size = sizeof(struct geneve_net), .size = sizeof(struct geneve_net),
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment