Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
Re: pppd(8): add support for rdomain
To:
Denis Fondras <denis@openbsd.org>
Cc:
tech@openbsd.org
Date:
Mon, 8 Jul 2024 22:15:02 +0200

Download raw body.

Thread
On Mon, Jul 08, 2024 at 08:51:16PM +0200, Denis Fondras wrote:
> Now, we can run the PPP interface in an rdomain and get a default route
> installed.
> 
> Here is an improved version compared to yesterday's diff, fixing the warning
> message about mismatch on rdomain.
> 
> ```
> # ifconfig ppp0 rdomain 5 up
> # ifconfig em0 192.168.8.2/30 up
> # route add 10.42.0.240 192.168.8.1
> # rcctl start xl2tpd
> # echo c l2tp > /var/run/xl2tpd/l2tp-control
> 
> $ ping -V5 8.8.8.8
> PING 8.8.8.8 (8.8.8.8): 56 data bytes
> 64 bytes from 8.8.8.8: icmp_seq=0 ttl=119 time=71.606 ms
> 64 bytes from 8.8.8.8: icmp_seq=1 ttl=119 time=64.730 ms
> ```
> 
> OK ?
> 
> Index: sys/net/ppp_tty.c
> ===================================================================
> RCS file: /cvs/src/sys/net/ppp_tty.c,v
> diff -u -p -r1.54 ppp_tty.c
> --- sys/net/ppp_tty.c	2 Jan 2022 22:36:04 -0000	1.54
> +++ sys/net/ppp_tty.c	30 Jun 2024 15:43:19 -0000
> @@ -371,6 +371,7 @@ pppwrite(struct tty *tp, struct uio *uio
>      bcopy(mtod(m0, u_char *), dst.sa_data, PPP_HDRLEN);
>      m0->m_data += PPP_HDRLEN;
>      m0->m_len -= PPP_HDRLEN;
> +    m0->m_pkthdr.ph_rtableid = sc->sc_if.if_rdomain;
>      return sc->sc_if.if_output(&sc->sc_if, m0, &dst, NULL);
>  }
> 
> Index: usr.sbin/pppd/sys-bsd.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/pppd/sys-bsd.c,v
> diff -u -p -r1.33 sys-bsd.c
> --- usr.sbin/pppd/sys-bsd.c	19 Feb 2024 16:39:03 -0000	1.33
> +++ usr.sbin/pppd/sys-bsd.c	30 Jun 2024 15:43:21 -0000
> @@ -118,6 +118,7 @@ static int initdisc = -1;	/* Initial TTY
>  static int initfdflags = -1;	/* Initial file descriptor flags for ppp_fd */
>  static int ppp_fd = -1;		/* fd which is set to PPP discipline */
>  static int rtm_seq;
> +static int rtableid;

This global feels wrong to me. Why is it needed? Can't dodefaultroute()
take the ifp->if_rdomain value?
 
>  static int restore_term;	/* 1 => we've munged the terminal */
>  static struct termios inittermios; /* Initial TTY termios */
> @@ -218,7 +219,9 @@ ppp_available()
>  	return 1;		/* can't tell */
> 
>      strlcpy(ifr.ifr_name, "ppp0", sizeof(ifr.ifr_name));
> -    ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) == 0;
> +    ok = ioctl(s, SIOCGIFRDOMAIN, (caddr_t) &ifr) == 0;
> +    if (ok)
> +	rtableid = ifr.ifr_rdomainid;
>      close(s);
> 
>      no_ppp_msg = "\
> @@ -1115,6 +1118,7 @@ dodefaultroute(g, cmd)
>      memset(&rtmsg, 0, sizeof(rtmsg));
>      rtmsg.hdr.rtm_type = cmd == 's'? RTM_ADD: RTM_DELETE;
>      rtmsg.hdr.rtm_flags = RTF_UP | RTF_GATEWAY;
> +    rtmsg.hdr.rtm_tableid = rtableid;
>      rtmsg.hdr.rtm_version = RTM_VERSION;
>      rtmsg.hdr.rtm_seq = ++rtm_seq;
>      rtmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
> 

-- 
:wq Claudio