Hello,

patch 6,


# HG changeset patch
# User MJP
# Date 1452862925 -3600
#      Fri Jan 15 14:02:05 2016 +0100
# Node ID 90fa2a12bfaa8776e883c168aaf39be0b16fea4d
# Parent  fd7f48f3955596de5fe098de0f4208106578c9db
Feature: Can listen on an interface with a specific rdomain.

diff -r fd7f48f39555 -r 90fa2a12bfaa usr.sbin/npppd/l2tp/l2tpd.c
--- usr.sbin/npppd/l2tp/l2tpd.c Fri Jan 15 13:38:16 2016 +0100
+++ usr.sbin/npppd/l2tp/l2tpd.c Fri Jan 15 14:02:05 2016 +0100
@@ -60,6 +60,7 @@
 #include "l2tp_local.h"
 #include "addr_range.h"
 #include "net_utils.h"
+#include <net/if.h>           /* for IF_NAMESIZE */
 
 #ifdef L2TPD_DEBUG
 #define        L2TPD_ASSERT(x) ASSERT(x)
@@ -261,7 +262,8 @@
 l2tpd_listener_start(l2tpd_listener *_this)
 {
        l2tpd *_l2tpd;
-       int    af, lvl, opt, sock, ival;
+       int    af, lvl, opt, sock, ival, rdomain;
+       char   ifname[IF_NAMESIZE];
        char   hbuf[NI_MAXHOST + NI_MAXSERV + 16];
 
        _l2tpd = _this->self;
@@ -301,6 +303,23 @@
                    "setsockopt(,,SO_REUSEPORT) failed in %s(): %m", __func__);
                goto fail;
        }
+       rdomain = 0;
+       get_ifname_by_sockaddr((struct sockaddr *)&_this->bind, ifname);
+       if (strlen(ifname) > 0) {
+               if (ifname_get_rdomain(ifname, &rdomain) != 0) {
+                       l2tpd_log(_l2tpd, LOG_ERR,
+                           "ifname_get_rdomain(%s) failed in %s()", ifname, 
__func__);
+                       goto fail;
+               }
+       }
+       if (rdomain != 0) {
+               if (setsockopt(sock, SOL_SOCKET, SO_RTABLE, &rdomain,
+                   sizeof(rdomain)) == -1) {
+                       l2tpd_log(_l2tpd, LOG_ERR,
+                           "setsockopt(,,SO_RTABLE) failed in %s(): %m", 
__func__);
+                       goto fail;
+               }
+       }
        if (bind(sock, (struct sockaddr *)&_this->bind,
            _this->bind.sin6.sin6_len) != 0) {
                l2tpd_log(_l2tpd, LOG_ERR, "Binding %s/udp: %m",
@@ -401,9 +420,11 @@
            l2tpd_io_event, _this);
        event_add(&_this->ev_sock, NULL);
 
-       l2tpd_log(_l2tpd, LOG_INFO, "Listening %s/udp (L2TP LNS) [%s]",
+       l2tpd_log(_l2tpd, LOG_INFO, 
+           "Listening %s/udp (rdomain %i) (L2TP LNS) [%s]",
            addrport_tostring((struct sockaddr *)&_this->bind,
-           _this->bind.sin6.sin6_len, hbuf, sizeof(hbuf)), _this->tun_name);
+           _this->bind.sin6.sin6_len, hbuf, sizeof(hbuf)), rdomain,
+           _this->tun_name);
 
        return 0;
 fail:
diff -r fd7f48f39555 -r 90fa2a12bfaa usr.sbin/npppd/pptp/pptpd.c
--- usr.sbin/npppd/pptp/pptpd.c Fri Jan 15 13:38:16 2016 +0100
+++ usr.sbin/npppd/pptp/pptpd.c Fri Jan 15 14:02:05 2016 +0100
@@ -290,7 +290,8 @@
 static int
 pptpd_listener_start(pptpd_listener *_this)
 {
-       int sock, ival, sock_gre;
+       int sock, ival, sock_gre, rdomain;
+       char ifname[IF_NAMESIZE];
        struct sockaddr_in bind_sin, bind_sin_gre;
        int wildcardbinding;
 
@@ -327,6 +328,23 @@
                    "fcntl(F_SET_FL) failed at %s(): %m", __func__);
                goto fail;
        }
+       rdomain = 0;
+       get_ifname_by_sockaddr((struct sockaddr *)&_this->bind_sin, ifname);
+       if (strlen(ifname) > 0) {
+               if (ifname_get_rdomain(ifname, &rdomain) != 0) {
+                       pptpd_log(_this->self, LOG_ERR,
+                           "ifname_get_rdomain(%s) failed in %s()", ifname, 
__func__);
+                       goto fail;
+               }
+       }
+       if (rdomain != 0) {
+               if (setsockopt(sock, SOL_SOCKET, SO_RTABLE, &rdomain,
+                       sizeof(rdomain)) == -1) {
+                       pptpd_log(_this->self, LOG_ERR,
+                               "setsockopt(,,SO_RTABLE) failed in %s(): %m", 
__func__);
+                       goto fail;
+               }
+       }
        if (bind(sock, (struct sockaddr *)&_this->bind_sin,
            _this->bind_sin.sin_len) != 0) {
                pptpd_log(_this->self, LOG_ERR,
@@ -376,6 +394,14 @@
                    "fcntl(F_SET_FL) failed at %s(): %m", __func__);
                goto fail;
        }
+       if (rdomain != 0) {
+               if (setsockopt(sock_gre, SOL_SOCKET, SO_RTABLE, &rdomain,
+                   sizeof(rdomain)) == -1) {
+                       pptpd_log(_this->self, LOG_ERR,
+                               "setsockopt(,,SO_RTABLE) failed in %s(): %m", 
__func__);
+                       goto fail;
+               }
+       }
        if (bind(sock_gre, (struct sockaddr *)&bind_sin_gre,
            bind_sin_gre.sin_len) != 0) {
                pptpd_log(_this->self, LOG_ERR,

Reply via email to