Skip to content

Commit 0700af6

Browse files
committed
Fix the TCP/UDP packet offset (ihl is number of 32 bits).
1 parent b7e0865 commit 0700af6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/netxduo/packet_filter_glue.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333
#include <wolfsentry/wolfsentry_netxduo.h>
3434
#include <string.h>
3535

36-
/* Network byte order conversion functions */
37-
#ifndef ntohs
38-
#define ntohs(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
39-
#endif
40-
#ifndef ntohl
41-
#define ntohl(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24))
42-
#endif
4336

4437
/* Constants for address conversion */
4538
#define MAX_UINT32_DECIMAL_LEN 12 /* Max for 32-bit: 4294967295 (10 digits) + null + extra */
@@ -666,7 +659,8 @@ static int parse_ip_packet(unsigned char *packet_data, unsigned long data_length
666659
struct netx_udp_header *udp;
667660
unsigned long ip_addr;
668661

669-
if (!packet_data || !local_addr || !remote_addr || !local_port || !remote_port || !protocol) {
662+
if (!packet_data || !local_addr || !remote_addr || !local_port ||
663+
!remote_port || !protocol) {
670664
return -1;
671665
}
672666

@@ -720,7 +714,7 @@ static int parse_ip_packet(unsigned char *packet_data, unsigned long data_length
720714

721715
/* Extract port numbers for TCP and UDP */
722716
if (*protocol == IPPROTO_TCP || *protocol == IPPROTO_UDP) {
723-
unsigned int ip_header_len = ip->ihl;
717+
unsigned int ip_header_len = ip->ihl * 4; /* number of 32-bits */
724718

725719
if (data_length < ip_header_len + sizeof(struct netx_tcp_header)) {
726720
return -1;
@@ -832,7 +826,9 @@ int wolfsentry_netx_ip_packet_filter(struct wolfsentry_context* ctx, unsigned ch
832826
}
833827

834828
/* Set route flags for inbound packet */
835-
route_flags = WOLFSENTRY_ROUTE_FLAG_DIRECTION_IN;
829+
route_flags = WOLFSENTRY_ROUTE_FLAG_DIRECTION_IN |
830+
WOLFSENTRY_ROUTE_FLAG_SA_REMOTE_ADDR_WILDCARD |
831+
WOLFSENTRY_ROUTE_FLAG_SA_REMOTE_PORT_WILDCARD;
836832

837833
/* Initialize action results */
838834
action_results = WOLFSENTRY_ACTION_RES_NONE;

0 commit comments

Comments
 (0)