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