netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: pablo@netfilter.org
Subject: [libnftables PATCH 17/21] exthdr: xml: use string for type node
Date: Wed, 26 Jun 2013 13:37:17 +0200	[thread overview]
Message-ID: <20130626113716.23511.49932.stgit@nfdev.cica.es> (raw)
In-Reply-To: <20130626113509.23511.14359.stgit@nfdev.cica.es>

This patch implements using a string for the <type> node.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
 src/expr/exthdr.c |   49 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 44 insertions(+), 5 deletions(-)

diff --git a/src/expr/exthdr.c b/src/expr/exthdr.c
index 762facd..3cccc28 100644
--- a/src/expr/exthdr.c
+++ b/src/expr/exthdr.c
@@ -25,6 +25,10 @@
 
 #include "expr_ops.h"
 
+#ifndef IPPROTO_MH
+#define IPPROTO_MH 135
+#endif
+
 struct nft_expr_exthdr {
 	enum nft_registers	dreg;
 	uint8_t			type;
@@ -171,6 +175,41 @@ nft_rule_expr_exthdr_parse(struct nft_rule_expr *e, struct nlattr *attr)
 	return 0;
 }
 
+static const char *exthdr_type2str(uint32_t type)
+{
+	switch (type) {
+	case IPPROTO_HOPOPTS:
+		return "hopopts";
+	case IPPROTO_ROUTING:
+		return "routing";
+	case IPPROTO_FRAGMENT:
+		return "fragment";
+	case IPPROTO_DSTOPTS:
+		return "dstopts";
+	case IPPROTO_MH:
+		return "mh";
+	default:
+		return "unknown";
+	}
+}
+
+static int str2exthdr_type(char *str)
+{
+	if (strcmp(str, "hopopts") == 0)
+		return IPPROTO_HOPOPTS;
+	else if (strcmp(str, "routing") == 0)
+		return IPPROTO_ROUTING;
+	else if (strcmp(str, "fragment") == 0)
+		return IPPROTO_FRAGMENT;
+	else if (strcmp(str, "dstopts") == 0)
+		return IPPROTO_DSTOPTS;
+	else if (strcmp(str, "mh") == 0)
+		return IPPROTO_MH;
+
+	return -1;
+}
+
+
 static int
 nft_rule_expr_exthdr_xml_parse(struct nft_rule_expr *e, char *xml)
 {
@@ -226,13 +265,12 @@ nft_rule_expr_exthdr_xml_parse(struct nft_rule_expr *e, char *xml)
 		return -1;
 	}
 
-	tmp = strtoull(node->child->value.opaque, &endptr, 10);
-	if (tmp > UINT8_MAX || tmp < 0 || *endptr) {
+	if (str2exthdr_type(node->child->value.opaque) < 0) {
 		mxmlDelete(tree);
 		return -1;
 	}
 
-	exthdr->type = tmp;
+	exthdr->type = str2exthdr_type(node->child->value.opaque);
 	e->flags |= (1 << NFT_EXPR_EXTHDR_TYPE);
 
 	/* Get and set <offset> */
@@ -285,9 +323,10 @@ nft_rule_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type,
 	switch(type) {
 	case NFT_RULE_O_XML:
 		return snprintf(buf, len, "<dreg>%u</dreg>"
-					  "<type>%u</type><offset>%u</offset>"
+					  "<type>%s</type><offset>%u</offset>"
 					  "<len>%u</len>",
-					exthdr->dreg, exthdr->type,
+					exthdr->dreg,
+					exthdr_type2str(exthdr->type),
 					exthdr->offset, exthdr->len);
 
 	case NFT_RULE_O_DEFAULT:


  parent reply	other threads:[~2013-06-26 11:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-26 11:36 [libnftables PATCH 00/21] Small fixes for XML Arturo Borrero Gonzalez
2013-06-26 11:36 ` [libnftables PATCH 01/21] chain: add hooknum2str Arturo Borrero Gonzalez
2013-06-26 11:36 ` [libnftables PATCH 02/21] src: xml: convert family values to string Arturo Borrero Gonzalez
2013-06-26 11:36 ` [libnftables PATCH 03/21] rule: xml: conditional compat info Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 04/21] bitwise: xml: mask and xor use same number of data registers Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 05/21] expr: xml: validate registers < NFT_REG_MAX Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 06/21] nat: xml: change nat types string to dnat/snat Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 07/21] nat: xml: change IP range node names Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 08/21] byteorder: xml: op as string Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 09/21] ct: xml: add extra dir check Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 10/21] ct: xml: use key's name string instead of numbers Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 11/21] exthdr: xml: fix mandatory elements Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 12/21] chain: xml: use string for policy Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 13/21] data_reg: xml: len node shows byte length Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 14/21] data_reg: xml: fix bytes movements Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 15/21] target&match: xml: don't print rev number Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 16/21] payload: xml: use string for base attribute Arturo Borrero Gonzalez
2013-06-26 11:37 ` Arturo Borrero Gonzalez [this message]
2013-06-26 11:37 ` [libnftables PATCH 18/21] meta: xml: use string to represent key attribute Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 19/21] nat: snprintf: fix buffer offset Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 20/21] nat: xml: rename node type to nat_type Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 21/21] exthdr: xml: rename type node to exthdr_type Arturo Borrero Gonzalez
2013-06-27 17:58 ` [libnftables PATCH 00/21] Small fixes for XML Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130626113716.23511.49932.stgit@nfdev.cica.es \
    --to=arturo.borrero.glez@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).