Commit 24abc415 authored by Robert David Graham's avatar Robert David Graham
Browse files

flush sendq

parent 903f7fb8
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -440,6 +440,13 @@ infinite:
        goto infinite;
    }

    /*
     * Flush any untransmitted packets. High-speed mechanisms like Windows
     * "sendq" and Linux's "PF_RING" queue packets and transmit many together,
     * so there may be some packets that we've queueud but not yet transmitted.
     * This call makes sure they are transmitted.
     */
    rawsock_flush(adapter);

    /*
     * We are done transmitting. However, response packets will take several
@@ -466,6 +473,10 @@ infinite:
                            &packets_sent,
                            &batch_size);

            /* Make sure they've actually been transmitted, not just queued up for
             * transmit */
            rawsock_flush(adapter);

            pixie_usleep(1000);
        }
    }
+24 −16
Original line number Diff line number Diff line
@@ -264,6 +264,25 @@ adapter_from_index(unsigned index)
    }
}

/***************************************************************************
 * Some methods of transmit queue multiple packets in a buffer then
 * send all queued packets at once. At the end of a scan, we might have
 * some pending packets that haven't been transmitted yet. Therefore,
 * we'll have to flush them.
 ***************************************************************************/
void
rawsock_flush(struct Adapter *adapter)
{
    if (adapter->sendq) {
        pcap_sendqueue_transmit(adapter->pcap, adapter->sendq, 0);

        /* Dude, I totally forget why this step is necessary. I vaguely
         * remember there's a good reason for it though */
        pcap_sendqueue_destroy(adapter->sendq);
        adapter->sendq =  pcap_sendqueue_alloc(SENDQ_SIZE);
    }

}

/***************************************************************************
 * wrapper for libpcap's sendpacket
@@ -309,25 +328,14 @@ rawsock_send_packet(

        err = pcap_sendqueue_queue(adapter->sendq, &hdr, packet);
        if (err) {
            //printf("sendpacket() failed %d\n", x);
            //for (;;)
            pcap_sendqueue_transmit(adapter->pcap, adapter->sendq, 0);
            //printf("pcap_send_queue)() returned %u\n", x);
            pcap_sendqueue_destroy(adapter->sendq);
            adapter->sendq =  pcap_sendqueue_alloc(SENDQ_SIZE);
            rawsock_flush(adapter);
            pcap_sendqueue_queue(adapter->sendq, &hdr, packet);
            //("sendpacket() returned %d\n", x);
            //exit(1);
        } else
            ; //printf("+%u\n", count++);
        if (flush) {
            pcap_sendqueue_transmit(adapter->pcap, adapter->sendq, 0);
        }

            /* Dude, I totally forget why this step is necessary. I vaguely
             * remember there's a good reason for it though */
            pcap_sendqueue_destroy(adapter->sendq);
            adapter->sendq =  pcap_sendqueue_alloc(SENDQ_SIZE);
        if (flush) {
            rawsock_flush(adapter);
        }

        return 0;
    }

+9 −0
Original line number Diff line number Diff line
@@ -81,6 +81,15 @@ const char *rawsock_win_name(const char *ifname);

int rawsock_is_adapter_names_equal(const char *lhs, const char *rhs);

/**
 * Transmit any queued (but not yet transmitted) packets. Useful only when
 * using a high-speed transmit mechanism. Since flushing happens automatically
 * whenever the transmit queue is full, this is only needed in boundary
 * cases, like when shutting down.
 */
void
rawsock_flush(struct Adapter *adapter);

int rawsock_send_packet(
    struct Adapter *adapter,
    const unsigned char *packet,