diff options
author | Chris Kuiper <ckuiper@google.com> | 2019-06-05 16:07:18 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-06-05 16:08:29 -0700 |
commit | d18bb4f38a7a89456dad1f3a0e8ff13a0b65ba7f (patch) | |
tree | 60ceff0188eab8a476ff923a11fa9dfee3db97ee /pkg/tcpip/stack/route.go | |
parent | c08fcaa364e917b19aad0f74a8e3a1c700d0bfcc (diff) |
Adjust route when looping multicast packets
Multicast packets are special in that their destination address does not
identify a specific interface. When sending out such a packet the multicast
address is the remote address, but for incoming packets it is the local
address. Hence, when looping a multicast packet, the route needs to be
tweaked to reflect this.
PiperOrigin-RevId: 251739298
Diffstat (limited to 'pkg/tcpip/stack/route.go')
-rw-r--r-- | pkg/tcpip/stack/route.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/pkg/tcpip/stack/route.go b/pkg/tcpip/stack/route.go index 3d4c282a9..55ed02479 100644 --- a/pkg/tcpip/stack/route.go +++ b/pkg/tcpip/stack/route.go @@ -187,3 +187,13 @@ func (r *Route) Clone() Route { r.ref.incRef() return *r } + +// MakeLoopedRoute duplicates the given route and tweaks it in case of multicast. +func (r *Route) MakeLoopedRoute() Route { + l := r.Clone() + if header.IsV4MulticastAddress(r.RemoteAddress) || header.IsV6MulticastAddress(r.RemoteAddress) { + l.RemoteAddress, l.LocalAddress = l.LocalAddress, l.RemoteAddress + l.RemoteLinkAddress = l.LocalLinkAddress + } + return l +} |