FD.io VPP  v16.06
Vector Packet Processing
cnat_ipv4_icmp_query_inside_input_exception.c
Go to the documentation of this file.
1 /*
2  *---------------------------------------------------------------------------
3  * cnat_ipv4_icmp_query_inside_input_exception.c - cnat_ipv4_icmp_query_inside_input_exception node pipeline stage functions
4  *
5  * Copyright (c) 2008-2014 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 #include <vlib/vlib.h>
21 #include <vnet/vnet.h>
22 #include <vppinfra/error.h>
23 #include <vnet/buffer.h>
24 
25 #include "cnat_ipv4_icmp.h"
26 
27 #define foreach_cnat_ipv4_icmp_q_inside_input_exc_error \
28 _(CNAT_V4_ICMP_Q_I2O_E_T_PKT, "v4 icmp query i2o-e transmit") \
29 _(CNAT_V4_ICMP_Q_I2O_E_G_PKT, "v4 icmp query i2o-e gen icmp msg") \
30 _(CNAT_V4_ICMP_Q_I2O_E_D_PKT, "v4 icmp query i2o-e pkt drop") \
31 _(CNAT_V4_ICMP_Q_I2O_E_DC_PKT, "v4 icmp query i2o-e drop (no config)") \
32 _(CNAT_V4_ICMP_Q_I2O_E_DR_PKT, "v4 icmp query i2o-e drop (not in run state)") \
33 _(CNAT_V4_ICMP_Q_I2O_E_DD_PKT, "v4 icmp query i2o-e drop (no direct port)") \
34 _(CNAT_V4_ICMP_Q_I2O_E_DA_PKT, "v4 icmp query i2o-e drop (no any port)") \
35 _(CNAT_V4_ICMP_Q_I2O_E_DO_PKT, "v4 icmp query i2o-e drop (out of port limit)") \
36 _(CNAT_V4_ICMP_Q_I2O_E_DS_PKT, "v4 icmp query i2o_e drop (out of session db)")
37 
38 typedef enum {
39 #define _(sym,str) sym,
41 #undef _
44 
45 
47 #define _(sym,string) string,
49 #undef _
50 };
51 
52 typedef struct {
54  /* $$$$ add data here */
55 
56  /* convenience variables */
60 
61 typedef enum {
63  //CNAT_V4_ICMP_Q_E_I2O_GEN,
67 
68 #define CNAT_V4_ICMP_Q_E_I2O_GEN CNAT_V4_ICMP_Q_E_I2O_T
69 
72 
73 #define NSTAGES 2
74 
75 /*
76  * Use the generic buffer metadata + first line of packet data prefetch
77  * stage function from <api/pipeline.h>. This is usually a Good Idea.
78  */
79 #define stage0 generic_stage0
80 
81 static inline u32 last_stage (vlib_main_t *vm, vlib_node_runtime_t *node,
82  u32 bi)
83 {
84  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi);
85  int disposition = CNAT_V4_ICMP_Q_E_I2O_T;
86  int counter = CNAT_V4_ICMP_Q_I2O_E_T_PKT;
87 
89  u8 ipv4_hdr_len = (ip->version_hdr_len_words & 0xf) << 2;
90  icmp_v4_t *icmp = (icmp_v4_t *)((u8*)ip + ipv4_hdr_len);
92  u32 node_counter_base_index = n->error_heap_index;
93  vlib_error_main_t * em = &vm->error_main;
94 
95  cnat_key_t dest_info;
96  cnat_gen_icmp_info info;
99 
100  PLATFORM_CNAT_SET_RX_VRF(vnet_buffer(b0)->sw_if_index[VLIB_RX],
101  ki.k.k.vrf, CNAT_ICMP)
102 
103  ki.k.k.ipv4 =
104  clib_net_to_host_u32(ip->src_addr);
105  ki.k.k.port =
106  clib_net_to_host_u16(icmp->identifier);
107 
108  dest_info.k.port = 0;
109  dest_info.k.ipv4 = clib_net_to_host_u32(ip->dest_addr);
110  PLATFORM_CNAT_SET_RX_VRF(vnet_buffer(b0)->sw_if_index[VLIB_RX],
111  dest_info.k.vrf, CNAT_ICMP)
112 
114  &info, &dest_info);
115  if (PREDICT_TRUE(db != 0)) {
116 
118  printf("\nDUMPING ICMP PKT BEFORE\n");
119  print_icmp_pkt(ip);
120  }
121 
123  /*
124  * Decrement TTL and update IPv4 checksum
125  */
127  }
128 
129  /*
130  * step 6 do nat before fwd pkt
131  */
132  swap_ip_src_icmp_id(ip, icmp, db, db->in2out_key.k.vrf);
133 
135  printf("\nDUMPING ICMP PKT AFTER\n");
136  print_icmp_pkt(ip);
137  }
138 
139  /*
140  * update db for this pkt
141  */
144 
145  } else {
146  switch (info.error) {
147  case (CNAT_NO_VRF_RUN):
148  counter = CNAT_V4_ICMP_Q_I2O_E_DR_PKT;
149  break;
150  case (CNAT_OUT_LIMIT):
151  counter = CNAT_V4_ICMP_Q_I2O_E_DO_PKT;
152  break;
153  case (CNAT_NO_PORT_ANY):
154  case (CNAT_NO_POOL_ANY):
155  case (CNAT_BAD_INUSE_ANY):
156  case (CNAT_NOT_FOUND_ANY):
157  counter = CNAT_V4_ICMP_Q_I2O_E_DA_PKT;
158  break;
159  case (CNAT_INV_PORT_DIRECT):
160  case (CNAT_DEL_PORT_DIRECT):
161  case (CNAT_BAD_INUSE_DIRECT):
162  case (CNAT_NOT_FOUND_DIRECT):
163  counter = CNAT_V4_ICMP_Q_I2O_E_DD_PKT;
164  break;
165  case (CNAT_ERR_NO_SESSION_DB):
166  counter = CNAT_V4_ICMP_Q_I2O_E_DS_PKT;
167  break;
168  default:
169  counter = CNAT_V4_ICMP_Q_I2O_E_DC_PKT;
170  break;
171  }
172  /*
173  * send to icmp msg generate node
174  */
175  if (info.gen_icmp_msg == CNAT_ICMP_MSG) {
176  #if 0
177  u32 *fd = (u32*)ctx->feature_data;
178  fd[0] = info.svi_addr;
180  #endif
181  disposition = CNAT_V4_ICMP_Q_E_I2O_GEN;
182  counter = CNAT_V4_ICMP_Q_I2O_E_G_PKT;
183  } else {
184  disposition = CNAT_V4_ICMP_Q_E_I2O_D;
185  counter = CNAT_V4_ICMP_Q_I2O_E_D_PKT;
186  }
188  }
189 
190  em->counters[node_counter_base_index + counter] += 1;
191 
192  return disposition;
193 }
194 
195 #include <vnet/pipeline.h>
196 
198  vlib_node_runtime_t * node,
199  vlib_frame_t * frame)
200 {
201  return dispatch_pipeline (vm, node, frame);
202 }
203 
206  .name = "vcgn-v4-icmp-q-i2o-e",
207  .vector_size = sizeof (u32),
209 
212 
213  .n_next_nodes = CNAT_V4_ICMP_Q_E_I2O_NEXT,
214 
215  /* edit / add dispositions here */
216  .next_nodes = {
217  //[CNAT_V4_ICMP_Q_E_I2O_GEN] = "icmp_msg_gen", /* Currently it will go
218  //to ip4-input node. We have to port icmp msg generator node */
219  [CNAT_V4_ICMP_Q_E_I2O_T] = "ip4-input",
220  [CNAT_V4_ICMP_Q_E_I2O_D] = "error-drop",
221  },
222 };
223 
224 
226 {
228 
229  mp->vlib_main = vm;
230  mp->vnet_main = vnet_get_main();
231 
232  return 0;
233 }
234 
u32 error_heap_index
Definition: node.h:244
always_inline vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Definition: node_funcs.h:46
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
#define PREDICT_TRUE(x)
Definition: clib.h:98
#define NULL
Definition: clib.h:55
cnat_ipv4_icmp_q_inside_input_exc_main_t cnat_ipv4_icmp_q_inside_input_exc_main
void swap_ip_src_icmp_id(ipv4_header *ip, icmp_v4_t *icmp, cnat_main_db_entry_t *db, u16 vrf)
Definition: cnat_db.h:153
u32 icmp_debug_flag
#define foreach_cnat_ipv4_icmp_q_inside_input_exc_error
struct _vlib_node_registration vlib_node_registration_t
cnat_errno_t error
Definition: cnat_db.h:528
#define CNAT_DB_UPDATE_IN2OUT_TIMER
Definition: cnat_db.h:557
always_inline void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:184
vnet_main_t * vnet_get_main(void)
Definition: misc.c:45
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:109
cnat_main_db_entry_t * cnat_get_main_db_entry_v2(cnat_db_key_bucket_t *ki, port_pair_t port_pair_type, port_type_t port_type, cnat_gen_icmp_info *info, cnat_key_t *dest_info)
Definition: cnat_db_v2.c:1102
cnat_key_t k
Definition: cnat_db.h:113
#define PLATFORM_CNAT_SET_RX_VRF(ctx, rx_vrf, proto)
vlib_error_main_t error_main
Definition: main.h:124
#define PREDICT_FALSE(x)
Definition: clib.h:97
#define CNAT_DEBUG_DROP_ICMP
Definition: cnat_cli.h:89
u64 * counters
Definition: error.h:73
#define CNAT_ICMP
Definition: cnat_db.h:95
#define ARRAY_LEN(x)
Definition: clib.h:59
cnat_db_key_t k
Definition: cnat_db.h:108
#define DEBUG_I2O_DROP(debug_flag)
Definition: cnat_db.h:565
unsigned int u32
Definition: types.h:88
#define vnet_buffer(b)
Definition: buffer.h:300
static uword cnat_ipv4_icmp_q_inside_input_exc_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u64 uword
Definition: types.h:112
static char * cnat_ipv4_icmp_q_inside_input_exc_error_strings[]
unsigned char u8
Definition: types.h:56
always_inline void ipv4_decr_ttl_n_calc_csum(ipv4_header *ipv4)
Definition: cnat_global.c:61
#define CNAT_ICMP_DEST_UNREACHABLE
u32 in2out_forwarding_count
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:140
#define PLATFORM_HANDLE_TTL_DECREMENT
clib_error_t * cnat_ipv4_icmp_q_inside_input_exc_init(vlib_main_t *vm)
void print_icmp_pkt(ipv4_header *ip)
always_inline vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:69
vlib_node_registration_t cnat_ipv4_icmp_q_inside_input_exc_node
(constructor) VLIB_REGISTER_NODE (cnat_ipv4_icmp_q_inside_input_exc_node)
static u32 last_stage(vlib_main_t *vm, vlib_node_runtime_t *node, u32 bi)
Definition: defs.h:45
cnat_key_t in2out_key
Definition: cnat_db.h:201
cnat_icmp_msg_t gen_icmp_msg
Definition: cnat_db.h:529