Support controller discovery in Debian packages.
[sliver-openvswitch.git] / datapath / flow.c
index fde6dd3..8cf09a1 100644 (file)
@@ -12,6 +12,7 @@
 #include <net/llc_pdu.h>
 #include <linux/ip.h>
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/tcp.h>
 #include <linux/udp.h>
 #include <linux/in.h>
@@ -42,18 +43,17 @@ int flow_fields_match(const struct sw_flow_key *a, const struct sw_flow_key *b,
 
 /* Returns nonzero if 'a' and 'b' match, that is, if their fields are equal
  * modulo wildcards, zero otherwise. */
-inline
 int flow_matches(const struct sw_flow_key *a, const struct sw_flow_key *b)
 {
        return flow_fields_match(a, b, (a->wildcards | b->wildcards));
 }
+EXPORT_SYMBOL(flow_matches);
 
 /* Returns nonzero if 't' (the table entry's key) and 'd' (the key 
  * describing the deletion) match, that is, if their fields are 
  * equal modulo wildcards, zero otherwise.  If 'strict' is nonzero, the
  * wildcards must match in both 't_key' and 'd_key'.  Note that the
  * table's wildcards are ignored unless 'strict' is set. */
-inline
 int flow_del_matches(const struct sw_flow_key *t, const struct sw_flow_key *d, int strict)
 {
        if (strict && (t->wildcards != d->wildcards))
@@ -61,6 +61,7 @@ int flow_del_matches(const struct sw_flow_key *t, const struct sw_flow_key *d, i
 
        return flow_fields_match(t, d, d->wildcards);
 }
+EXPORT_SYMBOL(flow_del_matches);
 
 void flow_extract_match(struct sw_flow_key* to, const struct ofp_match* from)
 {
@@ -72,26 +73,40 @@ void flow_extract_match(struct sw_flow_key* to, const struct ofp_match* from)
        memcpy(to->dl_dst, from->dl_dst, ETH_ALEN);
        to->dl_type = from->dl_type;
 
-       if (likely(from->dl_type == htons(ETH_P_IP))) {
+       to->nw_src = to->nw_dst = to->nw_proto = 0;
+       to->tp_src = to->tp_dst = 0;
+
+#define OFPFW_TP (OFPFW_TP_SRC | OFPFW_TP_DST)
+#define OFPFW_NW (OFPFW_NW_SRC | OFPFW_NW_DST | OFPFW_NW_PROTO)
+       if (to->wildcards & OFPFW_DL_TYPE) {
+               /* Can't sensibly match on network or transport headers if the
+                * data link type is unknown. */
+               to->wildcards |= OFPFW_NW | OFPFW_TP;
+       } else if (from->dl_type == htons(ETH_P_IP)) {
                to->nw_src   = from->nw_src;
                to->nw_dst   = from->nw_dst;
                to->nw_proto = from->nw_proto;
 
-               if ((from->nw_proto != IPPROTO_TCP && from->nw_proto != IPPROTO_UDP)) {
-                       goto no_th;
+               if (to->wildcards & OFPFW_NW_PROTO) {
+                       /* Can't sensibly match on transport headers if the
+                        * network protocol is unknown. */
+                       to->wildcards |= OFPFW_TP;
+               } else if (from->nw_proto == IPPROTO_TCP
+                          || from->nw_proto == IPPROTO_UDP) {
+                       to->tp_src = from->tp_src;
+                       to->tp_dst = from->tp_dst;
+               } else {
+                       /* Transport layer fields are undefined.  Mark them as
+                        * exact-match to allow such flows to reside in
+                        * table-hash, instead of falling into table-linear. */
+                       to->wildcards &= ~OFPFW_TP;
                }
-               to->tp_src = from->tp_src;
-               to->tp_dst = from->tp_dst;
-               return;
+       } else {
+               /* Network and transport layer fields are undefined.  Mark them
+                * as exact-match to allow such flows to reside in table-hash,
+                * instead of falling into table-linear. */
+               to->wildcards &= ~(OFPFW_NW | OFPFW_TP);
        }
-
-       to->nw_src = 0;
-       to->nw_dst = 0;
-       to->nw_proto = 0;
-
-no_th:
-       to->tp_src = 0;
-       to->tp_dst = 0;
 }
 
 void flow_fill_match(struct ofp_match* to, const struct sw_flow_key* from)
@@ -118,6 +133,7 @@ int flow_del(struct sw_flow *flow)
 {
        return !atomic_cmpxchg(&flow->deleted, 0, 1);
 }
+EXPORT_SYMBOL(flow_del);
 
 /* Allocates and returns a new flow with 'n_actions' action, using allocation
  * flags 'flags'.  Returns the new flow or a null pointer on failure. */
@@ -145,6 +161,7 @@ void flow_free(struct sw_flow *flow)
        kfree(flow->actions);
        kmem_cache_free(flow_cache, flow);
 }
+EXPORT_SYMBOL(flow_free);
 
 /* RCU callback used by flow_deferred_free. */
 static void rcu_callback(struct rcu_head *rcu)
@@ -159,6 +176,7 @@ void flow_deferred_free(struct sw_flow *flow)
 {
        call_rcu(&flow->rcu, rcu_callback);
 }
+EXPORT_SYMBOL(flow_deferred_free);
 
 /* Prints a representation of 'key' to the kernel log. */
 void print_flow(const struct sw_flow_key *key)
@@ -182,6 +200,7 @@ void print_flow(const struct sw_flow_key *key)
                        ((unsigned char *)&key->nw_dst)[3],
                        ntohs(key->tp_src), ntohs(key->tp_dst));
 }
+EXPORT_SYMBOL(print_flow);
 
 /* Parses the Ethernet frame in 'skb', which was received on 'in_port',
  * and initializes 'key' to match. */