1859 |
1859 |
SLIST_INSERT_HEAD(&peer->p_unused_index, iter, i_unused_entry);
|
1860 |
1860 |
}
|
1861 |
1861 |
|
|
1862 |
static int
|
|
1863 |
wg_update_endpoint_addrs(struct wg_endpoint *e, const struct sockaddr *srcsa,
|
|
1864 |
struct ifnet *rcvif)
|
|
1865 |
{
|
|
1866 |
const struct sockaddr_in *sa4;
|
|
1867 |
const struct sockaddr_in6 *sa6;
|
|
1868 |
int ret = 0;
|
|
1869 |
|
|
1870 |
/*
|
|
1871 |
* UDP passes a 2-element sockaddr array: first element is the
|
|
1872 |
* source addr/port, second the destination addr/port.
|
|
1873 |
*/
|
|
1874 |
if (srcsa->sa_family == AF_INET) {
|
|
1875 |
sa4 = (const struct sockaddr_in *)srcsa;
|
|
1876 |
e->e_remote.r_sin = sa4[0];
|
|
1877 |
/* Only update dest if not mcast/bcast */
|
|
1878 |
if (!(IN_MULTICAST(ntohl(sa4[1].sin_addr.s_addr)) ||
|
|
1879 |
sa4[1].sin_addr.s_addr == INADDR_BROADCAST ||
|
|
1880 |
in_broadcast(sa4[1].sin_addr, rcvif))) {
|
|
1881 |
e->e_local.l_in = sa4[1].sin_addr;
|
|
1882 |
}
|
|
1883 |
} else if (srcsa->sa_family == AF_INET6) {
|
|
1884 |
sa6 = (const struct sockaddr_in6 *)srcsa;
|
|
1885 |
e->e_remote.r_sin6 = sa6[0];
|
|
1886 |
/* Only update dest if not multicast */
|
|
1887 |
if (!IN6_IS_ADDR_MULTICAST(&sa6[1].sin6_addr))
|
|
1888 |
e->e_local.l_in6 = sa6[1].sin6_addr;
|
|
1889 |
} else {
|
|
1890 |
ret = EAFNOSUPPORT;
|
|
1891 |
}
|
|
1892 |
|
|
1893 |
return (ret);
|
|
1894 |
}
|
|
1895 |
|
1862 |
1896 |
static void
|
1863 |
1897 |
wg_input(struct mbuf *m0, int offset, struct inpcb *inpcb,
|
1864 |
1898 |
const struct sockaddr *srcsa, void *_sc)
|
... | ... | |
1890 |
1924 |
goto free;
|
1891 |
1925 |
}
|
1892 |
1926 |
e = wg_mbuf_endpoint_get(m);
|
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;
|
|
1927 |
|
|
1928 |
if (wg_update_endpoint_addrs(e, srcsa, m->m_pkthdr.rcvif)) {
|
|
1929 |
DPRINTF(sc, "unknown family\n");
|
|
1930 |
goto free;
|
|
1931 |
}
|
1899 |
1932 |
verify_endpoint(m);
|
1900 |
1933 |
|
1901 |
1934 |
if_inc_counter(sc->sc_ifp, IFCOUNTER_IPACKETS, 1);
|