| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if_wg.c,v 1.47 2020/08/31 20:31:03 riastradh Exp $ */ | | 1 | /* $NetBSD: if_wg.c,v 1.48 2020/08/31 20:31:43 riastradh Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (C) Ryota Ozaki <ozaki.ryota@gmail.com> | | 4 | * Copyright (C) Ryota Ozaki <ozaki.ryota@gmail.com> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -31,27 +31,27 @@ | | | @@ -31,27 +31,27 @@ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * This network interface aims to implement the WireGuard protocol. | | 33 | * This network interface aims to implement the WireGuard protocol. |
34 | * The implementation is based on the paper of WireGuard as of | | 34 | * The implementation is based on the paper of WireGuard as of |
35 | * 2018-06-30 [1]. The paper is referred in the source code with label | | 35 | * 2018-06-30 [1]. The paper is referred in the source code with label |
36 | * [W]. Also the specification of the Noise protocol framework as of | | 36 | * [W]. Also the specification of the Noise protocol framework as of |
37 | * 2018-07-11 [2] is referred with label [N]. | | 37 | * 2018-07-11 [2] is referred with label [N]. |
38 | * | | 38 | * |
39 | * [1] https://www.wireguard.com/papers/wireguard.pdf | | 39 | * [1] https://www.wireguard.com/papers/wireguard.pdf |
40 | * [2] http://noiseprotocol.org/noise.pdf | | 40 | * [2] http://noiseprotocol.org/noise.pdf |
41 | */ | | 41 | */ |
42 | | | 42 | |
43 | #include <sys/cdefs.h> | | 43 | #include <sys/cdefs.h> |
44 | __KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.47 2020/08/31 20:31:03 riastradh Exp $"); | | 44 | __KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.48 2020/08/31 20:31:43 riastradh Exp $"); |
45 | | | 45 | |
46 | #ifdef _KERNEL_OPT | | 46 | #ifdef _KERNEL_OPT |
47 | #include "opt_inet.h" | | 47 | #include "opt_inet.h" |
48 | #endif | | 48 | #endif |
49 | | | 49 | |
50 | #include <sys/param.h> | | 50 | #include <sys/param.h> |
51 | #include <sys/types.h> | | 51 | #include <sys/types.h> |
52 | | | 52 | |
53 | #include <sys/atomic.h> | | 53 | #include <sys/atomic.h> |
54 | #include <sys/callout.h> | | 54 | #include <sys/callout.h> |
55 | #include <sys/cprng.h> | | 55 | #include <sys/cprng.h> |
56 | #include <sys/cpu.h> | | 56 | #include <sys/cpu.h> |
57 | #include <sys/device.h> | | 57 | #include <sys/device.h> |
| @@ -4708,52 +4708,52 @@ wg_bind_port_user(struct wg_softc *wg, c | | | @@ -4708,52 +4708,52 @@ wg_bind_port_user(struct wg_softc *wg, c |
4708 | * Receive user packets. | | 4708 | * Receive user packets. |
4709 | */ | | 4709 | */ |
4710 | void | | 4710 | void |
4711 | rumpkern_wg_recv_user(struct wg_softc *wg, struct iovec *iov, size_t iovlen) | | 4711 | rumpkern_wg_recv_user(struct wg_softc *wg, struct iovec *iov, size_t iovlen) |
4712 | { | | 4712 | { |
4713 | struct ifnet *ifp = &wg->wg_if; | | 4713 | struct ifnet *ifp = &wg->wg_if; |
4714 | struct mbuf *m; | | 4714 | struct mbuf *m; |
4715 | const struct sockaddr *dst; | | 4715 | const struct sockaddr *dst; |
4716 | | | 4716 | |
4717 | WG_TRACE(""); | | 4717 | WG_TRACE(""); |
4718 | | | 4718 | |
4719 | dst = iov[0].iov_base; | | 4719 | dst = iov[0].iov_base; |
4720 | | | 4720 | |
4721 | m = m_gethdr(M_NOWAIT, MT_DATA); | | 4721 | m = m_gethdr(M_DONTWAIT, MT_DATA); |
4722 | if (m == NULL) | | 4722 | if (m == NULL) |
4723 | return; | | 4723 | return; |
4724 | m->m_len = m->m_pkthdr.len = 0; | | 4724 | m->m_len = m->m_pkthdr.len = 0; |
4725 | m_copyback(m, 0, iov[1].iov_len, iov[1].iov_base); | | 4725 | m_copyback(m, 0, iov[1].iov_len, iov[1].iov_base); |
4726 | | | 4726 | |
4727 | WG_DLOG("iov_len=%lu\n", iov[1].iov_len); | | 4727 | WG_DLOG("iov_len=%lu\n", iov[1].iov_len); |
4728 | WG_DUMP_BUF(iov[1].iov_base, iov[1].iov_len); | | 4728 | WG_DUMP_BUF(iov[1].iov_base, iov[1].iov_len); |
4729 | | | 4729 | |
4730 | (void)wg_output(ifp, m, dst, NULL); | | 4730 | (void)wg_output(ifp, m, dst, NULL); |
4731 | } | | 4731 | } |
4732 | | | 4732 | |
4733 | /* | | 4733 | /* |
4734 | * Receive packets from a peer. | | 4734 | * Receive packets from a peer. |
4735 | */ | | 4735 | */ |
4736 | void | | 4736 | void |
4737 | rumpkern_wg_recv_peer(struct wg_softc *wg, struct iovec *iov, size_t iovlen) | | 4737 | rumpkern_wg_recv_peer(struct wg_softc *wg, struct iovec *iov, size_t iovlen) |
4738 | { | | 4738 | { |
4739 | struct mbuf *m; | | 4739 | struct mbuf *m; |
4740 | const struct sockaddr *src; | | 4740 | const struct sockaddr *src; |
4741 | | | 4741 | |
4742 | WG_TRACE(""); | | 4742 | WG_TRACE(""); |
4743 | | | 4743 | |
4744 | src = iov[0].iov_base; | | 4744 | src = iov[0].iov_base; |
4745 | | | 4745 | |
4746 | m = m_gethdr(M_NOWAIT, MT_DATA); | | 4746 | m = m_gethdr(M_DONTWAIT, MT_DATA); |
4747 | if (m == NULL) | | 4747 | if (m == NULL) |
4748 | return; | | 4748 | return; |
4749 | m->m_len = m->m_pkthdr.len = 0; | | 4749 | m->m_len = m->m_pkthdr.len = 0; |
4750 | m_copyback(m, 0, iov[1].iov_len, iov[1].iov_base); | | 4750 | m_copyback(m, 0, iov[1].iov_len, iov[1].iov_base); |
4751 | | | 4751 | |
4752 | WG_DLOG("iov_len=%lu\n", iov[1].iov_len); | | 4752 | WG_DLOG("iov_len=%lu\n", iov[1].iov_len); |
4753 | WG_DUMP_BUF(iov[1].iov_base, iov[1].iov_len); | | 4753 | WG_DUMP_BUF(iov[1].iov_base, iov[1].iov_len); |
4754 | | | 4754 | |
4755 | wg_handle_packet(wg, m, src); | | 4755 | wg_handle_packet(wg, m, src); |
4756 | } | | 4756 | } |
4757 | #endif /* WG_RUMPKERNEL */ | | 4757 | #endif /* WG_RUMPKERNEL */ |
4758 | | | 4758 | |
4759 | /* | | 4759 | /* |