]>
Commit | Line | Data |
---|---|---|
a14bc59f | 1 | /* |
856081f6 | 2 | * Copyright (c) 2009, 2010, 2011 Nicira Networks. |
a14bc59f BP |
3 | * Distributed under the terms of the GNU GPL version 2. |
4 | * | |
5 | * Significant portions of this file may be copied from parts of the Linux | |
6 | * kernel, by Linus Torvalds and others. | |
7 | */ | |
8 | ||
064af421 BP |
9 | /* Interface exported by openvswitch_mod. */ |
10 | ||
11 | #ifndef DATAPATH_H | |
12 | #define DATAPATH_H 1 | |
13 | ||
14 | #include <asm/page.h> | |
15 | #include <linux/kernel.h> | |
16 | #include <linux/mutex.h> | |
064af421 | 17 | #include <linux/netdevice.h> |
38c6ecbc | 18 | #include <linux/seqlock.h> |
064af421 | 19 | #include <linux/skbuff.h> |
806e39cf | 20 | #include <linux/version.h> |
dd8d6b8c JG |
21 | |
22 | #include "checksum.h" | |
9cb8d24d | 23 | #include "compat.h" |
064af421 | 24 | #include "flow.h" |
2ba9026e | 25 | #include "dp_sysfs.h" |
6e0ce48e | 26 | #include "vlan.h" |
064af421 | 27 | |
f2459fe7 | 28 | struct vport; |
f2459fe7 | 29 | |
064af421 BP |
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 | |
a4fbb689 | 33 | #define VLAN_PCP_SHIFT 13 |
064af421 | 34 | |
5eab9abc | 35 | #define DP_MAX_PORTS 1024 |
064af421 | 36 | |
67a78abe BP |
37 | /** |
38 | * struct dp_stats_percpu - per-cpu packet processing statistics for a given | |
39 | * datapath. | |
40 | * @n_frags: Number of IP fragments processed by datapath. | |
41 | * @n_hit: Number of received packets for which a matching flow was found in | |
42 | * the flow table. | |
43 | * @n_miss: Number of received packets that had no matching flow in the flow | |
44 | * table. The sum of @n_hit and @n_miss is the number of packets that have | |
45 | * been received by the datapath. | |
46 | * @n_lost: Number of received packets that had no matching flow in the flow | |
47 | * table that could not be sent to userspace (normally due to an overflow in | |
48 | * one of the datapath's queues). | |
67a78abe | 49 | */ |
064af421 BP |
50 | struct dp_stats_percpu { |
51 | u64 n_frags; | |
52 | u64 n_hit; | |
53 | u64 n_missed; | |
54 | u64 n_lost; | |
38c6ecbc | 55 | seqcount_t seqlock; |
064af421 BP |
56 | }; |
57 | ||
72b06300 BP |
58 | /** |
59 | * struct datapath - datapath for flow-based packet switching | |
46c6a11d | 60 | * @rcu: RCU callback head for deferred destruction. |
254f2dc8 BP |
61 | * @dp_ifindex: ifindex of local port. |
62 | * @list_node: Element in global 'dps' list. | |
ed099e92 | 63 | * @ifobj: Represents /sys/class/net/<devname>/brif. Protected by RTNL. |
72b06300 | 64 | * @drop_frags: Drop all IP fragments if nonzero. |
72b06300 | 65 | * @n_flows: Number of flows currently in flow table. |
ed099e92 | 66 | * @table: Current flow table. Protected by genl_lock and RCU. |
df2c07f4 | 67 | * @ports: Map from port number to &struct vport. %OVSP_LOCAL port |
ed099e92 BP |
68 | * always exists, other ports may be %NULL. Protected by RTNL and RCU. |
69 | * @port_list: List of all ports in @ports in arbitrary order. RTNL required | |
70 | * to iterate or modify. | |
72b06300 | 71 | * @stats_percpu: Per-CPU datapath statistics. |
b4a7a3f3 | 72 | * @sflow_probability: Number of packets out of UINT_MAX to sample to the |
df2c07f4 | 73 | * %OVS_PACKET_CMD_SAMPLE multicast group, e.g. (@sflow_probability/UINT_MAX) |
982b8810 | 74 | * is the probability of sampling a given packet. |
ed099e92 BP |
75 | * |
76 | * Context: See the comment on locking at the top of datapath.c for additional | |
77 | * locking information. | |
72b06300 | 78 | */ |
064af421 | 79 | struct datapath { |
46c6a11d | 80 | struct rcu_head rcu; |
254f2dc8 BP |
81 | int dp_ifindex; |
82 | struct list_head list_node; | |
064af421 | 83 | struct kobject ifobj; |
064af421 BP |
84 | |
85 | int drop_frags; | |
86 | ||
064af421 | 87 | /* Flow table. */ |
e1040c77 | 88 | struct tbl __rcu *table; |
064af421 | 89 | |
064af421 | 90 | /* Switch ports. */ |
e1040c77 | 91 | struct vport __rcu *ports[DP_MAX_PORTS]; |
72b06300 | 92 | struct list_head port_list; |
064af421 BP |
93 | |
94 | /* Stats. */ | |
d3097eff | 95 | struct dp_stats_percpu __percpu *stats_percpu; |
72b06300 BP |
96 | |
97 | /* sFlow Sampling */ | |
98 | unsigned int sflow_probability; | |
064af421 BP |
99 | }; |
100 | ||
a063b0df JG |
101 | /** |
102 | * struct ovs_skb_cb - OVS data in skb CB | |
e779d8d9 | 103 | * @vport: The datapath port on which the skb entered the switch. |
3976f6d5 | 104 | * @flow: The flow associated with this packet. May be %NULL if no flow. |
c3729ee4 | 105 | * @tun_id: ID of the tunnel that encapsulated this packet. It is 0 if the |
a063b0df JG |
106 | * @ip_summed: Consistently stores L4 checksumming status across different |
107 | * kernel versions. | |
c3729ee4 JG |
108 | * @csum_start: Stores the offset from which to start checksumming independent |
109 | * of the transport header on all kernel versions. | |
b9298d3f | 110 | * packet was not received on a tunnel. |
6e0ce48e JG |
111 | * @vlan_tci: Provides a substitute for the skb->vlan_tci field on kernels |
112 | * before 2.6.27. | |
a063b0df JG |
113 | */ |
114 | struct ovs_skb_cb { | |
e779d8d9 | 115 | struct vport *vport; |
3976f6d5 | 116 | struct sw_flow *flow; |
c3729ee4 | 117 | __be64 tun_id; |
dd8d6b8c | 118 | #ifdef NEED_CSUM_NORMALIZE |
659586ef | 119 | enum csum_type ip_summed; |
c3729ee4 | 120 | u16 csum_start; |
dd8d6b8c | 121 | #endif |
6e0ce48e JG |
122 | #ifdef NEED_VLAN_FIELD |
123 | u16 vlan_tci; | |
124 | #endif | |
a063b0df JG |
125 | }; |
126 | #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb) | |
127 | ||
856081f6 BP |
128 | /** |
129 | * struct dp_upcall - metadata to include with a packet to send to userspace | |
df2c07f4 JP |
130 | * @cmd: One of %OVS_PACKET_CMD_*. |
131 | * @key: Becomes %OVS_PACKET_ATTR_KEY. Must be nonnull. | |
132 | * @userdata: Becomes %OVS_PACKET_ATTR_USERDATA if nonzero. | |
133 | * @sample_pool: Becomes %OVS_PACKET_ATTR_SAMPLE_POOL if nonzero. | |
134 | * @actions: Becomes %OVS_PACKET_ATTR_ACTIONS if nonnull. | |
856081f6 BP |
135 | * @actions_len: Number of bytes in @actions. |
136 | */ | |
137 | struct dp_upcall_info { | |
982b8810 | 138 | u8 cmd; |
856081f6 BP |
139 | const struct sw_flow_key *key; |
140 | u64 userdata; | |
141 | u32 sample_pool; | |
142 | const struct nlattr *actions; | |
143 | u32 actions_len; | |
144 | }; | |
145 | ||
064af421 BP |
146 | extern struct notifier_block dp_device_notifier; |
147 | extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd); | |
064af421 | 148 | |
e779d8d9 BP |
149 | void dp_process_received_packet(struct vport *, struct sk_buff *); |
150 | int dp_detach_port(struct vport *); | |
856081f6 | 151 | int dp_upcall(struct datapath *, struct sk_buff *, const struct dp_upcall_info *); |
1dcf111b | 152 | int dp_min_mtu(const struct datapath *dp); |
f2459fe7 | 153 | void set_internal_devs_mtu(const struct datapath *dp); |
064af421 BP |
154 | |
155 | struct datapath *get_dp(int dp_idx); | |
f2459fe7 | 156 | const char *dp_name(const struct datapath *dp); |
064af421 | 157 | |
064af421 | 158 | #endif /* datapath.h */ |