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>
28 /* Mask for the priority bits in a vlan header. If we ever merge upstream
29 * then this should go into include/linux/if_vlan.h. */
30 #define VLAN_PCP_MASK 0xe000
31 #define VLAN_PCP_SHIFT 13
33 #define DP_MAX_PORTS 1024
36 * struct dp_stats_percpu - per-cpu packet processing statistics for a given
38 * @n_frags: Number of IP fragments processed by datapath.
39 * @n_hit: Number of received packets for which a matching flow was found in
41 * @n_miss: Number of received packets that had no matching flow in the flow
42 * table. The sum of @n_hit and @n_miss is the number of packets that have
43 * been received by the datapath.
44 * @n_lost: Number of received packets that had no matching flow in the flow
45 * table that could not be sent to userspace (normally due to an overflow in
46 * one of the datapath's queues).
48 struct dp_stats_percpu {
57 * struct datapath - datapath for flow-based packet switching
58 * @rcu: RCU callback head for deferred destruction.
59 * @dp_idx: Datapath number (index into the dps[] array in datapath.c).
60 * @ifobj: Represents /sys/class/net/<devname>/brif. Protected by RTNL.
61 * @drop_frags: Drop all IP fragments if nonzero.
62 * @n_flows: Number of flows currently in flow table.
63 * @table: Current flow table. Protected by genl_lock and RCU.
64 * @ports: Map from port number to &struct vport. %ODPP_LOCAL port
65 * always exists, other ports may be %NULL. Protected by RTNL and RCU.
66 * @port_list: List of all ports in @ports in arbitrary order. RTNL required
67 * to iterate or modify.
68 * @stats_percpu: Per-CPU datapath statistics.
69 * @sflow_probability: Number of packets out of UINT_MAX to sample to the
70 * %ODP_PACKET_CMD_SAMPLE multicast group, e.g. (@sflow_probability/UINT_MAX)
71 * is the probability of sampling a given packet.
73 * Context: See the comment on locking at the top of datapath.c for additional
74 * locking information.
84 struct tbl __rcu *table;
87 struct vport __rcu *ports[DP_MAX_PORTS];
88 struct list_head port_list;
91 struct dp_stats_percpu __percpu *stats_percpu;
94 unsigned int sflow_probability;
98 * struct ovs_skb_cb - OVS data in skb CB
99 * @vport: The datapath port on which the skb entered the switch.
100 * @flow: The flow associated with this packet. May be %NULL if no flow.
101 * @ip_summed: Consistently stores L4 checksumming status across different
103 * @tun_id: ID of the tunnel that encapsulated this packet. It is 0 if the
104 * packet was not received on a tunnel.
108 struct sw_flow *flow;
109 #ifdef NEED_CSUM_NORMALIZE
110 enum csum_type ip_summed;
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 %ODP_PACKET_CMD_*.
119 * @key: Becomes %ODP_PACKET_ATTR_KEY. Must be nonnull.
120 * @userdata: Becomes %ODP_PACKET_ATTR_USERDATA if nonzero.
121 * @sample_pool: Becomes %ODP_PACKET_ATTR_SAMPLE_POOL if nonzero.
122 * @actions: Becomes %ODP_PACKET_ATTR_ACTIONS if nonnull.
123 * @actions_len: Number of bytes in @actions.
125 struct dp_upcall_info {
127 const struct sw_flow_key *key;
130 const struct nlattr *actions;
134 extern struct notifier_block dp_device_notifier;
135 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
137 void dp_process_received_packet(struct vport *, struct sk_buff *);
138 int dp_detach_port(struct vport *);
139 int dp_upcall(struct datapath *, struct sk_buff *, const struct dp_upcall_info *);
140 int dp_min_mtu(const struct datapath *dp);
141 void set_internal_devs_mtu(const struct datapath *dp);
143 struct datapath *get_dp(int dp_idx);
144 const char *dp_name(const struct datapath *dp);
146 #endif /* datapath.h */