For SNAT, don't store the pre-fragment L2 header before actions are applied.
[sliver-openvswitch.git] / datapath / datapath.h
1 /* Interface exported by OpenFlow module. */
2
3 #ifndef DATAPATH_H
4 #define DATAPATH_H 1
5
6 #include <linux/kernel.h>
7 #include <linux/mutex.h>
8 #include <linux/netlink.h>
9 #include <linux/netdevice.h>
10 #include <linux/workqueue.h>
11 #include <linux/skbuff.h>
12 #include "openflow/openflow.h"
13 #include "openflow/nicira-ext.h"
14 #include "flow.h"
15
16
17 #define NL_FLOWS_PER_MESSAGE 100
18
19 #ifdef NDEBUG
20 #define dprintk(x...)
21 #else
22 #define dprintk(x...) printk(x)
23 #endif
24
25 /* Capabilities supported by this implementation. */
26 #define OFP_SUPPORTED_CAPABILITIES ( OFPC_FLOW_STATS \
27                 | OFPC_TABLE_STATS \
28                 | OFPC_PORT_STATS \
29                 | OFPC_MULTI_PHY_TX )
30
31 /* Actions supported by this implementation. */
32 #define OFP_SUPPORTED_ACTIONS ( (1 << OFPAT_OUTPUT) \
33                 | (1 << OFPAT_SET_VLAN_VID) \
34                 | (1 << OFPAT_SET_VLAN_PCP) \
35                 | (1 << OFPAT_STRIP_VLAN) \
36                 | (1 << OFPAT_SET_DL_SRC) \
37                 | (1 << OFPAT_SET_DL_DST) \
38                 | (1 << OFPAT_SET_NW_SRC) \
39                 | (1 << OFPAT_SET_NW_DST) \
40                 | (1 << OFPAT_SET_TP_SRC) \
41                 | (1 << OFPAT_SET_TP_DST) )
42
43 struct sk_buff;
44
45 #define DP_MAX_PORTS 255
46
47 struct datapath {
48         int dp_idx;
49
50         struct timer_list timer;        /* Expiration timer. */
51         struct sw_chain *chain;  /* Forwarding rules. */
52         struct task_struct *dp_task; /* Kernel thread for maintenance. */
53
54         /* Data related to the "of" device of this datapath */
55         struct net_device *netdev;
56
57         /* Configuration set from controller */
58         uint16_t flags;
59         uint16_t miss_send_len;
60
61         /* Flag controlling whether Flow End messages are generated. */
62         uint8_t send_flow_end;
63
64         /* Switch ports. */
65         struct net_bridge_port *ports[DP_MAX_PORTS];
66         struct net_bridge_port *local_port; /* OFPP_LOCAL port. */
67         struct list_head port_list; /* All ports, including local_port. */
68 };
69
70 /* Information necessary to reply to the sender of an OpenFlow message. */
71 struct sender {
72         uint32_t xid;           /* OpenFlow transaction ID of request. */
73         uint32_t pid;           /* Netlink process ID of sending socket. */
74         uint32_t seq;           /* Netlink sequence ID of request. */
75 };
76
77 struct net_bridge_port {
78         u16     port_no;
79         u32 config;             /* Some subset of OFPPC_* flags. */
80         u32 state;              /* Some subset of OFPPS_* flags. */
81         spinlock_t lock;
82         struct work_struct port_task;
83         struct datapath *dp;
84         struct net_device *dev;
85         struct snat_conf *snat;  /* Only set if SNAT is configured for this port. */
86         struct list_head node;   /* Element in datapath.ports. */
87 };
88
89 extern struct mutex dp_mutex;
90 extern struct notifier_block dp_device_notifier;
91
92 int dp_del_switch_port(struct net_bridge_port *);
93 int dp_xmit_skb(struct sk_buff *skb);
94 int dp_output_port(struct datapath *, struct sk_buff *, int out_port,
95                    int ignore_no_fwd);
96 int dp_output_control(struct datapath *, struct sk_buff *, uint32_t, 
97                         size_t, int);
98 void dp_set_origin(struct datapath *, uint16_t, struct sk_buff *);
99 int dp_send_features_reply(struct datapath *, const struct sender *);
100 int dp_send_config_reply(struct datapath *, const struct sender *);
101 int dp_send_port_status(struct net_bridge_port *p, uint8_t status);
102 int dp_send_flow_end(struct datapath *, struct sw_flow *,
103                          enum nx_flow_end_reason);
104 int dp_send_error_msg(struct datapath *, const struct sender *, 
105                         uint16_t, uint16_t, const void *, size_t);
106 int dp_update_port_flags(struct datapath *dp, const struct ofp_port_mod *opm);
107 int dp_send_echo_reply(struct datapath *, const struct sender *,
108                        const struct ofp_header *);
109 int dp_send_hello(struct datapath *, const struct sender *,
110                   const struct ofp_header *);
111
112 /* Should hold at least RCU read lock when calling */
113 struct datapath *dp_get(int dp_idx);
114
115 #endif /* datapath.h */