smartalock / wireguard-lwip

WireGuard Implementation for lwIP
Other
189 stars 27 forks source link

Show when link has dropped? #10

Open AndyW999 opened 1 year ago

AndyW999 commented 1 year ago

If you deactivate the server or the server endpoint is removed from the network is there a way of indicating this?

It works great on my STM32F407 and ESP32 with ciniml/WireGuard-ESP32-Arduino

Thanks

Andy.

fspiot commented 3 months ago

Hello! Do you use FreeRTOS+LWIP to implement Wireguard on STM32F407? Can you share your project?

AndyW999 commented 3 months ago

Sorry I do not use an RTOS, I prefer being in control of my code ;)

fspiot commented 3 months ago

Sorry I do not use an RTOS, I prefer being in control of my code ;)

thanks! Can you really realize it using STM32F407? I compiled it according to the demo provided by the author. But
wg_netif = netif_add(&wg_netif_struct, &ipaddr, &netmask, &gateway, &wg, &wireguardif_init, &ip_input);
There seems to be a problem with this function. Do you know what's going on here?

AndyW999 commented 3 months ago

Set it up and my WG implementation is in the attached ZIP file, hope it is of some use!

I also got it working with ESP32

static void wireguard_setup() { struct wireguardif_init_data wg; struct wireguardif_peer peer; ip_addr_t ipaddr = IPADDR4_INIT_BYTES(WIREGUARD_IPADDRESS[0], WIREGUARD_IPADDRESS[1], WIREGUARD_IPADDRESS[2], WIREGUARD_IPADDRESS[3]); ip_addr_t netmask = IPADDR4_INIT_BYTES(WIREGUARD_SUBNET[0], WIREGUARD_SUBNET[1], WIREGUARD_SUBNET[2], WIREGUARD_SUBNET[3]); ip_addr_t gateway = IPADDR4_INIT_BYTES(WIREGUARD_GW[0], WIREGUARD_GW[1], WIREGUARD_GW[2], WIREGUARD_GW[3]);

// Setup the WireGuard device structure
wg.private_key = &WIREGUARD_MY_PRIV;
wg.listen_port = WIREGUARD_LISTENPORT;
wg.bind_netif = NULL;

// Register the new WireGuard network interface with lwIP
wg_netif = netif_add(&wg_netif_struct, &ipaddr, &netmask, &gateway, &wg, &wireguardif_init, &ip_input);

// Mark the interface as administratively up, link up flag is set automatically when peer connects
netif_set_up(wg_netif);

// Initialise the first WireGuard peer structure
wireguardif_peer_init(&peer);
peer.public_key = &WIREGUARD_THEIR_PUB;
peer.preshared_key = NULL;
// Allow all IPs through tunnel
IP4_ADDR(&peer.allowed_ip, 0, 0, 0, 0);

// peer.allowed_ip = IPADDR4_INIT_BYTES(0, 0, 0, 0); IP4_ADDR(&peer.allowed_mask, 0, 0, 0, 0); // peer.allowed_mask = IPADDR4_INIT_BYTES(0, 0, 0, 0);

// If we know the endpoint's address can add here
IP4_ADDR(&peer.endpoint_ip, WIREGUARD_ENDPOINTIP[0], WIREGUARD_ENDPOINTIP[1], WIREGUARD_ENDPOINTIP[2], WIREGUARD_ENDPOINTIP[3]);

// peer.endpoint_ip = IPADDR4_INIT_BYTES(10, 0, 0, 12); peer.endport_port = WIREGUARD_LISTENPORT;//51820;

// Register the new WireGuard peer with the netwok interface
wireguardif_add_peer(wg_netif, &peer, &wireguard_peer_index);

if ((wireguard_peer_index != WIREGUARDIF_INVALID_INDEX) && !ip_addr_isany(&peer.endpoint_ip)) {
    // Start outbound connection to peer
    wireguardif_connect(wg_netif, wireguard_peer_index);
}

} Wireguard.zip

AndyW999 commented 3 months ago

Looks like the paste got a bit screwed!

WGSetup.txt

fspiot commented 3 months ago

Looks like the paste got a bit screwed!

WGSetup.txt Thank you very much