diff --git a/graftcp.c b/graftcp.c index 26e5e42..be5a4b0 100644 --- a/graftcp.c +++ b/graftcp.c @@ -245,10 +245,15 @@ void connect_pre_handle(struct proc_info *pinfp) return; } - if (dest_sa.sin_family == AF_INET) /* IPv4 */ + if (dest_sa.sin_family == AF_INET) { /* IPv4 */ + memcpy(si->dest_addr, &dest_sa, sizeof(dest_sa)); + si->dest_addr_len = sizeof(dest_sa); putdata(pinfp->pid, addr, (char *)&PROXY_SA, sizeof(PROXY_SA)); - else /* IPv6 */ + } else { /* IPv6 */ + memcpy(si->dest_addr, &dest_sa6, sizeof(dest_sa6)); + si->dest_addr_len = sizeof(dest_sa6); putdata(pinfp->pid, addr, (char *)&PROXY_SA6, sizeof(PROXY_SA6)); + } char buf[1024] = { 0 }; strcpy(buf, dest_ip_addr_str); @@ -306,6 +311,16 @@ void socket_exiting_handle(struct proc_info *pinfp, int fd) add_socket_info(si); } +void connect_exiting_handle(struct proc_info *pinfp) +{ + int socket_fd = get_syscall_arg(pinfp->pid, 0); + struct socket_info *si = find_socket_info((socket_fd << 31) + pinfp->pid); + if (si == NULL || si->dest_addr_len == 0) + return; + long addr = get_syscall_arg(pinfp->pid, 1); + putdata(pinfp->pid, addr, si->dest_addr, si->dest_addr_len); +} + void do_child(struct graftcp_conf *conf, int argc, char **argv) { char *args[argc + 1]; @@ -409,6 +424,9 @@ int trace_syscall_exiting(struct proc_info *pinfp) } socket_exiting_handle(pinfp, child_ret); break; + case SYS_connect: + connect_exiting_handle(pinfp); + break; } end: pinfp->flags &= ~FLAG_INSYSCALL; diff --git a/graftcp.h b/graftcp.h index 4dc6884..7cf6345 100644 --- a/graftcp.h +++ b/graftcp.h @@ -87,6 +87,8 @@ struct socket_info { uint64_t magic_fd; int domain; int type; + size_t dest_addr_len; + char dest_addr[sizeof(struct sockaddr_in6)]; struct timeval conn_ti; UT_hash_handle hh; /* makes this structure hashable */ };