- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
ip_conntrack_proto_udp.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:
Linux/Unix编程
开发平台:
Unix_Linux
- #include <linux/types.h>
- #include <linux/sched.h>
- #include <linux/timer.h>
- #include <linux/netfilter.h>
- #include <linux/in.h>
- #include <linux/udp.h>
- #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
- #define UDP_TIMEOUT (30*HZ)
- #define UDP_STREAM_TIMEOUT (180*HZ)
- static int udp_pkt_to_tuple(const void *datah, size_t datalen,
- struct ip_conntrack_tuple *tuple)
- {
- const struct udphdr *hdr = datah;
- tuple->src.u.udp.port = hdr->source;
- tuple->dst.u.udp.port = hdr->dest;
- return 1;
- }
- static int udp_invert_tuple(struct ip_conntrack_tuple *tuple,
- const struct ip_conntrack_tuple *orig)
- {
- tuple->src.u.udp.port = orig->dst.u.udp.port;
- tuple->dst.u.udp.port = orig->src.u.udp.port;
- return 1;
- }
- /* Print out the per-protocol part of the tuple. */
- static unsigned int udp_print_tuple(char *buffer,
- const struct ip_conntrack_tuple *tuple)
- {
- return sprintf(buffer, "sport=%hu dport=%hu ",
- ntohs(tuple->src.u.udp.port),
- ntohs(tuple->dst.u.udp.port));
- }
- /* Print out the private part of the conntrack. */
- static unsigned int udp_print_conntrack(char *buffer,
- const struct ip_conntrack *conntrack)
- {
- return 0;
- }
- /* Returns verdict for packet, and may modify conntracktype */
- static int udp_packet(struct ip_conntrack *conntrack,
- struct iphdr *iph, size_t len,
- enum ip_conntrack_info conntrackinfo)
- {
- /* If we've seen traffic both ways, this is some kind of UDP
- stream. Extend timeout. */
- if (conntrack->status & IPS_SEEN_REPLY) {
- ip_ct_refresh(conntrack, UDP_STREAM_TIMEOUT);
- /* Also, more likely to be important, and not a probe */
- set_bit(IPS_ASSURED_BIT, &conntrack->status);
- } else
- ip_ct_refresh(conntrack, UDP_TIMEOUT);
- return NF_ACCEPT;
- }
- /* Called when a new connection for this protocol found. */
- static int udp_new(struct ip_conntrack *conntrack,
- struct iphdr *iph, size_t len)
- {
- return 1;
- }
- struct ip_conntrack_protocol ip_conntrack_protocol_udp
- = { { NULL, NULL }, IPPROTO_UDP, "udp",
- udp_pkt_to_tuple, udp_invert_tuple, udp_print_tuple, udp_print_conntrack,
- udp_packet, udp_new, NULL, NULL, NULL };