Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: udp conntrack for lan interface #699

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LostAttractor
Copy link
Contributor

@LostAttractor LostAttractor commented Nov 15, 2024

Background

Previously, the wan interface had implemented udp conntrack
This PR implemented udp conntrack for lan interface.

Checklist

Full Changelogs

  • Implement udp conntrack for lan interface.

Test Result

You can use those python codes for testing,
Try to initiate a request from wan to lan. You should be able to observe that DAE skips the packet instead of routing it.
You could try to have reply packets routed to a node and observe whether dae0 has the reply packet.

server:

import socket

def udp_server(host='::', port=12345):
    """A UDP server supporting IPv6 and proper cleanup."""
    server_socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
    try:
        server_socket.bind((host, port))
        print(f"UDP server listening on [{host}]:{port}")

        while True:
            message, client_address = server_socket.recvfrom(1024)  # Buffer size 1024 bytes
            print(f"Received message: {message.decode()} from {client_address}")
            server_socket.sendto(b"ACK", client_address)
    except KeyboardInterrupt:
        print("Server shutting down...")
    finally:
        server_socket.close()
        print("Socket closed.")

if __name__ == "__main__":
    udp_server()

client:

import socket

def udp_client(host="::", port=12345):
    # Detect address family based on the provided server_host
    addr_info = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_DGRAM)

    # Use the first address returned (IPv6 preferred if available)
    family, socktype, proto, canonname, sockaddr = addr_info[0]

    client_socket = socket.socket(family, socktype, proto)
    client_socket.settimeout(2)  # Timeout for the response

    try:
        client_socket.sendto(b"Test", sockaddr)
        print(f"Sent to {sockaddr}")

        response, server = client_socket.recvfrom(1024)
        print(f"Received response: {response.decode()} from {server}")
    except socket.timeout:
        print("No response received, server might be unreachable.")
    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        client_socket.close()
        print("Client socket closed.")

if __name__ == "__main__":
    udp_client(host="127.0.0.1", port=23339)

@LostAttractor LostAttractor marked this pull request as ready for review November 25, 2024 03:19
@LostAttractor LostAttractor requested a review from a team as a code owner November 25, 2024 03:19
@LostAttractor LostAttractor marked this pull request as draft November 25, 2024 04:14
@jschwinger233
Copy link
Member

Would you like to add some test as part of CI? I'm inclined to cover this in bpf unit test.

@LostAttractor
Copy link
Contributor Author

LostAttractor commented Nov 25, 2024

Would you like to add some test as part of CI? I'm inclined to cover this in bpf unit test.

I write some simple python udp server/client for testing the symmetric udp datapath.
But it seems that udp conntrack is not working, even udp conntrack for wan interface in the main branch is not working
I remember it used to be worked, and I needed some time to figure it out.

I don’t know much about the CI for dae or for ebpf part. But I will have a try.

@LostAttractor
Copy link
Contributor Author

LostAttractor commented Nov 26, 2024

Would you like to add some test as part of CI? I'm inclined to cover this in bpf unit test.

I write some simple python udp server/client for testing the symmetric udp datapath. But it seems that udp conntrack is not working, even udp conntrack for wan interface in the main branch is not working I remember it used to be worked, and I needed some time to figure it out.

I don’t know much about the CI for dae or for ebpf part. But I will have a try.

There is no problem with the code. My unit tests are not working correctly, but I have completed some debugging functions. Since I use ipv6 for testing, my device has multiple addresses, and SOCK_DRGAM uses the default route with SLAAC address by default (instead of symmetric routing). This is inconsistent with the address used by my DNS server by default, causing the test failed.

I have already added the python code for testing in test result section.
Should I keep this pr as draft until I finish the CI part?

@LostAttractor LostAttractor force-pushed the udp_conntrack branch 2 times, most recently from 5e79db6 to e35c1b3 Compare November 26, 2024 03:40
@LostAttractor LostAttractor marked this pull request as ready for review December 25, 2024 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants