Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dlpisubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ pcap_process_pkts(pcap_t *p, pcap_handler callback, u_char *user,
*/
if (p->break_loop) {
if (n == 0) {
p->break_loop = 0;
return (-2);
return PCAP_ERROR_BREAK;
} else {
p->bp = bufp;
p->cc = ep - bufp;
Expand Down
15 changes: 4 additions & 11 deletions pcap-bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,15 +1190,9 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/*
* Has "pcap_breakloop()" been called?
*/
if (p->break_loop) {
/*
* Yes - clear the flag that indicates that it
* has, and return PCAP_ERROR_BREAK to indicate
* that we were told to break out of the loop.
*/
p->break_loop = 0;
if (p->break_loop)
return (PCAP_ERROR_BREAK);
}

cc = p->cc;
if (p->cc == 0) {
/*
Expand Down Expand Up @@ -1348,10 +1342,9 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
if (p->break_loop) {
p->bp = bp;
p->cc = (u_int)(ep - bp);
if (n == 0) {
p->break_loop = 0;
if (n == 0)
return (PCAP_ERROR_BREAK);
} else
else
return (n);
}

Expand Down
4 changes: 1 addition & 3 deletions pcap-bt-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,8 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
/* ignore interrupt system call error */
do {
if (handle->break_loop)
{
handle->break_loop = 0;
return PCAP_ERROR_BREAK;
}

ret = recvmsg(handle->fd, &msg, 0);
} while ((ret == -1) && (errno == EINTR));

Expand Down
4 changes: 1 addition & 3 deletions pcap-bt-monitor-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch

do {
if (handle->break_loop)
{
handle->break_loop = 0;
return PCAP_ERROR_BREAK;
}

ret = recvmsg(handle->fd, &msg, 0);
} while ((ret == -1) && (errno == EINTR));

Expand Down
18 changes: 2 additions & 16 deletions pcap-dag.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,8 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/*
* Has "pcap_breakloop()" been called?
*/
if (p->break_loop) {
/*
* Yes - clear the flag that indicates that
* it has, and return PCAP_ERROR_BREAK to indicate that
* we were told to break out of the loop.
*/
p->break_loop = 0;
if (p->break_loop)
return PCAP_ERROR_BREAK;
}

/* dag_advance_stream() will block (unless nonblock is called)
* until 64kB of data has accumulated.
Expand Down Expand Up @@ -395,15 +388,8 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/*
* Has "pcap_breakloop()" been called?
*/
if (p->break_loop) {
/*
* Yes - clear the flag that indicates that
* it has, and return PCAP_ERROR_BREAK to indicate that
* we were told to break out of the loop.
*/
p->break_loop = 0;
if (p->break_loop)
return PCAP_ERROR_BREAK;
}

rlen = ntohs(header->rlen);
if (rlen < dag_record_size)
Expand Down
6 changes: 2 additions & 4 deletions pcap-dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ dbus_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char *us
return -1;
}

if (handle->break_loop) {
handle->break_loop = 0;
return -2;
}
if (handle->break_loop)
return PCAP_ERROR_BREAK;

message = dbus_connection_pop_message(handlep->conn);
}
Expand Down
13 changes: 3 additions & 10 deletions pcap-dlpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,9 @@ pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/*
* Has "pcap_breakloop()" been called?
*/
if (p->break_loop) {
/*
* Yes - clear the flag that indicates
* that it has, and return -2 to
* indicate that we were told to
* break out of the loop.
*/
p->break_loop = 0;
return (-2);
}
if (p->break_loop)
return PCAP_ERROR_BREAK;

/*
* XXX - check for the DLPI primitive, which
* would be DL_HP_RAWDATA_IND on HP-UX
Expand Down
3 changes: 0 additions & 3 deletions pcap-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ static int pcap_dpdk_dispatch(pcap_t *p, int max_cnt, pcap_handler cb, u_char *c

while( pkt_cnt < max_cnt){
if (p->break_loop){
p->break_loop = 0;
return PCAP_ERROR_BREAK;
}
// read once in non-blocking mode, or try many times waiting for timeout_ms.
Expand All @@ -365,9 +364,7 @@ static int pcap_dpdk_dispatch(pcap_t *p, int max_cnt, pcap_handler cb, u_char *c
}else{
if (p->break_loop){
RTE_LOG(DEBUG, USER1, "dpdk: no packets available and break_loop is set in blocking mode.\n");
p->break_loop = 0;
return PCAP_ERROR_BREAK;

}
RTE_LOG(DEBUG, USER1, "dpdk: no packets available for timeout %d ms in blocking mode.\n", timeout_ms);
}
Expand Down
1 change: 0 additions & 1 deletion pcap-haiku.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pcap_read_haiku(pcap_t* handle, int maxPackets _U_, pcap_handler callback,
ssize_t bytesReceived;
do {
if (handle->break_loop) {
handle->break_loop = 0;
return PCAP_ERROR_BREAK;
}
bytesReceived = recvfrom(handle->fd, buffer, handle->bufsize, MSG_TRUNC,
Expand Down
4 changes: 1 addition & 3 deletions pcap-hurd.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ pcap_read_hurd(pcap_t *p, int cnt _U_, pcap_handler callback, u_char *user)
msg = (struct net_rcv_msg *)p->buffer;

retry:
if (p->break_loop) {
p->break_loop = 0;
if (p->break_loop)
return PCAP_ERROR_BREAK;
}

kr = mach_msg(&msg->msg_hdr, MACH_RCV_MSG | MACH_RCV_INTERRUPT, 0,
p->bufsize, ph->rcv_port, MACH_MSG_TIMEOUT_NONE,
Expand Down
13 changes: 10 additions & 3 deletions pcap-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ typedef int (*set_datalink_op_t)(pcap_t *, int);
typedef int (*getnonblock_op_t)(pcap_t *);
typedef int (*setnonblock_op_t)(pcap_t *, int);
typedef int (*stats_op_t)(pcap_t *, struct pcap_stat *);
typedef void (*breakloop_op_t)(pcap_t *);
typedef void (*breakloop_op_t)(pcap_t *, int);
#ifdef _WIN32
typedef struct pcap_stat *(*stats_ex_op_t)(pcap_t *, int *);
typedef int (*setbuff_op_t)(pcap_t *, int);
Expand All @@ -199,6 +199,12 @@ typedef int (*live_dump_ended_op_t)(pcap_t *, int);
#endif
typedef void (*cleanup_op_t)(pcap_t *);

enum {
PCAPINT_BREAK_RUN = 0,
PCAPINT_BREAK_IMMEDIATE,
PCAPINT_BREAK_FLUSH,
};

/*
* We put all the stuff used in the read code path at the beginning,
* to try to keep it together in the same cache line or lines.
Expand Down Expand Up @@ -228,7 +234,8 @@ struct pcap {
u_char *bp;
u_int cc;

sig_atomic_t break_loop; /* flag set to force break from packet-reading loop */
/* break packet-reading loop, will be set to one of PCAPINT_BREAK_* */
sig_atomic_t break_loop;

void *priv; /* private data for methods */

Expand Down Expand Up @@ -433,7 +440,7 @@ void pcapint_add_to_pcaps_to_close(pcap_t *);
void pcapint_remove_from_pcaps_to_close(pcap_t *);
void pcapint_cleanup_live_common(pcap_t *);
int pcapint_check_activated(pcap_t *);
void pcapint_breakloop_common(pcap_t *);
void pcapint_breakloop_common(pcap_t *, int mode);

/*
* Internal interfaces for "pcap_findalldevs()".
Expand Down
11 changes: 2 additions & 9 deletions pcap-libdlpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,8 @@ pcap_read_libdlpi(pcap_t *p, int count, pcap_handler callback, u_char *user)
}
do {
/* Has "pcap_breakloop()" been called? */
if (p->break_loop) {
/*
* Yes - clear the flag that indicates that it has,
* and return -2 to indicate that we were told to
* break out of the loop.
*/
p->break_loop = 0;
return (-2);
}
if (p->break_loop)
return PCAP_ERROR_BREAK;

msglen = p->bufsize;
bufp = p->buffer + p->offset;
Expand Down
48 changes: 26 additions & 22 deletions pcap-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,9 +1106,9 @@ set_poll_timeout(struct pcap_linux *handlep)
}
}

static void pcap_breakloop_linux(pcap_t *handle)
static void pcap_breakloop_linux(pcap_t *handle, int mode)
{
pcapint_breakloop_common(handle);
pcapint_breakloop_common(handle, mode);
struct pcap_linux *handlep = handle->priv;

uint64_t value = 1;
Expand Down Expand Up @@ -3676,10 +3676,8 @@ static int pcap_wait_for_frames_mmap(pcap_t *handle)
* It's EINTR; if we were told to break out of
* the loop, do so.
*/
if (handle->break_loop) {
handle->break_loop = 0;
return PCAP_ERROR_BREAK;
}
if (handle->break_loop)
return 0;
} else if (ret > 0) {
/*
* OK, some descriptor is ready.
Expand Down Expand Up @@ -3826,10 +3824,8 @@ static int pcap_wait_for_frames_mmap(pcap_t *handle)
* pcap_breakloop() call; if we were told
* to break out of the loop, do so.
*/
if (handle->break_loop) {
handle->break_loop = 0;
return PCAP_ERROR_BREAK;
}
if (handle->break_loop)
return 0;
}
}

Expand Down Expand Up @@ -4344,17 +4340,24 @@ pcap_read_linux_mmap_v2(pcap_t *handle, int max_packets, pcap_handler callback,
int pkts = 0;
int ret;

/* Stop processing if we should break out immediately */
if (handle->break_loop == PCAPINT_BREAK_IMMEDIATE)
return PCAP_ERROR_BREAK;

/* wait for frames availability.*/
h.raw = RING_GET_CURRENT_FRAME(handle);
if (!packet_mmap_acquire(h.h2)) {
if (!handle->break_loop && !packet_mmap_acquire(h.h2)) {
/*
* The current frame is owned by the kernel; wait for
* a frame to be handed to us.
*/
ret = pcap_wait_for_frames_mmap(handle);
if (ret) {
if (ret)
return ret;
}

/* We may have received an immediate break while polling */
if (handle->break_loop == PCAPINT_BREAK_IMMEDIATE)
return PCAP_ERROR_BREAK;
}

/*
Expand Down Expand Up @@ -4422,12 +4425,15 @@ pcap_read_linux_mmap_v2(pcap_t *handle, int max_packets, pcap_handler callback,
if (++handle->offset >= handle->cc)
handle->offset = 0;

/* check for break loop condition*/
if (handle->break_loop) {
handle->break_loop = 0;
return PCAP_ERROR_BREAK;
}
/* Abort processing if requested */
if (handle->break_loop == PCAPINT_BREAK_IMMEDIATE)
break;
}

/* All packets are drained, report loop break */
if (pkts == 0 && handle->break_loop)
return PCAP_ERROR_BREAK;

return pkts;
}

Expand All @@ -4451,7 +4457,7 @@ pcap_read_linux_mmap_v3(pcap_t *handle, int max_packets, pcap_handler callback,
* for a frame to be handed to us.
*/
ret = pcap_wait_for_frames_mmap(handle);
if (ret) {
if (ret && ret != PCAP_ERROR_BREAK) {
return ret;
}
}
Expand Down Expand Up @@ -4557,10 +4563,8 @@ pcap_read_linux_mmap_v3(pcap_t *handle, int max_packets, pcap_handler callback,
}

/* check for break loop condition*/
if (handle->break_loop) {
handle->break_loop = 0;
if (handle->break_loop)
return PCAP_ERROR_BREAK;
}
}
if (pkts == 0 && handlep->timeout == 0) {
/* Block until we see a packet. */
Expand Down
8 changes: 0 additions & 8 deletions pcap-netfilter-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
* Has "pcap_breakloop()" been called?
*/
if (handle->break_loop) {
/*
* Yes - clear the flag that indicates that it
* has, and return PCAP_ERROR_BREAK to indicate
* that we were told to break out of the loop.
*/
handle->break_loop = 0;
return PCAP_ERROR_BREAK;
}
cc = handle->cc;
Expand All @@ -116,7 +110,6 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
do {
read_ret = recv(handle->fd, handle->buffer, handle->bufsize, 0);
if (handle->break_loop) {
handle->break_loop = 0;
return PCAP_ERROR_BREAK;
}
if (read_ret == -1 && errno == ENOBUFS)
Expand Down Expand Up @@ -165,7 +158,6 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
handle->bp = bp;
handle->cc = (u_int)(ep - bp);
if (count == 0) {
handle->break_loop = 0;
return PCAP_ERROR_BREAK;
} else
return count;
Expand Down
5 changes: 2 additions & 3 deletions pcap-netmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ pcap_netmap_dispatch(pcap_t *p, int cnt, pcap_handler cb, u_char *user)
pn->cb_arg = user;

for (;;) {
if (p->break_loop) {
p->break_loop = 0;
if (p->break_loop)
return PCAP_ERROR_BREAK;
}

/* nm_dispatch won't run forever */

ret = nm_dispatch((void *)d, cnt, (void *)pcap_netmap_filter, (void *)p);
Expand Down
Loading