summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/set.c
blob: 48b005097ab56aa78f39ea7c0533ea6d566ec5e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "subcommands.h"
#include "config.h"
#include "ipc.h"

int set_main(int argc, char *argv[])
{
	struct wgdevice *device = NULL;
	int ret = 1;

	if (argc < 3) {
		fprintf(stderr, "Usage: %s %s <interface> [listen-port <port>] [private-key <file path>] [peer <base64 public key> [remove] [endpoint <ip>:<port>] [persistent-keepalive <interval seconds>] [allowed-ips <ip1>/<cidr1>[,<ip2>/<cidr2>]...] ]...\n", PROG_NAME, argv[0]);
		return 1;
	}

	if (!config_read_cmd(&device, argv + 2, argc - 2))
		goto cleanup;
	strncpy(device->interface, argv[1], IFNAMSIZ -  1);
	device->interface[IFNAMSIZ - 1] = 0;

	if (ipc_set_device(device) != 0) {
		perror("Unable to set device");
		goto cleanup;
	}

	ret = 0;

cleanup:
	free(device);
	return ret;
}