Skip to content

Use gateway specified on command line "docker network create"#5

Open
vladwing wants to merge 2 commits into
leomos:mainfrom
vladwing:main
Open

Use gateway specified on command line "docker network create"#5
vladwing wants to merge 2 commits into
leomos:mainfrom
vladwing:main

Conversation

@vladwing

@vladwing vladwing commented Oct 24, 2024

Copy link
Copy Markdown

Currently dwgd doesn't set a default route and when it does set it using dwgd.route option, docker gets confused. Allow setting a default route using docker network create ... --gateway <IP>.

Copying from Issue #4, for context

The problem with the current implementation is that the routes are added as static routes, but docker doesn't understand it is 
dealing with a default route. Because of that, if you add another network to a container - for example a bridge, docker will see 
that the dwgd network doesn't provide a default route and will create a default route via the other network. You'll get an 
annoying message saying the container wasn't able to be created because 0.0.0.0/0 already exists. Currently dwgd doesn't use 
the gateway parameter, even though it is specified in the documentation as the way to create the network.

@leomos leomos left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Two general points:

  1. can you modify the entities_test and driver_test to take into account your changes? It should be as easy as adding a gateway: <whatever structure we settle on> here:

    ifname: "dwgd0",
    and something like IPv4Data: []*network.IPAMData{{ Gateway: fmt.Sprintf(<whatever logic to represent the value we settled on>), }}, here:
    },

  2. is it possible to provide an integration test that highlights what wasn't working before and works now? You said

    Because of that, if you add another network to a container - for example a bridge, docker will see that the dwgd network doesn't provide a default route and will create a default route via the other network.

    Maybe a copy-paste of this one with more than one network would be enough?

And of course thanks a lot for sending this!!!

Comment thread driver.go
if len(r.IPv4Data) > 0 {
TraceLog.Printf("ParseCIDR: %+v\n", r.IPv4Data[0].Gateway)
gateway, _, err := net.ParseCIDR(r.IPv4Data[0].Gateway)
if err == nil && gateway != nil {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

both here and on the IPv6 handling below I would fail if there is an error and return the error, to keep consistency on how it is done in the function.

Comment thread entities.go
@vladwing

Copy link
Copy Markdown
Author

Give me a bit of time to update the PR with the requested changes.

Comment thread entities.go
route string
ifname string
id string
endpoint *net.UDPAddr

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@leomos I would like to update this to a string in a future PR. Thoughts?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

it's a good idea to keep consistency with what we agreed over the gateway{_v6} fields.
If you can change it in this PR it's great, otherwise no problem in doing that later.

@vladwing vladwing Nov 4, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

What I have in mind is a slightly bigger change. Right now the daemon saves an IP address, which is not even the IP address at the moment of the tunnel creation. I think this should be an FQDN which is resolved at tunnel creation. It will still not solve all the problems the wg-quick solves, but it's a step in that direction and we can iterate over it. We can start by changing the endpoint to a string in this patch and continue with the complicated stuff in a later PR.

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