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

« back to all changes in this revision

Viewing changes to extensions/libip6t_ah.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_ah.h>
10
 
                                        
11
 
/* Function which prints out usage message. */
 
10
 
12
11
static void ah_help(void)
13
12
{
14
13
        printf(
15
14
"ah match options:\n"
16
 
" --ahspi [!] spi[:spi]         match spi (range)\n"
17
 
" --ahlen [!] length            total length of this header\n"
 
15
"[!] --ahspi spi[:spi]          match spi (range)\n"
 
16
"[!] --ahlen length             total length of this header\n"
18
17
" --ahres                       check the reserved filed, too\n");
19
18
}
20
19
 
34
33
        spi = strtoul(spistr, &ep, 0);
35
34
 
36
35
        if ( spistr == ep )
37
 
                exit_error(PARAMETER_PROBLEM,
 
36
                xtables_error(PARAMETER_PROBLEM,
38
37
                           "AH no valid digits in %s `%s'", typestr, spistr);
39
38
 
40
39
        if ( spi == ULONG_MAX  && errno == ERANGE )
41
 
                exit_error(PARAMETER_PROBLEM,
 
40
                xtables_error(PARAMETER_PROBLEM,
42
41
                           "%s `%s' specified too big: would overflow",
43
42
                           typestr, spistr);
44
43
 
45
44
        if ( *spistr != '\0'  && *ep != '\0' )
46
 
                exit_error(PARAMETER_PROBLEM,
 
45
                xtables_error(PARAMETER_PROBLEM,
47
46
                           "AH error parsing %s `%s'", typestr, spistr);
48
47
 
49
 
        return (u_int32_t) spi;
 
48
        return spi;
50
49
}
51
50
 
52
51
static void
68
67
        free(buffer);
69
68
}
70
69
 
71
 
/* Initialize the match. */
72
70
static void ah_init(struct xt_entry_match *m)
73
71
{
74
72
        struct ip6t_ah *ahinfo = (struct ip6t_ah *)m->data;
78
76
        ahinfo->hdrres = 0;
79
77
}
80
78
 
81
 
/* Function which parses command options; returns true if it
82
 
   ate an option */
83
79
static int ah_parse(int c, char **argv, int invert, unsigned int *flags,
84
80
                    const void *entry, struct xt_entry_match **match)
85
81
{
88
84
        switch (c) {
89
85
        case '1':
90
86
                if (*flags & IP6T_AH_SPI)
91
 
                        exit_error(PARAMETER_PROBLEM,
 
87
                        xtables_error(PARAMETER_PROBLEM,
92
88
                                   "Only one `--ahspi' allowed");
93
 
                check_inverse(optarg, &invert, &optind, 0);
 
89
                xtables_check_inverse(optarg, &invert, &optind, 0);
94
90
                parse_ah_spis(argv[optind-1], ahinfo->spis);
95
91
                if (invert)
96
92
                        ahinfo->invflags |= IP6T_AH_INV_SPI;
98
94
                break;
99
95
        case '2':
100
96
                if (*flags & IP6T_AH_LEN)
101
 
                        exit_error(PARAMETER_PROBLEM,
 
97
                        xtables_error(PARAMETER_PROBLEM,
102
98
                                   "Only one `--ahlen' allowed");
103
 
                check_inverse(optarg, &invert, &optind, 0);
 
99
                xtables_check_inverse(optarg, &invert, &optind, 0);
104
100
                ahinfo->hdrlen = parse_ah_spi(argv[optind-1], "length");
105
101
                if (invert)
106
102
                        ahinfo->invflags |= IP6T_AH_INV_LEN;
108
104
                break;
109
105
        case '3':
110
106
                if (*flags & IP6T_AH_RES)
111
 
                        exit_error(PARAMETER_PROBLEM,
 
107
                        xtables_error(PARAMETER_PROBLEM,
112
108
                                   "Only one `--ahres' allowed");
113
109
                ahinfo->hdrres = 1;
114
110
                *flags |= IP6T_AH_RES;
143
139
                printf("%s:%s%u ", name, inv, len);
144
140
}
145
141
 
146
 
/* Prints out the union ip6t_matchinfo. */
147
142
static void ah_print(const void *ip, const struct xt_entry_match *match,
148
143
                     int numeric)
149
144
{
163
158
                       ah->invflags & ~IP6T_AH_INV_MASK);
164
159
}
165
160
 
166
 
/* Saves the union ip6t_matchinfo in parsable form to stdout. */
167
161
static void ah_save(const void *ip, const struct xt_entry_match *match)
168
162
{
169
163
        const struct ip6t_ah *ahinfo = (struct ip6t_ah *)match->data;
170
164
 
171
165
        if (!(ahinfo->spis[0] == 0
172
166
            && ahinfo->spis[1] == 0xFFFFFFFF)) {
173
 
                printf("--ahspi %s", 
 
167
                printf("%s--ahspi ",
174
168
                        (ahinfo->invflags & IP6T_AH_INV_SPI) ? "! " : "");
175
169
                if (ahinfo->spis[0]
176
170
                    != ahinfo->spis[1])
183
177
        }
184
178
 
185
179
        if (ahinfo->hdrlen != 0 || (ahinfo->invflags & IP6T_AH_INV_LEN) ) {
186
 
                printf("--ahlen %s%u ", 
 
180
                printf("%s--ahlen %u ", 
187
181
                        (ahinfo->invflags & IP6T_AH_INV_LEN) ? "! " : "", 
188
182
                        ahinfo->hdrlen);
189
183
        }
195
189
static struct xtables_match ah_mt6_reg = {
196
190
        .name          = "ah",
197
191
        .version       = XTABLES_VERSION,
198
 
        .family        = PF_INET6,
 
192
        .family        = NFPROTO_IPV6,
199
193
        .size          = XT_ALIGN(sizeof(struct ip6t_ah)),
200
194
        .userspacesize = XT_ALIGN(sizeof(struct ip6t_ah)),
201
195
        .help          = ah_help,