~ubuntu-branches/ubuntu/precise/iptables/precise-proposed

« back to all changes in this revision

Viewing changes to extensions/libip6t_mh.c

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge
  • Date: 2011-11-07 13:46:11 UTC
  • mfrom: (5.1.9) (2.1.15 sid)
  • Revision ID: package-import@ubuntu.com-20111107134611-kc82oc327fb9ctq6
Tags: 1.4.12-1ubuntu1
* Merge from Debian unstable (LP: #887192). Remaining changes:
  - 9000-howtos.patch: add howtos/ and install them
  - 9001-build-libipq_pic.la.patch: Build libipq_pic.la with -fPIC
  - debian/control: Build-Depends on linuxdoc-tools
  - debian/iptables.install: install NAT and packetfilter howtos into
    /usr/share/doc
  - debian/iptables-dev.install: install netfilter howto into /usr/share/doc
  - debian/iptables-dev.doc-base.netfilter-extensions,
    debian/iptables-dev.doc-base.netfilter-hacking,
    debian/iptables.doc-base.nat, debian/iptables.doc-base.packet-filter: add
    howtos
  - debian/iptables-dev.install: install lib/*.la in usr/lib
  - No longer apply the following:
    + 9002-xt_recent-reap.patch: this requires a rewrite of the patch. For
      now adjust series to not apply, file a bug, assigning to the kernel
      team. Once they have resubmitted upstream, we can take the new patch.
    + 9003-compilation-error.patch: no longer needed with newer iptables

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 *
12
12
 * Based on libip6t_{icmpv6,udp}.c
13
13
 */
14
 
#include <stdbool.h>
 
14
#include <stdint.h>
15
15
#include <stdio.h>
16
 
#include <netdb.h>
17
16
#include <string.h>
18
17
#include <stdlib.h>
19
 
#include <getopt.h>
20
18
#include <xtables.h>
21
19
#include <linux/netfilter_ipv6/ip6t_mh.h>
22
20
 
 
21
enum {
 
22
        O_MH_TYPE = 0,
 
23
};
 
24
 
23
25
struct mh_name {
24
26
        const char *name;
25
 
        u_int8_t type;
 
27
        uint8_t type;
26
28
};
27
29
 
28
30
static const struct mh_name mh_names[] = {
100
102
        }
101
103
}
102
104
 
103
 
static void parse_mh_types(const char *mhtype, u_int8_t *types)
 
105
static void parse_mh_types(const char *mhtype, uint8_t *types)
104
106
{
105
107
        char *buffer;
106
108
        char *cp;
122
124
        free(buffer);
123
125
}
124
126
 
125
 
#define MH_TYPES 0x01
126
 
 
127
 
static int mh_parse(int c, char **argv, int invert, unsigned int *flags,
128
 
                    const void *entry, struct xt_entry_match **match)
 
127
static void mh_parse(struct xt_option_call *cb)
129
128
{
130
 
        struct ip6t_mh *mhinfo = (struct ip6t_mh *)(*match)->data;
131
 
 
132
 
        switch (c) {
133
 
        case '1':
134
 
                if (*flags & MH_TYPES)
135
 
                        xtables_error(PARAMETER_PROBLEM,
136
 
                                   "Only one `--mh-type' allowed");
137
 
                xtables_check_inverse(optarg, &invert, &optind, 0, argv);
138
 
                parse_mh_types(optarg, mhinfo->types);
139
 
                if (invert)
140
 
                        mhinfo->invflags |= IP6T_MH_INV_TYPE;
141
 
                *flags |= MH_TYPES;
142
 
                break;
143
 
 
144
 
        default:
145
 
                return 0;
146
 
        }
147
 
 
148
 
        return 1;
 
129
        struct ip6t_mh *mhinfo = cb->data;
 
130
 
 
131
        xtables_option_parse(cb);
 
132
        parse_mh_types(cb->arg, mhinfo->types);
 
133
        if (cb->invert)
 
134
                mhinfo->invflags |= IP6T_MH_INV_TYPE;
149
135
}
150
136
 
151
 
static const char *type_to_name(u_int8_t type)
 
137
static const char *type_to_name(uint8_t type)
152
138
{
153
139
        unsigned int i;
154
140
 
159
145
        return NULL;
160
146
}
161
147
 
162
 
static void print_type(u_int8_t type, int numeric)
 
148
static void print_type(uint8_t type, int numeric)
163
149
{
164
150
        const char *name;
165
151
        if (numeric || !(name = type_to_name(type)))
168
154
                printf("%s", name);
169
155
}
170
156
 
171
 
static void print_types(u_int8_t min, u_int8_t max, int invert, int numeric)
 
157
static void print_types(uint8_t min, uint8_t max, int invert, int numeric)
172
158
{
173
159
        const char *inv = invert ? "!" : "";
174
160
 
175
161
        if (min != 0 || max != 0xFF || invert) {
 
162
                printf(" ");
176
163
                if (min == max) {
177
164
                        printf("%s", inv);
178
165
                        print_type(min, numeric);
182
169
                        printf(":");
183
170
                        print_type(max, numeric);
184
171
                }
185
 
                printf(" ");
186
172
        }
187
173
}
188
174
 
191
177
{
192
178
        const struct ip6t_mh *mhinfo = (struct ip6t_mh *)match->data;
193
179
 
194
 
        printf("mh ");
 
180
        printf(" mh");
195
181
        print_types(mhinfo->types[0], mhinfo->types[1],
196
182
                    mhinfo->invflags & IP6T_MH_INV_TYPE,
197
183
                    numeric);
198
184
        if (mhinfo->invflags & ~IP6T_MH_INV_MASK)
199
 
                printf("Unknown invflags: 0x%X ",
 
185
                printf(" Unknown invflags: 0x%X",
200
186
                       mhinfo->invflags & ~IP6T_MH_INV_MASK);
201
187
}
202
188
 
208
194
                return;
209
195
 
210
196
        if (mhinfo->invflags & IP6T_MH_INV_TYPE)
211
 
                printf("! ");
 
197
                printf(" !");
212
198
 
213
199
        if (mhinfo->types[0] != mhinfo->types[1])
214
 
                printf("--mh-type %u:%u ", mhinfo->types[0], mhinfo->types[1]);
 
200
                printf(" --mh-type %u:%u", mhinfo->types[0], mhinfo->types[1]);
215
201
        else
216
 
                printf("--mh-type %u ", mhinfo->types[0]);
 
202
                printf(" --mh-type %u", mhinfo->types[0]);
217
203
}
218
204
 
219
 
static const struct option mh_opts[] = {
220
 
        {.name = "mh-type", .has_arg = true, .val = '1'},
221
 
        XT_GETOPT_TABLEEND,
 
205
static const struct xt_option_entry mh_opts[] = {
 
206
        {.name = "mh-type", .id = O_MH_TYPE, .type = XTTYPE_STRING,
 
207
         .flags = XTOPT_INVERT},
 
208
        XTOPT_TABLEEND,
222
209
};
223
210
 
224
211
static struct xtables_match mh_mt6_reg = {
229
216
        .userspacesize  = XT_ALIGN(sizeof(struct ip6t_mh)),
230
217
        .help           = mh_help,
231
218
        .init           = mh_init,
232
 
        .parse          = mh_parse,
 
219
        .x6_parse       = mh_parse,
233
220
        .print          = mh_print,
234
221
        .save           = mh_save,
235
 
        .extra_opts     = mh_opts,
 
222
        .x6_options     = mh_opts,
236
223
};
237
224
 
238
225
void _init(void)