jackpal / gateway

A golang library for discovering the address of a LAN gateway.
BSD 3-Clause "New" or "Revised" License
226 stars 69 forks source link

Fallback to netstat on darwin systems if route fails #35

Closed fuskovic closed 1 year ago

fuskovic commented 1 year ago

What this does

Tests

go test -v --run TestParseDarwinNetstat

jackpal commented 1 year ago

Why is /sbin/route parsing failing in your environment? Could /sbin/route parsing be fixed rather than implementing this fallback?

fuskovic commented 1 year ago

Why is /sbin/route parsing failing in your environment? Could /sbin/route parsing be fixed rather than implementing this fallback?

parseDarwinRouteGet is looking for a substring not found in the output.

/sbin/route -n get 0.0.0.0
   route to: default
destination: default
       mask: default
  interface: utun3
      flags: <UP,DONE,CLONING,STATIC,GLOBAL>
 recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
       0         0         0         0         0         0      1420         0
jackpal commented 1 year ago

I see, yes.

OK, reviewing your code, could you make the parser a little more robust:

Could you check that the "Flags" field contains a 'U' and a 'G' before trying to parse the Gateway value as an IP?

https://library.netapp.com/ecmdocs/ECMP1155586/html/GUID-07F1F043-7AB7-4749-8F8D-727929233E62.html

On Thu, Mar 30, 2023 at 8:48 PM Faris Huskovic @.***> wrote:

Why is /sbin/route parsing failing in your environment? Could /sbin/route parsing be fixed rather than implementing this fallback?

parseDarwinRouteGet is looking for a substring not found in the output.

/sbin/route -n get 0.0.0.0 route to: default destination: default mask: default interface: utun3 flags: <UP,DONE,CLONING,STATIC,GLOBAL> recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 0 0 0 0 0 0 1420 0

— Reply to this email directly, view it on GitHub https://github.com/jackpal/gateway/pull/35#issuecomment-1491247438, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABK3V4QW42LXELXQMUZ6Y3W6ZHZJANCNFSM6AAAAAAWOABUAE . You are receiving this because you commented.Message ID: @.***>

fuskovic commented 1 year ago

Could I ask you to push a new tag or publish a new release when you get a chance please?

I'd like to bump the version in my tool to include the fix.

On Thu, Mar 30, 2023 at 11:30 PM Jack Palevich @.***> wrote:

Merged #35 https://github.com/jackpal/gateway/pull/35 into master.

— Reply to this email directly, view it on GitHub https://github.com/jackpal/gateway/pull/35#event-8893897844, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIIG47INFMO64IV5MQO6RSDW6ZMVVANCNFSM6AAAAAAWOABUAE . You are receiving this because you authored the thread.Message ID: @.***>

jackpal commented 1 year ago

I accepted your request, thanks for contributing it and making the changes I requested!

But now that I look at other outstanding issues, I may also integrate https://github.com/jackpal/gateway/issues/27 , which I think might end up superseding your code.

I hope that's OK!

On Thu, Mar 30, 2023 at 9:28 PM Faris Huskovic @.***> wrote:

@fuskovic https://github.com/fuskovic requested your review on: #35 https://github.com/jackpal/gateway/pull/35 Fallback to netstat on darwin systems if route fails.

— Reply to this email directly, view it on GitHub https://github.com/jackpal/gateway/pull/35#event-8893890859, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABK3V3VMHI4V26PGTTNF7DW6ZMOZANCNFSM6AAAAAAWOABUAE . You are receiving this because your review was requested.Message ID: @.***>

fuskovic commented 1 year ago

sgtm

On Thu, Mar 30, 2023 at 11:36 PM Jack Palevich @.***> wrote:

I accepted your request, thanks for contributing it and making the changes I requested!

But now that I look at other outstanding issues, I may also integrate https://github.com/jackpal/gateway/issues/27 , which I think might end up superseding your code.

I hope that's OK!

On Thu, Mar 30, 2023 at 9:28 PM Faris Huskovic @.***> wrote:

@fuskovic https://github.com/fuskovic requested your review on: #35 https://github.com/jackpal/gateway/pull/35 Fallback to netstat on darwin systems if route fails.

— Reply to this email directly, view it on GitHub https://github.com/jackpal/gateway/pull/35#event-8893890859, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AABK3V3VMHI4V26PGTTNF7DW6ZMOZANCNFSM6AAAAAAWOABUAE

. You are receiving this because your review was requested.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/jackpal/gateway/pull/35#issuecomment-1491275232, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIIG47OSNAKXSPTOJBP4TF3W6ZNMTANCNFSM6AAAAAAWOABUAE . You are receiving this because you were mentioned.Message ID: @.***>

jackpal commented 1 year ago

I have tagged the current code v1.0.8

On Thu, Mar 30, 2023 at 9:47 PM Faris Huskovic @.***> wrote:

sgtm

On Thu, Mar 30, 2023 at 11:36 PM Jack Palevich @.***> wrote:

I accepted your request, thanks for contributing it and making the changes I requested!

But now that I look at other outstanding issues, I may also integrate https://github.com/jackpal/gateway/issues/27 , which I think might end up superseding your code.

I hope that's OK!

On Thu, Mar 30, 2023 at 9:28 PM Faris Huskovic @.***> wrote:

@fuskovic https://github.com/fuskovic requested your review on: #35 https://github.com/jackpal/gateway/pull/35 Fallback to netstat on darwin systems if route fails.

— Reply to this email directly, view it on GitHub https://github.com/jackpal/gateway/pull/35#event-8893890859, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AABK3V3VMHI4V26PGTTNF7DW6ZMOZANCNFSM6AAAAAAWOABUAE

. You are receiving this because your review was requested.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/jackpal/gateway/pull/35#issuecomment-1491275232, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AIIG47OSNAKXSPTOJBP4TF3W6ZNMTANCNFSM6AAAAAAWOABUAE

. You are receiving this because you were mentioned.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/jackpal/gateway/pull/35#issuecomment-1491281895, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABK3V5JGMG4YLPBFNO4GYDW6ZOVHANCNFSM6AAAAAAWOABUAE . You are receiving this because you modified the open/close state.Message ID: @.***>

jackpal commented 1 year ago

If it's not too much trouble, could you upgrade to v1.0.9 and check if your use-case works?

v1.0.9 replaces your code with #27

If that breaks your use case, let me know!