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

darwin nat implementation #298

Merged
merged 3 commits into from Jul 23, 2018

Conversation

Projects
None yet
3 participants
@zolia
Copy link
Member

commented Jul 16, 2018

Client still has to be on different machine.
This is due to 10.8.0.0/24 subnet clash. That is server wants to tunnel it through utun1, but client would need to tunnel it through utun2, but cannot do it since route already exists.

@zolia zolia requested review from tadovas and donce Jul 16, 2018

@zolia zolia requested a review from Waldz as a code owner Jul 16, 2018

@zolia zolia force-pushed the feature/MYST-641-darwin-nat-support branch 2 times, most recently from 9af81a0 to 91e79b9 Jul 16, 2018

}

func (service *servicePFCtl) disableRules() {
arguments := fmt.Sprintf("/sbin/pfctl -a nat-anchor:myst -F nat")

This comment has been minimized.

Copy link
@Waldz

Waldz Jul 17, 2018

Member

No arguments, do You really need to format it?

return err
}
natRule := fmt.Sprintf("nat on %v inet from %v to any -> %v", iface, rule.SourceAddress, rule.TargetIP)
arguments := fmt.Sprintf("echo \"%v\" | /sbin/pfctl -vEf -", natRule)

This comment has been minimized.

Copy link
@Waldz

Waldz Jul 17, 2018

Member

Use qoute ` to avoid \" escaping

This comment has been minimized.

Copy link
@Waldz

Waldz Jul 17, 2018

Member

Could could be just /sbin/pfctl -vE -f %s?

This comment has been minimized.

Copy link
@zolia

zolia Jul 17, 2018

Author Member

no, its input from stdin (-)

}

func (service *servicePFCtl) disableRules() {
arguments := fmt.Sprintf("/sbin/pfctl -F nat")

This comment has been minimized.

Copy link
@Waldz

Waldz Jul 17, 2018

Member

Sprintf is redundant, because there aren't variables

cmd := exec.Command(
"sh",
"-c",
arguments,

This comment has been minimized.

Copy link
@Waldz

Waldz Jul 17, 2018

Member

Looks like sub-command quoting is missing, is not it?

}
}
}
return "undefined", nil

This comment has been minimized.

Copy link
@Waldz

Waldz Jul 17, 2018

Member

Is not it error?

return
}

cmd := utils.SplitCommand("/usr/sbin/sysctl", "-w net.inet.ip.forwarding=0")

This comment has been minimized.

Copy link
@Waldz

Waldz Jul 17, 2018

Member

Looks like duplicated code, could be DRY'ied

This comment has been minimized.

Copy link
@zolia

zolia Jul 17, 2018

Author Member

its not, different path of command and different arguments.

if output, err := cmd.CombinedOutput(); err != nil {
if !strings.Contains(string(output), natRule) {
log.Warn("Failed to create pfctl rule: ", cmd.Args, " Returned exit error: ", err.Error(), " Cmd output: ", string(output))
log.Flush()

This comment has been minimized.

Copy link
@Waldz

Waldz Jul 17, 2018

Member

What is so special about your logs, that you flush it?

This comment has been minimized.

Copy link
@tadovas

tadovas Jul 18, 2018

Member

There is no need to flush logs on every step. Flushing is done on main package just before program exiting

@zolia zolia force-pushed the feature/MYST-641-darwin-nat-support branch 2 times, most recently from 960725f to 2aa9e30 Jul 18, 2018

@zolia zolia requested a review from Waldz Jul 18, 2018

@Waldz Waldz force-pushed the feature/MYST-641-darwin-nat-support branch from 2aa9e30 to 3148ca4 Jul 23, 2018

@zolia zolia force-pushed the feature/MYST-641-darwin-nat-support branch from 3148ca4 to 2aa9e30 Jul 23, 2018

@Waldz Waldz force-pushed the feature/MYST-641-darwin-nat-support branch from 2aa9e30 to db5642e Jul 23, 2018

Waldz added some commits Jul 23, 2018

DRY IP forwarding code
Signed-off-by: Waldz <valdas@mysterium.network>

@Waldz Waldz force-pushed the feature/MYST-641-darwin-nat-support branch from db5642e to f51efd0 Jul 23, 2018

@tadovas
Copy link
Member

left a comment

LGTM

@Waldz

Waldz approved these changes Jul 23, 2018

@zolia zolia merged commit 786c78f into master Jul 23, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@zolia zolia deleted the feature/MYST-641-darwin-nat-support branch Jul 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.