Index | Thread | Search

From:
Claudio Jeker <claudio@openbsd.org>
Subject:
Re: pppd(8): add support for rdomain
To:
Denis Fondras <denis@openbsd.org>
Cc:
tech@openbsd.org
Date:
Sat, 17 Aug 2024 11:09:46 +0200

Download raw body.

Thread
On Sat, Aug 17, 2024 at 11:03:11AM +0200, Denis Fondras wrote:
> With this diff, we can run the PPP interface in an rdomain and get a default
> route installed in the right routing domain.
> 
> 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	17 Aug 2024 08:01:33 -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.35 sys-bsd.c
> --- usr.sbin/pppd/sys-bsd.c	10 Aug 2024 05:32:28 -0000	1.35
> +++ usr.sbin/pppd/sys-bsd.c	17 Aug 2024 08:01:34 -0000
> @@ -1032,6 +1032,22 @@ cifaddr(int u, u_int32_t o, u_int32_t h)
>  }
>  
>  /*
> + * getrtableid - return routing table id of ppp interface
> + */
> +int
> +getrtableid(void)
> +{
> +    struct ifreq ifr;
> +    int tableid = 0;
> +

I think it would be best to initalize ifr to 0 first. Either via
	struct ifreq ifr = { 0 };
or using an explicit memset().

> +    strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
> +    if (ioctl(sockfd, SIOCGIFRDOMAIN, (caddr_t) &ifr) == 0)
> +	tableid = ifr.ifr_rdomainid;
> +
> +    return tableid;
> +}
> +
> +/*
>   * sifdefaultroute - assign a default route through the address given.
>   */
>  int
> @@ -1073,6 +1089,7 @@ dodefaultroute(u_int32_t g, int cmd)
>      rtmsg.hdr.rtm_type = cmd == 's'? RTM_ADD: RTM_DELETE;
>      rtmsg.hdr.rtm_flags = RTF_UP | RTF_GATEWAY;
>      rtmsg.hdr.rtm_version = RTM_VERSION;
> +    rtmsg.hdr.rtm_tableid = getrtableid();
>      rtmsg.hdr.rtm_seq = ++rtm_seq;
>      rtmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
>      rtmsg.dst.sin_len = sizeof(rtmsg.dst);

Apart from that. OK claudio@

-- 
:wq Claudio