datapath: Fix coding style issues.
[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 "compat.h"
24 #include "flow.h"
25 #include "dp_sysfs.h"
26 #include "vlan.h"
27
28 struct vport;
29
30 #define DP_MAX_PORTS 1024
31 #define SAMPLE_ACTION_DEPTH 3
32
33 /**
34  * struct dp_stats_percpu - per-cpu packet processing statistics for a given
35  * datapath.
36  * @n_hit: Number of received packets for which a matching flow was found in
37  * the flow table.
38  * @n_miss: Number of received packets that had no matching flow in the flow
39  * table.  The sum of @n_hit and @n_miss is the number of packets that have
40  * been received by the datapath.
41  * @n_lost: Number of received packets that had no matching flow in the flow
42  * table that could not be sent to userspace (normally due to an overflow in
43  * one of the datapath's queues).
44  */
45 struct dp_stats_percpu {
46         u64 n_hit;
47         u64 n_missed;
48         u64 n_lost;
49         seqcount_t seqlock;
50 };
51
52 /**
53  * struct datapath - datapath for flow-based packet switching
54  * @rcu: RCU callback head for deferred destruction.
55  * @list_node: Element in global 'dps' list.
56  * @ifobj: Represents /sys/class/net/<devname>/brif.  Protected by RTNL.
57  * @n_flows: Number of flows currently in flow table.
58  * @table: Current flow table.  Protected by genl_lock and RCU.
59  * @ports: Map from port number to &struct vport.  %OVSP_LOCAL port
60  * always exists, other ports may be %NULL.  Protected by RTNL and RCU.
61  * @port_list: List of all ports in @ports in arbitrary order.  RTNL required
62  * to iterate or modify.
63  * @stats_percpu: Per-CPU datapath statistics.
64  *
65  * Context: See the comment on locking at the top of datapath.c for additional
66  * locking information.
67  */
68 struct datapath {
69         struct rcu_head rcu;
70         struct list_head list_node;
71         struct kobject ifobj;
72
73         /* Flow table. */
74         struct flow_table __rcu *table;
75
76         /* Switch ports. */
77         struct vport __rcu *ports[DP_MAX_PORTS];
78         struct list_head port_list;
79
80         /* Stats. */
81         struct dp_stats_percpu __percpu *stats_percpu;
82 };
83
84 /**
85  * struct ovs_skb_cb - OVS data in skb CB
86  * @vport: The datapath port on which the skb entered the switch.
87  * @flow: The flow associated with this packet.  May be %NULL if no flow.
88  * @tun_id: ID of the tunnel that encapsulated this packet.  It is 0 if the
89  * @ip_summed: Consistently stores L4 checksumming status across different
90  * kernel versions.
91  * @csum_start: Stores the offset from which to start checksumming independent
92  * of the transport header on all kernel versions.
93  * packet was not received on a tunnel.
94  * @vlan_tci: Provides a substitute for the skb->vlan_tci field on kernels
95  * before 2.6.27.
96  */
97 struct ovs_skb_cb {
98         struct vport            *vport;
99         struct sw_flow          *flow;
100         __be64                  tun_id;
101 #ifdef NEED_CSUM_NORMALIZE
102         enum csum_type          ip_summed;
103         u16                     csum_start;
104 #endif
105 #ifdef NEED_VLAN_FIELD
106         u16                     vlan_tci;
107 #endif
108 };
109 #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
110
111 /**
112  * struct dp_upcall - metadata to include with a packet to send to userspace
113  * @cmd: One of %OVS_PACKET_CMD_*.
114  * @key: Becomes %OVS_PACKET_ATTR_KEY.  Must be nonnull.
115  * @userdata: If nonnull, its u64 value is extracted and passed to userspace as
116  * %OVS_PACKET_ATTR_USERDATA.
117  * @pid: Netlink PID to which packet should be sent.  If @pid is 0 then no
118  * packet is sent and the packet is accounted in the datapath's @n_lost
119  * counter.
120  */
121 struct dp_upcall_info {
122         u8 cmd;
123         const struct sw_flow_key *key;
124         const struct nlattr *userdata;
125         u32 pid;
126 };
127
128 extern struct notifier_block dp_device_notifier;
129 extern struct genl_multicast_group dp_vport_multicast_group;
130 extern int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
131
132 void dp_process_received_packet(struct vport *, struct sk_buff *);
133 void dp_detach_port(struct vport *);
134 int dp_upcall(struct datapath *, struct sk_buff *,
135               const struct dp_upcall_info *);
136
137 struct datapath *get_dp(int dp_idx);
138 const char *dp_name(const struct datapath *dp);
139 struct sk_buff *ovs_vport_cmd_build_info(struct vport *, u32 pid, u32 seq,
140                                          u8 cmd);
141
142 #endif /* datapath.h */