mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
iptables: return the proper revision number
The old implementation was erroneously returning the wrong revision PiperOrigin-RevId: 581400881
This commit is contained in:
committed by
gVisor bot
parent
dbf8cbbe83
commit
4a4e42f34d
@@ -153,24 +153,31 @@ type target interface {
|
||||
// marshals and unmarshals it. It is immutable after package initialization.
|
||||
var targetMakers = map[targetID]targetMaker{}
|
||||
|
||||
// targetRevision returns the maximum supported version of the matcher with
|
||||
// name `name` up to rev, and whether any such matcher with that name exists.
|
||||
func targetRevision(name string, netProto tcpip.NetworkProtocolNumber, rev uint8) (uint8, bool) {
|
||||
tid := targetID{
|
||||
name: name,
|
||||
networkProtocol: netProto,
|
||||
revision: rev,
|
||||
}
|
||||
if _, ok := targetMakers[tid]; !ok {
|
||||
return 0, false
|
||||
if _, ok := targetMakers[tid]; ok {
|
||||
return rev, true
|
||||
}
|
||||
|
||||
// Return the highest supported revision unless rev is higher.
|
||||
for _, other := range targetMakers {
|
||||
otherID := other.id()
|
||||
if name == otherID.name && netProto == otherID.networkProtocol && otherID.revision > rev {
|
||||
rev = uint8(otherID.revision)
|
||||
// Return the highest supported revision.
|
||||
var found bool
|
||||
var ret uint8
|
||||
for _, cur := range targetMakers {
|
||||
curID := cur.id()
|
||||
if name == curID.name && netProto == curID.networkProtocol {
|
||||
found = true
|
||||
if curID.revision > ret {
|
||||
ret = uint8(curID.revision)
|
||||
}
|
||||
}
|
||||
}
|
||||
return rev, true
|
||||
return ret, found
|
||||
}
|
||||
|
||||
// registerTargetMaker should be called by target extensions to register them
|
||||
|
||||
@@ -392,9 +392,13 @@ func TargetRevision(t *kernel.Task, revPtr hostarch.Addr, netProto tcpip.Network
|
||||
}
|
||||
maxSupported, ok := targetRevision(rev.Name.String(), netProto, rev.Revision)
|
||||
if !ok {
|
||||
// Return ENOENT if there's no target with that name.
|
||||
return linux.XTGetRevision{}, syserr.ErrNoFileOrDir
|
||||
}
|
||||
if maxSupported < rev.Revision {
|
||||
// Return EPROTONOSUPPORT if we have an insufficient revision.
|
||||
return linux.XTGetRevision{}, syserr.ErrProtocolNotSupported
|
||||
}
|
||||
rev.Revision = maxSupported
|
||||
return rev, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user