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 /* Mask for the priority bits in a vlan header. If we ever merge upstream
31 * then this should go into include/linux/if_vlan.h. */
32 #define VLAN_PCP_MASK 0xe000
33 #define VLAN_PCP_SHIFT 13
35 #define DP_MAX_PORTS 1024
37 #define SAMPLE_ACTION_DEPTH 3
40 * struct dp_stats_percpu - per-cpu packet processing statistics for a given
42 * @n_frags: Number of IP fragments processed by datapath.
43 * @n_hit: Number of received packets for which a matching flow was found in
45 * @n_miss: Number of received packets that had no matching flow in the flow
46 * table. The sum of @n_hit and @n_miss is the number of packets that have
47 * been received by the datapath.
48 * @n_lost: Number of received packets that had no matching flow in the flow
49 * table that could not be sent to userspace (normally due to an overflow in
50 * one of the datapath's queues).
52 struct dp_stats_percpu {
61 * struct datapath - datapath for flow-based packet switching
62 * @rcu: RCU callback head for deferred destruction.
63 * @list_node: Element in global 'dps' list.
64 * @ifobj: Represents /sys/class/net/<devname>/brif. Protected by RTNL.
65 * @drop_frags: Drop all IP fragments if nonzero.
66 * @n_flows: Number of flows currently in flow table.
67 * @table: Current flow table. Protected by genl_lock and RCU.
68 * @ports: Map from port number to &struct vport. %OVSP_LOCAL port
69 * always exists, other ports may be %NULL. Protected by RTNL and RCU.
70 * @port_list: List of all ports in @ports in arbitrary order. RTNL required
71 * to iterate or modify.
72 * @stats_percpu: Per-CPU datapath statistics.
74 * Context: See the comment on locking at the top of datapath.c for additional
75 * locking information.
79 struct list_head list_node;
85 struct flow_table __rcu *table;
88 struct vport __rcu *ports[DP_MAX_PORTS];
89 struct list_head port_list;
92 struct dp_stats_percpu __percpu *stats_percpu;
96 * struct ovs_skb_cb - OVS data in skb CB
97 * @vport: The datapath port on which the skb entered the switch.
98 * @flow: The flow associated with this packet. May be %NULL if no flow.
99 * @tun_id: ID of the tunnel that encapsulated this packet. It is 0 if the
100 * @ip_summed: Consistently stores L4 checksumming status across different
102 * @csum_start: Stores the offset from which to start checksumming independent
103 * of the transport header on all kernel versions.
104 * packet was not received on a tunnel.
105 * @vlan_tci: Provides a substitute for the skb->vlan_tci field on kernels
110 struct sw_flow *flow;
112 #ifdef NEED_CSUM_NORMALIZE
113 enum csum_type ip_summed;
116 #ifdef NEED_VLAN_FIELD
120 #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
123 * struct dp_upcall - metadata to include with a packet to send to userspace
124 * @cmd: One of %OVS_PACKET_CMD_*.
125 * @key: Becomes %OVS_PACKET_ATTR_KEY. Must be nonnull.
126 * @userdata: Is passed to user-space as %OVS_PACKET_ATTR_USERDATA if @cmd is
127 * %OVS_PACKET_CMD_ACTION.
129 struct dp_upcall_info {
131 const struct sw_flow_key *key;
135 extern struct notifier_block dp_device_notifier;
136 extern struct genl_multicast_group dp_vport_multicast_group;
137 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
139 void dp_process_received_packet(struct vport *, struct sk_buff *);
140 void dp_detach_port(struct vport *);
141 int dp_upcall(struct datapath *, struct sk_buff *, const struct dp_upcall_info *);
143 struct datapath *get_dp(int dp_idx);
144 const char *dp_name(const struct datapath *dp);
145 struct sk_buff *ovs_vport_cmd_build_info(struct vport *, u32 pid, u32 seq,
148 #endif /* datapath.h */