Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Added ioctl commands for configuring NCP of pppoe(4)
details: https://anonhg.NetBSD.org/src/rev/8d05a7f6646f
branches: trunk
changeset: 379096:8d05a7f6646f
user: yamaguchi <yamaguchi%NetBSD.org@localhost>
date: Tue May 11 01:27:45 2021 +0000
description:
Added ioctl commands for configuring NCP of pppoe(4)
diffstat:
sys/net/if_sppp.h | 12 ++++++++++-
sys/net/if_spppsubr.c | 52 +++++++++++++++++++++++++++++++++++++++++++-------
sys/net/if_spppvar.h | 3 +-
3 files changed, 57 insertions(+), 10 deletions(-)
diffs (192 lines):
diff -r 508c4aaedded -r 8d05a7f6646f sys/net/if_sppp.h
--- a/sys/net/if_sppp.h Tue May 11 01:23:21 2021 +0000
+++ b/sys/net/if_sppp.h Tue May 11 01:27:45 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_sppp.h,v 1.33 2021/05/11 01:15:11 yamaguchi Exp $ */
+/* $NetBSD: if_sppp.h,v 1.34 2021/05/11 01:27:45 yamaguchi Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -233,5 +233,15 @@ struct spppipv6cpstatus {
#define SPPPGETIPV6CPSTATUS _IOWR('i', 137, struct spppipv6cpstatus)
+#define SPPP_NCP_IPCP __BIT(0)
+#define SPPP_NCP_IPV6CP __BIT(1)
+struct spppncpcfg {
+ char ifname[IFNAMSIZ];
+ u_int ncp_flags;
+};
+
+#define SPPPGETNCPCFG _IOWR('i', 138, struct spppncpcfg)
+#define SPPPSETNCPCFG _IOW('i', 139, struct spppncpcfg)
+
#endif /* !_NET_IF_SPPP_H_ */
diff -r 508c4aaedded -r 8d05a7f6646f sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c Tue May 11 01:23:21 2021 +0000
+++ b/sys/net/if_spppsubr.c Tue May 11 01:27:45 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_spppsubr.c,v 1.232 2021/05/11 01:15:11 yamaguchi Exp $ */
+/* $NetBSD: if_spppsubr.c,v 1.233 2021/05/11 01:27:45 yamaguchi Exp $ */
/*
* Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.232 2021/05/11 01:15:11 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.233 2021/05/11 01:27:45 yamaguchi Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@@ -585,11 +585,7 @@ sppp_input(struct ifnet *ifp, struct mbu
log(LOG_DEBUG,
"%s: input packet is too small, %d bytes\n",
ifp->if_xname, m->m_pkthdr.len);
- drop:
- if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1);
- m_freem(m);
- SPPP_UNLOCK(sp);
- return;
+ goto drop;
}
if (sp->pp_flags & PP_NOFRAMING) {
@@ -663,7 +659,7 @@ sppp_input(struct ifnet *ifp, struct mbu
}
switch (protocol) {
- default:
+ reject_protocol:
if (sp->scp[IDX_LCP].state == STATE_OPENED) {
uint16_t prot = htons(protocol);
@@ -679,6 +675,8 @@ sppp_input(struct ifnet *ifp, struct mbu
"<proto=0x%x>\n", ifp->if_xname, ntohs(protocol));
if_statinc(ifp, if_noproto);
goto drop;
+ default:
+ goto reject_protocol;
case PPP_LCP:
SPPP_UNLOCK(sp);
sppp_cp_input(&lcp, sp, m);
@@ -700,6 +698,8 @@ sppp_input(struct ifnet *ifp, struct mbu
return;
#ifdef INET
case PPP_IPCP:
+ if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP))
+ goto reject_protocol;
SPPP_UNLOCK(sp);
if (sp->pp_phase == SPPP_PHASE_NETWORK) {
sppp_cp_input(&ipcp, sp, m);
@@ -717,6 +717,8 @@ sppp_input(struct ifnet *ifp, struct mbu
#endif
#ifdef INET6
case PPP_IPV6CP:
+ if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP))
+ goto reject_protocol;
SPPP_UNLOCK(sp);
if (sp->pp_phase == SPPP_PHASE_NETWORK) {
sppp_cp_input(&ipv6cp, sp, m);
@@ -766,6 +768,13 @@ queue_pkt:
IF_ENQUEUE(inq, m);
IFQ_UNLOCK(inq);
schednetisr(isr);
+ return;
+
+drop:
+ if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1);
+ m_freem(m);
+ SPPP_UNLOCK(sp);
+ return;
}
/*
@@ -1029,6 +1038,7 @@ sppp_attach(struct ifnet *ifp)
sp->pp_phase = SPPP_PHASE_DEAD;
sp->pp_up = sppp_notify_up;
sp->pp_down = sppp_notify_down;
+ sp->pp_ncpflags = SPPP_NCP_IPCP | SPPP_NCP_IPV6CP;
sppp_wq_set(&sp->work_ifdown, sppp_ifdown, NULL);
memset(sp->scp, 0, sizeof(sp->scp));
rw_init(&sp->pp_lock);
@@ -1265,6 +1275,7 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
case SPPPSETAUTHCFG:
case SPPPSETLCPCFG:
+ case SPPPSETNCPCFG:
case SPPPSETIDLETO:
case SPPPSETAUTHFAILURE:
case SPPPSETDNSOPTS:
@@ -1284,6 +1295,7 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
case SPPPGETAUTHCFG:
case SPPPGETLCPCFG:
+ case SPPPGETNCPCFG:
case SPPPGETAUTHFAILURES:
error = kauth_authorize_network(l->l_cred,
KAUTH_NETWORK_INTERFACE,
@@ -3491,6 +3503,9 @@ sppp_ipcp_open(struct sppp *sp, void *xc
KASSERT(SPPP_WLOCKED(sp));
KASSERT(!cpu_softintr_p());
+ if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP))
+ return;
+
sp->ipcp.flags &= ~(IPCP_HISADDR_SEEN|IPCP_MYADDR_SEEN|IPCP_MYADDR_DYN|IPCP_HISADDR_DYN);
sp->ipcp.req_myaddr = 0;
sp->ipcp.req_hisaddr = 0;
@@ -4065,6 +4080,9 @@ sppp_ipv6cp_open(struct sppp *sp, void *
KASSERT(SPPP_WLOCKED(sp));
KASSERT(!cpu_softintr_p());
+ if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP))
+ return;
+
#ifdef IPV6CP_MYIFID_DYN
sp->ipv6cp.flags &= ~(IPV6CP_MYIFID_SEEN|IPV6CP_MYIFID_DYN);
#else
@@ -6113,6 +6131,24 @@ sppp_params(struct sppp *sp, u_long cmd,
SPPP_UNLOCK(sp);
}
break;
+ case SPPPGETNCPCFG:
+ {
+ struct spppncpcfg *ncpp = (struct spppncpcfg *) data;
+
+ SPPP_LOCK(sp, RW_READER);
+ ncpp->ncp_flags = sp->pp_ncpflags;
+ SPPP_UNLOCK(sp);
+ }
+ break;
+ case SPPPSETNCPCFG:
+ {
+ struct spppncpcfg *ncpp = (struct spppncpcfg *) data;
+
+ SPPP_LOCK(sp, RW_WRITER);
+ sp->pp_ncpflags = ncpp->ncp_flags;
+ SPPP_UNLOCK(sp);
+ }
+ break;
case SPPPGETSTATUS:
{
struct spppstatus *status = (struct spppstatus *)data;
diff -r 508c4aaedded -r 8d05a7f6646f sys/net/if_spppvar.h
--- a/sys/net/if_spppvar.h Tue May 11 01:23:21 2021 +0000
+++ b/sys/net/if_spppvar.h Tue May 11 01:27:45 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_spppvar.h,v 1.36 2021/05/11 01:23:21 yamaguchi Exp $ */
+/* $NetBSD: if_spppvar.h,v 1.37 2021/05/11 01:27:45 yamaguchi Exp $ */
#ifndef _NET_IF_SPPPVAR_H_
#define _NET_IF_SPPPVAR_H_
@@ -141,6 +141,7 @@ struct sppp {
struct ifqueue pp_cpq; /* PPP control protocol queue */
struct sppp *pp_next; /* next interface in keepalive list */
u_int pp_flags; /* use Cisco protocol instead of PPP */
+ u_int pp_ncpflags; /* enable or disable each NCP */
u_int pp_framebytes; /* number of bytes added by (hardware) framing */
u_int pp_alivecnt; /* keepalive packets counter */
u_int pp_loopcnt; /* loopback detection counter */
Home |
Main Index |
Thread Index |
Old Index