Skip to content

Commit 84c77aa

Browse files
avagingvisor-bot
authored andcommitted
netstack: Don't treat ipv4 link-local addresses specially
In Linux, RFC 3927 logic is implemented in user-space. If we try to implement that within the netstack, it can introduce undesired compatibility issues. For example, GCE uses link-local addresses for some services like DNS. PiperOrigin-RevId: 770045074
1 parent cab42c6 commit 84c77aa

File tree

4 files changed

+10
-95
lines changed

4 files changed

+10
-95
lines changed

pkg/tcpip/network/ipv4/ipv4.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -934,22 +934,6 @@ func validateAddressesForForwarding(h header.IPv4) ip.ForwardingError {
934934
return &ip.ErrInitializingSourceAddress{}
935935
}
936936

937-
// As per RFC 3927 section 7,
938-
//
939-
// A router MUST NOT forward a packet with an IPv4 Link-Local source or
940-
// destination address, irrespective of the router's default route
941-
// configuration or routes obtained from dynamic routing protocols.
942-
//
943-
// A router which receives a packet with an IPv4 Link-Local source or
944-
// destination address MUST NOT forward the packet. This prevents
945-
// forwarding of packets back onto the network segment from which they
946-
// originated, or to any other segment.
947-
if header.IsV4LinkLocalUnicastAddress(srcAddr) {
948-
return &ip.ErrLinkLocalSourceAddress{}
949-
}
950-
if dstAddr := h.DestinationAddress(); header.IsV4LinkLocalUnicastAddress(dstAddr) || header.IsV4LinkLocalMulticastAddress(dstAddr) {
951-
return &ip.ErrLinkLocalDestinationAddress{}
952-
}
953937
return nil
954938
}
955939

@@ -1616,11 +1600,11 @@ func (p *protocol) Close() {
16161600
func (*protocol) Wait() {}
16171601

16181602
func (p *protocol) validateUnicastSourceAndMulticastDestination(addresses stack.UnicastSourceAndMulticastDestination) tcpip.Error {
1619-
if !p.isUnicastAddress(addresses.Source) || header.IsV4LinkLocalUnicastAddress(addresses.Source) {
1603+
if !p.isUnicastAddress(addresses.Source) {
16201604
return &tcpip.ErrBadAddress{}
16211605
}
16221606

1623-
if !header.IsV4MulticastAddress(addresses.Destination) || header.IsV4LinkLocalMulticastAddress(addresses.Destination) {
1607+
if !header.IsV4MulticastAddress(addresses.Destination) {
16241608
return &tcpip.ErrBadAddress{}
16251609
}
16261610

pkg/tcpip/network/ipv4/ipv4_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ func TestForwarding(t *testing.T) {
345345
const randomTimeOffset = 0x10203040
346346

347347
unreachableIPv4Addr := testutil.MustParse4("12.0.0.2")
348-
linkLocalIPv4Addr := testutil.MustParse4("169.254.0.0")
349348

350349
tests := []struct {
351350
name string
@@ -480,22 +479,6 @@ func TestForwarding(t *testing.T) {
480479
expectedPacketUnrouteableErrors: 1,
481480
expectPacketForwarded: false,
482481
},
483-
{
484-
name: "Link local destination",
485-
TTL: 2,
486-
srcAddr: remoteIPv4Addr1,
487-
dstAddr: linkLocalIPv4Addr,
488-
expectedLinkLocalDestErrors: 1,
489-
expectPacketForwarded: false,
490-
},
491-
{
492-
name: "Link local source",
493-
TTL: 2,
494-
srcAddr: linkLocalIPv4Addr,
495-
dstAddr: remoteIPv4Addr2,
496-
expectedLinkLocalSourceErrors: 1,
497-
expectPacketForwarded: false,
498-
},
499482
{
500483
name: "unspecified source",
501484
TTL: 2,

pkg/tcpip/tests/integration/forward_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,21 @@ func TestUnicastForwarding(t *testing.T) {
387387
srcAddr: ipv4LinkLocalUnicastAddr,
388388
dstAddr: utils.RemoteIPv4Addr,
389389
rx: rxICMPv4EchoRequest,
390-
expectForward: false,
390+
expectForward: true,
391+
checker: func(t *testing.T, v *buffer.View) {
392+
forwardedICMPv4EchoRequestChecker(t, v, ipv4LinkLocalUnicastAddr, utils.RemoteIPv4Addr)
393+
},
391394
},
392395
{
393396
name: "IPv4 link-local destination",
394397
netProto: ipv4.ProtocolNumber,
395398
srcAddr: utils.RemoteIPv4Addr,
396399
dstAddr: ipv4LinkLocalUnicastAddr,
397400
rx: rxICMPv4EchoRequest,
398-
expectForward: false,
401+
expectForward: true,
402+
checker: func(t *testing.T, v *buffer.View) {
403+
forwardedICMPv4EchoRequestChecker(t, v, utils.RemoteIPv4Addr, ipv4LinkLocalUnicastAddr)
404+
},
399405
},
400406
{
401407
name: "IPv4 non-link-local unicast",

pkg/tcpip/tests/integration/multicast_forward_test.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,6 @@ func TestAddMulticastRoute(t *testing.T) {
329329
multicastForwardingEventsBeforeAddRouteCalled: []multicastForwardingEvent{enabledForNIC, enabledForProtocol},
330330
wantErr: &tcpip.ErrBadAddress{},
331331
},
332-
{
333-
name: "link-local unicast source",
334-
srcAddr: linkLocalUnicastAddr,
335-
dstAddr: multicastAddr,
336-
routeIncomingNICID: incomingNICID,
337-
routeOutgoingNICID: outgoingNICID,
338-
multicastForwardingEventsBeforeAddRouteCalled: []multicastForwardingEvent{enabledForNIC, enabledForProtocol},
339-
wantErr: &tcpip.ErrBadAddress{},
340-
},
341332
{
342333
name: "empty source",
343334
srcAddr: emptyAddr,
@@ -365,15 +356,6 @@ func TestAddMulticastRoute(t *testing.T) {
365356
multicastForwardingEventsBeforeAddRouteCalled: []multicastForwardingEvent{enabledForNIC, enabledForProtocol},
366357
wantErr: &tcpip.ErrBadAddress{},
367358
},
368-
{
369-
name: "link-local multicast destination",
370-
srcAddr: remoteUnicastAddr,
371-
dstAddr: linkLocalMulticastAddr,
372-
routeIncomingNICID: incomingNICID,
373-
routeOutgoingNICID: outgoingNICID,
374-
multicastForwardingEventsBeforeAddRouteCalled: []multicastForwardingEvent{enabledForNIC, enabledForProtocol},
375-
wantErr: &tcpip.ErrBadAddress{},
376-
},
377359
{
378360
name: "unknown input NICID",
379361
srcAddr: remoteUnicastAddr,
@@ -600,12 +582,6 @@ func TestMulticastRouteLastUsedTime(t *testing.T) {
600582
dstAddr: multicastAddr,
601583
wantErr: &tcpip.ErrBadAddress{},
602584
},
603-
{
604-
name: "link-local unicast source",
605-
srcAddr: linkLocalUnicastAddr,
606-
dstAddr: multicastAddr,
607-
wantErr: &tcpip.ErrBadAddress{},
608-
},
609585
{
610586
name: "empty source",
611587
srcAddr: emptyAddr,
@@ -624,12 +600,6 @@ func TestMulticastRouteLastUsedTime(t *testing.T) {
624600
dstAddr: emptyAddr,
625601
wantErr: &tcpip.ErrBadAddress{},
626602
},
627-
{
628-
name: "link-local multicast destination",
629-
srcAddr: remoteUnicastAddr,
630-
dstAddr: linkLocalMulticastAddr,
631-
wantErr: &tcpip.ErrBadAddress{},
632-
},
633603
}
634604

635605
for _, test := range tests {
@@ -758,12 +728,6 @@ func TestRemoveMulticastRoute(t *testing.T) {
758728
dstAddr: multicastAddr,
759729
wantErr: &tcpip.ErrBadAddress{},
760730
},
761-
{
762-
name: "link-local unicast source",
763-
srcAddr: linkLocalUnicastAddr,
764-
dstAddr: multicastAddr,
765-
wantErr: &tcpip.ErrBadAddress{},
766-
},
767731
{
768732
name: "empty source",
769733
srcAddr: emptyAddr,
@@ -782,12 +746,6 @@ func TestRemoveMulticastRoute(t *testing.T) {
782746
dstAddr: emptyAddr,
783747
wantErr: &tcpip.ErrBadAddress{},
784748
},
785-
{
786-
name: "link-local multicast destination",
787-
srcAddr: remoteUnicastAddr,
788-
dstAddr: linkLocalMulticastAddr,
789-
wantErr: &tcpip.ErrBadAddress{},
790-
},
791749
}
792750

793751
for _, test := range tests {
@@ -927,22 +885,6 @@ func TestMulticastForwarding(t *testing.T) {
927885
routeInputInterface: incomingNICID,
928886
expectedForwardingInterfaces: []tcpip.NICID{outgoingNICID, otherOutgoingNICID},
929887
},
930-
{
931-
name: "forward and local",
932-
dstAddr: multicastAddr,
933-
ttl: packetTTL,
934-
routeInputInterface: incomingNICID,
935-
joinMulticastGroup: true,
936-
expectedForwardingInterfaces: []tcpip.NICID{outgoingNICID, otherOutgoingNICID},
937-
},
938-
{
939-
name: "local only",
940-
dstAddr: linkLocalMulticastAddr,
941-
ttl: packetTTL,
942-
routeInputInterface: incomingNICID,
943-
joinMulticastGroup: true,
944-
expectedForwardingInterfaces: []tcpip.NICID{},
945-
},
946888
{
947889
name: "multicast forwarding disabled for NIC",
948890
disableMulticastForwardingForNIC: true,

0 commit comments

Comments
 (0)