diff --git a/sys/dev/pci/if_lmc.c b/sys/dev/pci/if_lmc.c index a3bdea8b9a35..c43582cbebe5 100644 --- a/sys/dev/pci/if_lmc.c +++ b/sys/dev/pci/if_lmc.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_lmc.c,v 1.17 2001/11/13 07:48:43 lukem Exp $ */ +/* $NetBSD: if_lmc.c,v 1.18 2002/01/04 12:21:24 martin Exp $ */ /*- * Copyright (c) 1997-1999 LAN Media Corporation (LMC) @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_lmc.c,v 1.17 2001/11/13 07:48:43 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_lmc.c,v 1.18 2002/01/04 12:21:24 martin Exp $"); #include #include @@ -100,8 +100,10 @@ __KERNEL_RCSID(0, "$NetBSD: if_lmc.c,v 1.17 2001/11/13 07:48:43 lukem Exp $"); #endif -#if defined(__FreeBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) #include +#elif defined(__NetBSD__) +#include #endif #if defined(__bsdi__) diff --git a/sys/dev/pci/if_lmc_common.c b/sys/dev/pci/if_lmc_common.c index 805847dfaac9..635cd2b56227 100644 --- a/sys/dev/pci/if_lmc_common.c +++ b/sys/dev/pci/if_lmc_common.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_lmc_common.c,v 1.8 2001/11/13 07:48:44 lukem Exp $ */ +/* $NetBSD: if_lmc_common.c,v 1.9 2002/01/04 12:21:24 martin Exp $ */ /*- * Copyright (c) 1997-1999 LAN Media Corporation (LMC) @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_lmc_common.c,v 1.8 2001/11/13 07:48:44 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_lmc_common.c,v 1.9 2002/01/04 12:21:24 martin Exp $"); #include #include @@ -99,8 +99,10 @@ __KERNEL_RCSID(0, "$NetBSD: if_lmc_common.c,v 1.8 2001/11/13 07:48:44 lukem Exp #include #endif -#if defined(__FreeBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) #include +#elif defined(__NetBSD__) +#include #endif #if defined(__bsdi__) diff --git a/sys/dev/pci/if_lmc_media.c b/sys/dev/pci/if_lmc_media.c index 9ecc9558b932..d54737e9fa62 100644 --- a/sys/dev/pci/if_lmc_media.c +++ b/sys/dev/pci/if_lmc_media.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_lmc_media.c,v 1.12 2001/11/13 07:48:44 lukem Exp $ */ +/* $NetBSD: if_lmc_media.c,v 1.13 2002/01/04 12:21:24 martin Exp $ */ /*- * Copyright (c) 1997-1999 LAN Media Corporation (LMC) @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_lmc_media.c,v 1.12 2001/11/13 07:48:44 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_lmc_media.c,v 1.13 2002/01/04 12:21:24 martin Exp $"); #include #include @@ -75,8 +75,10 @@ __KERNEL_RCSID(0, "$NetBSD: if_lmc_media.c,v 1.12 2001/11/13 07:48:44 lukem Exp #include #endif -#if defined(__FreeBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) #include +#elif defined(__NetBSD__) +#include #endif #if defined(__bsdi__) diff --git a/sys/dev/pci/if_lmc_nbsd.c b/sys/dev/pci/if_lmc_nbsd.c index 688ec40c4297..372cb41a683a 100644 --- a/sys/dev/pci/if_lmc_nbsd.c +++ b/sys/dev/pci/if_lmc_nbsd.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_lmc_nbsd.c,v 1.15 2001/11/13 07:48:44 lukem Exp $ */ +/* $NetBSD: if_lmc_nbsd.c,v 1.16 2002/01/04 12:21:24 martin Exp $ */ /*- * Copyright (c) 1997-1999 LAN Media Corporation (LMC) @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_lmc_nbsd.c,v 1.15 2001/11/13 07:48:44 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_lmc_nbsd.c,v 1.16 2002/01/04 12:21:24 martin Exp $"); #include #include @@ -99,8 +99,10 @@ __KERNEL_RCSID(0, "$NetBSD: if_lmc_nbsd.c,v 1.15 2001/11/13 07:48:44 lukem Exp $ #include #endif -#if defined(__FreeBSD__) || defined(__NetBSD__) +#if defined(__FreeBSD__) #include +#elif defined(__NetBSD__) +#include #endif #if defined(__bsdi__) diff --git a/sys/net/if_pppoe.c b/sys/net/if_pppoe.c index caa6716bc7c1..cbab4819fced 100644 --- a/sys/net/if_pppoe.c +++ b/sys/net/if_pppoe.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.14 2001/12/16 23:53:31 martin Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.15 2002/01/04 12:21:25 martin Exp $ */ /* * Copyright (c) 2001 Martin Husemann. All rights reserved. @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.14 2001/12/16 23:53:31 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.15 2002/01/04 12:21:25 martin Exp $"); #include "pppoe.h" #include "bpfilter.h" @@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.14 2001/12/16 23:53:31 martin Exp $") #include #include #include +#include #include #if NBPFILTER > 0 @@ -101,11 +102,6 @@ struct pppoe_softc { LIST_ENTRY(pppoe_softc) sc_list; struct ifnet *sc_eth_if; /* ethernet interface we are using */ -#define PPPOE_STATE_INITIAL 0 -#define PPPOE_STATE_PADI_SENT 1 -#define PPPOE_STATE_PADR_SENT 2 -#define PPPOE_STATE_SESSION 3 -#define PPPOE_STATE_CLOSING 4 int sc_state; /* discovery phase or session connected */ struct ether_addr sc_dest; /* hardware address of concentrator */ u_int16_t sc_session; /* PPPoE session id */ @@ -660,6 +656,16 @@ pppoe_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data) return 0; } break; + case PPPOEGETSESSION: + { + struct pppoeconnectionstate *state = (struct pppoeconnectionstate*)data; + state->state = sc->sc_state; + state->session_id = sc->sc_session; + state->padi_retry_no = sc->sc_padi_retried; + state->padr_retry_no = sc->sc_padr_retried; + return 0; + } + break; case SIOCSIFFLAGS: { struct ifreq *ifr = (struct ifreq*) data; diff --git a/sys/net/if_pppoe.h b/sys/net/if_pppoe.h index 20ac9796a5be..9bdebee108a6 100644 --- a/sys/net/if_pppoe.h +++ b/sys/net/if_pppoe.h @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.h,v 1.1 2001/04/29 09:50:37 martin Exp $ */ +/* $NetBSD: if_pppoe.h,v 1.2 2002/01/04 12:21:25 martin Exp $ */ /* * Copyright (c) 2001 Martin Husemann. All rights reserved. @@ -36,7 +36,31 @@ struct pppoediscparms { }; #define PPPOESETPARMS _IOW('i', 110, struct pppoediscparms) -#define PPPOEGETPARMS _IOR('i', 111, struct pppoediscparms) +#define PPPOEGETPARMS _IOWR('i', 111, struct pppoediscparms) + +#define PPPOE_STATE_INITIAL 0 +#define PPPOE_STATE_PADI_SENT 1 +#define PPPOE_STATE_PADR_SENT 2 +#define PPPOE_STATE_SESSION 3 +#define PPPOE_STATE_CLOSING 4 + +struct pppoeconnectionstate { + char ifname[IFNAMSIZ]; /* pppoe interface name */ + u_int state; /* one of the PPPOE_STATE_ states above */ + u_int session_id; /* if state == PPPOE_STATE_SESSION */ + u_int padi_retry_no; /* number of retries already sent */ + u_int padr_retry_no; +}; + +#define PPPOEGETSESSION _IOWR('i', 112, struct pppoeconnectionstate) + +struct pppoeidletimeoutcfg { + char ifname[IFNAMSIZ]; /* pppoe interface name */ + u_long idle_timeout; /* idle timeout in seconds */ +}; + +#define PPPOEGETIDLETIMEOUT _IOWR('i', 113, struct pppoeidletimeoutcfg) +#define PPPOESETIDLETIMEOUT _IOW('i', 114, struct pppoeidletimeoutcfg) #ifdef _KERNEL diff --git a/sys/net/if_sppp.h b/sys/net/if_sppp.h index 1fd5aac3504f..2d929037d369 100644 --- a/sys/net/if_sppp.h +++ b/sys/net/if_sppp.h @@ -1,204 +1,82 @@ -/* $NetBSD: if_sppp.h,v 1.11 2001/12/31 21:55:46 thorpej Exp $ */ +/* $NetBSD: if_sppp.h,v 1.12 2002/01/04 12:21:25 martin Exp $ */ /* - * Defines for synchronous PPP/Cisco link level subroutines. + * Copyright (c) 2002 Martin Husemann. All rights reserved. * - * Copyright (C) 1994 Cronyx Ltd. - * Author: Serge Vakulenko, + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * - * Heavily revamped to conform to RFC 1661. - * Copyright (C) 1997, Joerg Wunsch. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. * - * This software is distributed with NO WARRANTIES, not even the implied - * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Authors grant any other persons or organizations permission to use - * or modify this software as long as this message is kept with the software, - * all derivative works or modified versions. - * - * From: Version 2.0, Fri Oct 6 20:39:21 MSK 1995 - * - * From: if_sppp.h,v 1.8 1997/10/11 11:25:20 joerg Exp - * - * From: Id: if_sppp.h,v 1.7 1998/12/01 20:20:19 hm Exp */ -#ifndef _NET_IF_HDLC_H_ -#define _NET_IF_HDLC_H_ 1 +/* ioctls used by the if_spppsubr.c driver */ -#include +#define SPPP_AUTHPROTO_NONE 0 +#define SPPP_AUTHPROTO_PAP 1 +#define SPPP_AUTHPROTO_CHAP 2 -#define IDX_LCP 0 /* idx into state table */ +#define SPPP_AUTHFLAG_NOCALLOUT 1 /* do not require authentication on */ + /* callouts */ +#define SPPP_AUTHFLAG_NORECHALLENGE 2 /* do not re-challenge CHAP */ -struct slcp { - u_long opts; /* LCP options to send (bitfield) */ - u_long magic; /* local magic number */ - u_long mru; /* our max receive unit */ - u_long their_mru; /* their max receive unit */ - u_long protos; /* bitmask of protos that are started */ - u_char echoid; /* id of last keepalive echo request */ - /* restart max values, see RFC 1661 */ - int timeout; - int max_terminate; - int max_configure; - int max_failure; +struct spppauthcfg { + char ifname[IFNAMSIZ]; /* pppoe interface name */ + int hisauth; /* one of SPPP_AUTHPROTO_* above */ + int myauth; /* one of SPPP_AUTHPROTO_* above */ + int myname_length; /* includes terminating 0 */ + int mysecret_length; /* includes terminating 0 */ + int hisname_length; /* includes terminating 0 */ + int hissecret_length; /* includes terminating 0 */ + int myauthflags; + int hisauthflags; + char *myname; + char *mysecret; + char *hisname; + char *hissecret; }; -#define IDX_IPCP 1 /* idx into state table */ -#define IDX_IPV6CP 2 /* idx into state table */ +#define SPPPGETAUTHCFG _IOWR('i', 120, struct spppauthcfg) +#define SPPPSETAUTHCFG _IOW('i', 121, struct spppauthcfg) -struct sipcp { - u_long opts; /* IPCP options to send (bitfield) */ - u_int flags; -#define IPCP_HISADDR_SEEN 1 /* have seen his address already */ -#define IPCP_MYADDR_SEEN 2 /* have a local address assigned already */ -#define IPCP_MYADDR_DYN 4 /* my address is dynamically assigned */ -#define IPCP_HISADDR_DYN 8 /* his address is dynamically assigned */ -#ifdef notdef -#define IPV6CP_MYIFID_DYN 2 /* my ifid is dynamically assigned */ -#endif -#define IPV6CP_MYIFID_SEEN 4 /* have seen his ifid already */ - u_int32_t saved_hisaddr;/* if hisaddr (IPv4) is dynamic, save original one here, in network byte order */ - u_int32_t req_hisaddr; /* remote address requested */ - u_int32_t req_myaddr; /* local address requested */ +struct sppplcpcfg { + char ifname[IFNAMSIZ]; /* pppoe interface name */ + int lcp_timeout; /* LCP timeout, in ticks */ }; -#define AUTHNAMELEN 48 -#define AUTHKEYLEN 16 - -struct sauth { - u_short proto; /* authentication protocol to use */ - u_short flags; -#define AUTHFLAG_NOCALLOUT 1 /* do not require authentication on */ - /* callouts */ -#define AUTHFLAG_NORECHALLENGE 2 /* do not re-challenge CHAP */ - u_char name[AUTHNAMELEN]; /* system identification name */ - u_char secret[AUTHKEYLEN]; /* secret password */ - u_char challenge[AUTHKEYLEN]; /* random challenge */ -}; - -#define IDX_PAP 3 -#define IDX_CHAP 4 - -#define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */ +#define SPPPGETLCPCFG _IOWR('i', 122, struct sppplcpcfg) +#define SPPPSETLCPCFG _IOW('i', 123, struct sppplcpcfg) /* * Don't change the order of this. Ordering the phases this way allows * for a comparision of ``pp_phase >= PHASE_AUTHENTICATE'' in order to * know whether LCP is up. */ -enum ppp_phase { - PHASE_DEAD, PHASE_ESTABLISH, PHASE_TERMINATE, - PHASE_AUTHENTICATE, PHASE_NETWORK +#define SPPP_PHASE_DEAD 0 +#define SPPP_PHASE_ESTABLISH 1 +#define SPPP_PHASE_TERMINATE 2 +#define SPPP_PHASE_AUTHENTICATE 3 +#define SPPP_PHASE_NETWORK 4 + +struct spppstatus { + char ifname[IFNAMSIZ]; /* pppoe interface name */ + int phase; /* one of SPPP_PHASE_* above */ }; -struct sppp { - /* NB: pp_if _must_ be first */ - struct ifnet pp_if; /* network interface data */ - struct ifqueue pp_fastq; /* fast output queue */ - 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_framebytes; /* number of bytes added by (hardware) framing */ - u_short pp_alivecnt; /* keepalive packets counter */ - u_short pp_loopcnt; /* loopback detection counter */ - u_long pp_seq[IDX_COUNT]; /* local sequence number */ - u_long pp_rseq[IDX_COUNT]; /* remote sequence number */ - enum ppp_phase pp_phase; /* phase we're currently in */ - int state[IDX_COUNT]; /* state machine */ - u_char confid[IDX_COUNT]; /* id of last configuration request */ - int rst_counter[IDX_COUNT]; /* restart counter */ - int fail_counter[IDX_COUNT]; /* negotiation failure counter */ -#if defined(__NetBSD__) - struct callout ch[IDX_COUNT]; /* per-proto and if callouts */ - struct callout pap_my_to_ch; /* PAP needs one more... */ -#endif -#if defined(__FreeBSD__) && __FreeBSD__ >= 3 - struct callout_handle ch[IDX_COUNT]; /* per-proto and if callouts */ - struct callout_handle pap_my_to_ch; /* PAP needs one more... */ -#endif - struct slcp lcp; /* LCP params */ - struct sipcp ipcp; /* IPCP params */ - struct sipcp ipv6cp; /* IPv6CP params */ - struct sauth myauth; /* auth params, i'm peer */ - struct sauth hisauth; /* auth params, i'm authenticator */ - /* - * These functions are filled in by sppp_attach(), and are - * expected to be used by the lower layer (hardware) drivers - * in order to communicate the (un)availability of the - * communication link. Lower layer drivers that are always - * ready to communicate (like hardware HDLC) can shortcut - * pp_up from pp_tls, and pp_down from pp_tlf. - */ - void (*pp_up)(struct sppp *sp); - void (*pp_down)(struct sppp *sp); - /* - * These functions need to be filled in by the lower layer - * (hardware) drivers if they request notification from the - * PPP layer whether the link is actually required. They - * correspond to the tls and tlf actions. - */ - void (*pp_tls)(struct sppp *sp); - void (*pp_tlf)(struct sppp *sp); - /* - * These (optional) functions may be filled by the hardware - * driver if any notification of established connections - * (currently: IPCP up) is desired (pp_con) or any internal - * state change of the interface state machine should be - * signaled for monitoring purposes (pp_chg). - */ - void (*pp_con)(struct sppp *sp); - void (*pp_chg)(struct sppp *sp, int new_state); -}; - -#define PP_KEEPALIVE 0x01 /* use keepalive protocol */ -#define PP_CISCO 0x02 /* use Cisco protocol instead of PPP */ - /* 0x04 was PP_TIMO */ -#define PP_CALLIN 0x08 /* we are being called */ -#define PP_NEEDAUTH 0x10 /* remote requested authentication */ -#define PP_NOFRAMING 0x20 /* do not add/expect encapsulation - around PPP frames (i.e. the serial - HDLC like encapsulation, RFC1662) */ - - -#define PP_MTU 1500 /* default/minimal MRU */ -#define PP_MAX_MRU 2048 /* maximal MRU we want to negotiate */ - -/* - * Definitions to pass struct sppp data down into the kernel using the - * SIOC[SG]IFGENERIC ioctl interface. - * - * In order to use this, create a struct spppreq, fill in the cmd - * field with SPPPIOGDEFS, and put the address of this structure into - * the ifr_data portion of a struct ifreq. Pass this struct to a - * SIOCGIFGENERIC ioctl. Then replace the cmd field by SPPPIOCDEFS, - * modify the defs field as desired, and pass the struct ifreq now - * to a SIOCSIFGENERIC ioctl. - */ - -#define SPPPIOGDEFS ((('S' << 24) + (1 << 16) + sizeof(struct sppp))) -#define SPPPIOSDEFS ((('S' << 24) + (2 << 16) + sizeof(struct sppp))) - -struct spppreq { - int cmd; - struct sppp defs; -}; - -#if (defined(__FreeBSD_version) && __FreeBSD_version < 300000) || \ - (defined(__FreeBSD__) && __FreeBSD__ < 3) -#define SIOCSIFGENERIC _IOW('i', 57, struct ifreq) /* generic IF set op */ -#define SIOCGIFGENERIC _IOWR('i', 58, struct ifreq) /* generic IF get op */ -#endif - -#if defined(KERNEL) || defined(_KERNEL) -void sppp_attach (struct ifnet *ifp); -void sppp_detach (struct ifnet *ifp); -void sppp_input (struct ifnet *ifp, struct mbuf *m); -int sppp_ioctl(struct ifnet *ifp, u_long cmd, void *data); -struct mbuf *sppp_dequeue (struct ifnet *ifp); -struct mbuf *sppp_pick(struct ifnet *ifp); -int sppp_isempty (struct ifnet *ifp); -void sppp_flush (struct ifnet *ifp); -#endif - -#endif /* _NET_IF_HDLC_H_ */ +#define SPPPGETSTATUS _IOWR('i', 124, struct spppstatus) diff --git a/sys/net/if_spppsubr.c b/sys/net/if_spppsubr.c index 8f8f590e569d..41ee39815dd8 100644 --- a/sys/net/if_spppsubr.c +++ b/sys/net/if_spppsubr.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_spppsubr.c,v 1.35 2001/12/16 23:55:28 martin Exp $ */ +/* $NetBSD: if_spppsubr.c,v 1.36 2002/01/04 12:21:25 martin Exp $ */ /* * Synchronous PPP/Cisco link level subroutines. @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.35 2001/12/16 23:55:28 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.36 2002/01/04 12:21:25 martin Exp $"); #include "opt_inet.h" #include "opt_ipx.h" @@ -36,7 +36,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.35 2001/12/16 23:55:28 martin Exp #include "opt_ns.h" #include - +#include #include #include #include @@ -44,7 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.35 2001/12/16 23:55:28 martin Exp #include #include #include - +#include #include #include @@ -82,6 +82,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.35 2001/12/16 23:55:28 martin Exp #endif #include +#include #define MAXALIVECNT 3 /* max. alive packets */ @@ -356,11 +357,10 @@ static const char *sppp_ipcp_opt_name(u_char opt); static const char *sppp_ipv6cp_opt_name(u_char opt); #endif static const char *sppp_lcp_opt_name(u_char opt); -static const char *sppp_phase_name(enum ppp_phase phase); +static const char *sppp_phase_name(int phase); static const char *sppp_proto_name(u_short proto); static const char *sppp_state_name(int state); static int sppp_params(struct sppp *sp, int cmd, void *data); -static int sppp_strnlen(u_char *p, int max); static void sppp_get_ip_addrs(struct sppp *sp, u_int32_t *src, u_int32_t *dst, u_int32_t *srcmask); static void sppp_keepalive(void *dummy); @@ -577,18 +577,18 @@ sppp_input(struct ifnet *ifp, struct mbuf *m) m_freem (m); return; case PPP_PAP: - if (sp->pp_phase >= PHASE_AUTHENTICATE) + if (sp->pp_phase >= SPPP_PHASE_AUTHENTICATE) sppp_pap_input(sp, m); m_freem (m); return; case PPP_CHAP: - if (sp->pp_phase >= PHASE_AUTHENTICATE) + if (sp->pp_phase >= SPPP_PHASE_AUTHENTICATE) sppp_chap_input(sp, m); m_freem (m); return; #ifdef INET case PPP_IPCP: - if (sp->pp_phase == PHASE_NETWORK) + if (sp->pp_phase == SPPP_PHASE_NETWORK) sppp_cp_input(&ipcp, sp, m); m_freem (m); return; @@ -601,7 +601,7 @@ sppp_input(struct ifnet *ifp, struct mbuf *m) #endif #ifdef INET6 case PPP_IPV6CP: - if (sp->pp_phase == PHASE_NETWORK) + if (sp->pp_phase == SPPP_PHASE_NETWORK) sppp_cp_input(&ipv6cp, sp, m); m_freem (m); return; @@ -616,7 +616,7 @@ sppp_input(struct ifnet *ifp, struct mbuf *m) #ifdef IPX case PPP_IPX: /* IPX IPXCP not implemented yet */ - if (sp->pp_phase == PHASE_NETWORK) { + if (sp->pp_phase == SPPP_PHASE_NETWORK) { schednetisr (NETISR_IPX); inq = &ipxintrq; } @@ -625,7 +625,7 @@ sppp_input(struct ifnet *ifp, struct mbuf *m) #ifdef NS case PPP_XNS: /* XNS IDPCP not implemented yet */ - if (sp->pp_phase == PHASE_NETWORK) { + if (sp->pp_phase == SPPP_PHASE_NETWORK) { schednetisr (NETISR_NS); inq = &nsintrq; } @@ -634,7 +634,7 @@ sppp_input(struct ifnet *ifp, struct mbuf *m) #ifdef ISO case PPP_ISO: /* OSI NLCP not implemented yet */ - if (sp->pp_phase == PHASE_NETWORK) { + if (sp->pp_phase == SPPP_PHASE_NETWORK) { schednetisr (NETISR_ISO); inq = &clnlintrq; } @@ -921,12 +921,14 @@ sppp_attach(struct ifnet *ifp) sp->pp_alivecnt = 0; memset(&sp->pp_seq[0], 0, sizeof(sp->pp_seq)); memset(&sp->pp_rseq[0], 0, sizeof(sp->pp_rseq)); - sp->pp_phase = PHASE_DEAD; + sp->pp_phase = SPPP_PHASE_DEAD; sp->pp_up = lcp.Up; sp->pp_down = lcp.Down; if_alloc_sadl(ifp); + memset(&sp->myauth, 0, sizeof sp->myauth); + memset(&sp->hisauth, 0, sizeof sp->hisauth); sppp_lcp_init(sp); sppp_ipcp_init(sp); sppp_ipv6cp_init(sp); @@ -957,6 +959,12 @@ sppp_detach(struct ifnet *ifp) } callout_stop(&sp->pap_my_to_ch); + /* free authentication info */ + if (sp->myauth.name) free(sp->myauth.name, M_DEVBUF); + if (sp->myauth.secret) free(sp->myauth.secret, M_DEVBUF); + if (sp->hisauth.name) free(sp->hisauth.name, M_DEVBUF); + if (sp->hisauth.secret) free(sp->hisauth.secret, M_DEVBUF); + if_free_sadl(ifp); } @@ -1031,7 +1039,7 @@ sppp_pick(struct ifnet *ifp) m = sp->pp_cpq.ifq_head; if (m == NULL && - (sp->pp_phase == PHASE_NETWORK || + (sp->pp_phase == SPPP_PHASE_NETWORK || (sp->pp_flags & PP_CISCO) != 0)) if ((m = sp->pp_fastq.ifq_head) == NULL) m = sp->pp_if.if_snd.ifq_head; @@ -1117,8 +1125,18 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd, void *data) case SIOCDELMULTI: break; - case SIOCGIFGENERIC: - case SIOCSIFGENERIC: + case SPPPSETAUTHCFG: + case SPPPSETLCPCFG: + { + struct proc *p = curproc; /* XXX */ + + if ((rv = suser(p->p_ucred, &p->p_acflag)) != 0) + break; + } + /* FALLTHROUGH */ + case SPPPGETAUTHCFG: + case SPPPGETLCPCFG: + case SPPPGETSTATUS: rv = sppp_params(sp, cmd, data); break; @@ -2139,7 +2157,7 @@ sppp_lcp_RCR(struct sppp *sp, struct lcp_header *h, int len) } /* * Remote want us to authenticate, remember this, - * so we stay in PHASE_AUTHENTICATE after LCP got + * so we stay in SPPP_PHASE_AUTHENTICATE after LCP got * up. */ sp->pp_flags |= PP_NEEDAUTH; @@ -2332,10 +2350,10 @@ sppp_lcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len) /* * Peer doesn't want to authenticate himself, * deny unless this is a dialout call, and - * AUTHFLAG_NOCALLOUT is set. + * SPPP_AUTHFLAG_NOCALLOUT is set. */ if ((sp->pp_flags & PP_CALLIN) == 0 && - (sp->hisauth.flags & AUTHFLAG_NOCALLOUT) != 0) { + (sp->hisauth.flags & SPPP_AUTHFLAG_NOCALLOUT) != 0) { if (debug) addlog(" [don't insist on auth " "for callout]"); @@ -2454,9 +2472,9 @@ sppp_lcp_tlu(struct sppp *sp) if ((sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0 || (sp->pp_flags & PP_NEEDAUTH) != 0) - sp->pp_phase = PHASE_AUTHENTICATE; + sp->pp_phase = SPPP_PHASE_AUTHENTICATE; else - sp->pp_phase = PHASE_NETWORK; + sp->pp_phase = SPPP_PHASE_NETWORK; if(debug) { @@ -2475,7 +2493,7 @@ sppp_lcp_tlu(struct sppp *sp) if ((cps[i])->flags & CP_AUTH) (cps[i])->Open(sp); - if (sp->pp_phase == PHASE_NETWORK) { + if (sp->pp_phase == SPPP_PHASE_NETWORK) { /* Notify all NCPs. */ for (i = 0; i < IDX_COUNT; i++) if ((cps[i])->flags & CP_NCP) @@ -2491,7 +2509,7 @@ sppp_lcp_tlu(struct sppp *sp) if (sp->pp_chg) sp->pp_chg(sp, (int)sp->pp_phase); - if (sp->pp_phase == PHASE_NETWORK) + if (sp->pp_phase == SPPP_PHASE_NETWORK) /* if no NCP is starting, close down */ sppp_lcp_check_and_close(sp); } @@ -2503,7 +2521,7 @@ sppp_lcp_tld(struct sppp *sp) int i; u_int32_t mask; - sp->pp_phase = PHASE_TERMINATE; + sp->pp_phase = SPPP_PHASE_TERMINATE; if(debug) { @@ -2529,7 +2547,7 @@ sppp_lcp_tls(struct sppp *sp) { STDDCL; - sp->pp_phase = PHASE_ESTABLISH; + sp->pp_phase = SPPP_PHASE_ESTABLISH; if(debug) { @@ -2547,7 +2565,7 @@ sppp_lcp_tlf(struct sppp *sp) { STDDCL; - sp->pp_phase = PHASE_DEAD; + sp->pp_phase = SPPP_PHASE_DEAD; if(debug) { @@ -2621,7 +2639,7 @@ static void sppp_lcp_check_and_close(struct sppp *sp) { - if (sp->pp_phase < PHASE_NETWORK) + if (sp->pp_phase < SPPP_PHASE_NETWORK) /* don't bother, we are already going down */ return; @@ -3250,7 +3268,7 @@ sppp_ipv6cp_RCR(struct sppp *sp, struct lcp_header *h, int len) case IPV6CP_OPT_IFID: memset(&desiredaddr, 0, sizeof(desiredaddr)); bcopy(&p[2], &desiredaddr.s6_addr[8], 8); - collision = (bcmp(&desiredaddr.s6_addr[8], + collision = (memcmp(&desiredaddr.s6_addr[8], &myaddr.s6_addr[8], 8) == 0); nohisaddr = IN6_IS_ADDR_UNSPECIFIED(&desiredaddr); @@ -3669,7 +3687,7 @@ sppp_chap_input(struct sppp *sp, struct mbuf *m) STDDCL; struct lcp_header *h; int len, x; - u_char *value, *name, digest[AUTHKEYLEN], dsize; + u_char *value, *name, digest[sizeof(sp->myauth.challenge)], dsize; int value_len, name_len; MD5_CTX ctx; @@ -3688,6 +3706,12 @@ sppp_chap_input(struct sppp *sp, struct mbuf *m) switch (h->type) { /* challenge, failure and success are his authproto */ case CHAP_CHALLENGE: + if (sp->myauth.secret == NULL || sp->myauth.name == NULL) { + /* can't do anything usefull */ + printf(SPP_FMT "chap input without my name and my secret being set\n", + SPP_ARGS(ifp)); + break; + } value = 1 + (u_char*)(h+1); value_len = value[-1]; name = value + value_len; @@ -3722,8 +3746,7 @@ sppp_chap_input(struct sppp *sp, struct mbuf *m) /* Compute reply value. */ MD5Init(&ctx); MD5Update(&ctx, &h->ident, 1); - MD5Update(&ctx, sp->myauth.secret, - sppp_strnlen(sp->myauth.secret, AUTHKEYLEN)); + MD5Update(&ctx, sp->myauth.secret, strlen(sp->myauth.secret)); MD5Update(&ctx, value, value_len); MD5Final(digest, &ctx); dsize = sizeof digest; @@ -3731,7 +3754,7 @@ sppp_chap_input(struct sppp *sp, struct mbuf *m) sppp_auth_send(&chap, sp, CHAP_RESPONSE, h->ident, sizeof dsize, (const char *)&dsize, sizeof digest, digest, - (size_t)sppp_strnlen(sp->myauth.name, AUTHNAMELEN), + strlen(sp->myauth.name), sp->myauth.name, 0); break; @@ -3780,6 +3803,12 @@ sppp_chap_input(struct sppp *sp, struct mbuf *m) /* response is my authproto */ case CHAP_RESPONSE: + if (sp->hisauth.secret == NULL) { + /* can't do anything usefull */ + printf(SPP_FMT "chap input without his secret being set\n", + SPP_ARGS(ifp)); + break; + } value = 1 + (u_char*)(h+1); value_len = value[-1]; name = value + value_len; @@ -3807,16 +3836,18 @@ sppp_chap_input(struct sppp *sp, struct mbuf *m) h->ident, sp->confid[IDX_CHAP]); break; } - if (name_len != sppp_strnlen(sp->hisauth.name, AUTHNAMELEN) - || bcmp(name, sp->hisauth.name, name_len) != 0) { + if (sp->hisauth.name != NULL && + (name_len != strlen(sp->hisauth.name) + || memcmp(name, sp->hisauth.name, name_len) != 0)) { log(LOG_INFO, SPP_FMT "chap response, his name ", SPP_ARGS(ifp)); sppp_print_string(name, name_len); addlog(" != expected "); sppp_print_string(sp->hisauth.name, - sppp_strnlen(sp->hisauth.name, AUTHNAMELEN)); + strlen(sp->hisauth.name)); addlog("\n"); - } + goto chap_failure; + } if (debug) { log(LOG_DEBUG, SPP_FMT "chap input(%s) " "<%s id=0x%x len=%d name=", @@ -3829,28 +3860,29 @@ sppp_chap_input(struct sppp *sp, struct mbuf *m) sppp_print_bytes(value, value_len); addlog(">\n"); } - if (value_len != AUTHKEYLEN) { + if (value_len != sizeof(sp->myauth.challenge)) { if (debug) log(LOG_DEBUG, SPP_FMT "chap bad hash value length: " "%d bytes, should be %d\n", SPP_ARGS(ifp), value_len, - AUTHKEYLEN); - break; + sizeof(sp->myauth.challenge)); + goto chap_failure; } MD5Init(&ctx); MD5Update(&ctx, &h->ident, 1); MD5Update(&ctx, sp->hisauth.secret, - sppp_strnlen(sp->hisauth.secret, AUTHKEYLEN)); - MD5Update(&ctx, sp->myauth.challenge, AUTHKEYLEN); + strlen(sp->hisauth.secret)); + MD5Update(&ctx, sp->myauth.challenge, sizeof(sp->myauth.challenge)); MD5Final(digest, &ctx); #define FAILMSG "Failed..." #define SUCCMSG "Welcome!" if (value_len != sizeof digest || - bcmp(digest, value, value_len) != 0) { + memcmp(digest, value, value_len) != 0) { +chap_failure: /* action scn, tld */ sppp_auth_send(&chap, sp, CHAP_FAILURE, h->ident, sizeof(FAILMSG) - 1, (u_char *)FAILMSG, @@ -3972,7 +4004,7 @@ sppp_chap_tlu(struct sppp *sp) * initial challenge-response exchange has taken place. * Provide for an option to avoid rechallenges. */ - if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0) { + if ((sp->hisauth.flags & SPPP_AUTHFLAG_NORECHALLENGE) == 0) { /* * Compute the re-challenge timeout. This will yield * a number between 300 and 810 seconds. @@ -3986,8 +4018,8 @@ sppp_chap_tlu(struct sppp *sp) log(LOG_DEBUG, SPP_FMT "chap %s, ", SPP_ARGS(ifp), - sp->pp_phase == PHASE_NETWORK? "reconfirmed": "tlu"); - if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0) + sp->pp_phase == SPPP_PHASE_NETWORK? "reconfirmed": "tlu"); + if ((sp->hisauth.flags & SPPP_AUTHFLAG_NORECHALLENGE) == 0) addlog("next re-challenge in %d seconds\n", i); else addlog("re-challenging supressed\n"); @@ -4012,7 +4044,7 @@ sppp_chap_tlu(struct sppp *sp) * If we are already in phase network, we are done here. This * is the case if this is a dummy tlu event after a re-challenge. */ - if (sp->pp_phase != PHASE_NETWORK) + if (sp->pp_phase != SPPP_PHASE_NETWORK) sppp_phase_network(sp); } @@ -4036,6 +4068,13 @@ sppp_chap_scr(struct sppp *sp) u_int32_t *ch, seed; u_char clen; + if (sp->myauth.name == NULL) { + /* can't do anything usefull */ + printf(SPP_FMT "chap starting without my name being set\n", + SPP_ARGS(&sp->pp_if)); + return; + } + /* Compute random challenge. */ ch = (u_int32_t *)sp->myauth.challenge; microtime(&tv); @@ -4044,14 +4083,14 @@ sppp_chap_scr(struct sppp *sp) ch[1] = seed ^ random(); ch[2] = seed ^ random(); ch[3] = seed ^ random(); - clen = AUTHKEYLEN; + clen = 16; /* 4 * sizeof(u_int32_t) */ sp->confid[IDX_CHAP] = ++sp->pp_seq[IDX_CHAP]; sppp_auth_send(&chap, sp, CHAP_CHALLENGE, sp->confid[IDX_CHAP], sizeof clen, (const char *)&clen, - (size_t)AUTHKEYLEN, sp->myauth.challenge, - (size_t)sppp_strnlen(sp->myauth.name, AUTHNAMELEN), + sizeof(sp->myauth.challenge), sp->myauth.challenge, + strlen(sp->myauth.name), sp->myauth.name, 0); } @@ -4077,7 +4116,8 @@ sppp_pap_input(struct sppp *sp, struct mbuf *m) STDDCL; struct lcp_header *h; int len, x; - u_char *name, *passwd, mlen; + u_char mlen; + char *name, *passwd; int name_len, passwd_len; len = m->m_pkthdr.len; @@ -4094,6 +4134,12 @@ sppp_pap_input(struct sppp *sp, struct mbuf *m) switch (h->type) { /* PAP request is my authproto */ case PAP_REQ: + if (sp->hisauth.name == NULL || sp->hisauth.secret == NULL) { + /* can't do anything usefull */ + printf(SPP_FMT "pap request without his name and his secret being set\n", + SPP_ARGS(ifp)); + break; + } name = 1 + (u_char*)(h+1); name_len = name[-1]; passwd = name + name_len + 1; @@ -4123,10 +4169,8 @@ sppp_pap_input(struct sppp *sp, struct mbuf *m) sppp_print_string((char*)passwd, passwd_len); addlog(">\n"); } - if (name_len > AUTHNAMELEN || - passwd_len > AUTHKEYLEN || - bcmp(name, sp->hisauth.name, name_len) != 0 || - bcmp(passwd, sp->hisauth.secret, passwd_len) != 0) { + if (memcmp(name, sp->hisauth.name, name_len) != 0 || + memcmp(passwd, sp->hisauth.secret, passwd_len) != 0) { /* action scn, tld */ mlen = sizeof(FAILMSG) - 1; sppp_auth_send(&pap, sp, PAP_NAK, h->ident, @@ -4354,15 +4398,22 @@ sppp_pap_scr(struct sppp *sp) { u_char idlen, pwdlen; + if (sp->myauth.secret == NULL || sp->myauth.name == NULL) { + /* can't do anything usefull */ + printf(SPP_FMT "pap starting without my name and secret being set\n", + SPP_ARGS(&sp->pp_if)); + return; + } + sp->confid[IDX_PAP] = ++sp->pp_seq[IDX_PAP]; - pwdlen = sppp_strnlen(sp->myauth.secret, AUTHKEYLEN); - idlen = sppp_strnlen(sp->myauth.name, AUTHNAMELEN); + pwdlen = strlen(sp->myauth.secret); + idlen = strlen(sp->myauth.name); sppp_auth_send(&pap, sp, PAP_REQ, sp->confid[IDX_PAP], sizeof idlen, (const char *)&idlen, - (size_t)idlen, sp->myauth.name, + idlen, sp->myauth.name, sizeof pwdlen, (const char *)&pwdlen, - (size_t)pwdlen, sp->myauth.secret, + pwdlen, sp->myauth.secret, 0); } /* @@ -4480,7 +4531,7 @@ sppp_keepalive(void *dummy) /* No keepalive in PPP mode if LCP not opened yet. */ if (! (sp->pp_flags & PP_CISCO) && - sp->pp_phase < PHASE_AUTHENTICATE) + sp->pp_phase < SPPP_PHASE_AUTHENTICATE) continue; if (sp->pp_alivecnt == MAXALIVECNT) { @@ -4509,7 +4560,7 @@ sppp_keepalive(void *dummy) if (sp->pp_flags & PP_CISCO) sppp_cisco_send (sp, CISCO_KEEPALIVE_REQ, ++sp->pp_seq[IDX_LCP], sp->pp_rseq[IDX_LCP]); - else if (sp->pp_phase >= PHASE_AUTHENTICATE) { + else if (sp->pp_phase >= SPPP_PHASE_AUTHENTICATE) { int32_t nmagic = htonl (sp->lcp.magic); sp->lcp.echoid = ++sp->pp_seq[IDX_LCP]; sppp_cp_send (sp, PPP_LCP, ECHO_REQ, @@ -4795,104 +4846,114 @@ sppp_suggest_ip6_addr(struct sppp *sp, struct in6_addr *suggest) } #endif /*INET6*/ +/* + * Process ioctl requests specific to the PPP interface. + * Permissions have already been checked. + */ static int sppp_params(struct sppp *sp, int cmd, void *data) { - struct ifreq *ifr = (struct ifreq *)data; - struct spppreq spr; - -#if 0 - /* - * ifr->ifr_data is supposed to point to a struct spppreq. - * Check the cmd word first before attempting to fetch all the - * data. - */ - if ((subcmd = fuword(ifr->ifr_data)) == -1) - return EFAULT; -#endif - - if (copyin((caddr_t)ifr->ifr_data, &spr, sizeof spr) != 0) - return EFAULT; - - switch (spr.cmd) { - case SPPPIOGDEFS: - if (cmd != (int)SIOCGIFGENERIC) - return EINVAL; - /* - * We copy over the entire current state, but clean - * out some of the stuff we don't wanna pass up. - * Remember, SIOCGIFGENERIC is unprotected, and can be - * called by any user. No need to ever get PAP or - * CHAP secrets back to userland anyway. - */ - bcopy(sp, &spr.defs, sizeof(struct sppp)); - memset(spr.defs.myauth.secret, 0, AUTHKEYLEN); - memset(spr.defs.myauth.challenge, 0, AUTHKEYLEN); - memset(spr.defs.hisauth.secret, 0, AUTHKEYLEN); - memset(spr.defs.hisauth.challenge, 0, AUTHKEYLEN); - return copyout(&spr, (caddr_t)ifr->ifr_data, sizeof spr); - - case SPPPIOSDEFS: - if (cmd != (int)SIOCSIFGENERIC) - return EINVAL; - /* - * We have a very specific idea of which fields we allow - * being passed back from userland, so to not clobber our - * current state. For one, we only allow setting - * anything if LCP is in dead phase. Once the LCP - * negotiations started, the authentication settings must - * not be changed again. (The administrator can force an - * ifconfig down in order to get LCP back into dead - * phase.) - * - * Also, we only allow for authentication parameters to be - * specified. - * - * XXX Should allow to set or clear pp_flags. - * - * Finally, if the respective authentication protocol to - * be used is set differently than 0, but the secret is - * passed as all zeros, we don't trash the existing secret. - * This allows an administrator to change the system name - * only without clobbering the secret (which he didn't get - * back in a previous SPPPIOGDEFS call). However, the - * secrets are cleared if the authentication protocol is - * reset to 0. - */ - if (sp->pp_phase != PHASE_DEAD) - return EBUSY; - - if ((spr.defs.myauth.proto != 0 && spr.defs.myauth.proto != PPP_PAP && - spr.defs.myauth.proto != PPP_CHAP) || - (spr.defs.hisauth.proto != 0 && spr.defs.hisauth.proto != PPP_PAP && - spr.defs.hisauth.proto != PPP_CHAP)) - return EINVAL; - - if (spr.defs.myauth.proto == 0) - /* resetting myauth */ - memset(&sp->myauth, 0, sizeof sp->myauth); - else { - /* setting/changing myauth */ - sp->myauth.proto = spr.defs.myauth.proto; - bcopy(spr.defs.myauth.name, sp->myauth.name, AUTHNAMELEN); - if (spr.defs.myauth.secret[0] != '\0') - bcopy(spr.defs.myauth.secret, sp->myauth.secret, - AUTHKEYLEN); + switch (cmd) { + case SPPPGETAUTHCFG: + { + struct spppauthcfg * cfg = (struct spppauthcfg*)data; + cfg->myauthflags = sp->myauth.flags; + cfg->hisauthflags = sp->hisauth.flags; + strncpy(cfg->ifname, sp->pp_if.if_xname, IFNAMSIZ); + cfg->hisauth = 0; + if (sp->hisauth.proto) + cfg->hisauth = sp->hisauth.proto == PPP_PAP ? SPPP_AUTHPROTO_PAP : SPPP_AUTHPROTO_CHAP; + cfg->myauth = 0; + if (sp->myauth.proto) + cfg->myauth = sp->myauth.proto == PPP_PAP ? SPPP_AUTHPROTO_PAP : SPPP_AUTHPROTO_CHAP; + if (cfg->myname_length == 0) { + if (sp->myauth.name != NULL) + cfg->myname_length = strlen(sp->myauth.name)+1; + } else { + int rv; + size_t len = strlen(sp->myauth.name); + if (cfg->myname_length < len+1) + return ENAMETOOLONG; + rv = copyout(sp->myauth.name, cfg->myname, len); + if (rv) return rv; } - if (spr.defs.hisauth.proto == 0) - /* resetting hisauth */ - memset(&sp->hisauth, 0, sizeof sp->hisauth); - else { - /* setting/changing hisauth */ - sp->hisauth.proto = spr.defs.hisauth.proto; - sp->hisauth.flags = spr.defs.hisauth.flags; - bcopy(spr.defs.hisauth.name, sp->hisauth.name, AUTHNAMELEN); - if (spr.defs.hisauth.secret[0] != '\0') - bcopy(spr.defs.hisauth.secret, sp->hisauth.secret, - AUTHKEYLEN); + if (cfg->hisname_length == 0) { + if(sp->hisauth.name != NULL) + cfg->hisname_length = strlen(sp->hisauth.name)+1; + } else { + int rv; + size_t len = strlen(sp->hisauth.name); + if (cfg->hisname_length < len+1) + return ENAMETOOLONG; + rv = copyout(sp->hisauth.name, cfg->hisname, len); + if (rv) return rv; } - break; + } + break; + case SPPPSETAUTHCFG: + { + struct spppauthcfg * cfg = (struct spppauthcfg*)data; + int rv; + if (sp->myauth.name) free(sp->myauth.name, M_DEVBUF); + sp->myauth.name = NULL; + if (sp->myauth.secret) free(sp->myauth.secret, M_DEVBUF); + sp->myauth.secret = NULL; + if (sp->hisauth.name) free(sp->hisauth.name, M_DEVBUF); + sp->hisauth.name = NULL; + if (sp->hisauth.secret) free(sp->hisauth.secret, M_DEVBUF); + sp->hisauth.secret = NULL; + + if (cfg->hisname != NULL && cfg->hisname_length) { + sp->hisauth.name = malloc(cfg->hisname_length, M_DEVBUF, M_WAITOK); + rv = copyin(cfg->hisname, sp->hisauth.name, cfg->hisname_length); + if (rv) return rv; + sp->hisauth.name[cfg->hisname_length-1] = 0; + } + if (cfg->hissecret != NULL && cfg->hissecret_length) { + sp->hisauth.secret = malloc(cfg->hissecret_length, M_DEVBUF, M_WAITOK); + rv = copyin(cfg->hissecret, sp->hisauth.secret, cfg->hissecret_length); + if (rv) return rv; + sp->hisauth.secret[cfg->hisname_length-1] = 0; + } + if (cfg->myname != NULL && cfg->myname_length) { + sp->myauth.name = malloc(cfg->myname_length, M_DEVBUF, M_WAITOK); + rv = copyin(cfg->myname, sp->myauth.name, cfg->myname_length); + if (rv) return rv; + sp->myauth.name[cfg->myname_length-1] = 0; + } + if (cfg->mysecret != NULL && cfg->mysecret_length) { + sp->myauth.secret = malloc(cfg->mysecret_length, M_DEVBUF, M_WAITOK); + rv = copyin(cfg->mysecret, sp->myauth.secret, cfg->mysecret_length); + if (rv) return rv; + sp->myauth.secret[cfg->myname_length-1] = 0; + } + sp->myauth.flags = cfg->myauthflags; + if (cfg->myauth) + sp->myauth.proto = cfg->myauth == SPPP_AUTHPROTO_PAP ? PPP_PAP : PPP_CHAP; + sp->hisauth.flags = cfg->hisauthflags; + if (cfg->hisauth) + sp->hisauth.proto = cfg->hisauth == SPPP_AUTHPROTO_PAP ? PPP_PAP : PPP_CHAP; + } + break; + case SPPPGETLCPCFG: + { + struct sppplcpcfg * lcp = (struct sppplcpcfg*)data; + lcp->lcp_timeout = sp->lcp.timeout; + } + break; + case SPPPSETLCPCFG: + { + struct sppplcpcfg * lcp = (struct sppplcpcfg*)data; + sp->lcp.timeout = lcp->lcp_timeout; + } + break; + case SPPPGETSTATUS: + { + struct spppstatus * status = (struct spppstatus*)data; + status->phase = sp->pp_phase; + } + break; default: return EINVAL; } @@ -4907,7 +4968,7 @@ sppp_phase_network(struct sppp *sp) int i; u_int32_t mask; - sp->pp_phase = PHASE_NETWORK; + sp->pp_phase = SPPP_PHASE_NETWORK; if(debug) { @@ -5037,14 +5098,14 @@ sppp_state_name(int state) } static const char * -sppp_phase_name(enum ppp_phase phase) +sppp_phase_name(int phase) { switch (phase) { - case PHASE_DEAD: return "dead"; - case PHASE_ESTABLISH: return "establish"; - case PHASE_TERMINATE: return "terminate"; - case PHASE_AUTHENTICATE: return "authenticate"; - case PHASE_NETWORK: return "network"; + case SPPP_PHASE_DEAD: return "dead"; + case SPPP_PHASE_ESTABLISH: return "establish"; + case SPPP_PHASE_TERMINATE: return "terminate"; + case SPPP_PHASE_AUTHENTICATE: return "authenticate"; + case SPPP_PHASE_NETWORK: return "network"; } return "illegal"; } @@ -5101,16 +5162,6 @@ sppp_dotted_quad(u_int32_t addr) return s; } -static int -sppp_strnlen(u_char *p, int max) -{ - int len; - - for (len = 0; len < max && *p; ++p) - ++len; - return len; -} - /* a dummy, used to drop uninteresting events */ static void sppp_null(struct sppp *unused) diff --git a/sys/netisdn/i4b_i4bdrv.c b/sys/netisdn/i4b_i4bdrv.c index 0122e330353f..196989b085f0 100644 --- a/sys/netisdn/i4b_i4bdrv.c +++ b/sys/netisdn/i4b_i4bdrv.c @@ -27,7 +27,7 @@ * i4b_i4bdrv.c - i4b userland interface driver * -------------------------------------------- * - * $Id: i4b_i4bdrv.c,v 1.7 2001/11/15 09:48:28 lukem Exp $ + * $Id: i4b_i4bdrv.c,v 1.8 2002/01/04 12:21:26 martin Exp $ * * $FreeBSD$ * @@ -36,7 +36,7 @@ *---------------------------------------------------------------------------*/ #include -__KERNEL_RCSID(0, "$NetBSD: i4b_i4bdrv.c,v 1.7 2001/11/15 09:48:28 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i4b_i4bdrv.c,v 1.8 2002/01/04 12:21:26 martin Exp $"); #include "i4b.h" #include "i4bipr.h" @@ -73,16 +73,6 @@ __KERNEL_RCSID(0, "$NetBSD: i4b_i4bdrv.c,v 1.7 2001/11/15 09:48:28 lukem Exp $") #include "i4bing.h" #endif -#ifdef __bsdi__ -#include "ibc.h" -#else -#ifdef __FreeBSD__ -#include "i4bisppp.h" -#else -#include -#endif -#endif - #ifdef __FreeBSD__ #if defined(__FreeBSD__) && __FreeBSD__ == 3 diff --git a/sys/netisdn/i4b_isppp.c b/sys/netisdn/i4b_isppp.c index 005de6577a20..172855f3d9df 100644 --- a/sys/netisdn/i4b_isppp.c +++ b/sys/netisdn/i4b_isppp.c @@ -34,7 +34,7 @@ * the "cx" driver for Cronyx's HDLC-in-hardware device). This driver * is only the glue between sppp and i4b. * - * $Id: i4b_isppp.c,v 1.7 2001/11/13 01:06:21 lukem Exp $ + * $Id: i4b_isppp.c,v 1.8 2002/01/04 12:21:26 martin Exp $ * * $FreeBSD$ * @@ -43,7 +43,7 @@ *---------------------------------------------------------------------------*/ #include -__KERNEL_RCSID(0, "$NetBSD: i4b_isppp.c,v 1.7 2001/11/13 01:06:21 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i4b_isppp.c,v 1.8 2002/01/04 12:21:26 martin Exp $"); #ifndef __NetBSD__ #define USE_ISPPP @@ -73,6 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: i4b_isppp.c,v 1.7 2001/11/13 01:06:21 lukem Exp $"); #include #include #include +#include #include #include @@ -86,16 +87,7 @@ __KERNEL_RCSID(0, "$NetBSD: i4b_isppp.c,v 1.7 2001/11/13 01:06:21 lukem Exp $"); #include -#if defined(__FreeBSD__) || defined(__OpenBSD__) -#ifndef USE_ISPPP -#include -#else -#include -#endif /* USE_ISPPP */ -#else -#include -#endif - +#include #if defined(__FreeBSD_version) && __FreeBSD_version >= 400008 #include "bpf.h"