Manually set ip / bring up wg interface #5

Closed
opened 2024-02-16 13:38:33 +00:00 by MorningLightMountain713 · 9 comments

Hi there, thanks for these great tools!

When I create a wireguard interface, I'm having to manually bring up the interface and add an address to it.

Of note, looking at the interface for 'WgConfig the Address has a capitalized a. I tried it without the capital but that didn't work either.

Here is an example:

import { key, wginterface } from "wireguard-tools.js";

const newConf: wginterface.WgConfig = {
  Address: ["10.10.9.0/31"],
  privateKey: await key.privateKey(),
  portListen: 51000,
  peers: {
    "v4PLcjB38t0DffemaRMa4/M+vewv91VuL1YRcBr4KxA=": {
      endpoint: "172.16.32.66:51000",
      allowedIPs: ["172.23.45.0/24", "10.10.9.1/32"],
    },
  },
};

await wginterface.setConfig("wgB", newConf);

Then looking at the interface it is down, without an ip address.

53: wgB: <POINTOPOINT,NOARP> mtu 1420 qdisc noop state DOWN group default qlen 1000
    link/none

If I add an ip address and bring up the interface, the wireguard link works.

What am I doing wrong? Thanks

Hi there, thanks for these great tools! When I create a wireguard interface, I'm having to manually bring up the interface and add an address to it. Of note, looking at the interface for `'WgConfig` the `Address` has a capitalized a. I tried it without the capital but that didn't work either. Here is an example: ```typescript import { key, wginterface } from "wireguard-tools.js"; const newConf: wginterface.WgConfig = { Address: ["10.10.9.0/31"], privateKey: await key.privateKey(), portListen: 51000, peers: { "v4PLcjB38t0DffemaRMa4/M+vewv91VuL1YRcBr4KxA=": { endpoint: "172.16.32.66:51000", allowedIPs: ["172.23.45.0/24", "10.10.9.1/32"], }, }, }; await wginterface.setConfig("wgB", newConf); ``` Then looking at the interface it is down, without an ip address. ```bash 53: wgB: <POINTOPOINT,NOARP> mtu 1420 qdisc noop state DOWN group default qlen 1000 link/none ``` If I add an ip address and bring up the interface, the wireguard link works. What am I doing wrong? Thanks
davew@chud:~/netlink$ uname -a
Linux chud 5.15.0-94-generic #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
``` davew@chud:~/netlink$ uname -a Linux chud 5.15.0-94-generic #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux ```

Also, forgot to mention, when I try to delete the interface - it doesn't delete it.

await wginterface.deleteInterface("wgB")

I have to manually run

davew@chud:~/netlink$ sudo ip link del dev wgB
Also, forgot to mention, when I try to delete the interface - it doesn't delete it. ``` await wginterface.deleteInterface("wgB") ``` I have to manually run ``` davew@chud:~/netlink$ sudo ip link del dev wgB ```

hello, thanks, set ip address in any platform current not supported, in the future or next version added

in delete interface in windows and macOS is bug from code in addon, current fixing.

hello, thanks, set ip address in any platform current not supported, in the future or next version added in delete interface in windows and macOS is bug from code in addon, current fixing.

in linux correctly delete interface my computers and docker containers, check if run with sudo node, if persist i comment here

in linux correctly delete interface my computers and docker containers, check if run with sudo node, if persist i comment here

@MorningLightMountain713 current checking again in wsl if persist bug and another distros linux

@MorningLightMountain713 current checking again in wsl if persist bug and another distros linux

@MorningLightMountain713

use address, current is Address, a future rename to address

code reference: 38dca1bebe/addons/tools/wginterface.hh (L189-L195)

@MorningLightMountain713 use `address`, current is `Address`, a future rename to `address` code reference: https://sirherobrine23.org/Wireguard/Wireguard-tools.js/src/commit/38dca1bebe13212a9be0798a0e1c2ab45253e5cd/addons/tools/wginterface.hh#L189-L195

in linux correctly delete interface my computers and docker containers, check if run with sudo node, if persist i comment here

Issue persists, I am using sudo to run node.

Here is the code:

import { wginterface } from "wireguard-tools.js";

console.log(await wginterface.listDevices());
await wginterface.deleteInterface("wgB");
console.log(await wginterface.listDevices());

Here is the output:

davew@chud:~/netlink$ sudo /home/davew/.nvm/versions/node/v20.9.0/bin/node test.js
[ { name: 'wgB', from: 'kernel' } ]
[ { name: 'wgB', from: 'kernel' } ]
davew@chud:~/netlink$ ip addr show wgB
64: wgB: <POINTOPOINT,NOARP> mtu 1420 qdisc noop state DOWN group default qlen 1000
    link/none

Thanks

> in linux correctly delete interface my computers and docker containers, check if run with sudo node, if persist i comment here Issue persists, I am using sudo to run node. Here is the code: ```javascript import { wginterface } from "wireguard-tools.js"; console.log(await wginterface.listDevices()); await wginterface.deleteInterface("wgB"); console.log(await wginterface.listDevices()); ``` Here is the output: ```bash davew@chud:~/netlink$ sudo /home/davew/.nvm/versions/node/v20.9.0/bin/node test.js [ { name: 'wgB', from: 'kernel' } ] [ { name: 'wgB', from: 'kernel' } ] davew@chud:~/netlink$ ip addr show wgB 64: wgB: <POINTOPOINT,NOARP> mtu 1420 qdisc noop state DOWN group default qlen 1000 link/none ``` Thanks

This is how I'm adding the ip and bringing the interface up now:

import { createRtNetlink } from 'netlink'

const localAddr = "10.10.9.0"

const links = await socket.getLinks();
const wgLink = links.filter(x => x.attrs.ifname === 'wgB')[0]

const address = { family: 2, prefixlen: 31, scope: 0, index: wgLink.data.index }
const attrs = { local: Buffer.from(localAddr.split(".")) }
await socket.newAddress(address, attrs)

await socket.setLink({
  index: wgLink.data.index,
  change: { up: true },
  flags: { up: true },
})

It all works now:

davew@chud:~/netlink$ ip addr show wgB
66: wgB: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
    link/none
    inet 10.10.9.0/31 scope global wgB
       valid_lft forever preferred_lft forever
davew@chud:~/netlink$ ping 10.10.9.1
PING 10.10.9.1 (10.10.9.1) 56(84) bytes of data.
64 bytes from 10.10.9.1: icmp_seq=1 ttl=64 time=20.0 ms
64 bytes from 10.10.9.1: icmp_seq=2 ttl=64 time=17.9 ms
^C
--- 10.10.9.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 17.939/18.989/20.039/1.050 ms

I just need to add any additional routes for allowed networks

This is how I'm adding the ip and bringing the interface up now: ```javascript import { createRtNetlink } from 'netlink' const localAddr = "10.10.9.0" const links = await socket.getLinks(); const wgLink = links.filter(x => x.attrs.ifname === 'wgB')[0] const address = { family: 2, prefixlen: 31, scope: 0, index: wgLink.data.index } const attrs = { local: Buffer.from(localAddr.split(".")) } await socket.newAddress(address, attrs) await socket.setLink({ index: wgLink.data.index, change: { up: true }, flags: { up: true }, }) ``` It all works now: ```bash davew@chud:~/netlink$ ip addr show wgB 66: wgB: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000 link/none inet 10.10.9.0/31 scope global wgB valid_lft forever preferred_lft forever davew@chud:~/netlink$ ping 10.10.9.1 PING 10.10.9.1 (10.10.9.1) 56(84) bytes of data. 64 bytes from 10.10.9.1: icmp_seq=1 ttl=64 time=20.0 ms 64 bytes from 10.10.9.1: icmp_seq=2 ttl=64 time=17.9 ms ^C --- 10.10.9.1 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1000ms rtt min/avg/max/mdev = 17.939/18.989/20.039/1.050 ms ``` I just need to add any additional routes for allowed networks
Sirherobrine23 pinned this 2024-02-18 02:28:49 +00:00
Sirherobrine23 added the
Kind/Bug
Kind/Feature
Kind/Enhancement
labels 2024-02-18 02:32:27 +00:00
Sirherobrine23 added reference code_refactoring 2024-03-01 02:34:26 +00:00
Sirherobrine23 self-assigned this 2024-03-12 20:20:42 +00:00
Sirherobrine23 added a new dependency 2024-03-12 20:21:01 +00:00

Fixed #10, Linux and Windows now support setting IP addresses. route only external commands

Fixed #10, Linux and Windows now support setting IP addresses. route only external commands
Sirherobrine23 unpinned this 2024-04-06 03:00:32 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees Sirherobrine23
2 Participants
Notifications
Due Date
No due date set.
Depends on
#10 Big code refactoring
Wireguard/Wireguard-tools.js
Reference: Wireguard/Wireguard-tools.js#5
No description provided.