From 085a41cb35dc1d396cf2d5fd833696072d84c040 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 14 Oct 2011 15:33:49 -0700 Subject: [PATCH] datapath: Simplify tnl_find_port(). It's only called when we want a best-match now, so there's no need to pass in any flags that indicate the desired type of match. Signed-off-by: Ben Pfaff Acked-by: Jesse Gross --- datapath/tunnel.c | 60 +++++++++++++++++++---------------------- datapath/tunnel.h | 1 - datapath/vport-capwap.c | 4 +-- datapath/vport-gre.c | 8 +++--- 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/datapath/tunnel.c b/datapath/tunnel.c index e97b9f21..38004e9e 100644 --- a/datapath/tunnel.c +++ b/datapath/tunnel.c @@ -260,42 +260,36 @@ struct vport *tnl_find_port(__be32 saddr, __be32 daddr, __be64 key, lookup.saddr = saddr; lookup.daddr = daddr; - if (tunnel_type & TNL_T_KEY_EXACT) { - lookup.in_key = key; - lookup.tunnel_type = tunnel_type & ~TNL_T_KEY_MATCH; - - if (key_local_remote_ports) { - vport = port_table_lookup(&lookup, mutable); - if (vport) - return vport; - } - - if (key_remote_ports) { - lookup.saddr = 0; - vport = port_table_lookup(&lookup, mutable); - if (vport) - return vport; - - lookup.saddr = saddr; - } + /* First try for exact match on in_key. */ + lookup.in_key = key; + lookup.tunnel_type = tunnel_type | TNL_T_KEY_EXACT; + if (key_local_remote_ports) { + vport = port_table_lookup(&lookup, mutable); + if (vport) + return vport; } + if (key_remote_ports) { + lookup.saddr = 0; + vport = port_table_lookup(&lookup, mutable); + if (vport) + return vport; - if (tunnel_type & TNL_T_KEY_MATCH) { - lookup.in_key = 0; - lookup.tunnel_type = tunnel_type & ~TNL_T_KEY_EXACT; - - if (local_remote_ports) { - vport = port_table_lookup(&lookup, mutable); - if (vport) - return vport; - } + lookup.saddr = saddr; + } - if (remote_ports) { - lookup.saddr = 0; - vport = port_table_lookup(&lookup, mutable); - if (vport) - return vport; - } + /* Then try matches that wildcard in_key. */ + lookup.in_key = 0; + lookup.tunnel_type = tunnel_type | TNL_T_KEY_MATCH; + if (local_remote_ports) { + vport = port_table_lookup(&lookup, mutable); + if (vport) + return vport; + } + if (remote_ports) { + lookup.saddr = 0; + vport = port_table_lookup(&lookup, mutable); + if (vport) + return vport; } return NULL; diff --git a/datapath/tunnel.h b/datapath/tunnel.h index e7bafbc9..8d20c77b 100644 --- a/datapath/tunnel.h +++ b/datapath/tunnel.h @@ -33,7 +33,6 @@ /* These flags are only needed when calling tnl_find_port(). */ #define TNL_T_KEY_EXACT (1 << 10) #define TNL_T_KEY_MATCH (1 << 11) -#define TNL_T_KEY_EITHER (TNL_T_KEY_EXACT | TNL_T_KEY_MATCH) /* Private flags not exposed to userspace in this form. */ #define TNL_F_IN_KEY_MATCH (1 << 16) /* Store the key in tun_id to match in flow table. */ diff --git a/datapath/vport-capwap.c b/datapath/vport-capwap.c index 76db8a73..3fb4ffb3 100644 --- a/datapath/vport-capwap.c +++ b/datapath/vport-capwap.c @@ -334,8 +334,8 @@ static int capwap_rcv(struct sock *sk, struct sk_buff *skb) goto out; iph = ip_hdr(skb); - vport = tnl_find_port(iph->daddr, iph->saddr, key, - TNL_T_PROTO_CAPWAP | TNL_T_KEY_EITHER, &mutable); + vport = tnl_find_port(iph->daddr, iph->saddr, key, TNL_T_PROTO_CAPWAP, + &mutable); if (unlikely(!vport)) { icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); goto error; diff --git a/datapath/vport-gre.c b/datapath/vport-gre.c index 8775d38c..cc64d129 100644 --- a/datapath/vport-gre.c +++ b/datapath/vport-gre.c @@ -193,8 +193,8 @@ static void gre_err(struct sk_buff *skb, u32 info) if (tunnel_hdr_len < 0) return; - vport = tnl_find_port(iph->saddr, iph->daddr, key, - TNL_T_PROTO_GRE | TNL_T_KEY_EITHER, &mutable); + vport = tnl_find_port(iph->saddr, iph->daddr, key, TNL_T_PROTO_GRE, + &mutable); if (!vport) return; @@ -330,8 +330,8 @@ static int gre_rcv(struct sk_buff *skb) goto error; iph = ip_hdr(skb); - vport = tnl_find_port(iph->daddr, iph->saddr, key, - TNL_T_PROTO_GRE | TNL_T_KEY_EITHER, &mutable); + vport = tnl_find_port(iph->daddr, iph->saddr, key, TNL_T_PROTO_GRE, + &mutable); if (unlikely(!vport)) { icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); goto error; -- 2.30.2