Compare commits
No commits in common. "f53f0233a91d5d00c5dcb7af5342d60d6c248e32" and "07e4e5069fb13977722265cc07af6b92241b8afe" have entirely different histories.
f53f0233a9
...
07e4e5069f
7 changed files with 37 additions and 50 deletions
|
@ -20,7 +20,6 @@ import (
|
|||
"math/bits"
|
||||
|
||||
"github.com/sfiera/multitalk/pkg/ethernet"
|
||||
"github.com/sfiera/multitalk/pkg/ethertalk"
|
||||
)
|
||||
|
||||
// Inside AppleTalk, appendix D
|
||||
|
@ -97,10 +96,6 @@ func ToUpper(s string) string {
|
|||
}
|
||||
|
||||
func MulticastAddr(zone string) ethernet.Addr {
|
||||
if zone == "" || zone == "*" {
|
||||
return ethertalk.AppleTalkBroadcast
|
||||
}
|
||||
|
||||
// Inside AppleTalk, pp 3-10 and pp 8-18
|
||||
h := Checksum(ToUpper(zone))
|
||||
return ethernet.Addr{0x09, 0x00, 0x07, 0x00, 0x00, byte(h % 0xFD)}
|
||||
|
|
10
main.go
10
main.go
|
@ -341,7 +341,7 @@ func main() {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -474,7 +474,13 @@ func main() {
|
|||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
continue
|
||||
|
|
|
@ -47,7 +47,7 @@ func (rtr *Router) HandleAEP(src ethernet.Addr, ddpkt *ddp.ExtPacket) error {
|
|||
ddpkt.DstSocket, ddpkt.SrcSocket = ddpkt.SrcSocket, ddpkt.DstSocket
|
||||
ddpkt.Data[0] = byte(aep.EchoReply)
|
||||
|
||||
return rtr.sendEtherTalkDDP(src, ddpkt)
|
||||
return rtr.SendEtherTalkDDP(src, ddpkt)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("invalid AEP function %d", ep.Function)
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
"gitea.drjosh.dev/josh/jrouter/atalk/nbp"
|
||||
"github.com/sfiera/multitalk/pkg/ddp"
|
||||
"github.com/sfiera/multitalk/pkg/ethernet"
|
||||
"github.com/sfiera/multitalk/pkg/ethertalk"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
log.Print("NBP: Replying to LkUp with LkUp-Reply for myself")
|
||||
return rtr.sendEtherTalkDDP(srcHWAddr, outDDP)
|
||||
return rtr.SendEtherTalkDDP(srcHWAddr, outDDP)
|
||||
|
||||
case nbp.FunctionBrRq:
|
||||
// There must be 1!
|
||||
tuple := &nbpkt.Tuples[0]
|
||||
|
||||
ethDst := ethertalk.AppleTalkBroadcast
|
||||
if tuple.Zone != "*" && tuple.Zone != "" {
|
||||
ethDst = atalk.MulticastAddr(tuple.Zone)
|
||||
}
|
||||
|
||||
zones := rtr.ZoneTable.LookupName(tuple.Zone)
|
||||
for _, z := range zones {
|
||||
if z.Local {
|
||||
|
@ -71,11 +77,10 @@ func (rtr *Router) HandleNBP(srcHWAddr ethernet.Addr, ddpkt *ddp.ExtPacket) erro
|
|||
|
||||
outDDP := *ddpkt
|
||||
outDDP.Size = uint16(len(nbpRaw)) + atalk.DDPExtHeaderSize
|
||||
outDDP.DstNet = 0x0000 // Local network broadcast
|
||||
outDDP.DstNode = 0xFF // Broadcast node address within the dest network
|
||||
outDDP.Data = nbpRaw
|
||||
|
||||
if err := rtr.ZoneMulticastEtherTalkDDP(tuple.Zone, &outDDP); err != nil {
|
||||
if err := rtr.SendEtherTalkDDP(ethDst, &outDDP); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -88,7 +93,7 @@ func (rtr *Router) HandleNBP(srcHWAddr ethernet.Addr, ddpkt *ddp.ExtPacket) erro
|
|||
continue
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,10 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
|
||||
"gitea.drjosh.dev/josh/jrouter/atalk"
|
||||
"gitea.drjosh.dev/josh/jrouter/atalk/nbp"
|
||||
"github.com/sfiera/multitalk/pkg/ddp"
|
||||
"github.com/sfiera/multitalk/pkg/ethertalk"
|
||||
)
|
||||
|
||||
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.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
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,6 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.drjosh.dev/josh/jrouter/atalk"
|
||||
"github.com/google/gopacket/pcap"
|
||||
"github.com/sfiera/multitalk/pkg/ddp"
|
||||
"github.com/sfiera/multitalk/pkg/ethernet"
|
||||
|
@ -31,32 +28,11 @@ type Router struct {
|
|||
PcapHandle *pcap.Handle
|
||||
MyHWAddr ethernet.Addr
|
||||
MyDDPAddr ddp.Addr
|
||||
AARPMachine *AARPMachine
|
||||
RouteTable *RoutingTable
|
||||
ZoneTable *ZoneTable
|
||||
}
|
||||
|
||||
func (rtr *Router) SendEtherTalkDDP(ctx context.Context, 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 {
|
||||
func (rtr *Router) SendEtherTalkDDP(dstEth ethernet.Addr, pkt *ddp.ExtPacket) error {
|
||||
outFrame, err := ethertalk.AppleTalk(rtr.MyHWAddr, *pkt)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
|
@ -29,7 +28,7 @@ import (
|
|||
"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 {
|
||||
case ddp.ProtoATP:
|
||||
atpkt, err := atp.UnmarshalPacket(ddpkt.Data)
|
||||
|
@ -107,7 +106,7 @@ func (rtr *Router) HandleZIP(ctx context.Context, srcHWAddr ethernet.Addr, ddpkt
|
|||
},
|
||||
Data: ddpBody,
|
||||
}
|
||||
return rtr.sendEtherTalkDDP(srcHWAddr, respDDP)
|
||||
return rtr.SendEtherTalkDDP(srcHWAddr, respDDP)
|
||||
|
||||
case *atp.TResp:
|
||||
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,
|
||||
}
|
||||
return rtr.sendEtherTalkDDP(srcHWAddr, outDDP)
|
||||
return rtr.SendEtherTalkDDP(srcHWAddr, outDDP)
|
||||
}
|
||||
|
||||
// Inside AppleTalk SE, pp 8-11:
|
||||
|
@ -273,7 +272,7 @@ func (rtr *Router) HandleZIP(ctx context.Context, srcHWAddr ethernet.Addr, ddpkt
|
|||
dstEth = srcHWAddr
|
||||
}
|
||||
|
||||
return rtr.sendEtherTalkDDP(dstEth, outDDP)
|
||||
return rtr.SendEtherTalkDDP(dstEth, outDDP)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("TODO: handle type %T", zipkt)
|
||||
|
|
Loading…
Reference in a new issue