Rx pkt in SUT "from" specific port

13 views
Skip to first unread message

Gary

unread,
Jul 19, 2023, 2:16:28 PM7/19/23
to packetdrill
Hello friends,
My packetdrill script is running on my system under test (SUT). My requirement is to receive (inbound) pkts from (i.e. src_port) a specific port to the SUT. Outbound pkts from the SUT should go to the specific port.

The way I have been able to run packetdrill is by doing a listen on SUT and specifying connect_port as a specific port. This results in inbound pkt to the SUT being to the specific port (dst_port). What is required for my purpose is the src_port  being a specific port. Is there a way I can reverse the roles where I connect() from SUT packetdrill script instead of listen() ?

My current script running on SUT:
============================

// Create a socket.

    0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3

   +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0

   +0 bind(3, ..., ...) = 0

   +0 listen(3, 1) = 0

// Establish a connection.

   +0 < S 0:0(0) win 20000 <mss 1000,sackOK,nop,nop>

   +0 > S. 0:0(0) ack 1 <mss 1460,sackOK,eol,nop>

 +.01 < . 1:1(0) ack 1 win 20000

   +0 accept(3, ..., ...) = 4

----- BLAH BLAH ----

 +0 close(4) = 0

   +0 > F. 1:1(0) ack 1001 win 65535

 +0 < . 1001:1001(0) ack 2 win 20000

=======

My current cmd lines

==================

On SUT

packetdrill --wire_client --wire_client_dev=<client_dev>  --wire_server_ip=<server_ip> /data/packetdrill/test.pkl --remote_ip=<remote_ip> --local_ip=<local_ip> --gateway_ip=<gateway_ip>  --wire_client_mac=<client_mac> -v --bind_port <bind_port> --connect_port <connect_port> 

On peer

packetdrill --wire_server -v --wire_server_dev=<server_dev>  --bind_port <bind_port> --connect_port <connect_port>

Here in my case bind_port and connect_port are the same and is the specific port I want to receive pkts from (src_port) instead to transmitting to (dst_port) from SUT point of view.

Would appreciate any help on this

Thanks


Neal Cardwell

unread,
Jul 19, 2023, 6:11:31 PM7/19/23
to Gary, packetdrill
Hi,

It sounds like you would need to implement a new packetdrill feature, by changing this line:

This line looks like the following:
   socket->live.remote.port = htons(next_ephemeral_port(state));
That is the line that picks a random source port for incoming TCP SYN packets.

Unfortunately, I don't have time to implement such a feature, but perhaps that pointer can help you or someone else get started on implementing something.

best regards,
neal


--
You received this message because you are subscribed to the Google Groups "packetdrill" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packetdrill...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packetdrill/2eeaf59e-7fde-4272-ac60-d7c969fd8370n%40googlegroups.com.

Gary

unread,
Jul 20, 2023, 2:08:43 AM7/20/23
to Neal Cardwell, packetdrill
Hi Neal,
Thanks for the reply.
I'm not sure the problem statement is clear though.
What I need is the remote peer to have a  src port which is specific. Ideally I would need the remote peer to be listening (and bind to the specific port) and local SUT (where the pktdrill script runs) to do the connect() socket call (instead of the listen())

Regards,
Gary

Neal Cardwell

unread,
Jul 20, 2023, 9:23:37 AM7/20/23
to Gary, packetdrill
Hi Gary,

OK, if you want the local SUT to do the connect, then you can have the script specify a connect() system call (packetdrill scripts specify the sequence of system calls that should happen on the SUT). Here's an example:

Then you can control the port packetdrill uses for the destination of the connect using the --connect_port=1234 option. As a corollary that will also set the source port for the incoming packets to be the given port. That should meet the requirements you mentioned ("My requirement is to receive (inbound) pkts from (i.e. src_port) a specific port to the SUT. Outbound pkts from the SUT should go to the specific port.").

best regards,
neal


Gary

unread,
Jul 20, 2023, 11:47:10 AM7/20/23
to Neal Cardwell, packetdrill
Thanks a ton Neal !
Really appreciate it.
Reply all
Reply to author
Forward
0 new messages