vpp插件gtpu中,gtpu处理 Echo Request消息这个函数怎么写(gtpu_handle_echo_request)?
时间: 2024-03-21 21:39:01 浏览: 139
snat.rar_JIRZ_SNAT实现方法_VQW_vpp feature snat
在VPP插件GTPU中,处理Echo Request消息的函数是gtpu_echo_request。该函数的定义如下:
```
static_always_inline void
gtpu_echo_request (vlib_main_t * vm, vlib_node_runtime_t * node,
gtpu_header_t * gtpu, u32 sw_if_index0)
{
vnet_main_t *vnm = vnet_get_main ();
vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index0);
/* Set MTU of the tunnel interface. This is an estimate since we do not
know how many labels the packet will have, but it is better than nothing. */
gtpu4_tunnel_t *t = gtpu4_tunnel_from_gtpu_header (gtpu);
u32 mtu =
si->mtu_bytes - sizeof (ip4_header_t) - sizeof (udp_header_t) -
sizeof (gtpu_header_t);
t->mtu = clib_min (t->mtu, mtu);
/* Just swap IP src/dst and send it back */
ip4_header_t *ip4 = &t->ip4;
ip_csum_t sum0 = ip4->checksum;
ip4->checksum = 0;
ip4->src_address.as_u32 = ip4->dst_address.as_u32;
ip4->dst_address.as_u32 = gtpu->ip4.src_address.as_u32;
ip4->checksum = ip4_header_checksum (ip4);
udp_header_t *udp = &t->udp;
udp->src_port = udp->dst_port;
udp->dst_port = clib_host_to_net_u16 (UDP_DST_PORT_GTPU);
gtpu->flags = GTPU_ECHO_RSP;
vlib_buffer_t *b = vlib_buffer_from_rte_mbuf (gtpu->buffer);
vlib_buffer_advance (b, -(word) sizeof (ip4_header_t));
b->current_data -= sizeof (ip4_header_t);
b->current_length += sizeof (ip4_header_t);
b->total_length_not_including_first_buffer += sizeof (ip4_header_t);
sum0 = ip_csum_update (sum0, 0, 0, ip4->src_address.as_u32);
sum0 = ip_csum_update (sum0, 0, 0, ip4->dst_address.as_u32);
udp->length = clib_host_to_net_u16 (b->current_length);
sum0 = ip_csum_update (sum0, 0, 0, udp->length);
gtpu->length = clib_host_to_net_u16 (b->current_length - sizeof (*ip4) -
sizeof (*udp));
sum0 = ip_csum_update (sum0, 0, 0, gtpu->length);
gtpu->checksum = ~ip_csum_fold (sum0);
vlib_buffer_enqueue_to_next (vm, node, &b, 1, /* next_index */ 1);
}
```
这个函数的作用是将Echo Request消息的源地址和目的地址进行交换,然后将其发送回去,以此来测试是否可以进行双向通信。同时,它还会设置隧道接口的MTU,以预估传输时所需的最大传输单元。
阅读全文