2 * Copyright (c) 2015-2019 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "conntrack-private.h"
20 #include "conntrack-tp.h"
21 #include "dp-packet.h"
23 enum OVS_PACKED_ENUM other_state
{
31 enum other_state state
; /* 'conn' lock protected. */
34 static const enum ct_timeout other_timeouts
[] = {
35 [OTHERS_FIRST
] = CT_TM_OTHER_FIRST
,
36 [OTHERS_MULTIPLE
] = CT_TM_OTHER_MULTIPLE
,
37 [OTHERS_BIDIR
] = CT_TM_OTHER_BIDIR
,
40 static struct conn_other
*
41 conn_other_cast(const struct conn
*conn
)
43 return CONTAINER_OF(conn
, struct conn_other
, up
);
46 static enum ct_update_res
47 other_conn_update(struct conntrack
*ct
, struct conn
*conn_
,
48 struct dp_packet
*pkt OVS_UNUSED
, bool reply
, long long now
)
50 struct conn_other
*conn
= conn_other_cast(conn_
);
51 enum ct_update_res ret
= CT_UPDATE_VALID
;
53 if (reply
&& conn
->state
!= OTHERS_BIDIR
) {
54 conn
->state
= OTHERS_BIDIR
;
55 } else if (conn
->state
== OTHERS_FIRST
) {
56 conn
->state
= OTHERS_MULTIPLE
;
57 ret
= CT_UPDATE_VALID_NEW
;
60 conn_update_expiration(ct
, &conn
->up
, other_timeouts
[conn
->state
], now
);
66 other_valid_new(struct dp_packet
*pkt OVS_UNUSED
)
72 other_new_conn(struct conntrack
*ct
, struct dp_packet
*pkt OVS_UNUSED
,
73 long long now
, uint32_t tp_id
)
75 struct conn_other
*conn
;
77 conn
= xzalloc(sizeof *conn
);
78 conn
->state
= OTHERS_FIRST
;
79 conn
->up
.tp_id
= tp_id
;
81 conn_init_expiration(ct
, &conn
->up
, other_timeouts
[conn
->state
], now
);
86 struct ct_l4_proto ct_proto_other
= {
87 .new_conn
= other_new_conn
,
88 .valid_new
= other_valid_new
,
89 .conn_update
= other_conn_update
,