Future pathces will make use of those functions. Signed-off-by: Andy Zhou <az...@nicira.com> --- datapath/Modules.mk | 1 + datapath/actions.c | 27 ++++++++++++++++ datapath/actions.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ datapath/datapath.c | 4 +++ datapath/datapath.h | 2 +- 5 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 datapath/actions.h
diff --git a/datapath/Modules.mk b/datapath/Modules.mk index 90e158c..2e74f6e 100644 --- a/datapath/Modules.mk +++ b/datapath/Modules.mk @@ -23,6 +23,7 @@ openvswitch_sources = \ openvswitch_headers = \ compat.h \ + actions.h \ datapath.h \ flow.h \ flow_netlink.h \ diff --git a/datapath/actions.c b/datapath/actions.c index bccf397..9dd9063 100644 --- a/datapath/actions.c +++ b/datapath/actions.c @@ -39,6 +39,9 @@ #include "mpls.h" #include "vlan.h" #include "vport.h" +#include "actions.h" + +static DEFINE_PER_CPU(struct ovs_action_stack, ovs_action_stacks); static void flow_key_clone(struct sk_buff *skb, struct sw_flow_key *new_key) { @@ -949,3 +952,27 @@ out_loop: return error; } + +void ovs_action_stacks_init(void) +{ + int i; + + for_each_possible_cpu(i) { + struct ovs_action_stack *stack; + + stack = &per_cpu(ovs_action_stacks, i); + ovs_action_stack_init(stack); + } +} + +void ovs_action_stacks_exit(void) +{ + int i; + + for_each_possible_cpu(i) { + struct ovs_action_stack *stack; + + stack = &per_cpu(ovs_action_stacks, i); + BUG_ON(stack->top != 0); + } +} diff --git a/datapath/actions.h b/datapath/actions.h new file mode 100644 index 0000000..e4601a6 --- /dev/null +++ b/datapath/actions.h @@ -0,0 +1,90 @@ +/* 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 + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA + */ + +#ifndef ACTION_H +#define ACTION_H 1 + +#include <linux/kernel.h> +#include <linux/mutex.h> +#include <linux/netdevice.h> +#include <linux/skbuff.h> + +#include "compat.h" +#include "flow.h" +#include "flow_table.h" +#include "vlan.h" +#include "vport.h" + +#define OVS_ACTION_STACK_LIMIT 10 + +struct ovs_deferred_action { + struct sk_buff *skb; + struct nlattr *actions; + int rem; + + /* Store pkt_key clone during recirc */ + struct sw_flow_key pkt_key; +}; + +struct ovs_action_stack { + /* Deffered action stack */ + int top; + struct ovs_deferred_action stack[OVS_ACTION_STACK_LIMIT]; +}; + +void ovs_action_stacks_init(void); +void ovs_action_stacks_exit(void); +int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb); +void ovs_process_action_stack(void); + +static inline void ovs_action_stack_init(struct ovs_action_stack *stack) +{ + stack->top = 0; +} + +static inline struct ovs_deferred_action * +ovs_action_stack_pop(struct ovs_action_stack *stack) +{ + if (stack->top) { + stack->top--; + return &stack->stack[stack->top]; + } + + return NULL; +} + +static inline struct ovs_deferred_action * +ovs_action_stack_push(struct ovs_action_stack *stack, + struct sk_buff *skb, + struct nlattr *actions, int rem) +{ + struct ovs_deferred_action *elem; + + if (stack->top >= OVS_ACTION_STACK_LIMIT - 1) + return NULL; + + elem = &stack->stack[stack->top]; + elem->skb = skb; + elem->actions = actions; + elem->rem = rem; + + stack->top++; + + return elem; +} + +#endif /* actions.h */ diff --git a/datapath/datapath.c b/datapath/datapath.c index e477c72..aa13817 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -61,6 +61,7 @@ #include "vlan.h" #include "vport-internal_dev.h" #include "vport-netdev.h" +#include "actions.h" int ovs_net_id __read_mostly; @@ -2136,6 +2137,8 @@ static int __init dp_init(void) if (err < 0) goto error_unreg_notifier; + ovs_action_stacks_init(); + return 0; error_unreg_notifier: @@ -2158,6 +2161,7 @@ static void dp_cleanup(void) rcu_barrier(); ovs_vport_exit(); ovs_flow_exit(); + ovs_action_stacks_exit(); } module_init(dp_init); diff --git a/datapath/datapath.h b/datapath/datapath.h index 4874ab5..73f4e14 100644 --- a/datapath/datapath.h +++ b/datapath/datapath.h @@ -31,6 +31,7 @@ #include "flow_table.h" #include "vlan.h" #include "vport.h" +#include "actions.h" #define DP_MAX_PORTS USHRT_MAX #define DP_VPORT_HASH_BUCKETS 1024 @@ -197,7 +198,6 @@ const char *ovs_dp_name(const struct datapath *dp); struct sk_buff *ovs_vport_cmd_build_info(struct vport *, u32 portid, u32 seq, u8 cmd); -int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb); void ovs_dp_notify_wq(struct work_struct *work); #define OVS_NLERR(fmt, ...) \ -- 1.9.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev