openvswitch: Add recirc action
Subsystems (3)
PATCH v6 5/11 openvswitch: Add recirc action
From: Andy Zhou <[email protected]>
Recirc action allows a packet to reenter openvswitch processing. currently openvswitch lookup flow for packet received and execute set of actions on that packet, with help of recirc action we can process/modify the packet and recirculate it back in openvswitch for another pass.
MPLS flow processing can make use of recirc by first striping off MPLS portion of packet then passing inner packet back to openvswitch for further processing.
For example:
Match on: mpls with ip addr x; action: decrement ttl. Results in two flows
1. Match on: mpls flow; action: pop_mpls, recirc(id)
2. Match on: ip addr x flow with and recirc-id == id; action: dec_ttl
--- include/uapi/linux/openvswitch.h | 2 ++ net/openvswitch/actions.c | 46 +++++++++++++++++++++++++++++++++++- net/openvswitch/datapath.c | 50 ++++++++++++++++++++++++++++------------ net/openvswitch/datapath.h | 8 +++++-- net/openvswitch/flow.h | 1 + net/openvswitch/flow_netlink.c | 16 +++++++++++++ 6 files changed, 105 insertions(+), 18 deletions(-)
include/uapi/linux/openvswitch.h +2 -0
@@ -291,6 +291,7 @@ enum ovs_key_attr {OVS_KEY_ATTR_TCP_FLAGS ,/* be16 TCP flags. */ OVS_KEY_ATTR_DP_HASH ,/* u32 hash value. Value 0 indicates the hash is not computed by the datapath. */ +OVS_KEY_ATTR_RECIRC_ID ,/* u32 recirc id */ #ifdef __KERNEL__ OVS_KEY_ATTR_IPV4_TUNNEL, /* struct ovs_key_ipv4_tunnel */
@@ -544,6 +545,7 @@ enum ovs_action_attr {OVS_ACTION_ATTR_PUSH_VLAN ,/* struct ovs_action_push_vlan. */ OVS_ACTION_ATTR_POP_VLAN ,/* No argument. */ OVS_ACTION_ATTR_SAMPLE ,/* Nested OVS_SAMPLE_ATTR_*. */ +OVS_ACTION_ATTR_RECIRC ,/* u32 recirc_id. */ OVS_ACTION_ATTR_HASH ,/* struct ovs_action_hash. */ __OVS_ACTION_ATTR_MAX };
net/openvswitch/actions.c +45 -1
62 lines not on this page · raw message
net/openvswitch/datapath.c +35 -15
95 lines not on this page · raw message
net/openvswitch/datapath.h +6 -2
@@ -1,5 +1,5 @@/* -* Copyright (c) 2007-2012 Nicira, Inc. +* Copyright (c) 2007-2014 Nicira, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public
@@ -97,12 +97,14 @@ struct datapath {* @flow: The flow associated with this packet. May be %NULL if no flow. * @pkt_key: The flow information extracted from the packet. Must be nonnull. * @tun_key: Key for the tunnel that encapsulated this packet. NULL if the -* packet is not being tunneled. +* @input_vport: The original vport packet came in on. This value is cached +* when a packet is received by OVS. */ struct ovs_skb_cb {struct sw_flow *flow;struct sw_flow_key *pkt_key;struct ovs_key_ipv4_tunnel *tun_key; +struct vport *input_vport; };#define OVS_CB (skb) ((struct ovs_skb_cb *)(skb)->cb)
@@ -184,6 +186,8 @@ extern struct notifier_block ovs_dp_device_notifier;extern struct genl_family dp_vport_genl_family;void ovs_dp_process_received_packet (struct vport *,struct sk_buff *); +void ovs_dp_process_packet_with_key (struct sk_buff *, +struct sw_flow_key *pkt_key);void ovs_dp_detach_port (struct vport *);int ovs_dp_upcall (struct datapath *,struct sk_buff *,const struct dp_upcall_info *);
net/openvswitch/flow.h +1 -0
@@ -73,6 +73,7 @@ struct sw_flow_key {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. */ +u32 recirc_id;/* Recirculation ID. */ struct {u8 src[ETH_ALEN ];/* Ethernet source address. */ u8 dst[ETH_ALEN ];/* Ethernet destination address. */
net/openvswitch/flow_netlink.c +16 -0
@@ -252,6 +252,7 @@ static const int ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = { [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_RECIRC_ID] = sizeof(u32), [OVS_KEY_ATTR_TUNNEL] = -1, };
@@ -462,6 +463,13 @@ static int metadata_from_nlattrs(struct sw_flow_match *match, u64 *attrs, *attrs &= ~(1 <<OVS_KEY_ATTR_DP_HASH ); } +if (*attrs & (1 <<OVS_KEY_ATTR_RECIRC_ID )) { +u32 recirc_id =nla_get_u32 (a[OVS_KEY_ATTR_RECIRC_ID ]); + +SW_FLOW_KEY_PUT (match, recirc_id, recirc_id, is_mask); + *attrs &= ~(1 <<OVS_KEY_ATTR_RECIRC_ID ); + } +if (*attrs & (1 <<OVS_KEY_ATTR_PRIORITY )) {SW_FLOW_KEY_PUT (match, phy.priority,nla_get_u32 (a[OVS_KEY_ATTR_PRIORITY ]), is_mask);
@@ -867,6 +875,7 @@ int ovs_nla_get_flow_metadata(struct sw_flow *flow, flow->key.phy.priority =0 ; flow->key.phy.skb_mark =0 ; flow->key.ovs_flow_hash =0 ; + flow->key.recirc_id =0 ;memset (tun_key,0 ,sizeof (flow->key.tun_key)); err =parse_flow_nlattrs (attr, a, &attrs);
@@ -893,6 +902,9 @@ int ovs_nla_put_flow(const struct sw_flow_key *swkey,if (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_RECIRC_ID , output->recirc_id)) + goto nla_put_failure; +if (nla_put_u32 (skb,OVS_KEY_ATTR_PRIORITY , output->phy.priority)) goto nla_put_failure;
@@ -1421,6 +1433,7 @@ int ovs_nla_copy_actions(const struct nlattr *attr,/* Expected argument lengths, (u32)-1 for variable length. */ static const u32 action_lens[OVS_ACTION_ATTR_MAX +1 ] = { [OVS_ACTION_ATTR_OUTPUT ] =sizeof (u32), + [OVS_ACTION_ATTR_RECIRC ] =sizeof (u32), [OVS_ACTION_ATTR_USERSPACE ] = (u32)-1 , [OVS_ACTION_ATTR_PUSH_VLAN ] =sizeof (struct ovs_action_push_vlan ), [OVS_ACTION_ATTR_POP_VLAN ] =0 ,
@@ -1477,6 +1490,9 @@ int ovs_nla_copy_actions(const struct nlattr *attr,return -EINVAL ;break ; +case OVS_ACTION_ATTR_RECIRC : +break ; +case OVS_ACTION_ATTR_SET : err =validate_set (a, key, sfa, &skip_copy);if (err)
Signature · 1 line
1.9.3