From nobody Sat Dec 4 12:58:18 2021 X-Original-To: dev-commits-ports-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 9D83818B4D85; Sat, 4 Dec 2021 12:58:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J5qVy2j2yz4WB6; Sat, 4 Dec 2021 12:58:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3C79F24C06; Sat, 4 Dec 2021 12:58:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1B4CwIbY044283; Sat, 4 Dec 2021 12:58:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B4CwIUO044282; Sat, 4 Dec 2021 12:58:18 GMT (envelope-from git) Date: Sat, 4 Dec 2021 12:58:18 GMT Message-Id: <202112041258.1B4CwIUO044282@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org From: Eugene Grosbein Subject: git: db72bd31c56b - main - net/mpd5: Re-implement improvement for multi-homed L2TP server List-Id: Commit messages for all branches of the ports repository List-Archive: https://lists.freebsd.org/archives/dev-commits-ports-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-ports-all@freebsd.org X-BeenThere: dev-commits-ports-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: eugen X-Git-Repository: ports X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: db72bd31c56b6a3eb502aa2a650a1aab302b43ca Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638622698; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XZsQ+OWc5xdWLD1/uJ+f8yiuX5ENEBcX9ZW1+jnxSaA=; b=kVx7zBY+ji6oSe5Y/h/bqjDOIdkkUrnKMCuDUtPCrgDGPCLPflcfj1VPXKb3mExYhq1Tts Sz3oOETQXf3/VavuQEHHhDt1IGVu6OFpBx6oBGl2KbYUfOAWTVKjoC8r5nhQHxmFK0v3HH VHOEpjN31RclnXX+yCANZ5WzBTXsJMk1+SRJ/WqQUSa8y8nYbAJMPIIqQjj3wl0ZSVgmqk YCzDnUCQo1+M6rdiJzY20mNlNVaHqFtBaSDtdxlBWYsGAVYfafOopStzUm3awjLoQf9QG+ fM5eCAs31gUBtREOtUsEaoXhl3VHsvSKFQUtahj/NSzhjuSj3QdQCM8vbIFHTQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638622698; a=rsa-sha256; cv=none; b=ykoS6syF8GY8YcIE0wAqdx3S03yECQRUeodRBi+KZp+mzXRmHqMEt9//yR3fY3MM1xtgDs KMNTZ/33wskhKdzIcuIV6rt63ES4sSnm2i+Zx/IgNLNLKjM4J62nl5MLQD2SG4J4SCi+9s mR+BJMb4SVmwJxhtf/2HqhUbLwhiNUHnKZwNksm/fMZnUJ/To1HLdvDDXVQ8rQhk45nqp1 bQ7FjZV2owi6yc2YC5yIZ1Ye8Bu8ep9dnYiMsFGKZFBUtEHofjUGfq1ZPiREwH8XaBhYOI sAGJEkxluqCoQsNsSBlaXasxeIHrt4kNSdVQY/0x67l8rhGc0NiTQCY+RVAn4A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by eugen: URL: https://cgit.FreeBSD.org/ports/commit/?id=db72bd31c56b6a3eb502aa2a650a1aab302b43ca commit db72bd31c56b6a3eb502aa2a650a1aab302b43ca Author: Eugene Grosbein AuthorDate: 2021-12-04 12:56:13 +0000 Commit: Eugene Grosbein CommitDate: 2021-12-04 12:58:09 +0000 net/mpd5: Re-implement improvement for multi-homed L2TP server Import upstream r2437-r2440: Use IP_RECVDSTADDR socket option for IPv4 L2TP server with unspecified self address (0.0.0.0) to determine destination IP address of incoming request and bind new tunnel to right address. This unbreaks multihomed L2TP server setup. --- net/mpd5/Makefile | 2 +- net/mpd5/files/patch-l2tp-multihomed | 161 +++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 1 deletion(-) diff --git a/net/mpd5/Makefile b/net/mpd5/Makefile index 206baa1d9059..9e4ed26ee476 100644 --- a/net/mpd5/Makefile +++ b/net/mpd5/Makefile @@ -2,7 +2,7 @@ PORTNAME= mpd DISTVERSION= 5.9 -PORTREVISION= 4 +PORTREVISION= 6 CATEGORIES= net MASTER_SITES= SF/${PORTNAME}/Mpd5/Mpd-${PORTVERSION} PKGNAMESUFFIX= 5 diff --git a/net/mpd5/files/patch-l2tp-multihomed b/net/mpd5/files/patch-l2tp-multihomed new file mode 100644 index 000000000000..33ec387c37c4 --- /dev/null +++ b/net/mpd5/files/patch-l2tp-multihomed @@ -0,0 +1,161 @@ +Index: src/util.c +=================================================================== +--- src/util.c (revision 2436) ++++ src/util.c (working copy) +@@ -16,8 +16,9 @@ + #include + #include + #include +-#include ++#include + #include ++#include + #include + #include + #include +@@ -1545,4 +1546,52 @@ IfaceSetFlag(const char *ifname, int value) + } + close(s); + return (0); ++} ++ ++/* ++ * Obtain some data, peer (source) and destination addresses of SOCK_DGRAM IPv4 UDP request. ++ */ ++ssize_t GetDataAddrs(int sock, void *dbuf, size_t dbufsize, ++ struct sockaddr_storage *peer, socklen_t peer_len, ++ struct u_addr *addr) ++{ ++ struct { ++ struct msghdr msg; ++ struct iovec iov; ++ } b; ++ union { /* ensure correct alignment for space */ ++ struct cmsghdr cm; ++ char space[CMSG_SPACE(sizeof(struct in_addr))]; ++ } buf; ++ ++ struct cmsghdr *p; ++ ssize_t size; ++ ++ /* Sanity check */ ++ if (addr->family != AF_INET) { ++ errno = EAFNOSUPPORT; ++ return (-1); ++ } ++ ++ b.msg.msg_name = peer; ++ b.msg.msg_namelen = peer_len; ++ b.msg.msg_iov = &b.iov; ++ b.msg.msg_iovlen = 1; ++ b.msg.msg_control = &buf; ++ b.msg.msg_controllen = sizeof(buf); ++ b.msg.msg_flags = 0; ++ ++ b.iov.iov_base = dbuf; ++ b.iov.iov_len = dbufsize; ++ ++ if ((size = recvmsg(sock, &b.msg, 0)) < 0) { ++ Perror("%s: recvmsg: %s", __FUNCTION__, strerror(errno)); ++ return (size); ++ } ++ ++ p = CMSG_FIRSTHDR(&b.msg); ++ if (p && p->cmsg_level == IPPROTO_IP && p->cmsg_type == IP_RECVDSTADDR) ++ memcpy(&addr->u.ip4, CMSG_DATA(p), sizeof(addr->u.ip4)); ++ ++ return (size); + } +Index: src/util.h +=================================================================== +--- src/util.h (revision 2436) ++++ src/util.h (working copy) +@@ -101,6 +101,10 @@ extern int GetPeerEther(struct u_addr *addr, struct so + extern void ppp_util_ascify(char *buf, size_t max, const char *bytes, size_t len); + extern int IfaceSetFlag(const char *ifname, int value); + ++ssize_t GetDataAddrs(int sock, void *dbuf, size_t dbufsize, ++ struct sockaddr_storage *peer, socklen_t peer_len, ++ struct u_addr *addr); ++ + #ifndef HAVE_NTOA_R + extern char *ether_ntoa_r(const struct ether_addr *n, char *a); + #endif +Index: src/l2tp.c +=================================================================== +--- src/l2tp.c (revision 2436) ++++ src/l2tp.c (working copy) +@@ -1374,6 +1374,7 @@ L2tpServerEvent(int type, void *arg) + struct ngm_mkpeer mkpeer; + struct sockaddr_storage peer_sas; + struct sockaddr_storage sas; ++ struct u_addr server_addr; + const size_t bufsize = 8192; + u_int16_t *buf = NULL; + char hook[NG_HOOKSIZ]; +@@ -1393,9 +1394,18 @@ L2tpServerEvent(int type, void *arg) + /* Allocate buffer */ + buf = Malloc(MB_PHYS, bufsize); + ++ u_addrcopy(&s->self_addr, &server_addr); ++ + /* Read packet */ + sas_len = sizeof(peer_sas); +- if ((len = recvfrom(s->sock, buf, bufsize, 0, ++ ++ if (u_addrempty(&s->self_addr)) { ++ if ((len = GetDataAddrs(s->sock, buf, bufsize, ++ &peer_sas, sas_len, &server_addr)) == -1) { ++ Perror("L2TP: GetDataAddrs"); ++ goto fail; ++ } ++ } else if ((len = recvfrom(s->sock, buf, bufsize, 0, + (struct sockaddr *)&peer_sas, &sas_len)) == -1) { + Perror("L2TP: recvfrom"); + goto fail; +@@ -1415,9 +1425,23 @@ L2tpServerEvent(int type, void *arg) + tun->self_port = s->self_port; + tun->alive = 1; + +- Log(LG_PHYS, ("Incoming L2TP packet from %s %d", +- u_addrtoa(&tun->peer_addr, namebuf, sizeof(namebuf)), tun->peer_port)); ++ if (u_addrempty(&tun->self_addr)) ++ u_addrcopy(&server_addr, &tun->self_addr); + ++ if (u_addrempty(&tun->self_addr)) ++ Log(LG_PHYS, ("Incoming L2TP packet from %s %d", ++ u_addrtoa(&tun->peer_addr, namebuf, sizeof(namebuf)), ++ tun->peer_port)); ++ else { ++ char buf3[INET_ADDRSTRLEN]; ++ ++ Log(LG_PHYS, ("Incoming L2TP packet from %s %d to %s %d", ++ u_addrtoa(&tun->peer_addr, namebuf, sizeof(namebuf)), ++ tun->peer_port, ++ u_addrtoa(&tun->self_addr, buf3, sizeof(buf3)), ++ tun->self_port)); ++ } ++ + /* Examine all L2TP links to get best possible fit tunnel parameters. */ + for (k = 0; k < gNumLinks; k++) { + Link l2; +@@ -1552,7 +1576,7 @@ L2tpServerEvent(int type, void *arg) + } + + /* Bind socket to a new port */ +- u_addrtosockaddr(&s->self_addr,s->self_port,&sas); ++ u_addrtosockaddr(&tun->self_addr,tun->self_port,&sas); + if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE, + NGM_KSOCKET_BIND, &sas, sas.ss_len) == -1) { + Perror("L2TP: bind"); +@@ -1649,6 +1673,10 @@ L2tpListen(Link l) + SO_REUSEPORT, &one, sizeof(one)) == -1) { + Perror("L2TP: setsockopt"); + goto fail; ++ } ++ if (u_addrempty(&s->self_addr)) { ++ int on = 1; ++ setsockopt(s->sock, IPPROTO_IP, IP_RECVDSTADDR, &on, sizeof(on)); + } + u_addrtosockaddr(&s->self_addr, s->self_port, &sa); + if (bind(s->sock, (struct sockaddr *)&sa, sa.ss_len) == -1) {