~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to net/netfilter/xt_sctp.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1
2
#include <linux/module.h>
2
3
#include <linux/skbuff.h>
3
4
#include <net/ip.h>
4
5
#include <net/ipv6.h>
 
6
#include <net/sctp/sctp.h>
5
7
#include <linux/sctp.h>
6
8
 
7
9
#include <linux/netfilter/x_tables.h>
15
17
MODULE_ALIAS("ipt_sctp");
16
18
MODULE_ALIAS("ip6t_sctp");
17
19
 
18
 
#ifdef DEBUG_SCTP
19
 
#define duprintf(format, args...) printk(format , ## args)
20
 
#else
21
 
#define duprintf(format, args...)
22
 
#endif
23
 
 
24
20
#define SCCHECK(cond, option, flag, invflag) (!((flag) & (option)) \
25
21
                                              || (!!((invflag) & (option)) ^ (cond)))
26
22
 
52
48
        const struct xt_sctp_flag_info *flag_info = info->flag_info;
53
49
        int flag_count = info->flag_count;
54
50
 
55
 
#ifdef DEBUG_SCTP
 
51
#ifdef DEBUG
56
52
        int i = 0;
57
53
#endif
58
54
 
62
58
        do {
63
59
                sch = skb_header_pointer(skb, offset, sizeof(_sch), &_sch);
64
60
                if (sch == NULL || sch->length == 0) {
65
 
                        duprintf("Dropping invalid SCTP packet.\n");
 
61
                        pr_debug("Dropping invalid SCTP packet.\n");
66
62
                        *hotdrop = true;
67
63
                        return false;
68
64
                }
69
 
 
70
 
                duprintf("Chunk num: %d\toffset: %d\ttype: %d\tlength: %d\tflags: %x\n",
71
 
                                ++i, offset, sch->type, htons(sch->length), sch->flags);
72
 
 
73
 
                offset += (ntohs(sch->length) + 3) & ~3;
74
 
 
75
 
                duprintf("skb->len: %d\toffset: %d\n", skb->len, offset);
 
65
#ifdef DEBUG
 
66
                pr_debug("Chunk num: %d\toffset: %d\ttype: %d\tlength: %d"
 
67
                         "\tflags: %x\n",
 
68
                         ++i, offset, sch->type, htons(sch->length),
 
69
                         sch->flags);
 
70
#endif
 
71
                offset += WORD_ROUND(ntohs(sch->length));
 
72
 
 
73
                pr_debug("skb->len: %d\toffset: %d\n", skb->len, offset);
76
74
 
77
75
                if (SCTP_CHUNKMAP_IS_SET(info->chunkmap, sch->type)) {
78
76
                        switch (chunk_match_type) {
117
115
}
118
116
 
119
117
static bool
120
 
sctp_mt(const struct sk_buff *skb, const struct xt_match_param *par)
 
118
sctp_mt(const struct sk_buff *skb, struct xt_action_param *par)
121
119
{
122
120
        const struct xt_sctp_info *info = par->matchinfo;
123
121
        const sctp_sctphdr_t *sh;
124
122
        sctp_sctphdr_t _sh;
125
123
 
126
124
        if (par->fragoff != 0) {
127
 
                duprintf("Dropping non-first fragment.. FIXME\n");
 
125
                pr_debug("Dropping non-first fragment.. FIXME\n");
128
126
                return false;
129
127
        }
130
128
 
131
129
        sh = skb_header_pointer(skb, par->thoff, sizeof(_sh), &_sh);
132
130
        if (sh == NULL) {
133
 
                duprintf("Dropping evil TCP offset=0 tinygram.\n");
134
 
                *par->hotdrop = true;
 
131
                pr_debug("Dropping evil TCP offset=0 tinygram.\n");
 
132
                par->hotdrop = true;
135
133
                return false;
136
134
        }
137
 
        duprintf("spt: %d\tdpt: %d\n", ntohs(sh->source), ntohs(sh->dest));
 
135
        pr_debug("spt: %d\tdpt: %d\n", ntohs(sh->source), ntohs(sh->dest));
138
136
 
139
137
        return  SCCHECK(ntohs(sh->source) >= info->spts[0]
140
138
                        && ntohs(sh->source) <= info->spts[1],
143
141
                        && ntohs(sh->dest) <= info->dpts[1],
144
142
                        XT_SCTP_DEST_PORTS, info->flags, info->invflags)
145
143
                && SCCHECK(match_packet(skb, par->thoff + sizeof(sctp_sctphdr_t),
146
 
                                        info, par->hotdrop),
 
144
                                        info, &par->hotdrop),
147
145
                           XT_SCTP_CHUNK_TYPES, info->flags, info->invflags);
148
146
}
149
147
 
150
 
static bool sctp_mt_check(const struct xt_mtchk_param *par)
 
148
static int sctp_mt_check(const struct xt_mtchk_param *par)
151
149
{
152
150
        const struct xt_sctp_info *info = par->matchinfo;
153
151
 
154
 
        return !(info->flags & ~XT_SCTP_VALID_FLAGS)
155
 
                && !(info->invflags & ~XT_SCTP_VALID_FLAGS)
156
 
                && !(info->invflags & ~info->flags)
157
 
                && ((!(info->flags & XT_SCTP_CHUNK_TYPES)) ||
158
 
                        (info->chunk_match_type &
159
 
                                (SCTP_CHUNK_MATCH_ALL
160
 
                                | SCTP_CHUNK_MATCH_ANY
161
 
                                | SCTP_CHUNK_MATCH_ONLY)));
 
152
        if (info->flags & ~XT_SCTP_VALID_FLAGS)
 
153
                return -EINVAL;
 
154
        if (info->invflags & ~XT_SCTP_VALID_FLAGS)
 
155
                return -EINVAL;
 
156
        if (info->invflags & ~info->flags)
 
157
                return -EINVAL;
 
158
        if (!(info->flags & XT_SCTP_CHUNK_TYPES))
 
159
                return 0;
 
160
        if (info->chunk_match_type & (SCTP_CHUNK_MATCH_ALL |
 
161
            SCTP_CHUNK_MATCH_ANY | SCTP_CHUNK_MATCH_ONLY))
 
162
                return 0;
 
163
        return -EINVAL;
162
164
}
163
165
 
164
166
static struct xt_match sctp_mt_reg[] __read_mostly = {