|
Using ftrace: Noticed the syscall: 1 ftp-6551 [001] 79.062836: sys_socket <-system_call_fastpath 2 ftp-6551 [001] 79.062838: security_socket_create <-__sock_create 3 ftp-6551 [001] 79.062838: cap_socket_create <-security_socket_create 4 ftp-6551 [001] 79.062843: __unix_insert_socket <-unix_create1 5 ftp-6551 [001] 79.062844: security_socket_post_create <-__sock_create 6 ftp-6551 [001] 79.062844: cap_socket_post_create <-security_socket_post_create 7 ftp-6551 [001] 79.062847: security_socket_connect <-sys_connect 8 ftp-6551 [001] 79.062848: cap_socket_connect <-security_socket_connect 9 ftp-6551 [001] 79.062849: __unix_insert_socket <-unix_create1 10 ftp-6551 [001] 79.062855: __unix_remove_socket <-unix_release_sock 11 ftp-6551 [001] 79.062858: __unix_remove_socket <-unix_release_sock 12 ftp-6551 [001] 79.062864: sys_socket <-system_call_fastpath 13 ftp-6551 [001] 79.062864: security_socket_create <-__sock_create and here noticed that fastpathis used: 23 ftp-6551 [001] 79.063083: sys_socket <-system_call_fastpath 24 ftp-6551 [001] 79.063084: security_socket_create <-__sock_create 25 ftp-6551 [001] 79.063084: cap_socket_create <-security_socket_create 26 ftp-6551 [001] 79.063086: __unix_insert_socket <-unix_create1 >From here onwards noticed the tcp APIs are used: 141 ftp-6551 [001] 79.063367: tcp_options <-tcp_new 142 ftp-6551 [001] 79.063369: tcp_packet <-nf_conntrack_in 143 ftp-6551 [001] 79.063373: ipv4_confirm <-nf_iterate 144 ftp-6551 [001] 79.063379: ipv4_conntrack_defrag <-nf_iterate 145 ftp-6551 [001] 79.063379: ipv4_conntrack_in <-nf_iterate 146 ftp-6551 [001] 79.063382: ipv4_confirm <-nf_iterate 147 ftp-6551 [001] 79.063383: tcp_v4_rcv <-ip_local_deliver_finish 148 ftp-6551 [001] 79.063385: cap_socket_sock_rcv_skb <-security_sock_rcv_skb And looking into tcp_v4_do_rcv(): 149 ftp-6551 [001] 79.063386: tcp_v4_do_rcv <-tcp_v4_rcv 150 ftp-6551 [001] 79.063386: tcp_parse_md5sig_option <-tcp_v4_do_rcv 151 ftp-6551 [001] 79.063387: tcp_rcv_state_process <-tcp_v4_do_rcv 152 ftp-6551 [001] 79.063387: tcp_v4_conn_request <-tcp_rcv_state_process 153 ftp-6551 [001] 79.063388: tcp_parse_options <-tcp_v4_conn_request 154 ftp-6551 [001] 79.063391: tcp_make_synack <-__tcp_v4_send_synack the function is a function pointer in the following structure: 2379 struct proto tcp_prot = { 2380 .name = "TCP", 2381 .owner = THIS_MODULE, 2382 .close = tcp_close, 2383 .connect = tcp_v4_connect, 2384 .disconnect = tcp_disconnect, 2385 .accept = inet_csk_accept, 2386 .ioctl = tcp_ioctl, 2387 .init = tcp_v4_init_sock, 2388 .destroy = tcp_v4_destroy_sock, 2389 .shutdown = tcp_shutdown, 2390 .setsockopt = tcp_setsockopt, 2391 .getsockopt = tcp_getsockopt, 2392 .recvmsg = tcp_recvmsg, 2393 .backlog_rcv = tcp_v4_do_rcv, 2394 .hash = inet_hash, 2395 .unhash = inet_unhash, 2396 .get_port = inet_csk_get_port, 2397 .enter_memory_pressure = tcp_enter_memory_pressure, 2398 .sockets_allocated = &tcp_sockets_allocated, 2399 .orphan_count = &tcp_orphan_count, 2400 .memory_allocated = &tcp_memory_allocated, 2401 .memory_pressure = &tcp_memory_pressure, 2402 .sysctl_mem = sysctl_tcp_mem, 2403 .sysctl_wmem = sysctl_tcp_wmem, 2404 .sysctl_rmem = sysctl_tcp_rmem, 2405 .max_header = MAX_TCP_HEADER, 2406 .obj_size = sizeof(struct tcp_sock), 2407 .slab_flags = SLAB_DESTROY_BY_RCU, 2408 .twsk_prot = &tcp_timewait_sock_ops, 2409 .rsk_prot = &tcp_request_sock_ops, 2410 .h.hashinfo = &tcp_hashinfo, 2411 #ifdef CONFIG_COMPAT 2412 .compat_setsockopt = compat_tcp_setsockopt, 2413 .compat_getsockopt = compat_tcp_getsockopt, 2414 #endif 2415 }; and the function is called by tcp_v4_rcv(): 1521 /* 1522 * From tcp_input.c 1523 */ 1524 1525 int tcp_v4_rcv(struct sk_buff *skb) 1526 { 1527 const struct iphdr *iph; 1528 struct tcphdr *th; 1529 struct sock *sk; 1530 int ret; 1531 struct net *net = dev_net(skb->dev); 1532 1533 if (skb->pkt_type != PACKET_HOST) 1534 goto discard_it; 1535 1536 /* Count it even if it's bad */ 1537 TCP_INC_STATS_BH(net, TCP_MIB_INSEGS); 1538 1539 if (!pskb_may_pull(skb, sizeof(struct tcphdr))) 1540 goto discard_it; 1541 1542 th = tcp_hdr(skb); 1543 1544 if (th->doff < sizeof(struct tcphdr) / 4) 1545 goto bad_packet; 1546 if (!pskb_may_pull(skb, th->doff * 4)) 1547 goto discard_it; 1548 1549 /* An explanation is required here, I think. 1550 * Packet length and doff are validated by header prediction, 1551 * provided case of th->doff==0 is eliminated. 1552 * So, we defer the checks. */ 1553 if (!skb_csum_unnecessary(skb) && tcp_v4_checksum_init(skb)) 1554 goto bad_packet; 1555 1556 th = tcp_hdr(skb); where tcp_v4_rcv() is a function pointer of handler: 1414 static struct net_protocol tcp_protocol = { 1415 .handler = tcp_v4_rcv, 1416 .err_handler = tcp_v4_err, 1417 .gso_send_check = tcp_v4_gso_send_check, 1418 .gso_segment = tcp_tso_segment, 1419 .gro_receive = tcp4_gro_receive, 1420 .gro_complete = tcp4_gro_complete, 1421 .no_policy = 1, 1422 .netns_ok = 1, 1423 }; 1424 1425 static struct net_protocol udp_protocol = { 1426 .handler = udp_rcv, 1427 .err_handler = udp_err, 1428 .no_policy = 1, 1429 .netns_ok = 1, 1430 }; 1431 and the callers of handler() are: icmp.c: icmp_pointers[icmph->type].handler(skb); ip_input.c: ret = ipprot->handler(skb); tunnel4.c: if (!handler->handler(skb)) tunnel4.c: if (!handler->handler(skb)) and caller inside ip_input.c are: 192 static int ip_local_deliver_finish(struct sk_buff *skb) 193 { 194 struct net *net = dev_net(skb->dev); 195 196 __skb_pull(skb, ip_hdrlen(skb)); 197 198 /* Point into the IP datagram, just past the header. */ 199 skb_reset_transport_header(skb); 200 201 rcu_read_lock(); 202 { 203 int protocol = ip_hdr(skb)->protocol; 204 int hash, raw; 205 struct net_protocol *ipprot; 206 207 resubmit: 208 raw = raw_local_deliver(skb, protocol); 209 210 hash = protocol & (MAX_INET_PROTOS - 1); 211 ipprot = rcu_dereference(inet_protos[hash]); 212 if (ipprot != NULL) { 213 int ret; 214 215 if (!net_eq(net, &init_net) && !ipprot->netns_ok) { 216 if (net_ratelimit()) 217 printk("%s: proto %d isn't netns-ready\n", 218 __func__, protocol); 219 kfree_skb(skb); 220 goto out; 221 } 222 223 if (!ipprot->no_policy) { 224 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { 225 kfree_skb(skb); 226 goto out; 227 } 228 nf_reset(skb); 229 } 230 ret = ipprot->handler(skb); 231 if (ret < 0) { 232 protocol = -ret; 233 goto resubmit; 234 } 235 IP_INC_STATS_BH(net, IPSTATS_MIB_INDELIVERS); 236 } else { 237 if (!raw) { 238 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { 239 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS); 240 icmp_send(skb, ICMP_DEST_UNREACH, 241 ICMP_PROT_UNREACH, 0); And others API defined in same file are: 1 EXPORT_SYMBOL_GPL(tcp_twsk_unique); 2 EXPORT_SYMBOL(tcp_v4_md5_lookup); 3 EXPORT_SYMBOL(tcp_v4_md5_do_add); 4 EXPORT_SYMBOL(tcp_v4_md5_do_del); 5 EXPORT_SYMBOL(tcp_v4_md5_hash_skb); 6 EXPORT_SYMBOL(tcp_v4_destroy_sock); 7 EXPORT_SYMBOL(tcp4_gro_receive); 8 EXPORT_SYMBOL(tcp4_gro_complete); 9 EXPORT_SYMBOL(ipv4_specific); 10 EXPORT_SYMBOL(tcp_hashinfo); 11 EXPORT_SYMBOL(tcp_prot); 12 EXPORT_SYMBOL(tcp_v4_conn_request); 13 EXPORT_SYMBOL(tcp_v4_connect); 14 EXPORT_SYMBOL(tcp_v4_do_rcv); 15 EXPORT_SYMBOL(tcp_v4_remember_stamp); 16 EXPORT_SYMBOL(tcp_v4_send_check); 17 EXPORT_SYMBOL(tcp_v4_syn_recv_sock); 18 EXPORT_SYMBOL(tcp_proc_register); 19 EXPORT_SYMBOL(tcp_proc_unregister); 20 EXPORT_SYMBOL(sysctl_tcp_low_latency); and continuing: 155 ftp-6551 [001] 79.063391: tcp_select_initial_window <-tcp_make_synack 156 ftp-6551 [001] 79.063392: tcp_v4_reqsk_md5_lookup <-tcp_make_synack 157 ftp-6551 [001] 79.063392: tcp_options_write <-tcp_make_synack 158 ftp-6551 [001] 79.063393: ipv4_conntrack_defrag <-nf_iterate 159 ftp-6551 [001] 79.063393: ipv4_conntrack_local <-nf_iterate 160 ftp-6551 [001] 79.063393: ipv4_get_l4proto <-nf_conntrack_in 161 ftp-6551 [001] 79.063394: tcp_error <-nf_conntrack_in 162 ftp-6551 [001] 79.063394: ipv4_pkt_to_tuple <-nf_ct_get_tuple 163 ftp-6551 [001] 79.063394: tcp_pkt_to_tuple <-nf_ct_get_tuple 164 ftp-6551 [001] 79.063395: tcp_packet <-nf_conntrack_in 165 ftp-6551 [001] 79.063395: tcp_options <-tcp_packet 166 ftp-6551 [001] 79.063397: ipv4_confirm <-nf_iterate 167 ftp-6551 [001] 79.063399: ipv4_conntrack_defrag <-nf_iterate 168 ftp-6551 [001] 79.063399: ipv4_conntrack_in <-nf_iterate 169 ftp-6551 [001] 79.063400: ipv4_confirm <-nf_iterate 170 ftp-6551 [001] 79.063400: tcp_v4_rcv <-ip_local_deliver_finish 171 ftp-6551 [001] 79.063401: cap_socket_sock_rcv_skb <-security_sock_rcv_skb 172 ftp-6551 [001] 79.063403: tcp_v4_do_rcv <-release_sock 173 ftp-6551 [001] 79.063403: tcp_parse_md5sig_option <-tcp_v4_do_rcv 174 ftp-6551 [001] 79.063403: tcp_rcv_state_process <-tcp_v4_do_rcv 175 ftp-6551 [001] 79.063404: tcp_parse_options <-tcp_rcv_state_process 176 ftp-6551 [001] 79.063404: tcp_ack <-tcp_rcv_state_process 177 ftp-6551 [001] 79.063405: tcp_fast_path_on <-tcp_ack |
