Compare commits

..

2 commits

Author SHA1 Message Date
0d92cd7ba6
Tweak AppleTalk loop 2024-04-12 13:10:04 +10:00
ce3aa5faf5
Add NBP machine (WIP) 2024-04-12 13:09:04 +10:00
3 changed files with 57 additions and 4 deletions

View file

@ -35,6 +35,15 @@ const (
FunctionFwdReq Function = 4
)
func (f Function) String() string {
return map[Function]string{
FunctionBrRq: "BrRq",
FunctionLkUp: "LkUp",
FunctionLkUpReply: "LkUp-Reply",
FunctionFwdReq: "FwdReq",
}[f]
}
// Packet represents an NBP packet.
type Packet struct {
Function Function // top 4 bits of first byte

19
main.go
View file

@ -169,6 +169,14 @@ func main() {
rtmpCh := make(chan *ddp.ExtPacket, 1024)
go rtmpMachine.Run(ctx, rtmpCh)
// --------------------- NBP --------------------
nbpMachine := &NBPMachine{
aarp: aarpMachine,
pcapHandle: pcapHandle,
}
nbpCh := make(chan *ddp.ExtPacket, 1024)
go nbpMachine.Run(ctx, nbpCh)
// ---------- Raw AppleTalk/AARP inbound ----------
go func() {
for {
@ -206,8 +214,8 @@ func main() {
case ethertalk.AppleTalkProto:
// log.Print("Got an AppleTalk frame")
var ddpkt ddp.ExtPacket
if err := ddp.ExtUnmarshal(ethFrame.Payload, &ddpkt); err != nil {
ddpkt := new(ddp.ExtPacket)
if err := ddp.ExtUnmarshal(ethFrame.Payload, ddpkt); err != nil {
log.Printf("Couldn't unmarshal DDP packet: %v", err)
continue
}
@ -245,10 +253,13 @@ func main() {
switch ddpkt.DstSocket {
case 1: // The RTMP socket
rtmpCh <- &ddpkt
rtmpCh <- ddpkt
case 2: // The NIS (NBP socket)
nbpCh <- ddpkt
case 4: // The AEP socket
if err := handleAEP(pcapHandle, myHWAddr, ethFrame.Src, &ddpkt); err != nil {
if err := handleAEP(pcapHandle, myHWAddr, ethFrame.Src, ddpkt); err != nil {
log.Printf("AEP: Couldn't handle: %v", err)
}

33
nbp.go Normal file
View file

@ -0,0 +1,33 @@
package main
import (
"context"
"log"
"gitea.drjosh.dev/josh/jrouter/atalk/nbp"
"github.com/google/gopacket/pcap"
"github.com/sfiera/multitalk/pkg/ddp"
)
type NBPMachine struct {
aarp *AARPMachine
pcapHandle *pcap.Handle
}
func (NBPMachine) Run(ctx context.Context, incoming <-chan *ddp.ExtPacket) error {
for {
select {
case <-ctx.Done():
return ctx.Err()
case ddpkt := <-incoming:
pkt, err := nbp.Unmarshal(ddpkt.Data)
if err != nil {
log.Printf("NBP: invalid packet: %v", err)
continue
}
// TODO:
log.Printf("NBP: Got %v", pkt.Function)
}
}
}