mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-19 05:02:34 +00:00
wgengine/router: add a addrFamily type [linux]
In prep for more netlink-ification. Change-Id: I7c34a04001988107dc2583597aa4f26ddb887e91
This commit is contained in:
parent
c41fe182f0
commit
19189d7018
@ -748,11 +748,29 @@ func (r *linuxRouter) downInterface() error {
|
|||||||
return netlink.LinkSetDown(link)
|
return netlink.LinkSetDown(link)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *linuxRouter) iprouteFamilies() []string {
|
// addrFamily is an address family: IPv4 or IPv6.
|
||||||
if r.v6Available {
|
type addrFamily byte
|
||||||
return []string{"-4", "-6"}
|
|
||||||
|
const (
|
||||||
|
v4 = addrFamily(4)
|
||||||
|
v6 = addrFamily(6)
|
||||||
|
)
|
||||||
|
|
||||||
|
func (f addrFamily) dashArg() string {
|
||||||
|
switch f {
|
||||||
|
case 4:
|
||||||
|
return "-4"
|
||||||
|
case 6:
|
||||||
|
return "-6"
|
||||||
}
|
}
|
||||||
return []string{"-4"}
|
panic("illegal")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *linuxRouter) addrFamilies() []addrFamily {
|
||||||
|
if r.v6Available {
|
||||||
|
return []addrFamily{v4, v6}
|
||||||
|
}
|
||||||
|
return []addrFamily{v4}
|
||||||
}
|
}
|
||||||
|
|
||||||
// addIPRules adds the policy routing rule that avoids tailscaled
|
// addIPRules adds the policy routing rule that avoids tailscaled
|
||||||
@ -883,10 +901,10 @@ func (r *linuxRouter) justAddIPRules() error {
|
|||||||
|
|
||||||
rg := newRunGroup(nil, r.cmd)
|
rg := newRunGroup(nil, r.cmd)
|
||||||
|
|
||||||
for _, family := range r.iprouteFamilies() {
|
for _, family := range r.addrFamilies() {
|
||||||
for _, r := range ipRules {
|
for _, r := range ipRules {
|
||||||
args := []string{
|
args := []string{
|
||||||
"ip", family,
|
"ip", family.dashArg(),
|
||||||
"rule", "add",
|
"rule", "add",
|
||||||
"pref", strconv.Itoa(r.Priority),
|
"pref", strconv.Itoa(r.Priority),
|
||||||
}
|
}
|
||||||
@ -931,7 +949,7 @@ func (r *linuxRouter) delIPRules() error {
|
|||||||
// unknown rules during deletion.
|
// unknown rules during deletion.
|
||||||
rg := newRunGroup([]int{2, 254}, r.cmd)
|
rg := newRunGroup([]int{2, 254}, r.cmd)
|
||||||
|
|
||||||
for _, family := range r.iprouteFamilies() {
|
for _, family := range r.addrFamilies() {
|
||||||
// When deleting rules, we want to be a bit specific (mention which
|
// When deleting rules, we want to be a bit specific (mention which
|
||||||
// table we were routing to) but not *too* specific (fwmarks, etc).
|
// table we were routing to) but not *too* specific (fwmarks, etc).
|
||||||
// That leaves us some flexibility to change these values in later
|
// That leaves us some flexibility to change these values in later
|
||||||
@ -939,7 +957,7 @@ func (r *linuxRouter) delIPRules() error {
|
|||||||
// combination.
|
// combination.
|
||||||
for _, r := range ipRules {
|
for _, r := range ipRules {
|
||||||
args := []string{
|
args := []string{
|
||||||
"ip", family,
|
"ip", family.dashArg(),
|
||||||
"rule", "del",
|
"rule", "del",
|
||||||
"pref", strconv.Itoa(r.Priority),
|
"pref", strconv.Itoa(r.Priority),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user