datapath: Remove implementation of port groups.
[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 struct dp_port;
27
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
32
33 #define DP_MAX_PORTS 1024
34
35 #define DP_N_QUEUES 3
36 #define DP_MAX_QUEUE_LEN 100
37
38 /**
39  * struct dp_stats_percpu - per-cpu packet processing statistics for a given
40  * datapath.
41  * @n_frags: Number of IP fragments processed by datapath.
42  * @n_hit: Number of received packets for which a matching flow was found in
43  * the flow table.
44  * @n_miss: Number of received packets that had no matching flow in the flow
45  * table.  The sum of @n_hit and @n_miss is the number of packets that have
46  * been received by the datapath.
47  * @n_lost: Number of received packets that had no matching flow in the flow
48  * table that could not be sent to userspace (normally due to an overflow in
49  * one of the datapath's queues).
50  */
51 struct dp_stats_percpu {
52         u64 n_frags;
53         u64 n_hit;
54         u64 n_missed;
55         u64 n_lost;
56         seqcount_t seqlock;
57 };
58
59 /**
60  * struct datapath - datapath for flow-based packet switching
61  * @mutex: Mutual exclusion for ioctls.
62  * @dp_idx: Datapath number (index into the dps[] array in datapath.c).
63  * @ifobj: Represents /sys/class/net/<devname>/brif.
64  * @drop_frags: Drop all IP fragments if nonzero.
65  * @queues: %DP_N_QUEUES sets of queued packets for userspace to handle.
66  * @waitqueue: Waitqueue, for waiting for new packets in @queues.
67  * @n_flows: Number of flows currently in flow table.
68  * @table: Current flow table (RCU protected).
69  * @n_ports: Number of ports currently in @ports.
70  * @ports: Map from port number to &struct dp_port.  %ODPP_LOCAL port
71  * always exists, other ports may be %NULL.
72  * @port_list: List of all ports in @ports in arbitrary order.
73  * @stats_percpu: Per-CPU datapath statistics.
74  * @sflow_probability: Number of packets out of UINT_MAX to sample to the
75  * %ODPL_SFLOW queue, e.g. (@sflow_probability/UINT_MAX) is the probability of
76  * sampling a given packet.
77  */
78 struct datapath {
79         struct mutex mutex;
80         int dp_idx;
81         struct kobject ifobj;
82
83         int drop_frags;
84
85         /* Queued data. */
86         struct sk_buff_head queues[DP_N_QUEUES];
87         wait_queue_head_t waitqueue;
88
89         /* Flow table. */
90         struct tbl *table;
91
92         /* Switch ports. */
93         unsigned int n_ports;
94         struct dp_port *ports[DP_MAX_PORTS];
95         struct list_head port_list;
96
97         /* Stats. */
98         struct dp_stats_percpu *stats_percpu;
99
100         /* sFlow Sampling */
101         unsigned int sflow_probability;
102 };
103
104 /**
105  * struct dp_port - one port within a datapath
106  * @port_no: Index into @dp's @ports array.
107  * @dp: Datapath to which this port belongs.
108  * @vport: The network device attached to this port.  The contents depends on
109  * the device and should be accessed only through the vport_* functions.
110  * @kobj: Represents /sys/class/net/<devname>/brport.
111  * @linkname: The name of the link from /sys/class/net/<datapath>/brif to this
112  * &struct dp_port.  (We keep this around so that we can delete it if the
113  * device gets renamed.)  Set to the null string when no link exists.
114  * @node: Element in @dp's @port_list.
115  * @sflow_pool: Number of packets that were candidates for sFlow sampling,
116  * regardless of whether they were actually chosen and sent down to userspace.
117  */
118 struct dp_port {
119         u16 port_no;
120         struct datapath *dp;
121         struct vport *vport;
122         struct kobject kobj;
123         char linkname[IFNAMSIZ];
124         struct list_head node;
125         atomic_t sflow_pool;
126 };
127
128 enum csum_type {
129         OVS_CSUM_NONE = 0,
130         OVS_CSUM_UNNECESSARY = 1,
131         OVS_CSUM_COMPLETE = 2,
132         OVS_CSUM_PARTIAL = 3,
133 };
134
135 /**
136  * struct ovs_skb_cb - OVS data in skb CB
137  * @dp_port: The datapath port on which the skb entered the switch.
138  * @flow: The flow associated with this packet.  May be %NULL if no flow.
139  * @ip_summed: Consistently stores L4 checksumming status across different
140  * kernel versions.
141  * @tun_id: ID (in network byte order) of the tunnel that encapsulated this
142  * packet. It is 0 if the packet was not received on a tunnel.
143  */
144 struct ovs_skb_cb {
145         struct dp_port          *dp_port;
146         struct sw_flow          *flow;
147         enum csum_type          ip_summed;
148         __be32                  tun_id;
149 };
150 #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
151
152 extern struct notifier_block dp_device_notifier;
153 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
154
155 void dp_process_received_packet(struct dp_port *, struct sk_buff *);
156 int dp_detach_port(struct dp_port *, int may_delete);
157 int dp_output_control(struct datapath *, struct sk_buff *, int, u32 arg);
158 int dp_min_mtu(const struct datapath *dp);
159 void set_internal_devs_mtu(const struct datapath *dp);
160
161 struct datapath *get_dp(int dp_idx);
162 const char *dp_name(const struct datapath *dp);
163
164 #if defined(CONFIG_XEN) && defined(HAVE_PROTO_DATA_VALID)
165 int vswitch_skb_checksum_setup(struct sk_buff *skb);
166 #else
167 static inline int vswitch_skb_checksum_setup(struct sk_buff *skb)
168 {
169         return 0;
170 }
171 #endif
172
173 void compute_ip_summed(struct sk_buff *skb, bool xmit);
174 void forward_ip_summed(struct sk_buff *skb);
175
176 #endif /* datapath.h */