Signed-off-by: Andy Zhou <[email protected]>
----
V3->v4:
* Rehash the hash with hash_basis
* always accept dp_hash mask
* add mask to ovs_nla_put_flow() API
V2->V3:
* rename dp_hash to ovs_flow_hash
* Simplify netlink message error checking logic
* other cleanups
---
datapath/actions.c | 18 ++++++++++++++++++
datapath/datapath.c | 8 +++++---
datapath/flow.h | 1 +
datapath/flow_netlink.c | 30 +++++++++++++++++++++++++++++-
datapath/flow_netlink.h | 2 +-
5 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/datapath/actions.c b/datapath/actions.c
index 82cfd2d..87a8a40 100644
--- a/datapath/actions.c
+++ b/datapath/actions.c
@@ -460,6 +460,20 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
nla_len(acts_list), true);
}
+static void execute_hash(struct sk_buff *skb, const struct nlattr *attr)
+{
+ struct sw_flow_key *key = OVS_CB(skb)->pkt_key;
+ struct ovs_action_hash *hash_act = nla_data(attr);
+ u32 hash = 0;
+
+ /* OVS_HASH_ALG_L4 is the only possible hash algorithm. */
+ hash = skb_get_rxhash(skb);
+ if (!hash)
+ hash = 0x1;
+
+ key->ovs_flow_hash = jhash_1word(hash, hash_act->hash_basis);
+}
+
static int execute_set_action(struct sk_buff *skb,
const struct nlattr *nested_attr)
{
@@ -536,6 +550,10 @@ static int do_execute_actions(struct datapath *dp, struct
sk_buff *skb,
output_userspace(dp, skb, a);
break;
+ case OVS_ACTION_ATTR_HASH:
+ execute_hash(skb, a);
+ break;
+
case OVS_ACTION_ATTR_PUSH_VLAN:
err = push_vlan(skb, nla_data(a));
if (unlikely(err)) /* skb already freed. */
diff --git a/datapath/datapath.c b/datapath/datapath.c
index 6dfe69d..0fdd1d4 100644
--- a/datapath/datapath.c
+++ b/datapath/datapath.c
@@ -469,7 +469,7 @@ static int queue_userspace_packet(struct datapath *dp,
struct sk_buff *skb,
upcall->dp_ifindex = dp_ifindex;
nla = nla_nest_start(user_skb, OVS_PACKET_ATTR_KEY);
- ovs_nla_put_flow(upcall_info->key, upcall_info->key, user_skb);
+ ovs_nla_put_flow(upcall_info->key, NULL, upcall_info->key, user_skb);
nla_nest_end(user_skb, nla);
if (upcall_info->userdata)
@@ -690,7 +690,8 @@ static int ovs_flow_cmd_fill_info(const struct sw_flow
*flow, int dp_ifindex,
if (!nla)
goto nla_put_failure;
- err = ovs_nla_put_flow(&flow->unmasked_key, &flow->unmasked_key, skb);
+ err = ovs_nla_put_flow(&flow->unmasked_key, &flow->mask->key,
+ &flow->unmasked_key, skb);
if (err)
goto error;
nla_nest_end(skb, nla);
@@ -699,7 +700,8 @@ static int ovs_flow_cmd_fill_info(const struct sw_flow
*flow, int dp_ifindex,
if (!nla)
goto nla_put_failure;
- err = ovs_nla_put_flow(&flow->key, &flow->mask->key, skb);
+ err = ovs_nla_put_flow(&flow->key, &flow->mask->key,
+ &flow->mask->key, skb);
if (err)
goto error;
diff --git a/datapath/flow.h b/datapath/flow.h
index 1bb6ce0..a4cb57e 100644
--- a/datapath/flow.h
+++ b/datapath/flow.h
@@ -74,6 +74,7 @@ struct sw_flow_key {
u32 skb_mark; /* SKB mark. */
u16 in_port; /* Input switch port (or DP_MAX_PORTS).
*/
} __packed phy; /* Safe when right after 'tun_key'. */
+ u32 ovs_flow_hash; /* Datapath computed hash value. */
struct {
u8 src[ETH_ALEN]; /* Ethernet source address. */
u8 dst[ETH_ALEN]; /* Ethernet destination address. */
diff --git a/datapath/flow_netlink.c b/datapath/flow_netlink.c
index 5c32cd0..6b9a120 100644
--- a/datapath/flow_netlink.c
+++ b/datapath/flow_netlink.c
@@ -128,6 +128,7 @@ static bool match_validate(const struct sw_flow_match
*match,
/* Always allowed mask fields. */
mask_allowed |= ((1ULL << OVS_KEY_ATTR_TUNNEL)
| (1ULL << OVS_KEY_ATTR_IN_PORT)
+ | (1ULL << OVS_KEY_ATTR_DP_HASH)
| (1ULL << OVS_KEY_ATTR_ETHERTYPE));
/* Check key attributes. */
@@ -252,6 +253,7 @@ static const int ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = {
[OVS_KEY_ATTR_ICMPV6] = sizeof(struct ovs_key_icmpv6),
[OVS_KEY_ATTR_ARP] = sizeof(struct ovs_key_arp),
[OVS_KEY_ATTR_ND] = sizeof(struct ovs_key_nd),
+ [OVS_KEY_ATTR_DP_HASH] = sizeof(u32),
[OVS_KEY_ATTR_TUNNEL] = -1,
};
@@ -455,6 +457,13 @@ static int ipv4_tun_to_nlattr(struct sk_buff *skb,
static int metadata_from_nlattrs(struct sw_flow_match *match, u64 *attrs,
const struct nlattr **a, bool is_mask)
{
+ if (*attrs & (1ULL << OVS_KEY_ATTR_DP_HASH)) {
+ u32 hash_val = nla_get_u32(a[OVS_KEY_ATTR_DP_HASH]);
+
+ SW_FLOW_KEY_PUT(match, ovs_flow_hash, hash_val, is_mask);
+ *attrs &= ~(1ULL << OVS_KEY_ATTR_DP_HASH);
+ }
+
if (*attrs & (1ULL << OVS_KEY_ATTR_PRIORITY)) {
SW_FLOW_KEY_PUT(match, phy.priority,
nla_get_u32(a[OVS_KEY_ATTR_PRIORITY]), is_mask);
@@ -859,6 +868,7 @@ int ovs_nla_get_flow_metadata(struct sw_flow *flow,
flow->key.phy.in_port = DP_MAX_PORTS;
flow->key.phy.priority = 0;
flow->key.phy.skb_mark = 0;
+ flow->key.ovs_flow_hash = 0;
memset(tun_key, 0, sizeof(flow->key.tun_key));
err = parse_flow_nlattrs(attr, a, &attrs);
@@ -876,12 +886,17 @@ int ovs_nla_get_flow_metadata(struct sw_flow *flow,
}
int ovs_nla_put_flow(const struct sw_flow_key *swkey,
+ const struct sw_flow_key *mask,
const struct sw_flow_key *output, struct sk_buff *skb)
{
struct ovs_key_ethernet *eth_key;
struct nlattr *nla, *encap;
bool is_mask = (swkey != output);
+ if ((output->ovs_flow_hash || (mask && mask->ovs_flow_hash)) &&
+ nla_put_u32(skb, OVS_KEY_ATTR_DP_HASH, output->ovs_flow_hash))
+ goto nla_put_failure;
+
if (nla_put_u32(skb, OVS_KEY_ATTR_PRIORITY, output->phy.priority))
goto nla_put_failure;
@@ -1422,7 +1437,8 @@ int ovs_nla_copy_actions(const struct nlattr *attr,
[OVS_ACTION_ATTR_PUSH_VLAN] = sizeof(struct
ovs_action_push_vlan),
[OVS_ACTION_ATTR_POP_VLAN] = 0,
[OVS_ACTION_ATTR_SET] = (u32)-1,
- [OVS_ACTION_ATTR_SAMPLE] = (u32)-1
+ [OVS_ACTION_ATTR_SAMPLE] = (u32)-1,
+ [OVS_ACTION_ATTR_HASH] = sizeof(struct ovs_action_hash)
};
const struct ovs_action_push_vlan *vlan;
int type = nla_type(a);
@@ -1449,6 +1465,18 @@ int ovs_nla_copy_actions(const struct nlattr *attr,
return -EINVAL;
break;
+ case OVS_ACTION_ATTR_HASH: {
+ const struct ovs_action_hash *act_hash = nla_data(a);
+
+ switch (act_hash->hash_alg) {
+ case OVS_HASH_ALG_L4:
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ break;
+ }
case OVS_ACTION_ATTR_POP_VLAN:
break;
diff --git a/datapath/flow_netlink.h b/datapath/flow_netlink.h
index 4401510..4457258 100644
--- a/datapath/flow_netlink.h
+++ b/datapath/flow_netlink.h
@@ -40,7 +40,7 @@
void ovs_match_init(struct sw_flow_match *match,
struct sw_flow_key *key, struct sw_flow_mask *mask);
-int ovs_nla_put_flow(const struct sw_flow_key *,
+int ovs_nla_put_flow(const struct sw_flow_key *, const struct sw_flow_key *,
const struct sw_flow_key *, struct sk_buff *);
int ovs_nla_get_flow_metadata(struct sw_flow *flow,
const struct nlattr *attr);
--
1.9.1
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev