For SNAT, don't store the pre-fragment L2 header before actions are applied.
[sliver-openvswitch.git] / secchan / secchan.h
1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2  * Junior University
3  *
4  * We are making the OpenFlow specification and associated documentation
5  * (Software) available for public use and benefit with the expectation
6  * that others will use, modify and enhance the Software and contribute
7  * those enhancements back to the community. However, since we would
8  * like to make the Software available for broadest use, with as few
9  * restrictions as possible permission is hereby granted, free of
10  * charge, to any person obtaining a copy of this Software to deal in
11  * the Software under the copyrights without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  *
29  * The name and trademarks of copyright holder(s) may NOT be used in
30  * advertising or publicity pertaining to the Software or any
31  * derivatives without specific, written prior permission.
32  */
33
34 #ifndef SECCHAN_H
35 #define SECCHAN_H 1
36
37 #include <regex.h>
38 #include <stdbool.h>
39 #include <stddef.h>
40 #include "list.h"
41 #include "packets.h"
42
43 struct secchan;
44
45 /* Behavior when the connection to the controller fails. */
46 enum fail_mode {
47     FAIL_OPEN,                  /* Act as learning switch. */
48     FAIL_CLOSED                 /* Drop all packets. */
49 };
50
51 /* Maximum number of management connection listeners. */
52 #define MAX_MGMT 8
53
54 /* Settings that may be configured by the user. */
55 struct settings {
56     /* Overall mode of operation. */
57     bool discovery;           /* Discover the controller automatically? */
58     bool in_band;             /* Connect to controller in-band? */
59
60     /* Related vconns and network devices. */
61     const char *dp_name;        /* Local datapath. */
62     const char *controller_name; /* Controller (if not discovery mode). */
63     const char *listener_names[MAX_MGMT]; /* Listen for mgmt connections. */
64     size_t n_listeners;          /* Number of mgmt connection listeners. */
65     const char *monitor_name;   /* Listen for traffic monitor connections. */
66
67     /* Failure behavior. */
68     enum fail_mode fail_mode; /* Act as learning switch if no controller? */
69     int max_idle;             /* Idle time for flows in fail-open mode. */
70     int probe_interval;       /* # seconds idle before sending echo request. */
71     int max_backoff;          /* Max # seconds between connection attempts. */
72
73     /* Packet-in rate-limiting. */
74     int rate_limit;           /* Tokens added to bucket per second. */
75     int burst_limit;          /* Maximum number token bucket size. */
76
77     /* Discovery behavior. */
78     regex_t accept_controller_regex;  /* Controller vconns to accept. */
79     const char *accept_controller_re; /* String version of regex. */
80     bool update_resolv_conf;          /* Update /etc/resolv.conf? */
81
82     /* Spanning tree protocol. */
83     bool enable_stp;
84
85     /* Remote command execution. */
86     char *command_acl;          /* Command white/blacklist, as shell globs. */
87     char *command_dir;          /* Directory that contains commands. */
88
89     /* NetFlow logging. */
90     char *netflow_dst;          /* Host and port to send NetFlow traffic. */
91 };
92
93 struct half {
94     struct rconn *rconn;
95     struct ofpbuf *rxbuf;
96     int n_txq;                  /* No. of packets queued for tx on 'rconn'. */
97 };
98
99 struct relay {
100     struct list node;
101
102 #define HALF_LOCAL 0
103 #define HALF_REMOTE 1
104     struct half halves[2];
105
106     /* The secchan has a primary connection (relay) to an OpenFlow controller.
107      * This primary connection actually makes two connections to the datapath:
108      * one for OpenFlow requests and responses, and one that is only used for
109      * receiving asynchronous events such as 'ofp_packet_in' events.  This
110      * design keeps replies to OpenFlow requests from being dropped by the
111      * kernel due to a flooded network device.
112      *
113      * The secchan may also have any number of secondary "management"
114      * connections (relays).  These connections do not receive asychronous
115      * events and thus have a null 'async_rconn'. */
116     bool is_mgmt_conn;          /* Is this a management connection? */
117     struct rconn *async_rconn;  /* For receiving asynchronous events. */
118 };
119
120 struct hook_class {
121     bool (*local_packet_cb)(struct relay *, void *aux);
122     bool (*remote_packet_cb)(struct relay *, void *aux);
123     void (*periodic_cb)(void *aux);
124     void (*wait_cb)(void *aux);
125     void (*closing_cb)(struct relay *, void *aux);
126 };
127
128 void add_hook(struct secchan *, const struct hook_class *, void *);
129
130 struct ofp_packet_in *get_ofp_packet_in(struct relay *);
131 bool get_ofp_packet_eth_header(struct relay *, struct ofp_packet_in **,
132                                struct eth_header **);
133 void get_ofp_packet_payload(struct ofp_packet_in *, struct ofpbuf *);
134
135
136 #endif /* secchan.h */