2018-09-20 01:49:47 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
2018-01-03 21:58:00 +01:00
|
|
|
* Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
2017-11-30 16:23:50 +01:00
|
|
|
*/
|
2015-06-05 15:58:00 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2017-09-25 04:22:09 +02:00
|
|
|
|
|
|
|
#include "containers.h"
|
2015-06-05 15:58:00 +02:00
|
|
|
#include "config.h"
|
2016-07-20 21:24:27 +02:00
|
|
|
#include "ipc.h"
|
2017-09-25 04:22:09 +02:00
|
|
|
#include "subcommands.h"
|
2015-06-05 15:58:00 +02:00
|
|
|
|
|
|
|
int set_main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct wgdevice *device = NULL;
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
if (argc < 3) {
|
2017-04-27 11:10:50 +02:00
|
|
|
fprintf(stderr, "Usage: %s %s <interface> [listen-port <port>] [fwmark <mark>] [private-key <file path>] [peer <base64 public key> [remove] [preshared-key <file path>] [endpoint <ip>:<port>] [persistent-keepalive <interval seconds>] [allowed-ips <ip1>/<cidr1>[,<ip2>/<cidr2>]...] ]...\n", PROG_NAME, argv[0]);
|
2015-06-05 15:58:00 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-09-25 04:22:09 +02:00
|
|
|
device = config_read_cmd(argv + 2, argc - 2);
|
|
|
|
if (!device)
|
2015-06-05 15:58:00 +02:00
|
|
|
goto cleanup;
|
2017-09-25 04:22:09 +02:00
|
|
|
strncpy(device->name, argv[1], IFNAMSIZ - 1);
|
2018-02-14 23:21:11 +01:00
|
|
|
device->name[IFNAMSIZ - 1] = '\0';
|
2015-06-05 15:58:00 +02:00
|
|
|
|
2016-07-20 21:24:27 +02:00
|
|
|
if (ipc_set_device(device) != 0) {
|
2018-05-18 19:51:33 +02:00
|
|
|
perror("Unable to modify interface");
|
2015-06-05 15:58:00 +02:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2017-09-25 04:22:09 +02:00
|
|
|
free_wgdevice(device);
|
2015-06-05 15:58:00 +02:00
|
|
|
return ret;
|
|
|
|
}
|