diff options
author | andre <andre@FreeBSD.org> | 2007-05-18 19:58:37 +0000 |
---|---|---|
committer | andre <andre@FreeBSD.org> | 2007-05-18 19:58:37 +0000 |
commit | 696f13b7fdbc64ff2137b4759d3fcc0bae6121b3 (patch) | |
tree | d51b510129fddae06935d023c8528c4a3a87232d /sys/netinet/tcp_input.c | |
parent | b753e575a766d7e9e6f70bacf49e41516a9e5556 (diff) | |
download | FreeBSD-src-696f13b7fdbc64ff2137b4759d3fcc0bae6121b3.zip FreeBSD-src-696f13b7fdbc64ff2137b4759d3fcc0bae6121b3.tar.gz |
Add tcp_log_addrs() function to generate and standardized TCP log line
for use thoughout the tcp subsystem.
It is IPv4 and IPv6 aware creates a line in the following format:
"TCP: [1.2.3.4]:50332 to [1.2.3.4]:80 tcpflags <RST>"
A "\n" is not included at the end. The caller is supposed to add
further information after the standard tcp log header.
The function returns a NUL terminated string which the caller has
to free(s, M_TCPLOG) after use. All memory allocation is done
with M_NOWAIT and the return value may be NULL in memory shortage
situations.
Either struct in_conninfo || (struct tcphdr && (struct ip || struct
ip6_hdr) have to be supplied.
Due to ip[6].h header inclusion limitations and ordering issues the
struct ip and struct ip6_hdr parameters have to be casted and passed
as void * pointers.
tcp_log_addrs(struct in_conninfo *inc, struct tcphdr *th, void *ip4hdr,
void *ip6hdr)
Usage example:
struct ip *ip;
char *tcplog;
if (tcplog = tcp_log_addrs(NULL, th, (void *)ip, NULL)) {
log(LOG_DEBUG, "%s; %s: Connection attempt to closed port\n",
tcplog, __func__);
free(s, M_TCPLOG);
}
Diffstat (limited to 'sys/netinet/tcp_input.c')
-rw-r--r-- | sys/netinet/tcp_input.c | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 163b588..02a9c22 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -240,7 +240,6 @@ tcp_input(struct mbuf *m, int off0) #ifdef INET6 struct ip6_hdr *ip6 = NULL; int isipv6; - char ip6buf[INET6_ADDRSTRLEN]; #else const int isipv6 = 0; #endif @@ -481,30 +480,17 @@ findpcb: */ if ((tcp_log_in_vain == 1 && (thflags & TH_SYN)) || tcp_log_in_vain == 2) { -#ifndef INET6 - char dbuf[4*sizeof "123"], sbuf[4*sizeof "123"]; + char *s; +#ifdef INET6 + s = tcp_log_addrs(NULL, th, (void *)ip, (void *)ip6); #else - char dbuf[INET6_ADDRSTRLEN+2], sbuf[INET6_ADDRSTRLEN+2]; - if (isipv6) { - strcpy(dbuf, "["); - strcat(dbuf, - ip6_sprintf(ip6buf, &ip6->ip6_dst)); - strcat(dbuf, "]"); - strcpy(sbuf, "["); - strcat(sbuf, - ip6_sprintf(ip6buf, &ip6->ip6_src)); - strcat(sbuf, "]"); - } else + s = tcp_log_addrs(NULL, th, (void *)ip, NULL); #endif /* INET6 */ - { - strcpy(dbuf, inet_ntoa(ip->ip_dst)); - strcpy(sbuf, inet_ntoa(ip->ip_src)); + if (s != NULL) { + log(LOG_INFO, "%s; %s: Connection attempt " + "to closed port\n", s, __func__); + free(s, M_TCPLOG); } - log(LOG_INFO, - "Connection attempt to TCP %s:%d " - "from %s:%d flags:0x%02x\n", - dbuf, ntohs(th->th_dport), sbuf, - ntohs(th->th_sport), thflags); } /* * When blackholing do not respond with a RST but |