Commit f925d0a6 authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller

net: tcp_probe: add IPv6 support

The tcp_probe currently only supports analysis of IPv4 connections.
Therefore, it would be nice to have IPv6 supported as well. Since we
have the recently added %pISpc specifier that is IPv4/IPv6 generic,
build related sockaddress structures from the flow information and
pass this to our format string. Tested with SSH and HTTP sessions
on IPv4 and IPv6.
Signed-off-by: default avatarDaniel Borkmann <dborkman@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d8cdeda6
...@@ -54,8 +54,11 @@ static const char procname[] = "tcpprobe"; ...@@ -54,8 +54,11 @@ static const char procname[] = "tcpprobe";
struct tcp_log { struct tcp_log {
ktime_t tstamp; ktime_t tstamp;
__be32 saddr, daddr; union {
__be16 sport, dport; struct sockaddr raw;
struct sockaddr_in v4;
struct sockaddr_in6 v6;
} src, dst;
u16 length; u16 length;
u32 snd_nxt; u32 snd_nxt;
u32 snd_una; u32 snd_una;
...@@ -87,6 +90,30 @@ static inline int tcp_probe_avail(void) ...@@ -87,6 +90,30 @@ static inline int tcp_probe_avail(void)
return bufsize - tcp_probe_used() - 1; return bufsize - tcp_probe_used() - 1;
} }
#define tcp_probe_copy_fl_to_si4(inet, si4, mem) \
do { \
si4.sin_family = AF_INET; \
si4.sin_port = inet->inet_##mem##port; \
si4.sin_addr.s_addr = inet->inet_##mem##addr; \
} while (0) \
#if IS_ENABLED(CONFIG_IPV6)
#define tcp_probe_copy_fl_to_si6(inet, si6, mem) \
do { \
struct ipv6_pinfo *pi6 = inet->pinet6; \
si6.sin6_family = AF_INET6; \
si6.sin6_port = inet->inet_##mem##port; \
si6.sin6_addr = pi6->mem##addr; \
si6.sin6_flowinfo = 0; /* No need here. */ \
si6.sin6_scope_id = 0; /* No need here. */ \
} while (0)
#else
#define tcp_probe_copy_fl_to_si6(fl, si6, mem) \
do { \
memset(&si6, 0, sizeof(si6)); \
} while (0)
#endif
/* /*
* Hook inserted to be called before each receive packet. * Hook inserted to be called before each receive packet.
* Note: arguments must match tcp_rcv_established()! * Note: arguments must match tcp_rcv_established()!
...@@ -108,10 +135,19 @@ static int jtcp_rcv_established(struct sock *sk, struct sk_buff *skb, ...@@ -108,10 +135,19 @@ static int jtcp_rcv_established(struct sock *sk, struct sk_buff *skb,
struct tcp_log *p = tcp_probe.log + tcp_probe.head; struct tcp_log *p = tcp_probe.log + tcp_probe.head;
p->tstamp = ktime_get(); p->tstamp = ktime_get();
p->saddr = inet->inet_saddr; switch (sk->sk_family) {
p->sport = inet->inet_sport; case AF_INET:
p->daddr = inet->inet_daddr; tcp_probe_copy_fl_to_si4(inet, p->src.v4, s);
p->dport = inet->inet_dport; tcp_probe_copy_fl_to_si4(inet, p->dst.v4, d);
break;
case AF_INET6:
tcp_probe_copy_fl_to_si6(inet, p->src.v6, s);
tcp_probe_copy_fl_to_si6(inet, p->dst.v6, d);
break;
default:
BUG();
}
p->length = skb->len; p->length = skb->len;
p->snd_nxt = tp->snd_nxt; p->snd_nxt = tp->snd_nxt;
p->snd_una = tp->snd_una; p->snd_una = tp->snd_una;
...@@ -159,12 +195,10 @@ static int tcpprobe_sprint(char *tbuf, int n) ...@@ -159,12 +195,10 @@ static int tcpprobe_sprint(char *tbuf, int n)
= ktime_to_timespec(ktime_sub(p->tstamp, tcp_probe.start)); = ktime_to_timespec(ktime_sub(p->tstamp, tcp_probe.start));
return scnprintf(tbuf, n, return scnprintf(tbuf, n,
"%lu.%09lu %pI4:%u %pI4:%u %d %#x %#x %u %u %u %u %u\n", "%lu.%09lu %pISpc %pISpc %d %#x %#x %u %u %u %u %u\n",
(unsigned long) tv.tv_sec, (unsigned long) tv.tv_sec,
(unsigned long) tv.tv_nsec, (unsigned long) tv.tv_nsec,
&p->saddr, ntohs(p->sport), &p->src, &p->dst, p->length, p->snd_nxt, p->snd_una,
&p->daddr, ntohs(p->dport),
p->length, p->snd_nxt, p->snd_una,
p->snd_cwnd, p->ssthresh, p->snd_wnd, p->srtt, p->rcv_wnd); p->snd_cwnd, p->ssthresh, p->snd_wnd, p->srtt, p->rcv_wnd);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment