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

Default protocol type for listen addr tcp/0.0.0.0:x is tcp6 #47

Closed
ghthor opened this issue Feb 25, 2022 · 5 comments
Closed

Default protocol type for listen addr tcp/0.0.0.0:x is tcp6 #47

ghthor opened this issue Feb 25, 2022 · 5 comments

Comments

@ghthor
Copy link

ghthor commented Feb 25, 2022

I've recently started using layer4 to perform some tcp proxying for ingress to some services. Currently our edge is accepting traffic with ipv4 addresses. My caddy file looks like the following.

{
  "apps": {
    "layer4": {
      "servers": {
        "tcp": {
          "listen": ["tcp/0.0.0.0:1010"],
          "routes": [{
            "handle": [{
              "handler": "proxy",
              "proxy_protocol": "",
              "upstreams": [
                {"dial": ["tcp/${cluster_internal_ip}:1010"]}
              ]
            }]
          }]
        }
      }
    }
  }
}

You'll notice that my listener network addr is default tcp and provides the ipv4 catchall addr 0.0.0.0. This configuration would lead me to believe that the socker should open on tcp 0.0.0.0:1010 but what I've found is that it's opening on tcp6 :::1010.

~$ sudo netstat -plunt | grep 1010
tcp6       0      0 :::1010                 :::*                    LISTEN      13739/caddy-l4      

I'm noticing the same behavior on Ubuntu 16.04.4 LTS and Ubuntu 18.04.5 LTS. I have not checked on Ubuntu 20.*.

host1~$ uname -r -v && lsb_release -a 2>/dev/null | grep Desc
5.4.0-1038-aws #40~18.04.1-Ubuntu SMP Sat Feb 6 01:56:56 UTC 2021
Description:	Ubuntu 18.04.5 LTS
host2~$ uname -r -v && lsb_release -a 2>/dev/null | grep Desc
4.4.0-1128-aws #142-Ubuntu SMP Fri Apr 16 12:42:33 UTC 2021
Description:	Ubuntu 16.04.4 LTS

I'm running caddy with layer4 as a docker container using --network-mode=host from this docker container I've created

@francislavoie
Copy link
Collaborator

You can use tcp4/ to explicitly bind for IPv4 only, but tcp/ will attempt to bind for both. These network types are defined by the Go stdlib: https://pkg.go.dev/net#Dial

@mholt
Copy link
Owner

mholt commented Feb 25, 2022

I believe that behavior is set by the kernel if a tcp/ip version is unspecified and the address is ambiguous. (So I'm not particularly surprised in this case.)

@ghthor
Copy link
Author

ghthor commented Feb 25, 2022

Ok, that all makes sense. I'm going to perform some tests to clarify that even when netstat is reporting tcp6 :::1010 that caddy is still receiving ipv4 packets sent to the same port.

@ghthor
Copy link
Author

ghthor commented Feb 26, 2022

Alright, I tested this and its accepting tcp4 traffic even when it netstat only lists it as tcp6. Guess this is a non issue, thanks for helping me settle this concern!

@ghthor ghthor closed this as completed Feb 26, 2022
@RussellLuo
Copy link
Collaborator

There happens to be an issue here golang/go#48723, which I think may be useful :)

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

No branches or pull requests

4 participants