X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat_det_in2out.c;h=b9b940559b6fc72f72aa4221031157eb96fd7767;hb=e3621518046ad7f37ccf77c549a93375ab89da19;hp=22b76373731c227740f8a538522328f64765de6c;hpb=1c2ac860ed9a80dac539af6408d70f7dfd2c238e;p=vpp.git diff --git a/src/plugins/nat/nat_det_in2out.c b/src/plugins/nat/nat_det_in2out.c index 22b76373731..b9b940559b6 100644 --- a/src/plugins/nat/nat_det_in2out.c +++ b/src/plugins/nat/nat_det_in2out.c @@ -26,6 +26,7 @@ #include #include #include +#include typedef struct { @@ -85,6 +86,7 @@ format_nat_det_in2out_trace (u8 * s, va_list * args) * @param[in,out] node NAT node runtime * @param[in] thread_index thread index * @param[in,out] b0 buffer containing packet to be translated + * @param[in,out] ip0 ip header * @param[out] p_proto protocol used for matching * @param[out] p_value address and port after NAT translation * @param[out] p_dont_translate if packet should not be translated @@ -94,16 +96,17 @@ format_nat_det_in2out_trace (u8 * s, va_list * args) u32 icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node, u32 thread_index, vlib_buffer_t * b0, - ip4_header_t * ip0, u8 * p_proto, - snat_session_key_t * p_value, u8 * p_dont_translate, - void *d, void *e) + ip4_header_t * ip0, ip4_address_t * addr, + u16 * port, u32 * fib_index, + nat_protocol_t * proto, void *d, void *e, + u8 * dont_translate) { + vlib_main_t *vm = vlib_get_main (); icmp46_header_t *icmp0; u32 sw_if_index0; u32 rx_fib_index0; - u8 protocol; + nat_protocol_t protocol; snat_det_out_key_t key0; - u8 dont_translate = 0; u32 next0 = ~0; icmp_echo_header_t *echo0, *inner_echo0 = 0; ip4_header_t *inner_ip0; @@ -115,6 +118,7 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node, snat_det_session_t *ses0 = 0; ip4_address_t in_addr; u16 in_port; + *dont_translate = 0; icmp0 = (icmp46_header_t *) ip4_next_header (ip0); echo0 = (icmp_echo_header_t *) (icmp0 + 1); @@ -124,7 +128,7 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node, if (!icmp_type_is_error_message (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags)) { - protocol = SNAT_PROTOCOL_ICMP; + protocol = NAT_PROTOCOL_ICMP; in_addr = ip0->src_address; in_port = vnet_buffer (b0)->ip.reass.l4_src_port; } @@ -133,17 +137,17 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node, /* if error message, then it's not fragmented and we can access it */ inner_ip0 = (ip4_header_t *) (echo0 + 1); l4_header = ip4_next_header (inner_ip0); - protocol = ip_proto_to_snat_proto (inner_ip0->protocol); + protocol = ip_proto_to_nat_proto (inner_ip0->protocol); in_addr = inner_ip0->dst_address; switch (protocol) { - case SNAT_PROTOCOL_ICMP: + case NAT_PROTOCOL_ICMP: inner_icmp0 = (icmp46_header_t *) l4_header; inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1); in_port = inner_echo0->identifier; break; - case SNAT_PROTOCOL_UDP: - case SNAT_PROTOCOL_TCP: + case NAT_PROTOCOL_UDP: + case NAT_PROTOCOL_TCP: in_port = ((tcp_udp_header_t *) l4_header)->dst_port; break; default: @@ -162,7 +166,7 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node, IP_PROTOCOL_ICMP, rx_fib_index0))) { - dont_translate = 1; + *dont_translate = 1; goto out; } next0 = NAT_DET_IN2OUT_NEXT_DROP; @@ -182,7 +186,7 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node, IP_PROTOCOL_ICMP, rx_fib_index0))) { - dont_translate = 1; + *dont_translate = 1; goto out; } if (icmp0->type != ICMP4_echo_request) @@ -225,20 +229,19 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node, goto out; } - u32 now = (u32) vlib_time_now (sm->vlib_main); + u32 now = (u32) vlib_time_now (vm); ses0->state = SNAT_SESSION_ICMP_ACTIVE; ses0->expire = now + sm->icmp_timeout; out: - *p_proto = protocol; + *proto = protocol; if (ses0) { - p_value->addr = new_addr0; - p_value->fib_index = sm->outside_fib_index; - p_value->port = ses0->out.out_port; + *addr = new_addr0; + *fib_index = sm->outside_fib_index; + *port = ses0->out.out_port; } - *p_dont_translate = dont_translate; if (d) *(snat_det_session_t **) d = ses0; if (e) @@ -332,9 +335,9 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm, goto trace0; } - proto0 = ip_proto_to_snat_proto (ip0->protocol); + proto0 = ip_proto_to_nat_proto (ip0->protocol); - if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP)) + if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP)) { rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0); @@ -409,7 +412,7 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm, src_address /* changed member */ ); ip0->checksum = ip_csum_fold (sum0); - if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP)) + if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP)) { if (tcp0->flags & TCP_FLAG_SYN) ses0->state = SNAT_SESSION_TCP_SYN_SENT; @@ -436,7 +439,7 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm, sum0 = ip_csum_update (sum0, old_port0, new_port0, ip4_header_t /* cheat */ , length /* changed member */ ); - mss_clamping (sm, tcp0, &sum0); + mss_clamping (sm->mss_clamping, tcp0, &sum0); tcp0->checksum = ip_csum_fold (sum0); } else @@ -505,9 +508,9 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm, goto trace1; } - proto1 = ip_proto_to_snat_proto (ip1->protocol); + proto1 = ip_proto_to_nat_proto (ip1->protocol); - if (PREDICT_FALSE (proto1 == SNAT_PROTOCOL_ICMP)) + if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_ICMP)) { rx_fib_index1 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index1); @@ -582,7 +585,7 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm, src_address /* changed member */ ); ip1->checksum = ip_csum_fold (sum1); - if (PREDICT_TRUE (proto1 == SNAT_PROTOCOL_TCP)) + if (PREDICT_TRUE (proto1 == NAT_PROTOCOL_TCP)) { if (tcp1->flags & TCP_FLAG_SYN) ses1->state = SNAT_SESSION_TCP_SYN_SENT; @@ -609,7 +612,7 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm, sum1 = ip_csum_update (sum1, old_port1, new_port1, ip4_header_t /* cheat */ , length /* changed member */ ); - mss_clamping (sm, tcp1, &sum1); + mss_clamping (sm->mss_clamping, tcp1, &sum1); tcp1->checksum = ip_csum_fold (sum1); } else @@ -714,9 +717,9 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm, goto trace00; } - proto0 = ip_proto_to_snat_proto (ip0->protocol); + proto0 = ip_proto_to_nat_proto (ip0->protocol); - if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP)) + if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP)) { rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0); @@ -791,7 +794,7 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm, src_address /* changed member */ ); ip0->checksum = ip_csum_fold (sum0); - if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP)) + if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP)) { if (tcp0->flags & TCP_FLAG_SYN) ses0->state = SNAT_SESSION_TCP_SYN_SENT; @@ -818,7 +821,7 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm, sum0 = ip_csum_update (sum0, old_port0, new_port0, ip4_header_t /* cheat */ , length /* changed member */ ); - mss_clamping (sm, tcp0, &sum0); + mss_clamping (sm->mss_clamping, tcp0, &sum0); tcp0->checksum = ip_csum_fold (sum0); } else