Compare commits

..

No commits in common. "f53f0233a91d5d00c5dcb7af5342d60d6c248e32" and "07e4e5069fb13977722265cc07af6b92241b8afe" have entirely different histories.

7 changed files with 37 additions and 50 deletions

View file

@ -20,7 +20,6 @@ import (
"math/bits" "math/bits"
"github.com/sfiera/multitalk/pkg/ethernet" "github.com/sfiera/multitalk/pkg/ethernet"
"github.com/sfiera/multitalk/pkg/ethertalk"
) )
// Inside AppleTalk, appendix D // Inside AppleTalk, appendix D
@ -97,10 +96,6 @@ func ToUpper(s string) string {
} }
func MulticastAddr(zone string) ethernet.Addr { func MulticastAddr(zone string) ethernet.Addr {
if zone == "" || zone == "*" {
return ethertalk.AppleTalkBroadcast
}
// Inside AppleTalk, pp 3-10 and pp 8-18 // Inside AppleTalk, pp 3-10 and pp 8-18
h := Checksum(ToUpper(zone)) h := Checksum(ToUpper(zone))
return ethernet.Addr{0x09, 0x00, 0x07, 0x00, 0x00, byte(h % 0xFD)} return ethernet.Addr{0x09, 0x00, 0x07, 0x00, 0x00, byte(h % 0xFD)}

10
main.go
View file

@ -341,7 +341,7 @@ func main() {
} }
case 6: // The ZIS (zone information socket / ZIP socket) case 6: // The ZIS (zone information socket / ZIP socket)
if err := rooter.HandleZIP(ctx, ethFrame.Src, ddpkt); err != nil { if err := rooter.HandleZIP(ethFrame.Src, ddpkt); err != nil {
log.Printf("ZIP: couldn't handle: %v", err) log.Printf("ZIP: couldn't handle: %v", err)
} }
@ -474,7 +474,13 @@ func main() {
} }
// Note: resolving AARP can block // Note: resolving AARP can block
if err := rooter.SendEtherTalkDDP(ctx, ddpkt); err != nil { dstEth, err := aarpMachine.Resolve(ctx, ddp.Addr{Network: ddpkt.DstNet, Node: ddpkt.DstNode})
if err != nil {
log.Printf("DDP/AURP: couldn't resolve DDP dest %d.%d to an Ethernet address", ddpkt.DstNet, ddpkt.DstNode)
continue
}
if err := rooter.SendEtherTalkDDP(dstEth, ddpkt); err != nil {
log.Printf("DDP/AURP: couldn't send Ethertalk out: %v", err) log.Printf("DDP/AURP: couldn't send Ethertalk out: %v", err)
} }
continue continue

View file

@ -47,7 +47,7 @@ func (rtr *Router) HandleAEP(src ethernet.Addr, ddpkt *ddp.ExtPacket) error {
ddpkt.DstSocket, ddpkt.SrcSocket = ddpkt.SrcSocket, ddpkt.DstSocket ddpkt.DstSocket, ddpkt.SrcSocket = ddpkt.SrcSocket, ddpkt.DstSocket
ddpkt.Data[0] = byte(aep.EchoReply) ddpkt.Data[0] = byte(aep.EchoReply)
return rtr.sendEtherTalkDDP(src, ddpkt) return rtr.SendEtherTalkDDP(src, ddpkt)
default: default:
return fmt.Errorf("invalid AEP function %d", ep.Function) return fmt.Errorf("invalid AEP function %d", ep.Function)

View file

@ -24,6 +24,7 @@ import (
"gitea.drjosh.dev/josh/jrouter/atalk/nbp" "gitea.drjosh.dev/josh/jrouter/atalk/nbp"
"github.com/sfiera/multitalk/pkg/ddp" "github.com/sfiera/multitalk/pkg/ddp"
"github.com/sfiera/multitalk/pkg/ethernet" "github.com/sfiera/multitalk/pkg/ethernet"
"github.com/sfiera/multitalk/pkg/ethertalk"
) )
func (rtr *Router) HandleNBP(srcHWAddr ethernet.Addr, ddpkt *ddp.ExtPacket) error { func (rtr *Router) HandleNBP(srcHWAddr ethernet.Addr, ddpkt *ddp.ExtPacket) error {
@ -46,12 +47,17 @@ func (rtr *Router) HandleNBP(srcHWAddr ethernet.Addr, ddpkt *ddp.ExtPacket) erro
return err return err
} }
log.Print("NBP: Replying to LkUp with LkUp-Reply for myself") log.Print("NBP: Replying to LkUp with LkUp-Reply for myself")
return rtr.sendEtherTalkDDP(srcHWAddr, outDDP) return rtr.SendEtherTalkDDP(srcHWAddr, outDDP)
case nbp.FunctionBrRq: case nbp.FunctionBrRq:
// There must be 1! // There must be 1!
tuple := &nbpkt.Tuples[0] tuple := &nbpkt.Tuples[0]
ethDst := ethertalk.AppleTalkBroadcast
if tuple.Zone != "*" && tuple.Zone != "" {
ethDst = atalk.MulticastAddr(tuple.Zone)
}
zones := rtr.ZoneTable.LookupName(tuple.Zone) zones := rtr.ZoneTable.LookupName(tuple.Zone)
for _, z := range zones { for _, z := range zones {
if z.Local { if z.Local {
@ -71,11 +77,10 @@ func (rtr *Router) HandleNBP(srcHWAddr ethernet.Addr, ddpkt *ddp.ExtPacket) erro
outDDP := *ddpkt outDDP := *ddpkt
outDDP.Size = uint16(len(nbpRaw)) + atalk.DDPExtHeaderSize outDDP.Size = uint16(len(nbpRaw)) + atalk.DDPExtHeaderSize
outDDP.DstNet = 0x0000 // Local network broadcast outDDP.DstNode = 0xFF // Broadcast node address within the dest network
outDDP.DstNode = 0xFF // Broadcast node address within the dest network
outDDP.Data = nbpRaw outDDP.Data = nbpRaw
if err := rtr.ZoneMulticastEtherTalkDDP(tuple.Zone, &outDDP); err != nil { if err := rtr.SendEtherTalkDDP(ethDst, &outDDP); err != nil {
return err return err
} }
@ -88,7 +93,7 @@ func (rtr *Router) HandleNBP(srcHWAddr ethernet.Addr, ddpkt *ddp.ExtPacket) erro
continue continue
} }
log.Print("NBP: Replying to BrRq with LkUp-Reply for myself") log.Print("NBP: Replying to BrRq with LkUp-Reply for myself")
if err := rtr.sendEtherTalkDDP(srcHWAddr, outDDP2); err != nil { if err := rtr.SendEtherTalkDDP(srcHWAddr, outDDP2); err != nil {
return err return err
} }

View file

@ -20,8 +20,10 @@ import (
"fmt" "fmt"
"log" "log"
"gitea.drjosh.dev/josh/jrouter/atalk"
"gitea.drjosh.dev/josh/jrouter/atalk/nbp" "gitea.drjosh.dev/josh/jrouter/atalk/nbp"
"github.com/sfiera/multitalk/pkg/ddp" "github.com/sfiera/multitalk/pkg/ddp"
"github.com/sfiera/multitalk/pkg/ethertalk"
) )
func (rtr *Router) HandleNBPInAURP(peer *Peer, ddpkt *ddp.ExtPacket) error { func (rtr *Router) HandleNBPInAURP(peer *Peer, ddpkt *ddp.ExtPacket) error {
@ -65,7 +67,11 @@ func (rtr *Router) HandleNBPInAURP(peer *Peer, ddpkt *ddp.ExtPacket) error {
ddpkt.DstNode = 0xFF // Broadcast node address within the dest network ddpkt.DstNode = 0xFF // Broadcast node address within the dest network
ddpkt.Data = nbpRaw ddpkt.Data = nbpRaw
if err := rtr.ZoneMulticastEtherTalkDDP(tuple.Zone, ddpkt); err != nil { dstEth := ethertalk.AppleTalkBroadcast
if tuple.Zone != "*" && tuple.Zone != "" {
dstEth = atalk.MulticastAddr(tuple.Zone)
}
if err := rtr.SendEtherTalkDDP(dstEth, ddpkt); err != nil {
return err return err
} }

View file

@ -17,9 +17,6 @@
package router package router
import ( import (
"context"
"gitea.drjosh.dev/josh/jrouter/atalk"
"github.com/google/gopacket/pcap" "github.com/google/gopacket/pcap"
"github.com/sfiera/multitalk/pkg/ddp" "github.com/sfiera/multitalk/pkg/ddp"
"github.com/sfiera/multitalk/pkg/ethernet" "github.com/sfiera/multitalk/pkg/ethernet"
@ -27,36 +24,15 @@ import (
) )
type Router struct { type Router struct {
Config *Config Config *Config
PcapHandle *pcap.Handle PcapHandle *pcap.Handle
MyHWAddr ethernet.Addr MyHWAddr ethernet.Addr
MyDDPAddr ddp.Addr MyDDPAddr ddp.Addr
AARPMachine *AARPMachine RouteTable *RoutingTable
RouteTable *RoutingTable ZoneTable *ZoneTable
ZoneTable *ZoneTable
} }
func (rtr *Router) SendEtherTalkDDP(ctx context.Context, pkt *ddp.ExtPacket) error { func (rtr *Router) SendEtherTalkDDP(dstEth ethernet.Addr, pkt *ddp.ExtPacket) error {
dstEth := ethertalk.AppleTalkBroadcast
if pkt.DstNode != 0xFF {
de, err := rtr.AARPMachine.Resolve(ctx, ddp.Addr{Network: pkt.DstNet, Node: pkt.DstNode})
if err != nil {
return err
}
dstEth = de
}
return rtr.sendEtherTalkDDP(dstEth, pkt)
}
func (rtr *Router) BroadcastEtherTalkDDP(pkt *ddp.ExtPacket) error {
return rtr.sendEtherTalkDDP(ethertalk.AppleTalkBroadcast, pkt)
}
func (rtr *Router) ZoneMulticastEtherTalkDDP(zone string, pkt *ddp.ExtPacket) error {
return rtr.sendEtherTalkDDP(atalk.MulticastAddr(zone), pkt)
}
func (rtr *Router) sendEtherTalkDDP(dstEth ethernet.Addr, pkt *ddp.ExtPacket) error {
outFrame, err := ethertalk.AppleTalk(rtr.MyHWAddr, *pkt) outFrame, err := ethertalk.AppleTalk(rtr.MyHWAddr, *pkt)
if err != nil { if err != nil {
return err return err

View file

@ -17,7 +17,6 @@
package router package router
import ( import (
"context"
"fmt" "fmt"
"log" "log"
@ -29,7 +28,7 @@ import (
"github.com/sfiera/multitalk/pkg/ethertalk" "github.com/sfiera/multitalk/pkg/ethertalk"
) )
func (rtr *Router) HandleZIP(ctx context.Context, srcHWAddr ethernet.Addr, ddpkt *ddp.ExtPacket) error { func (rtr *Router) HandleZIP(srcHWAddr ethernet.Addr, ddpkt *ddp.ExtPacket) error {
switch ddpkt.Proto { switch ddpkt.Proto {
case ddp.ProtoATP: case ddp.ProtoATP:
atpkt, err := atp.UnmarshalPacket(ddpkt.Data) atpkt, err := atp.UnmarshalPacket(ddpkt.Data)
@ -107,7 +106,7 @@ func (rtr *Router) HandleZIP(ctx context.Context, srcHWAddr ethernet.Addr, ddpkt
}, },
Data: ddpBody, Data: ddpBody,
} }
return rtr.sendEtherTalkDDP(srcHWAddr, respDDP) return rtr.SendEtherTalkDDP(srcHWAddr, respDDP)
case *atp.TResp: case *atp.TResp:
return fmt.Errorf("TODO: support handling ZIP ATP replies?") return fmt.Errorf("TODO: support handling ZIP ATP replies?")
@ -146,7 +145,7 @@ func (rtr *Router) HandleZIP(ctx context.Context, srcHWAddr ethernet.Addr, ddpkt
}, },
Data: respRaw, Data: respRaw,
} }
return rtr.sendEtherTalkDDP(srcHWAddr, outDDP) return rtr.SendEtherTalkDDP(srcHWAddr, outDDP)
} }
// Inside AppleTalk SE, pp 8-11: // Inside AppleTalk SE, pp 8-11:
@ -273,7 +272,7 @@ func (rtr *Router) HandleZIP(ctx context.Context, srcHWAddr ethernet.Addr, ddpkt
dstEth = srcHWAddr dstEth = srcHWAddr
} }
return rtr.sendEtherTalkDDP(dstEth, outDDP) return rtr.SendEtherTalkDDP(dstEth, outDDP)
default: default:
return fmt.Errorf("TODO: handle type %T", zipkt) return fmt.Errorf("TODO: handle type %T", zipkt)