@@ -11,7 +11,6 @@ import (
1111 "encoding/binary"
1212 "errors"
1313 "fmt"
14- "net"
1514 "sync"
1615
1716 zmq "github.com/pebbe/zmq4"
@@ -57,7 +56,7 @@ type zmqSender interface {
5756}
5857
5958type ipSelector interface {
60- Select ([]byte , uint , uint , bool ) (net. IP , error )
59+ Select ([]byte , uint , uint , bool ) (* lib. PhantomIP , error )
6160}
6261
6362// RegProcessor provides an interface to publish registrations and helper functions to process registration requests
@@ -276,6 +275,7 @@ func (p *RegProcessor) processBdReq(c2sPayload *pb.C2SWrapper) (*pb.Registration
276275 return nil , ErrRegProcessFailed
277276 }
278277
278+ phantomSubnetSupportsRandPort := false
279279 if c2s .GetV4Support () {
280280 p .selectorMutex .RLock ()
281281 defer p .selectorMutex .RUnlock ()
@@ -292,6 +292,7 @@ func (p *RegProcessor) processBdReq(c2sPayload *pb.C2SWrapper) (*pb.Registration
292292
293293 addr4 := binary .BigEndian .Uint32 (phantom4 .To4 ())
294294 regResp .Ipv4Addr = & addr4
295+ phantomSubnetSupportsRandPort = phantom4 .SupportsPortRand
295296 }
296297
297298 if c2s .GetV6Support () {
@@ -307,7 +308,8 @@ func (p *RegProcessor) processBdReq(c2sPayload *pb.C2SWrapper) (*pb.Registration
307308 return nil , err
308309 }
309310
310- regResp .Ipv6Addr = phantom6
311+ regResp .Ipv6Addr = * phantom6 .IP
312+ phantomSubnetSupportsRandPort = phantom6 .SupportsPortRand
311313 }
312314
313315 transportType := c2s .GetTransport ()
@@ -322,15 +324,22 @@ func (p *RegProcessor) processBdReq(c2sPayload *pb.C2SWrapper) (*pb.Registration
322324 return nil , fmt .Errorf ("failed to parse transport parameters: %w" , err )
323325 }
324326
325- dstPort , err := t .GetDstPort (uint (c2s .GetClientLibVersion ()), cjkeys .ConjureSeed , params )
326- if err != nil {
327- return nil , fmt .Errorf ("error determining destination port: %w" , err )
328- }
327+ if phantomSubnetSupportsRandPort {
328+ dstPort , err := t .GetDstPort (uint (c2s .GetClientLibVersion ()), cjkeys .ConjureSeed , params )
329+ if err != nil {
330+ return nil , fmt .Errorf ("error determining destination port: %w" , err )
331+ }
329332
330- // we have to cast to uint32 because protobuf using varint for all int / uint types and doesn't
331- // have an outward facing uint16 type.
332- port := uint32 (dstPort )
333- regResp .DstPort = & port
333+ // we have to cast to uint32 because protobuf using varint for all int / uint types and doesn't
334+ // have an outward facing uint16 type.
335+
336+ port := uint32 (dstPort )
337+ regResp .DstPort = & port
338+ } else {
339+ port := uint32 (443 )
340+ regResp .DstPort = & port
341+
342+ }
334343
335344 // Overrides will modify the C2SWrapper and put the updated registrationResponse inside to be
336345 // forwarded to the station.
0 commit comments