summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sock_events.c6
-rw-r--r--utils.c26
-rw-r--r--utils.h3
3 files changed, 33 insertions, 2 deletions
diff --git a/sock_events.c b/sock_events.c
index 9340d7d..a2b4108 100644
--- a/sock_events.c
+++ b/sock_events.c
@@ -85,7 +85,8 @@ void sock_ev_accept(int fd, int ret, int err, struct sockaddr *addr,
{
if (ret < 0)
return;
- udtrace_add_fd(ret);
+ LOG("accept(fd=%d on parent fd=%d)\n", ret, fd);
+ udtrace_add_fd_child(fd, ret);
}
void sock_ev_accept4(int fd, int ret, int err, struct sockaddr *addr,
@@ -93,7 +94,8 @@ void sock_ev_accept4(int fd, int ret, int err, struct sockaddr *addr,
{
if (ret < 0)
return;
- udtrace_add_fd(ret);
+ LOG("accept(fd=%d on parent fd=%d)\n", ret, fd);
+ udtrace_add_fd_child(fd, ret);
}
void sock_ev_send(int fd, int ret, int err, const void *buf, size_t bytes,
diff --git a/utils.c b/utils.c
index f188205..e1b0d7d 100644
--- a/utils.c
+++ b/utils.c
@@ -85,6 +85,32 @@ void udtrace_add_fd(int fd)
ss->fd = fd;
}
+/* add a file descriptor from the list of to-be-traced ones */
+void udtrace_add_fd_child(int pfd, int cfd)
+{
+ struct sock_state *pss, *css;
+
+ /* Find the parent socket state first */
+ pss = udtrace_sstate_by_fd(pfd);
+ if (!pss) {
+ LOG("Couldn't find parent UNIX FD %d for %d\n", pfd, cfd);
+ return;
+ }
+
+ /* Find an unused state in unix_fds */
+ css = udtrace_sstate_by_fd(-1);
+ if (!css) {
+ LOG("Couldn't add UNIX FD %d (no space in unix_fds)\n", cfd);
+ return;
+ }
+
+ LOG("Adding FD %d as a child of %d\n", cfd, pfd);
+
+ css->dissector = pss->dissector;
+ css->path = strdup(pss->path);
+ css->fd = cfd;
+}
+
/* delete a file descriptor from the list of to-be-traced ones */
void udtrace_del_fd(int fd)
{
diff --git a/utils.h b/utils.h
index 8145c9b..6829ffe 100644
--- a/utils.h
+++ b/utils.h
@@ -21,6 +21,9 @@ struct sock_state *udtrace_sstate_by_fd(int fd);
/* add a file descriptor from the list of to-be-traced ones */
void udtrace_add_fd(int fd);
+/* add a file descriptor from the list of to-be-traced ones */
+void udtrace_add_fd_child(int pfd, int cfd);
+
/* delete a file descriptor from the list of to-be-traced ones */
void udtrace_del_fd(int fd);
personal git repositories of Harald Welte. Your mileage may vary