~ubuntu-branches/ubuntu/saucy/iptables/saucy

« back to all changes in this revision

Viewing changes to iptables/iptables.c

  • Committer: Package Import Robot
  • Author(s): Chris J Arges, Chris J Arges
  • Date: 2013-06-07 09:50:09 UTC
  • mfrom: (2.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130607095009-aajdci0h8xfkd3n8
Tags: 1.4.18-1ubuntu1
[ Chris J Arges ]
* Merge from Debian unstable (LP: #1191004).  Remaining changes:
  - debian/control: add linuxdoc-tools dep, remove libipq references
  - debian/rules: compile with --disable-libipq
  - 9000-howtos.patch: add howtos/ and install them
  - 9002-libxt_recent-Add-support-for-reap-option.patch: Some changes are
    upstream, patch needed for additional reap option checks.
  - debian/iptables.install: install NAT and packetfilter howtos 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: remove usr/share/man/man3 only used with
    libipq manpages
* Dropped changes:
  - debian/iptables.lintian-overrides: remove unuseful lintian override
    delta
  - 9001-build-libipq_pic.la.patch: remove patch that hasn't been applied
    since 12.04.
  - 9001-Fixed-FTBS-by-copying-linux-types.h-from-linux-3.2.patch:
    changes are upstream.
  - 9003-lp1020490.patch: changes are upstream.
  - 9004-argv-is-null.patch: changes are upstream.
  - 9005-lp1027252-fixrestore.patch: changes are upstream.
  - 9006-lp1042260-fix-inverted-physdev.patch: changes are upstream.
  - 9007-lp982961-xtables-lm-noasneeded.patch: changes are upstream.
  - 9009-libxt-string-fix-space-around-arguments.patch: changes are upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include <iptables.h>
40
40
#include <xtables.h>
41
41
#include <fcntl.h>
42
 
#include <sys/utsname.h>
43
42
#include "xshared.h"
44
43
 
45
44
#ifndef TRUE
49
48
#define FALSE 0
50
49
#endif
51
50
 
52
 
#define FMT_NUMERIC     0x0001
53
 
#define FMT_NOCOUNTS    0x0002
54
 
#define FMT_KILOMEGAGIGA 0x0004
55
 
#define FMT_OPTIONS     0x0008
56
 
#define FMT_NOTABLE     0x0010
57
 
#define FMT_NOTARGET    0x0020
58
 
#define FMT_VIA         0x0040
59
 
#define FMT_NONEWLINE   0x0080
60
 
#define FMT_LINENUMBERS 0x0100
61
 
 
62
 
#define FMT_PRINT_RULE (FMT_NOCOUNTS | FMT_OPTIONS | FMT_VIA \
63
 
                        | FMT_NUMERIC | FMT_NOTABLE)
64
 
#define FMT(tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab))
65
 
 
66
 
 
67
51
#define CMD_NONE                0x0000U
68
52
#define CMD_INSERT              0x0001U
69
53
#define CMD_DELETE              0x0002U
82
66
#define CMD_CHECK               0x4000U
83
67
#define NUMBER_OF_CMD   16
84
68
static const char cmdflags[] = { 'I', 'D', 'D', 'R', 'A', 'L', 'F', 'Z',
85
 
                                 'Z', 'N', 'X', 'P', 'E', 'S', 'C' };
 
69
                                 'N', 'X', 'P', 'E', 'S', 'Z', 'C' };
86
70
 
87
71
#define OPT_FRAGMENT    0x00800U
88
72
#define NUMBER_OF_OPT   ARRAY_SIZE(optflags)
172
156
/* -n */ 0,
173
157
/* -s */ IPT_INV_SRCIP,
174
158
/* -d */ IPT_INV_DSTIP,
175
 
/* -p */ IPT_INV_PROTO,
 
159
/* -p */ XT_INV_PROTO,
176
160
/* -j */ 0,
177
161
/* -v */ 0,
178
162
/* -x */ 0,
187
171
#define prog_name iptables_globals.program_name
188
172
#define prog_vers iptables_globals.program_version
189
173
 
190
 
int kernel_version;
191
 
 
192
 
/* Primitive headers... */
193
 
/* defined in netinet/in.h */
194
 
#if 0
195
 
#ifndef IPPROTO_ESP
196
 
#define IPPROTO_ESP 50
197
 
#endif
198
 
#ifndef IPPROTO_AH
199
 
#define IPPROTO_AH 51
200
 
#endif
201
 
#endif
202
 
 
203
 
enum {
204
 
        IPT_DOTTED_ADDR = 0,
205
 
        IPT_DOTTED_MASK
206
 
};
207
 
 
208
174
static void __attribute__((noreturn))
209
175
exit_tryhelp(int status)
210
176
{
448
414
}
449
415
 
450
416
static void
451
 
print_num(uint64_t number, unsigned int format)
452
 
{
453
 
        if (format & FMT_KILOMEGAGIGA) {
454
 
                if (number > 99999) {
455
 
                        number = (number + 500) / 1000;
456
 
                        if (number > 9999) {
457
 
                                number = (number + 500) / 1000;
458
 
                                if (number > 9999) {
459
 
                                        number = (number + 500) / 1000;
460
 
                                        if (number > 9999) {
461
 
                                                number = (number + 500) / 1000;
462
 
                                                printf(FMT("%4lluT ","%lluT "), (unsigned long long)number);
463
 
                                        }
464
 
                                        else printf(FMT("%4lluG ","%lluG "), (unsigned long long)number);
465
 
                                }
466
 
                                else printf(FMT("%4lluM ","%lluM "), (unsigned long long)number);
467
 
                        } else
468
 
                                printf(FMT("%4lluK ","%lluK "), (unsigned long long)number);
469
 
                } else
470
 
                        printf(FMT("%5llu ","%llu "), (unsigned long long)number);
471
 
        } else
472
 
                printf(FMT("%8llu ","%llu "), (unsigned long long)number);
473
 
}
474
 
 
475
 
 
476
 
static void
477
 
print_header(unsigned int format, const char *chain, struct iptc_handle *handle)
478
 
{
479
 
        struct ipt_counters counters;
 
417
print_header(unsigned int format, const char *chain, struct xtc_handle *handle)
 
418
{
 
419
        struct xt_counters counters;
480
420
        const char *pol = iptc_get_policy(chain, &counters, handle);
481
421
        printf("Chain %s", chain);
482
422
        if (pol) {
483
423
                printf(" (policy %s", pol);
484
424
                if (!(format & FMT_NOCOUNTS)) {
485
425
                        fputc(' ', stdout);
486
 
                        print_num(counters.pcnt, (format|FMT_NOTABLE));
 
426
                        xtables_print_num(counters.pcnt, (format|FMT_NOTABLE));
487
427
                        fputs("packets, ", stdout);
488
 
                        print_num(counters.bcnt, (format|FMT_NOTABLE));
 
428
                        xtables_print_num(counters.bcnt, (format|FMT_NOTABLE));
489
429
                        fputs("bytes", stdout);
490
430
                }
491
431
                printf(")\n");
524
464
 
525
465
 
526
466
static int
527
 
print_match(const struct ipt_entry_match *m,
 
467
print_match(const struct xt_entry_match *m,
528
468
            const struct ipt_ip *ip,
529
469
            int numeric)
530
470
{
550
490
               const char *targname,
551
491
               unsigned int num,
552
492
               unsigned int format,
553
 
               struct iptc_handle *const handle)
 
493
               struct xtc_handle *const handle)
554
494
{
555
495
        const struct xtables_target *target = NULL;
556
 
        const struct ipt_entry_target *t;
 
496
        const struct xt_entry_target *t;
557
497
        uint8_t flags;
558
498
        char buf[BUFSIZ];
559
499
 
560
500
        if (!iptc_is_chain(targname, handle))
561
501
                target = xtables_find_target(targname, XTF_TRY_LOAD);
562
502
        else
563
 
                target = xtables_find_target(IPT_STANDARD_TARGET,
 
503
                target = xtables_find_target(XT_STANDARD_TARGET,
564
504
                         XTF_LOAD_MUST_SUCCEED);
565
505
 
566
506
        t = ipt_get_target((struct ipt_entry *)fw);
570
510
                printf(FMT("%-4u ", "%u "), num);
571
511
 
572
512
        if (!(format & FMT_NOCOUNTS)) {
573
 
                print_num(fw->counters.pcnt, format);
574
 
                print_num(fw->counters.bcnt, format);
 
513
                xtables_print_num(fw->counters.pcnt, format);
 
514
                xtables_print_num(fw->counters.bcnt, format);
575
515
        }
576
516
 
577
517
        if (!(format & FMT_NOTARGET))
578
518
                printf(FMT("%-9s ", "%s "), targname);
579
519
 
580
 
        fputc(fw->ip.invflags & IPT_INV_PROTO ? '!' : ' ', stdout);
 
520
        fputc(fw->ip.invflags & XT_INV_PROTO ? '!' : ' ', stdout);
581
521
        {
582
522
                const char *pname = proto_to_name(fw->ip.proto, format&FMT_NUMERIC);
583
523
                if (pname)
672
612
 
673
613
static void
674
614
print_firewall_line(const struct ipt_entry *fw,
675
 
                    struct iptc_handle *const h)
 
615
                    struct xtc_handle *const h)
676
616
{
677
 
        struct ipt_entry_target *t;
 
617
        struct xt_entry_target *t;
678
618
 
679
619
        t = ipt_get_target((struct ipt_entry *)fw);
680
620
        print_firewall(fw, t->u.user.name, 0, FMT_PRINT_RULE, h);
681
621
}
682
622
 
683
623
static int
684
 
append_entry(const ipt_chainlabel chain,
 
624
append_entry(const xt_chainlabel chain,
685
625
             struct ipt_entry *fw,
686
626
             unsigned int nsaddrs,
687
627
             const struct in_addr saddrs[],
690
630
             const struct in_addr daddrs[],
691
631
             const struct in_addr dmasks[],
692
632
             int verbose,
693
 
             struct iptc_handle *handle)
 
633
             struct xtc_handle *handle)
694
634
{
695
635
        unsigned int i, j;
696
636
        int ret = 1;
711
651
}
712
652
 
713
653
static int
714
 
replace_entry(const ipt_chainlabel chain,
 
654
replace_entry(const xt_chainlabel chain,
715
655
              struct ipt_entry *fw,
716
656
              unsigned int rulenum,
717
657
              const struct in_addr *saddr, const struct in_addr *smask,
718
658
              const struct in_addr *daddr, const struct in_addr *dmask,
719
659
              int verbose,
720
 
              struct iptc_handle *handle)
 
660
              struct xtc_handle *handle)
721
661
{
722
662
        fw->ip.src.s_addr = saddr->s_addr;
723
663
        fw->ip.dst.s_addr = daddr->s_addr;
730
670
}
731
671
 
732
672
static int
733
 
insert_entry(const ipt_chainlabel chain,
 
673
insert_entry(const xt_chainlabel chain,
734
674
             struct ipt_entry *fw,
735
675
             unsigned int rulenum,
736
676
             unsigned int nsaddrs,
740
680
             const struct in_addr daddrs[],
741
681
             const struct in_addr dmasks[],
742
682
             int verbose,
743
 
             struct iptc_handle *handle)
 
683
             struct xtc_handle *handle)
744
684
{
745
685
        unsigned int i, j;
746
686
        int ret = 1;
771
711
 
772
712
        size = sizeof(struct ipt_entry);
773
713
        for (matchp = matches; matchp; matchp = matchp->next)
774
 
                size += XT_ALIGN(sizeof(struct ipt_entry_match)) + matchp->match->size;
 
714
                size += XT_ALIGN(sizeof(struct xt_entry_match)) + matchp->match->size;
775
715
 
776
716
        mask = xtables_calloc(1, size
777
 
                         + XT_ALIGN(sizeof(struct ipt_entry_target))
 
717
                         + XT_ALIGN(sizeof(struct xt_entry_target))
778
718
                         + target->size);
779
719
 
780
720
        memset(mask, 0xFF, sizeof(struct ipt_entry));
782
722
 
783
723
        for (matchp = matches; matchp; matchp = matchp->next) {
784
724
                memset(mptr, 0xFF,
785
 
                       XT_ALIGN(sizeof(struct ipt_entry_match))
 
725
                       XT_ALIGN(sizeof(struct xt_entry_match))
786
726
                       + matchp->match->userspacesize);
787
 
                mptr += XT_ALIGN(sizeof(struct ipt_entry_match)) + matchp->match->size;
 
727
                mptr += XT_ALIGN(sizeof(struct xt_entry_match)) + matchp->match->size;
788
728
        }
789
729
 
790
730
        memset(mptr, 0xFF,
791
 
               XT_ALIGN(sizeof(struct ipt_entry_target))
 
731
               XT_ALIGN(sizeof(struct xt_entry_target))
792
732
               + target->userspacesize);
793
733
 
794
734
        return mask;
795
735
}
796
736
 
797
737
static int
798
 
delete_entry(const ipt_chainlabel chain,
 
738
delete_entry(const xt_chainlabel chain,
799
739
             struct ipt_entry *fw,
800
740
             unsigned int nsaddrs,
801
741
             const struct in_addr saddrs[],
804
744
             const struct in_addr daddrs[],
805
745
             const struct in_addr dmasks[],
806
746
             int verbose,
807
 
             struct iptc_handle *handle,
 
747
             struct xtc_handle *handle,
808
748
             struct xtables_rule_match *matches,
809
749
             const struct xtables_target *target)
810
750
{
830
770
}
831
771
 
832
772
static int
833
 
check_entry(const ipt_chainlabel chain, struct ipt_entry *fw,
 
773
check_entry(const xt_chainlabel chain, struct ipt_entry *fw,
834
774
            unsigned int nsaddrs, const struct in_addr *saddrs,
835
775
            const struct in_addr *smasks, unsigned int ndaddrs,
836
776
            const struct in_addr *daddrs, const struct in_addr *dmasks,
837
 
            bool verbose, struct iptc_handle *handle,
 
777
            bool verbose, struct xtc_handle *handle,
838
778
            struct xtables_rule_match *matches,
839
779
            const struct xtables_target *target)
840
780
{
860
800
}
861
801
 
862
802
int
863
 
for_each_chain4(int (*fn)(const ipt_chainlabel, int, struct iptc_handle *),
864
 
               int verbose, int builtinstoo, struct iptc_handle *handle)
 
803
for_each_chain4(int (*fn)(const xt_chainlabel, int, struct xtc_handle *),
 
804
               int verbose, int builtinstoo, struct xtc_handle *handle)
865
805
{
866
806
        int ret = 1;
867
807
        const char *chain;
874
814
                chain = iptc_next_chain(handle);
875
815
        }
876
816
 
877
 
        chains = xtables_malloc(sizeof(ipt_chainlabel) * chaincount);
 
817
        chains = xtables_malloc(sizeof(xt_chainlabel) * chaincount);
878
818
        i = 0;
879
819
        chain = iptc_first_chain(handle);
880
820
        while (chain) {
881
 
                strcpy(chains + i*sizeof(ipt_chainlabel), chain);
 
821
                strcpy(chains + i*sizeof(xt_chainlabel), chain);
882
822
                i++;
883
823
                chain = iptc_next_chain(handle);
884
824
        }
885
825
 
886
826
        for (i = 0; i < chaincount; i++) {
887
827
                if (!builtinstoo
888
 
                    && iptc_builtin(chains + i*sizeof(ipt_chainlabel),
 
828
                    && iptc_builtin(chains + i*sizeof(xt_chainlabel),
889
829
                                    handle) == 1)
890
830
                        continue;
891
 
                ret &= fn(chains + i*sizeof(ipt_chainlabel), verbose, handle);
 
831
                ret &= fn(chains + i*sizeof(xt_chainlabel), verbose, handle);
892
832
        }
893
833
 
894
834
        free(chains);
896
836
}
897
837
 
898
838
int
899
 
flush_entries4(const ipt_chainlabel chain, int verbose,
900
 
              struct iptc_handle *handle)
 
839
flush_entries4(const xt_chainlabel chain, int verbose,
 
840
              struct xtc_handle *handle)
901
841
{
902
842
        if (!chain)
903
843
                return for_each_chain4(flush_entries4, verbose, 1, handle);
908
848
}
909
849
 
910
850
static int
911
 
zero_entries(const ipt_chainlabel chain, int verbose,
912
 
             struct iptc_handle *handle)
 
851
zero_entries(const xt_chainlabel chain, int verbose,
 
852
             struct xtc_handle *handle)
913
853
{
914
854
        if (!chain)
915
855
                return for_each_chain4(zero_entries, verbose, 1, handle);
920
860
}
921
861
 
922
862
int
923
 
delete_chain4(const ipt_chainlabel chain, int verbose,
924
 
             struct iptc_handle *handle)
 
863
delete_chain4(const xt_chainlabel chain, int verbose,
 
864
             struct xtc_handle *handle)
925
865
{
926
866
        if (!chain)
927
867
                return for_each_chain4(delete_chain4, verbose, 0, handle);
932
872
}
933
873
 
934
874
static int
935
 
list_entries(const ipt_chainlabel chain, int rulenum, int verbose, int numeric,
936
 
             int expanded, int linenumbers, struct iptc_handle *handle)
 
875
list_entries(const xt_chainlabel chain, int rulenum, int verbose, int numeric,
 
876
             int expanded, int linenumbers, struct xtc_handle *handle)
937
877
{
938
878
        int found = 0;
939
879
        unsigned int format;
1044
984
        }
1045
985
}
1046
986
 
1047
 
static int print_match_save(const struct ipt_entry_match *e,
 
987
static int print_match_save(const struct xt_entry_match *e,
1048
988
                        const struct ipt_ip *ip)
1049
989
{
1050
990
        const struct xtables_match *match =
1051
991
                xtables_find_match(e->u.user.name, XTF_TRY_LOAD, NULL);
1052
992
 
1053
993
        if (match) {
1054
 
                printf(" -m %s", e->u.user.name);
 
994
                printf(" -m %s",
 
995
                        match->alias ? match->alias(e) : e->u.user.name);
1055
996
 
1056
997
                /* some matches don't provide a save function */
1057
998
                if (match->save)
1100
1041
/* We want this to be readable, so only print out neccessary fields.
1101
1042
 * Because that's the kind of world I want to live in.  */
1102
1043
void print_rule4(const struct ipt_entry *e,
1103
 
                struct iptc_handle *h, const char *chain, int counters)
 
1044
                struct xtc_handle *h, const char *chain, int counters)
1104
1045
{
1105
 
        const struct ipt_entry_target *t;
 
1046
        const struct xt_entry_target *t;
1106
1047
        const char *target_name;
1107
1048
 
1108
1049
        /* print counters for iptables-save */
1125
1066
        print_iface('o', e->ip.outiface, e->ip.outiface_mask,
1126
1067
                    e->ip.invflags & IPT_INV_VIA_OUT);
1127
1068
 
1128
 
        print_proto(e->ip.proto, e->ip.invflags & IPT_INV_PROTO);
 
1069
        print_proto(e->ip.proto, e->ip.invflags & XT_INV_PROTO);
1129
1070
 
1130
1071
        if (e->ip.flags & IPT_F_FRAG)
1131
1072
                printf("%s -f",
1140
1081
        if (counters < 0)
1141
1082
                printf(" -c %llu %llu", (unsigned long long)e->counters.pcnt, (unsigned long long)e->counters.bcnt);
1142
1083
 
1143
 
        /* Print target name */
 
1084
        /* Print target name and targinfo part */
1144
1085
        target_name = iptc_get_target(e, h);
1145
 
        if (target_name && (*target_name != '\0'))
1146
 
#ifdef IPT_F_GOTO
1147
 
                printf(" -%c %s", e->ip.flags & IPT_F_GOTO ? 'g' : 'j', target_name);
1148
 
#else
1149
 
                printf(" -j %s", target_name);
1150
 
#endif
1151
 
 
1152
 
        /* Print targinfo part */
1153
1086
        t = ipt_get_target((struct ipt_entry *)e);
1154
1087
        if (t->u.user.name[0]) {
1155
1088
                const struct xtables_target *target =
1161
1094
                        exit(1);
1162
1095
                }
1163
1096
 
 
1097
                printf(" -j %s", target->alias ? target->alias(t) : target_name);
1164
1098
                if (target->save)
1165
1099
                        target->save(&e->ip, t);
1166
1100
                else {
1167
 
                        /* If the target size is greater than ipt_entry_target
 
1101
                        /* If the target size is greater than xt_entry_target
1168
1102
                         * there is something to be saved, we just don't know
1169
1103
                         * how to print it */
1170
1104
                        if (t->u.target_size !=
1171
 
                            sizeof(struct ipt_entry_target)) {
 
1105
                            sizeof(struct xt_entry_target)) {
1172
1106
                                fprintf(stderr, "Target `%s' is missing "
1173
1107
                                                "save function\n",
1174
1108
                                        t->u.user.name);
1175
1109
                                exit(1);
1176
1110
                        }
1177
1111
                }
1178
 
        }
 
1112
        } else if (target_name && (*target_name != '\0'))
 
1113
#ifdef IPT_F_GOTO
 
1114
                printf(" -%c %s", e->ip.flags & IPT_F_GOTO ? 'g' : 'j', target_name);
 
1115
#else
 
1116
                printf(" -j %s", target_name);
 
1117
#endif
 
1118
 
1179
1119
        printf("\n");
1180
1120
}
1181
1121
 
1182
1122
static int
1183
 
list_rules(const ipt_chainlabel chain, int rulenum, int counters,
1184
 
             struct iptc_handle *handle)
 
1123
list_rules(const xt_chainlabel chain, int rulenum, int counters,
 
1124
             struct xtc_handle *handle)
1185
1125
{
1186
1126
        const char *this = NULL;
1187
1127
        int found = 0;
1198
1138
                        continue;
1199
1139
 
1200
1140
                if (iptc_builtin(this, handle)) {
1201
 
                        struct ipt_counters count;
 
1141
                        struct xt_counters count;
1202
1142
                        printf("-P %s %s", this, iptc_get_policy(this, &count, handle));
1203
1143
                        if (counters)
1204
1144
                            printf(" -c %llu %llu", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt);
1235
1175
static struct ipt_entry *
1236
1176
generate_entry(const struct ipt_entry *fw,
1237
1177
               struct xtables_rule_match *matches,
1238
 
               struct ipt_entry_target *target)
 
1178
               struct xt_entry_target *target)
1239
1179
{
1240
1180
        unsigned int size;
1241
1181
        struct xtables_rule_match *matchp;
1260
1200
        return e;
1261
1201
}
1262
1202
 
1263
 
static void clear_rule_matches(struct xtables_rule_match **matches)
1264
 
{
1265
 
        struct xtables_rule_match *matchp, *tmp;
1266
 
 
1267
 
        for (matchp = *matches; matchp;) {
1268
 
                tmp = matchp->next;
1269
 
                if (matchp->match->m) {
1270
 
                        free(matchp->match->m);
1271
 
                        matchp->match->m = NULL;
1272
 
                }
1273
 
                if (matchp->match == matchp->match->next) {
1274
 
                        free(matchp->match);
1275
 
                        matchp->match = NULL;
1276
 
                }
1277
 
                free(matchp);
1278
 
                matchp = tmp;
1279
 
        }
1280
 
 
1281
 
        *matches = NULL;
1282
 
}
1283
 
 
1284
 
void
1285
 
get_kernel_version(void) {
1286
 
        static struct utsname uts;
1287
 
        int x = 0, y = 0, z = 0;
1288
 
 
1289
 
        if (uname(&uts) == -1) {
1290
 
                fprintf(stderr, "Unable to retrieve kernel version.\n");
1291
 
                xtables_free_opts(1);
1292
 
                exit(1);
1293
 
        }
1294
 
 
1295
 
        sscanf(uts.release, "%d.%d.%d", &x, &y, &z);
1296
 
        kernel_version = LINUX_VERSION(x, y, z);
1297
 
}
1298
 
 
1299
1203
static void command_jump(struct iptables_command_state *cs)
1300
1204
{
1301
1205
        size_t size;
1308
1212
        if (cs->target == NULL)
1309
1213
                return;
1310
1214
 
1311
 
        size = XT_ALIGN(sizeof(struct ipt_entry_target))
 
1215
        size = XT_ALIGN(sizeof(struct xt_entry_target))
1312
1216
                + cs->target->size;
1313
1217
 
1314
1218
        cs->target->t = xtables_calloc(1, size);
1315
1219
        cs->target->t->u.target_size = size;
1316
 
        strcpy(cs->target->t->u.user.name, cs->jumpto);
 
1220
        if (cs->target->real_name == NULL) {
 
1221
                strcpy(cs->target->t->u.user.name, cs->jumpto);
 
1222
        } else {
 
1223
                /* Alias support for userspace side */
 
1224
                strcpy(cs->target->t->u.user.name, cs->target->real_name);
 
1225
                if (!(cs->target->ext_flags & XTABLES_EXT_ALIAS))
 
1226
                        fprintf(stderr, "Notice: The %s target is converted into %s target "
 
1227
                                "in rule listing and saving.\n",
 
1228
                                cs->jumpto, cs->target->real_name);
 
1229
        }
1317
1230
        cs->target->t->u.user.revision = cs->target->revision;
 
1231
 
1318
1232
        xs_init_target(cs->target);
1319
1233
 
1320
1234
        if (cs->target->x6_options != NULL)
1339
1253
                           "unexpected ! flag before --match");
1340
1254
 
1341
1255
        m = xtables_find_match(optarg, XTF_LOAD_MUST_SUCCEED, &cs->matches);
1342
 
        size = XT_ALIGN(sizeof(struct ipt_entry_match)) + m->size;
 
1256
        size = XT_ALIGN(sizeof(struct xt_entry_match)) + m->size;
1343
1257
        m->m = xtables_calloc(1, size);
1344
1258
        m->m->u.match_size = size;
1345
 
        strcpy(m->m->u.user.name, m->name);
 
1259
        if (m->real_name == NULL) {
 
1260
                strcpy(m->m->u.user.name, m->name);
 
1261
        } else {
 
1262
                strcpy(m->m->u.user.name, m->real_name);
 
1263
                if (!(m->ext_flags & XTABLES_EXT_ALIAS))
 
1264
                        fprintf(stderr, "Notice: the %s match is converted into %s match "
 
1265
                                "in rule listing and saving.\n", m->name, m->real_name);
 
1266
        }
1346
1267
        m->m->u.user.revision = m->revision;
 
1268
 
1347
1269
        xs_init_match(m);
1348
1270
        if (m == m->next)
1349
1271
                return;
1358
1280
                xtables_error(OTHER_PROBLEM, "can't alloc memory!");
1359
1281
}
1360
1282
 
1361
 
int do_command4(int argc, char *argv[], char **table, struct iptc_handle **handle)
 
1283
int do_command4(int argc, char *argv[], char **table, struct xtc_handle **handle)
1362
1284
{
1363
1285
        struct iptables_command_state cs;
1364
1286
        struct ipt_entry *e = NULL;
1577
1499
                        cs.fw.ip.proto = xtables_parse_protocol(cs.protocol);
1578
1500
 
1579
1501
                        if (cs.fw.ip.proto == 0
1580
 
                            && (cs.fw.ip.invflags & IPT_INV_PROTO))
 
1502
                            && (cs.fw.ip.invflags & XT_INV_PROTO))
1581
1503
                                xtables_error(PARAMETER_PROBLEM,
1582
1504
                                           "rule would never match protocol");
1583
1505
                        break;
1855
1777
                        || iptc_is_chain(cs.jumpto, *handle))) {
1856
1778
                        size_t size;
1857
1779
 
1858
 
                        cs.target = xtables_find_target(IPT_STANDARD_TARGET,
 
1780
                        cs.target = xtables_find_target(XT_STANDARD_TARGET,
1859
1781
                                         XTF_LOAD_MUST_SUCCEED);
1860
1782
 
1861
 
                        size = sizeof(struct ipt_entry_target)
 
1783
                        size = sizeof(struct xt_entry_target)
1862
1784
                                + cs.target->size;
1863
1785
                        cs.target->t = xtables_calloc(1, size);
1864
1786
                        cs.target->t->u.target_size = size;
1981
1903
        if (verbose > 1)
1982
1904
                dump_entries(*handle);
1983
1905
 
1984
 
        clear_rule_matches(&cs.matches);
 
1906
        xtables_rule_matches_free(&cs.matches);
1985
1907
 
1986
1908
        if (e != NULL) {
1987
1909
                free(e);