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 #if defined(CONFIG_MIPS_BRCM)
17 #include <linux/udp.h>
18 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
20 unsigned long ip_ct_udp_timeout = 30*HZ;
21 unsigned long ip_ct_udp_timeout_stream = 180*HZ;
23 #if defined(CONFIG_MIPS_BRCM)
24 unsigned long ip_ct_udp_unreplieddns_timeout = 1*HZ;
27 static int udp_pkt_to_tuple(const struct sk_buff *skb,
29 struct ip_conntrack_tuple *tuple)
33 /* Actually only need first 8 bytes. */
34 if (skb_copy_bits(skb, dataoff, &hdr, 8) != 0)
37 tuple->src.u.udp.port = hdr.source;
38 tuple->dst.u.udp.port = hdr.dest;
43 static int udp_invert_tuple(struct ip_conntrack_tuple *tuple,
44 const struct ip_conntrack_tuple *orig)
46 tuple->src.u.udp.port = orig->dst.u.udp.port;
47 tuple->dst.u.udp.port = orig->src.u.udp.port;
51 /* Print out the per-protocol part of the tuple. */
52 static unsigned int udp_print_tuple(char *buffer,
53 const struct ip_conntrack_tuple *tuple)
55 return sprintf(buffer, "sport=%hu dport=%hu ",
56 ntohs(tuple->src.u.udp.port),
57 ntohs(tuple->dst.u.udp.port));
60 /* Print out the private part of the conntrack. */
61 static unsigned int udp_print_conntrack(char *buffer,
62 const struct ip_conntrack *conntrack)
67 /* Returns verdict for packet, and may modify conntracktype */
68 static int udp_packet(struct ip_conntrack *conntrack,
69 const struct sk_buff *skb,
70 enum ip_conntrack_info conntrackinfo)
72 /* If we've seen traffic both ways, this is some kind of UDP
73 stream. Extend timeout. */
74 if (test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)) {
75 ip_ct_refresh(conntrack, ip_ct_udp_timeout_stream);
76 /* Also, more likely to be important, and not a probe */
77 set_bit(IPS_ASSURED_BIT, &conntrack->status);
79 #if defined(CONFIG_MIPS_BRCM)
81 /* Special handling of UNRPLIED DNS query packet: Song Wang
82 * Before NAT and WAN interface are UP, during that time window,
83 * if a DNS query is sent out, there will be an UNRPLIED DNS connection track entry
84 * in which expected src/dst are private IP addresses in the tuple.
85 * After NAT and WAN interface are UP, the UNRPLIED DNS connection track
86 * entry should go away ASAP to enable the establishment of the tuple with
87 * the expected src/dst that are public IP addresses.
89 struct iphdr *iph = skb->nh.iph;
90 struct udphdr *udph = (void *)iph + iph->ihl * 4;
91 __u16 dport = ntohs(udph->dest);
94 ip_ct_refresh(conntrack, ip_ct_udp_unreplieddns_timeout);
96 ip_ct_refresh(conntrack, ip_ct_udp_timeout);
99 ip_ct_refresh(conntrack, ip_ct_udp_timeout);
105 /* Called when a new connection for this protocol found. */
106 static int udp_new(struct ip_conntrack *conntrack, const struct sk_buff *skb)
111 struct ip_conntrack_protocol ip_conntrack_protocol_udp
112 = { { NULL, NULL }, IPPROTO_UDP, "udp",
113 udp_pkt_to_tuple, udp_invert_tuple, udp_print_tuple, udp_print_conntrack,
114 udp_packet, udp_new, NULL, NULL, NULL };