Project

General

Profile

PR11338_if_wg.diff

Peter Grehan, 01/31/2021 01:00 AM

View differences:

sys/dev/if_wg/module/if_wg_session.c
1890 1890
		goto free;
1891 1891
	}
1892 1892
	e = wg_mbuf_endpoint_get(m);
1893
	e->e_remote.r_sa = *srcsa;
1893
	if (srcsa->sa_family == AF_INET)
1894
		e->e_remote.r_sin = *(const struct sockaddr_in *)srcsa;
1895
	else if (srcsa->sa_family == AF_INET6)
1896
		e->e_remote.r_sin6 = *(const struct sockaddr_in6 *)srcsa;
1897
	else
1898
		e->e_remote.r_sa = *srcsa;
1894 1899
	verify_endpoint(m);
1895 1900

  
1896 1901
	if_inc_counter(sc->sc_ifp, IFCOUNTER_IPACKETS, 1);
sys/dev/if_wg/module/module.c
391 391
	int i, count;
392 392
	nvlist_t *nvl;
393 393
	caddr_t key;
394
	size_t sa_sz;
394 395
	struct wg_allowedip *aip;
396
	struct wg_endpoint *ep;
395 397

  
396 398
	if ((nvl = nvlist_create(0)) == NULL)
397 399
		return (NULL);
398 400
	key = peer->p_remote.r_public;
399 401
	nvlist_add_binary(nvl, "public-key", key, WG_KEY_SIZE);
400
	nvlist_add_binary(nvl, "endpoint", &peer->p_endpoint.e_remote, sizeof(struct sockaddr));
402
	ep = &peer->p_endpoint;
403
	if (ep->e_remote.r_sa.sa_family != 0) {
404
		sa_sz = (ep->e_remote.r_sa.sa_family == AF_INET) ?
405
			sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
406
		nvlist_add_binary(nvl, "endpoint", &ep->e_remote, sa_sz);
407
	}
401 408
	i = count = 0;
402 409
	CK_LIST_FOREACH(rt, &peer->p_routes, r_entry) {
403 410
		count++;
......
592 599
	}
593 600
	if (nvlist_exists_binary(nvl, "endpoint")) {
594 601
		endpoint = nvlist_get_binary(nvl, "endpoint", &size);
595
		if (size != sizeof(*endpoint)) {
602
		if (size > sizeof(peer->p_endpoint.e_remote)) {
596 603
			device_printf(dev, "%s bad length for endpoint %zu\n", __func__, size);
597 604
			err = EBADMSG;
598 605
			goto out;
599 606
		}
600
		memcpy(&peer->p_endpoint.e_remote, endpoint,
601
		    sizeof(peer->p_endpoint.e_remote));
607
		memcpy(&peer->p_endpoint.e_remote, endpoint, size);
602 608
	}
603 609
	if (nvlist_exists_binary(nvl, "pre-shared-key")) {
604 610
		const void *key;