~ubuntu-branches/ubuntu/oneiric/iptables/oneiric

« back to all changes in this revision

Viewing changes to extensions/libxt_multiport.c

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge, Lorenzo De Liso, Jamie Strandboge
  • Date: 2010-11-12 15:58:40 UTC
  • mfrom: (5.1.8 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20101112155840-jm07l9o9722h0bvm
Tags: 1.4.10-1ubuntu1
[ Lorenzo De Liso ]
* Merge from debian unstable (LP: #671652), remaining changes:
  - Don't fail to run iptables-save if iptables module isn't loaded.
  - Revert changes between 1.4.1.1-3 and 1.4.1.1-4, thus bringing back
    the howtos.
  - Added linuxdoc-tools to Build-Depends
  - Modified debian/iptables{,-dev}.install to match DM syntax
    (removed debian/tmp)
  - Added -fno-strict-aliasing -Werror switches to regular_CFLAGS
    for catching errors early
  - Removed unused TC_NUM_RULES() and TC_GET_RULE()
* debian/patches/03-compilation-error.patch: updated
* debian/patches/0600-makefile_jedi_handwaving.patch: updated
* Dropped changes:
  - debian/patches/0902-docs-version-reference.diff: modifies files inside
    the debian/ directory and hence is not needed

[ Jamie Strandboge ]
* debian/patches/9000-howtos.patch:
  - combine 0102-howtos.patch and 0103-sgml_errors.patch into this patch
    and apply after the Debian patches for easier maintenance
  - add DEP-3 comments
* debian/patches/9001-build-libipq_pic.la.patch:
  - Build libipq_pic.la with -fPIC
  - add DEP-3 comments
* debian/iptables-dev.install: install lib/*.la in usr/lib
* merge debian/patches/9002-xt_recent-reap.patch:
  - support for the xt_recent filter --reap switch (refreshed and updated)
  - add DEP-3 comments
* debian/patches/9003-compilation-error.patch:
  - renamed 03-compilation-error.patch as 9003-compilation-error.patch
  - apply after Debian patches for easier maintenance
  - add DEP-3 comments
* debian/iptables.doc-base.{nat|packet-filter}: update for 2.6
* Dropped changes:
  - Replaced ipt_DSCP.h by xpt_DSCP.h in ipt_ECN.h and ipt_echn.h (applied
    upstream)
  - 9001-build-libipq_pic.a.patch (using la instead)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Shared library add-on to iptables to add multiple TCP port support. */
 
2
#include <stdbool.h>
2
3
#include <stdio.h>
3
4
#include <netdb.h>
4
5
#include <string.h>
44
45
}
45
46
 
46
47
static const struct option multiport_opts[] = {
47
 
        { "source-ports", 1, NULL, '1' },
48
 
        { "sports", 1, NULL, '1' }, /* synonym */
49
 
        { "destination-ports", 1, NULL, '2' },
50
 
        { "dports", 1, NULL, '2' }, /* synonym */
51
 
        { "ports", 1, NULL, '3' },
52
 
        { .name = NULL }
 
48
        {.name = "source-ports",      .has_arg = true, .val = '1'},
 
49
        {.name = "sports",            .has_arg = true, .val = '1'}, /* synonym */
 
50
        {.name = "destination-ports", .has_arg = true, .val = '2'},
 
51
        {.name = "dports",            .has_arg = true, .val = '2'}, /* synonym */
 
52
        {.name = "ports",             .has_arg = true, .val = '3'},
 
53
        XT_GETOPT_TABLEEND,
53
54
};
54
55
 
55
56
static char *
164
165
 
165
166
        switch (c) {
166
167
        case '1':
167
 
                xtables_check_inverse(argv[optind-1], &invert, &optind, 0);
 
168
                xtables_check_inverse(optarg, &invert, &optind, 0, argv);
168
169
                proto = check_proto(pnum, invflags);
169
 
                multiinfo->count = parse_multi_ports(argv[optind-1],
 
170
                multiinfo->count = parse_multi_ports(optarg,
170
171
                                                     multiinfo->ports, proto);
171
172
                multiinfo->flags = XT_MULTIPORT_SOURCE;
172
173
                break;
173
174
 
174
175
        case '2':
175
 
                xtables_check_inverse(argv[optind-1], &invert, &optind, 0);
 
176
                xtables_check_inverse(optarg, &invert, &optind, 0, argv);
176
177
                proto = check_proto(pnum, invflags);
177
 
                multiinfo->count = parse_multi_ports(argv[optind-1],
 
178
                multiinfo->count = parse_multi_ports(optarg,
178
179
                                                     multiinfo->ports, proto);
179
180
                multiinfo->flags = XT_MULTIPORT_DESTINATION;
180
181
                break;
181
182
 
182
183
        case '3':
183
 
                xtables_check_inverse(argv[optind-1], &invert, &optind, 0);
 
184
                xtables_check_inverse(optarg, &invert, &optind, 0, argv);
184
185
                proto = check_proto(pnum, invflags);
185
 
                multiinfo->count = parse_multi_ports(argv[optind-1],
 
186
                multiinfo->count = parse_multi_ports(optarg,
186
187
                                                     multiinfo->ports, proto);
187
188
                multiinfo->flags = XT_MULTIPORT_EITHER;
188
189
                break;
231
232
 
232
233
        switch (c) {
233
234
        case '1':
234
 
                xtables_check_inverse(argv[optind-1], &invert, &optind, 0);
 
235
                xtables_check_inverse(optarg, &invert, &optind, 0, argv);
235
236
                proto = check_proto(pnum, invflags);
236
 
                parse_multi_ports_v1(argv[optind-1], multiinfo, proto);
 
237
                parse_multi_ports_v1(optarg, multiinfo, proto);
237
238
                multiinfo->flags = XT_MULTIPORT_SOURCE;
238
239
                break;
239
240
 
240
241
        case '2':
241
 
                xtables_check_inverse(argv[optind-1], &invert, &optind, 0);
 
242
                xtables_check_inverse(optarg, &invert, &optind, 0, argv);
242
243
                proto = check_proto(pnum, invflags);
243
 
                parse_multi_ports_v1(argv[optind-1], multiinfo, proto);
 
244
                parse_multi_ports_v1(optarg, multiinfo, proto);
244
245
                multiinfo->flags = XT_MULTIPORT_DESTINATION;
245
246
                break;
246
247
 
247
248
        case '3':
248
 
                xtables_check_inverse(argv[optind-1], &invert, &optind, 0);
 
249
                xtables_check_inverse(optarg, &invert, &optind, 0, argv);
249
250
                proto = check_proto(pnum, invflags);
250
 
                parse_multi_ports_v1(argv[optind-1], multiinfo, proto);
 
251
                parse_multi_ports_v1(optarg, multiinfo, proto);
251
252
                multiinfo->flags = XT_MULTIPORT_EITHER;
252
253
                break;
253
254
 
509
510
        __multiport_save_v1(match, ip->proto);
510
511
}
511
512
 
512
 
static struct xtables_match multiport_match = {
513
 
        .family         = NFPROTO_IPV4,
514
 
        .name           = "multiport",
515
 
        .revision       = 0,
516
 
        .version        = XTABLES_VERSION,
517
 
        .size           = XT_ALIGN(sizeof(struct xt_multiport)),
518
 
        .userspacesize  = XT_ALIGN(sizeof(struct xt_multiport)),
519
 
        .help           = multiport_help,
520
 
        .parse          = multiport_parse,
521
 
        .final_check    = multiport_check,
522
 
        .print          = multiport_print,
523
 
        .save           = multiport_save,
524
 
        .extra_opts     = multiport_opts,
525
 
};
526
 
 
527
 
static struct xtables_match multiport_match6 = {
528
 
        .family         = NFPROTO_IPV6,
529
 
        .name           = "multiport",
530
 
        .revision       = 0,
531
 
        .version        = XTABLES_VERSION,
532
 
        .size           = XT_ALIGN(sizeof(struct xt_multiport)),
533
 
        .userspacesize  = XT_ALIGN(sizeof(struct xt_multiport)),
534
 
        .help           = multiport_help,
535
 
        .parse          = multiport_parse6,
536
 
        .final_check    = multiport_check,
537
 
        .print          = multiport_print6,
538
 
        .save           = multiport_save6,
539
 
        .extra_opts     = multiport_opts,
540
 
};
541
 
 
542
 
static struct xtables_match multiport_match_v1 = {
543
 
        .family         = NFPROTO_IPV4,
544
 
        .name           = "multiport",
545
 
        .version        = XTABLES_VERSION,
546
 
        .revision       = 1,
547
 
        .size           = XT_ALIGN(sizeof(struct xt_multiport_v1)),
548
 
        .userspacesize  = XT_ALIGN(sizeof(struct xt_multiport_v1)),
549
 
        .help           = multiport_help_v1,
550
 
        .parse          = multiport_parse_v1,
551
 
        .final_check    = multiport_check,
552
 
        .print          = multiport_print_v1,
553
 
        .save           = multiport_save_v1,
554
 
        .extra_opts     = multiport_opts,
555
 
};
556
 
 
557
 
static struct xtables_match multiport_match6_v1 = {
558
 
        .family         = NFPROTO_IPV6,
559
 
        .name           = "multiport",
560
 
        .version        = XTABLES_VERSION,
561
 
        .revision       = 1,
562
 
        .size           = XT_ALIGN(sizeof(struct xt_multiport_v1)),
563
 
        .userspacesize  = XT_ALIGN(sizeof(struct xt_multiport_v1)),
564
 
        .help           = multiport_help_v1,
565
 
        .parse          = multiport_parse6_v1,
566
 
        .final_check    = multiport_check,
567
 
        .print          = multiport_print6_v1,
568
 
        .save           = multiport_save6_v1,
569
 
        .extra_opts     = multiport_opts,
 
513
static struct xtables_match multiport_mt_reg[] = {
 
514
        {
 
515
                .family        = NFPROTO_IPV4,
 
516
                .name          = "multiport",
 
517
                .revision      = 0,
 
518
                .version       = XTABLES_VERSION,
 
519
                .size          = XT_ALIGN(sizeof(struct xt_multiport)),
 
520
                .userspacesize = XT_ALIGN(sizeof(struct xt_multiport)),
 
521
                .help          = multiport_help,
 
522
                .parse         = multiport_parse,
 
523
                .final_check   = multiport_check,
 
524
                .print         = multiport_print,
 
525
                .save          = multiport_save,
 
526
                .extra_opts    = multiport_opts,
 
527
        },
 
528
        {
 
529
                .family        = NFPROTO_IPV6,
 
530
                .name          = "multiport",
 
531
                .revision      = 0,
 
532
                .version       = XTABLES_VERSION,
 
533
                .size          = XT_ALIGN(sizeof(struct xt_multiport)),
 
534
                .userspacesize = XT_ALIGN(sizeof(struct xt_multiport)),
 
535
                .help          = multiport_help,
 
536
                .parse         = multiport_parse6,
 
537
                .final_check   = multiport_check,
 
538
                .print         = multiport_print6,
 
539
                .save          = multiport_save6,
 
540
                .extra_opts    = multiport_opts,
 
541
        },
 
542
        {
 
543
                .family        = NFPROTO_IPV4,
 
544
                .name          = "multiport",
 
545
                .version       = XTABLES_VERSION,
 
546
                .revision      = 1,
 
547
                .size          = XT_ALIGN(sizeof(struct xt_multiport_v1)),
 
548
                .userspacesize = XT_ALIGN(sizeof(struct xt_multiport_v1)),
 
549
                .help          = multiport_help_v1,
 
550
                .parse         = multiport_parse_v1,
 
551
                .final_check   = multiport_check,
 
552
                .print         = multiport_print_v1,
 
553
                .save          = multiport_save_v1,
 
554
                .extra_opts    = multiport_opts,
 
555
        },
 
556
        {
 
557
                .family        = NFPROTO_IPV6,
 
558
                .name          = "multiport",
 
559
                .version       = XTABLES_VERSION,
 
560
                .revision      = 1,
 
561
                .size          = XT_ALIGN(sizeof(struct xt_multiport_v1)),
 
562
                .userspacesize = XT_ALIGN(sizeof(struct xt_multiport_v1)),
 
563
                .help          = multiport_help_v1,
 
564
                .parse         = multiport_parse6_v1,
 
565
                .final_check   = multiport_check,
 
566
                .print         = multiport_print6_v1,
 
567
                .save          = multiport_save6_v1,
 
568
                .extra_opts    = multiport_opts,
 
569
        },
570
570
};
571
571
 
572
572
void
573
573
_init(void)
574
574
{
575
 
        xtables_register_match(&multiport_match);
576
 
        xtables_register_match(&multiport_match6);
577
 
        xtables_register_match(&multiport_match_v1);
578
 
        xtables_register_match(&multiport_match6_v1);
 
575
        xtables_register_matches(multiport_mt_reg, ARRAY_SIZE(multiport_mt_reg));
579
576
}