2 * Copyright (c) 2009, 2010, 2011 Nicira Networks.
3 * Distributed under the terms of the GNU GPL version 2.
5 * Significant portions of this file may be copied from parts of the Linux
6 * kernel, by Linus Torvalds and others.
9 /* Interface exported by openvswitch_mod. */
15 #include <linux/kernel.h>
16 #include <linux/mutex.h>
17 #include <linux/netdevice.h>
18 #include <linux/seqlock.h>
19 #include <linux/skbuff.h>
20 #include <linux/version.h>
30 #define DP_MAX_PORTS 1024
31 #define SAMPLE_ACTION_DEPTH 3
34 * struct dp_stats_percpu - per-cpu packet processing statistics for a given
36 * @n_frags: Number of IP fragments processed by datapath.
37 * @n_hit: Number of received packets for which a matching flow was found in
39 * @n_miss: Number of received packets that had no matching flow in the flow
40 * table. The sum of @n_hit and @n_miss is the number of packets that have
41 * been received by the datapath.
42 * @n_lost: Number of received packets that had no matching flow in the flow
43 * table that could not be sent to userspace (normally due to an overflow in
44 * one of the datapath's queues).
46 struct dp_stats_percpu {
55 * struct datapath - datapath for flow-based packet switching
56 * @rcu: RCU callback head for deferred destruction.
57 * @list_node: Element in global 'dps' list.
58 * @ifobj: Represents /sys/class/net/<devname>/brif. Protected by RTNL.
59 * @drop_frags: Drop all IP fragments if nonzero.
60 * @n_flows: Number of flows currently in flow table.
61 * @table: Current flow table. Protected by genl_lock and RCU.
62 * @ports: Map from port number to &struct vport. %OVSP_LOCAL port
63 * always exists, other ports may be %NULL. Protected by RTNL and RCU.
64 * @port_list: List of all ports in @ports in arbitrary order. RTNL required
65 * to iterate or modify.
66 * @stats_percpu: Per-CPU datapath statistics.
68 * Context: See the comment on locking at the top of datapath.c for additional
69 * locking information.
73 struct list_head list_node;
79 struct flow_table __rcu *table;
82 struct vport __rcu *ports[DP_MAX_PORTS];
83 struct list_head port_list;
86 struct dp_stats_percpu __percpu *stats_percpu;
90 * struct ovs_skb_cb - OVS data in skb CB
91 * @vport: The datapath port on which the skb entered the switch.
92 * @flow: The flow associated with this packet. May be %NULL if no flow.
93 * @tun_id: ID of the tunnel that encapsulated this packet. It is 0 if the
94 * @ip_summed: Consistently stores L4 checksumming status across different
96 * @csum_start: Stores the offset from which to start checksumming independent
97 * of the transport header on all kernel versions.
98 * packet was not received on a tunnel.
99 * @vlan_tci: Provides a substitute for the skb->vlan_tci field on kernels
104 struct sw_flow *flow;
106 #ifdef NEED_CSUM_NORMALIZE
107 enum csum_type ip_summed;
110 #ifdef NEED_VLAN_FIELD
114 #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
117 * struct dp_upcall - metadata to include with a packet to send to userspace
118 * @cmd: One of %OVS_PACKET_CMD_*.
119 * @key: Becomes %OVS_PACKET_ATTR_KEY. Must be nonnull.
120 * @userdata: Is passed to user-space as %OVS_PACKET_ATTR_USERDATA if @cmd is
121 * %OVS_PACKET_CMD_ACTION.
123 struct dp_upcall_info {
125 const struct sw_flow_key *key;
129 extern struct notifier_block dp_device_notifier;
130 extern struct genl_multicast_group dp_vport_multicast_group;
131 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
133 void dp_process_received_packet(struct vport *, struct sk_buff *);
134 void dp_detach_port(struct vport *);
135 int dp_upcall(struct datapath *, struct sk_buff *, const struct dp_upcall_info *);
137 struct datapath *get_dp(int dp_idx);
138 const char *dp_name(const struct datapath *dp);
139 struct sk_buff *ovs_vport_cmd_build_info(struct vport *, u32 pid, u32 seq,
142 #endif /* datapath.h */