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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/* Kernel module to match TCP MSS values. */
2
#include <linux/module.h>
3
#include <linux/skbuff.h>
4
#include <net/tcp.h>
5
 
6
#include <linux/netfilter_ipv4/ipt_tcpmss.h>
7
#include <linux/netfilter_ipv4/ip_tables.h>
8
 
9
#define TH_SYN 0x02
10
 
11
/* Returns 1 if the mss option is set and matched by the range, 0 otherwise */
12
static inline int
13
mssoption_match(u_int16_t min, u_int16_t max,
14
                const struct tcphdr *tcp,
15
                u_int16_t datalen,
16
                int invert,
17
                int *hotdrop)
18
{
19
        unsigned int i;
20
        const u_int8_t *opt = (u_int8_t *)tcp;
21
 
22
        /* If we don't have the whole header, drop packet. */
23
        if (tcp->doff * 4 > datalen) {
24
                *hotdrop = 1;
25
                return 0;
26
        }
27
 
28
        for (i = sizeof(struct tcphdr); i < tcp->doff * 4; ) {
29
                if ((opt[i] == TCPOPT_MSS)
30
                    && ((tcp->doff * 4 - i) >= TCPOLEN_MSS)
31
                    && (opt[i+1] == TCPOLEN_MSS)) {
32
                        u_int16_t mssval;
33
 
34
                        mssval = (opt[i+2] << 8) | opt[i+3];
35
 
36
                        return (mssval >= min && mssval <= max) ^ invert;
37
                }
38
                if (opt[i] < 2) i++;
39
                else i += opt[i+1]?:1;
40
        }
41
 
42
        return invert;
43
}
44
 
45
static int
46
match(const struct sk_buff *skb,
47
      const struct net_device *in,
48
      const struct net_device *out,
49
      const void *matchinfo,
50
      int offset,
51
      const void *hdr,
52
      u_int16_t datalen,
53
      int *hotdrop)
54
{
55
        const struct ipt_tcpmss_match_info *info = matchinfo;
56
        const struct tcphdr *tcph = (void *)skb->nh.iph + skb->nh.iph->ihl*4;
57
 
58
        return mssoption_match(info->mss_min, info->mss_max, tcph,
59
                               skb->len - skb->nh.iph->ihl*4,
60
                               info->invert, hotdrop);
61
}
62
 
63
static inline int find_syn_match(const struct ipt_entry_match *m)
64
{
65
        const struct ipt_tcp *tcpinfo = (const struct ipt_tcp *)m->data;
66
 
67
        if (strcmp(m->u.kernel.match->name, "tcp") == 0
68
            && (tcpinfo->flg_cmp & TH_SYN)
69
            && !(tcpinfo->invflags & IPT_TCP_INV_FLAGS))
70
                return 1;
71
 
72
        return 0;
73
}
74
 
75
static int
76
checkentry(const char *tablename,
77
           const struct ipt_ip *ip,
78
           void *matchinfo,
79
           unsigned int matchsize,
80
           unsigned int hook_mask)
81
{
82
        if (matchsize != IPT_ALIGN(sizeof(struct ipt_tcpmss_match_info)))
83
                return 0;
84
 
85
        /* Must specify -p tcp */
86
        if (ip->proto != IPPROTO_TCP || (ip->invflags & IPT_INV_PROTO)) {
87
                printk("tcpmss: Only works on TCP packets\n");
88
                return 0;
89
        }
90
 
91
        return 1;
92
}
93
 
94
static struct ipt_match tcpmss_match
95
= { { NULL, NULL }, "tcpmss", &match, &checkentry, NULL, THIS_MODULE };
96
 
97
static int __init init(void)
98
{
99
        return ipt_register_match(&tcpmss_match);
100
}
101
 
102
static void __exit fini(void)
103
{
104
        ipt_unregister_match(&tcpmss_match);
105
}
106
 
107
module_init(init);
108
module_exit(fini);
109
MODULE_LICENSE("GPL");

powered by: WebSVN 2.1.0

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