|
|
@ -24,9 +24,9 @@ var NewIP net.IP
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
// Get command line arguments
|
|
|
|
// Get command line arguments
|
|
|
|
logLvl := flag.Int("log", 4, "allowed: 5 (debug), 4 (info), 3 (warning), 2 (error), 1 (fatal)")
|
|
|
|
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")
|
|
|
|
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")
|
|
|
|
newmac := flag.String("newmac", "52:54:00:12:34:aa", "MAC after change")
|
|
|
|
passthrough := flag.Bool("passthrough", false, "Whether to pass every traffic through")
|
|
|
|
passthrough := flag.Bool("passthrough", false, "Whether to pass every traffic through")
|
|
|
|
proxy := flag.String("proxy", "1", "Number of the proxy switch")
|
|
|
|
proxy := flag.String("proxy", "1", "Number of the proxy switch")
|
|
|
@ -78,7 +78,7 @@ func pipeForward(reader io.Reader, writer io.Writer, prefix string, passthrough
|
|
|
|
// Handle IPv6 packet
|
|
|
|
// Handle IPv6 packet
|
|
|
|
if ipv4layer := packet.Layer(layers.LayerTypeIPv4); ipv4layer != nil {
|
|
|
|
if ipv4layer := packet.Layer(layers.LayerTypeIPv4); ipv4layer != nil {
|
|
|
|
ipv4Packet, _ := ipv4layer.(*layers.IPv4)
|
|
|
|
ipv4Packet, _ := ipv4layer.(*layers.IPv4)
|
|
|
|
log.Debug("IP Protocol", ipv4Packet.Protocol)
|
|
|
|
log.Debug("IP Protocol ", ipv4Packet.Protocol)
|
|
|
|
filterIP(prefix, &ipv4Packet.DstIP, &ipv4Packet.SrcIP, ipv4Packet.LayerType())
|
|
|
|
filterIP(prefix, &ipv4Packet.DstIP, &ipv4Packet.SrcIP, ipv4Packet.LayerType())
|
|
|
|
|
|
|
|
|
|
|
|
// Handle ICMP packet (based on IPv4)
|
|
|
|
// Handle ICMP packet (based on IPv4)
|
|
|
@ -169,6 +169,22 @@ func filterIP(prefix string, dst interface{}, src interface{}, context gopacket.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ip, isIp := target.(*net.IP)
|
|
|
|
ip, isIp := target.(*net.IP)
|
|
|
|
bs, isBs := target.(*[]byte)
|
|
|
|
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) {
|
|
|
|
if isIp && bytes.Equal(*ip, condVal) {
|
|
|
|
*ip = newVal
|
|
|
|
*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)
|
|
|
@ -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
|
|
|
|
// 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) {
|
|
|
|
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 target interface{}
|
|
|
|
var condVal net.HardwareAddr
|
|
|
|
var condVal net.HardwareAddr
|
|
|
|
var newVal net.HardwareAddr
|
|
|
|
var newVal net.HardwareAddr
|
|
|
|