mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
iptables: remove unused min/max NAT range fields
PiperOrigin-RevId: 334531794
This commit is contained in:
committed by
gVisor bot
parent
e5ece9aea7
commit
0aae51c6e0
@@ -194,11 +194,9 @@ func (*redirectTargetMaker) marshal(target stack.Target) []byte {
|
||||
|
||||
ret := make([]byte, 0, linux.SizeOfXTRedirectTarget)
|
||||
xt.NfRange.RangeSize = 1
|
||||
if rt.RangeProtoSpecified {
|
||||
xt.NfRange.RangeIPV4.Flags |= linux.NF_NAT_RANGE_PROTO_SPECIFIED
|
||||
}
|
||||
xt.NfRange.RangeIPV4.MinPort = htons(rt.MinPort)
|
||||
xt.NfRange.RangeIPV4.MaxPort = htons(rt.MaxPort)
|
||||
xt.NfRange.RangeIPV4.Flags |= linux.NF_NAT_RANGE_PROTO_SPECIFIED
|
||||
xt.NfRange.RangeIPV4.MinPort = htons(rt.Port)
|
||||
xt.NfRange.RangeIPV4.MaxPort = xt.NfRange.RangeIPV4.MinPort
|
||||
return binary.Marshal(ret, usermem.ByteOrder, xt)
|
||||
}
|
||||
|
||||
@@ -231,23 +229,23 @@ func (*redirectTargetMaker) unmarshal(buf []byte, filter stack.IPHeaderFilter) (
|
||||
// Also check if we need to map ports or IP.
|
||||
// For now, redirect target only supports destination port change.
|
||||
// Port range and IP range are not supported yet.
|
||||
if nfRange.RangeIPV4.Flags&linux.NF_NAT_RANGE_PROTO_SPECIFIED == 0 {
|
||||
if nfRange.RangeIPV4.Flags != linux.NF_NAT_RANGE_PROTO_SPECIFIED {
|
||||
nflog("redirectTargetMaker: invalid range flags %d", nfRange.RangeIPV4.Flags)
|
||||
return nil, syserr.ErrInvalidArgument
|
||||
}
|
||||
target.RangeProtoSpecified = true
|
||||
|
||||
target.MinIP = tcpip.Address(nfRange.RangeIPV4.MinIP[:])
|
||||
target.MaxIP = tcpip.Address(nfRange.RangeIPV4.MaxIP[:])
|
||||
|
||||
// TODO(gvisor.dev/issue/170): Port range is not supported yet.
|
||||
if nfRange.RangeIPV4.MinPort != nfRange.RangeIPV4.MaxPort {
|
||||
nflog("redirectTargetMaker: MinPort != MaxPort (%d, %d)", nfRange.RangeIPV4.MinPort, nfRange.RangeIPV4.MaxPort)
|
||||
return nil, syserr.ErrInvalidArgument
|
||||
}
|
||||
if nfRange.RangeIPV4.MinIP != nfRange.RangeIPV4.MaxIP {
|
||||
nflog("redirectTargetMaker: MinIP != MaxIP (%d, %d)", nfRange.RangeIPV4.MinPort, nfRange.RangeIPV4.MaxPort)
|
||||
return nil, syserr.ErrInvalidArgument
|
||||
}
|
||||
|
||||
target.MinPort = ntohs(nfRange.RangeIPV4.MinPort)
|
||||
target.MaxPort = ntohs(nfRange.RangeIPV4.MaxPort)
|
||||
target.Addr = tcpip.Address(nfRange.RangeIPV4.MinIP[:])
|
||||
target.Port = ntohs(nfRange.RangeIPV4.MinPort)
|
||||
|
||||
return &target, nil
|
||||
}
|
||||
|
||||
@@ -281,8 +281,8 @@ func (ct *ConnTrack) insertRedirectConn(pkt *PacketBuffer, hook Hook, rt Redirec
|
||||
// rule. This tuple will be used to manipulate the packet in
|
||||
// handlePacket.
|
||||
replyTID := tid.reply()
|
||||
replyTID.srcAddr = rt.MinIP
|
||||
replyTID.srcPort = rt.MinPort
|
||||
replyTID.srcAddr = rt.Addr
|
||||
replyTID.srcPort = rt.Port
|
||||
var manip manipType
|
||||
switch hook {
|
||||
case Prerouting:
|
||||
|
||||
@@ -128,26 +128,14 @@ func (ReturnTarget) Action(*PacketBuffer, *ConnTrack, Hook, *GSO, *Route, tcpip.
|
||||
const RedirectTargetName = "REDIRECT"
|
||||
|
||||
// RedirectTarget redirects the packet by modifying the destination port/IP.
|
||||
// Min and Max values for IP and Ports in the struct indicate the range of
|
||||
// values which can be used to redirect.
|
||||
// TODO(gvisor.dev/issue/170): Other flags need to be added after we support
|
||||
// them.
|
||||
type RedirectTarget struct {
|
||||
// TODO(gvisor.dev/issue/170): Other flags need to be added after
|
||||
// we support them.
|
||||
// RangeProtoSpecified flag indicates single port is specified to
|
||||
// redirect.
|
||||
RangeProtoSpecified bool
|
||||
// Addr indicates address used to redirect.
|
||||
Addr tcpip.Address
|
||||
|
||||
// MinIP indicates address used to redirect.
|
||||
MinIP tcpip.Address
|
||||
|
||||
// MaxIP indicates address used to redirect.
|
||||
MaxIP tcpip.Address
|
||||
|
||||
// MinPort indicates port used to redirect.
|
||||
MinPort uint16
|
||||
|
||||
// MaxPort indicates port used to redirect.
|
||||
MaxPort uint16
|
||||
// Port indicates port used to redirect.
|
||||
Port uint16
|
||||
|
||||
// NetworkProtocol is the network protocol the target is used with.
|
||||
NetworkProtocol tcpip.NetworkProtocolNumber
|
||||
@@ -180,11 +168,9 @@ func (rt RedirectTarget) Action(pkt *PacketBuffer, ct *ConnTrack, hook Hook, gso
|
||||
// to primary address of the incoming interface in Prerouting.
|
||||
switch hook {
|
||||
case Output:
|
||||
rt.MinIP = tcpip.Address([]byte{127, 0, 0, 1})
|
||||
rt.MaxIP = tcpip.Address([]byte{127, 0, 0, 1})
|
||||
rt.Addr = tcpip.Address([]byte{127, 0, 0, 1})
|
||||
case Prerouting:
|
||||
rt.MinIP = address
|
||||
rt.MaxIP = address
|
||||
rt.Addr = address
|
||||
default:
|
||||
panic("redirect target is supported only on output and prerouting hooks")
|
||||
}
|
||||
@@ -195,7 +181,7 @@ func (rt RedirectTarget) Action(pkt *PacketBuffer, ct *ConnTrack, hook Hook, gso
|
||||
switch protocol := netHeader.TransportProtocol(); protocol {
|
||||
case header.UDPProtocolNumber:
|
||||
udpHeader := header.UDP(pkt.TransportHeader().View())
|
||||
udpHeader.SetDestinationPort(rt.MinPort)
|
||||
udpHeader.SetDestinationPort(rt.Port)
|
||||
|
||||
// Calculate UDP checksum and set it.
|
||||
if hook == Output {
|
||||
@@ -213,7 +199,7 @@ func (rt RedirectTarget) Action(pkt *PacketBuffer, ct *ConnTrack, hook Hook, gso
|
||||
}
|
||||
}
|
||||
// Change destination address.
|
||||
netHeader.SetDestinationAddress(rt.MinIP)
|
||||
netHeader.SetDestinationAddress(rt.Addr)
|
||||
netHeader.SetChecksum(0)
|
||||
netHeader.SetChecksum(^netHeader.CalculateChecksum())
|
||||
pkt.NatDone = true
|
||||
|
||||
Reference in New Issue
Block a user