aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-08-23 10:16:33 -0400
committerDavid S. Miller <davem@davemloft.net>2013-08-27 15:53:34 -0400
commitb1dcdc68b1f4cc77f603d7507f7a14f1f4864d41 (patch)
tree68d57d467880c4a8af41a88952dbee3a39b232b5
parentabd939d2fde990ddf45d5a61efcb3511f059805f (diff)
net: tcp_probe: allow more advanced ingress filtering by mark
Currently, the tcp_probe snooper can either filter packets by a given port (handed to the module via module parameter e.g. port=80) or lets all TCP traffic pass (port=0, default). When a port is specified, the port number is tested against the sk's source/destination port. Thus, if one of them matches, the information will be further processed for the log. As this is quite limited, allow for more advanced filtering possibilities which can facilitate debugging/analysis with the help of the tcp_probe snooper. Therefore, similarly as added to BPF machine in commit 7e75f93e ("pkt_sched: ingress socket filter by mark"), add the possibility to use skb->mark as a filter. If the mark is not being used otherwise, this allows ingress filtering by flow (e.g. in order to track updates from only a single flow, or a subset of all flows for a given port) and other things such as dynamic logging and reconfiguration without removing/re-inserting the tcp_probe module, etc. Simple example: insmod net/ipv4/tcp_probe.ko fwmark=8888 full=1 ... iptables -A INPUT -i eth4 -t mangle -p tcp --dport 22 \ --sport 60952 -j MARK --set-mark 8888 [... sampling interval ...] iptables -D INPUT -i eth4 -t mangle -p tcp --dport 22 \ --sport 60952 -j MARK --set-mark 8888 The current option to filter by a given port is still being preserved. A similar approach could be done for the sctp_probe module as a follow-up. Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/ipv4/tcp_probe.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
index 301a3effe579..622a4377b397 100644
--- a/net/ipv4/tcp_probe.c
+++ b/net/ipv4/tcp_probe.c
@@ -46,6 +46,10 @@ static unsigned int bufsize __read_mostly = 4096;
46MODULE_PARM_DESC(bufsize, "Log buffer size in packets (4096)"); 46MODULE_PARM_DESC(bufsize, "Log buffer size in packets (4096)");
47module_param(bufsize, uint, 0); 47module_param(bufsize, uint, 0);
48 48
49static unsigned int fwmark __read_mostly = 0;
50MODULE_PARM_DESC(fwmark, "skb mark to match (0=no mark)");
51module_param(fwmark, uint, 0);
52
49static int full __read_mostly; 53static int full __read_mostly;
50MODULE_PARM_DESC(full, "Full log (1=every ack packet received, 0=only cwnd changes)"); 54MODULE_PARM_DESC(full, "Full log (1=every ack packet received, 0=only cwnd changes)");
51module_param(full, int, 0); 55module_param(full, int, 0);
@@ -124,9 +128,11 @@ static int jtcp_rcv_established(struct sock *sk, struct sk_buff *skb,
124 const struct tcp_sock *tp = tcp_sk(sk); 128 const struct tcp_sock *tp = tcp_sk(sk);
125 const struct inet_sock *inet = inet_sk(sk); 129 const struct inet_sock *inet = inet_sk(sk);
126 130
127 /* Only update if port matches */ 131 /* Only update if port or skb mark matches */
128 if ((port == 0 || ntohs(inet->inet_dport) == port || 132 if (((port == 0 && fwmark == 0) ||
129 ntohs(inet->inet_sport) == port) && 133 ntohs(inet->inet_dport) == port ||
134 ntohs(inet->inet_sport) == port ||
135 (fwmark > 0 && skb->mark == fwmark)) &&
130 (full || tp->snd_cwnd != tcp_probe.lastcwnd)) { 136 (full || tp->snd_cwnd != tcp_probe.lastcwnd)) {
131 137
132 spin_lock(&tcp_probe.lock); 138 spin_lock(&tcp_probe.lock);
@@ -284,7 +290,8 @@ static __init int tcpprobe_init(void)
284 if (ret) 290 if (ret)
285 goto err1; 291 goto err1;
286 292
287 pr_info("probe registered (port=%d) bufsize=%u\n", port, bufsize); 293 pr_info("probe registered (port=%d/fwmark=%u) bufsize=%u\n",
294 port, fwmark, bufsize);
288 return 0; 295 return 0;
289 err1: 296 err1:
290 remove_proc_entry(procname, init_net.proc_net); 297 remove_proc_entry(procname, init_net.proc_net);