Download raw body.
ppp(4) : Add IPv6 support
Le Mon, Feb 19, 2024 at 07:01:15AM +0000, Miod Vallat a écrit :
> > Here is a diff to add IPv6 support to ppp(4).
> > With this diff, I can send and receive IPv6 packets over a PPP connection.
>
> Look good to me, but...
>
> > Index: if_ppp.c
>
> > @@ -579,13 +583,9 @@ pppsioctl(struct ifnet *ifp, u_long cmd,
> > break;
> >
> > case SIOCSIFADDR:
> > - if (ifa->ifa_addr->sa_family != AF_INET)
> > - error = EAFNOSUPPORT;
> > break;
> >
> > case SIOCSIFDSTADDR:
> > - if (ifa->ifa_addr->sa_family != AF_INET)
> > - error = EAFNOSUPPORT;
> > break;
> >
> > case SIOCSIFMTU:
>
> You probably want to nevertheless check sa_family and only allow
> AF_INET, and AF_INET6 #ifdef INET6, as done e.g. in netinet/ip_carp.c.
Thank you Miod. Here is an updated diff.
Index: share/man/man4/ppp.4
===================================================================
RCS file: /cvs/src/share/man/man4/ppp.4,v
retrieving revision 1.16
diff -u -p -r1.16 ppp.4
--- share/man/man4/ppp.4 28 Jul 2015 14:31:50 -0000 1.16
+++ share/man/man4/ppp.4 19 Feb 2024 16:56:44 -0000
@@ -80,11 +80,3 @@ The
.Nm
device appeared in
.Ox 1.2 .
-.Sh BUGS
-Currently, only the
-.Xr ip 4
-protocol is supported by this device.
-Note that the
-.Xr pppoe 4
-device does support
-.Xr ip6 4 .
Index: sys/net/if_ppp.c
===================================================================
RCS file: /cvs/src/sys/net/if_ppp.c,v
retrieving revision 1.117
diff -u -p -r1.117 if_ppp.c
--- sys/net/if_ppp.c 21 Aug 2020 22:59:27 -0000 1.117
+++ sys/net/if_ppp.c 19 Feb 2024 16:56:44 -0000
@@ -494,6 +494,11 @@ pppioctl(struct ppp_softc *sc, u_long cm
case PPP_IP:
npx = NP_IP;
break;
+#ifdef INET6
+ case PPP_IPV6:
+ npx = NP_IPV6;
+ break;
+#endif
default:
return EINVAL;
}
@@ -579,15 +584,19 @@ pppsioctl(struct ifnet *ifp, u_long cmd,
break;
case SIOCSIFADDR:
- if (ifa->ifa_addr->sa_family != AF_INET)
- error = EAFNOSUPPORT;
- break;
-
case SIOCSIFDSTADDR:
- if (ifa->ifa_addr->sa_family != AF_INET)
+ switch (ifa->ifa_addr->sa_family) {
+ case AF_INET:
+ break;
+#ifdef INET6
+ case AF_INET6:
+ break;
+#endif
+ default:
error = EAFNOSUPPORT;
+ break;
+ }
break;
-
case SIOCSIFMTU:
sc->sc_if.if_mtu = ifr->ifr_mtu;
break;
@@ -674,6 +683,14 @@ pppoutput(struct ifnet *ifp, struct mbuf
protocol = PPP_IP;
mode = sc->sc_npmode[NP_IP];
break;
+#ifdef INET6
+ case AF_INET6:
+ address = PPP_ALLSTATIONS;
+ control = PPP_UI;
+ protocol = PPP_IPV6;
+ mode = sc->sc_npmode[NP_IPV6];
+ break;
+#endif
case AF_UNSPEC:
address = PPP_ADDRESS(dst->sa_data);
control = PPP_CONTROL(dst->sa_data);
@@ -804,6 +821,11 @@ ppp_requeue(struct ppp_softc *sc)
case PPP_IP:
mode = sc->sc_npmode[NP_IP];
break;
+#ifdef INET6
+ case PPP_IPV6:
+ mode = sc->sc_npmode[NP_IPV6];
+ break;
+#endif
default:
mode = NPMODE_PASS;
}
@@ -1391,7 +1413,25 @@ ppp_inproc(struct ppp_softc *sc, struct
ipv4_input(ifp, m);
rv = 1;
break;
+#ifdef INET6
+ case PPP_IPV6:
+ /*
+ * IPv6 packet - take off the ppp header and pass it up to IPv6.
+ */
+ if ((ifp->if_flags & IFF_UP) == 0 ||
+ sc->sc_npmode[NP_IPV6] != NPMODE_PASS) {
+ /* interface is down - drop the packet. */
+ m_freem(m);
+ return;
+ }
+ m->m_pkthdr.len -= PPP_HDRLEN;
+ m->m_data += PPP_HDRLEN;
+ m->m_len -= PPP_HDRLEN;
+ ipv6_input(ifp, m);
+ rv = 1;
+ break;
+#endif
default:
/*
* Some other protocol - place on input queue for read().
Index: sys/net/if_pppvar.h
===================================================================
RCS file: /cvs/src/sys/net/if_pppvar.h,v
retrieving revision 1.20
diff -u -p -r1.20 if_pppvar.h
--- sys/net/if_pppvar.h 20 May 2020 06:44:30 -0000 1.20
+++ sys/net/if_pppvar.h 19 Feb 2024 16:56:44 -0000
@@ -81,7 +81,8 @@
* indexing sc_npmode.
*/
#define NP_IP 0 /* Internet Protocol */
-#define NUM_NP 1 /* Number of NPs. */
+#define NP_IPV6 1 /* Internet Protocol v6 */
+#define NUM_NP 2 /* Number of NPs. */
struct ppp_pkt;
ppp(4) : Add IPv6 support