From: Eric Leblond <eric@regit.org>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, Eric Leblond <eric@regit.org>
Subject: [nftables RFC PATCH] icmp: add code filtering with name
Date: Mon, 10 Feb 2014 13:33:25 +0100 [thread overview]
Message-ID: <1392035605-2889-2-git-send-email-eric@regit.org> (raw)
In-Reply-To: <1392035605-2889-1-git-send-email-eric@regit.org>
This patch define names for code field allowing to use string
instead of integer when filtering on icmp code.
Signed-off-by: Eric Leblond <eric@regit.org>
---
include/datatype.h | 2 ++
src/proto.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/include/datatype.h b/include/datatype.h
index 9e609cf..033ae08 100644
--- a/include/datatype.h
+++ b/include/datatype.h
@@ -34,6 +34,7 @@
* @TYPE_CT_DIR: conntrack direction
* @TYPE_CT_STATUS: conntrack status (bitmask subtype)
* @TYPE_ICMP6_TYPE: ICMPv6 type codes (integer subtype)
+ * @TYPE_ICMP_CODE: ICMP code codes (integer subtype)
*/
enum datatypes {
TYPE_INVALID,
@@ -66,6 +67,7 @@ enum datatypes {
TYPE_CT_DIR,
TYPE_CT_STATUS,
TYPE_ICMP6_TYPE,
+ TYPE_ICMP_CODE,
__TYPE_MAX
};
#define TYPE_MAX (__TYPE_MAX - 1)
diff --git a/src/proto.c b/src/proto.c
index cc073af..bb56766 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -315,12 +315,52 @@ static const struct datatype icmp_type_type = {
#define ICMPHDR_TYPE(__name, __type, __member) \
HDR_TYPE(__name, __type, struct icmphdr, __member)
+static const struct symbol_table icmp_code_tbl = {
+ .symbols = {
+ SYMBOL("network-unreachable", ICMP_NET_UNREACH),
+ SYMBOL("host-unreachable", ICMP_HOST_UNREACH),
+ SYMBOL("protocol-unreachable", ICMP_PROT_UNREACH),
+ SYMBOL("port-unreachable", ICMP_PORT_UNREACH),
+ SYMBOL("fragmentation-needed", ICMP_FRAG_NEEDED),
+ SYMBOL("source-route-failed", ICMP_SR_FAILED),
+ SYMBOL("network-unknown", ICMP_NET_UNKNOWN),
+ SYMBOL("host-unknown", ICMP_HOST_UNKNOWN),
+ SYMBOL("host-isolated", ICMP_HOST_ISOLATED),
+ SYMBOL("network-prohibited", ICMP_NET_ANO),
+ SYMBOL("host-prohibited", ICMP_HOST_ANO),
+ SYMBOL("TOS-network-unreachable", ICMP_NET_UNR_TOS),
+ SYMBOL("TOS-host-unreachable", ICMP_HOST_UNR_TOS),
+ SYMBOL("communication-prohibited", ICMP_PKT_FILTERED),
+ SYMBOL("host-precedence-violation", ICMP_PREC_VIOLATION),
+ SYMBOL("precedence-cutoff", ICMP_PREC_CUTOFF),
+
+ SYMBOL("network-redirect", ICMP_REDIR_NET),
+ SYMBOL("host-redirect", ICMP_REDIR_HOST),
+ SYMBOL("network-redirect-tos", ICMP_REDIR_NETTOS),
+ SYMBOL("host-redirect-tos", ICMP_REDIR_HOSTTOS),
+
+ SYMBOL("ttl-exceeded", ICMP_EXC_TTL),
+ SYMBOL("fragtime-exceeded", ICMP_EXC_FRAGTIME),
+ SYMBOL_LIST_END
+ },
+};
+
+static const struct datatype icmp_code_type = {
+ .type = TYPE_ICMP_CODE,
+ .name = "icmp_code",
+ .desc = "ICMP code",
+ .byteorder = BYTEORDER_BIG_ENDIAN,
+ .size = BITS_PER_BYTE,
+ .basetype = &integer_type,
+ .sym_tbl = &icmp_code_tbl,
+};
+
const struct proto_desc proto_icmp = {
.name = "icmp",
.base = PROTO_BASE_TRANSPORT_HDR,
.templates = {
[ICMPHDR_TYPE] = ICMPHDR_TYPE("type", &icmp_type_type, type),
- [ICMPHDR_CODE] = ICMPHDR_FIELD("code", code),
+ [ICMPHDR_CODE] = ICMPHDR_TYPE("code", &icmp_code_type, code),
[ICMPHDR_CHECKSUM] = ICMPHDR_FIELD("checksum", checksum),
[ICMPHDR_ID] = ICMPHDR_FIELD("id", un.echo.id),
[ICMPHDR_SEQ] = ICMPHDR_FIELD("sequence", un.echo.sequence),
@@ -806,6 +846,7 @@ const struct proto_desc proto_eth = {
static void __init proto_init(void)
{
datatype_register(&icmp_type_type);
+ datatype_register(&icmp_code_type);
datatype_register(&tcp_flag_type);
datatype_register(&dccp_pkttype_type);
datatype_register(&arpop_type);
--
1.9.0.rc3
next prev parent reply other threads:[~2014-02-10 12:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-10 12:33 [nftables RFC PATCH 0/1] implementing icmp code filtering Eric Leblond
2014-02-10 12:33 ` Eric Leblond [this message]
2014-02-10 13:12 ` Patrick McHardy
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=1392035605-2889-2-git-send-email-eric@regit.org \
--to=eric@regit.org \
--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).