Skip to contentSkip to conversation

expr: meta: Add pkttype support

PATCH Superseded Ana Rey 2 participants 5 messages Jun 12, 2014 – Aug 5, 2014

Subsystems (2)
lore
Share & tools
lore

Ana Rey

author
#0 lore raw

PATCH 1/1 expr: meta: Add pkttype support

Add pkttype support in meta. The pkttype option does not set.

Before, If we want to declare a pktype, It has used a syntax like this:

nft add rule ip filter input meta pkttype broadcast

Joint work with Alvaro Neira Ayuso <[email protected]>

---
 include/linux/netfilter/nf_tables.h | 2 ++
 src/expr/meta.c                     | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)
include/linux/netfilter/nf_tables.h +2 -0
index 2a88f64..9eb5153 100644
@@ -571,6 +571,7 @@ enum nft_exthdr_attributes {
  * @NFT_META_L4PROTO: layer 4 protocol number
  * @NFT_META_BRI_IIFNAME: packet input bridge interface name
  * @NFT_META_BRI_OIFNAME: packet output bridge interface name
+ * @NFT_META_PKTTYPE: Packet class
  */
 enum nft_meta_keys {
 	NFT_META_LEN,
@@ -592,6 +593,7 @@ enum nft_meta_keys {
 	NFT_META_L4PROTO,
 	NFT_META_BRI_IIFNAME,
 	NFT_META_BRI_OIFNAME,
+	NFT_META_PKTTYPE,
 };
 
 /**
src/expr/meta.c +2 -1
index fb945f0..24057f2 100644
@@ -23,7 +23,7 @@
 #include "expr_ops.h"
 
 #ifndef NFT_META_MAX
-#define NFT_META_MAX (NFT_META_BRI_OIFNAME + 1)
+#define NFT_META_MAX (NFT_META_PKTTYPE + 1)
 #endif
 
 struct nft_expr_meta {
@@ -155,6 +155,7 @@ static const char *meta_key2str_array[NFT_META_MAX] = {
 	[NFT_META_SECMARK]	= "secmark",
 	[NFT_META_BRI_IIFNAME]	= "bri_iifname",
 	[NFT_META_BRI_OIFNAME]	= "bri_oifname",
+	[NFT_META_PKTTYPE]	= "pkttype"
 };
 
 static const char *meta_key2str(uint8_t key)
Signature · 1 line
2.0.0
author
#1 lore raw

PATCH 1/1 netfilter: nf_tables: add pktype support to meta expression

Joint work with Álvaro Neira Ayuso <[email protected]>

---
 include/uapi/linux/netfilter/nf_tables.h |  2 ++
 net/netfilter/nft_meta.c                 | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
index 2a88f64..9eb5153 100644
@@ -571,6 +571,7 @@ enum nft_exthdr_attributes {
  * @NFT_META_L4PROTO: layer 4 protocol number
  * @NFT_META_BRI_IIFNAME: packet input bridge interface name
  * @NFT_META_BRI_OIFNAME: packet output bridge interface name
+ * @NFT_META_PKTTYPE: Packet class
  */
 enum nft_meta_keys {
 	NFT_META_LEN,
@@ -592,6 +593,7 @@ enum nft_meta_keys {
 	NFT_META_L4PROTO,
 	NFT_META_BRI_IIFNAME,
 	NFT_META_BRI_OIFNAME,
+	NFT_META_PKTTYPE,
 };
 
 /**
net/netfilter/nft_meta.c +17 -0
index 852b178..1d9d5b3 100644
@@ -14,6 +14,9 @@
 #include <linux/netlink.h>
 #include <linux/netfilter.h>
 #include <linux/netfilter/nf_tables.h>
+#include <linux/in.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
 #include <net/dst.h>
 #include <net/sock.h>
 #include <net/tcp_states.h> /* for TCP_TIME_WAIT */
@@ -124,6 +127,19 @@ void nft_meta_get_eval(const struct nft_expr *expr,
 		dest->data[0] = skb->secmark;
 		break;
 #endif
+	case NFT_META_PKTTYPE:
+		dest->data[0] = skb->pkt_type;
+		if (skb->pkt_type != PACKET_LOOPBACK)
+			dest->data[0] = skb->pkt_type;
+		else if (expr->ops->type->family == NFPROTO_IPV4 &&
+			 ipv4_is_multicast(ip_hdr(skb)->daddr))
+			dest->data[0] = PACKET_MULTICAST;
+		else if (expr->ops->type->family == NFPROTO_IPV6 &&
+			 ipv6_hdr(skb)->daddr.s6_addr[0] == 0xFF)
+			dest->data[0] = PACKET_MULTICAST;
+		else
+			dest->data[0] = PACKET_BROADCAST;
+		break;
 	default:
 		WARN_ON(1);
 		goto err;
@@ -194,6 +210,7 @@ int nft_meta_get_init(const struct nft_ctx *ctx,
 #endif
 #ifdef CONFIG_NETWORK_SECMARK
 	case NFT_META_SECMARK:
+	case NFT_META_PKTTYPE:
 #endif
 		break;
 	default:
Signature · 6 lines
2.0.0

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#3 lore raw

PATCH 1/1 src: Add support for pkttype in meta

In reply to Ana Rey

Joint work with Alvaro Neira Ayuso <[email protected]>

---
 include/datatype.h                  |  1 +
 include/linux/netfilter/nf_tables.h |  2 ++
 src/meta.c                          | 55 +++++++++++++++++++++++++++++++++++++
 src/parser.y                        |  2 ++
 src/scanner.l                       |  1 +
 5 files changed, 61 insertions(+)
include/datatype.h +1 -0
index b53358c..66ca8ed 100644
@@ -70,6 +70,7 @@ enum datatypes {
 	TYPE_CT_STATUS,
 	TYPE_ICMP6_TYPE,
 	TYPE_CT_LABEL,
+	TYPE_PKTTYPE,
 	__TYPE_MAX
 };
 #define TYPE_MAX		(__TYPE_MAX - 1)
include/linux/netfilter/nf_tables.h +2 -0
index a5f8ec0..e391ed4 100644
@@ -535,6 +535,7 @@ enum nft_exthdr_attributes {
  * @NFT_META_L4PROTO: layer 4 protocol number
  * @NFT_META_BRI_IIFNAME: packet input bridge interface name
  * @NFT_META_BRI_OIFNAME: packet output bridge interface name
+ * @@NFT_META_PKTTYPE: packet class
  */
 enum nft_meta_keys {
 	NFT_META_LEN,
@@ -556,6 +557,7 @@ enum nft_meta_keys {
 	NFT_META_L4PROTO,
 	NFT_META_BRI_IIFNAME,
 	NFT_META_BRI_OIFNAME,
+	NFT_META_PKTTYPE,
 };
 
 /**
src/meta.c +55 -0

73 lines not on this page · raw message

src/parser.y +2 -0
index 3e08e21..6da6e98 100644
@@ -324,6 +324,7 @@ static int monitor_lookup_event(const char *event)
 %token RTCLASSID		"rtclassid"
 %token IBRIPORT			"ibriport"
 %token OBRIPORT			"obriport"
+%token PKTTYPE			"pkttype"
 
 %token CT			"ct"
 %token DIRECTION		"direction"
@@ -1784,6 +1785,7 @@ meta_key_unqualified	:	MARK		{ $$ = NFT_META_MARK; }
 			|	RTCLASSID	{ $$ = NFT_META_RTCLASSID; }
 			|	IBRIPORT	{ $$ = NFT_META_BRI_IIFNAME; }
 			|       OBRIPORT	{ $$ = NFT_META_BRI_OIFNAME; }
+			|       PKTTYPE		{ $$ = NFT_META_PKTTYPE; }
 			;
 
 meta_stmt		:	META	meta_key	SET	expr
src/scanner.l +1 -0
index 73a1a3f..1d2be76 100644
@@ -406,6 +406,7 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
 "rtclassid"		{ return RTCLASSID; }
 "ibriport"		{ return IBRIPORT; }
 "obriport"		{ return OBRIPORT; }
+"pkttype"		{ return PKTTYPE; }
 
 "ct"			{ return CT; }
 "direction"		{ return DIRECTION; }
Signature · 1 line
2.0.0
#2 lore raw

Re: [PATCH] netfilter: nf_tables: add pktype support to meta expression

In reply to Ana Rey

On 12 June 2014 19:17, Ana Rey <[email protected]> wrote:
[...]

net/netfilter/nft_meta.c int nft_meta_get_init(const struct nft_ctx *ctx, · line 214

Quoted 6 lines
net/netfilter/nft_meta.c +1 -0
@@ -194,6 +210,7 @@ int nft_meta_get_init(const struct nft_ctx *ctx,
 #endif
 #ifdef CONFIG_NETWORK_SECMARK
        case NFT_META_SECMARK:
+       case NFT_META_PKTTYPE:
 #endif

Why to enclose this in the #ifdef CONFIG_NETWORK_SECMARK?

regards

Signature · 5 lines
Arturo Borrero González
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#4 lore raw

PATCH v2 1/1 expr: meta: Add pkttype support

In reply to Ana Rey

Add pkttype support in meta. The pkttype option does not set.

---
[Changes in v2:]
Fix the description of @NFT_META_PKTTYPE expression keys

 include/linux/netfilter/nf_tables.h |    2 ++
 src/expr/meta.c                     |    3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)
include/linux/netfilter/nf_tables.h +2 -0
index 801bdd1..72ad208 100644
@@ -571,6 +571,7 @@ enum nft_exthdr_attributes {
  * @NFT_META_L4PROTO: layer 4 protocol number
  * @NFT_META_BRI_IIFNAME: packet input bridge interface name
  * @NFT_META_BRI_OIFNAME: packet output bridge interface name
+ * @NFT_META_PKTTYPE: Packet type
  */
 enum nft_meta_keys {
 	NFT_META_LEN,
@@ -592,6 +593,7 @@ enum nft_meta_keys {
 	NFT_META_L4PROTO,
 	NFT_META_BRI_IIFNAME,
 	NFT_META_BRI_OIFNAME,
+	NFT_META_PKTTYPE,
 };
 
 /**
src/expr/meta.c +2 -1
index 85097b5..35ca177 100644
@@ -23,7 +23,7 @@
 #include "expr_ops.h"
 
 #ifndef NFT_META_MAX
-#define NFT_META_MAX (NFT_META_BRI_OIFNAME + 1)
+#define NFT_META_MAX (NFT_META_PKTTYPE + 1)
 #endif
 
 struct nft_expr_meta {
@@ -153,6 +153,7 @@ static const char *meta_key2str_array[NFT_META_MAX] = {
 	[NFT_META_SECMARK]	= "secmark",
 	[NFT_META_BRI_IIFNAME]	= "bri_iifname",
 	[NFT_META_BRI_OIFNAME]	= "bri_oifname",
+	[NFT_META_PKTTYPE]	= "pkttype"
 };
 
 static const char *meta_key2str(uint8_t key)
Signature · 1 line
1.7.10.4