2020-02-12 20:53:55 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-08-05 23:42:39 +01:00
|
|
|
//go:build !android
|
2020-04-24 14:23:32 +01:00
|
|
|
// +build !android
|
|
|
|
|
2020-02-12 20:53:55 +00:00
|
|
|
package monitor
|
|
|
|
|
|
|
|
import (
|
2020-07-07 00:36:57 +01:00
|
|
|
"net"
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
"net/netip"
|
2020-02-17 19:28:07 +00:00
|
|
|
"time"
|
2020-02-12 20:53:55 +00:00
|
|
|
|
2020-07-07 00:36:57 +01:00
|
|
|
"github.com/jsimonetti/rtnetlink"
|
2020-02-12 20:53:55 +00:00
|
|
|
"github.com/mdlayher/netlink"
|
|
|
|
"golang.org/x/sys/unix"
|
2022-04-08 22:54:28 +01:00
|
|
|
"tailscale.com/envknob"
|
2022-07-25 04:08:42 +01:00
|
|
|
"tailscale.com/net/netaddr"
|
2020-07-07 00:36:57 +01:00
|
|
|
"tailscale.com/net/tsaddr"
|
|
|
|
"tailscale.com/types/logger"
|
2020-02-12 20:53:55 +00:00
|
|
|
)
|
|
|
|
|
2022-04-08 22:54:28 +01:00
|
|
|
var debugNetlinkMessages = envknob.Bool("TS_DEBUG_NETLINK")
|
|
|
|
|
2020-07-15 00:28:02 +01:00
|
|
|
// unspecifiedMessage is a minimal message implementation that should not
|
|
|
|
// be ignored. In general, OS-specific implementations should use better
|
|
|
|
// types and avoid this if they can.
|
|
|
|
type unspecifiedMessage struct{}
|
|
|
|
|
|
|
|
func (unspecifiedMessage) ignore() bool { return false }
|
|
|
|
|
2020-02-12 20:53:55 +00:00
|
|
|
// nlConn wraps a *netlink.Conn and returns a monitor.Message
|
|
|
|
// instead of a netlink.Message. Currently, messages are discarded,
|
|
|
|
// but down the line, when messages trigger different logic depending
|
|
|
|
// on the type of event, this provides the capability of handling
|
|
|
|
// each architecture-specific message in a generic fashion.
|
|
|
|
type nlConn struct {
|
2020-07-07 00:36:57 +01:00
|
|
|
logf logger.Logf
|
|
|
|
conn *netlink.Conn
|
|
|
|
buffered []netlink.Message
|
2022-04-08 21:06:40 +01:00
|
|
|
|
|
|
|
// addrCache maps interface indices to a set of addresses, and is
|
|
|
|
// used to suppress duplicate RTM_NEWADDR messages. It is populated
|
|
|
|
// by RTM_NEWADDR messages and de-populated by RTM_DELADDR. See
|
|
|
|
// issue #4282.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
addrCache map[uint32]map[netip.Addr]bool
|
2020-02-12 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 00:26:11 +01:00
|
|
|
func newOSMon(logf logger.Logf, m *Mon) (osMon, error) {
|
2020-02-12 20:53:55 +00:00
|
|
|
conn, err := netlink.Dial(unix.NETLINK_ROUTE, &netlink.Config{
|
2021-02-23 03:38:07 +00:00
|
|
|
// Routes get us most of the events of interest, but we need
|
|
|
|
// address as well to cover things like DHCP deciding to give
|
|
|
|
// us a new address upon renewal - routing wouldn't change,
|
|
|
|
// but all reachability would.
|
2021-07-18 22:50:47 +01:00
|
|
|
Groups: unix.RTMGRP_IPV4_IFADDR | unix.RTMGRP_IPV6_IFADDR |
|
|
|
|
unix.RTMGRP_IPV4_ROUTE | unix.RTMGRP_IPV6_ROUTE |
|
|
|
|
unix.RTMGRP_IPV4_RULE, // no IPV6_RULE in x/sys/unix
|
2020-02-12 20:53:55 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-04-01 00:26:11 +01:00
|
|
|
// Google Cloud Run does not implement NETLINK_ROUTE RTMGRP support
|
|
|
|
logf("monitor_linux: AF_NETLINK RTMGRP failed, falling back to polling")
|
|
|
|
return newPollingMon(logf, m)
|
2020-02-12 20:53:55 +00:00
|
|
|
}
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
return &nlConn{logf: logf, conn: conn, addrCache: make(map[uint32]map[netip.Addr]bool)}, nil
|
2020-02-12 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 20:03:50 +01:00
|
|
|
func (c *nlConn) IsInterestingInterface(iface string) bool { return true }
|
|
|
|
|
2020-12-20 17:54:22 +00:00
|
|
|
func (c *nlConn) Close() error { return c.conn.Close() }
|
2020-02-12 20:53:55 +00:00
|
|
|
|
2020-02-17 17:00:38 +00:00
|
|
|
func (c *nlConn) Receive() (message, error) {
|
2020-07-07 00:36:57 +01:00
|
|
|
if len(c.buffered) == 0 {
|
|
|
|
var err error
|
|
|
|
c.buffered, err = c.conn.Receive()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(c.buffered) == 0 {
|
|
|
|
// Unexpected. Not seen in wild, but sleep defensively.
|
|
|
|
time.Sleep(time.Second)
|
2020-07-07 19:07:12 +01:00
|
|
|
return ignoreMessage{}, nil
|
2020-07-07 00:36:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
msg := c.buffered[0]
|
|
|
|
c.buffered = c.buffered[1:]
|
|
|
|
|
|
|
|
// See https://github.com/torvalds/linux/blob/master/include/uapi/linux/rtnetlink.h
|
|
|
|
// And https://man7.org/linux/man-pages/man7/rtnetlink.7.html
|
|
|
|
switch msg.Header.Type {
|
2020-07-07 19:07:12 +01:00
|
|
|
case unix.RTM_NEWADDR, unix.RTM_DELADDR:
|
2020-07-07 00:36:57 +01:00
|
|
|
var rmsg rtnetlink.AddressMessage
|
|
|
|
if err := rmsg.UnmarshalBinary(msg.Data); err != nil {
|
2020-08-06 04:44:05 +01:00
|
|
|
c.logf("failed to parse type %v: %v", msg.Header.Type, err)
|
2020-07-07 19:07:12 +01:00
|
|
|
return unspecifiedMessage{}, nil
|
2020-07-07 00:36:57 +01:00
|
|
|
}
|
2022-04-08 22:54:28 +01:00
|
|
|
|
2022-04-08 21:06:40 +01:00
|
|
|
nip := netaddrIP(rmsg.Attributes.Address)
|
|
|
|
|
|
|
|
if debugNetlinkMessages {
|
|
|
|
typ := "RTM_NEWADDR"
|
|
|
|
if msg.Header.Type == unix.RTM_DELADDR {
|
|
|
|
typ = "RTM_DELADDR"
|
|
|
|
}
|
|
|
|
|
|
|
|
// label attributes are seemingly only populated for ipv4 addresses in the wild.
|
|
|
|
label := rmsg.Attributes.Label
|
|
|
|
if label == "" {
|
|
|
|
itf, err := net.InterfaceByIndex(int(rmsg.Index))
|
|
|
|
if err == nil {
|
|
|
|
label = itf.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.logf("%s: %s(%d) %s / %s", typ, label, rmsg.Index, rmsg.Attributes.Address, rmsg.Attributes.Local)
|
|
|
|
}
|
|
|
|
|
|
|
|
addrs := c.addrCache[rmsg.Index]
|
|
|
|
|
|
|
|
// Ignore duplicate RTM_NEWADDR messages using c.addrCache to
|
|
|
|
// detect them. See nlConn.addrcache and issue #4282.
|
|
|
|
if msg.Header.Type == unix.RTM_NEWADDR {
|
|
|
|
if addrs == nil {
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
addrs = make(map[netip.Addr]bool)
|
2022-04-08 21:06:40 +01:00
|
|
|
c.addrCache[rmsg.Index] = addrs
|
|
|
|
}
|
|
|
|
|
|
|
|
if addrs[nip] {
|
|
|
|
if debugNetlinkMessages {
|
|
|
|
c.logf("ignored duplicate RTM_NEWADDR for %s", nip)
|
|
|
|
}
|
|
|
|
return ignoreMessage{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
addrs[nip] = true
|
|
|
|
} else { // msg.Header.Type == unix.RTM_DELADDR
|
|
|
|
if addrs != nil {
|
|
|
|
delete(addrs, nip)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(addrs) == 0 {
|
|
|
|
delete(c.addrCache, rmsg.Index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-08 22:54:28 +01:00
|
|
|
nam := &newAddrMessage{
|
2022-04-08 21:06:40 +01:00
|
|
|
IfIndex: rmsg.Index,
|
|
|
|
Addr: nip,
|
|
|
|
Delete: msg.Header.Type == unix.RTM_DELADDR,
|
2022-04-08 22:54:28 +01:00
|
|
|
}
|
|
|
|
if debugNetlinkMessages {
|
|
|
|
c.logf("%+v", nam)
|
|
|
|
}
|
|
|
|
return nam, nil
|
2020-08-12 21:12:56 +01:00
|
|
|
case unix.RTM_NEWROUTE, unix.RTM_DELROUTE:
|
|
|
|
typeStr := "RTM_NEWROUTE"
|
|
|
|
if msg.Header.Type == unix.RTM_DELROUTE {
|
|
|
|
typeStr = "RTM_DELROUTE"
|
|
|
|
}
|
2020-07-07 00:36:57 +01:00
|
|
|
var rmsg rtnetlink.RouteMessage
|
|
|
|
if err := rmsg.UnmarshalBinary(msg.Data); err != nil {
|
2020-08-12 21:12:56 +01:00
|
|
|
c.logf("%s: failed to parse: %v", typeStr, err)
|
|
|
|
return unspecifiedMessage{}, nil
|
|
|
|
}
|
|
|
|
src := netaddrIPPrefix(rmsg.Attributes.Src, rmsg.SrcLength)
|
|
|
|
dst := netaddrIPPrefix(rmsg.Attributes.Dst, rmsg.DstLength)
|
|
|
|
gw := netaddrIP(rmsg.Attributes.Gateway)
|
|
|
|
|
2022-02-12 16:05:24 +00:00
|
|
|
if msg.Header.Type == unix.RTM_NEWROUTE &&
|
|
|
|
(rmsg.Attributes.Table == 255 || rmsg.Attributes.Table == 254) &&
|
2022-07-25 04:08:42 +01:00
|
|
|
(dst.Addr().IsMulticast() || dst.Addr().IsLinkLocalUnicast()) {
|
2022-04-08 22:54:28 +01:00
|
|
|
|
|
|
|
if debugNetlinkMessages {
|
|
|
|
c.logf("%s ignored", typeStr)
|
|
|
|
}
|
|
|
|
|
2022-02-12 16:05:24 +00:00
|
|
|
// Normal Linux route changes on new interface coming up; don't log or react.
|
|
|
|
return ignoreMessage{}, nil
|
|
|
|
}
|
|
|
|
|
2021-04-12 18:27:10 +01:00
|
|
|
if rmsg.Table == tsTable && dst.IsSingleIP() {
|
2020-08-12 21:12:56 +01:00
|
|
|
// Don't log. Spammy and normal to see a bunch of these on start-up,
|
|
|
|
// which we make ourselves.
|
2022-07-25 04:08:42 +01:00
|
|
|
} else if tsaddr.IsTailscaleIP(dst.Addr()) {
|
2022-02-12 16:05:24 +00:00
|
|
|
// Verbose only.
|
|
|
|
c.logf("%s: [v1] src=%v, dst=%v, gw=%v, outif=%v, table=%v", typeStr,
|
|
|
|
condNetAddrPrefix(src), condNetAddrPrefix(dst), condNetAddrIP(gw),
|
|
|
|
rmsg.Attributes.OutIface, rmsg.Attributes.Table)
|
2020-08-12 21:12:56 +01:00
|
|
|
} else {
|
|
|
|
c.logf("%s: src=%v, dst=%v, gw=%v, outif=%v, table=%v", typeStr,
|
|
|
|
condNetAddrPrefix(src), condNetAddrPrefix(dst), condNetAddrIP(gw),
|
|
|
|
rmsg.Attributes.OutIface, rmsg.Attributes.Table)
|
|
|
|
}
|
|
|
|
if msg.Header.Type == unix.RTM_DELROUTE {
|
|
|
|
// Just logging it for now.
|
|
|
|
// (Debugging https://github.com/tailscale/tailscale/issues/643)
|
2020-07-07 19:07:12 +01:00
|
|
|
return unspecifiedMessage{}, nil
|
2020-07-07 00:36:57 +01:00
|
|
|
}
|
2022-04-08 22:54:28 +01:00
|
|
|
|
|
|
|
nrm := &newRouteMessage{
|
2020-07-07 00:36:57 +01:00
|
|
|
Table: rmsg.Table,
|
2020-08-12 21:12:56 +01:00
|
|
|
Src: src,
|
|
|
|
Dst: dst,
|
|
|
|
Gateway: gw,
|
2022-04-08 22:54:28 +01:00
|
|
|
}
|
|
|
|
if debugNetlinkMessages {
|
|
|
|
c.logf("%+v", nrm)
|
|
|
|
}
|
|
|
|
return nrm, nil
|
2021-07-19 22:30:15 +01:00
|
|
|
case unix.RTM_NEWRULE:
|
|
|
|
// Probably ourselves adding it.
|
|
|
|
return ignoreMessage{}, nil
|
2021-07-18 22:50:47 +01:00
|
|
|
case unix.RTM_DELRULE:
|
|
|
|
// For https://github.com/tailscale/tailscale/issues/1591 where
|
|
|
|
// systemd-networkd deletes our rules.
|
|
|
|
var rmsg rtnetlink.RouteMessage
|
|
|
|
err := rmsg.UnmarshalBinary(msg.Data)
|
|
|
|
if err != nil {
|
|
|
|
c.logf("ip rule deleted; failed to parse netlink message: %v", err)
|
|
|
|
} else {
|
|
|
|
c.logf("ip rule deleted: %+v", rmsg)
|
|
|
|
// On `ip -4 rule del pref 5210 table main`, logs:
|
|
|
|
// monitor: ip rule deleted: {Family:2 DstLength:0 SrcLength:0 Tos:0 Table:254 Protocol:0 Scope:0 Type:1 Flags:0 Attributes:{Dst:<nil> Src:<nil> Gateway:<nil> OutIface:0 Priority:5210 Table:254 Mark:4294967295 Expires:<nil> Metrics:<nil> Multipath:[]}}
|
|
|
|
}
|
2022-04-08 22:54:28 +01:00
|
|
|
rdm := ipRuleDeletedMessage{
|
2021-07-20 22:10:52 +01:00
|
|
|
table: rmsg.Table,
|
|
|
|
priority: rmsg.Attributes.Priority,
|
2022-04-08 22:54:28 +01:00
|
|
|
}
|
|
|
|
if debugNetlinkMessages {
|
|
|
|
c.logf("%+v", rdm)
|
|
|
|
}
|
|
|
|
return rdm, nil
|
2020-07-07 00:36:57 +01:00
|
|
|
default:
|
2020-08-06 04:44:05 +01:00
|
|
|
c.logf("unhandled netlink msg type %+v, %q", msg.Header, msg.Data)
|
2020-07-07 18:44:54 +01:00
|
|
|
return unspecifiedMessage{}, nil
|
2020-02-12 20:53:55 +00:00
|
|
|
}
|
2020-07-07 00:36:57 +01:00
|
|
|
}
|
|
|
|
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
func netaddrIP(std net.IP) netip.Addr {
|
2020-07-07 00:36:57 +01:00
|
|
|
ip, _ := netaddr.FromStdIP(std)
|
|
|
|
return ip
|
|
|
|
}
|
|
|
|
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
func netaddrIPPrefix(std net.IP, bits uint8) netip.Prefix {
|
2020-08-12 21:12:56 +01:00
|
|
|
ip, _ := netaddr.FromStdIP(std)
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
return netip.PrefixFrom(ip, int(bits))
|
2020-08-12 21:12:56 +01:00
|
|
|
}
|
|
|
|
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
func condNetAddrPrefix(ipp netip.Prefix) string {
|
2022-07-25 04:08:42 +01:00
|
|
|
if !ipp.Addr().IsValid() {
|
2020-08-12 21:12:56 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return ipp.String()
|
|
|
|
}
|
|
|
|
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
func condNetAddrIP(ip netip.Addr) string {
|
2022-07-25 04:08:42 +01:00
|
|
|
if !ip.IsValid() {
|
2020-08-12 21:12:56 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return ip.String()
|
|
|
|
}
|
|
|
|
|
2020-07-07 00:36:57 +01:00
|
|
|
// newRouteMessage is a message for a new route being added.
|
|
|
|
type newRouteMessage struct {
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
Src, Dst netip.Prefix
|
|
|
|
Gateway netip.Addr
|
2020-08-12 21:12:56 +01:00
|
|
|
Table uint8
|
2020-07-07 00:36:57 +01:00
|
|
|
}
|
|
|
|
|
2020-08-12 21:12:56 +01:00
|
|
|
const tsTable = 52
|
|
|
|
|
2020-07-07 00:36:57 +01:00
|
|
|
func (m *newRouteMessage) ignore() bool {
|
2022-07-25 04:08:42 +01:00
|
|
|
return m.Table == tsTable || tsaddr.IsTailscaleIP(m.Dst.Addr())
|
2020-07-07 00:36:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// newAddrMessage is a message for a new address being added.
|
|
|
|
type newAddrMessage struct {
|
2022-04-08 21:06:40 +01:00
|
|
|
Delete bool
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
Addr netip.Addr
|
2022-04-08 21:06:40 +01:00
|
|
|
IfIndex uint32 // interface index
|
2020-07-07 00:36:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *newAddrMessage) ignore() bool {
|
|
|
|
return tsaddr.IsTailscaleIP(m.Addr)
|
2020-02-12 20:53:55 +00:00
|
|
|
}
|
2020-07-07 19:07:12 +01:00
|
|
|
|
|
|
|
type ignoreMessage struct{}
|
|
|
|
|
|
|
|
func (ignoreMessage) ignore() bool { return true }
|