I'm trying to understand, once a packet reaches the WireGuard interface (wg0
) how is it sent to the UDP port from where it can be sent to the receiving peer.
I was reading the WireGuard whitepaper and it says
The interface itself has a private key and a UDP port on which it listens (more on that later), followed by a list of peers
I have only an elementary understanding of networking but I thought processes listen on ports so what does it mean for a network interface to listen on a UDP port?
If there is some way for a network interface to listen to a port, then on the receiving peer, the packet can likewise be received on the WireGuard interface from the UDP port. Is this a correct understanding?
WireGuard does create an UDP socket and binds it to an address with special kernel functions:
sock_create_kern
andkernel_bind
.Here is WireGuard's source code for creating the IPv4 socket. There is a similar code for the IPv6 socket.
WireGuard binds the socket to an UDP tunnel with the
setup_upd_tunnel
call as well.