Skip to contentSkip to conversation

parser: fix parsing of ethernet protocol types

PATCH In review Pablo Neira Ayuso 2 participants 8 messages Jan 15, 2014 – Jan 16, 2014 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/3 parser: fix parsing of ethernet protocol types

This allows us to use the protocol type keyword, eg.

nft add rule ip filter output meta protocol ip6 counte

                                            ^^^
---
 src/parser.y |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
src/parser.y +29 -0
index 038282e..23662f7 100644
@@ -23,6 +23,7 @@
 #include <expression.h>
 #include <utils.h>
 #include <parser.h>
+#include <if_ether.h>
 #include <erec.h>
 
 #include "parser.h"
@@ -1418,6 +1419,13 @@ vlan_hdr_expr		:	VLAN	vlan_hdr_field
 			{
 				$$ = payload_expr_alloc(&@$, &payload_vlan, $2);
 			}
+			|	VLAN
+			{
+				uint16_t data = ETH_P_8021Q;
+				$$ = constant_expr_alloc(&@$, &ethertype_type,
+							 BYTEORDER_HOST_ENDIAN,
+							 sizeof(data) * BITS_PER_BYTE, &data);
+			}
 			;
 
 vlan_hdr_field		:	ID		{ $$ = VLANHDR_VID; }
@@ -1430,6 +1438,13 @@ arp_hdr_expr		:	ARP	arp_hdr_field
 			{
 				$$ = payload_expr_alloc(&@$, &payload_arp, $2);
 			}
+			|	ARP
+			{
+				uint16_t data = ETH_P_ARP;
+				$$ = constant_expr_alloc(&@$, &ethertype_type,
+							 BYTEORDER_HOST_ENDIAN,
+							 sizeof(data) * BITS_PER_BYTE, &data);
+			}
 			;
 
 arp_hdr_field		:	HTYPE		{ $$ = ARPHDR_HRD; }
@@ -1443,6 +1458,13 @@ ip_hdr_expr		:	IP	ip_hdr_field
 			{
 				$$ = payload_expr_alloc(&@$, &payload_ip, $2);
 			}
+			|	IP
+			{
+				uint16_t data = ETH_P_IP;
+				$$ = constant_expr_alloc(&@$, &ethertype_type,
+							 BYTEORDER_HOST_ENDIAN,
+							 sizeof(data) * BITS_PER_BYTE, &data);
+			}
 			;
 
 ip_hdr_field		:	VERSION		{ $$ = IPHDR_VERSION; }
@@ -1484,6 +1506,13 @@ ip6_hdr_expr		:	IP6	ip6_hdr_field
 			{
 				$$ = payload_expr_alloc(&@$, &payload_ip6, $2);
 			}
+			|	IP6
+			{
+				uint16_t data = ETH_P_IPV6;
+				$$ = constant_expr_alloc(&@$, &ethertype_type,
+							 BYTEORDER_HOST_ENDIAN,
+							 sizeof(data) * BITS_PER_BYTE, &data);
+			}
 			;
 
 ip6_hdr_field		:	VERSION		{ $$ = IP6HDR_VERSION; }
Signature · 1 line
1.7.10.4
author maintainer
#1 lore raw

PATCH 2/3 payload: fix crash when wrong ethernet protocol type is used

nft add rule ip filter output meta protocol xyz counter

                                            ^^^

This fix is similar to 4097ad7 ("meta: fix crash when parsing unresolvable mark values").

---
 src/payload.c |    1 +
 1 file changed, 1 insertion(+)
src/payload.c +1 -0
index 86d75fa..decfcd6 100644
@@ -993,6 +993,7 @@ static struct error_record *ethertype_parse(const struct expr *sym,
 {
 	struct error_record *erec;
 
+	*res = NULL;
 	erec = sym->dtype->basetype->parse(sym, res);
 	if (erec != NULL)
 		return erec;
Signature · 1 line
1.7.10.4
author maintainer
#3 lore raw

PATCH 3/3 payload: fix inconsistency in ethertype output

In reply to Pablo Neira Ayuso

Use ip6 instead of ipv6.

---
 src/payload.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/payload.c +1 -1
index decfcd6..bfd8ba4 100644
@@ -982,7 +982,7 @@ static const struct symbol_table ethertype_tbl = {
 	.symbols	= {
 		SYMBOL("ip",		ETH_P_IP),
 		SYMBOL("arp",		ETH_P_ARP),
-		SYMBOL("ipv6",		ETH_P_IPV6),
+		SYMBOL("ip6",		ETH_P_IPV6),
 		SYMBOL("vlan",		ETH_P_8021Q),
 		SYMBOL_LIST_END
 	},
Signature · 1 line
1.7.10.4
#5 lore raw
In reply to Pablo Neira Ayuso
Quoted 4 lines · Pablo Neira Ayuso

This allows us to use the protocol type keyword, eg.

nft add rule ip filter output meta protocol ip6 counte

                                            ^^^

I see two problems with this patch:

- the mapping to ETH_P_* is fixed. In case of f.i. meta nfproto relational expression it would have to map to NFPROTO_* values. So I think we should use symbolic expressions instead of constants and leave parsing to the evaluation phase-

- we're still using a mix of ip6 and ipv6. Lets also fix that, ideally as a patch before this one.

I can take care of this if you like.

Quoted 80 lines
---
 src/parser.y |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
src/parser.y +29 -0
index 038282e..23662f7 100644
@@ -23,6 +23,7 @@
 #include <expression.h>
 #include <utils.h>
 #include <parser.h>
+#include <if_ether.h>
 #include <erec.h>
 
 #include "parser.h"
@@ -1418,6 +1419,13 @@ vlan_hdr_expr		:	VLAN	vlan_hdr_field
 			{
 				$$ = payload_expr_alloc(&@$, &payload_vlan, $2);
 			}
+			|	VLAN
+			{
+				uint16_t data = ETH_P_8021Q;
+				$$ = constant_expr_alloc(&@$, &ethertype_type,
+							 BYTEORDER_HOST_ENDIAN,
+							 sizeof(data) * BITS_PER_BYTE, &data);
+			}
 			;
 
 vlan_hdr_field		:	ID		{ $$ = VLANHDR_VID; }
@@ -1430,6 +1438,13 @@ arp_hdr_expr		:	ARP	arp_hdr_field
 			{
 				$$ = payload_expr_alloc(&@$, &payload_arp, $2);
 			}
+			|	ARP
+			{
+				uint16_t data = ETH_P_ARP;
+				$$ = constant_expr_alloc(&@$, &ethertype_type,
+							 BYTEORDER_HOST_ENDIAN,
+							 sizeof(data) * BITS_PER_BYTE, &data);
+			}
 			;
 
 arp_hdr_field		:	HTYPE		{ $$ = ARPHDR_HRD; }
@@ -1443,6 +1458,13 @@ ip_hdr_expr		:	IP	ip_hdr_field
 			{
 				$$ = payload_expr_alloc(&@$, &payload_ip, $2);
 			}
+			|	IP
+			{
+				uint16_t data = ETH_P_IP;
+				$$ = constant_expr_alloc(&@$, &ethertype_type,
+							 BYTEORDER_HOST_ENDIAN,
+							 sizeof(data) * BITS_PER_BYTE, &data);
+			}
 			;
 
 ip_hdr_field		:	VERSION		{ $$ = IPHDR_VERSION; }
@@ -1484,6 +1506,13 @@ ip6_hdr_expr		:	IP6	ip6_hdr_field
 			{
 				$$ = payload_expr_alloc(&@$, &payload_ip6, $2);
 			}
+			|	IP6
+			{
+				uint16_t data = ETH_P_IPV6;
+				$$ = constant_expr_alloc(&@$, &ethertype_type,
+							 BYTEORDER_HOST_ENDIAN,
+							 sizeof(data) * BITS_PER_BYTE, &data);
+			}
 			;
 
 ip6_hdr_field		:	VERSION		{ $$ = IP6HDR_VERSION; }
Signature · 6 lines
1.7.10.4

--
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
#2 lore raw

Re: [PATCH nft 2/3] payload: fix crash when wrong ethernet protocol type is used

In reply to Pablo Neira Ayuso
Quoted 5 lines · Pablo Neira Ayuso

nft add rule ip filter output meta protocol xyz counter

                                            ^^^

This fix is similar to 4097ad7 ("meta: fix crash when parsing unresolvable mark values").

I already fixed that for mark_type, but didn't realize we have more instances of this. I double checked and we should be good now.

Quoted 24 lines
---
 src/payload.c |    1 +
 1 file changed, 1 insertion(+)
src/payload.c +1 -0
index 86d75fa..decfcd6 100644
@@ -993,6 +993,7 @@ static struct error_record *ethertype_parse(const struct expr *sym,
 {
 	struct error_record *erec;
 
+	*res = NULL;
 	erec = sym->dtype->basetype->parse(sym, res);
 	if (erec != NULL)
 		return erec;
Signature · 6 lines
1.7.10.4

--
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
#4 lore raw

Re: [PATCH nft 3/3] payload: fix inconsistency in ethertype output

In reply to Pablo Neira Ayuso
Quoted 1 line · Pablo Neira Ayuso

Use ip6 instead of ipv6.

Sorry, didn't see this before. That leaves just the first problem for patch 1/3.

Quoted 20 lines
---
 src/payload.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/payload.c +1 -1
index decfcd6..bfd8ba4 100644
@@ -982,7 +982,7 @@ static const struct symbol_table ethertype_tbl = {
 	.symbols	= {
 		SYMBOL("ip",		ETH_P_IP),
 		SYMBOL("arp",		ETH_P_ARP),
-		SYMBOL("ipv6",		ETH_P_IPV6),
+		SYMBOL("ip6",		ETH_P_IPV6),
 		SYMBOL("vlan",		ETH_P_8021Q),
 		SYMBOL_LIST_END
 	},
Signature · 1 line
1.7.10.4
author maintainer
#6 lore raw
In reply to Patrick McHardy
Quoted 6 lines · Patrick McHardy
Quoted 4 lines · Pablo Neira Ayuso

This allows us to use the protocol type keyword, eg.

nft add rule ip filter output meta protocol ip6 counte

                                            ^^^
Quoted 6 lines

I see two problems with this patch:

- the mapping to ETH_P_* is fixed. In case of f.i. meta nfproto relational expression it would have to map to NFPROTO_* values. So I think we should use symbolic expressions instead of constants and leave parsing to the evaluation phase-

Yes, that change needs to be done in next-3.14 to get it working with your new inet table. I was focusing to fix this in master for the upcoming release.

Quoted 4 lines

- we're still using a mix of ip6 and ipv6. Lets also fix that, ideally as a patch before this one.

I can take care of this if you like.

Please, go ahead, I'm looking at more pending stuff I want to provide feedback on.

#7 lore raw
Quoted 18 lines · Pablo Neira Ayuso
Quoted 6 lines · Patrick McHardy
Quoted 4 lines · Pablo Neira Ayuso

This allows us to use the protocol type keyword, eg.

nft add rule ip filter output meta protocol ip6 counte

                                            ^^^
Quoted 6 lines

I see two problems with this patch:

- the mapping to ETH_P_* is fixed. In case of f.i. meta nfproto relational expression it would have to map to NFPROTO_* values. So I think we should use symbolic expressions instead of constants and leave parsing to the evaluation phase-

Yes, that change needs to be done in next-3.14 to get it working with your new inet table. I was focusing to fix this in master for the upcoming release.

Quoted 7 lines
Quoted 4 lines

- we're still using a mix of ip6 and ipv6. Lets also fix that, ideally as a patch before this one.

I can take care of this if you like.

Please, go ahead, I'm looking at more pending stuff I want to provide feedback on.

Already done :) I'm simply going to take your entire patchset and integrate it with my change since they kind of depend on each other.