1 /* (C) 1999-2001 Paul `Rusty' Russell
2 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/types.h>
10 #include <linux/sched.h>
11 #include <linux/timer.h>
12 #include <linux/netfilter.h>
14 #include <linux/udp.h>
15 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
17 unsigned long ip_ct_udp_timeout = 30*HZ;
18 unsigned long ip_ct_udp_timeout_stream = 180*HZ;
20 static int udp_pkt_to_tuple(const struct sk_buff *skb,
22 struct ip_conntrack_tuple *tuple)
26 /* Actually only need first 8 bytes. */
27 if (skb_copy_bits(skb, dataoff, &hdr, 8) != 0)
30 tuple->src.u.udp.port = hdr.source;
31 tuple->dst.u.udp.port = hdr.dest;
36 static int udp_invert_tuple(struct ip_conntrack_tuple *tuple,
37 const struct ip_conntrack_tuple *orig)
39 tuple->src.u.udp.port = orig->dst.u.udp.port;
40 tuple->dst.u.udp.port = orig->src.u.udp.port;
44 /* Print out the per-protocol part of the tuple. */
45 static unsigned int udp_print_tuple(char *buffer,
46 const struct ip_conntrack_tuple *tuple)
48 return sprintf(buffer, "sport=%hu dport=%hu ",
49 ntohs(tuple->src.u.udp.port),
50 ntohs(tuple->dst.u.udp.port));
53 /* Print out the private part of the conntrack. */
54 static unsigned int udp_print_conntrack(char *buffer,
55 const struct ip_conntrack *conntrack)
60 /* Returns verdict for packet, and may modify conntracktype */
61 static int udp_packet(struct ip_conntrack *conntrack,
62 const struct sk_buff *skb,
63 enum ip_conntrack_info conntrackinfo)
65 /* If we've seen traffic both ways, this is some kind of UDP
66 stream. Extend timeout. */
67 if (test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)) {
68 ip_ct_refresh(conntrack, ip_ct_udp_timeout_stream);
69 /* Also, more likely to be important, and not a probe */
70 set_bit(IPS_ASSURED_BIT, &conntrack->status);
72 ip_ct_refresh(conntrack, ip_ct_udp_timeout);
77 /* Called when a new connection for this protocol found. */
78 static int udp_new(struct ip_conntrack *conntrack, const struct sk_buff *skb)
83 struct ip_conntrack_protocol ip_conntrack_protocol_udp
84 = { { NULL, NULL }, IPPROTO_UDP, "udp",
85 udp_pkt_to_tuple, udp_invert_tuple, udp_print_tuple, udp_print_conntrack,
86 udp_packet, udp_new, NULL, NULL, NULL };