~ubuntu-branches/ubuntu/quantal/iptables/quantal-proposed

« back to all changes in this revision

Viewing changes to extensions/libip6t_frag.c

  • Committer: Bazaar Package Importer
  • Author(s): Nicolas Valcárcel Scerpella
  • Date: 2009-05-06 16:35:21 UTC
  • mfrom: (5.1.6 upstream) (2.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20090506163521-2hbruo0m33h04wxf
Tags: 1.4.3.2-2ubuntu1
* Merge from debian unstable (LP: #372920), remaining changes:
  - Don't fail to run iptables-save if iptables module isn't loaded.
  - debian/patches/0901-build-libipq_pic.a.patch - Build libipq_pic.a with
    -fPIC. Upstream changed build system and patch modified accordingly.
  - Revert changes between 1.4.1.1-3 and 1.4.1.1-4, thus bringing back
    the howtos.
* Droped unexistent patches from debian/patches/series
* Droped 0903-autoload-module-in-iptables-save.diff, fixed upstream
* Added linuxdoc-tools to Build-Depends
* Modified debian/iptables{,-dev}.install to match DM syntax 
  (removed debian/tmp)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#include <stdlib.h>
6
6
#include <getopt.h>
7
7
#include <errno.h>
8
 
#include <ip6tables.h>
 
8
#include <xtables.h>
9
9
#include <linux/netfilter_ipv6/ip6t_frag.h>
10
 
                                        
11
 
/* Function which prints out usage message. */
 
10
 
12
11
static void frag_help(void)
13
12
{
14
13
        printf(
15
14
"frag match options:\n"
16
 
" --fragid [!] id[:id]          match the id (range)\n"
17
 
" --fraglen [!] length          total length of this header\n"
 
15
"[!] --fragid id[:id]           match the id (range)\n"
 
16
"[!] --fraglen length           total length of this header\n"
18
17
" --fragres                     check the reserved filed, too\n"
19
18
" --fragfirst                   matches on the first fragment\n"
20
19
" [--fragmore|--fraglast]       there are more fragments or this\n"
40
39
        id = strtoul(idstr, &ep, 0);
41
40
 
42
41
        if ( idstr == ep ) {
43
 
                exit_error(PARAMETER_PROBLEM,
 
42
                xtables_error(PARAMETER_PROBLEM,
44
43
                           "FRAG no valid digits in %s `%s'", typestr, idstr);
45
44
        }
46
45
        if ( id == ULONG_MAX  && errno == ERANGE ) {
47
 
                exit_error(PARAMETER_PROBLEM,
 
46
                xtables_error(PARAMETER_PROBLEM,
48
47
                           "%s `%s' specified too big: would overflow",
49
48
                           typestr, idstr);
50
49
        }       
51
50
        if ( *idstr != '\0'  && *ep != '\0' ) {
52
 
                exit_error(PARAMETER_PROBLEM,
 
51
                xtables_error(PARAMETER_PROBLEM,
53
52
                           "FRAG error parsing %s `%s'", typestr, idstr);
54
53
        }
55
 
        return (u_int32_t) id;
 
54
        return id;
56
55
}
57
56
 
58
57
static void
74
73
        free(buffer);
75
74
}
76
75
 
77
 
/* Initialize the match. */
78
76
static void frag_init(struct xt_entry_match *m)
79
77
{
80
78
        struct ip6t_frag *fraginfo = (struct ip6t_frag *)m->data;
86
84
        fraginfo->invflags = 0;
87
85
}
88
86
 
89
 
/* Function which parses command options; returns true if it
90
 
   ate an option */
91
87
static int frag_parse(int c, char **argv, int invert, unsigned int *flags,
92
88
                      const void *entry, struct xt_entry_match **match)
93
89
{
96
92
        switch (c) {
97
93
        case '1':
98
94
                if (*flags & IP6T_FRAG_IDS)
99
 
                        exit_error(PARAMETER_PROBLEM,
 
95
                        xtables_error(PARAMETER_PROBLEM,
100
96
                                   "Only one `--fragid' allowed");
101
 
                check_inverse(optarg, &invert, &optind, 0);
 
97
                xtables_check_inverse(optarg, &invert, &optind, 0);
102
98
                parse_frag_ids(argv[optind-1], fraginfo->ids);
103
99
                if (invert)
104
100
                        fraginfo->invflags |= IP6T_FRAG_INV_IDS;
107
103
                break;
108
104
        case '2':
109
105
                if (*flags & IP6T_FRAG_LEN)
110
 
                        exit_error(PARAMETER_PROBLEM,
 
106
                        xtables_error(PARAMETER_PROBLEM,
111
107
                                   "Only one `--fraglen' allowed");
112
 
                check_inverse(optarg, &invert, &optind, 0);
 
108
                xtables_check_inverse(optarg, &invert, &optind, 0);
113
109
                fraginfo->hdrlen = parse_frag_id(argv[optind-1], "length");
114
110
                if (invert)
115
111
                        fraginfo->invflags |= IP6T_FRAG_INV_LEN;
118
114
                break;
119
115
        case '3':
120
116
                if (*flags & IP6T_FRAG_RES)
121
 
                        exit_error(PARAMETER_PROBLEM,
 
117
                        xtables_error(PARAMETER_PROBLEM,
122
118
                                   "Only one `--fragres' allowed");
123
119
                fraginfo->flags |= IP6T_FRAG_RES;
124
120
                *flags |= IP6T_FRAG_RES;
125
121
                break;
126
122
        case '4':
127
123
                if (*flags & IP6T_FRAG_FST)
128
 
                        exit_error(PARAMETER_PROBLEM,
 
124
                        xtables_error(PARAMETER_PROBLEM,
129
125
                                   "Only one `--fragfirst' allowed");
130
126
                fraginfo->flags |= IP6T_FRAG_FST;
131
127
                *flags |= IP6T_FRAG_FST;
132
128
                break;
133
129
        case '5':
134
130
                if (*flags & (IP6T_FRAG_MF|IP6T_FRAG_NMF)) 
135
 
                        exit_error(PARAMETER_PROBLEM,
 
131
                        xtables_error(PARAMETER_PROBLEM,
136
132
                           "Only one `--fragmore' or `--fraglast' allowed");
137
133
                fraginfo->flags |= IP6T_FRAG_MF;
138
134
                *flags |= IP6T_FRAG_MF;
139
135
                break;
140
136
        case '6':
141
137
                if (*flags & (IP6T_FRAG_MF|IP6T_FRAG_NMF)) 
142
 
                        exit_error(PARAMETER_PROBLEM,
 
138
                        xtables_error(PARAMETER_PROBLEM,
143
139
                           "Only one `--fragmore' or `--fraglast' allowed");
144
140
                fraginfo->flags |= IP6T_FRAG_NMF;
145
141
                *flags |= IP6T_FRAG_NMF;
166
162
        }
167
163
}
168
164
 
169
 
/* Prints out the union ip6t_matchinfo. */
170
165
static void frag_print(const void *ip, const struct xt_entry_match *match,
171
166
                       int numeric)
172
167
{
199
194
                       frag->invflags & ~IP6T_FRAG_INV_MASK);
200
195
}
201
196
 
202
 
/* Saves the union ip6t_matchinfo in parsable form to stdout. */
203
197
static void frag_save(const void *ip, const struct xt_entry_match *match)
204
198
{
205
199
        const struct ip6t_frag *fraginfo = (struct ip6t_frag *)match->data;
206
200
 
207
201
        if (!(fraginfo->ids[0] == 0
208
202
            && fraginfo->ids[1] == 0xFFFFFFFF)) {
209
 
                printf("--fragid %s", 
 
203
                printf("%s--fragid ", 
210
204
                        (fraginfo->invflags & IP6T_FRAG_INV_IDS) ? "! " : "");
211
205
                if (fraginfo->ids[0]
212
206
                    != fraginfo->ids[1])
219
213
        }
220
214
 
221
215
        if (fraginfo->flags & IP6T_FRAG_LEN) {
222
 
                printf("--fraglen %s%u ", 
 
216
                printf("%s--fraglen %u ", 
223
217
                        (fraginfo->invflags & IP6T_FRAG_INV_LEN) ? "! " : "", 
224
218
                        fraginfo->hdrlen);
225
219
        }
240
234
static struct xtables_match frag_mt6_reg = {
241
235
        .name          = "frag",
242
236
        .version       = XTABLES_VERSION,
243
 
        .family        = PF_INET6,
 
237
        .family        = NFPROTO_IPV6,
244
238
        .size          = XT_ALIGN(sizeof(struct ip6t_frag)),
245
239
        .userspacesize = XT_ALIGN(sizeof(struct ip6t_frag)),
246
240
        .help          = frag_help,