Skip to content

Fixed NAT service and modified utils function#238

Merged
frisso merged 4 commits intopolycube-network:masterfrom
DavideAG:packetcapture_service
Nov 25, 2019
Merged

Fixed NAT service and modified utils function#238
frisso merged 4 commits intopolycube-network:masterfrom
DavideAG:packetcapture_service

Conversation

@DavideAG
Copy link
Copy Markdown
Contributor

This pull request will fix NAT service.
We need to investigate if the problem persists for future transparent services.

@DavideAG DavideAG requested a review from a team as a code owner November 20, 2019 21:26
Copy link
Copy Markdown
Contributor

@goldenrye goldenrye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/LGTM

@DavideAG DavideAG force-pushed the packetcapture_service branch from 78bf3e2 to 106430b Compare November 21, 2019 08:23
… if the problem persists for future transparent services
@DavideAG DavideAG force-pushed the packetcapture_service branch from 106430b to 77003ff Compare November 21, 2019 08:27
Comment thread src/services/pcn-nat/src/Nat_dp.c Outdated
if (data + sizeof(*eth) + sizeof(*ip) + sizeof(*tcp) > data_end)
uint8_t header_len = 4 * ip->ihl;
struct tcphdr *tcp = data + sizeof(*eth) + header_len;
if (data + sizeof(*eth) + header_len + sizeof(*tcp) > data_end)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to write this as:
if ( (tcp+ sizeof(*tcp)) > data_end)
The same for other similar lines below.

Copy link
Copy Markdown
Collaborator

@sebymiano sebymiano Nov 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely feasible, although the way it is written now is in line with the kernel code (e.g., https://github.com/torvalds/linux/blob/2027cabe6afea5d471401ec704b65ce18f958fdc/samples/bpf/parse_simple.c#L36)

However, if you decide to change it I would suggest to write it in this way:

if ( (void *)tcp + sizeof(*tcp) > data_end )

this would avoid annoying warnings on different pointer types comparisons.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, thank you for your help @sebymiano. I will do it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebymiano thanks for the comment.
I was just wondering how smart is the compiler. Since "*tcp = data + sizeof(*eth) + header_len;" was computed the line before, I was simply proposing the reuse that result instead of computing it again in the next line.
So, if the compiler is smart, this code rewriting is useless. If it is not so smart, this saves a couple of ASM instructions (and, to me, looks more clear).

@DavideAG DavideAG force-pushed the packetcapture_service branch 2 times, most recently from 29e795e to ed1b49e Compare November 24, 2019 14:20
@DavideAG DavideAG force-pushed the packetcapture_service branch from a9ab073 to 9c7e6ad Compare November 24, 2019 14:57
@frisso frisso merged commit 4bf7d94 into polycube-network:master Nov 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants