Skip to content

Instantly share code, notes, and snippets.

@Gottox
Last active November 4, 2021 20:13
Show Gist options
  • Save Gottox/e1aa46a0ff74af3473d1a16aeb6cbec4 to your computer and use it in GitHub Desktop.
Save Gottox/e1aa46a0ff74af3473d1a16aeb6cbec4 to your computer and use it in GitHub Desktop.

wg-automesh idea

  • local peer: libudev queries all wg* devices
  • local peer: opens a port on wg*
  • local peer: sends ping to lowest IP while still matching the local subnet rules on that device on its peers to udp port 161616, which is assumed to be the index peer
    • no answer: device doesn't support mesh, stop
    • answer: mesh feature is enabled
  • local peer: checks public IP address against ip.s01.de
  • local peer: sends public IP address to index peer
  • index peer: checks if the public IP the client assumes to have match with the one saved on the wg config
    • no: setup is not supported by mesh, stop
    • yes: pubkey and ip address is saved to the list of known peers
  • index peer: sends back a list of all known peers with:
    • private IP
    • mesh port (default 161616))
  • local peer: sends to remote peer:
    • public IP
    • wireguard port
    • pubkey
  • remote peer: sends to local peer:
    • public IP
    • wireguard port
    • pubkey
  • local peer: sends establish command
  • remote peer: sends establish command
  • both peers: as soon as an establish command has been received (and the local establish command has been sent) add a wg peer with the known configuration
  • both peers: repeatedly send ping packets to the other peer until a ping package is received
    • timeout: unknown error, unconfigure the other peer and blacklist it
    • ping received: connection established
  • any peer: stop sending packages
  • any peer: add other peer to the list of known peers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment