datapath: Simplify tnl_find_port().
authorBen Pfaff <blp@nicira.com>
Fri, 14 Oct 2011 22:33:49 +0000 (15:33 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 17 Oct 2011 15:59:48 +0000 (08:59 -0700)
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 <blp@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
datapath/tunnel.c
datapath/tunnel.h
datapath/vport-capwap.c
datapath/vport-gre.c

index e97b9f2..38004e9 100644 (file)
@@ -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;
index e7bafbc..8d20c77 100644 (file)
@@ -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. */
index 76db8a7..3fb4ffb 100644 (file)
@@ -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;
index 8775d38..cc64d12 100644 (file)
@@ -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;