]> git.proxmox.com Git - ovs.git/blob - lib/conntrack-other.c
ofp-port: Drop of useless indirection in ofputil_pull_ofp14_port_stats().
[ovs.git] / lib / conntrack-other.c
1 /*
2 * Copyright (c) 2015, 2016 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <config.h>
18
19 #include "conntrack-private.h"
20 #include "dp-packet.h"
21
22 enum other_state {
23 OTHERS_FIRST,
24 OTHERS_MULTIPLE,
25 OTHERS_BIDIR,
26 };
27
28 struct conn_other {
29 struct conn up;
30 enum other_state state;
31 };
32
33 static const enum ct_timeout other_timeouts[] = {
34 [OTHERS_FIRST] = CT_TM_OTHER_FIRST,
35 [OTHERS_MULTIPLE] = CT_TM_OTHER_MULTIPLE,
36 [OTHERS_BIDIR] = CT_TM_OTHER_BIDIR,
37 };
38
39 static struct conn_other *
40 conn_other_cast(const struct conn *conn)
41 {
42 return CONTAINER_OF(conn, struct conn_other, up);
43 }
44
45 static enum ct_update_res
46 other_conn_update(struct conn *conn_, struct conntrack_bucket *ctb,
47 struct dp_packet *pkt OVS_UNUSED, bool reply, long long now)
48 {
49 struct conn_other *conn = conn_other_cast(conn_);
50
51 if (reply && conn->state != OTHERS_BIDIR) {
52 conn->state = OTHERS_BIDIR;
53 } else if (conn->state == OTHERS_FIRST) {
54 conn->state = OTHERS_MULTIPLE;
55 }
56
57 conn_update_expiration(ctb, &conn->up, other_timeouts[conn->state], now);
58
59 return CT_UPDATE_VALID;
60 }
61
62 static bool
63 other_valid_new(struct dp_packet *pkt OVS_UNUSED)
64 {
65 return true;
66 }
67
68 static struct conn *
69 other_new_conn(struct conntrack_bucket *ctb, struct dp_packet *pkt OVS_UNUSED,
70 long long now)
71 {
72 struct conn_other *conn;
73
74 conn = xzalloc(sizeof *conn);
75 conn->state = OTHERS_FIRST;
76
77 conn_init_expiration(ctb, &conn->up, other_timeouts[conn->state], now);
78
79 return &conn->up;
80 }
81
82 struct ct_l4_proto ct_proto_other = {
83 .new_conn = other_new_conn,
84 .valid_new = other_valid_new,
85 .conn_update = other_conn_update,
86 };