Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified dummy_interface struct to add prefixlen along with Address #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions vnet/unix/netlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func (ns *net_namespace) getTuntapInterface(ifindex uint32) (intf *tuntap_interf
type dummy_interface struct {
isAdminUp bool
// Current set of ip4/ip6 addresses for dummy interface collected from netlink IfAddrMessage.
ip4Addrs map[ip4.Address]ip.FibIndex
ip6Addrs map[ip6.Address]ip.FibIndex
ip4Addrs map[ip4.Prefix]ip.FibIndex
ip6Addrs map[ip6.Prefix]ip.FibIndex
}

// True if given netlink NEWLINK message is for a dummy interface as indicated by IFLA_INFO_KIND.
Expand All @@ -141,15 +141,23 @@ func (ns *net_namespace) getDummyInterface(ifindex uint32) (i *dummy_interface,
func (i *dummy_interface) addDelDummyPuntPrefixes(m *Main, isDel bool) {
for addr, fi := range i.ip4Addrs {
m4 := ip4.GetMain(m.v)
p := ip4.Prefix{Address: addr, Len: 32}
p := ip4.Prefix{Address: addr.Address, Len: 32}
q := p.ToIpPrefix()
m4.AddDelRoute(&q, fi, ip.AdjPunt, isDel)

p1 := ip4.Prefix{Address: addr.Address, Len: addr.Len}
q1 := p1.ToIpPrefix()
m4.AddDelRoute(&q1, fi, ip.AdjPunt, isDel)
}
for addr, fi := range i.ip6Addrs {
m6 := ip6.GetMain(m.v)
p := ip6.Prefix{Address: addr, Len: 128}
p := ip6.Prefix{Address: addr.Address, Len: 128}
q := p.ToIpPrefix()
m6.AddDelRoute(&q, fi, ip.AdjPunt, isDel)

p1 := ip6.Prefix{Address: addr.Address, Len: addr.Len}
q1 := p1.ToIpPrefix()
m6.AddDelRoute(&q1, fi, ip.AdjPunt, isDel)
}
}
func (ns *net_namespace) knownInterface(i uint32) (ok bool) {
Expand Down Expand Up @@ -578,16 +586,20 @@ func (e *netlinkEvent) ip4IfaddrMsg(v *netlink.IfAddrMessage) (err error) {
if di, ok := e.ns.getDummyInterface(v.Index); ok {
fi := e.ns.fibIndexForNamespace()
q := p.ToIpPrefix()

p1 := ip4Prefix(v.Attrs[netlink.IFA_ADDRESS], 32)
q1 := p1.ToIpPrefix()
if di.isAdminUp || isDel {
m4.AddDelRoute(&q, fi, ip.AdjPunt, isDel)
m4.AddDelRoute(&q1, fi, ip.AdjPunt, isDel)
}
if isDel {
delete(di.ip4Addrs, p.Address)
delete(di.ip4Addrs, p)
} else {
if di.ip4Addrs == nil {
di.ip4Addrs = make(map[ip4.Address]ip.FibIndex)
di.ip4Addrs = make(map[ip4.Prefix]ip.FibIndex)
}
di.ip4Addrs[p.Address] = fi
di.ip4Addrs[p] = fi
}
} else if si, intf, ok := e.ns.siForIfIndex(v.Index); ok {
e.ns.validateFibIndexForSi(si, intf)
Expand Down