]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
extensions: libxt_CLASSIFY: Add translation to nft
authorLiping Zhang <liping.zhang@spreadtrum.com>
Sun, 21 Aug 2016 14:34:55 +0000 (22:34 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 22 Aug 2016 09:44:33 +0000 (11:44 +0200)
For examples:
  # iptables-translate -A OUTPUT -j CLASSIFY --set-class 0:0
  nft add rule ip filter OUTPUT counter meta priority set none
  # iptables-translate -A OUTPUT -j CLASSIFY --set-class ffff:ffff
  nft add rule ip filter OUTPUT counter meta priority set root
  # iptables-translate -A OUTPUT -j CLASSIFY --set-class 1:234
  nft add rule ip filter OUTPUT counter meta priority set 1:234

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
extensions/libxt_CLASSIFY.c

index cd016d8f7eae2c991010cb58009eedd132c45663..ba88f7584ce49e9cbb2952fd61da13db0d06945e 100644 (file)
@@ -80,6 +80,31 @@ arpCLASSIFY_print(const void *ip, const struct xt_entry_target *target,
        CLASSIFY_save(ip, target);
 }
 
+static int CLASSIFY_xlate(struct xt_xlate *xl,
+                         const struct xt_xlate_tg_params *params)
+{
+       const struct xt_classify_target_info *clinfo =
+               (const struct xt_classify_target_info *)params->target->data;
+       __u32 handle = clinfo->priority;
+
+       xt_xlate_add(xl, "meta priority set ");
+
+       switch (handle) {
+       case TC_H_ROOT:
+               xt_xlate_add(xl, "root");
+               break;
+       case TC_H_UNSPEC:
+               xt_xlate_add(xl, "none");
+               break;
+       default:
+               xt_xlate_add(xl, "%0x:%0x", TC_H_MAJ(handle) >> 16,
+                            TC_H_MIN(handle));
+               break;
+       }
+
+       return 1;
+}
+
 static struct xtables_target classify_target[] = {
        {
                .family         = NFPROTO_UNSPEC,
@@ -92,6 +117,7 @@ static struct xtables_target classify_target[] = {
                .save           = CLASSIFY_save,
                .x6_parse       = CLASSIFY_parse,
                .x6_options     = CLASSIFY_opts,
+               .xlate          = CLASSIFY_xlate,
        },
        {
                .family         = NFPROTO_ARP,
@@ -103,6 +129,7 @@ static struct xtables_target classify_target[] = {
                .print          = arpCLASSIFY_print,
                .x6_parse       = CLASSIFY_parse,
                .x6_options     = CLASSIFY_opts,
+               .xlate          = CLASSIFY_xlate,
        },
 };