• gdb attach + tcp fin + ack


    tcp fin

    [root@localhost ~]# ps -elf | grep print
    0 R root      10489  10488 99  80   0 - 8389208 -    22:32 pts/0    00:41:17 build/printreq -c1 -n1 -- 10.10.103.229 80
    0 S root      10603  10582  0  80   0 -  1729 pipe_w 23:13 pts/2    00:00:00 grep --color=auto print
    [root@localhost ~]# gdb attach 10489
    GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-119.el7
    Copyright (C) 2013 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "aarch64-redhat-linux-gnu".
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>...
    attach: No such file or directory.
    Attaching to process 10489
    Reading symbols from /data1/dpdk-19.11/demo/dpdk-simple-web/build/printreq...done.
    Reading symbols from /lib64/librt.so.1...Reading symbols from /usr/lib/debug/usr/lib64/librt-2.17.so.debug...done.
    done.
    Loaded symbols for /lib64/librt.so.1
    Reading symbols from /lib64/libm.so.6...Reading symbols from /usr/lib/debug/usr/lib64/libm-2.17.so.debug...done.
    done.
    Loaded symbols for /lib64/libm.so.6
    Reading symbols from /lib64/libnuma.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libnuma.so.1.0.0.debug...done.
    done.
    Loaded symbols for /lib64/libnuma.so.1
    Reading symbols from /lib64/libdl.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libdl-2.17.so.debug...done.
    done.
    Loaded symbols for /lib64/libdl.so.2
    Reading symbols from /lib64/libpthread.so.0...Reading symbols from /usr/lib/debug/usr/lib64/libpthread-2.17.so.debug...done.
    done.
    [New LWP 10491]
    [New LWP 10490]
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib64/libthread_db.so.1".
    Loaded symbols for /lib64/libpthread.so.0
    Reading symbols from /lib64/libc.so.6...Reading symbols from /usr/lib/debug/usr/lib64/libc-2.17.so.debug...done.
    done.
    Loaded symbols for /lib64/libc.so.6
    Reading symbols from /lib64/libgcc_s.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libgcc_s-4.8.5-20150702.so.1.debug...done.
    done.
    Loaded symbols for /lib64/libgcc_s.so.1
    Reading symbols from /lib/ld-linux-aarch64.so.1...Reading symbols from /usr/lib/debug/usr/lib64/ld-2.17.so.debug...done.
    done.
    Loaded symbols for /lib/ld-linux-aarch64.so.1
    hinic_recv_pkts (rx_queue=0x13feabe80, rx_pkts=0xffffc5f3bef0, nb_pkts=32)
        at /data1/dpdk-19.11/drivers/net/hinic/hinic_pmd_rx.c:970
    970             sw_ci = HINIC_GET_RQ_LOCAL_CI(rxq);
    (gdb) b process_tcp
    Breakpoint 1 at 0x468cc4: file /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c, line 515.
    (gdb) c
    Continuing.
    
    Breakpoint 1, process_tcp (mbuf=0x13e833a80, eh=eh@entry=0x13e833b80, iph=iph@entry=0x13e833b8e, ipv4_hdrlen=20, 
        len=len@entry=60) at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:515
    515             struct rte_tcp_hdr *tcph = (struct rte_tcp_hdr *)((unsigned char *)(iph) + ipv4_hdrlen);
    (gdb) s
    514     {
    (gdb) n
    515             struct rte_tcp_hdr *tcph = (struct rte_tcp_hdr *)((unsigned char *)(iph) + ipv4_hdrlen);
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    519             printf("TCP flags=%d
    ", tcph->tcp_flags);
    (gdb) n
    521             if (len < (int)(sizeof(struct rte_ether_hdr) + ipv4_hdrlen + sizeof(struct rte_tcp_hdr))) {
    (gdb) n
    527             if (tcph->dst_port != tcp_port)
    (gdb) n
    525                     return 0;
    (gdb) n
    527             if (tcph->dst_port != tcp_port)
    (gdb) n
    530             if ((tcph->tcp_flags & (TCP_SYN | TCP_ACK)) == TCP_SYN) {       // SYN packet, send SYN+ACK
    (gdb) n
    575             } else if (tcph->tcp_flags & TCP_FIN) { // FIN packet, send ACK
    (gdb) n
    577                     fprintf(stderr, "FIN packet
    ");
    (gdb) n
    579                     recv_tcp_fin_pkts++;
    (gdb) n
    580                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    579                     recv_tcp_fin_pkts++;
    (gdb) n
    580                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    581                     swap_4bytes((unsigned char *)&iph->src_addr, (unsigned char *)&iph->dst_addr);
    (gdb) n
    580                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    581                     swap_4bytes((unsigned char *)&iph->src_addr, (unsigned char *)&iph->dst_addr);
    (gdb) n
    583                     swap_4bytes((unsigned char *)&tcph->sent_seq, (unsigned char *)&tcph->recv_ack);
    (gdb) n
    582                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    585                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->recv_ack) + 1);
    (gdb) n
    582                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    583                     swap_4bytes((unsigned char *)&tcph->sent_seq, (unsigned char *)&tcph->recv_ack);
    (gdb) n
    582                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    585                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->recv_ack) + 1);
    (gdb) n
    584                     tcph->tcp_flags = TCP_ACK;
    (gdb) n
    585                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->recv_ack) + 1);
    (gdb) n
    586                     tcph->data_off = (sizeof(struct rte_tcp_hdr) / 4) << 4;
    (gdb) n
    588                     pkt_len = ipv4_hdrlen + sizeof(struct rte_tcp_hdr);
    (gdb) n
    585                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->recv_ack) + 1);
    (gdb) n
    586                     tcph->data_off = (sizeof(struct rte_tcp_hdr) / 4) << 4;
    (gdb) n
    583                     swap_4bytes((unsigned char *)&tcph->sent_seq, (unsigned char *)&tcph->recv_ack);
    (gdb) n
    587                     tcph->cksum = 0;
    (gdb) n
    592                     rte_pktmbuf_data_len(mbuf) = rte_pktmbuf_pkt_len(mbuf) = pkt_len + RTE_ETHER_HDR_LEN;
    (gdb) n
    589                     iph->total_length = rte_cpu_to_be_16(pkt_len);
    (gdb) n
    591                     iph->time_to_live = TTL;
    (gdb) n
    589                     iph->total_length = rte_cpu_to_be_16(pkt_len);
    (gdb) n
    590                     iph->hdr_checksum = 0;
    (gdb) n
    591                     iph->time_to_live = TTL;
    (gdb) n
    593                     if (hardware_cksum) {
    (gdb) n
    592                     rte_pktmbuf_data_len(mbuf) = rte_pktmbuf_pkt_len(mbuf) = pkt_len + RTE_ETHER_HDR_LEN;
    (gdb) n
    593                     if (hardware_cksum) {
    (gdb) n
    596                             mbuf->l2_len = RTE_ETHER_HDR_LEN;
    (gdb) n
    597                             mbuf->l3_len = ipv4_hdrlen;
    (gdb) n
    598                             mbuf->l4_len = 0;
    (gdb) n
    597                             mbuf->l3_len = ipv4_hdrlen;
    (gdb) n
    595                             mbuf->ol_flags = PKT_TX_IPV4 | PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM;
    (gdb) n
    599                             tcph->cksum = rte_ipv4_phdr_cksum((const struct rte_ipv4_hdr *)iph, 0);
    (gdb) n
    605                     printf("I will reply following:
    ");
    (gdb) n
    606                     dump_packet((unsigned char *)eh, rte_pktmbuf_data_len(mbuf));
    (gdb) n
    608                     int ret = rte_eth_tx_burst(0, 0, &mbuf, 1);
    (gdb) n
    609                     if (ret == 1)
    (gdb) n
    570                             return 1;
    (gdb) n
    776     }
    (gdb) n
    lcore_main () at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:1075
    1075                    for (i = 0; i < nb_rx; i++) {
    (gdb) c
    Continuing.

    tcp 三次握手

    Breakpoint 1, process_tcp (mbuf=0x13e7f5500, eh=eh@entry=0x13e7f5600, iph=iph@entry=0x13e7f560e, ipv4_hdrlen=20, 
        len=len@entry=74) at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:515
    515             struct rte_tcp_hdr *tcph = (struct rte_tcp_hdr *)((unsigned char *)(iph) + ipv4_hdrlen);
    (gdb) bt
    #0  process_tcp (mbuf=0x13e7f5500, eh=eh@entry=0x13e7f5600, iph=iph@entry=0x13e7f560e, ipv4_hdrlen=20, 
        len=len@entry=74) at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:515
    #1  0x0000000000465ef0 in lcore_main () at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:1104
    #2  main (argc=<optimized out>, argv=<optimized out>)
        at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:1227
    (gdb) n
    514     {
    (gdb) n
    515             struct rte_tcp_hdr *tcph = (struct rte_tcp_hdr *)((unsigned char *)(iph) + ipv4_hdrlen);
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    519             printf("TCP flags=%d
    ", tcph->tcp_flags);
    (gdb) n
    521             if (len < (int)(sizeof(struct rte_ether_hdr) + ipv4_hdrlen + sizeof(struct rte_tcp_hdr))) {
    (gdb) n
    527             if (tcph->dst_port != tcp_port)
    (gdb) n
    525                     return 0;
    (gdb) n
    527             if (tcph->dst_port != tcp_port)
    (gdb) n
    530             if ((tcph->tcp_flags & (TCP_SYN | TCP_ACK)) == TCP_SYN) {       // SYN packet, send SYN+ACK
    (gdb) n
    532                     printf("SYN packet
    ");
    (gdb) n
    534                     recv_tcp_syn_pkts++;
    (gdb) n
    536                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    534                     recv_tcp_syn_pkts++;
    (gdb) n
    536                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    537                     swap_4bytes((unsigned char *)&iph->src_addr, (unsigned char *)&iph->dst_addr);
    (gdb) n
    536                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    537                     swap_4bytes((unsigned char *)&iph->src_addr, (unsigned char *)&iph->dst_addr);
    (gdb) n
    540                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + 1);
    (gdb) n
    538                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    540                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + 1);
    (gdb) n
    538                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    540                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + 1);
    (gdb) n
    538                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    540                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + 1);
    (gdb) n
    539                     tcph->tcp_flags = TCP_ACK | TCP_SYN;
    (gdb) n
    542                         rte_cpu_to_be_32(*(uint32_t *) & iph->src_addr +
    (gdb) n
    538                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    542                         rte_cpu_to_be_32(*(uint32_t *) & iph->src_addr +
    (gdb) n
    546                     tcph->data_off = (sizeof(struct rte_tcp_hdr) / 4) << 4;
    (gdb) n
    548                     pkt_len = ipv4_hdrlen + sizeof(struct rte_tcp_hdr);
    (gdb) n
    541                     tcph->sent_seq =
    (gdb) n
    546                     tcph->data_off = (sizeof(struct rte_tcp_hdr) / 4) << 4;
    (gdb) n
    547                     tcph->cksum = 0;
    (gdb) n
    552                     rte_pktmbuf_data_len(mbuf) = rte_pktmbuf_pkt_len(mbuf) = pkt_len + RTE_ETHER_HDR_LEN;
    (gdb) n
    549                     iph->total_length = rte_cpu_to_be_16(pkt_len);
    (gdb) n
    551                     iph->time_to_live = TTL;
    (gdb) n
    549                     iph->total_length = rte_cpu_to_be_16(pkt_len);
    (gdb) n
    550                     iph->hdr_checksum = 0;
    (gdb) n
    551                     iph->time_to_live = TTL;
    (gdb) n
    553                     if (hardware_cksum) {
    (gdb) n
    552                     rte_pktmbuf_data_len(mbuf) = rte_pktmbuf_pkt_len(mbuf) = pkt_len + RTE_ETHER_HDR_LEN;
    (gdb) n
    553                     if (hardware_cksum) {
    (gdb) n
    556                             mbuf->l2_len = RTE_ETHER_HDR_LEN;
    (gdb) n
    557                             mbuf->l3_len = ipv4_hdrlen;
    (gdb) n
    558                             mbuf->l4_len = 0;
    (gdb) n
    557                             mbuf->l3_len = ipv4_hdrlen;
    (gdb) n
    555                             mbuf->ol_flags = PKT_TX_IPV4 | PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM;
    (gdb) n
    559                             tcph->cksum = rte_ipv4_phdr_cksum((const struct rte_ipv4_hdr *)iph, 0);
    (gdb) n
    565                     printf("I will reply following:
    ");
    (gdb) n
    566                     dump_packet((unsigned char *)eh, rte_pktmbuf_data_len(mbuf));
    (gdb) n
    568                     int ret = rte_eth_tx_burst(0, 0, &mbuf, 1);
    (gdb) n
    569                     if (ret == 1)
    (gdb) n
    570                             return 1;
    (gdb) n
    776     }
    (gdb) nnnnn
    Undefined command: "nnnnn".  Try "help".
    (gdb) n
    lcore_main () at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:1075
    1075                    for (i = 0; i < nb_rx; i++) {
    (gdb) n
    1069                    const uint16_t nb_rx = rte_eth_rx_burst(port, 0, bufs, BURST_SIZE);
    (gdb) n
    1070                    if (unlikely(nb_rx == 0))
    (gdb) n
    1078                            recv_pkts++;
    (gdb) n
    1076                            int len = rte_pktmbuf_data_len(bufs[i]);
    (gdb) n
    1079                            if (recv_pkts % STATS_PKTS == 0)
    (gdb) n
    1078                            recv_pkts++;
    (gdb) n
    1079                            if (recv_pkts % STATS_PKTS == 0)
    (gdb) n
    1077                            struct rte_ether_hdr *eh = rte_pktmbuf_mtod(bufs[i], struct rte_ether_hdr *);
    (gdb) n
    1079                            if (recv_pkts % STATS_PKTS == 0)
    (gdb) n
    1078                            recv_pkts++;
    (gdb) n
    1079                            if (recv_pkts % STATS_PKTS == 0)
    (gdb) n
    1076                            int len = rte_pktmbuf_data_len(bufs[i]);
    (gdb) n
    1077                            struct rte_ether_hdr *eh = rte_pktmbuf_mtod(bufs[i], struct rte_ether_hdr *);
    (gdb) n
    1079                            if (recv_pkts % STATS_PKTS == 0)
    (gdb) c
    Continuing.
    
    Breakpoint 1, process_tcp (mbuf=0x13e843b00, eh=eh@entry=0x13e843c00, iph=iph@entry=0x13e843c0e, ipv4_hdrlen=20, 
        len=len@entry=74) at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:515
    515             struct rte_tcp_hdr *tcph = (struct rte_tcp_hdr *)((unsigned char *)(iph) + ipv4_hdrlen);
    (gdb) n
    514     {
    (gdb) n
    515             struct rte_tcp_hdr *tcph = (struct rte_tcp_hdr *)((unsigned char *)(iph) + ipv4_hdrlen);
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    519             printf("TCP flags=%d
    ", tcph->tcp_flags);
    (gdb) n
    521             if (len < (int)(sizeof(struct rte_ether_hdr) + ipv4_hdrlen + sizeof(struct rte_tcp_hdr))) {
    (gdb) n
    527             if (tcph->dst_port != tcp_port)
    (gdb) n
    525                     return 0;
    (gdb) n
    527             if (tcph->dst_port != tcp_port)
    (gdb) n
    530             if ((tcph->tcp_flags & (TCP_SYN | TCP_ACK)) == TCP_SYN) {       // SYN packet, send SYN+ACK
    (gdb) n
    532                     printf("SYN packet
    ");
    (gdb) n
    534                     recv_tcp_syn_pkts++;
    (gdb) n
    536                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    534                     recv_tcp_syn_pkts++;
    (gdb) n
    536                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    537                     swap_4bytes((unsigned char *)&iph->src_addr, (unsigned char *)&iph->dst_addr);
    (gdb) n
    536                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    537                     swap_4bytes((unsigned char *)&iph->src_addr, (unsigned char *)&iph->dst_addr);
    (gdb) n
    540                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + 1);
    (gdb) n
    538                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    540                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + 1);
    (gdb) n
    538                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    540                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + 1);
    (gdb) n
    538                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    540                     tcph->recv_ack = rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + 1);
    (gdb) nn
    Undefined command: "nn".  Try "help".
    (gdb) n
    539                     tcph->tcp_flags = TCP_ACK | TCP_SYN;
    (gdb) n
    542                         rte_cpu_to_be_32(*(uint32_t *) & iph->src_addr +
    (gdb) n
    538                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    542                         rte_cpu_to_be_32(*(uint32_t *) & iph->src_addr +
    (gdb) n
    546                     tcph->data_off = (sizeof(struct rte_tcp_hdr) / 4) << 4;
    (gdb) n
    548                     pkt_len = ipv4_hdrlen + sizeof(struct rte_tcp_hdr);
    (gdb) n
    541                     tcph->sent_seq =
    (gdb) n
    546                     tcph->data_off = (sizeof(struct rte_tcp_hdr) / 4) << 4;
    (gdb) n
    547                     tcph->cksum = 0;
    (gdb) n
    552                     rte_pktmbuf_data_len(mbuf) = rte_pktmbuf_pkt_len(mbuf) = pkt_len + RTE_ETHER_HDR_LEN;
    (gdb) n
    549                     iph->total_length = rte_cpu_to_be_16(pkt_len);
    (gdb) n
    551                     iph->time_to_live = TTL;
    (gdb) n
    549                     iph->total_length = rte_cpu_to_be_16(pkt_len);
    (gdb) n
    550                     iph->hdr_checksum = 0;
    (gdb) n
    551                     iph->time_to_live = TTL;
    (gdb) n
    553                     if (hardware_cksum) {
    (gdb) n
    552                     rte_pktmbuf_data_len(mbuf) = rte_pktmbuf_pkt_len(mbuf) = pkt_len + RTE_ETHER_HDR_LEN;
    (gdb) n
    553                     if (hardware_cksum) {
    (gdb) n
    556                             mbuf->l2_len = RTE_ETHER_HDR_LEN;
    (gdb) n
    557                             mbuf->l3_len = ipv4_hdrlen;
    (gdb) n
    558                             mbuf->l4_len = 0;
    (gdb) n
    557                             mbuf->l3_len = ipv4_hdrlen;
    (gdb) nn
    Undefined command: "nn".  Try "help".
    (gdb) n
    555                             mbuf->ol_flags = PKT_TX_IPV4 | PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM;
    (gdb) n
    559                             tcph->cksum = rte_ipv4_phdr_cksum((const struct rte_ipv4_hdr *)iph, 0);
    (gdb) n
    565                     printf("I will reply following:
    ");
    (gdb) n
    566                     dump_packet((unsigned char *)eh, rte_pktmbuf_data_len(mbuf));
    (gdb) n
    568                     int ret = rte_eth_tx_burst(0, 0, &mbuf, 1);
    (gdb) n
    569                     if (ret == 1)
    (gdb) n
    570                             return 1;
    (gdb) n
    776     }
    (gdb) 
    (gdb) c
    Continuing.
    
    Breakpoint 1, process_tcp (mbuf=0x13e805580, eh=eh@entry=0x13e805680, iph=iph@entry=0x13e80568e, ipv4_hdrlen=20, 
        len=len@entry=81) at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:515
    515             struct rte_tcp_hdr *tcph = (struct rte_tcp_hdr *)((unsigned char *)(iph) + ipv4_hdrlen);
    (gdb) n
    514     {
    (gdb) n
    515             struct rte_tcp_hdr *tcph = (struct rte_tcp_hdr *)((unsigned char *)(iph) + ipv4_hdrlen);
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    514     {
    (gdb) n
    518             printf("TCP packet, dport=%d
    ", rte_be_to_cpu_16(tcph->dst_port));
    (gdb) n
    519             printf("TCP flags=%d
    ", tcph->tcp_flags);
    (gdb) n
    521             if (len < (int)(sizeof(struct rte_ether_hdr) + ipv4_hdrlen + sizeof(struct rte_tcp_hdr))) {
    (gdb) n
    527             if (tcph->dst_port != tcp_port)
    (gdb) n
    525                     return 0;
    (gdb) n
    527             if (tcph->dst_port != tcp_port)
    (gdb) n
    530             if ((tcph->tcp_flags & (TCP_SYN | TCP_ACK)) == TCP_SYN) {       // SYN packet, send SYN+ACK
    (gdb) n
    575             } else if (tcph->tcp_flags & TCP_FIN) { // FIN packet, send ACK
    (gdb) n
    615             } else if ((tcph->tcp_flags & (TCP_SYN | TCP_ACK)) == TCP_ACK) {        // ACK packet, send DATA
    (gdb) n
    622                     recv_tcp_data_pkts++;
    (gdb) n
    616                     pkt_len = rte_be_to_cpu_16(iph->total_length);
    (gdb) n
    622                     recv_tcp_data_pkts++;
    (gdb) n
    624                     printf("ACK pkt len=%d(inc ether) ip len=%d
    ", rte_pktmbuf_data_len(mbuf),
    (gdb) n
    617                     int tcp_payload_len = pkt_len - ipv4_hdrlen - (tcph->data_off >> 4) * 4;
    (gdb) n
    616                     pkt_len = rte_be_to_cpu_16(iph->total_length);
    (gdb) n
    622                     recv_tcp_data_pkts++;
    (gdb) n
    616                     pkt_len = rte_be_to_cpu_16(iph->total_length);
    (gdb) n
    624                     printf("ACK pkt len=%d(inc ether) ip len=%d
    ", rte_pktmbuf_data_len(mbuf),
    (gdb) n
    617                     int tcp_payload_len = pkt_len - ipv4_hdrlen - (tcph->data_off >> 4) * 4;
    (gdb) n
    624                     printf("ACK pkt len=%d(inc ether) ip len=%d
    ", rte_pktmbuf_data_len(mbuf),
    (gdb) n
    617                     int tcp_payload_len = pkt_len - ipv4_hdrlen - (tcph->data_off >> 4) * 4;
    (gdb) n
    622                     recv_tcp_data_pkts++;
    (gdb) n
    624                     printf("ACK pkt len=%d(inc ether) ip len=%d
    ", rte_pktmbuf_data_len(mbuf),
    (gdb) n
    626                     printf("tcp payload len=%d
    ", tcp_payload_len);
    (gdb) n
    628                     if (tcp_payload_len <= 5) {
    (gdb) n
    635                         rte_cpu_to_be_32(*(uint32_t *) & iph->src_addr +
    (gdb) n
    634                     if (tcph->recv_ack !=
    (gdb) n
    635                         rte_cpu_to_be_32(*(uint32_t *) & iph->src_addr +
    (gdb) n
    634                     if (tcph->recv_ack !=
    (gdb) n
    644                     tcp_payload = (unsigned char *)iph + ipv4_hdrlen + (tcph->data_off >> 4) * 4;
    (gdb) n
    646                         (4, iph, tcph, tcp_payload, tcp_payload_len, buf + sizeof(struct rte_tcp_hdr),
    (gdb) n
    644                     tcp_payload = (unsigned char *)iph + ipv4_hdrlen + (tcph->data_off >> 4) * 4;
    (gdb) n
    646                         (4, iph, tcph, tcp_payload, tcp_payload_len, buf + sizeof(struct rte_tcp_hdr),
    (gdb) n
    618                     int ntcp_payload_len = MAXIPLEN;
    (gdb) n
    650                     printf("http return new payload len=%d
    ", ntcp_payload_len);
    (gdb) n
    654                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    653                         rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + tcp_payload_len);
    (gdb) n
    654                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    655                     swap_4bytes((unsigned char *)&iph->src_addr, (unsigned char *)&iph->dst_addr);
    (gdb) n
    654                     swap_6bytes((unsigned char *)&eh->s_addr, (unsigned char *)&eh->d_addr);
    (gdb) n
    656                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    655                     swap_4bytes((unsigned char *)&iph->src_addr, (unsigned char *)&iph->dst_addr);
    (gdb) n
    653                         rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + tcp_payload_len);
    (gdb) n
    658                     tcph->sent_seq = tcph->recv_ack;
    (gdb) n
    653                         rte_cpu_to_be_32(rte_be_to_cpu_32(tcph->sent_seq) + tcp_payload_len);
    (gdb) n
    656                     swap_2bytes((unsigned char *)&tcph->src_port, (unsigned char *)&tcph->dst_port);
    (gdb) n
    652                     uint32_t ack_seq =
    (gdb) n
    657                     tcph->tcp_flags = TCP_ACK | TCP_PSH | TCP_FIN;
    (gdb) n
    658                     tcph->sent_seq = tcph->recv_ack;
    (gdb) n
    659                     tcph->recv_ack = ack_seq;
    (gdb) n
    660                     tcph->cksum = 0;
    (gdb) n
    662                     iph->time_to_live = TTL;
    (gdb) n
    661                     iph->hdr_checksum = 0;
    (gdb) n
    664                     if (ntcp_payload_len <= TCPMSS) {       // tcp packet fit in one IP packet
    (gdb) n
    713                             iph->packet_id = tcph->dst_port;
    (gdb) n
    711                             iph->total_length = rte_cpu_to_be_16(left + sizeof(struct rte_ipv4_hdr));
    (gdb) n
    713                             iph->packet_id = tcph->dst_port;
    (gdb) n
    712                             iph->fragment_offset = 0;
    (gdb) n
    714                             tcph->data_off = (sizeof(struct rte_tcp_hdr) / 4) << 4;
    (gdb) n
    716                             rte_memcpy(ntcph, tcph, sizeof(struct rte_tcp_hdr));    // copy tcp header to begin of buf
    (gdb) n
    717                             ntcph->cksum = rte_ipv4_udptcp_cksum(iph, ntcph);       // trick but works, now eth/ip header in mbuf, tcp packet in buf
    (gdb) n
    716                             rte_memcpy(ntcph, tcph, sizeof(struct rte_tcp_hdr));    // copy tcp header to begin of buf
    (gdb) n
    705                             int left = ntcp_payload_len + sizeof(struct rte_tcp_hdr);
    (gdb) n
    717                             ntcph->cksum = rte_ipv4_udptcp_cksum(iph, ntcph);       // trick but works, now eth/ip header in mbuf, tcp packet in buf
    (gdb) n
    724                                     frag = rte_pktmbuf_alloc(mbuf_pool);
    (gdb) n
    743                                     fprintf(stderr, "frag offset %d, pkt len=%d
    ", offset, pkt_len);
    (gdb) n
    717                             ntcph->cksum = rte_ipv4_udptcp_cksum(iph, ntcph);       // trick but works, now eth/ip header in mbuf, tcp packet in buf
    (gdb) n
    724                                     frag = rte_pktmbuf_alloc(mbuf_pool);
    (gdb) n
    743                                     fprintf(stderr, "frag offset %d, pkt len=%d
    ", offset, pkt_len);
    (gdb) n
    724                                     frag = rte_pktmbuf_alloc(mbuf_pool);
    (gdb) n
    743                                     fprintf(stderr, "frag offset %d, pkt len=%d
    ", offset, pkt_len);
    (gdb) n
    719                                     len = left < TCPMSS ? left : (TCPMSS & 0xfff0);
    (gdb) n
    722                                     printf("offset=%d len=%d
    ", offset, len);
    (gdb) n
    724                                     frag = rte_pktmbuf_alloc(mbuf_pool);
    (gdb) n
    720                                     left -= len;
    (gdb) n
    724                                     frag = rte_pktmbuf_alloc(mbuf_pool);
    (gdb) n
    729                                     neh = rte_pktmbuf_mtod(frag, struct rte_ether_hdr *);
    (gdb) n
    730                                     rte_memcpy(neh, eh, RTE_ETHER_HDR_LEN + sizeof(struct rte_ipv4_hdr));   // copy eth/ip header
    (gdb) n
    729                                     neh = rte_pktmbuf_mtod(frag, struct rte_ether_hdr *);
    (gdb) n
    724                                     frag = rte_pktmbuf_alloc(mbuf_pool);
    (gdb) n
    730                                     rte_memcpy(neh, eh, RTE_ETHER_HDR_LEN + sizeof(struct rte_ipv4_hdr));   // copy eth/ip header
    (gdb) n
    735                                     rte_memcpy(ntcph, buf + offset, len);
    (gdb) n
    730                                     rte_memcpy(neh, eh, RTE_ETHER_HDR_LEN + sizeof(struct rte_ipv4_hdr));   // copy eth/ip header
    (gdb) n
    735                                     rte_memcpy(ntcph, buf + offset, len);
    (gdb) n
    730                                     rte_memcpy(neh, eh, RTE_ETHER_HDR_LEN + sizeof(struct rte_ipv4_hdr));   // copy eth/ip header
    (gdb) n
    735                                     rte_memcpy(ntcph, buf + offset, len);
    (gdb) n
    737                                     pkt_len = len + sizeof(struct rte_ipv4_hdr);
    (gdb) n
    738                                     niph->total_length = rte_cpu_to_be_16(pkt_len);
    (gdb) n
    739                                     niph->fragment_offset = rte_cpu_to_be_16(offset >> 3);
    (gdb) n
    738                                     niph->total_length = rte_cpu_to_be_16(pkt_len);
    (gdb) n
    740                                     if (left > 0)
    (gdb) n
    739                                     niph->fragment_offset = rte_cpu_to_be_16(offset >> 3);
    (gdb) n
    740                                     if (left > 0)
    (gdb) n
    741                                             niph->fragment_offset |= rte_cpu_to_be_16(RTE_IPV4_HDR_MF_FLAG);
    (gdb) n
    743                                     fprintf(stderr, "frag offset %d, pkt len=%d
    ", offset, pkt_len);
    (gdb) n
    745                                     rte_pktmbuf_data_len(frag) = rte_pktmbuf_pkt_len(frag) =
    (gdb) n
    747                                     if (hardware_cksum) {
    (gdb) n
    746                                         pkt_len + RTE_ETHER_HDR_LEN;
    (gdb) n
    747                                     if (hardware_cksum) {
    (gdb) n
    745                                     rte_pktmbuf_data_len(frag) = rte_pktmbuf_pkt_len(frag) =
    (gdb) n
    747                                     if (hardware_cksum) {
    (gdb) n
    750                                             frag->l2_len = RTE_ETHER_HDR_LEN;
    (gdb) n
    751                                             frag->l3_len = sizeof(struct rte_ipv4_hdr);
    (gdb) n
    749                                             frag->ol_flags = PKT_TX_IPV4 | PKT_TX_IP_CKSUM;
    (gdb) n
    751                                             frag->l3_len = sizeof(struct rte_ipv4_hdr);
    (gdb) n
    752                                             frag->l4_len = len;
    (gdb) n
    760                                     int ret = rte_eth_tx_burst(0, 0, &frag, 1);
    (gdb) n
    761                                     if (ret != 1) {
    (gdb) 
    (gdb) b simple-web-server.c:645
    Breakpoint 2 at 0x469ee0: file /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c, line 645.
    (gdb) c
    Continuing.
    
    Breakpoint 2, process_tcp (mbuf=0x13e907080, eh=eh@entry=0x13e907180, iph=iph@entry=0x13e90718e, ipv4_hdrlen=20, 
        len=len@entry=81) at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:650
    650                     printf("http return new payload len=%d
    ", ntcp_payload_len);
    (gdb) bt
    #0  process_tcp (mbuf=0x13e907080, eh=eh@entry=0x13e907180, iph=iph@entry=0x13e90718e, ipv4_hdrlen=20, 
        len=len@entry=81) at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:650
    #1  0x0000000000465ef0 in lcore_main () at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:1104
    #2  main (argc=<optimized out>, argv=<optimized out>)
        at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:1227
    (gdb) 
    Continuing.
    
    Breakpoint 1, process_tcp (mbuf=0x13e857e00, eh=eh@entry=0x13e857f00, iph=iph@entry=0x13e857f0e, ipv4_hdrlen=20, 
        len=len@entry=81) at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:650
    650                     printf("http return new payload len=%d
    ", ntcp_payload_len);
    (gdb) p *tcp_payload
    value has been optimized out
    (gdb) p ((unsigned char *)iph + ipv4_hdrlen + (tcph->data_off >> 4) * 4)
    $1 = (unsigned char *) 0x13e857f36 "Gangadhar Hi Shaktimaan hai"
    (gdb) 
    gdb调试程序的时候打印变量值会出现<value optimized out> 情况,可以在gcc编译的时候加上 -O0参数项,意思是不进行编译优化,调试的时候就会顺畅了,运行流程不会跳来跳去的,发布项目的时候记得不要在使用 -O0参数项,gcc 默认编译或加上-O2优化编译会提高程序运行速度. 
    (gdb) c
    Continuing.
    
    Breakpoint 1, process_tcp (mbuf=0x13e837d00, eh=0x13e837e00, iph=0x13e837e0e, ipv4_hdrlen=20, len=81)
        at /data1/dpdk-19.11/demo/dpdk-simple-web/simple-web-server.c:645
    645                     if (process_http
    (gdb) p *tcp_payload
    $1 = 71 'G'
    (gdb) p tcp_payload
    $2 = (unsigned char *) 0x13e837e36 "Gangadhar Hi Shaktimaan hai"
    (gdb) 
  • 相关阅读:
    Linux unalias命令 取消别名
    linux cp 拷贝文件或目录
    POJ 1850
    POJ 1844
    POJ 1852
    POJ 1837
    POJ 1833
    POJ 1804
    POJ 1789
    POJ 1781
  • 原文地址:https://www.cnblogs.com/dream397/p/13684123.html
Copyright © 2020-2023  润新知