2 * Copyright (c) 2015, 2016 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.
20 #include <sys/types.h>
21 #include <netinet/in.h>
22 #include <netinet/icmp6.h>
24 #include "conntrack-private.h"
25 #include "dp-packet.h"
34 enum icmp_state state
;
37 static const enum ct_timeout icmp_timeouts
[] = {
38 [ICMPS_FIRST
] = CT_TM_ICMP_FIRST
,
39 [ICMPS_REPLY
] = CT_TM_ICMP_REPLY
,
42 static struct conn_icmp
*
43 conn_icmp_cast(const struct conn
*conn
)
45 return CONTAINER_OF(conn
, struct conn_icmp
, up
);
48 static enum ct_update_res
49 icmp_conn_update(struct conn
*conn_
, struct conntrack_bucket
*ctb
,
50 struct dp_packet
*pkt OVS_UNUSED
, bool reply
, long long now
)
52 struct conn_icmp
*conn
= conn_icmp_cast(conn_
);
54 if (reply
&& conn
->state
!= ICMPS_REPLY
) {
55 conn
->state
= ICMPS_REPLY
;
58 conn_update_expiration(ctb
, &conn
->up
, icmp_timeouts
[conn
->state
], now
);
60 return CT_UPDATE_VALID
;
64 icmp4_valid_new(struct dp_packet
*pkt
)
66 struct icmp_header
*icmp
= dp_packet_l4(pkt
);
68 return icmp
->icmp_type
== ICMP4_ECHO_REQUEST
69 || icmp
->icmp_type
== ICMP4_INFOREQUEST
70 || icmp
->icmp_type
== ICMP4_TIMESTAMP
;
74 icmp6_valid_new(struct dp_packet
*pkt
)
76 struct icmp6_header
*icmp6
= dp_packet_l4(pkt
);
78 return icmp6
->icmp6_type
== ICMP6_ECHO_REQUEST
;
82 icmp_new_conn(struct conntrack_bucket
*ctb
, struct dp_packet
*pkt OVS_UNUSED
,
85 struct conn_icmp
*conn
;
87 conn
= xzalloc(sizeof *conn
);
88 conn
->state
= ICMPS_FIRST
;
90 conn_init_expiration(ctb
, &conn
->up
, icmp_timeouts
[conn
->state
], now
);
95 struct ct_l4_proto ct_proto_icmp4
= {
96 .new_conn
= icmp_new_conn
,
97 .valid_new
= icmp4_valid_new
,
98 .conn_update
= icmp_conn_update
,
101 struct ct_l4_proto ct_proto_icmp6
= {
102 .new_conn
= icmp_new_conn
,
103 .valid_new
= icmp6_valid_new
,
104 .conn_update
= icmp_conn_update
,