Skip to content

Commit

Permalink
fix(plc4go/bacnet): fix issues with address parsing and vlan
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 13, 2024
1 parent 19f5db7 commit 1f00503
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions plc4go/internal/bacnetip/PDU.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,14 @@ func (a *Address) decodeAddress(addr any) error {
a.AddrSubnet = &addrSubnet

bcast := *a.AddrSubnet | ^(*a.AddrMask)
ipReverse := make(net.IP, 4)
binary.BigEndian.PutUint32(ipReverse, bcast&uint32(_longMask))
a.AddrBroadcastTuple = &AddressTuple[string, uint16]{ipReverse.String(), *a.AddrPort}
bcastIpReverse := make(net.IP, 4)
binary.BigEndian.PutUint32(bcastIpReverse, bcast&uint32(_longMask))
a.AddrBroadcastTuple = &AddressTuple[string, uint16]{bcastIpReverse.String(), *a.AddrPort}
a.log.Debug().Stringer("addrBroadcastTuple", a.AddrBroadcastTuple).Msg("addrBroadcastTuple")

portReverse := make([]byte, 2)
binary.BigEndian.PutUint16(portReverse, *a.AddrPort&uint16(_shortMask))
a.AddrAddress = append(ipReverse, portReverse...)
a.AddrAddress = append(parseAddr.AsSlice(), portReverse...)
addrLen := uint8(6)
a.AddrLen = &addrLen
}
Expand Down Expand Up @@ -357,6 +358,24 @@ func (a *Address) decodeAddress(addr any) error {

return nil
}

if ethernet_re.MatchString(addr) {
panic("implement me") // TODO:
}

// TODO: "^\d+$"
// TODO: "^\d+:[*]$"
// TODO: "^\d+:\d+$"
// TODO: "^0x([0-9A-Fa-f][0-9A-Fa-f])+$"
// TODO: "^X'([0-9A-Fa-f][0-9A-Fa-f])+'$"
// TODO: "^\d+:0x([0-9A-Fa-f][0-9A-Fa-f])+$"
// TODO: "^\d+:X'([0-9A-Fa-f][0-9A-Fa-f])+'$"

if interface_re.MatchString(addr) {
panic("implement me") // TODO:
}

return errors.New("unrecognized format")
case *AddressTuple[string, uint16]:
uaddr, port := addr.Left, addr.Right
a.AddrPort = &port
Expand Down
2 changes: 1 addition & 1 deletion plc4go/internal/bacnetip/vlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (n *Node) Indication(args Args, kwargs KWArgs) error {
// leave it alone to allow for simulated spoofing
pdu := args.Get0PDU()
if pduSource := pdu.GetPDUSource(); pduSource == nil {
pdu.SetPDUDestination(n.address)
pdu.SetPDUSource(n.address)
} else if !n.spoofing && !pduSource.Equals(n.address) {
return errors.Errorf("spoofing address conflict (pduSource: '%s', nodeAddress: '%s').", pduSource, n.address)
}
Expand Down

0 comments on commit 1f00503

Please sign in to comment.