Simplify and move the test of nonip filter.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/fltselect.c | 2 +-
src/packet.c | 25 +++++--------------------
2 files changed, 6 insertions(+), 21 deletions(-)
diff --git a/src/fltselect.c b/src/fltselect.c
index 65ae37a..e42755d 100644
--- a/src/fltselect.c
+++ b/src/fltselect.c
@@ -116,7 +116,7 @@ int nonipfilter(struct filterstate *filter, unsigned int protocol)
case ETH_P_RARP:
result = filter->rarp;
break;
- case 0:
+ default:
result = filter->nonip;
break;
}
diff --git a/src/packet.c b/src/packet.c
index 520da55..611a67f 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -230,27 +230,7 @@ int processpacket(char *tpacket, char **packet, unsigned int *br,
if (*packet == NULL)
return INVALID_PACKET;
- /*
- * Apply non-IP packet filter
- */
-
- if ((fromaddr->sll_protocol != ETH_P_IP)
- && (fromaddr->sll_protocol != ETH_P_IPV6)) {
- if ((fromaddr->sll_protocol == ETH_P_ARP)
- || (fromaddr->sll_protocol == ETH_P_RARP)) {
- if (!nonipfilter(filter, fromaddr->sll_protocol)) {
- return PACKET_FILTERED;
- }
- } else {
- if (!nonipfilter(filter, 0)) {
- return PACKET_FILTERED;
- }
- }
- return PACKET_OK;
- }
-
if (fromaddr->sll_protocol == ETH_P_IP) {
-
/*
* At this point, we're now processing IP packets. Start by getting
* IP header and length.
@@ -373,6 +353,11 @@ int processpacket(char *tpacket, char **packet, unsigned int *br,
*dport = 0;
break;
}
+ } else {
+ /* not IPv4 and not IPv6: apply non-IP packet filter */
+ if (!nonipfilter(filter, fromaddr->sll_protocol)) {
+ return PACKET_FILTERED;
+ }
}
return PACKET_OK;
}
--
1.7.8.4