OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [ipv4/] [netfilter/] [ip_conntrack_tftp.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * Licensed under GNU GPL version 2 Copyright Magnus Boden <mb@ozaba.mine.nu>
3
 * Version: 0.0.7
4
 *
5
 * Thu 21 Mar 2002 Harald Welte <laforge@gnumonks.org>
6
 *      - port to newnat API
7
 *
8
 */
9
 
10
#include <linux/module.h>
11
#include <linux/ip.h>
12
#include <linux/udp.h>
13
 
14
#include <linux/netfilter.h>
15
#include <linux/netfilter_ipv4/ip_tables.h>
16
#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
17
#include <linux/netfilter_ipv4/ip_conntrack_tftp.h>
18
 
19
MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>");
20
MODULE_DESCRIPTION("Netfilter connection tracking module for tftp");
21
MODULE_LICENSE("GPL");
22
 
23
#define MAX_PORTS 8
24
static int ports[MAX_PORTS];
25
static int ports_c = 0;
26
#ifdef MODULE_PARM
27
MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
28
MODULE_PARM_DESC(ports, "port numbers of tftp servers");
29
#endif
30
 
31
#if 0
32
#define DEBUGP(format, args...) printk(__FILE__ ":" __FUNCTION__ ": " \
33
                                       format, ## args)
34
#else
35
#define DEBUGP(format, args...)
36
#endif
37
 
38
static int tftp_help(const struct iphdr *iph, size_t len,
39
        struct ip_conntrack *ct,
40
        enum ip_conntrack_info ctinfo)
41
{
42
        struct udphdr *udph = (void *)iph + iph->ihl * 4;
43
        struct tftphdr *tftph = (void *)udph + 8;
44
        struct ip_conntrack_expect exp;
45
 
46
        switch (ntohs(tftph->opcode)) {
47
        /* RRQ and WRQ works the same way */
48
        case TFTP_OPCODE_READ:
49
        case TFTP_OPCODE_WRITE:
50
                DEBUGP("");
51
                DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
52
                DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
53
                memset(&exp, 0, sizeof(exp));
54
 
55
                exp.tuple = ct->tuplehash[IP_CT_DIR_REPLY].tuple;
56
                exp.mask.src.ip = 0xffffffff;
57
                exp.mask.dst.ip = 0xffffffff;
58
                exp.mask.dst.u.udp.port = 0xffff;
59
                exp.mask.dst.protonum = 0xffff;
60
                exp.expectfn = NULL;
61
 
62
                DEBUGP("expect: ");
63
                DUMP_TUPLE(&exp.tuple);
64
                DUMP_TUPLE(&exp.mask);
65
                ip_conntrack_expect_related(ct, &exp);
66
                break;
67
        default:
68
                DEBUGP("Unknown opcode\n");
69
        }
70
        return NF_ACCEPT;
71
}
72
 
73
static struct ip_conntrack_helper tftp[MAX_PORTS];
74
static char tftp_names[MAX_PORTS][10];
75
 
76
static void fini(void)
77
{
78
        int i;
79
 
80
        for (i = 0 ; i < ports_c; i++) {
81
                DEBUGP("unregistering helper for port %d\n",
82
                        ports[i]);
83
                ip_conntrack_helper_unregister(&tftp[i]);
84
        }
85
}
86
 
87
static int __init init(void)
88
{
89
        int i, ret;
90
        char *tmpname;
91
 
92
        if (!ports[0])
93
                ports[0]=TFTP_PORT;
94
 
95
        for (i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
96
                /* Create helper structure */
97
                tftp[i].tuple.dst.protonum = IPPROTO_UDP;
98
                tftp[i].tuple.src.u.udp.port = htons(ports[i]);
99
                tftp[i].mask.dst.protonum = 0xFFFF;
100
                tftp[i].mask.src.u.udp.port = 0xFFFF;
101
                tftp[i].max_expected = 1;
102
                tftp[i].timeout = 0;
103
                tftp[i].flags = IP_CT_HELPER_F_REUSE_EXPECT;
104
                tftp[i].me = THIS_MODULE;
105
                tftp[i].help = tftp_help;
106
 
107
                tmpname = &tftp_names[i][0];
108
                if (ports[i] == TFTP_PORT)
109
                        sprintf(tmpname, "tftp");
110
                else
111
                        sprintf(tmpname, "tftp-%d", i);
112
                tftp[i].name = tmpname;
113
 
114
                DEBUGP("port #%d: %d\n", i, ports[i]);
115
 
116
                ret=ip_conntrack_helper_register(&tftp[i]);
117
                if (ret) {
118
                        printk("ERROR registering helper for port %d\n",
119
                                ports[i]);
120
                        fini();
121
                        return(ret);
122
                }
123
                ports_c++;
124
        }
125
        return(0);
126
}
127
 
128
module_init(init);
129
module_exit(fini);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.