Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161253298
D50447.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D50447.diff
View Options
diff --git a/sys/dev/wg/if_wg.c b/sys/dev/wg/if_wg.c
--- a/sys/dev/wg/if_wg.c
+++ b/sys/dev/wg/if_wg.c
@@ -312,7 +312,8 @@
static void wg_timers_run_new_handshake(void *);
static void wg_timers_run_zero_key_material(void *);
static void wg_timers_run_persistent_keepalive(void *);
-static int wg_aip_add(struct wg_softc *, struct wg_peer *, sa_family_t, const void *, uint8_t);
+static int wg_aip_add(struct wg_softc *, struct wg_peer *, sa_family_t,
+ const void *, uint8_t);
static struct wg_peer *wg_aip_lookup(struct wg_softc *, sa_family_t, void *);
static void wg_aip_remove_all(struct wg_softc *, struct wg_peer *);
static struct wg_peer *wg_peer_create(struct wg_softc *,
@@ -526,46 +527,62 @@
rw_runlock(&peer->p_endpoint_lock);
}
-/* Allowed IP */
static int
-wg_aip_add(struct wg_softc *sc, struct wg_peer *peer, sa_family_t af, const void *addr, uint8_t cidr)
+wg_aip_addrinfo(struct wg_aip *aip, const void *baddr, uint8_t cidr)
{
- struct radix_node_head *root;
- struct radix_node *node;
- struct wg_aip *aip;
- int ret = 0;
-
- aip = malloc(sizeof(*aip), M_WG, M_WAITOK | M_ZERO);
- aip->a_peer = peer;
- aip->a_af = af;
+ struct aip_addr *addr, *mask;
- switch (af) {
+ addr = &aip->a_addr;
+ mask = &aip->a_mask;
+ switch (aip->a_af) {
#ifdef INET
case AF_INET:
if (cidr > 32) cidr = 32;
- root = sc->sc_aip4;
- aip->a_addr.in = *(const struct in_addr *)addr;
- aip->a_mask.ip = htonl(~((1LL << (32 - cidr)) - 1) & 0xffffffff);
- aip->a_addr.ip &= aip->a_mask.ip;
- aip->a_addr.length = aip->a_mask.length = offsetof(struct aip_addr, in) + sizeof(struct in_addr);
+ addr->in = *(const struct in_addr *)baddr;
+ mask->ip = htonl(~((1LL << (32 - cidr)) - 1) & 0xffffffff);
+ addr->ip &= mask->ip;
+ addr->length = mask->length = offsetof(struct aip_addr, in) + sizeof(struct in_addr);
break;
#endif
#ifdef INET6
case AF_INET6:
if (cidr > 128) cidr = 128;
- root = sc->sc_aip6;
- aip->a_addr.in6 = *(const struct in6_addr *)addr;
- in6_prefixlen2mask(&aip->a_mask.in6, cidr);
+ addr->in6 = *(const struct in6_addr *)baddr;
+ in6_prefixlen2mask(&mask->in6, cidr);
for (int i = 0; i < 4; i++)
- aip->a_addr.ip6[i] &= aip->a_mask.ip6[i];
- aip->a_addr.length = aip->a_mask.length = offsetof(struct aip_addr, in6) + sizeof(struct in6_addr);
+ addr->ip6[i] &= mask->ip6[i];
+ addr->length = mask->length = offsetof(struct aip_addr, in6) + sizeof(struct in6_addr);
break;
#endif
default:
- free(aip, M_WG);
return (EAFNOSUPPORT);
}
+ return (0);
+}
+
+/* Allowed IP */
+static int
+wg_aip_add(struct wg_softc *sc, struct wg_peer *peer, sa_family_t af,
+ const void *baddr, uint8_t cidr)
+{
+ struct radix_node_head *root = NULL;
+ struct radix_node *node;
+ struct wg_aip *aip;
+ int ret = 0;
+
+ aip = malloc(sizeof(*aip), M_WG, M_WAITOK | M_ZERO);
+ aip->a_peer = peer;
+ aip->a_af = af;
+
+ ret = wg_aip_addrinfo(aip, baddr, cidr);
+ if (ret != 0) {
+ free(aip, M_WG);
+ return (ret);
+ }
+
+ root = af == AF_INET ? sc->sc_aip4 : sc->sc_aip6;
+ MPASS(root != NULL);
RADIX_NODE_HEAD_LOCK(root);
node = root->rnh_addaddr(&aip->a_addr, &aip->a_mask, &root->rh, aip->a_nodes);
if (node == aip->a_nodes) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jul 3, 4:07 AM (30 m, 46 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34611529
Default Alt Text
D50447.diff (3 KB)
Attached To
Mode
D50447: kern: wg: split address/mask construction out of wg_aip_add()
Attached
Detach File
Event Timeline
Log In to Comment