mosers
/
eaas-vde-proxy
Archiviert
1
0
Fork 0

Changed filter method to variable types [Close #13]

main
Simon Moser vor 3 Jahren
Ursprung 57fe77b73f
Commit 7c28b957d4
Signiert von: mosers
GPG-Schlüssel-ID: 96B3365A234B500C

@ -113,8 +113,8 @@ func pipeForward(reader io.Reader, writer io.Writer, prefix string, passthrough
if frame.EthernetType == layers.EthernetTypeARP { if frame.EthernetType == layers.EthernetTypeARP {
arpPacket := packet.Layer(layers.LayerTypeARP).(*layers.ARP) arpPacket := packet.Layer(layers.LayerTypeARP).(*layers.ARP)
log.Debug(prefix, "ARP Type ", arpPacket.Operation) log.Debug(prefix, "ARP Type ", arpPacket.Operation)
filterIPb(prefix, &arpPacket.DstProtAddress, &arpPacket.SourceProtAddress, arpPacket.LayerType()) filterIP(prefix, &arpPacket.DstProtAddress, &arpPacket.SourceProtAddress, arpPacket.LayerType())
filterMACb(prefix, &arpPacket.DstHwAddress, &arpPacket.SourceHwAddress, arpPacket.LayerType()) filterMAC(prefix, &arpPacket.DstHwAddress, &arpPacket.SourceHwAddress, arpPacket.LayerType())
} }
log.Debug("End packet") log.Debug("End packet")
@ -150,9 +150,9 @@ func pipeForward(reader io.Reader, writer io.Writer, prefix string, passthrough
} }
} }
// filterIP checks whether an IP target in net.IP format equals a given value. If yes, it is changed // filterIP checks whether an IP target selected from src and dst equals a given value. If yes, it is changed
func filterIP(prefix string, dst *net.IP, src *net.IP, context gopacket.LayerType) { func filterIP(prefix string, dst interface{}, src interface{}, context gopacket.LayerType) {
var target *net.IP var target interface{}
var condVal net.IP var condVal net.IP
var newVal net.IP var newVal net.IP
var which string var which string
@ -167,38 +167,21 @@ func filterIP(prefix string, dst *net.IP, src *net.IP, context gopacket.LayerTyp
condVal = OldIP condVal = OldIP
newVal = NewIP newVal = NewIP
} }
if bytes.Equal(*target, condVal) { ip, isIp := target.(*net.IP)
*target = newVal bs, isBs := target.(*[]byte)
if isIp && bytes.Equal(*ip, condVal) {
*ip = newVal
log.Debugf("%s%s %s IP %s changed to %s", prefix, context, which, condVal, newVal) log.Debugf("%s%s %s IP %s changed to %s", prefix, context, which, condVal, newVal)
} }
} if isBs && bytes.Equal(*bs, condVal) {
*bs = newVal
// filterIPb checks whether an IP target in []byte format equals a given value. If yes, it is changed
func filterIPb(prefix string, dst *[]byte, src *[]byte, context gopacket.LayerType) {
var target *[]byte
var condVal net.IP
var newVal net.IP
var which string
if prefix == cmd.In {
target = dst
which = "dst"
condVal = NewIP
newVal = OldIP
} else if prefix == cmd.Out {
target = src
which = "src"
condVal = OldIP
newVal = NewIP
}
if bytes.Equal(*target, condVal) {
*target = newVal
log.Debugf("%s%s %s IP %s changed to %s", prefix, context, which, condVal, newVal) log.Debugf("%s%s %s IP %s changed to %s", prefix, context, which, condVal, newVal)
} }
} }
// filterMAC checks whether a MAC target in net.HardwareAddr format equals a given value. If yes, it is changed // filterMAC checks whether a MAC target selected from src and dst equals a given value. If yes, it is changed
func filterMAC(prefix string, dst *net.HardwareAddr, src *net.HardwareAddr, context gopacket.LayerType) { func filterMAC(prefix string, dst interface{}, src interface{}, context gopacket.LayerType) {
var target *net.HardwareAddr var target interface{}
var condVal net.HardwareAddr var condVal net.HardwareAddr
var newVal net.HardwareAddr var newVal net.HardwareAddr
var which string var which string
@ -213,31 +196,14 @@ func filterMAC(prefix string, dst *net.HardwareAddr, src *net.HardwareAddr, cont
condVal = OldMac condVal = OldMac
newVal = NewMac newVal = NewMac
} }
if bytes.Equal(*target, condVal) { mac, isMac := target.(*net.HardwareAddr)
*target = newVal bs, isBs := target.(*[]byte)
if isMac && bytes.Equal(*mac, condVal) {
*mac = newVal
log.Debugf("%s%s %s MAC %s changed to %s", prefix, context, which, condVal, newVal) log.Debugf("%s%s %s MAC %s changed to %s", prefix, context, which, condVal, newVal)
} }
} if isBs && bytes.Equal(*bs, condVal) {
*bs = newVal
// filterMACb checks whether a MAC target in []byte format equals a given value. If yes, it is changed
func filterMACb(prefix string, dst *[]byte, src *[]byte, context gopacket.LayerType) {
var target *[]byte
var condVal net.HardwareAddr
var newVal net.HardwareAddr
var which string
if prefix == cmd.In {
target = dst
which = "dst"
condVal = NewMac
newVal = OldMac
} else if prefix == cmd.Out {
target = src
which = "src"
condVal = OldMac
newVal = NewMac
}
if bytes.Equal(*target, condVal) {
*target = newVal
log.Debugf("%s%s %s MAC %s changed to %s", prefix, context, which, condVal, newVal) log.Debugf("%s%s %s MAC %s changed to %s", prefix, context, which, condVal, newVal)
} }
} }