Break secchan into multiple files, to make it more maintainable.
[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 /* Behavior when the connection to the controller fails. */
44 enum fail_mode {
45     FAIL_OPEN,                  /* Act as learning switch. */
46     FAIL_CLOSED                 /* Drop all packets. */
47 };
48
49 /* Maximum number of management connection listeners. */
50 #define MAX_MGMT 8
51
52 /* Settings that may be configured by the user. */
53 struct settings {
54     /* Overall mode of operation. */
55     bool discovery;           /* Discover the controller automatically? */
56     bool in_band;             /* Connect to controller in-band? */
57
58     /* Related vconns and network devices. */
59     const char *dp_name;        /* Local datapath. */
60     const char *controller_name; /* Controller (if not discovery mode). */
61     const char *listener_names[MAX_MGMT]; /* Listen for mgmt connections. */
62     size_t n_listeners;          /* Number of mgmt connection listeners. */
63     const char *monitor_name;   /* Listen for traffic monitor connections. */
64
65     /* Failure behavior. */
66     enum fail_mode fail_mode; /* Act as learning switch if no controller? */
67     int max_idle;             /* Idle time for flows in fail-open mode. */
68     int probe_interval;       /* # seconds idle before sending echo request. */
69     int max_backoff;          /* Max # seconds between connection attempts. */
70
71     /* Packet-in rate-limiting. */
72     int rate_limit;           /* Tokens added to bucket per second. */
73     int burst_limit;          /* Maximum number token bucket size. */
74
75     /* Discovery behavior. */
76     regex_t accept_controller_regex;  /* Controller vconns to accept. */
77     const char *accept_controller_re; /* String version of regex. */
78     bool update_resolv_conf;          /* Update /etc/resolv.conf? */
79
80     /* Spanning tree protocol. */
81     bool enable_stp;
82 };
83
84 struct half {
85     struct rconn *rconn;
86     struct ofpbuf *rxbuf;
87     int n_txq;                  /* No. of packets queued for tx on 'rconn'. */
88 };
89
90 struct relay {
91     struct list node;
92
93 #define HALF_LOCAL 0
94 #define HALF_REMOTE 1
95     struct half halves[2];
96
97     bool is_mgmt_conn;
98 };
99
100 struct hook {
101     bool (*packet_cb[2])(struct relay *, void *aux);
102     void (*periodic_cb)(void *aux);
103     void (*wait_cb)(void *aux);
104     void *aux;
105 };
106
107 struct hook make_hook(bool (*local_packet_cb)(struct relay *, void *),
108                       bool (*remote_packet_cb)(struct relay *, void *),
109                       void (*periodic_cb)(void *),
110                       void (*wait_cb)(void *),
111                       void *aux);
112 struct ofp_packet_in *get_ofp_packet_in(struct relay *);
113 bool get_ofp_packet_eth_header(struct relay *, struct ofp_packet_in **,
114                                struct eth_header **);
115 void get_ofp_packet_payload(struct ofp_packet_in *, struct ofpbuf *);
116
117
118 #endif /* secchan.h */