 |
Flowgrind
Advanced TCP traffic generator
|
Go to the documentation of this file.
32 #include <sys/socket.h>
33 #include <sys/types.h>
34 #include <netinet/in.h>
35 #include <netinet/in_systm.h>
36 #include <netinet/ip.h>
37 #include <arpa/inet.h>
38 #include <netinet/if_ether.h>
59 #ifndef HAVE_PTHREAD_BARRIER
64 #define PCAP_SNAPLEN 130
67 #define PCAP_FILTER "tcp"
70 #define PCAP_PROMISC 0
73 static char errbuf[PCAP_ERRBUF_SIZE] =
"";
88 logging(LOG_WARNING,
"error in pcap_findalldevs: %s\n",
errbuf);
93 for (pcap_if_t *d =
alldevs; d; d = d->next) {
95 if (asprintf(&devdes,
"%s: ", d->name) == -1)
98 for (pcap_addr_t *a = d->addresses; a; a = a->next) {
104 sizeof(
struct sockaddr)));
108 DEBUG_MSG(LOG_ERR,
"pcap: found pcapable device (%s)", devdes);
134 DEBUG_MSG(LOG_DEBUG,
"fg_pcap_cleanup() called for flow %d",
flow->
id);
170 struct addrinfo *ainf = NULL;
173 logging(LOG_WARNING,
"getaddrinfo() failed (%s). Eliding "
174 "packet capture for flow", gai_strerror(rc));
181 for (d =
alldevs; d; d = d->next) {
182 for (pcap_addr_t *a = d->addresses; a; a = a->next) {
186 DEBUG_MSG(LOG_NOTICE,
"pcap: data connection "
187 "inbound from %s (%s)", d->name,
189 sizeof(
struct sockaddr)));
199 logging(LOG_WARNING,
"failed to determine interface for data "
200 "connection. No pcap support");
209 logging(LOG_WARNING,
"failed to init pcap on device %s: %s",
214 uint32_t net = 0, mask = 0;
215 if (pcap_lookupnet(d->name, &net, &mask,
errbuf) < 0) {
216 logging(LOG_WARNING,
"pcap: netmask lookup failed: %s",
errbuf);
222 logging(LOG_WARNING,
"pcap: failed to set non-blocking: %s",
228 struct bpf_program pcap_program;
231 logging(LOG_WARNING,
"pcap: failed compiling filter '%s': %s",
238 &pcap_program) < 0) {
239 logging(LOG_WARNING,
"pcap: failed to set filter: %s",
245 char *dump_filename = NULL;
254 char timestamp[30] =
"";
255 ctimenow_r(timestamp,
sizeof(timestamp),
false);
259 char hostname[128] =
"";
260 if (!gethostname(hostname,
sizeof(hostname)))
266 DEBUG_MSG(LOG_NOTICE,
"dumping to \"%s\"", dump_filename);
273 logging(LOG_WARNING,
"pcap: failed to open dump file writing: %s",
286 logging(LOG_WARNING,
"pcap_dispatch() failed. Packet "
287 "dumping stopped for flow %d",
flow->
id);
292 struct pcap_stat p_stats;
295 DEBUG_MSG(LOG_NOTICE,
"pcap: finished dumping %d packets for "
297 DEBUG_MSG(LOG_NOTICE,
"pcap: %d packets received by filter for "
298 "flow %d", p_stats.ps_recv,
flow->
id);
299 DEBUG_MSG(LOG_NOTICE,
"pcap: %d packets dropped by kernel for "
300 "flow %d", p_stats.ps_drop,
flow->
id);
303 pthread_testcancel();
308 pthread_cleanup_pop(1);
320 logging(LOG_WARNING,
"pcap: dumping already in progress on "
335 logging(LOG_WARNING,
"could not start pcap thread: %s",
#define DEBUG_MSG(LVL, MSG,...)
Print debug message to standard error.
Packet capture support for the Flowgrind daemon.
int fg_pcap_init(void)
Initialize flowgrind's pcap library.
Functions to manipulate strings used by Flowgrind.
int pthread_barrier_wait(pthread_barrier_t *barrier)
Synchronizes participating threads at the barrier referenced by barrier.
static pcap_if_t * alldevs
static void * fg_pcap_work(void *arg)
Worker method performing actual packet capturing for the provided flow.
int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count)
Allocates resources required to use the barrier referenced by barrier.
static pthread_barrier_t pcap_barrier
void logging(int priority, const char *fmt,...)
struct flow_settings settings
struct pcap_dumper_t * pcap_dumper
void fg_pcap_cleanup(void *arg)
Cleanup method to be called after dumping of the specified flow has finished.
static char errbuf[PCAP_ERRBUF_SIZE]
int traffic_dump
Dump traffic using libpcap (option -M).
void fg_pcap_go(struct flow *flow)
Start a tcpdump to capture traffic of the provided flow.
Routines used to manipulate socket parameters for Flowgrind.
Timing related routines used by Flowgrind.
Object for barrier synchronization.
char sockaddr_compare(const struct sockaddr *a, const struct sockaddr *b)
int asprintf_append(char **strp, const char *fmt,...)
Missing pthread barrier implemenation for OS X.
const char * fg_nameinfo(const struct sockaddr *sa, socklen_t salen)
struct pcap_t * pcap_handle
const char * ctimenow_r(char *buf, size_t size, bool ns)
Returns the current wall-clock time as null-terminated string.
char bind_address[1000]
The interface address for the flow (used by daemon).
Debugging routines for Flowgrind controller and daemon.
Routines used by the Flowgrind daemon.