Initial commit of vpp code.
[vpp.git] / vnet / vnet / vcgn / cnat_global.c
1 /* 
2  *------------------------------------------------------------------
3  * cnat_global.c - global variables
4  *
5  * Copyright (c) 2008-2009, 2012 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 /* gloable variables */
21
22 #include <vlib/vlib.h>
23 #include <vnet/vnet.h>
24 #include <vppinfra/error.h>
25 #include <vnet/buffer.h>
26
27 #include "dslite_defs.h"
28 #include "tcp_header_definitions.h"
29 u32 cnat_current_time;
30 u8 nfv9_configured = 0;
31 /* ctx/sf alloc error counters */
32 u32 null_enq_pkt;
33 u32 null_deq_pkt;
34
35 u32 null_enq_ctx;
36 u32 null_deq_ctx;
37
38 u32 null_enq_wqe;
39 u32 null_deq_wqe;
40
41 u32 ctx_alloc_errs;
42 u32 sf_alloc_errs;
43
44 u32 rcv_pkt_errs;
45
46 /* TOBE_PORTED : Remove following once we bring DSLite */
47 u32 dslite_config_debug_level = 1;
48 u32 dslite_data_path_debug_level = 1;
49 u32 dslite_defrag_debug_level = 1;
50 u32 dslite_debug_level = 1;
51
52 dslite_table_entry_t *dslite_table_db_ptr;
53
54 /*
55  * ipv4_decr_ttl_n_calc_csum()
56  * - It decrements the TTL and calculates the incremental IPv4 checksum
57  */
58
59 /* TOBE_PORTED: Following is in cnat_util.c */
60 always_inline
61 void ipv4_decr_ttl_n_calc_csum(ipv4_header *ipv4)
62 {
63     u32 checksum;
64     u16 old;
65     u16 ttl;
66
67     ttl = ipv4->ttl;
68     old = clib_net_to_host_u16(ttl);
69
70     /* Decrement TTL */
71     ipv4->ttl--;
72
73     /* Calculate incremental checksum */
74     checksum = old + (~clib_net_to_host_u16(ttl) & 0xFFFF);
75     checksum += clib_net_to_host_u16(ipv4->checksum);
76     checksum = (checksum & 0xFFFF) + (checksum >> 16);
77     ipv4->checksum = clib_host_to_net_u32(checksum + (checksum >> 16));
78 }
79