Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alignment Problem on ARM #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/openvpn/clinat.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ client_nat_transform(const struct client_nat_option_list *list,
struct ip_tcp_udp_hdr *h = (struct ip_tcp_udp_hdr *) BPTR(ipbuf);
int i;
uint32_t addr, *addr_ptr;
const uint32_t *from, *to;
uint32_t from, to;
int accumulate = 0;
unsigned int amask;
unsigned int alog = 0;
Expand All @@ -215,38 +215,40 @@ client_nat_transform(const struct client_nat_option_list *list,
const struct client_nat_entry *e = &list->entries[i]; /* current NAT rule */
if (e->type ^ direction)
{
addr = *(addr_ptr = &h->ip.daddr);
addr_ptr = &h->ip.daddr;
memcpy( &addr, addr_ptr, sizeof( addr )); ;
amask = 2;
}
else
{
addr = *(addr_ptr = &h->ip.saddr);
addr_ptr = &h->ip.saddr;
memcpy( &addr, addr_ptr, sizeof( addr )); ;
amask = 1;
}
if (direction)
{
from = &e->foreign_network;
to = &e->network;
from = e->foreign_network;
to = e->network;
}
else
{
from = &e->network;
to = &e->foreign_network;
from = e->network;
to = e->foreign_network;
}

if (((addr & e->netmask) == *from) && !(amask & alog))
if (((addr & e->netmask) == from) && !(amask & alog))
{
/* pre-adjust IP checksum */
ADD_CHECKSUM_32(accumulate, addr);

/* do NAT transform */
addr = (addr & ~e->netmask) | *to;
addr = (addr & ~e->netmask) | to;

/* post-adjust IP checksum */
SUB_CHECKSUM_32(accumulate, addr);

/* write the modified address to packet */
*addr_ptr = addr;
memcpy( addr_ptr, &addr , sizeof( addr ));

/* mark as modified */
alog |= amask;
Expand Down