Skip to content

Commit 7212cd6

Browse files
committed
ipn/ipnlocal: use node peer caps for ingress
1 parent c645702 commit 7212cd6

3 files changed

Lines changed: 3 additions & 49 deletions

File tree

ipn/ipnlocal/node_backend.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,6 @@ func (nb *nodeBackend) PeerCaps(src netip.Addr) tailcfg.PeerCapMap {
295295
return nb.peerCapsLocked(src)
296296
}
297297

298-
// peerCapsForService returns the capabilities that remote src IP has to the
299-
// specified VIP service hosted by this node.
300-
func (nb *nodeBackend) peerCapsForService(src netip.Addr, serviceName tailcfg.ServiceName) tailcfg.PeerCapMap {
301-
nb.mu.Lock()
302-
defer nb.mu.Unlock()
303-
return nb.peerCapsForServiceLocked(src, serviceName)
304-
}
305-
306298
func (nb *nodeBackend) peerCapsLocked(src netip.Addr) tailcfg.PeerCapMap {
307299
if nb.netMap == nil {
308300
return nil
@@ -325,26 +317,6 @@ func (nb *nodeBackend) peerCapsLocked(src netip.Addr) tailcfg.PeerCapMap {
325317
return nil
326318
}
327319

328-
func (nb *nodeBackend) peerCapsForServiceLocked(src netip.Addr, serviceName tailcfg.ServiceName) tailcfg.PeerCapMap {
329-
if nb.netMap == nil || serviceName == "" {
330-
return nil
331-
}
332-
filt := nb.filterAtomic.Load()
333-
if filt == nil {
334-
return nil
335-
}
336-
serviceIPMap := nb.netMap.GetVIPServiceIPMap()
337-
if len(serviceIPMap) == 0 {
338-
return nil
339-
}
340-
for _, dst := range serviceIPMap[serviceName] {
341-
if dst.BitLen() == src.BitLen() { // match on family
342-
return filt.CapsWithValues(src, dst)
343-
}
344-
}
345-
return nil
346-
}
347-
348320
// PeerHasCap reports whether the peer contains the given capability string,
349321
// with any value(s).
350322
func (nb *nodeBackend) PeerHasCap(peer tailcfg.NodeView, wantCap tailcfg.PeerCapability) bool {

ipn/ipnlocal/serve.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,12 +1101,7 @@ func (b *LocalBackend) addAppCapabilitiesHeader(r *httputil.ProxyRequest) error
11011101
if acceptCaps.IsNil() {
11021102
return nil
11031103
}
1104-
var peerCaps tailcfg.PeerCapMap
1105-
if c.ForVIPService != "" {
1106-
peerCaps = b.currentNode().peerCapsForService(c.SrcAddr.Addr(), c.ForVIPService)
1107-
} else {
1108-
peerCaps = b.PeerCaps(c.SrcAddr.Addr())
1109-
}
1104+
peerCaps := b.PeerCaps(c.SrcAddr.Addr())
11101105
if peerCaps == nil {
11111106
return nil
11121107
}

ipn/ipnlocal/serve_test.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,26 +1012,13 @@ func TestServeHTTPProxyGrantHeader(t *testing.T) {
10121012
func TestServeHTTPProxyGrantHeaderForVIPService(t *testing.T) {
10131013
b := newTestBackend(t)
10141014

1015-
svcIPMapJSON, err := json.Marshal(tailcfg.ServiceIPMappings{
1016-
"svc:foo": {netip.MustParseAddr("100.101.101.101")},
1017-
})
1018-
if err != nil {
1019-
t.Fatal(err)
1020-
}
1021-
10221015
nm := b.NetMap()
1023-
self := nm.SelfNode.AsStruct()
1024-
self.CapMap = tailcfg.NodeCapMap{
1025-
tailcfg.NodeAttrServiceHost: []tailcfg.RawMessage{tailcfg.RawMessage(svcIPMapJSON)},
1026-
}
1027-
nm.SelfNode = self.View()
1028-
10291016
matches, err := filter.MatchesFromFilterRules([]tailcfg.FilterRule{
10301017
{
10311018
SrcIPs: []string{"100.150.151.152"},
10321019
CapGrant: []tailcfg.CapGrant{{
10331020
Dsts: []netip.Prefix{
1034-
netip.MustParsePrefix("100.101.101.101/32"),
1021+
netip.MustParsePrefix("100.150.151.151/32"),
10351022
},
10361023
CapMap: tailcfg.PeerCapMap{
10371024
"example.com/cap/interesting": []tailcfg.RawMessage{
@@ -1044,7 +1031,7 @@ func TestServeHTTPProxyGrantHeaderForVIPService(t *testing.T) {
10441031
SrcIPs: []string{"100.150.151.153"},
10451032
CapGrant: []tailcfg.CapGrant{{
10461033
Dsts: []netip.Prefix{
1047-
netip.MustParsePrefix("100.101.101.101/32"),
1034+
netip.MustParsePrefix("100.150.151.151/32"),
10481035
},
10491036
CapMap: tailcfg.PeerCapMap{
10501037
"example.com/cap/boring": []tailcfg.RawMessage{

0 commit comments

Comments
 (0)