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

Get MAC/IP from traffic [Close #12]

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

@ -24,9 +24,9 @@ var NewIP net.IP
func main() {
// Get command line arguments
logLvl := flag.Int("log", 4, "allowed: 5 (debug), 4 (info), 3 (warning), 2 (error), 1 (fatal)")
oldip := flag.String("oldip", "10.0.0.11", "IP before change")
oldip := flag.String("oldip", "", "IP before change")
newip := flag.String("newip", "10.0.0.15", "IP after change")
oldmac := flag.String("oldmac", "52:54:00:12:34:56", "MAC before change")
oldmac := flag.String("oldmac", "", "MAC before change")
newmac := flag.String("newmac", "52:54:00:12:34:aa", "MAC after change")
passthrough := flag.Bool("passthrough", false, "Whether to pass every traffic through")
proxy := flag.String("proxy", "1", "Number of the proxy switch")
@ -169,6 +169,22 @@ func filterIP(prefix string, dst interface{}, src interface{}, context gopacket.
}
ip, isIp := target.(*net.IP)
bs, isBs := target.(*[]byte)
// If no OldIP is set yet, get it from outgoing src field
if OldIP == nil {
if prefix == cmd.In {
return
} else if prefix == cmd.Out {
if isIp {
OldIP = *ip
} else if isBs {
OldIP = *bs
}
log.Info("OldIP set to ", OldIP)
condVal = OldIP
}
}
if isIp && bytes.Equal(*ip, condVal) {
*ip = newVal
log.Debugf("%s%s %s IP %s changed to %s", prefix, context, which, condVal, newVal)
@ -181,6 +197,17 @@ func filterIP(prefix string, dst interface{}, src interface{}, context gopacket.
// 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 interface{}, src interface{}, context gopacket.LayerType) {
// If no OldMac is set yet, get it from outgoing src field
// Has to be HardwareAddr because this is used for ethernet frames which call this method first
if OldMac == nil {
if prefix == cmd.In {
return
} else if prefix == cmd.Out {
OldMac = *src.(*net.HardwareAddr)
log.Info("OldMac set to ", OldMac)
}
}
var target interface{}
var condVal net.HardwareAddr
var newVal net.HardwareAddr