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

Feature Request: Force IPv4 or IPv6 flag #6

Closed
andersmarkendahl opened this issue May 19, 2020 · 4 comments
Closed

Feature Request: Force IPv4 or IPv6 flag #6

andersmarkendahl opened this issue May 19, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@andersmarkendahl
Copy link

What is missing?

For testing purposes when using the kahttp client it would be helpful with a flag that can force the client to connect over specific IPfamily only. This so that a host that should be reachable over both IPfamilies can be tested properly.

Suggestion

Similar flags exist in curl and wget

man wget
[...]
       -4
       --inet4-only
       -6
       --inet6-only
           Force connecting to IPv4 or IPv6 addresses.  With --inet4-only or
           -4, Wget will only connect to IPv4 hosts, ignoring AAAA records in
           DNS, and refusing to connect to IPv6 addresses specified in URLs.
           Conversely, with --inet6-only or -6, Wget will only connect to IPv6
           hosts and ignore A records and IPv4 addresses....
@uablrek uablrek self-assigned this May 19, 2020
@uablrek uablrek added the enhancement New feature or request label May 19, 2020
@uablrek
Copy link
Contributor

uablrek commented May 19, 2020

Work-around

Set the -srccidr parameter to the address for the outgoing interface using the desired family;

$ ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:00:00:01:01:03  
          inet addr:192.168.1.3  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::200:ff:fe01:103/64 Scope:Link
          inet6 addr: 1000::1:c0a8:103/120 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2257 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2268 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:181094 (176.8 KiB)  TX bytes:202952 (198.1 KiB)
$ kahttp kahttp -address http://vm-001/cgi-bin/info -monitor -timeout 5s -srccidr 192.168.1.3/32
... (ipv4 used)
$ kahttp kahttp -address http://vm-001/cgi-bin/info -monitor -timeout 5s -srccidr 1000::1:c0a8:103/128
... (ipv6 used)

Note that masks must be /32 and /128.

@uablrek
Copy link
Contributor

uablrek commented May 19, 2020

It is not so easy (anymore) to enforce ipv6/ipv4 in go. They are using "Happy Eyeballs" which means; try ipv6 first, Fast Fallback to ipv4 if it doesn't work. See; https://godoc.org/net#Dialer

I am sure it can be done in some way but if the work-around above is enough I will let this issue rest for some time.

@andersmarkendahl
Copy link
Author

An update on this issue. We are actively using the proposed WA (srccidr flag) since a few weeks back and it seems to work fine for our purposes.
Example:

is_v6() {
  test "${1#*":"}" != "$1" && return 0
  return 1
}
get_src() {
  ip=$1
  if $(is_v6 $ip);then
    src=$(ip -6 route get $ip | grep -Eo 'src \S+' | cut -d' ' -f2)
    src="$src/128"
  else
    src=$(ip route get $ip | grep -Eo 'src \S+' | cut -d' ' -f2)
    src="$src/32"
  fi
  echo $src
}
kahttp ... -srccidr $(get_src 1000::1)
kahttp ... -srccidr $(get_src 10.0.0.1)

If this is too tricky to improve, then you can close this issue.
If you plan to improve later you can keep open.

@uablrek
Copy link
Contributor

uablrek commented Nov 27, 2020

I document the -srccidr and close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants