koron / go-ssdp

SSDP library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ability to tune the TTL?

mharbison72 opened this issue · comments

I don't see any way to set the TTL on the connection from outside of this module. The spec[1] says the default value should be 2 for everything except M-SEARCH response, but I don't see SetTTL() from ipv4.PacketConn called at all.

[1] https://openconnectivity.org/upnp-specs/UPnP-arch-DeviceArchitecture-v2.0-20200417.pdf

for future implementation: https://pkg.go.dev/golang.org/x/net/ipv4#PacketConn.SetTTL

from https://openconnectivity.org/upnp-specs/UPnP-arch-DeviceArchitecture-v2.0-20200417.pdf

To limit network congestion, the time-to-live (TTL) of each IP packet for each multicast
message should default to 2 and should be configurable.

  • pp.20 - 1 Discovery

The TTL for the IP packet should default to 2 and should be configurable.

  • pp.27 - 1.2.2 Device available - NOTIFY with ssdp:alive
  • pp.31 - 1.2.3 Device unavailable -- NOTIFY with ssdp:byebye
  • pp.33 - 1.2.4 Device Update – NOTIFY with ssdp:update
  • pp.35 - 1.3.2 Search request with M-SEARCH

No need to limit TTL for the IP packet in response to a search request.

  • pp.40 - 1.3.3 Search response

Lastly, like SSDP, to limit network congestion, the time-to-live (TTL) of each IP packet for each multicast message should default to 2 and should be configurable. This should be the same value as that used in SSDP. When the TTL is greater than 1, it is possible for multicast messages to traverse multiple routers; therefore control points and devices using non-AutoIP addresses shall send an IGMP Join message so that routers will forward multicast messages to them (this is not necessary when using an Auto-IP address since packets with Auto-IP addresses will not be forwarded by routers).

  • pp.99 - 4.2 Multicast Eventing

TTL is not mentioned in https://datatracker.ietf.org/doc/html/draft-cai-ssdp-v1-03 which this package referenced.

It looks like reasonable that make default TTL is 2 and configurable.

func TTL(ttl int) Option can be used for this.