datapath: Change dp_idx to dp_ifindex, the ifindex of the local port.
[sliver-openvswitch.git] / datapath / datapath.h
1 /*
2  * Copyright (c) 2009, 2010, 2011 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/seqlock.h>
19 #include <linux/skbuff.h>
20 #include <linux/version.h>
21
22 #include "checksum.h"
23 #include "flow.h"
24 #include "dp_sysfs.h"
25
26 struct vport;
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 /**
36  * struct dp_stats_percpu - per-cpu packet processing statistics for a given
37  * datapath.
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
40  * the flow table.
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).
47  */
48 struct dp_stats_percpu {
49         u64 n_frags;
50         u64 n_hit;
51         u64 n_missed;
52         u64 n_lost;
53         seqcount_t seqlock;
54 };
55
56 /**
57  * struct datapath - datapath for flow-based packet switching
58  * @rcu: RCU callback head for deferred destruction.
59  * @dp_ifindex: ifindex of local port.
60  * @list_node: Element in global 'dps' list.
61  * @ifobj: Represents /sys/class/net/<devname>/brif.  Protected by RTNL.
62  * @drop_frags: Drop all IP fragments if nonzero.
63  * @n_flows: Number of flows currently in flow table.
64  * @table: Current flow table.  Protected by genl_lock and RCU.
65  * @ports: Map from port number to &struct vport.  %ODPP_LOCAL port
66  * always exists, other ports may be %NULL.  Protected by RTNL and RCU.
67  * @port_list: List of all ports in @ports in arbitrary order.  RTNL required
68  * to iterate or modify.
69  * @stats_percpu: Per-CPU datapath statistics.
70  * @sflow_probability: Number of packets out of UINT_MAX to sample to the
71  * %ODP_PACKET_CMD_SAMPLE multicast group, e.g. (@sflow_probability/UINT_MAX)
72  * is the probability of sampling a given packet.
73  *
74  * Context: See the comment on locking at the top of datapath.c for additional
75  * locking information.
76  */
77 struct datapath {
78         struct rcu_head rcu;
79         int dp_ifindex;
80         struct list_head list_node;
81         struct kobject ifobj;
82
83         int drop_frags;
84
85         /* Flow table. */
86         struct tbl __rcu *table;
87
88         /* Switch ports. */
89         struct vport __rcu *ports[DP_MAX_PORTS];
90         struct list_head port_list;
91
92         /* Stats. */
93         struct dp_stats_percpu __percpu *stats_percpu;
94
95         /* sFlow Sampling */
96         unsigned int sflow_probability;
97 };
98
99 /**
100  * struct ovs_skb_cb - OVS data in skb CB
101  * @vport: The datapath port on which the skb entered the switch.
102  * @flow: The flow associated with this packet.  May be %NULL if no flow.
103  * @ip_summed: Consistently stores L4 checksumming status across different
104  * kernel versions.
105  * @tun_id: ID of the tunnel that encapsulated this packet.  It is 0 if the
106  * packet was not received on a tunnel.
107  */
108 struct ovs_skb_cb {
109         struct vport            *vport;
110         struct sw_flow          *flow;
111 #ifdef NEED_CSUM_NORMALIZE
112         enum csum_type          ip_summed;
113 #endif
114         __be64                  tun_id;
115 };
116 #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
117
118 /**
119  * struct dp_upcall - metadata to include with a packet to send to userspace
120  * @cmd: One of %ODP_PACKET_CMD_*.
121  * @key: Becomes %ODP_PACKET_ATTR_KEY.  Must be nonnull.
122  * @userdata: Becomes %ODP_PACKET_ATTR_USERDATA if nonzero.
123  * @sample_pool: Becomes %ODP_PACKET_ATTR_SAMPLE_POOL if nonzero.
124  * @actions: Becomes %ODP_PACKET_ATTR_ACTIONS if nonnull.
125  * @actions_len: Number of bytes in @actions.
126 */
127 struct dp_upcall_info {
128         u8 cmd;
129         const struct sw_flow_key *key;
130         u64 userdata;
131         u32 sample_pool;
132         const struct nlattr *actions;
133         u32 actions_len;
134 };
135
136 extern struct notifier_block dp_device_notifier;
137 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
138
139 void dp_process_received_packet(struct vport *, struct sk_buff *);
140 int dp_detach_port(struct vport *);
141 int dp_upcall(struct datapath *, struct sk_buff *, const struct dp_upcall_info *);
142 int dp_min_mtu(const struct datapath *dp);
143 void set_internal_devs_mtu(const struct datapath *dp);
144
145 struct datapath *get_dp(int dp_idx);
146 const char *dp_name(const struct datapath *dp);
147
148 #endif /* datapath.h */