[sr-dev] [kamailio/kamailio] t_relay() sending packets from the wrong TCP socket (#1532)

Vadim Lebedev vadim at mbdsys.com
Fri Jun 22 10:33:54 CEST 2018


Well i don't want to be nit picking however, i believe you're mistaken
here.  You can reuse port on which you are listening for outgoing
connections too.
You need to use* setsockopt(... SO_REUSEPORT ).*..
here goes the demo:

#!/usr/bin/python3
import socket
import threading


READER1_ADDR = ("127.0.0.1", 23008)
READER2_ADDR = ("127.0.0.1", 23009)



class wait_conn(threading.Thread):
    def __init__(self, addr, name):

        super(wait_conn,self).__init__()

        self.name = name
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
        self.sock.bind(addr)
        self.sock.listen(3)

    def run(self):
        s, a = self.sock.accept()
        print(self.name, ": Incomming connection from: ",  s.getpeername())
        s.close()
        self.sock.close()


t1 = wait_conn(READER1_ADDR, "r1")
t1.start()
t2 = wait_conn(READER2_ADDR, "r2")
t2.start()

w1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
w1.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
w1.bind(READER1_ADDR)
w1.connect(READER2_ADDR)
w1.close()




t1.join(1.0)
t2.join(1.0)




2018-06-21 21:27 GMT+02:00 Daniel-Constantin Mierla <
notifications at github.com>:

> Obviously the difference is that kamailio does bind() and listen() on the
> socket (ip:port) first -- maybe that should have said to be clear about
> what case we talk here. So try with socket(), bind(), listen() and then
> connect().
>
> Once there is listen() on a socket, read events for it mean accept()
> should be done. The kernel won't create an outgoing connection from a
> listen socket, but use ephemeral ports.
>
>> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/kamailio/kamailio/issues/1532#issuecomment-399216138>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AF36ZceX6KXDz8U4aUKDqzbkS-kEvCLiks5t-_OKgaJpZM4UAV3q>
> .
>
> _______________________________________________
> Kamailio (SER) - Development Mailing List
> sr-dev at lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20180622/402e86be/attachment-0002.html>


More information about the sr-dev mailing list