linux路由基础知识(一)

avatar
作者
猴君
阅读量:1

内核路由表:fib_table

路由表项的增加和查询,fib_table_insert和fib_table_lookup。

跟踪fib_table_insert和fib_table_lookup两个接口。

#!/usr/bin/env bpftrace  #include <linux/pci.h> #include <linux/netdevice.h>  kprobe:fib_table_insert {     printf("fib_table_insert\n");     @[kstack]=count(); }  kprobe:fib_table_lookup {     printf("fib_table_lookup\n");     @[kstack]=count(); }

在创建路由的时候,可以捕获到fib_table_insert接口的使用。

正常的接受报文会触发路由表的查询。

1)一个是接收报文路径,会有入向input路由表的查找;

2)一个是用户态发起connec/bind,或者内核tcp接受路径回复ack的时候,会有出向output路由表的创建和查找。

[root@localhost leiyanjie]# bpftrace route.bt Attaching 2 probes... fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup fib_table_lookup ^C  @[     fib_table_lookup+1     ip_route_output_key_hash_rcu+942     ip_route_output_key_hash+90     ip_route_output_flow+25     inet_csk_route_req+221     tcp_conn_request+898     tcp_rcv_state_process+382     tcp_v4_do_rcv+186     tcp_v4_rcv+3577     ip_protocol_deliver_rcu+48     ip_local_deliver_finish+68     ip_local_deliver+255     ip_rcv+216     __netif_receive_skb_one_core+137     process_backlog+158     net_rx_action+309     __do_softirq+188     asm_call_sysvec_on_stack+15     do_softirq_own_stack+55     do_softirq.part.18+47     __local_bh_enable_ip+79     ip_finish_output2+384     ip_output+109     __ip_queue_xmit+359     __tcp_transmit_skb+2638     tcp_connect+2856     tcp_v4_connect+1237     __inet_stream_connect+210     inet_stream_connect+54     __sys_connect+154     __x64_sys_connect+22     do_syscall_64+48     entry_SYSCALL_64_after_hwframe+98 ]: 1 @[     fib_table_lookup+1     __inet_dev_addr_type.isra.28+167     __inet6_bind+675     __sys_bind+211     __x64_sys_bind+22     do_syscall_64+48     entry_SYSCALL_64_after_hwframe+98 ]: 1 @[     fib_table_lookup+1     ip_route_output_key_hash_rcu+942     ip_route_output_key_hash+90     ip_route_output_flow+25     inet_csk_route_child_sock+286     tcp_v4_syn_recv_sock+912     tcp_v6_syn_recv_sock+1568     tcp_check_req+306     tcp_v4_rcv+2456     ip_protocol_deliver_rcu+48     ip_local_deliver_finish+68     ip_local_deliver+255     ip_rcv+216     __netif_receive_skb_one_core+137     process_backlog+158     net_rx_action+309     __do_softirq+188     asm_call_sysvec_on_stack+15     do_softirq_own_stack+55     do_softirq.part.18+47     __local_bh_enable_ip+79     ip_finish_output2+384     ip_output+109     __ip_queue_xmit+359     __tcp_transmit_skb+2638     tcp_rcv_synsent_state_process+1803     tcp_rcv_state_process+235     tcp_v4_do_rcv+186     __release_sock+121     release_sock+43     inet_stream_connect+65     __sys_connect+154     __x64_sys_connect+22     do_syscall_64+48     entry_SYSCALL_64_after_hwframe+98 ]: 1 @[     fib_table_lookup+1     ip_route_output_key_hash_rcu+942     ip_route_output_key_hash+90     ip_route_output_flow+25     ip_send_unicast_reply+480     tcp_v4_send_ack+648     tcp_v4_rcv+1259     ip_protocol_deliver_rcu+48     ip_local_deliver_finish+68     ip_local_deliver+255     ip_rcv+216     __netif_receive_skb_one_core+137     process_backlog+158     net_rx_action+309     __do_softirq+188     asm_call_sysvec_on_stack+15     do_softirq_own_stack+55     do_softirq.part.18+47     flush_smp_call_function_from_idle+68     do_idle+328     cpu_startup_entry+25     start_secondary+276     secondary_startup_64_no_verify+176 ]: 3 @[     fib_table_lookup+1     ip_route_output_key_hash_rcu+942     ip_route_output_key_hash+90     ip_route_output_flow+25     tcp_v4_connect+1209     __inet_stream_connect+210     inet_stream_connect+54     __sys_connect+154     __x64_sys_connect+22     do_syscall_64+48     entry_SYSCALL_64_after_hwframe+98 ]: 4 @[     fib_table_lookup+1     ip_route_output_key_hash_rcu+942     ip_route_output_key_hash+90     ip_route_output_flow+25     tcp_v4_connect+357     __inet_stream_connect+210     inet_stream_connect+54     __sys_connect+154     __x64_sys_connect+22     do_syscall_64+48     entry_SYSCALL_64_after_hwframe+98 ]: 4 @[     fib_table_lookup+1     ip_route_output_key_hash_rcu+942     ip_route_output_key_hash+90     tcp_v4_connect+943     __inet_stream_connect+210     inet_stream_connect+54     __sys_connect+154     __x64_sys_connect+22     do_syscall_64+48     entry_SYSCALL_64_after_hwframe+98 ]: 4 @[     fib_table_lookup+1     ip_route_input_slow+492     ip_route_input_rcu+609     ip_route_input_noref+37     ip_rcv_finish_core.isra.22+101     ip_rcv_finish+100     ip_rcv+216     __netif_receive_skb_one_core+137     process_backlog+158     net_rx_action+309     __do_softirq+188     asm_call_sysvec_on_stack+15     do_softirq_own_stack+55     do_softirq.part.18+47     flush_smp_call_function_from_idle+68     do_idle+328     cpu_startup_entry+25     start_secondary+276     secondary_startup_64_no_verify+176 ]: 11 @[     fib_table_lookup+1     __fib_validate_source+326     fib_validate_source+70     ip_route_input_slow+2498     ip_route_input_rcu+609     ip_route_input_noref+37     ip_rcv_finish_core.isra.22+101     ip_rcv_finish+100     ip_rcv+216     __netif_receive_skb_one_core+137     process_backlog+158     net_rx_action+309     __do_softirq+188     asm_call_sysvec_on_stack+15     do_softirq_own_stack+55     do_softirq.part.18+47     flush_smp_call_function_from_idle+68     do_idle+328     cpu_startup_entry+25     start_secondary+276     secondary_startup_64_no_verify+176 ]: 11

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!