datapath: Use call_rcu() when deleting a datapath.
[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
23 #include "checksum.h"
24 #include "flow.h"
25 #include "dp_sysfs.h"
26
27 struct vport;
28
29 /* Mask for the priority bits in a vlan header.  If we ever merge upstream
30  * then this should go into include/linux/if_vlan.h. */
31 #define VLAN_PCP_MASK 0xe000
32 #define VLAN_PCP_SHIFT 13
33
34 #define DP_MAX_PORTS 1024
35
36 #define DP_N_QUEUES 3
37 #define DP_MAX_QUEUE_LEN 100
38
39 /**
40  * struct dp_stats_percpu - per-cpu packet processing statistics for a given
41  * datapath.
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
44  * the flow table.
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).
51  */
52 struct dp_stats_percpu {
53         u64 n_frags;
54         u64 n_hit;
55         u64 n_missed;
56         u64 n_lost;
57         seqcount_t seqlock;
58 };
59
60 /**
61  * struct datapath - datapath for flow-based packet switching
62  * @rcu: RCU callback head for deferred destruction.
63  * @mutex: Mutual exclusion for ioctls.
64  * @dp_idx: Datapath number (index into the dps[] array in datapath.c).
65  * @ifobj: Represents /sys/class/net/<devname>/brif.
66  * @drop_frags: Drop all IP fragments if nonzero.
67  * @queues: %DP_N_QUEUES sets of queued packets for userspace to handle.
68  * @waitqueue: Waitqueue, for waiting for new packets in @queues.
69  * @n_flows: Number of flows currently in flow table.
70  * @table: Current flow table.
71  * @n_ports: Number of ports currently in @ports.
72  * @ports: Map from port number to &struct vport.  %ODPP_LOCAL port
73  * always exists, other ports may be %NULL.
74  * @port_list: List of all ports in @ports in arbitrary order.
75  * @stats_percpu: Per-CPU datapath statistics.
76  * @sflow_probability: Number of packets out of UINT_MAX to sample to the
77  * %ODPL_SFLOW queue, e.g. (@sflow_probability/UINT_MAX) is the probability of
78  * sampling a given packet.
79  */
80 struct datapath {
81         struct rcu_head rcu;
82         struct mutex mutex;
83         int dp_idx;
84         struct kobject ifobj;
85
86         int drop_frags;
87
88         /* Queued data. */
89         struct sk_buff_head queues[DP_N_QUEUES];
90         wait_queue_head_t waitqueue;
91
92         /* Flow table. */
93         struct tbl __rcu *table;
94
95         /* Switch ports. */
96         unsigned int n_ports;
97         struct vport __rcu *ports[DP_MAX_PORTS];
98         struct list_head port_list;
99
100         /* Stats. */
101         struct dp_stats_percpu __percpu *stats_percpu;
102
103         /* sFlow Sampling */
104         unsigned int sflow_probability;
105 };
106
107 /**
108  * struct ovs_skb_cb - OVS data in skb CB
109  * @vport: The datapath port on which the skb entered the switch.
110  * @flow: The flow associated with this packet.  May be %NULL if no flow.
111  * @ip_summed: Consistently stores L4 checksumming status across different
112  * kernel versions.
113  * @tun_id: ID of the tunnel that encapsulated this packet.  It is 0 if the
114  * packet was not received on a tunnel.
115  */
116 struct ovs_skb_cb {
117         struct vport            *vport;
118         struct sw_flow          *flow;
119 #ifdef NEED_CSUM_NORMALIZE
120         enum csum_type          ip_summed;
121 #endif
122         __be64                  tun_id;
123 };
124 #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
125
126 extern struct notifier_block dp_device_notifier;
127 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
128
129 void dp_process_received_packet(struct vport *, struct sk_buff *);
130 int dp_detach_port(struct vport *);
131 int dp_output_control(struct datapath *, struct sk_buff *, int, u64 arg);
132 int dp_min_mtu(const struct datapath *dp);
133 void set_internal_devs_mtu(const struct datapath *dp);
134
135 struct datapath *get_dp(int dp_idx);
136 const char *dp_name(const struct datapath *dp);
137
138 #endif /* datapath.h */