aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-05 10:44:45 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-05 11:05:33 +0100
commit622c1490252033a37ff3e4d40eb18c570a41d670 (patch)
treedbe4878a12f6f8fd9cfaaa612156175ca13020cd
parentAdd notify to alert new session has been created (diff)
downloadwireguard-openbsd-622c1490252033a37ff3e4d40eb18c570a41d670.tar.xz
wireguard-openbsd-622c1490252033a37ff3e4d40eb18c570a41d670.zip
Refactoring of {s,g}et_* to *_{s,g}et
-rw-r--r--src/if_wg.c30
-rw-r--r--src/if_wg.h34
-rw-r--r--src/patches/ifconfig.patch24
-rw-r--r--src/wireguard.h1
4 files changed, 43 insertions, 46 deletions
diff --git a/src/if_wg.c b/src/if_wg.c
index f96ee1c..31be12a 100644
--- a/src/if_wg.c
+++ b/src/if_wg.c
@@ -152,12 +152,12 @@ int wg_clone_create(struct if_clone *, int);
int wg_clone_destroy(struct ifnet *);
int wg_bind_port(struct wg_softc *);
-int wg_ioctl_set_peer(struct wg_softc *, u_long,
- struct wg_set_peer *);
-int wg_ioctl_set_serv(struct wg_softc *, u_long,
- struct wg_set_serv *);
-void wg_ioctl_get_serv(struct wg_softc *, struct wg_get_serv *);
-int wg_ioctl_get_peer(struct wg_softc *, struct wg_get_peer *);
+int wg_ioctl_peer_set(struct wg_softc *, u_long,
+ struct wg_peer_set *);
+int wg_ioctl_serv_set(struct wg_softc *, u_long,
+ struct wg_serv_set *);
+void wg_ioctl_serv_get(struct wg_softc *, struct wg_serv_get *);
+int wg_ioctl_peer_get(struct wg_softc *, struct wg_peer_get *);
int wg_ioctl(struct ifnet *, u_long, caddr_t);
@@ -1076,9 +1076,8 @@ wg_softc_peer_clean(struct wg_peer *peer)
DPRINTF(sc, "deleted peer: %x\n", peer->p_id);
}
-/* TODO flip set_peer -> peer_set */
int
-wg_ioctl_set_peer(struct wg_softc *sc, u_long cmd, struct wg_set_peer *wsp)
+wg_ioctl_peer_set(struct wg_softc *sc, u_long cmd, struct wg_peer_set *wsp)
{
int ret = 0;
struct wg_peer *peer;
@@ -1095,7 +1094,6 @@ wg_ioctl_set_peer(struct wg_softc *sc, u_long cmd, struct wg_set_peer *wsp)
if (IS_NULL_KEY(wsp->sp_pubkey.k) || IS_MASKED_KEY(wsp->sp_pubkey.k))
return EINVAL;
- /* TODO compat with byte key */
pub = wsp->sp_pubkey;
if ((peer = wg_device_ref_peerkey(&sc->sc_dev, &pub)) == NULL) {
route = malloc(sizeof(*route), M_DEVBUF, M_WAITOK | M_ZERO);
@@ -1151,7 +1149,7 @@ wg_ioctl_set_peer(struct wg_softc *sc, u_long cmd, struct wg_set_peer *wsp)
}
int
-wg_ioctl_set_serv(struct wg_softc *sc, u_long cmd, struct wg_set_serv *wss)
+wg_ioctl_serv_set(struct wg_softc *sc, u_long cmd, struct wg_serv_set *wss)
{
struct wg_peer *peer;
struct wg_keypair kp;
@@ -1185,7 +1183,7 @@ wg_ioctl_set_serv(struct wg_softc *sc, u_long cmd, struct wg_set_serv *wss)
}
void
-wg_ioctl_get_serv(struct wg_softc *sc, struct wg_get_serv *wgs)
+wg_ioctl_serv_get(struct wg_softc *sc, struct wg_serv_get *wgs)
{
struct map_item *item;
struct wg_peer *peer;
@@ -1207,7 +1205,7 @@ wg_ioctl_get_serv(struct wg_softc *sc, struct wg_get_serv *wgs)
}
int
-wg_ioctl_get_peer(struct wg_softc *sc, struct wg_get_peer *wgp)
+wg_ioctl_peer_get(struct wg_softc *sc, struct wg_peer_get *wgp)
{
size_t num = 0;
struct wg_peer *peer;
@@ -1251,7 +1249,7 @@ wg_ioctl(struct ifnet * ifp, u_long cmd, caddr_t data)
case SIOCSWGSERVPORT: /* Set WireGuard server port */
case SIOCSWGSERVKEY: /* Set WireGuard server private + public key */
case SIOCCWGPEERS: /* Clear all WireGuard peers */
- ret = wg_ioctl_set_serv(sc, cmd, (struct wg_set_serv *) data);
+ ret = wg_ioctl_serv_set(sc, cmd, (struct wg_serv_set *) data);
break;
case SIOCSWGPEERIP: /* Set WireGuard peer endpoint IP */
case SIOCSWGPEERPSK: /* Set WireGuard peer preshared key */
@@ -1260,13 +1258,13 @@ wg_ioctl(struct ifnet * ifp, u_long cmd, caddr_t data)
case SIOCDWGPEER: /* Delete WireGuard peer */
case SIOCDWGPEERAIP: /* Delete WireGuard peer allowedip */
case SIOCCWGPEERAIP: /* Clear WireGuard peer */
- ret = wg_ioctl_set_peer(sc, cmd, (struct wg_set_peer *) data);
+ ret = wg_ioctl_peer_set(sc, cmd, (struct wg_peer_set *) data);
break;
case SIOCGWGSERV: /* Get WireGuard server configuration */
- wg_ioctl_get_serv(sc, (struct wg_get_serv *) data);
+ wg_ioctl_serv_get(sc, (struct wg_serv_get *) data);
break;
case SIOCGWGPEER: /* Get WireGuard peer status */
- wg_ioctl_get_peer(sc, (struct wg_get_peer *) data);
+ wg_ioctl_peer_get(sc, (struct wg_peer_get *) data);
break;
/* Interface IOCTLs */
diff --git a/src/if_wg.h b/src/if_wg.h
index 54b8c69..743ffab 100644
--- a/src/if_wg.h
+++ b/src/if_wg.h
@@ -37,21 +37,21 @@ static inline int _memchrcmp(uint8_t *b, uint8_t c, size_t l) {
#define IS_MASKED_KEY(k) (!_memchrcmp(k, 0xff, WG_KEY_SIZE))
/* GET */
-#define SIOCGWGSERV _IOWR('i', 200, struct wg_get_serv)
-#define SIOCGWGPEER _IOWR('i', 201, struct wg_get_peer)
+#define SIOCGWGSERV _IOWR('i', 200, struct wg_serv_get)
+#define SIOCGWGPEER _IOWR('i', 201, struct wg_peer_get)
/* SET */
-#define SIOCSWGSERVPORT _IOW('i', 202, struct wg_set_serv)
-#define SIOCSWGSERVKEY _IOW('i', 203, struct wg_set_serv)
-#define SIOCCWGPEERS _IOW('i', 204, struct wg_set_serv)
-
-#define SIOCSWGPEERIP _IOW('i', 205, struct wg_set_peer)
-#define SIOCSWGPEERAIP _IOW('i', 206, struct wg_set_peer)
-#define SIOCSWGPEERPSK _IOW('i', 207, struct wg_set_peer)
-#define SIOCSWGPEERPKA _IOW('i', 208, struct wg_set_peer)
-#define SIOCDWGPEER _IOW('i', 209, struct wg_set_peer)
-#define SIOCDWGPEERAIP _IOW('i', 210, struct wg_set_peer)
-#define SIOCCWGPEERAIP _IOW('i', 211, struct wg_set_peer)
+#define SIOCSWGSERVPORT _IOW('i', 202, struct wg_serv_set)
+#define SIOCSWGSERVKEY _IOW('i', 203, struct wg_serv_set)
+#define SIOCCWGPEERS _IOW('i', 204, struct wg_serv_set)
+
+#define SIOCSWGPEERIP _IOW('i', 205, struct wg_peer_set)
+#define SIOCSWGPEERAIP _IOW('i', 206, struct wg_peer_set)
+#define SIOCSWGPEERPSK _IOW('i', 207, struct wg_peer_set)
+#define SIOCSWGPEERPKA _IOW('i', 208, struct wg_peer_set)
+#define SIOCDWGPEER _IOW('i', 209, struct wg_peer_set)
+#define SIOCDWGPEERAIP _IOW('i', 210, struct wg_peer_set)
+#define SIOCCWGPEERAIP _IOW('i', 211, struct wg_peer_set)
union wg_ip {
struct sockaddr sa;
@@ -77,7 +77,7 @@ struct wg_cidr {
} c_ip;
};
-struct wg_set_serv {
+struct wg_serv_set {
char ss_name[IFNAMSIZ];
union {
struct wg_privkey d_privkey;
@@ -85,7 +85,7 @@ struct wg_set_serv {
} ss_data;
};
-struct wg_set_peer {
+struct wg_peer_set {
char sp_name[IFNAMSIZ];
struct wg_pubkey sp_pubkey;
union {
@@ -103,7 +103,7 @@ struct wg_set_peer {
#define sp_pka sp_data.d_pka
#define sp_ip sp_data.d_ip
-struct wg_get_peer {
+struct wg_peer_get {
char gp_name[IFNAMSIZ];
struct wg_pubkey gp_pubkey;
struct wg_privkey gp_shared;
@@ -116,7 +116,7 @@ struct wg_get_peer {
size_t gp_num_routes;
};
-struct wg_get_serv {
+struct wg_serv_get {
char gs_name[IFNAMSIZ];
struct wg_keypair gs_keypair;
in_port_t gs_port;
diff --git a/src/patches/ifconfig.patch b/src/patches/ifconfig.patch
index 841f597..6983569 100644
--- a/src/patches/ifconfig.patch
+++ b/src/patches/ifconfig.patch
@@ -137,7 +137,7 @@
+ if (IS_NULL_KEY(wg_peer))
+ errx(1, "wgpip: wgpeer not set");
+
-+ struct wg_set_peer wsp;
++ struct wg_peer_set wsp;
+ struct addrinfo *ai;
+
+ int error = getaddrinfo(host, service, NULL, &ai);
@@ -157,7 +157,7 @@
+void
+setwgpeeraip(const char *aip, int param)
+{
-+ struct wg_set_peer wsp;
++ struct wg_peer_set wsp;
+
+ if (IS_NULL_KEY(wg_peer))
+ errx(1, "wgaip: wgpeer not set");
@@ -174,7 +174,7 @@
+void
+setwgpeerpsk(const char *psk_b64, int param)
+{
-+ struct wg_set_peer wsp;
++ struct wg_peer_set wsp;
+
+ if (IS_NULL_KEY(wg_peer))
+ errx(1, "wgpsk: wgpeer not set");
@@ -191,7 +191,7 @@
+setwgpeerpka(const char *pka, int param)
+{
+ const char *errmsg;
-+ struct wg_set_peer wsp;
++ struct wg_peer_set wsp;
+
+ if (IS_NULL_KEY(wg_peer))
+ errx(1, "wgpsk: wgpeer not set");
@@ -210,7 +210,7 @@
+setwglocalport(const char *port, int param)
+{
+ const char *errmsg;
-+ struct wg_set_serv wss;
++ struct wg_serv_set wss;
+
+ strlcpy(wss.ss_name, name, sizeof(wss.ss_name));
+ wss.ss_port = strtonum(port, 1, 65535, &errmsg);
@@ -224,7 +224,7 @@
+void
+setwglocalkey(const char *privkey_b64, int param)
+{
-+ struct wg_set_serv wss;
++ struct wg_serv_set wss;
+
+ strlcpy(wss.ss_name, name, sizeof(wss.ss_name));
+ WG_LOAD_KEY(wss.ss_privkey.k, privkey_b64, "wgkey");
@@ -236,7 +236,7 @@
+void
+unsetwgpeer(const char *peerkey_b64, int param)
+{
-+ struct wg_set_peer wsp;
++ struct wg_peer_set wsp;
+
+ strlcpy(wsp.sp_name, name, sizeof(wsp.sp_name));
+ WG_LOAD_KEY(wsp.sp_pubkey.k, peerkey_b64, "-wgpeer");
@@ -248,7 +248,7 @@
+void
+unsetwgpeerip(const char *c, int i)
+{
-+ struct wg_set_peer wsp;
++ struct wg_peer_set wsp;
+
+ if (IS_NULL_KEY(wg_peer))
+ errx(1, "-wgpip: wgpeer not set");
@@ -264,7 +264,7 @@
+void
+unsetwgpeeraip(const char *aip, int param)
+{
-+ struct wg_set_peer wsp;
++ struct wg_peer_set wsp;
+
+ if (IS_NULL_KEY(wg_peer))
+ errx(1, "wgaip: wgpeer not set");
@@ -281,7 +281,7 @@
+void
+unsetwgpeerpsk(const char *c, int param)
+{
-+ struct wg_set_peer wsp;
++ struct wg_peer_set wsp;
+
+ if (IS_NULL_KEY(wg_peer))
+ errx(1, "wgpsk: wgpeer not set");
@@ -302,8 +302,8 @@
+ char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
+ char key[WG_BASE64_KEY_SIZE + 1]; /* extra byte for \0 */
+
-+ struct wg_get_serv wgs;
-+ struct wg_get_peer wgp;
++ struct wg_serv_get wgs;
++ struct wg_peer_get wgp;
+
+ strlcpy(wgs.gs_name, name, sizeof(wgs.gs_name));
+ strlcpy(wgp.gp_name, name, sizeof(wgp.gp_name));
diff --git a/src/wireguard.h b/src/wireguard.h
index 1ee235c..ecabe89 100644
--- a/src/wireguard.h
+++ b/src/wireguard.h
@@ -178,7 +178,6 @@ struct wg_peer {
struct wg_device *p_device;
struct wg_pubkey p_remote;
struct refcnt p_refcnt;
- SLIST_ENTRY(wg_peer) p_entry;
/* All protected by p_lock */
struct rwlock p_lock;