Commit 2e0b26e1 authored by pravin shelar's avatar pravin shelar Committed by David S. Miller

geneve: Optimize geneve device lookup.

Rather than comparing 64-bit tunnel-id, compare tunnel vni
which is 24-bit id. This also save conversion from vni
to tunnel id on each tunnel packet receive.
Signed-off-by: default avatarPravin B Shelar <pshelar@ovn.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bcceeec3
...@@ -103,6 +103,17 @@ static void tunnel_id_to_vni(__be64 tun_id, __u8 *vni) ...@@ -103,6 +103,17 @@ static void tunnel_id_to_vni(__be64 tun_id, __u8 *vni)
#endif #endif
} }
static bool eq_tun_id_and_vni(u8 *tun_id, u8 *vni)
{
#ifdef __BIG_ENDIAN
return (vni[0] == tun_id[2]) &&
(vni[1] == tun_id[1]) &&
(vni[2] == tun_id[0]);
#else
return !memcmp(vni, &tun_id[5], 3);
#endif
}
static sa_family_t geneve_get_sk_family(struct geneve_sock *gs) static sa_family_t geneve_get_sk_family(struct geneve_sock *gs)
{ {
return gs->sock->sk->sk_family; return gs->sock->sk->sk_family;
...@@ -111,7 +122,6 @@ static sa_family_t geneve_get_sk_family(struct geneve_sock *gs) ...@@ -111,7 +122,6 @@ static sa_family_t geneve_get_sk_family(struct geneve_sock *gs)
static struct geneve_dev *geneve_lookup(struct geneve_sock *gs, static struct geneve_dev *geneve_lookup(struct geneve_sock *gs,
__be32 addr, u8 vni[]) __be32 addr, u8 vni[])
{ {
__be64 id = vni_to_tunnel_id(vni);
struct hlist_head *vni_list_head; struct hlist_head *vni_list_head;
struct geneve_dev *geneve; struct geneve_dev *geneve;
__u32 hash; __u32 hash;
...@@ -120,7 +130,7 @@ static struct geneve_dev *geneve_lookup(struct geneve_sock *gs, ...@@ -120,7 +130,7 @@ static struct geneve_dev *geneve_lookup(struct geneve_sock *gs,
hash = geneve_net_vni_hash(vni); hash = geneve_net_vni_hash(vni);
vni_list_head = &gs->vni_list[hash]; vni_list_head = &gs->vni_list[hash];
hlist_for_each_entry_rcu(geneve, vni_list_head, hlist) { hlist_for_each_entry_rcu(geneve, vni_list_head, hlist) {
if (!memcmp(&id, &geneve->info.key.tun_id, sizeof(id)) && if (eq_tun_id_and_vni((u8 *)&geneve->info.key.tun_id, vni) &&
addr == geneve->info.key.u.ipv4.dst) addr == geneve->info.key.u.ipv4.dst)
return geneve; return geneve;
} }
...@@ -131,7 +141,6 @@ static struct geneve_dev *geneve_lookup(struct geneve_sock *gs, ...@@ -131,7 +141,6 @@ static struct geneve_dev *geneve_lookup(struct geneve_sock *gs,
static struct geneve_dev *geneve6_lookup(struct geneve_sock *gs, static struct geneve_dev *geneve6_lookup(struct geneve_sock *gs,
struct in6_addr addr6, u8 vni[]) struct in6_addr addr6, u8 vni[])
{ {
__be64 id = vni_to_tunnel_id(vni);
struct hlist_head *vni_list_head; struct hlist_head *vni_list_head;
struct geneve_dev *geneve; struct geneve_dev *geneve;
__u32 hash; __u32 hash;
...@@ -140,7 +149,7 @@ static struct geneve_dev *geneve6_lookup(struct geneve_sock *gs, ...@@ -140,7 +149,7 @@ static struct geneve_dev *geneve6_lookup(struct geneve_sock *gs,
hash = geneve_net_vni_hash(vni); hash = geneve_net_vni_hash(vni);
vni_list_head = &gs->vni_list[hash]; vni_list_head = &gs->vni_list[hash];
hlist_for_each_entry_rcu(geneve, vni_list_head, hlist) { hlist_for_each_entry_rcu(geneve, vni_list_head, hlist) {
if (!memcmp(&id, &geneve->info.key.tun_id, sizeof(id)) && if (eq_tun_id_and_vni((u8 *)&geneve->info.key.tun_id, vni) &&
ipv6_addr_equal(&addr6, &geneve->info.key.u.ipv6.dst)) ipv6_addr_equal(&addr6, &geneve->info.key.u.ipv6.dst))
return geneve; return geneve;
} }
......
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