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

Set outbound interface, like ping -I option #32

Closed

Conversation

ilolicon
Copy link

Hello,

I attempted to implement a useful feature - sending data packets from a specific network interface, similar to what the "ping" command's "-I" option does in Linux.
Hoping I did it correctly. Test successfully passed on Linux OS.

Thanks!

The issues related to this feature:

go-ping/ping#111

go-ping/ping#204

@ilolicon ilolicon changed the title Set outbound interface name, like ping -I option Set outbound interface, like ping -I option Apr 12, 2023
@SuperQ
Copy link
Contributor

SuperQ commented Apr 12, 2023

This needs a DCO sign-off. You can use git commit -s --amend to add it.

ping.go Outdated
Comment on lines 185 to 186
// Iface used to send/recv ICMP messages
Iface string
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the short name

Suggested change
// Iface used to send/recv ICMP messages
Iface string
// Interface used to send/recv ICMP messages
Interface string

Copy link
Author

Choose a reason for hiding this comment

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

The original intention was just to avoid confusion with the go interface keyword

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe InterfaceName then if needed?

Copy link
Author

@ilolicon ilolicon Apr 12, 2023

Choose a reason for hiding this comment

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

I adopted Interface to make a new commit but the ci test still fails
I use the same ci docker image locally and it works fine. Am I doing something wrong?
I hope you can give me some help, thank you very much

circleci@3b386f984da0:~/project/pro-bing$ git branch -vv
* feature-interface-binding 60b7449 [origin/feature-interface-binding] Refactoring the variable name `Iface` to `Interface` and `ifaceIndex` to `ifIndex`(keeping it consistent with `ControlMessage`)
  main                      a17ba03 [origin/main] Merge pull request #29 from TheRushingWookie/add_context
circleci@3b386f984da0:~/project/pro-bing$ make style vet test
>> checking code style
>> vetting code
GO111MODULE= go vet  ./...
>> running all tests
GO111MODULE= go test -race -cover  ./...
ok  	github.com/prometheus-community/pro-bing	(cached)	coverage: 76.9% of statements
?   	github.com/prometheus-community/pro-bing/cmd/ping	[no test files]

ci error message: socket: permission denied

Signed-off-by: ilolicon <[email protected]>
… to `ifIndex`(keeping it consistent with `ControlMessage`)

Signed-off-by: ilolicon <[email protected]>
@ilolicon ilolicon force-pushed the feature-interface-binding branch from 8dffa7b to 60b7449 Compare April 12, 2023 08:29
@ilolicon ilolicon requested a review from Hipska April 15, 2023 07:55
@@ -29,6 +29,9 @@ Examples:
# ping google for 10 seconds
ping -t 10s www.google.com

# ping google specified interface
ping -I eth1 www.goole.com
Copy link

Choose a reason for hiding this comment

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

there is a typo here: goo[g]le.com

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ping -I eth1 www.goole.com
ping -I eth1 www.google.com

@bluecmd
Copy link

bluecmd commented Nov 10, 2023

FWIW, I would like to see this feature added in order to use VRF with this library.

@HsimWong
Copy link

I need this feature really bad. Can anyone merge this?

@bluecmd
Copy link

bluecmd commented Jul 19, 2024

The PR needs to be rebased if it is to have any chance of getting merged.

@dan-sherwin
Copy link

Checking on this PR? I could use it. Is it dead?

@liuweiky
Copy link

Hi, any updates on this PR? It is quite useful when debugging the network on hosts with multiple net interfaces.

@MatthieuCoder
Copy link
Contributor

I need this to use link-local IPv6 addresses

@Hipska
Copy link
Contributor

Hipska commented Oct 29, 2024

At least the PR has conflicts, @ilolicon can you resolve them?

@SuperQ
Copy link
Contributor

SuperQ commented Oct 29, 2024

If someone would like to fork this code and submit a new PR, feel free.

MatthieuCoder added a commit to MatthieuCoder/pro-bing that referenced this pull request Oct 29, 2024
This allows using `pro-bing` to use VRFs interfaces and IPv6 link-local addresses.
Originally from @ilolicon in prometheus-community#32.

commit 16f9286
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 15:46:13 2024 +0400

    Remove the un-used function in te `packetConn` interface that did not get removed during the merging process

commit 88bb1f5
Author: ilolicon <[email protected]>
Date:   Wed Apr 12 16:23:06 2023 +0800

    Refactoring the variable name `Iface` to `Interface` and `ifaceIndex` to `ifIndex`(keeping it consistent with `ControlMessage`)

    Signed-off-by: ilolicon <[email protected]>

commit 887b4e2
Author: ilolicon <[email protected]>
Date:   Wed Apr 12 10:39:36 2023 +0800

    feat: interface binding

    Signed-off-by: ilolicon <[email protected]>
MatthieuCoder added a commit to MatthieuCoder/pro-bing that referenced this pull request Oct 29, 2024
This allows using `pro-bing` to use VRFs interfaces and IPv6 link-local addresses.
Originally from @ilolicon in prometheus-community#32.

commit 16f9286
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 15:46:13 2024 +0400

    Remove the un-used function in te `packetConn` interface that did not get removed during the merging process

commit 88bb1f5
Author: ilolicon <[email protected]>
Date:   Wed Apr 12 16:23:06 2023 +0800

    Refactoring the variable name `Iface` to `Interface` and `ifaceIndex` to `ifIndex`(keeping it consistent with `ControlMessage`)

    Signed-off-by: ilolicon <[email protected]>

commit 887b4e2
Author: ilolicon <[email protected]>
Date:   Wed Apr 12 10:39:36 2023 +0800

    feat: interface binding

    Signed-off-by: ilolicon <[email protected]>

Signed-off-by: Matthieu Pignolet <[email protected]>
MatthieuCoder added a commit to MatthieuCoder/pro-bing that referenced this pull request Oct 29, 2024
…al addresses.

Squashed commit of the following:

commit 7385672
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 16:11:33 2024 +0400

    Renaming the `Interface` Pinger property to `InterfaceDevice` to avoid conflict with the `interface` keyword.

    Signed-off-by: Matthieu Pignolet <[email protected]>

commit 978c60e
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 15:59:36 2024 +0400

    Add the `Interface` option to `Pinger`

    This allows using `pro-bing` to use VRFs interfaces and IPv6 link-local addresses.
    Originally from @ilolicon in prometheus-community#32.

    commit 16f9286
    Author: Matthieu Pignolet <[email protected]>
    Date:   Tue Oct 29 15:46:13 2024 +0400

        Remove the un-used function in te `packetConn` interface that did not get removed during the merging process

    commit 88bb1f5
    Author: ilolicon <[email protected]>
    Date:   Wed Apr 12 16:23:06 2023 +0800

        Refactoring the variable name `Iface` to `Interface` and `ifaceIndex` to `ifIndex`(keeping it consistent with `ControlMessage`)

        Signed-off-by: ilolicon <[email protected]>

    commit 887b4e2
    Author: ilolicon <[email protected]>
    Date:   Wed Apr 12 10:39:36 2023 +0800

        feat: interface binding

        Signed-off-by: ilolicon <[email protected]>

    Signed-off-by: Matthieu Pignolet <[email protected]>
MatthieuCoder added a commit to MatthieuCoder/pro-bing that referenced this pull request Oct 29, 2024
…al addresses.

Squashed commit of the following:

commit 7385672
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 16:11:33 2024 +0400

    Renaming the `Interface` Pinger property to `InterfaceDevice` to avoid conflict with the `interface` keyword.

    Signed-off-by: Matthieu Pignolet <[email protected]>

commit 978c60e
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 15:59:36 2024 +0400

    Add the `Interface` option to `Pinger`

    This allows using `pro-bing` to use VRFs interfaces and IPv6 link-local addresses.
    Originally from @ilolicon in prometheus-community#32.

    commit 16f9286
    Author: Matthieu Pignolet <[email protected]>
    Date:   Tue Oct 29 15:46:13 2024 +0400

        Remove the un-used function in te `packetConn` interface that did not get removed during the merging process

    commit 88bb1f5
    Author: ilolicon <[email protected]>
    Date:   Wed Apr 12 16:23:06 2023 +0800

        Refactoring the variable name `Iface` to `Interface` and `ifaceIndex` to `ifIndex`(keeping it consistent with `ControlMessage`)

        Signed-off-by: ilolicon <[email protected]>

    commit 887b4e2
    Author: ilolicon <[email protected]>
    Date:   Wed Apr 12 10:39:36 2023 +0800

        feat: interface binding

        Signed-off-by: ilolicon <[email protected]>

    Signed-off-by: Matthieu Pignolet <[email protected]>

Signed-off-by: Matthieu Pignolet <[email protected]>
MatthieuCoder added a commit to MatthieuCoder/pro-bing that referenced this pull request Oct 29, 2024
commit 75cbb26
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 20:49:25 2024 +0400

    Use the machine executor for CI

    Signed-off-by: Matthieu Pignolet <[email protected]>

commit a0e098a
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 20:48:33 2024 +0400

    Using the machine executor for CI

    Signed-off-by: Matthieu Pignolet <[email protected]>

commit 77e1065
Merge: 3cb9e40 a563de4
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 20:09:52 2024 +0400

    Merge branch 'prometheus-community:main' into main

commit 3cb9e40
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 20:05:12 2024 +0400

    Remote the un-used workaround used to avoid the `lo` interfaces

    Signed-off-by: Matthieu Pignolet <[email protected]>

commit 006d173
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 17:11:14 2024 +0400

    add a function (`testSetInterfaceNameChooseInterface`) to choose any interface that has an IP address assigned to it
    this is a "hack" to supposedly make CircleCI happy

    Signed-off-by: Matthieu Pignolet <[email protected]>

commit 7385672
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 16:11:33 2024 +0400

    Renaming the `Interface` Pinger property to `InterfaceDevice` to avoid conflict with the `interface` keyword.

    Signed-off-by: Matthieu Pignolet <[email protected]>

commit 978c60e
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 15:59:36 2024 +0400

    Add the `Interface` option to `Pinger`

    This allows using `pro-bing` to use VRFs interfaces and IPv6 link-local addresses.
    Originally from @ilolicon in prometheus-community#32.

    commit 16f9286
    Author: Matthieu Pignolet <[email protected]>
    Date:   Tue Oct 29 15:46:13 2024 +0400

        Remove the un-used function in te `packetConn` interface that did not get removed during the merging process

    commit 88bb1f5
    Author: ilolicon <[email protected]>
    Date:   Wed Apr 12 16:23:06 2023 +0800

        Refactoring the variable name `Iface` to `Interface` and `ifaceIndex` to `ifIndex`(keeping it consistent with `ControlMessage`)

        Signed-off-by: ilolicon <[email protected]>

    commit 887b4e2
    Author: ilolicon <[email protected]>
    Date:   Wed Apr 12 10:39:36 2023 +0800

        feat: interface binding

        Signed-off-by: ilolicon <[email protected]>

    Signed-off-by: Matthieu Pignolet <[email protected]>

Signed-off-by: Matthieu Pignolet <[email protected]>
MatthieuCoder added a commit to MatthieuCoder/pro-bing that referenced this pull request Oct 29, 2024
…t specifies the device that needs to be used to send and receive ICMP echo requests and response.

This allows usage of `pro-bing` with linux VRFs, and IPv6 link-local addresses.

Squashed commit of the following:

commit 7385672
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 16:11:33 2024 +0400

    Renaming the `Interface` Pinger property to `InterfaceDevice` to avoid conflict with the `interface` keyword.

    Signed-off-by: Matthieu Pignolet <[email protected]>

commit 978c60e
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 15:59:36 2024 +0400

Add the `Interface` option to `Pinger`

This allows using `pro-bing` to use VRFs interfaces and IPv6 link-local addresses.
Originally from @ilolicon in prometheus-community#32.

commit 16f9286
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 15:46:13 2024 +0400

    Remove the un-used function in te `packetConn` interface that did not get removed during the merging process

commit 88bb1f5
Author: ilolicon <[email protected]>
Date:   Wed Apr 12 16:23:06 2023 +0800

    Refactoring the variable name `Iface` to `Interface` and `ifaceIndex` to `ifIndex`(keeping it consistent with `ControlMessage`)

    Signed-off-by: ilolicon <[email protected]>

commit 887b4e2
Author: ilolicon <[email protected]>
Date:   Wed Apr 12 10:39:36 2023 +0800

    feat: interface binding

    Signed-off-by: ilolicon <[email protected]>
MatthieuCoder added a commit to MatthieuCoder/pro-bing that referenced this pull request Oct 29, 2024
…t specifies the device that needs to be used to send and receive ICMP echo requests and response.

This allows usage of `pro-bing` with linux VRFs, and IPv6 link-local addresses.

Squashed commit of the following:

commit 7385672
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 16:11:33 2024 +0400

    Renaming the `Interface` Pinger property to `InterfaceDevice` to avoid conflict with the `interface` keyword.

    Signed-off-by: Matthieu Pignolet <[email protected]>

commit 978c60e
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 15:59:36 2024 +0400

Add the `Interface` option to `Pinger`

This allows using `pro-bing` to use VRFs interfaces and IPv6 link-local addresses.
Originally from @ilolicon in prometheus-community#32.

commit 16f9286
Author: Matthieu Pignolet <[email protected]>
Date:   Tue Oct 29 15:46:13 2024 +0400

    Remove the un-used function in te `packetConn` interface that did not get removed during the merging process

commit 88bb1f5
Author: ilolicon <[email protected]>
Date:   Wed Apr 12 16:23:06 2023 +0800

    Refactoring the variable name `Iface` to `Interface` and `ifaceIndex` to `ifIndex`(keeping it consistent with `ControlMessage`)

    Signed-off-by: ilolicon <[email protected]>

commit 887b4e2
Author: ilolicon <[email protected]>
Date:   Wed Apr 12 10:39:36 2023 +0800

    feat: interface binding

    Signed-off-by: ilolicon <[email protected]>

Signed-off-by: Matthieu Pignolet <[email protected]>
@ilolicon
Copy link
Author

At least the PR has conflicts, @ilolicon can you resolve them?

Sorry, I was too busy recently and didn't pay attention to the news. It seems that @MatthieuCoder has resolved the conflict.

@HsimWong
Copy link

HsimWong commented Nov 5, 2024

Resolved #123

@SuperQ SuperQ closed this Nov 5, 2024
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.

9 participants