]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
byteorder: xml: op as string
authorArturo Borrero <arturo.borrero.glez@gmail.com>
Wed, 26 Jun 2013 11:37:05 +0000 (13:37 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 27 Jun 2013 17:11:24 +0000 (19:11 +0200)
This patch changes the numerical value of the XML byteorder's <op> node to a string representation.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
src/expr/byteorder.c

index c2f38a88fa00810e66e581703f9cc505efcd8faa..b0ba0095aa331b8e8f23da288832d7959b2dc565 100644 (file)
@@ -196,6 +196,11 @@ nft_rule_expr_byteorder_parse(struct nft_rule_expr *e, struct nlattr *attr)
        return ret;
 }
 
+static char *expr_byteorder_str[] = {
+       [NFT_BYTEORDER_HTON] = "hton",
+       [NFT_BYTEORDER_NTOH] = "ntoh",
+};
+
 static int
 nft_rule_expr_byteorder_xml_parse(struct nft_rule_expr *e, char *xml)
 {
@@ -249,11 +254,13 @@ nft_rule_expr_byteorder_xml_parse(struct nft_rule_expr *e, char *xml)
        if (node == NULL)
                goto err;
 
-       tmp = strtoull(node->child->value.opaque, &endptr, 10);
-       if (tmp > UINT8_MAX || tmp < 0 || *endptr)
+       if (strcmp(node->child->value.opaque, "ntoh") == 0)
+               byteorder->op = NFT_BYTEORDER_NTOH;
+       else if (strcmp(node->child->value.opaque, "hton") == 0)
+               byteorder->op = NFT_BYTEORDER_HTON;
+       else
                goto err;
 
-       byteorder->op = tmp;
        e->flags |= (1 << NFT_EXPR_BYTEORDER_OP);
 
        node = mxmlFindElement(tree, tree, "len", NULL, NULL, MXML_DESCEND);
@@ -298,10 +305,11 @@ nft_rule_expr_byteorder_snprintf_xml(char *buf, size_t size,
 
        ret = snprintf(buf, len, "<sreg>%u</sreg>"
                                 "<dreg>%u</dreg>"
-                                "<op>%u</op>"
+                                "<op>%s</op>"
                                 "<len>%u</len>"
                                 "<size>%u</size>",
-                      byteorder->sreg, byteorder->dreg, byteorder->op,
+                      byteorder->sreg, byteorder->dreg,
+                      expr_byteorder_str[byteorder->op],
                       byteorder->len, byteorder->size);
        SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
@@ -314,8 +322,9 @@ nft_rule_expr_byteorder_snprintf_default(char *buf, size_t size,
 {
        int len = size, offset = 0, ret;
 
-       ret = snprintf(buf, len, "sreg=%u dreg=%u op=%u len=%u size=%u ",
-                      byteorder->sreg, byteorder->dreg, byteorder->op,
+       ret = snprintf(buf, len, "sreg=%u dreg=%u op=%s len=%u size=%u ",
+                      byteorder->sreg, byteorder->dreg,
+                      expr_byteorder_str[byteorder->op],
                       byteorder->len, byteorder->size);
        SNPRINTF_BUFFER_SIZE(ret, size, len, offset);