<div dir="ltr">Hello,<br><br>I've got a problem when using Twisted UDP-based app with IPv6. I know UDP IPv6 is not yet officially supported, I am using the unoffcial hack found somewhere on the net.<br><br>----------------UNOFFICIAL HACK----------------------<br>
In twisted/internet/udp.py:<br><br>(...)<br>    def __init__(self, port, proto, interface='', maxPacketSize=8192, reactor=None):<br>        """<br>        Initialize with a numeric port to listen on.<br>
        """<br>        base.BasePort.__init__(self, reactor)<br>        self.port = port<br>        self.protocol = proto<br>        self.maxPacketSize = maxPacketSize<br>        self.interface = interface<br>
        self.setLogStr()<br>        self._connectedAddr = None<br>+       if interface and abstract.isIPv6Address(interface): ###<br>+          self.addressFamily = socket.AF_INET6 ###<br><br>(...)<br>    def doRead(self):<br>
        """<br>        Called when my socket is ready for reading.<br>        """<br>        read = 0<br>        while read < self.maxThroughput:<br>            try:<br>                data, addr = self.socket.recvfrom(self.maxPacketSize)<br>
            except socket.error as se:<br>                no = se.args[0]<br>                if no in _sockErrReadIgnore:<br>                    return<br>                if no in _sockErrReadRefuse:<br>                    if self._connectedAddr:<br>
                        self.protocol.connectionRefused()<br>                    return<br>                raise<br>            else:<br>                read += len(data)<br>                try:<br>+                 addr = (addr[0], addr[1]) ###<br>
                    self.protocol.datagramReceived(data, addr)<br>                except:<br>                    log.err()<br>--------------END OF UNOFFICIAL HACK------------------------<br><br>I deploy my protocol like that:<br>
<br>reactor.listenUDP(5683, myapp.MyProtocol(), interface="::")<br>reactor.run()<br><br>The problem is: <br>1. My server receives a request from remote client (with destination address being valid global IPv6 address)<br>
2. The server sends a response, but uses different source address (which is also valid and assigned to local wlan0 interface). <br>3. Remote host drops the response (destination address of the request and source address of the response do not match).<br>
<br>It is common for IPv6 interfaces to have multiple global IPv6 addresses - because of privacy reasons (both on Windows and Linux).<br><br>My question is - can I read manually the destination address from the incoming request datagram, and set it as a source address manually in the outgoing response datagram?<br>
<br>Best Regards<br>Maciej Wasilak<br><br></div>