diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index cbba9cd4ed0d..05671ce00527 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -571,7 +571,7 @@ tcp_input(struct mbuf *m, int off0) */ if ((tcp_log_in_vain == 1 && (thflags & TH_SYN)) || tcp_log_in_vain == 2) { - if ((s = tcp_log_addrs(NULL, th, (void *)ip, ip6))) + if ((s = tcp_log_vain(NULL, th, (void *)ip, ip6))) log(LOG_INFO, "%s; %s: Connection attempt " "to closed port\n", s, __func__); } diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index f23a54049120..fe8f79a61ed2 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -268,6 +268,8 @@ VNET_DEFINE(uma_zone_t, sack_hole_zone); static struct inpcb *tcp_notify(struct inpcb *, int); static void tcp_isn_tick(void *); +static char * tcp_log_addr(struct in_conninfo *inc, struct tcphdr *th, + void *ip4hdr, const void *ip6hdr); /* * Target size of TCP PCB hash tables. Must be a power of two. @@ -2233,10 +2235,34 @@ SYSCTL_PROC(_net_inet_tcp, TCPCTL_DROP, drop, * Due to header inclusion and ordering limitations the struct ip * and ip6_hdr pointers have to be passed as void pointers. */ +char * +tcp_log_vain(struct in_conninfo *inc, struct tcphdr *th, void *ip4hdr, + const void *ip6hdr) +{ + + /* Is logging enabled? */ + if (tcp_log_in_vain == 0) + return (NULL); + + return (tcp_log_addr(inc, th, ip4hdr, ip6hdr)); +} + char * tcp_log_addrs(struct in_conninfo *inc, struct tcphdr *th, void *ip4hdr, const void *ip6hdr) { + + /* Is logging enabled? */ + if (tcp_log_debug == 0) + return (NULL); + + return (tcp_log_addr(inc, th, ip4hdr, ip6hdr)); +} + +static char * +tcp_log_addr(struct in_conninfo *inc, struct tcphdr *th, void *ip4hdr, + const void *ip6hdr) +{ char *s, *sp; size_t size; struct ip *ip; @@ -2259,10 +2285,6 @@ tcp_log_addrs(struct in_conninfo *inc, struct tcphdr *th, void *ip4hdr, 2 * INET_ADDRSTRLEN; #endif /* INET6 */ - /* Is logging enabled? */ - if (tcp_log_debug == 0 && tcp_log_in_vain == 0) - return (NULL); - s = malloc(size, M_TCPLOG, M_ZERO|M_NOWAIT); if (s == NULL) return (NULL); diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 5811439dcd60..7482277be293 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -611,6 +611,8 @@ void tcp_destroy(void); void tcp_fini(void *); char *tcp_log_addrs(struct in_conninfo *, struct tcphdr *, void *, const void *); +char *tcp_log_vain(struct in_conninfo *, struct tcphdr *, void *, + const void *); int tcp_reass(struct tcpcb *, struct tcphdr *, int *, struct mbuf *); void tcp_reass_init(void); #ifdef VIMAGE