@@ -311,6 +311,7 @@ extern struct buffer_instance *first_instance;
int trace_net_make(int port, enum port_type type);
int trace_net_search(int start_port, int *sfd, enum port_type type);
+int trace_net_print_connection(int fd);
struct buffer_instance *allocate_instance(const char *name);
void add_instance(struct buffer_instance *instance, int cpu_count);
@@ -366,6 +367,7 @@ int get_vsocket_params(int fd, unsigned int *lcid, unsigned int *rcid);
int trace_vsock_get_port(int sd, unsigned int *port);
bool trace_vsock_can_splice_read(void);
int trace_vsock_local_cid(void);
+int trace_vsock_print_connection(int fd);
#else
static inline int trace_vsock_open(unsigned int cid, unsigned int port)
{
@@ -403,6 +405,10 @@ static inline int trace_vsock_local_cid(void)
{
return -ENOTSUP;
}
+static inline int trace_vsock_print_connection(int fd)
+{
+ return -1;
+}
#endif /* VSOCK */
/* No longer in event-utils.h */
@@ -109,6 +109,18 @@ static char *get_clock(int argc, char **argv)
return NULL;
}
+static void trace_print_connection(int fd, bool network)
+{
+ int ret;
+
+ if (network)
+ ret = trace_net_print_connection(fd);
+ else
+ ret = trace_vsock_print_connection(fd);
+ if (ret < 0)
+ tracecmd_debug("Could not print connection fd:%d\n", fd);
+}
+
static void agent_handle(int sd, int nr_cpus, int page_size, bool network)
{
struct tracecmd_tsync_protos *tsync_protos = NULL;
@@ -273,6 +285,8 @@ static void agent_serve(unsigned int port, bool do_daemon, bool network)
continue;
die("accept");
}
+ if (tracecmd_get_debug())
+ trace_print_connection(cd, network);
if (handler_pid)
goto busy;
@@ -756,6 +756,28 @@ static int do_fork(int cfd)
return 0;
}
+int trace_net_print_connection(int fd)
+{
+ char host[NI_MAXHOST], service[NI_MAXSERV];
+ struct sockaddr_storage net_addr;
+ socklen_t addr_len;
+
+ addr_len = sizeof(net_addr);
+ if (getpeername(fd, (struct sockaddr *)&net_addr, &addr_len))
+ return -1;
+
+ if (getnameinfo((struct sockaddr *)&net_addr, addr_len,
+ host, NI_MAXHOST,
+ service, NI_MAXSERV, NI_NUMERICSERV))
+ return -1;
+
+ if (tracecmd_get_debug())
+ tracecmd_debug("Connected to %s:%s fd:%d\n", host, service, fd);
+ else
+ tracecmd_plog("Connected to %s:%s\n", host, service);
+ return 0;
+}
+
static int do_connection(int cfd, struct sockaddr *addr,
socklen_t addr_len)
{
@@ -94,6 +94,26 @@ int get_vsocket_params(int fd, unsigned int *lcid, unsigned int *rcid)
return 0;
}
+int trace_vsock_print_connection(int fd)
+{
+ struct sockaddr_vm vm_addr;
+ socklen_t addr_len;
+ int cid, port;
+
+ addr_len = sizeof(vm_addr);
+ if (getpeername(fd, (struct sockaddr *)&vm_addr, &addr_len))
+ return -1;
+ if (vm_addr.svm_family != AF_VSOCK)
+ return -1;
+ cid = vm_addr.svm_cid;
+ port = vm_addr.svm_port;
+ if (tracecmd_get_debug())
+ tracecmd_debug("Connected to @%u:%u fd:%d\n", cid, port, fd);
+ else
+ tracecmd_plog("Connected to @%u:%u\n", cid, port);
+ return 0;
+}
+
static int try_splice_read_vsock(void)
{
int ret, sd, brass[2];