Branch data Line data Source code
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 : : #ifndef CONNTRACK_PRIVATE_H
18 : : #define CONNTRACK_PRIVATE_H 1
19 : :
20 : : #include <sys/types.h>
21 : : #include <netinet/in.h>
22 : : #include <netinet/ip6.h>
23 : :
24 : : #include "conntrack.h"
25 : : #include "ct-dpif.h"
26 : : #include "openvswitch/hmap.h"
27 : : #include "openvswitch/list.h"
28 : : #include "openvswitch/types.h"
29 : : #include "packets.h"
30 : : #include "unaligned.h"
31 : :
32 : : struct ct_addr {
33 : : union {
34 : : ovs_16aligned_be32 ipv4;
35 : : union ovs_16aligned_in6_addr ipv6;
36 : : ovs_be32 ipv4_aligned;
37 : : struct in6_addr ipv6_aligned;
38 : : };
39 : : };
40 : :
41 : : struct ct_endpoint {
42 : : struct ct_addr addr;
43 : : union {
44 : : ovs_be16 port;
45 : : struct {
46 : : ovs_be16 icmp_id;
47 : : uint8_t icmp_type;
48 : : uint8_t icmp_code;
49 : : };
50 : : };
51 : : };
52 : :
53 : : /* Changes to this structure need to be reflected in conn_key_hash() */
54 : : struct conn_key {
55 : : struct ct_endpoint src;
56 : : struct ct_endpoint dst;
57 : :
58 : : ovs_be16 dl_type;
59 : : uint8_t nw_proto;
60 : : uint16_t zone;
61 : : };
62 : :
63 : : struct conn {
64 : : struct conn_key key;
65 : : struct conn_key rev_key;
66 : : long long expiration;
67 : : struct ovs_list exp_node;
68 : : struct hmap_node node;
69 : : uint32_t mark;
70 : : ovs_u128 label;
71 : : };
72 : :
73 : : enum ct_update_res {
74 : : CT_UPDATE_INVALID,
75 : : CT_UPDATE_VALID,
76 : : CT_UPDATE_NEW,
77 : : };
78 : :
79 : : struct ct_l4_proto {
80 : : struct conn *(*new_conn)(struct conntrack_bucket *, struct dp_packet *pkt,
81 : : long long now);
82 : : bool (*valid_new)(struct dp_packet *pkt);
83 : : enum ct_update_res (*conn_update)(struct conn *conn,
84 : : struct conntrack_bucket *,
85 : : struct dp_packet *pkt, bool reply,
86 : : long long now);
87 : : void (*conn_get_protoinfo)(const struct conn *,
88 : : struct ct_dpif_protoinfo *);
89 : : };
90 : :
91 : : extern struct ct_l4_proto ct_proto_tcp;
92 : : extern struct ct_l4_proto ct_proto_other;
93 : : extern struct ct_l4_proto ct_proto_icmp4;
94 : : extern struct ct_l4_proto ct_proto_icmp6;
95 : :
96 : : extern long long ct_timeout_val[];
97 : :
98 : : static inline void
99 : 531 : conn_init_expiration(struct conntrack_bucket *ctb, struct conn *conn,
100 : : enum ct_timeout tm, long long now)
101 : : {
102 : 531 : conn->expiration = now + ct_timeout_val[tm];
103 : 531 : ovs_list_push_back(&ctb->exp_lists[tm], &conn->exp_node);
104 : 531 : }
105 : :
106 : : static inline void
107 : 451 : conn_update_expiration(struct conntrack_bucket *ctb, struct conn *conn,
108 : : enum ct_timeout tm, long long now)
109 : : {
110 : 451 : ovs_list_remove(&conn->exp_node);
111 : 451 : conn_init_expiration(ctb, conn, tm, now);
112 : 451 : }
113 : :
114 : : #endif /* conntrack-private.h */
|