wg: rename kernel to ipc

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2016-07-20 21:24:27 +02:00
parent 9889b42788
commit b318e81cd0
7 changed files with 25 additions and 25 deletions

View File

@ -12,7 +12,7 @@
#include <errno.h> #include <errno.h>
#include "config.h" #include "config.h"
#include "kernel.h" #include "ipc.h"
#include "base64.h" #include "base64.h"
#define COMMENT_CHAR '#' #define COMMENT_CHAR '#'

View File

@ -26,7 +26,7 @@
#include <sys/un.h> #include <sys/un.h>
#include <sys/signal.h> #include <sys/signal.h>
#include "kernel.h" #include "ipc.h"
#include "../uapi.h" #include "../uapi.h"
#define SOCK_PATH RUNSTATEDIR "/wireguard/" #define SOCK_PATH RUNSTATEDIR "/wireguard/"
@ -455,7 +455,7 @@ out:
#endif #endif
/* first\0second\0third\0forth\0last\0\0 */ /* first\0second\0third\0forth\0last\0\0 */
char *get_wireguard_interfaces(void) char *ipc_list_devices(void)
{ {
struct inflatable_buffer buffer = { .len = 4096 }; struct inflatable_buffer buffer = { .len = 4096 };
int ret; int ret;
@ -484,7 +484,7 @@ cleanup:
return buffer.buffer; return buffer.buffer;
} }
int get_device(struct wgdevice **dev, const char *interface) int ipc_get_device(struct wgdevice **dev, const char *interface)
{ {
#ifdef __linux__ #ifdef __linux__
if (userspace_has_wireguard_interface(interface)) if (userspace_has_wireguard_interface(interface))
@ -495,7 +495,7 @@ int get_device(struct wgdevice **dev, const char *interface)
#endif #endif
} }
int set_device(struct wgdevice *dev) int ipc_set_device(struct wgdevice *dev)
{ {
#ifdef __linux__ #ifdef __linux__
if (userspace_has_wireguard_interface(dev->interface)) if (userspace_has_wireguard_interface(dev->interface))
@ -506,7 +506,7 @@ int set_device(struct wgdevice *dev)
#endif #endif
} }
bool has_wireguard_interface(const char *interface) bool ipc_has_device(const char *interface)
{ {
#ifdef __linux__ #ifdef __linux__
return userspace_has_wireguard_interface(interface) || kernel_has_wireguard_interface(interface); return userspace_has_wireguard_interface(interface) || kernel_has_wireguard_interface(interface);

View File

@ -1,16 +1,16 @@
/* Copyright 2015-2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */ /* Copyright 2015-2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */
#ifndef KERNEL_H #ifndef IPC_H
#define KERNEL_H #define IPC_H
#include <stdbool.h> #include <stdbool.h>
struct wgdevice; struct wgdevice;
int set_device(struct wgdevice *dev); int ipc_set_device(struct wgdevice *dev);
int get_device(struct wgdevice **dev, const char *interface); int ipc_get_device(struct wgdevice **dev, const char *interface);
char *get_wireguard_interfaces(void); char *ipc_list_devices(void);
bool has_wireguard_interface(const char *interface); bool ipc_has_device(const char *interface);
#define for_each_wgpeer(__dev, __peer, __i) for ((__i) = 0, (__peer) = (typeof(__peer))((uint8_t *)(__dev) + sizeof(struct wgdevice)); \ #define for_each_wgpeer(__dev, __peer, __i) for ((__i) = 0, (__peer) = (typeof(__peer))((uint8_t *)(__dev) + sizeof(struct wgdevice)); \

View File

@ -5,7 +5,7 @@
#include <string.h> #include <string.h>
#include "subcommands.h" #include "subcommands.h"
#include "config.h" #include "config.h"
#include "kernel.h" #include "ipc.h"
int set_main(int argc, char *argv[]) int set_main(int argc, char *argv[])
{ {
@ -22,7 +22,7 @@ int set_main(int argc, char *argv[])
strncpy(device->interface, argv[1], IFNAMSIZ - 1); strncpy(device->interface, argv[1], IFNAMSIZ - 1);
device->interface[IFNAMSIZ - 1] = 0; device->interface[IFNAMSIZ - 1] = 0;
if (set_device(device) != 0) { if (ipc_set_device(device) != 0) {
perror("Unable to set device"); perror("Unable to set device");
goto cleanup; goto cleanup;
} }

View File

@ -6,7 +6,7 @@
#include <string.h> #include <string.h>
#include "config.h" #include "config.h"
#include "kernel.h" #include "ipc.h"
#include "subcommands.h" #include "subcommands.h"
int setconf_main(int argc, char *argv[]) int setconf_main(int argc, char *argv[])
@ -45,7 +45,7 @@ int setconf_main(int argc, char *argv[])
strncpy(device->interface, argv[1], IFNAMSIZ - 1); strncpy(device->interface, argv[1], IFNAMSIZ - 1);
device->interface[IFNAMSIZ - 1] = 0; device->interface[IFNAMSIZ - 1] = 0;
if (set_device(device) != 0) { if (ipc_set_device(device) != 0) {
perror("Unable to set device"); perror("Unable to set device");
goto cleanup; goto cleanup;
} }

View File

@ -14,7 +14,7 @@
#include <time.h> #include <time.h>
#include <netdb.h> #include <netdb.h>
#include "kernel.h" #include "ipc.h"
#include "subcommands.h" #include "subcommands.h"
#include "terminal.h" #include "terminal.h"
#include "base64.h" #include "base64.h"
@ -326,7 +326,7 @@ int show_main(int argc, char *argv[])
} }
if (argc == 1 || !strcmp(argv[1], "all")) { if (argc == 1 || !strcmp(argv[1], "all")) {
char *interfaces = get_wireguard_interfaces(), *interface; char *interfaces = ipc_list_devices(), *interface;
if (!interfaces) { if (!interfaces) {
perror("Unable to get devices"); perror("Unable to get devices");
return 1; return 1;
@ -334,7 +334,7 @@ int show_main(int argc, char *argv[])
interface = interfaces; interface = interfaces;
for (size_t len = 0; (len = strlen(interface)); interface += len + 1) { for (size_t len = 0; (len = strlen(interface)); interface += len + 1) {
struct wgdevice *device = NULL; struct wgdevice *device = NULL;
if (get_device(&device, interface) < 0) { if (ipc_get_device(&device, interface) < 0) {
perror("Unable to get device"); perror("Unable to get device");
continue; continue;
} }
@ -358,7 +358,7 @@ int show_main(int argc, char *argv[])
show_usage(); show_usage();
return 1; return 1;
} }
interfaces = get_wireguard_interfaces(); interfaces = ipc_list_devices();
if (!interfaces) { if (!interfaces) {
perror("Unable to get devices"); perror("Unable to get devices");
return 1; return 1;
@ -371,12 +371,12 @@ int show_main(int argc, char *argv[])
show_usage(); show_usage();
else { else {
struct wgdevice *device = NULL; struct wgdevice *device = NULL;
if (!has_wireguard_interface(argv[1])) { if (!ipc_has_device(argv[1])) {
fprintf(stderr, "`%s` is not a valid WireGuard interface\n", argv[1]); fprintf(stderr, "`%s` is not a valid WireGuard interface\n", argv[1]);
show_usage(); show_usage();
return 1; return 1;
} }
if (get_device(&device, argv[1]) < 0) { if (ipc_get_device(&device, argv[1]) < 0) {
perror("Unable to get device"); perror("Unable to get device");
show_usage(); show_usage();
return 1; return 1;

View File

@ -12,7 +12,7 @@
#include "subcommands.h" #include "subcommands.h"
#include "base64.h" #include "base64.h"
#include "kernel.h" #include "ipc.h"
#include "../uapi.h" #include "../uapi.h"
int showconf_main(int argc, char *argv[]) int showconf_main(int argc, char *argv[])
@ -31,13 +31,13 @@ int showconf_main(int argc, char *argv[])
return 1; return 1;
} }
if (!has_wireguard_interface(argv[1])) { if (!ipc_has_device(argv[1])) {
fprintf(stderr, "`%s` is not a valid WireGuard interface\n", argv[1]); fprintf(stderr, "`%s` is not a valid WireGuard interface\n", argv[1]);
fprintf(stderr, "Usage: %s %s <interface>\n", PROG_NAME, argv[0]); fprintf(stderr, "Usage: %s %s <interface>\n", PROG_NAME, argv[0]);
return 1; return 1;
} }
if (get_device(&device, argv[1])) { if (ipc_get_device(&device, argv[1])) {
perror("Unable to get device"); perror("Unable to get device");
goto cleanup; goto cleanup;
} }