providing sock from main thread in order to faciliate dropping privs
This commit is contained in:
parent
c943dd529c
commit
473b96b1aa
13
src/send.c
13
src/send.c
@ -132,7 +132,7 @@ int send_init(void)
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_socket(void)
|
int get_socket(void)
|
||||||
{
|
{
|
||||||
int sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
|
int sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
|
||||||
if (sock <= 0) {
|
if (sock <= 0) {
|
||||||
@ -142,7 +142,7 @@ static int get_socket(void)
|
|||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_dryrun_socket(void)
|
int get_dryrun_socket(void)
|
||||||
{
|
{
|
||||||
// we need a socket in order to gather details about the system
|
// we need a socket in order to gather details about the system
|
||||||
// such as source MAC address and IP address. However, because
|
// such as source MAC address and IP address. However, because
|
||||||
@ -167,16 +167,11 @@ static inline ipaddr_n_t get_src_ip(ipaddr_n_t dst, int local_offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// one sender thread
|
// one sender thread
|
||||||
int send_run(void)
|
int send_run(int sock)
|
||||||
{
|
{
|
||||||
log_debug("send", "thread started");
|
log_debug("send", "thread started");
|
||||||
pthread_mutex_lock(&send_mutex);
|
pthread_mutex_lock(&send_mutex);
|
||||||
int sock;
|
|
||||||
if (zconf.dryrun) {
|
|
||||||
sock = get_dryrun_socket();
|
|
||||||
} else {
|
|
||||||
sock = get_socket();
|
|
||||||
}
|
|
||||||
struct sockaddr_ll sockaddr;
|
struct sockaddr_ll sockaddr;
|
||||||
// get source interface index
|
// get source interface index
|
||||||
struct ifreq if_idx;
|
struct ifreq if_idx;
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
#ifndef SEND_H
|
#ifndef SEND_H
|
||||||
#define SEND_H
|
#define SEND_H
|
||||||
|
|
||||||
|
int get_socket(void);
|
||||||
|
int get_dryrun_socket(void);
|
||||||
int send_init(void);
|
int send_init(void);
|
||||||
int send_run(void);
|
int send_run(int);
|
||||||
|
|
||||||
#endif //_SEND_H
|
#endif //SEND_H
|
||||||
|
15
src/zmap.c
15
src/zmap.c
@ -90,10 +90,12 @@ static void set_cpu(void)
|
|||||||
pthread_mutex_unlock(&cpu_affinity_mutex);
|
pthread_mutex_unlock(&cpu_affinity_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* start_send(__attribute__((unused)) void *arg)
|
static void* start_send(void *arg)
|
||||||
{
|
{
|
||||||
|
uintptr_t v = (uintptr_t) arg;
|
||||||
|
int sock = (int) v & 0xFFFF;
|
||||||
set_cpu();
|
set_cpu();
|
||||||
send_run();
|
send_run(sock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +240,14 @@ static void start_zmap(void)
|
|||||||
assert(tsend);
|
assert(tsend);
|
||||||
log_debug("zmap", "using %d sender threads", zconf.senders);
|
log_debug("zmap", "using %d sender threads", zconf.senders);
|
||||||
for (int i=0; i < zconf.senders; i++) {
|
for (int i=0; i < zconf.senders; i++) {
|
||||||
int r = pthread_create(&tsend[i], NULL, start_send, NULL);
|
uintptr_t sock;
|
||||||
|
if (zconf.dryrun) {
|
||||||
|
sock = get_dryrun_socket();
|
||||||
|
} else {
|
||||||
|
sock = get_socket();
|
||||||
|
}
|
||||||
|
|
||||||
|
int r = pthread_create(&tsend[i], NULL, start_send, (void*) sock);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
log_fatal("zmap", "unable to create send thread");
|
log_fatal("zmap", "unable to create send thread");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
Loading…
Reference in New Issue
Block a user