datapath: Merge "struct dp_port" into "struct vport".
[sliver-openvswitch.git] / datapath / datapath.h
1 /*
2  * Copyright (c) 2009, 2010 Nicira Networks.
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
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>
17 #include <linux/netdevice.h>
18 #include <linux/workqueue.h>
19 #include <linux/seqlock.h>
20 #include <linux/skbuff.h>
21 #include <linux/version.h>
22 #include "flow.h"
23 #include "dp_sysfs.h"
24
25 struct vport;
26
27 /* Mask for the priority bits in a vlan header.  If we ever merge upstream
28  * then this should go into include/linux/if_vlan.h. */
29 #define VLAN_PCP_MASK 0xe000
30 #define VLAN_PCP_SHIFT 13
31
32 #define DP_MAX_PORTS 1024
33
34 #define DP_N_QUEUES 3
35 #define DP_MAX_QUEUE_LEN 100
36
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).
49  */
50 struct dp_stats_percpu {
51         u64 n_frags;
52         u64 n_hit;
53         u64 n_missed;
54         u64 n_lost;
55         seqcount_t seqlock;
56 };
57
58 /**
59  * struct datapath - datapath for flow-based packet switching
60  * @mutex: Mutual exclusion for ioctls.
61  * @dp_idx: Datapath number (index into the dps[] array in datapath.c).
62  * @ifobj: Represents /sys/class/net/<devname>/brif.
63  * @drop_frags: Drop all IP fragments if nonzero.
64  * @queues: %DP_N_QUEUES sets of queued packets for userspace to handle.
65  * @waitqueue: Waitqueue, for waiting for new packets in @queues.
66  * @n_flows: Number of flows currently in flow table.
67  * @table: Current flow table (RCU protected).
68  * @n_ports: Number of ports currently in @ports.
69  * @ports: Map from port number to &struct vport.  %ODPP_LOCAL port
70  * always exists, other ports may be %NULL.
71  * @port_list: List of all ports in @ports in arbitrary order.
72  * @stats_percpu: Per-CPU datapath statistics.
73  * @sflow_probability: Number of packets out of UINT_MAX to sample to the
74  * %ODPL_SFLOW queue, e.g. (@sflow_probability/UINT_MAX) is the probability of
75  * sampling a given packet.
76  */
77 struct datapath {
78         struct mutex mutex;
79         int dp_idx;
80         struct kobject ifobj;
81
82         int drop_frags;
83
84         /* Queued data. */
85         struct sk_buff_head queues[DP_N_QUEUES];
86         wait_queue_head_t waitqueue;
87
88         /* Flow table. */
89         struct tbl *table;
90
91         /* Switch ports. */
92         unsigned int n_ports;
93         struct vport *ports[DP_MAX_PORTS];
94         struct list_head port_list;
95
96         /* Stats. */
97         struct dp_stats_percpu *stats_percpu;
98
99         /* sFlow Sampling */
100         unsigned int sflow_probability;
101 };
102
103 enum csum_type {
104         OVS_CSUM_NONE = 0,
105         OVS_CSUM_UNNECESSARY = 1,
106         OVS_CSUM_COMPLETE = 2,
107         OVS_CSUM_PARTIAL = 3,
108 };
109
110 /**
111  * struct ovs_skb_cb - OVS data in skb CB
112  * @vport: The datapath port on which the skb entered the switch.
113  * @flow: The flow associated with this packet.  May be %NULL if no flow.
114  * @ip_summed: Consistently stores L4 checksumming status across different
115  * kernel versions.
116  * @tun_id: ID (in network byte order) of the tunnel that encapsulated this
117  * packet. It is 0 if the packet was not received on a tunnel.
118  */
119 struct ovs_skb_cb {
120         struct vport            *vport;
121         struct sw_flow          *flow;
122         enum csum_type          ip_summed;
123         __be32                  tun_id;
124 };
125 #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
126
127 extern struct notifier_block dp_device_notifier;
128 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
129
130 void dp_process_received_packet(struct vport *, struct sk_buff *);
131 int dp_detach_port(struct vport *);
132 int dp_output_control(struct datapath *, struct sk_buff *, int, u32 arg);
133 int dp_min_mtu(const struct datapath *dp);
134 void set_internal_devs_mtu(const struct datapath *dp);
135
136 struct datapath *get_dp(int dp_idx);
137 const char *dp_name(const struct datapath *dp);
138
139 #if defined(CONFIG_XEN) && defined(HAVE_PROTO_DATA_VALID)
140 int vswitch_skb_checksum_setup(struct sk_buff *skb);
141 #else
142 static inline int vswitch_skb_checksum_setup(struct sk_buff *skb)
143 {
144         return 0;
145 }
146 #endif
147
148 void compute_ip_summed(struct sk_buff *skb, bool xmit);
149 void forward_ip_summed(struct sk_buff *skb);
150
151 #endif /* datapath.h */