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

prog, sys: add tcp packets descriptions #122

Merged
merged 1 commit into from
Jan 30, 2017
Merged

Conversation

xairy
Copy link
Collaborator

@xairy xairy commented Jan 30, 2017

Also embed tcp checksums into packets.

var csum IPChecksum
csum.Update(encodeArg(srcAddr, pid))
csum.Update(encodeArg(dstAddr, pid))
csum.Update(append([]byte{0}, encodeArg(protocol, pid)...))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you do append([]byte{0}, ...?
it is used to make a copy of a slice, but the slice returned by encodeArg is already not aliased with anything else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I want to make an array of two bytes, the first one is 0 and the second one is the protocol id (the protocol field encodes into 1 byte).
Is there a way to do this better?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, OK, I missed the {0} part.
Simple/faster way may be:

[]byte{0, byte(protocol.Value(pid))}

}

func calcChecksumIPv4(arg *Arg, pid int) (*Arg, *Arg) {
csumField := findFieldByName(arg, "csum")
if csumField == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would move the nil check and panic into findFieldByName itself, because it is duplicated multiple times.
It is also possible to type/size checks into findFieldByName. If some of the checks are optional, then you can use 0/nil as 'don't check'.

Also embed tcp checksums into packets.
@xairy xairy merged commit 8987a85 into google:master Jan 30, 2017
@xairy xairy deleted the tcp-checksums branch January 30, 2017 20:03
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.

2 participants