21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/kernel.h>
25 #include <linux/socket.h>
26 #include <linux/tcp.h>
27 #include <linux/slab.h>
29 #include <linux/module.h>
31 #include <linux/time.h>
53 static const char procname[] =
"tcpprobe";
79 static inline int tcp_probe_used(
void)
81 return (tcp_probe.head - tcp_probe.tail) & (
bufsize - 1);
84 static inline int tcp_probe_avail(
void)
86 return bufsize - tcp_probe_used() - 1;
96 const struct tcp_sock *tp = tcp_sk(sk);
97 const struct inet_sock *inet = inet_sk(sk);
104 spin_lock(&tcp_probe.lock);
106 if (tcp_probe_avail() > 1) {
107 struct tcp_log *
p = tcp_probe.log + tcp_probe.head;
112 p->
daddr = inet->inet_daddr;
119 p->
ssthresh = tcp_current_ssthresh(sk);
122 tcp_probe.head = (tcp_probe.head + 1) & (
bufsize - 1);
125 spin_unlock(&tcp_probe.lock);
134 static struct jprobe tcp_jprobe = {
136 .symbol_name =
"tcp_rcv_established",
138 .entry = jtcp_rcv_established,
144 spin_lock_bh(&tcp_probe.lock);
145 tcp_probe.head = tcp_probe.tail = 0;
147 spin_unlock_bh(&tcp_probe.lock);
152 static int tcpprobe_sprint(
char *tbuf,
int n)
155 = tcp_probe.log + tcp_probe.tail;
157 = ktime_to_timespec(ktime_sub(p->
tstamp, tcp_probe.start));
160 "%lu.%09lu %pI4:%u %pI4:%u %d %#x %#x %u %u %u %u\n",
161 (
unsigned long) tv.
tv_sec,
170 size_t len, loff_t *ppos)
184 tcp_probe_used() > 0);
188 spin_lock_bh(&tcp_probe.lock);
189 if (tcp_probe.head == tcp_probe.tail) {
191 spin_unlock_bh(&tcp_probe.lock);
195 width = tcpprobe_sprint(tbuf,
sizeof(tbuf));
197 if (cnt + width < len)
198 tcp_probe.tail = (tcp_probe.tail + 1) & (
bufsize - 1);
200 spin_unlock_bh(&tcp_probe.lock);
204 if (cnt + width >= len)
212 return cnt == 0 ? error :
cnt;
217 .open = tcpprobe_open,
218 .read = tcpprobe_read,
222 static __init int tcpprobe_init(
void)
249 kfree(tcp_probe.log);
254 static __exit void tcpprobe_exit(
void)
258 kfree(tcp_probe.log);