2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Synchronous PPP/Cisco link level subroutines.
24 * Keepalive protocol implemented in both Cisco and PPP modes.
26 * Copyright (C) 1994-1996 Cronyx Engineering Ltd.
27 * Author: Serge Vakulenko, <vak@cronyx.ru>
29 * Heavily revamped to conform to RFC 1661.
30 * Copyright (C) 1997, Joerg Wunsch.
32 * This software is distributed with NO WARRANTIES, not even the implied
33 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35 * Authors grant any other persons or organisations permission to use
36 * or modify this software as long as this message is kept with the software,
37 * all derivative works or modified versions.
39 * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997
43 #include <sys/param.h>
45 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
52 # include "opt_inet.h"
57 #include <sys/systm.h>
58 #include <sys/kernel.h>
59 #include <sys/sockio.h>
60 #include <sys/socket.h>
61 #include <sys/syslog.h>
62 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
63 #include <machine/random.h>
65 #include <sys/malloc.h>
69 #if defined (__OpenBSD__)
76 #include <net/netisr.h>
77 #include <net/if_types.h>
78 #include <net/route.h>
80 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
81 #include <machine/random.h>
83 #if defined (__NetBSD__) || defined (__OpenBSD__)
84 #include <kern/cpu_number.h> /* XXX for softnet */
87 #include <machine/stdarg.h>
90 #include <netinet/in.h>
91 #include <netinet/in_systm.h>
92 #include <netinet/in_var.h>
93 #include <netinet/ip.h>
94 #include <netinet/tcp.h>
95 # if defined (__FreeBSD__) || defined (__OpenBSD__)
96 # include <netinet/if_ether.h>
98 # include <net/ethertypes.h>
101 # error Huh? sppp without INET?
105 #include <netipx/ipx.h>
106 #include <netipx/ipx_if.h>
110 #include <netns/ns.h>
111 #include <netns/ns_if.h>
115 #include <netiso/argo_debug.h>
116 #include <netiso/iso.h>
117 #include <netiso/iso_var.h>
118 #include <netiso/iso_snpac.h>
121 #include <net/if_sppp.h>
123 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
124 # define UNTIMEOUT(fun, arg, handle) untimeout(fun, arg, handle)
125 # define TIMEOUT(fun, arg1, arg2, handle) handle = timeout(fun, arg1, arg2)
126 # define IOCTL_CMD_T u_long
128 # define UNTIMEOUT(fun, arg, handle) untimeout(fun, arg)
129 # define TIMEOUT(fun, arg1, arg2, handle) timeout(fun, arg1, arg2)
130 # define IOCTL_CMD_T int
133 #define MAXALIVECNT 3 /* max. alive packets */
136 * Interface flags that can be set in an ifconfig command.
138 * Setting link0 will make the link passive, i.e. it will be marked
139 * as being administrative openable, but won't be opened to begin
140 * with. Incoming calls will be answered, or subsequent calls with
141 * -link1 will cause the administrative open of the LCP layer.
143 * Setting link1 will cause the link to auto-dial only as packets
146 * Setting IFF_DEBUG will syslog the option negotiation and state
147 * transitions at level kern.debug. Note: all logs consistently look
150 * <if-name><unit>: <proto-name> <additional info...>
152 * with <if-name><unit> being something like "bppp0", and <proto-name>
153 * being one of "lcp", "ipcp", "cisco", "chap", "pap", etc.
156 #define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */
157 #define IFF_AUTO IFF_LINK1 /* auto-dial on output */
159 #define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
160 #define PPP_UI 0x03 /* Unnumbered Information */
161 #define PPP_IP 0x0021 /* Internet Protocol */
162 #define PPP_ISO 0x0023 /* ISO OSI Protocol */
163 #define PPP_XNS 0x0025 /* Xerox NS Protocol */
164 #define PPP_IPX 0x002b /* Novell IPX Protocol */
165 #define PPP_LCP 0xc021 /* Link Control Protocol */
166 #define PPP_PAP 0xc023 /* Password Authentication Protocol */
167 #define PPP_CHAP 0xc223 /* Challenge-Handshake Auth Protocol */
168 #define PPP_IPCP 0x8021 /* Internet Protocol Control Protocol */
170 #define CONF_REQ 1 /* PPP configure request */
171 #define CONF_ACK 2 /* PPP configure acknowledge */
172 #define CONF_NAK 3 /* PPP configure negative ack */
173 #define CONF_REJ 4 /* PPP configure reject */
174 #define TERM_REQ 5 /* PPP terminate request */
175 #define TERM_ACK 6 /* PPP terminate acknowledge */
176 #define CODE_REJ 7 /* PPP code reject */
177 #define PROTO_REJ 8 /* PPP protocol reject */
178 #define ECHO_REQ 9 /* PPP echo request */
179 #define ECHO_REPLY 10 /* PPP echo reply */
180 #define DISC_REQ 11 /* PPP discard request */
182 #define LCP_OPT_MRU 1 /* maximum receive unit */
183 #define LCP_OPT_ASYNC_MAP 2 /* async control character map */
184 #define LCP_OPT_AUTH_PROTO 3 /* authentication protocol */
185 #define LCP_OPT_QUAL_PROTO 4 /* quality protocol */
186 #define LCP_OPT_MAGIC 5 /* magic number */
187 #define LCP_OPT_RESERVED 6 /* reserved */
188 #define LCP_OPT_PROTO_COMP 7 /* protocol field compression */
189 #define LCP_OPT_ADDR_COMP 8 /* address/control field compression */
191 #define IPCP_OPT_ADDRESSES 1 /* both IP addresses; deprecated */
192 #define IPCP_OPT_COMPRESSION 2 /* IP compression protocol (VJ) */
193 #define IPCP_OPT_ADDRESS 3 /* local IP address */
195 #define PAP_REQ 1 /* PAP name/password request */
196 #define PAP_ACK 2 /* PAP acknowledge */
197 #define PAP_NAK 3 /* PAP fail */
199 #define CHAP_CHALLENGE 1 /* CHAP challenge request */
200 #define CHAP_RESPONSE 2 /* CHAP challenge response */
201 #define CHAP_SUCCESS 3 /* CHAP response ok */
202 #define CHAP_FAILURE 4 /* CHAP response failed */
204 #define CHAP_MD5 5 /* hash algorithm - MD5 */
206 #define CISCO_MULTICAST 0x8f /* Cisco multicast address */
207 #define CISCO_UNICAST 0x0f /* Cisco unicast address */
208 #define CISCO_KEEPALIVE 0x8035 /* Cisco keepalive protocol */
209 #define CISCO_ADDR_REQ 0 /* Cisco address request */
210 #define CISCO_ADDR_REPLY 1 /* Cisco address reply */
211 #define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */
213 /* states are named and numbered according to RFC 1661 */
214 #define STATE_INITIAL 0
215 #define STATE_STARTING 1
216 #define STATE_CLOSED 2
217 #define STATE_STOPPED 3
218 #define STATE_CLOSING 4
219 #define STATE_STOPPING 5
220 #define STATE_REQ_SENT 6
221 #define STATE_ACK_RCVD 7
222 #define STATE_ACK_SENT 8
223 #define STATE_OPENED 9
230 #define PPP_HEADER_LEN sizeof (struct ppp_header)
237 #define LCP_HEADER_LEN sizeof (struct lcp_header)
239 struct cisco_packet
{
247 #define CISCO_PACKET_LEN 18
250 * We follow the spelling and capitalization of RFC 1661 here, to make
251 * it easier comparing with the standard. Please refer to this RFC in
252 * case you can't make sense out of these abbreviation; it will also
253 * explain the semantics related to the various events and actions.
256 u_short proto
; /* PPP control protocol number */
257 u_char protoidx
; /* index into state table in struct sppp */
259 #define CP_LCP 0x01 /* this is the LCP */
260 #define CP_AUTH 0x02 /* this is an authentication protocol */
261 #define CP_NCP 0x04 /* this is a NCP */
262 #define CP_QUAL 0x08 /* this is a quality reporting protocol */
263 const char *name
; /* name of this control protocol */
265 void (*Up
)(struct sppp
*sp
);
266 void (*Down
)(struct sppp
*sp
);
267 void (*Open
)(struct sppp
*sp
);
268 void (*Close
)(struct sppp
*sp
);
269 void (*TO
)(void *sp
);
270 int (*RCR
)(struct sppp
*sp
, struct lcp_header
*h
, int len
);
271 void (*RCN_rej
)(struct sppp
*sp
, struct lcp_header
*h
, int len
);
272 void (*RCN_nak
)(struct sppp
*sp
, struct lcp_header
*h
, int len
);
274 void (*tlu
)(struct sppp
*sp
);
275 void (*tld
)(struct sppp
*sp
);
276 void (*tls
)(struct sppp
*sp
);
277 void (*tlf
)(struct sppp
*sp
);
278 void (*scr
)(struct sppp
*sp
);
281 static struct sppp
*spppq
;
282 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
283 static struct callout_handle keepalive_ch
;
286 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
287 #define SPP_FMT "%s%d: "
288 #define SPP_ARGS(ifp) (ifp)->if_name, (ifp)->if_unit
290 #define SPP_FMT "%s: "
291 #define SPP_ARGS(ifp) (ifp)->if_xname
295 * The following disgusting hack gets around the problem that IP TOS
296 * can't be set yet. We want to put "interactive" traffic on a high
297 * priority queue. To decide if traffic is interactive, we check that
298 * a) it is TCP and b) one of its ports is telnet, rlogin or ftp control.
300 * XXX is this really still necessary? - joerg -
302 static u_short interactive_ports
[8] = {
306 #define INTERACTIVE(p) (interactive_ports[(p) & 7] == (p))
308 /* almost every function needs these */
310 struct ifnet *ifp = &sp->pp_if; \
311 int debug = ifp->if_flags & IFF_DEBUG
313 static int sppp_output(struct ifnet
*ifp
, struct mbuf
*m
,
314 struct sockaddr
*dst
, struct rtentry
*rt
);
316 static void sppp_cisco_send(struct sppp
*sp
, int type
, long par1
, long par2
);
317 static void sppp_cisco_input(struct sppp
*sp
, struct mbuf
*m
);
319 static void sppp_cp_input(const struct cp
*cp
, struct sppp
*sp
,
321 static void sppp_cp_send(struct sppp
*sp
, u_short proto
, u_char type
,
322 u_char ident
, u_short len
, void *data
);
323 /* static void sppp_cp_timeout(void *arg); */
324 static void sppp_cp_change_state(const struct cp
*cp
, struct sppp
*sp
,
326 static void sppp_auth_send(const struct cp
*cp
,
327 struct sppp
*sp
, unsigned int type
, unsigned int id
,
330 static void sppp_up_event(const struct cp
*cp
, struct sppp
*sp
);
331 static void sppp_down_event(const struct cp
*cp
, struct sppp
*sp
);
332 static void sppp_open_event(const struct cp
*cp
, struct sppp
*sp
);
333 static void sppp_close_event(const struct cp
*cp
, struct sppp
*sp
);
334 static void sppp_to_event(const struct cp
*cp
, struct sppp
*sp
);
336 static void sppp_null(struct sppp
*sp
);
338 static void sppp_lcp_init(struct sppp
*sp
);
339 static void sppp_lcp_up(struct sppp
*sp
);
340 static void sppp_lcp_down(struct sppp
*sp
);
341 static void sppp_lcp_open(struct sppp
*sp
);
342 static void sppp_lcp_close(struct sppp
*sp
);
343 static void sppp_lcp_TO(void *sp
);
344 static int sppp_lcp_RCR(struct sppp
*sp
, struct lcp_header
*h
, int len
);
345 static void sppp_lcp_RCN_rej(struct sppp
*sp
, struct lcp_header
*h
, int len
);
346 static void sppp_lcp_RCN_nak(struct sppp
*sp
, struct lcp_header
*h
, int len
);
347 static void sppp_lcp_tlu(struct sppp
*sp
);
348 static void sppp_lcp_tld(struct sppp
*sp
);
349 static void sppp_lcp_tls(struct sppp
*sp
);
350 static void sppp_lcp_tlf(struct sppp
*sp
);
351 static void sppp_lcp_scr(struct sppp
*sp
);
352 static void sppp_lcp_check_and_close(struct sppp
*sp
);
353 static int sppp_ncp_check(struct sppp
*sp
);
355 static void sppp_ipcp_init(struct sppp
*sp
);
356 static void sppp_ipcp_up(struct sppp
*sp
);
357 static void sppp_ipcp_down(struct sppp
*sp
);
358 static void sppp_ipcp_open(struct sppp
*sp
);
359 static void sppp_ipcp_close(struct sppp
*sp
);
360 static void sppp_ipcp_TO(void *sp
);
361 static int sppp_ipcp_RCR(struct sppp
*sp
, struct lcp_header
*h
, int len
);
362 static void sppp_ipcp_RCN_rej(struct sppp
*sp
, struct lcp_header
*h
, int len
);
363 static void sppp_ipcp_RCN_nak(struct sppp
*sp
, struct lcp_header
*h
, int len
);
364 static void sppp_ipcp_tlu(struct sppp
*sp
);
365 static void sppp_ipcp_tld(struct sppp
*sp
);
366 static void sppp_ipcp_tls(struct sppp
*sp
);
367 static void sppp_ipcp_tlf(struct sppp
*sp
);
368 static void sppp_ipcp_scr(struct sppp
*sp
);
370 static void sppp_pap_input(struct sppp
*sp
, struct mbuf
*m
);
371 static void sppp_pap_init(struct sppp
*sp
);
372 static void sppp_pap_open(struct sppp
*sp
);
373 static void sppp_pap_close(struct sppp
*sp
);
374 static void sppp_pap_TO(void *sp
);
375 static void sppp_pap_my_TO(void *sp
);
376 static void sppp_pap_tlu(struct sppp
*sp
);
377 static void sppp_pap_tld(struct sppp
*sp
);
378 static void sppp_pap_scr(struct sppp
*sp
);
380 static void sppp_chap_input(struct sppp
*sp
, struct mbuf
*m
);
381 static void sppp_chap_init(struct sppp
*sp
);
382 static void sppp_chap_open(struct sppp
*sp
);
383 static void sppp_chap_close(struct sppp
*sp
);
384 static void sppp_chap_TO(void *sp
);
385 static void sppp_chap_tlu(struct sppp
*sp
);
386 static void sppp_chap_tld(struct sppp
*sp
);
387 static void sppp_chap_scr(struct sppp
*sp
);
389 static const char *sppp_auth_type_name(u_short proto
, u_char type
);
390 static const char *sppp_cp_type_name(u_char type
);
391 static const char *sppp_dotted_quad(u_long addr
);
392 static const char *sppp_ipcp_opt_name(u_char opt
);
393 static const char *sppp_lcp_opt_name(u_char opt
);
394 static const char *sppp_phase_name(enum ppp_phase phase
);
395 static const char *sppp_proto_name(u_short proto
);
396 static const char *sppp_state_name(int state
);
397 static int sppp_params(struct sppp
*sp
, u_long cmd
, void *data
);
398 static int sppp_strnlen(u_char
*p
, int max
);
399 static void sppp_get_ip_addrs(struct sppp
*sp
, u_long
*src
, u_long
*dst
,
401 static void sppp_keepalive(void *dummy
);
402 static void sppp_phase_network(struct sppp
*sp
);
403 static void sppp_print_bytes(const u_char
*p
, u_short len
);
404 static void sppp_print_string(const char *p
, u_short len
);
405 static void sppp_qflush(struct ifqueue
*ifq
);
406 static void sppp_set_ip_addr(struct sppp
*sp
, u_long src
);
408 /* our control protocol descriptors */
409 static const struct cp lcp
= {
410 PPP_LCP
, IDX_LCP
, CP_LCP
, "lcp",
411 sppp_lcp_up
, sppp_lcp_down
, sppp_lcp_open
, sppp_lcp_close
,
412 sppp_lcp_TO
, sppp_lcp_RCR
, sppp_lcp_RCN_rej
, sppp_lcp_RCN_nak
,
413 sppp_lcp_tlu
, sppp_lcp_tld
, sppp_lcp_tls
, sppp_lcp_tlf
,
417 static const struct cp ipcp
= {
418 PPP_IPCP
, IDX_IPCP
, CP_NCP
, "ipcp",
419 sppp_ipcp_up
, sppp_ipcp_down
, sppp_ipcp_open
, sppp_ipcp_close
,
420 sppp_ipcp_TO
, sppp_ipcp_RCR
, sppp_ipcp_RCN_rej
, sppp_ipcp_RCN_nak
,
421 sppp_ipcp_tlu
, sppp_ipcp_tld
, sppp_ipcp_tls
, sppp_ipcp_tlf
,
425 static const struct cp pap
= {
426 PPP_PAP
, IDX_PAP
, CP_AUTH
, "pap",
427 sppp_null
, sppp_null
, sppp_pap_open
, sppp_pap_close
,
428 sppp_pap_TO
, 0, 0, 0,
429 sppp_pap_tlu
, sppp_pap_tld
, sppp_null
, sppp_null
,
433 static const struct cp chap
= {
434 PPP_CHAP
, IDX_CHAP
, CP_AUTH
, "chap",
435 sppp_null
, sppp_null
, sppp_chap_open
, sppp_chap_close
,
436 sppp_chap_TO
, 0, 0, 0,
437 sppp_chap_tlu
, sppp_chap_tld
, sppp_null
, sppp_null
,
441 static const struct cp
*cps
[IDX_COUNT
] = {
443 &ipcp
, /* IDX_IPCP */
445 &chap
, /* IDX_CHAP */
450 * Exported functions, comprising our interface to the lower layer.
454 * Process the received packet.
457 sppp_input(struct ifnet
*ifp
, struct mbuf
*m
)
459 struct ppp_header
*h
;
460 struct ifqueue
*inq
= 0;
462 struct sppp
*sp
= (struct sppp
*)ifp
;
463 int debug
= ifp
->if_flags
& IFF_DEBUG
;
465 if (ifp
->if_flags
& IFF_UP
)
466 /* Count received bytes, add FCS and one flag */
467 ifp
->if_ibytes
+= m
->m_pkthdr
.len
+ 3;
469 if (m
->m_pkthdr
.len
<= PPP_HEADER_LEN
) {
470 /* Too small packet, drop it. */
473 SPP_FMT
"input packet is too small, %d bytes\n",
474 SPP_ARGS(ifp
), m
->m_pkthdr
.len
);
482 /* Get PPP header. */
483 h
= mtod (m
, struct ppp_header
*);
484 m_adj (m
, PPP_HEADER_LEN
);
486 switch (h
->address
) {
487 case PPP_ALLSTATIONS
:
488 if (h
->control
!= PPP_UI
)
490 if (sp
->pp_flags
& PP_CISCO
) {
493 SPP_FMT
"PPP packet in Cisco mode "
494 "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
496 h
->address
, h
->control
, ntohs(h
->protocol
));
499 switch (ntohs (h
->protocol
)) {
501 if (sp
->state
[IDX_LCP
] == STATE_OPENED
)
502 sppp_cp_send (sp
, PPP_LCP
, PROTO_REJ
,
503 ++sp
->pp_seq
, m
->m_pkthdr
.len
+ 2,
507 SPP_FMT
"invalid input protocol "
508 "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
510 h
->address
, h
->control
, ntohs(h
->protocol
));
514 sppp_cp_input(&lcp
, sp
, m
);
518 if (sp
->pp_phase
>= PHASE_AUTHENTICATE
)
519 sppp_pap_input(sp
, m
);
523 if (sp
->pp_phase
>= PHASE_AUTHENTICATE
)
524 sppp_chap_input(sp
, m
);
529 if (sp
->pp_phase
== PHASE_NETWORK
)
530 sppp_cp_input(&ipcp
, sp
, m
);
534 if (sp
->state
[IDX_IPCP
] == STATE_OPENED
) {
535 schednetisr (NETISR_IP
);
542 /* IPX IPXCP not implemented yet */
543 if (sp
->pp_phase
== PHASE_NETWORK
) {
544 schednetisr (NETISR_IPX
);
551 /* XNS IDPCP not implemented yet */
552 if (sp
->pp_phase
== PHASE_NETWORK
) {
553 schednetisr (NETISR_NS
);
560 /* OSI NLCP not implemented yet */
561 if (sp
->pp_phase
== PHASE_NETWORK
) {
562 schednetisr (NETISR_ISO
);
569 case CISCO_MULTICAST
:
571 /* Don't check the control field here (RFC 1547). */
572 if (! (sp
->pp_flags
& PP_CISCO
)) {
575 SPP_FMT
"Cisco packet in PPP mode "
576 "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
578 h
->address
, h
->control
, ntohs(h
->protocol
));
581 switch (ntohs (h
->protocol
)) {
585 case CISCO_KEEPALIVE
:
586 sppp_cisco_input ((struct sppp
*) ifp
, m
);
591 schednetisr (NETISR_IP
);
597 schednetisr (NETISR_IPX
);
603 schednetisr (NETISR_NS
);
609 default: /* Invalid PPP packet. */
613 SPP_FMT
"invalid input packet "
614 "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
616 h
->address
, h
->control
, ntohs(h
->protocol
));
620 if (! (ifp
->if_flags
& IFF_UP
) || ! inq
)
625 if (IF_QFULL (inq
)) {
626 /* Queue overflow. */
630 log(LOG_DEBUG
, SPP_FMT
"protocol queue overflow\n",
639 * Enqueue transmit packet.
642 sppp_output(struct ifnet
*ifp
, struct mbuf
*m
,
643 struct sockaddr
*dst
, struct rtentry
*rt
)
645 struct sppp
*sp
= (struct sppp
*) ifp
;
646 struct ppp_header
*h
;
649 int debug
= ifp
->if_flags
& IFF_DEBUG
;
653 if ((ifp
->if_flags
& IFF_UP
) == 0 ||
654 (ifp
->if_flags
& (IFF_RUNNING
| IFF_AUTO
)) == 0) {
660 if ((ifp
->if_flags
& (IFF_RUNNING
| IFF_AUTO
)) == IFF_AUTO
) {
662 * Interface is not yet running, but auto-dial. Need
663 * to start LCP for it.
665 ifp
->if_flags
|= IFF_RUNNING
;
673 if (dst
->sa_family
== AF_INET
) {
674 /* XXX Check mbuf length here? */
675 struct ip
*ip
= mtod (m
, struct ip
*);
676 struct tcphdr
*tcp
= (struct tcphdr
*) ((long*)ip
+ ip
->ip_hl
);
679 * When using dynamic local IP address assignment by using
680 * 0.0.0.0 as a local address, the first TCP session will
681 * not connect because the local TCP checksum is computed
682 * using 0.0.0.0 which will later become our real IP address
683 * so the TCP checksum computed at the remote end will
684 * become invalid. So we
685 * - don't let packets with src ip addr 0 thru
686 * - we flag TCP packets with src ip 0 as an error
689 if(ip
->ip_src
.s_addr
== INADDR_ANY
) /* -hm */
693 if(ip
->ip_p
== IPPROTO_TCP
)
694 return(EADDRNOTAVAIL
);
700 * Put low delay, telnet, rlogin and ftp control packets
701 * in front of the queue.
703 if (IF_QFULL (&sp
->pp_fastq
))
705 else if (ip
->ip_tos
& IPTOS_LOWDELAY
)
707 else if (m
->m_len
< sizeof *ip
+ sizeof *tcp
)
709 else if (ip
->ip_p
!= IPPROTO_TCP
)
711 else if (INTERACTIVE (ntohs (tcp
->th_sport
)))
713 else if (INTERACTIVE (ntohs (tcp
->th_dport
)))
719 * Prepend general data packet PPP header. For now, IP only.
721 M_PREPEND (m
, PPP_HEADER_LEN
, M_DONTWAIT
);
724 log(LOG_DEBUG
, SPP_FMT
"no memory for transmit header\n",
731 * May want to check size of packet
732 * (albeit due to the implementation it's always enough)
734 h
= mtod (m
, struct ppp_header
*);
735 if (sp
->pp_flags
& PP_CISCO
) {
736 h
->address
= CISCO_UNICAST
; /* unicast address */
739 h
->address
= PPP_ALLSTATIONS
; /* broadcast address */
740 h
->control
= PPP_UI
; /* Unnumbered Info */
743 switch (dst
->sa_family
) {
745 case AF_INET
: /* Internet Protocol */
746 if (sp
->pp_flags
& PP_CISCO
)
747 h
->protocol
= htons (ETHERTYPE_IP
);
750 * Don't choke with an ENETDOWN early. It's
751 * possible that we just started dialing out,
752 * so don't drop the packet immediately. If
753 * we notice that we run out of buffer space
754 * below, we will however remember that we are
755 * not ready to carry IP packets, and return
756 * ENETDOWN, as opposed to ENOBUFS.
758 h
->protocol
= htons(PPP_IP
);
759 if (sp
->state
[IDX_IPCP
] != STATE_OPENED
)
765 case AF_NS
: /* Xerox NS Protocol */
766 h
->protocol
= htons ((sp
->pp_flags
& PP_CISCO
) ?
767 ETHERTYPE_NS
: PPP_XNS
);
771 case AF_IPX
: /* Novell IPX Protocol */
772 h
->protocol
= htons ((sp
->pp_flags
& PP_CISCO
) ?
773 ETHERTYPE_IPX
: PPP_IPX
);
777 case AF_ISO
: /* ISO OSI Protocol */
778 if (sp
->pp_flags
& PP_CISCO
)
780 h
->protocol
= htons (PPP_ISO
);
788 return (EAFNOSUPPORT
);
792 * Queue message on interface, and start output if interface
795 if (IF_QFULL (ifq
)) {
796 IF_DROP (&ifp
->if_snd
);
800 return (rv
? rv
: ENOBUFS
);
803 if (! (ifp
->if_flags
& IFF_OACTIVE
))
804 (*ifp
->if_start
) (ifp
);
807 * Count output packets and bytes.
808 * The packet length includes header, FCS and 1 flag,
809 * according to RFC 1333.
811 ifp
->if_obytes
+= m
->m_pkthdr
.len
+ 3;
817 sppp_attach(struct ifnet
*ifp
)
819 struct sppp
*sp
= (struct sppp
*) ifp
;
821 /* Initialize keepalive handler. */
823 TIMEOUT(sppp_keepalive
, 0, hz
* 10, keepalive_ch
);
825 /* Insert new entry into the keepalive list. */
829 sp
->pp_if
.if_mtu
= PP_MTU
;
830 sp
->pp_if
.if_flags
= IFF_POINTOPOINT
| IFF_MULTICAST
;
831 sp
->pp_if
.if_type
= IFT_PPP
;
832 sp
->pp_if
.if_output
= sppp_output
;
834 sp
->pp_flags
= PP_KEEPALIVE
;
836 sp
->pp_fastq
.ifq_maxlen
= 32;
837 sp
->pp_cpq
.ifq_maxlen
= 20;
842 sp
->pp_phase
= PHASE_DEAD
;
844 sp
->pp_down
= lcp
.Down
;
853 sppp_detach(struct ifnet
*ifp
)
855 struct sppp
**q
, *p
, *sp
= (struct sppp
*) ifp
;
858 /* Remove the entry from the keepalive list. */
859 for (q
= &spppq
; (p
= *q
); q
= &p
->pp_next
)
865 /* Stop keepalive handler. */
867 UNTIMEOUT(sppp_keepalive
, 0, keepalive_ch
);
869 for (i
= 0; i
< IDX_COUNT
; i
++)
870 UNTIMEOUT((cps
[i
])->TO
, (void *)sp
, sp
->ch
[i
]);
871 UNTIMEOUT(sppp_pap_my_TO
, (void *)sp
, sp
->pap_my_to_ch
);
875 * Flush the interface output queue.
878 sppp_flush(struct ifnet
*ifp
)
880 struct sppp
*sp
= (struct sppp
*) ifp
;
882 sppp_qflush (&sp
->pp_if
.if_snd
);
883 sppp_qflush (&sp
->pp_fastq
);
884 sppp_qflush (&sp
->pp_cpq
);
888 * Check if the output queue is empty.
891 sppp_isempty(struct ifnet
*ifp
)
893 struct sppp
*sp
= (struct sppp
*) ifp
;
897 empty
= !sp
->pp_fastq
.ifq_head
&& !sp
->pp_cpq
.ifq_head
&&
898 !sp
->pp_if
.if_snd
.ifq_head
;
904 * Get next packet to send.
907 sppp_dequeue(struct ifnet
*ifp
)
909 struct sppp
*sp
= (struct sppp
*) ifp
;
915 * Process only the control protocol queue until we have at
916 * least one NCP open.
918 * Do always serve all three queues in Cisco mode.
920 IF_DEQUEUE(&sp
->pp_cpq
, m
);
922 (sppp_ncp_check(sp
) || (sp
->pp_flags
& PP_CISCO
) != 0)) {
923 IF_DEQUEUE(&sp
->pp_fastq
, m
);
925 IF_DEQUEUE (&sp
->pp_if
.if_snd
, m
);
932 * Pick the next packet, do not remove it from the queue.
935 sppp_pick(struct ifnet
*ifp
)
937 struct sppp
*sp
= (struct sppp
*)ifp
;
943 m
= sp
->pp_cpq
.ifq_head
;
945 (sp
->pp_phase
== PHASE_NETWORK
||
946 (sp
->pp_flags
& PP_CISCO
) != 0))
947 if ((m
= sp
->pp_fastq
.ifq_head
) == NULL
)
948 m
= sp
->pp_if
.if_snd
.ifq_head
;
954 * Process an ioctl request. Called on low priority level.
957 sppp_ioctl(struct ifnet
*ifp
, IOCTL_CMD_T cmd
, void *data
)
959 struct ifreq
*ifr
= (struct ifreq
*) data
;
960 struct sppp
*sp
= (struct sppp
*) ifp
;
961 int s
, rv
, going_up
, going_down
, newmode
;
972 /* fall through... */
975 going_up
= ifp
->if_flags
& IFF_UP
&&
976 (ifp
->if_flags
& IFF_RUNNING
) == 0;
977 going_down
= (ifp
->if_flags
& IFF_UP
) == 0 &&
978 ifp
->if_flags
& IFF_RUNNING
;
979 newmode
= ifp
->if_flags
& (IFF_AUTO
| IFF_PASSIVE
);
980 if (newmode
== (IFF_AUTO
| IFF_PASSIVE
)) {
982 newmode
= IFF_PASSIVE
;
983 ifp
->if_flags
&= ~IFF_AUTO
;
986 if (going_up
|| going_down
)
988 if (going_up
&& newmode
== 0) {
989 /* neither auto-dial nor passive */
990 ifp
->if_flags
|= IFF_RUNNING
;
991 if (!(sp
->pp_flags
& PP_CISCO
))
993 } else if (going_down
) {
995 ifp
->if_flags
&= ~IFF_RUNNING
;
1002 #define ifr_mtu ifr_metric
1005 if (ifr
->ifr_mtu
< 128 || ifr
->ifr_mtu
> sp
->lcp
.their_mru
)
1007 ifp
->if_mtu
= ifr
->ifr_mtu
;
1012 if (*(short*)data
< 128 || *(short*)data
> sp
->lcp
.their_mru
)
1014 ifp
->if_mtu
= *(short*)data
;
1019 ifr
->ifr_mtu
= ifp
->if_mtu
;
1024 *(short*)data
= ifp
->if_mtu
;
1031 case SIOCGIFGENERIC
:
1032 case SIOCSIFGENERIC
:
1033 rv
= sppp_params(sp
, cmd
, data
);
1045 * Cisco framing implementation.
1049 * Handle incoming Cisco keepalive protocol packets.
1052 sppp_cisco_input(struct sppp
*sp
, struct mbuf
*m
)
1055 struct cisco_packet
*h
;
1058 if (m
->m_pkthdr
.len
< CISCO_PACKET_LEN
) {
1061 SPP_FMT
"cisco invalid packet length: %d bytes\n",
1062 SPP_ARGS(ifp
), m
->m_pkthdr
.len
);
1065 h
= mtod (m
, struct cisco_packet
*);
1068 SPP_FMT
"cisco input: %d bytes "
1069 "<0x%lx 0x%lx 0x%lx 0x%x 0x%x-0x%x>\n",
1070 SPP_ARGS(ifp
), m
->m_pkthdr
.len
,
1071 (u_long
)ntohl (h
->type
), (u_long
)h
->par1
, (u_long
)h
->par2
, (u_int
)h
->rel
,
1072 (u_int
)h
->time0
, (u_int
)h
->time1
);
1073 switch (ntohl (h
->type
)) {
1076 addlog(SPP_FMT
"cisco unknown packet type: 0x%lx\n",
1077 SPP_ARGS(ifp
), (u_long
)ntohl (h
->type
));
1079 case CISCO_ADDR_REPLY
:
1080 /* Reply on address request, ignore */
1082 case CISCO_KEEPALIVE_REQ
:
1083 sp
->pp_alivecnt
= 0;
1084 sp
->pp_rseq
= ntohl (h
->par1
);
1085 if (sp
->pp_seq
== sp
->pp_rseq
) {
1086 /* Local and remote sequence numbers are equal.
1087 * Probably, the line is in loopback mode. */
1088 if (sp
->pp_loopcnt
>= MAXALIVECNT
) {
1089 printf (SPP_FMT
"loopback\n",
1092 if (ifp
->if_flags
& IFF_UP
) {
1094 sppp_qflush (&sp
->pp_cpq
);
1099 /* Generate new local sequence number */
1100 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
1101 sp
->pp_seq
= random();
1103 sp
->pp_seq
^= time
.tv_sec
^ time
.tv_usec
;
1108 if (! (ifp
->if_flags
& IFF_UP
) &&
1109 (ifp
->if_flags
& IFF_RUNNING
)) {
1111 printf (SPP_FMT
"up\n", SPP_ARGS(ifp
));
1114 case CISCO_ADDR_REQ
:
1115 sppp_get_ip_addrs(sp
, &me
, 0, &mymask
);
1117 sppp_cisco_send(sp
, CISCO_ADDR_REPLY
, me
, mymask
);
1123 * Send Cisco keepalive packet.
1126 sppp_cisco_send(struct sppp
*sp
, int type
, long par1
, long par2
)
1129 struct ppp_header
*h
;
1130 struct cisco_packet
*ch
;
1132 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
1135 u_long t
= (time
.tv_sec
- boottime
.tv_sec
) * 1000;
1138 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
1139 getmicrouptime(&tv
);
1142 MGETHDR (m
, M_DONTWAIT
, MT_DATA
);
1145 m
->m_pkthdr
.len
= m
->m_len
= PPP_HEADER_LEN
+ CISCO_PACKET_LEN
;
1146 m
->m_pkthdr
.rcvif
= 0;
1148 h
= mtod (m
, struct ppp_header
*);
1149 h
->address
= CISCO_MULTICAST
;
1151 h
->protocol
= htons (CISCO_KEEPALIVE
);
1153 ch
= (struct cisco_packet
*) (h
+ 1);
1154 ch
->type
= htonl (type
);
1155 ch
->par1
= htonl (par1
);
1156 ch
->par2
= htonl (par2
);
1159 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
1160 ch
->time0
= htons ((u_short
) (tv
.tv_sec
>> 16));
1161 ch
->time1
= htons ((u_short
) tv
.tv_sec
);
1163 ch
->time0
= htons ((u_short
) (t
>> 16));
1164 ch
->time1
= htons ((u_short
) t
);
1169 SPP_FMT
"cisco output: <0x%lx 0x%lx 0x%lx 0x%x 0x%x-0x%x>\n",
1170 SPP_ARGS(ifp
), (u_long
)ntohl (ch
->type
), (u_long
)ch
->par1
,
1171 (u_long
)ch
->par2
, (u_int
)ch
->rel
, (u_int
)ch
->time0
, (u_int
)ch
->time1
);
1173 if (IF_QFULL (&sp
->pp_cpq
)) {
1174 IF_DROP (&sp
->pp_fastq
);
1175 IF_DROP (&ifp
->if_snd
);
1178 IF_ENQUEUE (&sp
->pp_cpq
, m
);
1179 if (! (ifp
->if_flags
& IFF_OACTIVE
))
1180 (*ifp
->if_start
) (ifp
);
1181 ifp
->if_obytes
+= m
->m_pkthdr
.len
+ 3;
1185 * PPP protocol implementation.
1189 * Send PPP control protocol packet.
1192 sppp_cp_send(struct sppp
*sp
, u_short proto
, u_char type
,
1193 u_char ident
, u_short len
, void *data
)
1196 struct ppp_header
*h
;
1197 struct lcp_header
*lh
;
1200 if (len
> MHLEN
- PPP_HEADER_LEN
- LCP_HEADER_LEN
)
1201 len
= MHLEN
- PPP_HEADER_LEN
- LCP_HEADER_LEN
;
1202 MGETHDR (m
, M_DONTWAIT
, MT_DATA
);
1205 m
->m_pkthdr
.len
= m
->m_len
= PPP_HEADER_LEN
+ LCP_HEADER_LEN
+ len
;
1206 m
->m_pkthdr
.rcvif
= 0;
1208 h
= mtod (m
, struct ppp_header
*);
1209 h
->address
= PPP_ALLSTATIONS
; /* broadcast address */
1210 h
->control
= PPP_UI
; /* Unnumbered Info */
1211 h
->protocol
= htons (proto
); /* Link Control Protocol */
1213 lh
= (struct lcp_header
*) (h
+ 1);
1216 lh
->len
= htons (LCP_HEADER_LEN
+ len
);
1218 bcopy (data
, lh
+1, len
);
1221 log(LOG_DEBUG
, SPP_FMT
"%s output <%s id=0x%x len=%d",
1223 sppp_proto_name(proto
),
1224 sppp_cp_type_name (lh
->type
), lh
->ident
,
1227 sppp_print_bytes ((u_char
*) (lh
+1), len
);
1230 if (IF_QFULL (&sp
->pp_cpq
)) {
1231 IF_DROP (&sp
->pp_fastq
);
1232 IF_DROP (&ifp
->if_snd
);
1236 IF_ENQUEUE (&sp
->pp_cpq
, m
);
1237 if (! (ifp
->if_flags
& IFF_OACTIVE
))
1238 (*ifp
->if_start
) (ifp
);
1239 ifp
->if_obytes
+= m
->m_pkthdr
.len
+ 3;
1243 * Handle incoming PPP control protocol packets.
1246 sppp_cp_input(const struct cp
*cp
, struct sppp
*sp
, struct mbuf
*m
)
1249 struct lcp_header
*h
;
1250 int len
= m
->m_pkthdr
.len
;
1257 SPP_FMT
"%s invalid packet length: %d bytes\n",
1258 SPP_ARGS(ifp
), cp
->name
, len
);
1261 h
= mtod (m
, struct lcp_header
*);
1264 SPP_FMT
"%s input(%s): <%s id=0x%x len=%d",
1265 SPP_ARGS(ifp
), cp
->name
,
1266 sppp_state_name(sp
->state
[cp
->protoidx
]),
1267 sppp_cp_type_name (h
->type
), h
->ident
, ntohs (h
->len
));
1269 sppp_print_bytes ((u_char
*) (h
+1), len
-4);
1272 if (len
> ntohs (h
->len
))
1273 len
= ntohs (h
->len
);
1274 p
= (u_char
*)(h
+ 1);
1279 addlog(SPP_FMT
"%s invalid conf-req length %d\n",
1280 SPP_ARGS(ifp
), cp
->name
,
1285 /* handle states where RCR doesn't get a SCA/SCN */
1286 switch (sp
->state
[cp
->protoidx
]) {
1288 case STATE_STOPPING
:
1291 sppp_cp_send(sp
, cp
->proto
, TERM_ACK
, h
->ident
,
1295 rv
= (cp
->RCR
)(sp
, h
, len
);
1296 switch (sp
->state
[cp
->protoidx
]) {
1300 /* fall through... */
1301 case STATE_ACK_SENT
:
1302 case STATE_REQ_SENT
:
1303 sppp_cp_change_state(cp
, sp
, rv
?
1304 STATE_ACK_SENT
: STATE_REQ_SENT
);
1307 sp
->rst_counter
[cp
->protoidx
] = sp
->lcp
.max_configure
;
1309 sppp_cp_change_state(cp
, sp
, rv
?
1310 STATE_ACK_SENT
: STATE_REQ_SENT
);
1312 case STATE_ACK_RCVD
:
1314 sppp_cp_change_state(cp
, sp
, STATE_OPENED
);
1316 log(LOG_DEBUG
, SPP_FMT
"%s tlu\n",
1321 sppp_cp_change_state(cp
, sp
, STATE_ACK_RCVD
);
1324 printf(SPP_FMT
"%s illegal %s in state %s\n",
1325 SPP_ARGS(ifp
), cp
->name
,
1326 sppp_cp_type_name(h
->type
),
1327 sppp_state_name(sp
->state
[cp
->protoidx
]));
1332 if (h
->ident
!= sp
->confid
[cp
->protoidx
]) {
1334 addlog(SPP_FMT
"%s id mismatch 0x%x != 0x%x\n",
1335 SPP_ARGS(ifp
), cp
->name
,
1336 h
->ident
, sp
->confid
[cp
->protoidx
]);
1340 switch (sp
->state
[cp
->protoidx
]) {
1343 sppp_cp_send(sp
, cp
->proto
, TERM_ACK
, h
->ident
, 0, 0);
1346 case STATE_STOPPING
:
1348 case STATE_REQ_SENT
:
1349 sp
->rst_counter
[cp
->protoidx
] = sp
->lcp
.max_configure
;
1350 sppp_cp_change_state(cp
, sp
, STATE_ACK_RCVD
);
1355 case STATE_ACK_RCVD
:
1357 sppp_cp_change_state(cp
, sp
, STATE_REQ_SENT
);
1359 case STATE_ACK_SENT
:
1360 sp
->rst_counter
[cp
->protoidx
] = sp
->lcp
.max_configure
;
1361 sppp_cp_change_state(cp
, sp
, STATE_OPENED
);
1363 log(LOG_DEBUG
, SPP_FMT
"%s tlu\n",
1364 SPP_ARGS(ifp
), cp
->name
);
1368 printf(SPP_FMT
"%s illegal %s in state %s\n",
1369 SPP_ARGS(ifp
), cp
->name
,
1370 sppp_cp_type_name(h
->type
),
1371 sppp_state_name(sp
->state
[cp
->protoidx
]));
1377 if (h
->ident
!= sp
->confid
[cp
->protoidx
]) {
1379 addlog(SPP_FMT
"%s id mismatch 0x%x != 0x%x\n",
1380 SPP_ARGS(ifp
), cp
->name
,
1381 h
->ident
, sp
->confid
[cp
->protoidx
]);
1385 if (h
->type
== CONF_NAK
)
1386 (cp
->RCN_nak
)(sp
, h
, len
);
1388 (cp
->RCN_rej
)(sp
, h
, len
);
1390 switch (sp
->state
[cp
->protoidx
]) {
1393 sppp_cp_send(sp
, cp
->proto
, TERM_ACK
, h
->ident
, 0, 0);
1395 case STATE_REQ_SENT
:
1396 case STATE_ACK_SENT
:
1397 sp
->rst_counter
[cp
->protoidx
] = sp
->lcp
.max_configure
;
1403 case STATE_ACK_RCVD
:
1404 sppp_cp_change_state(cp
, sp
, STATE_ACK_SENT
);
1408 case STATE_STOPPING
:
1411 printf(SPP_FMT
"%s illegal %s in state %s\n",
1412 SPP_ARGS(ifp
), cp
->name
,
1413 sppp_cp_type_name(h
->type
),
1414 sppp_state_name(sp
->state
[cp
->protoidx
]));
1420 switch (sp
->state
[cp
->protoidx
]) {
1421 case STATE_ACK_RCVD
:
1422 case STATE_ACK_SENT
:
1423 sppp_cp_change_state(cp
, sp
, STATE_REQ_SENT
);
1428 case STATE_STOPPING
:
1429 case STATE_REQ_SENT
:
1431 /* Send Terminate-Ack packet. */
1433 log(LOG_DEBUG
, SPP_FMT
"%s send terminate-ack\n",
1434 SPP_ARGS(ifp
), cp
->name
);
1435 sppp_cp_send(sp
, cp
->proto
, TERM_ACK
, h
->ident
, 0, 0);
1439 sp
->rst_counter
[cp
->protoidx
] = 0;
1440 sppp_cp_change_state(cp
, sp
, STATE_STOPPING
);
1444 printf(SPP_FMT
"%s illegal %s in state %s\n",
1445 SPP_ARGS(ifp
), cp
->name
,
1446 sppp_cp_type_name(h
->type
),
1447 sppp_state_name(sp
->state
[cp
->protoidx
]));
1452 switch (sp
->state
[cp
->protoidx
]) {
1455 case STATE_REQ_SENT
:
1456 case STATE_ACK_SENT
:
1459 sppp_cp_change_state(cp
, sp
, STATE_CLOSED
);
1462 case STATE_STOPPING
:
1463 sppp_cp_change_state(cp
, sp
, STATE_STOPPED
);
1466 case STATE_ACK_RCVD
:
1467 sppp_cp_change_state(cp
, sp
, STATE_REQ_SENT
);
1472 sppp_cp_change_state(cp
, sp
, STATE_ACK_RCVD
);
1475 printf(SPP_FMT
"%s illegal %s in state %s\n",
1476 SPP_ARGS(ifp
), cp
->name
,
1477 sppp_cp_type_name(h
->type
),
1478 sppp_state_name(sp
->state
[cp
->protoidx
]));
1484 /* XXX catastrophic rejects (RXJ-) aren't handled yet. */
1486 SPP_FMT
"%s: ignoring RXJ (%s) for proto 0x%x, "
1487 "danger will robinson\n",
1488 SPP_ARGS(ifp
), cp
->name
,
1489 sppp_cp_type_name(h
->type
), ntohs(*((u_short
*)p
)));
1490 switch (sp
->state
[cp
->protoidx
]) {
1493 case STATE_REQ_SENT
:
1494 case STATE_ACK_SENT
:
1496 case STATE_STOPPING
:
1499 case STATE_ACK_RCVD
:
1500 sppp_cp_change_state(cp
, sp
, STATE_REQ_SENT
);
1503 printf(SPP_FMT
"%s illegal %s in state %s\n",
1504 SPP_ARGS(ifp
), cp
->name
,
1505 sppp_cp_type_name(h
->type
),
1506 sppp_state_name(sp
->state
[cp
->protoidx
]));
1511 if (cp
->proto
!= PPP_LCP
)
1513 /* Discard the packet. */
1516 if (cp
->proto
!= PPP_LCP
)
1518 if (sp
->state
[cp
->protoidx
] != STATE_OPENED
) {
1520 addlog(SPP_FMT
"lcp echo req but lcp closed\n",
1527 addlog(SPP_FMT
"invalid lcp echo request "
1528 "packet length: %d bytes\n",
1529 SPP_ARGS(ifp
), len
);
1532 if (ntohl (*(long*)(h
+1)) == sp
->lcp
.magic
) {
1533 /* Line loopback mode detected. */
1534 printf(SPP_FMT
"loopback\n", SPP_ARGS(ifp
));
1536 sppp_qflush (&sp
->pp_cpq
);
1538 /* Shut down the PPP link. */
1544 *(long*)(h
+1) = htonl (sp
->lcp
.magic
);
1546 addlog(SPP_FMT
"got lcp echo req, sending echo rep\n",
1548 sppp_cp_send (sp
, PPP_LCP
, ECHO_REPLY
, h
->ident
, len
-4, h
+1);
1551 if (cp
->proto
!= PPP_LCP
)
1553 if (h
->ident
!= sp
->lcp
.echoid
) {
1559 addlog(SPP_FMT
"lcp invalid echo reply "
1560 "packet length: %d bytes\n",
1561 SPP_ARGS(ifp
), len
);
1565 addlog(SPP_FMT
"lcp got echo rep\n",
1567 if (ntohl (*(long*)(h
+1)) != sp
->lcp
.magic
)
1568 sp
->pp_alivecnt
= 0;
1571 /* Unknown packet type -- send Code-Reject packet. */
1574 addlog(SPP_FMT
"%s send code-rej for 0x%x\n",
1575 SPP_ARGS(ifp
), cp
->name
, h
->type
);
1576 sppp_cp_send(sp
, cp
->proto
, CODE_REJ
, ++sp
->pp_seq
,
1577 m
->m_pkthdr
.len
, h
);
1584 * The generic part of all Up/Down/Open/Close/TO event handlers.
1585 * Basically, the state transition handling in the automaton.
1588 sppp_up_event(const struct cp
*cp
, struct sppp
*sp
)
1593 log(LOG_DEBUG
, SPP_FMT
"%s up(%s)\n",
1594 SPP_ARGS(ifp
), cp
->name
,
1595 sppp_state_name(sp
->state
[cp
->protoidx
]));
1597 switch (sp
->state
[cp
->protoidx
]) {
1599 sppp_cp_change_state(cp
, sp
, STATE_CLOSED
);
1601 case STATE_STARTING
:
1602 sp
->rst_counter
[cp
->protoidx
] = sp
->lcp
.max_configure
;
1604 sppp_cp_change_state(cp
, sp
, STATE_REQ_SENT
);
1607 printf(SPP_FMT
"%s illegal up in state %s\n",
1608 SPP_ARGS(ifp
), cp
->name
,
1609 sppp_state_name(sp
->state
[cp
->protoidx
]));
1614 sppp_down_event(const struct cp
*cp
, struct sppp
*sp
)
1619 log(LOG_DEBUG
, SPP_FMT
"%s down(%s)\n",
1620 SPP_ARGS(ifp
), cp
->name
,
1621 sppp_state_name(sp
->state
[cp
->protoidx
]));
1623 switch (sp
->state
[cp
->protoidx
]) {
1626 sppp_cp_change_state(cp
, sp
, STATE_INITIAL
);
1629 sppp_cp_change_state(cp
, sp
, STATE_STARTING
);
1632 case STATE_STOPPING
:
1633 case STATE_REQ_SENT
:
1634 case STATE_ACK_RCVD
:
1635 case STATE_ACK_SENT
:
1636 sppp_cp_change_state(cp
, sp
, STATE_STARTING
);
1640 sppp_cp_change_state(cp
, sp
, STATE_STARTING
);
1643 printf(SPP_FMT
"%s illegal down in state %s\n",
1644 SPP_ARGS(ifp
), cp
->name
,
1645 sppp_state_name(sp
->state
[cp
->protoidx
]));
1651 sppp_open_event(const struct cp
*cp
, struct sppp
*sp
)
1656 log(LOG_DEBUG
, SPP_FMT
"%s open(%s)\n",
1657 SPP_ARGS(ifp
), cp
->name
,
1658 sppp_state_name(sp
->state
[cp
->protoidx
]));
1660 switch (sp
->state
[cp
->protoidx
]) {
1662 sppp_cp_change_state(cp
, sp
, STATE_STARTING
);
1665 case STATE_STARTING
:
1668 sp
->rst_counter
[cp
->protoidx
] = sp
->lcp
.max_configure
;
1670 sppp_cp_change_state(cp
, sp
, STATE_REQ_SENT
);
1673 case STATE_STOPPING
:
1674 case STATE_REQ_SENT
:
1675 case STATE_ACK_RCVD
:
1676 case STATE_ACK_SENT
:
1680 sppp_cp_change_state(cp
, sp
, STATE_STOPPING
);
1687 sppp_close_event(const struct cp
*cp
, struct sppp
*sp
)
1692 log(LOG_DEBUG
, SPP_FMT
"%s close(%s)\n",
1693 SPP_ARGS(ifp
), cp
->name
,
1694 sppp_state_name(sp
->state
[cp
->protoidx
]));
1696 switch (sp
->state
[cp
->protoidx
]) {
1701 case STATE_STARTING
:
1702 sppp_cp_change_state(cp
, sp
, STATE_INITIAL
);
1706 sppp_cp_change_state(cp
, sp
, STATE_CLOSED
);
1708 case STATE_STOPPING
:
1709 sppp_cp_change_state(cp
, sp
, STATE_CLOSING
);
1714 case STATE_REQ_SENT
:
1715 case STATE_ACK_RCVD
:
1716 case STATE_ACK_SENT
:
1717 sp
->rst_counter
[cp
->protoidx
] = sp
->lcp
.max_terminate
;
1718 sppp_cp_send(sp
, cp
->proto
, TERM_REQ
, ++sp
->pp_seq
, 0, 0);
1719 sppp_cp_change_state(cp
, sp
, STATE_CLOSING
);
1725 sppp_to_event(const struct cp
*cp
, struct sppp
*sp
)
1732 log(LOG_DEBUG
, SPP_FMT
"%s TO(%s) rst_counter = %d\n",
1733 SPP_ARGS(ifp
), cp
->name
,
1734 sppp_state_name(sp
->state
[cp
->protoidx
]),
1735 sp
->rst_counter
[cp
->protoidx
]);
1737 if (--sp
->rst_counter
[cp
->protoidx
] < 0)
1739 switch (sp
->state
[cp
->protoidx
]) {
1741 sppp_cp_change_state(cp
, sp
, STATE_CLOSED
);
1744 case STATE_STOPPING
:
1745 sppp_cp_change_state(cp
, sp
, STATE_STOPPED
);
1748 case STATE_REQ_SENT
:
1749 case STATE_ACK_RCVD
:
1750 case STATE_ACK_SENT
:
1751 sppp_cp_change_state(cp
, sp
, STATE_STOPPED
);
1757 switch (sp
->state
[cp
->protoidx
]) {
1759 case STATE_STOPPING
:
1760 sppp_cp_send(sp
, cp
->proto
, TERM_REQ
, ++sp
->pp_seq
,
1762 TIMEOUT(cp
->TO
, (void *)sp
, sp
->lcp
.timeout
,
1763 sp
->ch
[cp
->protoidx
]);
1765 case STATE_REQ_SENT
:
1766 case STATE_ACK_RCVD
:
1768 /* sppp_cp_change_state() will restart the timer */
1769 sppp_cp_change_state(cp
, sp
, STATE_REQ_SENT
);
1771 case STATE_ACK_SENT
:
1773 TIMEOUT(cp
->TO
, (void *)sp
, sp
->lcp
.timeout
,
1774 sp
->ch
[cp
->protoidx
]);
1782 * Change the state of a control protocol in the state automaton.
1783 * Takes care of starting/stopping the restart timer.
1786 sppp_cp_change_state(const struct cp
*cp
, struct sppp
*sp
, int newstate
)
1788 sp
->state
[cp
->protoidx
] = newstate
;
1790 UNTIMEOUT(cp
->TO
, (void *)sp
, sp
->ch
[cp
->protoidx
]);
1793 case STATE_STARTING
:
1799 case STATE_STOPPING
:
1800 case STATE_REQ_SENT
:
1801 case STATE_ACK_RCVD
:
1802 case STATE_ACK_SENT
:
1803 TIMEOUT(cp
->TO
, (void *)sp
, sp
->lcp
.timeout
,
1804 sp
->ch
[cp
->protoidx
]);
1809 *--------------------------------------------------------------------------*
1811 * The LCP implementation. *
1813 *--------------------------------------------------------------------------*
1816 sppp_lcp_init(struct sppp
*sp
)
1818 sp
->lcp
.opts
= (1 << LCP_OPT_MAGIC
);
1820 sp
->state
[IDX_LCP
] = STATE_INITIAL
;
1821 sp
->fail_counter
[IDX_LCP
] = 0;
1823 sp
->lcp
.mru
= sp
->lcp
.their_mru
= PP_MTU
;
1826 * Initialize counters and timeout values. Note that we don't
1827 * use the 3 seconds suggested in RFC 1661 since we are likely
1828 * running on a fast link. XXX We should probably implement
1829 * the exponential backoff option. Note that these values are
1830 * relevant for all control protocols, not just LCP only.
1832 sp
->lcp
.timeout
= 1 * hz
;
1833 sp
->lcp
.max_terminate
= 2;
1834 sp
->lcp
.max_configure
= 10;
1835 sp
->lcp
.max_failure
= 10;
1836 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
1837 callout_handle_init(&sp
->ch
[IDX_LCP
]);
1842 sppp_lcp_up(struct sppp
*sp
)
1847 * If this interface is passive or dial-on-demand, and we are
1848 * still in Initial state, it means we've got an incoming
1849 * call. Activate the interface.
1851 if ((ifp
->if_flags
& (IFF_AUTO
| IFF_PASSIVE
)) != 0) {
1854 SPP_FMT
"Up event", SPP_ARGS(ifp
));
1855 ifp
->if_flags
|= IFF_RUNNING
;
1856 if (sp
->state
[IDX_LCP
] == STATE_INITIAL
) {
1858 addlog("(incoming call)\n");
1859 sp
->pp_flags
|= PP_CALLIN
;
1865 sppp_up_event(&lcp
, sp
);
1869 sppp_lcp_down(struct sppp
*sp
)
1873 sppp_down_event(&lcp
, sp
);
1876 * If this is neither a dial-on-demand nor a passive
1877 * interface, simulate an ``ifconfig down'' action, so the
1878 * administrator can force a redial by another ``ifconfig
1879 * up''. XXX For leased line operation, should we immediately
1880 * try to reopen the connection here?
1882 if ((ifp
->if_flags
& (IFF_AUTO
| IFF_PASSIVE
)) == 0) {
1884 SPP_FMT
"Down event, taking interface down.\n",
1890 SPP_FMT
"Down event (carrier loss)\n",
1893 sp
->pp_flags
&= ~PP_CALLIN
;
1894 if (sp
->state
[IDX_LCP
] != STATE_INITIAL
)
1896 ifp
->if_flags
&= ~IFF_RUNNING
;
1900 sppp_lcp_open(struct sppp
*sp
)
1903 * If we are authenticator, negotiate LCP_AUTH
1905 if (sp
->hisauth
.proto
!= 0)
1906 sp
->lcp
.opts
|= (1 << LCP_OPT_AUTH_PROTO
);
1908 sp
->lcp
.opts
&= ~(1 << LCP_OPT_AUTH_PROTO
);
1909 sp
->pp_flags
&= ~PP_NEEDAUTH
;
1910 sppp_open_event(&lcp
, sp
);
1914 sppp_lcp_close(struct sppp
*sp
)
1916 sppp_close_event(&lcp
, sp
);
1920 sppp_lcp_TO(void *cookie
)
1922 sppp_to_event(&lcp
, (struct sppp
*)cookie
);
1926 * Analyze a configure request. Return true if it was agreeable, and
1927 * caused action sca, false if it has been rejected or nak'ed, and
1928 * caused action scn. (The return value is used to make the state
1929 * transition decision in the state automaton.)
1932 sppp_lcp_RCR(struct sppp
*sp
, struct lcp_header
*h
, int len
)
1935 u_char
*buf
, *r
, *p
;
1942 buf
= r
= _MALLOC(len
, M_TEMP
, M_NOWAIT
);
1947 log(LOG_DEBUG
, SPP_FMT
"lcp parse opts: ",
1950 /* pass 1: check for things that need to be rejected */
1952 for (rlen
=0; len
>1 && p
[1]; len
-=p
[1], p
+=p
[1]) {
1954 addlog(" %s ", sppp_lcp_opt_name(*p
));
1958 /* fall through, both are same length */
1959 case LCP_OPT_ASYNC_MAP
:
1960 /* Async control character map. */
1961 if (len
>= 6 || p
[1] == 6)
1964 addlog("[invalid] ");
1967 /* Maximum receive unit. */
1968 if (len
>= 4 && p
[1] == 4)
1971 addlog("[invalid] ");
1973 case LCP_OPT_AUTH_PROTO
:
1976 addlog("[invalid] ");
1979 authproto
= (p
[2] << 8) + p
[3];
1980 if (authproto
== PPP_CHAP
&& p
[1] != 5) {
1982 addlog("[invalid chap len] ");
1985 if (sp
->myauth
.proto
== 0) {
1986 /* we are not configured to do auth */
1988 addlog("[not configured] ");
1992 * Remote want us to authenticate, remember this,
1993 * so we stay in PHASE_AUTHENTICATE after LCP got
1996 sp
->pp_flags
|= PP_NEEDAUTH
;
1999 /* Others not supported. */
2004 /* Add the option to rejected list. */
2011 addlog(" send conf-rej\n");
2012 sppp_cp_send (sp
, PPP_LCP
, CONF_REJ
, h
->ident
, rlen
, buf
);
2018 * pass 2: check for option values that are unacceptable and
2019 * thus require to be nak'ed.
2022 log(LOG_DEBUG
, SPP_FMT
"lcp parse opt values: ",
2027 for (rlen
=0; len
>1 && p
[1]; len
-=p
[1], p
+=p
[1]) {
2029 addlog(" %s ", sppp_lcp_opt_name(*p
));
2032 /* Magic number -- extract. */
2033 nmagic
= (u_long
)p
[2] << 24 |
2034 (u_long
)p
[3] << 16 | p
[4] << 8 | p
[5];
2035 if (nmagic
!= sp
->lcp
.magic
) {
2037 addlog("0x%lx ", nmagic
);
2041 * Local and remote magics equal -- loopback?
2043 if (sp
->pp_loopcnt
>= MAXALIVECNT
*5) {
2044 printf (SPP_FMT
"loopback\n",
2047 if (ifp
->if_flags
& IFF_UP
) {
2049 sppp_qflush(&sp
->pp_cpq
);
2055 addlog("[glitch] ");
2058 * We negate our magic here, and NAK it. If
2059 * we see it later in an NAK packet, we
2060 * suggest a new one.
2062 nmagic
= ~sp
->lcp
.magic
;
2064 p
[2] = nmagic
>> 24;
2065 p
[3] = nmagic
>> 16;
2070 case LCP_OPT_ASYNC_MAP
:
2071 /* Async control character map -- check to be zero. */
2072 if (! p
[2] && ! p
[3] && ! p
[4] && ! p
[5]) {
2078 addlog("[non-empty] ");
2079 /* suggest a zero one */
2080 p
[2] = p
[3] = p
[4] = p
[5] = 0;
2085 * Maximum receive unit. Always agreeable,
2086 * but ignored by now.
2088 sp
->lcp
.their_mru
= p
[2] * 256 + p
[3];
2090 addlog("%lu ", sp
->lcp
.their_mru
);
2093 case LCP_OPT_AUTH_PROTO
:
2094 authproto
= (p
[2] << 8) + p
[3];
2095 if (sp
->myauth
.proto
!= authproto
) {
2096 /* not agreed, nak */
2098 addlog("[mine %s != his %s] ",
2099 sppp_proto_name(sp
->hisauth
.proto
),
2100 sppp_proto_name(authproto
));
2101 p
[2] = sp
->myauth
.proto
>> 8;
2102 p
[3] = sp
->myauth
.proto
;
2105 if (authproto
== PPP_CHAP
&& p
[4] != CHAP_MD5
) {
2107 addlog("[chap not MD5] ");
2113 /* Add the option to nak'ed list. */
2119 if (++sp
->fail_counter
[IDX_LCP
] >= sp
->lcp
.max_failure
) {
2121 addlog(" max_failure (%d) exceeded, "
2123 sp
->lcp
.max_failure
);
2124 sppp_cp_send(sp
, PPP_LCP
, CONF_REJ
, h
->ident
, rlen
, buf
);
2127 addlog(" send conf-nak\n");
2128 sppp_cp_send (sp
, PPP_LCP
, CONF_NAK
, h
->ident
, rlen
, buf
);
2133 addlog(" send conf-ack\n");
2134 sp
->fail_counter
[IDX_LCP
] = 0;
2136 sppp_cp_send (sp
, PPP_LCP
, CONF_ACK
,
2137 h
->ident
, origlen
, h
+1);
2145 * Analyze the LCP Configure-Reject option list, and adjust our
2149 sppp_lcp_RCN_rej(struct sppp
*sp
, struct lcp_header
*h
, int len
)
2155 buf
= MALLOC (len
, M_TEMP
, M_NOWAIT
);
2160 log(LOG_DEBUG
, SPP_FMT
"lcp rej opts: ",
2164 for (; len
> 1 && p
[1]; len
-= p
[1], p
+= p
[1]) {
2166 addlog(" %s ", sppp_lcp_opt_name(*p
));
2169 /* Magic number -- can't use it, use 0 */
2170 sp
->lcp
.opts
&= ~(1 << LCP_OPT_MAGIC
);
2175 * Should not be rejected anyway, since we only
2176 * negotiate a MRU if explicitly requested by
2179 sp
->lcp
.opts
&= ~(1 << LCP_OPT_MRU
);
2181 case LCP_OPT_AUTH_PROTO
:
2183 * Peer doesn't want to authenticate himself,
2184 * deny unless this is a dialout call, and
2185 * AUTHFLAG_NOCALLOUT is set.
2187 if ((sp
->pp_flags
& PP_CALLIN
) == 0 &&
2188 (sp
->hisauth
.flags
& AUTHFLAG_NOCALLOUT
) != 0) {
2190 addlog("[don't insist on auth "
2192 sp
->lcp
.opts
&= ~(1 << LCP_OPT_AUTH_PROTO
);
2196 addlog("[access denied]\n");
2208 * Analyze the LCP Configure-NAK option list, and adjust our
2212 sppp_lcp_RCN_nak(struct sppp
*sp
, struct lcp_header
*h
, int len
)
2219 buf
= MALLOC (len
, M_TEMP
, M_NOWAIT
);
2224 log(LOG_DEBUG
, SPP_FMT
"lcp nak opts: ",
2228 for (; len
> 1 && p
[1]; len
-= p
[1], p
+= p
[1]) {
2230 addlog(" %s ", sppp_lcp_opt_name(*p
));
2233 /* Magic number -- renegotiate */
2234 if ((sp
->lcp
.opts
& (1 << LCP_OPT_MAGIC
)) &&
2235 len
>= 6 && p
[1] == 6) {
2236 magic
= (u_long
)p
[2] << 24 |
2237 (u_long
)p
[3] << 16 | p
[4] << 8 | p
[5];
2239 * If the remote magic is our negated one,
2240 * this looks like a loopback problem.
2241 * Suggest a new magic to make sure.
2243 if (magic
== ~sp
->lcp
.magic
) {
2245 addlog("magic glitch ");
2246 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
2247 sp
->lcp
.magic
= random();
2249 sp
->lcp
.magic
= time
.tv_sec
+ time
.tv_usec
;
2252 sp
->lcp
.magic
= magic
;
2254 addlog("%lu ", magic
);
2260 * Peer wants to advise us to negotiate an MRU.
2261 * Agree on it if it's reasonable, or use
2262 * default otherwise.
2264 if (len
>= 4 && p
[1] == 4) {
2265 u_int mru
= p
[2] * 256 + p
[3];
2268 if (mru
< PP_MTU
|| mru
> PP_MAX_MRU
)
2271 sp
->lcp
.opts
|= (1 << LCP_OPT_MRU
);
2274 case LCP_OPT_AUTH_PROTO
:
2276 * Peer doesn't like our authentication method,
2280 addlog("[access denied]\n");
2292 sppp_lcp_tlu(struct sppp
*sp
)
2299 if (! (ifp
->if_flags
& IFF_UP
) &&
2300 (ifp
->if_flags
& IFF_RUNNING
)) {
2301 /* Coming out of loopback mode. */
2303 printf (SPP_FMT
"up\n", SPP_ARGS(ifp
));
2306 for (i
= 0; i
< IDX_COUNT
; i
++)
2307 if ((cps
[i
])->flags
& CP_QUAL
)
2310 if ((sp
->lcp
.opts
& (1 << LCP_OPT_AUTH_PROTO
)) != 0 ||
2311 (sp
->pp_flags
& PP_NEEDAUTH
) != 0)
2312 sp
->pp_phase
= PHASE_AUTHENTICATE
;
2314 sp
->pp_phase
= PHASE_NETWORK
;
2317 log(LOG_DEBUG
, SPP_FMT
"phase %s\n", SPP_ARGS(ifp
),
2318 sppp_phase_name(sp
->pp_phase
));
2321 * Open all authentication protocols. This is even required
2322 * if we already proceeded to network phase, since it might be
2323 * that remote wants us to authenticate, so we might have to
2324 * send a PAP request. Undesired authentication protocols
2325 * don't do anything when they get an Open event.
2327 for (i
= 0; i
< IDX_COUNT
; i
++)
2328 if ((cps
[i
])->flags
& CP_AUTH
)
2331 if (sp
->pp_phase
== PHASE_NETWORK
) {
2332 /* Notify all NCPs. */
2333 for (i
= 0; i
< IDX_COUNT
; i
++)
2334 if ((cps
[i
])->flags
& CP_NCP
)
2338 /* Send Up events to all started protos. */
2339 for (i
= 0, mask
= 1; i
< IDX_COUNT
; i
++, mask
<<= 1)
2340 if (sp
->lcp
.protos
& mask
&& ((cps
[i
])->flags
& CP_LCP
) == 0)
2343 /* notify low-level driver of state change */
2345 sp
->pp_chg(sp
, (int)sp
->pp_phase
);
2347 if (sp
->pp_phase
== PHASE_NETWORK
)
2348 /* if no NCP is starting, close down */
2349 sppp_lcp_check_and_close(sp
);
2353 sppp_lcp_tld(struct sppp
*sp
)
2359 sp
->pp_phase
= PHASE_TERMINATE
;
2362 log(LOG_DEBUG
, SPP_FMT
"phase %s\n", SPP_ARGS(ifp
),
2363 sppp_phase_name(sp
->pp_phase
));
2366 * Take upper layers down. We send the Down event first and
2367 * the Close second to prevent the upper layers from sending
2368 * ``a flurry of terminate-request packets'', as the RFC
2371 for (i
= 0, mask
= 1; i
< IDX_COUNT
; i
++, mask
<<= 1)
2372 if (sp
->lcp
.protos
& mask
&& ((cps
[i
])->flags
& CP_LCP
) == 0) {
2374 (cps
[i
])->Close(sp
);
2379 sppp_lcp_tls(struct sppp
*sp
)
2383 sp
->pp_phase
= PHASE_ESTABLISH
;
2386 log(LOG_DEBUG
, SPP_FMT
"phase %s\n", SPP_ARGS(ifp
),
2387 sppp_phase_name(sp
->pp_phase
));
2389 /* Notify lower layer if desired. */
2397 sppp_lcp_tlf(struct sppp
*sp
)
2401 sp
->pp_phase
= PHASE_DEAD
;
2403 log(LOG_DEBUG
, SPP_FMT
"phase %s\n", SPP_ARGS(ifp
),
2404 sppp_phase_name(sp
->pp_phase
));
2406 /* Notify lower layer if desired. */
2414 sppp_lcp_scr(struct sppp
*sp
)
2416 char opt
[6 /* magicnum */ + 4 /* mru */ + 5 /* chap */];
2420 if (sp
->lcp
.opts
& (1 << LCP_OPT_MAGIC
)) {
2421 if (! sp
->lcp
.magic
)
2422 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
2423 sp
->lcp
.magic
= random();
2425 sp
->lcp
.magic
= time
.tv_sec
+ time
.tv_usec
;
2427 opt
[i
++] = LCP_OPT_MAGIC
;
2429 opt
[i
++] = sp
->lcp
.magic
>> 24;
2430 opt
[i
++] = sp
->lcp
.magic
>> 16;
2431 opt
[i
++] = sp
->lcp
.magic
>> 8;
2432 opt
[i
++] = sp
->lcp
.magic
;
2435 if (sp
->lcp
.opts
& (1 << LCP_OPT_MRU
)) {
2436 opt
[i
++] = LCP_OPT_MRU
;
2438 opt
[i
++] = sp
->lcp
.mru
>> 8;
2439 opt
[i
++] = sp
->lcp
.mru
;
2442 if (sp
->lcp
.opts
& (1 << LCP_OPT_AUTH_PROTO
)) {
2443 authproto
= sp
->hisauth
.proto
;
2444 opt
[i
++] = LCP_OPT_AUTH_PROTO
;
2445 opt
[i
++] = authproto
== PPP_CHAP
? 5: 4;
2446 opt
[i
++] = authproto
>> 8;
2447 opt
[i
++] = authproto
;
2448 if (authproto
== PPP_CHAP
)
2449 opt
[i
++] = CHAP_MD5
;
2452 sp
->confid
[IDX_LCP
] = ++sp
->pp_seq
;
2453 sppp_cp_send (sp
, PPP_LCP
, CONF_REQ
, sp
->confid
[IDX_LCP
], i
, &opt
);
2457 * Check the open NCPs, return true if at least one NCP is open.
2460 sppp_ncp_check(struct sppp
*sp
)
2464 for (i
= 0, mask
= 1; i
< IDX_COUNT
; i
++, mask
<<= 1)
2465 if (sp
->lcp
.protos
& mask
&& (cps
[i
])->flags
& CP_NCP
)
2471 * Re-check the open NCPs and see if we should terminate the link.
2472 * Called by the NCPs during their tlf action handling.
2475 sppp_lcp_check_and_close(struct sppp
*sp
)
2478 if (sp
->pp_phase
< PHASE_NETWORK
)
2479 /* don't bother, we are already going down */
2482 if (sppp_ncp_check(sp
))
2488 *--------------------------------------------------------------------------*
2490 * The IPCP implementation. *
2492 *--------------------------------------------------------------------------*
2496 sppp_ipcp_init(struct sppp
*sp
)
2500 sp
->state
[IDX_IPCP
] = STATE_INITIAL
;
2501 sp
->fail_counter
[IDX_IPCP
] = 0;
2502 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
2503 callout_handle_init(&sp
->ch
[IDX_IPCP
]);
2508 sppp_ipcp_up(struct sppp
*sp
)
2510 sppp_up_event(&ipcp
, sp
);
2514 sppp_ipcp_down(struct sppp
*sp
)
2516 sppp_down_event(&ipcp
, sp
);
2520 sppp_ipcp_open(struct sppp
*sp
)
2523 u_long myaddr
, hisaddr
;
2525 sp
->ipcp
.flags
&= ~(IPCP_HISADDR_SEEN
|IPCP_MYADDR_SEEN
|IPCP_MYADDR_DYN
);
2527 sppp_get_ip_addrs(sp
, &myaddr
, &hisaddr
, 0);
2529 * If we don't have his address, this probably means our
2530 * interface doesn't want to talk IP at all. (This could
2531 * be the case if somebody wants to speak only IPX, for
2532 * example.) Don't open IPCP in this case.
2534 if (hisaddr
== 0L) {
2535 /* XXX this message should go away */
2537 log(LOG_DEBUG
, SPP_FMT
"ipcp_open(): no IP interface\n",
2544 * I don't have an assigned address, so i need to
2545 * negotiate my address.
2547 sp
->ipcp
.flags
|= IPCP_MYADDR_DYN
;
2548 sp
->ipcp
.opts
|= (1 << IPCP_OPT_ADDRESS
);
2550 sp
->ipcp
.flags
|= IPCP_MYADDR_SEEN
;
2551 sppp_open_event(&ipcp
, sp
);
2555 sppp_ipcp_close(struct sppp
*sp
)
2557 sppp_close_event(&ipcp
, sp
);
2558 if (sp
->ipcp
.flags
& IPCP_MYADDR_DYN
)
2560 * My address was dynamic, clear it again.
2562 sppp_set_ip_addr(sp
, 0L);
2566 sppp_ipcp_TO(void *cookie
)
2568 sppp_to_event(&ipcp
, (struct sppp
*)cookie
);
2572 * Analyze a configure request. Return true if it was agreeable, and
2573 * caused action sca, false if it has been rejected or nak'ed, and
2574 * caused action scn. (The return value is used to make the state
2575 * transition decision in the state automaton.)
2578 sppp_ipcp_RCR(struct sppp
*sp
, struct lcp_header
*h
, int len
)
2580 u_char
*buf
, *r
, *p
;
2581 struct ifnet
*ifp
= &sp
->pp_if
;
2582 int rlen
, origlen
, debug
= ifp
->if_flags
& IFF_DEBUG
;
2583 u_long hisaddr
, desiredaddr
;
2589 * Make sure to allocate a buf that can at least hold a
2590 * conf-nak with an `address' option. We might need it below.
2592 buf
= r
= MALLOC ((len
< 6? 6: len
), M_TEMP
, M_NOWAIT
);
2596 /* pass 1: see if we can recognize them */
2598 log(LOG_DEBUG
, SPP_FMT
"ipcp parse opts: ",
2601 for (rlen
=0; len
>1 && p
[1]; len
-=p
[1], p
+=p
[1]) {
2603 addlog(" %s ", sppp_ipcp_opt_name(*p
));
2606 case IPCP_OPT_COMPRESSION
:
2607 if (len
>= 6 && p
[1] >= 6) {
2608 /* correctly formed compress option */
2612 addlog("[invalid] ");
2615 case IPCP_OPT_ADDRESS
:
2616 if (len
>= 6 && p
[1] == 6) {
2617 /* correctly formed address option */
2621 addlog("[invalid] ");
2624 /* Others not supported. */
2629 /* Add the option to rejected list. */
2636 addlog(" send conf-rej\n");
2637 sppp_cp_send (sp
, PPP_IPCP
, CONF_REJ
, h
->ident
, rlen
, buf
);
2642 /* pass 2: parse option values */
2643 sppp_get_ip_addrs(sp
, 0, &hisaddr
, 0);
2645 log(LOG_DEBUG
, SPP_FMT
"ipcp parse opt values: ",
2649 for (rlen
=0; len
>1 && p
[1]; len
-=p
[1], p
+=p
[1]) {
2651 addlog(" %s ", sppp_ipcp_opt_name(*p
));
2654 case IPCP_OPT_COMPRESSION
:
2657 case IPCP_OPT_ADDRESS
:
2658 /* This is the address he wants in his end */
2659 desiredaddr
= p
[2] << 24 | p
[3] << 16 |
2661 if (desiredaddr
== hisaddr
||
2662 (hisaddr
== 1 && desiredaddr
!= 0)) {
2664 * Peer's address is same as our value,
2665 * or we have set it to 0.0.0.1 to
2666 * indicate that we do not really care,
2667 * this is agreeable. Gonna conf-ack
2672 sppp_dotted_quad(hisaddr
));
2673 /* record that we've seen it already */
2674 sp
->ipcp
.flags
|= IPCP_HISADDR_SEEN
;
2678 * The address wasn't agreeable. This is either
2679 * he sent us 0.0.0.0, asking to assign him an
2680 * address, or he send us another address not
2681 * matching our value. Either case, we gonna
2682 * conf-nak it with our value.
2683 * XXX: we should "rej" if hisaddr == 0
2686 if (desiredaddr
== 0)
2687 addlog("[addr requested] ");
2689 addlog("%s [not agreed] ",
2690 sppp_dotted_quad(desiredaddr
));
2692 p
[2] = hisaddr
>> 24;
2693 p
[3] = hisaddr
>> 16;
2694 p
[4] = hisaddr
>> 8;
2699 /* Add the option to nak'ed list. */
2706 * If we are about to conf-ack the request, but haven't seen
2707 * his address so far, gonna conf-nak it instead, with the
2708 * `address' option present and our idea of his address being
2709 * filled in there, to request negotiation of both addresses.
2711 * XXX This can result in an endless req - nak loop if peer
2712 * doesn't want to send us his address. Q: What should we do
2713 * about it? XXX A: implement the max-failure counter.
2715 if (rlen
== 0 && !(sp
->ipcp
.flags
& IPCP_HISADDR_SEEN
) && !gotmyaddr
) {
2716 buf
[0] = IPCP_OPT_ADDRESS
;
2718 buf
[2] = hisaddr
>> 24;
2719 buf
[3] = hisaddr
>> 16;
2720 buf
[4] = hisaddr
>> 8;
2724 addlog("still need hisaddr ");
2729 addlog(" send conf-nak\n");
2730 sppp_cp_send (sp
, PPP_IPCP
, CONF_NAK
, h
->ident
, rlen
, buf
);
2733 addlog(" send conf-ack\n");
2734 sppp_cp_send (sp
, PPP_IPCP
, CONF_ACK
,
2735 h
->ident
, origlen
, h
+1);
2743 * Analyze the IPCP Configure-Reject option list, and adjust our
2747 sppp_ipcp_RCN_rej(struct sppp
*sp
, struct lcp_header
*h
, int len
)
2750 struct ifnet
*ifp
= &sp
->pp_if
;
2751 int debug
= ifp
->if_flags
& IFF_DEBUG
;
2754 buf
= MALLOC (len
, M_TEMP
, M_NOWAIT
);
2759 log(LOG_DEBUG
, SPP_FMT
"ipcp rej opts: ",
2763 for (; len
> 1 && p
[1]; len
-= p
[1], p
+= p
[1]) {
2765 addlog(" %s ", sppp_ipcp_opt_name(*p
));
2767 case IPCP_OPT_ADDRESS
:
2769 * Peer doesn't grok address option. This is
2770 * bad. XXX Should we better give up here?
2771 * XXX We could try old "addresses" option...
2773 sp
->ipcp
.opts
&= ~(1 << IPCP_OPT_ADDRESS
);
2776 case IPCP_OPT_COMPRESS
:
2777 sp
->ipcp
.opts
&= ~(1 << IPCP_OPT_COMPRESS
);
2789 * Analyze the IPCP Configure-NAK option list, and adjust our
2793 sppp_ipcp_RCN_nak(struct sppp
*sp
, struct lcp_header
*h
, int len
)
2796 struct ifnet
*ifp
= &sp
->pp_if
;
2797 int debug
= ifp
->if_flags
& IFF_DEBUG
;
2801 buf
= MALLOC (len
, M_TEMP
, M_NOWAIT
);
2806 log(LOG_DEBUG
, SPP_FMT
"ipcp nak opts: ",
2810 for (; len
> 1 && p
[1]; len
-= p
[1], p
+= p
[1]) {
2812 addlog(" %s ", sppp_ipcp_opt_name(*p
));
2814 case IPCP_OPT_ADDRESS
:
2816 * Peer doesn't like our local IP address. See
2817 * if we can do something for him. We'll drop
2818 * him our address then.
2820 if (len
>= 6 && p
[1] == 6) {
2821 wantaddr
= p
[2] << 24 | p
[3] << 16 |
2823 sp
->ipcp
.opts
|= (1 << IPCP_OPT_ADDRESS
);
2825 addlog("[wantaddr %s] ",
2826 sppp_dotted_quad(wantaddr
));
2828 * When doing dynamic address assignment,
2829 * we accept his offer. Otherwise, we
2830 * ignore it and thus continue to negotiate
2831 * our already existing value.
2832 * XXX: Bogus, if he said no once, he'll
2833 * just say no again, might as well die.
2835 if (sp
->ipcp
.flags
& IPCP_MYADDR_DYN
) {
2836 sppp_set_ip_addr(sp
, wantaddr
);
2839 sp
->ipcp
.flags
|= IPCP_MYADDR_SEEN
;
2844 case IPCP_OPT_COMPRESS
:
2846 * Peer wants different compression parameters.
2859 sppp_ipcp_tlu(struct sppp
*sp
)
2861 /* we are up - notify isdn daemon */
2867 sppp_ipcp_tld(struct sppp
*sp
)
2872 sppp_ipcp_tls(struct sppp
*sp
)
2874 /* indicate to LCP that it must stay alive */
2875 sp
->lcp
.protos
|= (1 << IDX_IPCP
);
2879 sppp_ipcp_tlf(struct sppp
*sp
)
2881 /* we no longer need LCP */
2882 sp
->lcp
.protos
&= ~(1 << IDX_IPCP
);
2883 sppp_lcp_check_and_close(sp
);
2887 sppp_ipcp_scr(struct sppp
*sp
)
2889 char opt
[6 /* compression */ + 6 /* address */];
2894 if (sp
->ipcp
.opts
& (1 << IPCP_OPT_COMPRESSION
)) {
2895 opt
[i
++] = IPCP_OPT_COMPRESSION
;
2897 opt
[i
++] = 0; /* VJ header compression */
2898 opt
[i
++] = 0x2d; /* VJ header compression */
2899 opt
[i
++] = max_slot_id
;
2900 opt
[i
++] = comp_slot_id
;
2904 if (sp
->ipcp
.opts
& (1 << IPCP_OPT_ADDRESS
)) {
2905 sppp_get_ip_addrs(sp
, &ouraddr
, 0, 0);
2906 opt
[i
++] = IPCP_OPT_ADDRESS
;
2908 opt
[i
++] = ouraddr
>> 24;
2909 opt
[i
++] = ouraddr
>> 16;
2910 opt
[i
++] = ouraddr
>> 8;
2914 sp
->confid
[IDX_IPCP
] = ++sp
->pp_seq
;
2915 sppp_cp_send(sp
, PPP_IPCP
, CONF_REQ
, sp
->confid
[IDX_IPCP
], i
, &opt
);
2920 *--------------------------------------------------------------------------*
2922 * The CHAP implementation. *
2924 *--------------------------------------------------------------------------*
2928 * The authentication protocols don't employ a full-fledged state machine as
2929 * the control protocols do, since they do have Open and Close events, but
2930 * not Up and Down, nor are they explicitly terminated. Also, use of the
2931 * authentication protocols may be different in both directions (this makes
2932 * sense, think of a machine that never accepts incoming calls but only
2933 * calls out, it doesn't require the called party to authenticate itself).
2935 * Our state machine for the local authentication protocol (we are requesting
2936 * the peer to authenticate) looks like:
2939 * +--------------------------------------------+
2941 * +--------+ Close +---------+ RCA+
2942 * | |<----------------------------------| |------+
2943 * +--->| Closed | TO* | Opened | sca |
2944 * | | |-----+ +-------| |<-----+
2945 * | +--------+ irc | | +---------+
2951 * | | +------->+ | |
2953 * | +--------+ V | |
2954 * | | |<----+<--------------------+ |
2960 * +------+ +------------------------------------------+
2961 * scn,tld sca,irc,ict,tlu
2966 * Open: LCP reached authentication phase
2967 * Close: LCP reached terminate phase
2969 * RCA+: received reply (pap-req, chap-response), acceptable
2970 * RCN: received reply (pap-req, chap-response), not acceptable
2971 * TO+: timeout with restart counter >= 0
2972 * TO-: timeout with restart counter < 0
2973 * TO*: reschedule timeout for CHAP
2975 * scr: send request packet (none for PAP, chap-challenge)
2976 * sca: send ack packet (pap-ack, chap-success)
2977 * scn: send nak packet (pap-nak, chap-failure)
2978 * ict: initialize re-challenge timer (CHAP only)
2980 * tlu: this-layer-up, LCP reaches network phase
2981 * tld: this-layer-down, LCP enters terminate phase
2983 * Note that in CHAP mode, after sending a new challenge, while the state
2984 * automaton falls back into Req-Sent state, it doesn't signal a tld
2985 * event to LCP, so LCP remains in network phase. Only after not getting
2986 * any response (or after getting an unacceptable response), CHAP closes,
2987 * causing LCP to enter terminate phase.
2989 * With PAP, there is no initial request that can be sent. The peer is
2990 * expected to send one based on the successful negotiation of PAP as
2991 * the authentication protocol during the LCP option negotiation.
2993 * Incoming authentication protocol requests (remote requests
2994 * authentication, we are peer) don't employ a state machine at all,
2995 * they are simply answered. Some peers [Ascend P50 firmware rev
2996 * 4.50] react allergically when sending IPCP requests while they are
2997 * still in authentication phase (thereby violating the standard that
2998 * demands that these NCP packets are to be discarded), so we keep
2999 * track of the peer demanding us to authenticate, and only proceed to
3000 * phase network once we've seen a positive acknowledge for the
3005 * Handle incoming CHAP packets.
3008 sppp_chap_input(struct sppp
*sp
, struct mbuf
*m
)
3011 struct lcp_header
*h
;
3013 u_char
*value
, *name
, digest
[AUTHKEYLEN
], dsize
;
3014 int value_len
, name_len
;
3017 len
= m
->m_pkthdr
.len
;
3021 SPP_FMT
"chap invalid packet length: %d bytes\n",
3022 SPP_ARGS(ifp
), len
);
3025 h
= mtod (m
, struct lcp_header
*);
3026 if (len
> ntohs (h
->len
))
3027 len
= ntohs (h
->len
);
3030 /* challenge, failure and success are his authproto */
3031 case CHAP_CHALLENGE
:
3032 value
= 1 + (u_char
*)(h
+1);
3033 value_len
= value
[-1];
3034 name
= value
+ value_len
;
3035 name_len
= len
- value_len
- 5;
3039 SPP_FMT
"chap corrupted challenge "
3040 "<%s id=0x%x len=%d",
3042 sppp_auth_type_name(PPP_CHAP
, h
->type
),
3043 h
->ident
, ntohs(h
->len
));
3045 sppp_print_bytes((u_char
*) (h
+1), len
-4);
3053 SPP_FMT
"chap input <%s id=0x%x len=%d name=",
3055 sppp_auth_type_name(PPP_CHAP
, h
->type
), h
->ident
,
3057 sppp_print_string((char*) name
, name_len
);
3058 addlog(" value-size=%d value=", value_len
);
3059 sppp_print_bytes(value
, value_len
);
3063 /* Compute reply value. */
3065 MD5Update(&ctx
, &h
->ident
, 1);
3066 MD5Update(&ctx
, sp
->myauth
.secret
,
3067 sppp_strnlen(sp
->myauth
.secret
, AUTHKEYLEN
));
3068 MD5Update(&ctx
, value
, value_len
);
3069 MD5Final(digest
, &ctx
);
3070 dsize
= sizeof digest
;
3072 sppp_auth_send(&chap
, sp
, CHAP_RESPONSE
, h
->ident
,
3073 sizeof dsize
, (const char *)&dsize
,
3074 sizeof digest
, digest
,
3075 (size_t)sppp_strnlen(sp
->myauth
.name
, AUTHNAMELEN
),
3082 log(LOG_DEBUG
, SPP_FMT
"chap success",
3086 sppp_print_string((char*)(h
+ 1), len
- 4);
3091 sp
->pp_flags
&= ~PP_NEEDAUTH
;
3092 if (sp
->myauth
.proto
== PPP_CHAP
&&
3093 (sp
->lcp
.opts
& (1 << LCP_OPT_AUTH_PROTO
)) &&
3094 (sp
->lcp
.protos
& (1 << IDX_CHAP
)) == 0) {
3096 * We are authenticator for CHAP but didn't
3097 * complete yet. Leave it to tlu to proceed
3104 sppp_phase_network(sp
);
3109 log(LOG_INFO
, SPP_FMT
"chap failure",
3113 sppp_print_string((char*)(h
+ 1), len
- 4);
3117 log(LOG_INFO
, SPP_FMT
"chap failure\n",
3119 /* await LCP shutdown by authenticator */
3122 /* response is my authproto */
3124 value
= 1 + (u_char
*)(h
+1);
3125 value_len
= value
[-1];
3126 name
= value
+ value_len
;
3127 name_len
= len
- value_len
- 5;
3131 SPP_FMT
"chap corrupted response "
3132 "<%s id=0x%x len=%d",
3134 sppp_auth_type_name(PPP_CHAP
, h
->type
),
3135 h
->ident
, ntohs(h
->len
));
3137 sppp_print_bytes((u_char
*)(h
+1), len
-4);
3142 if (h
->ident
!= sp
->confid
[IDX_CHAP
]) {
3145 SPP_FMT
"chap dropping response for old ID "
3146 "(got %d, expected %d)\n",
3148 h
->ident
, sp
->confid
[IDX_CHAP
]);
3151 if (name_len
!= sppp_strnlen(sp
->hisauth
.name
, AUTHNAMELEN
)
3152 || bcmp(name
, sp
->hisauth
.name
, name_len
) != 0) {
3153 log(LOG_INFO
, SPP_FMT
"chap response, his name ",
3155 sppp_print_string(name
, name_len
);
3156 addlog(" != expected ");
3157 sppp_print_string(sp
->hisauth
.name
,
3158 sppp_strnlen(sp
->hisauth
.name
, AUTHNAMELEN
));
3162 log(LOG_DEBUG
, SPP_FMT
"chap input(%s) "
3163 "<%s id=0x%x len=%d name=",
3165 sppp_state_name(sp
->state
[IDX_CHAP
]),
3166 sppp_auth_type_name(PPP_CHAP
, h
->type
),
3167 h
->ident
, ntohs (h
->len
));
3168 sppp_print_string((char*)name
, name_len
);
3169 addlog(" value-size=%d value=", value_len
);
3170 sppp_print_bytes(value
, value_len
);
3173 if (value_len
!= AUTHKEYLEN
) {
3176 SPP_FMT
"chap bad hash value length: "
3177 "%d bytes, should be %d\n",
3178 SPP_ARGS(ifp
), value_len
,
3184 MD5Update(&ctx
, &h
->ident
, 1);
3185 MD5Update(&ctx
, sp
->hisauth
.secret
,
3186 sppp_strnlen(sp
->hisauth
.secret
, AUTHKEYLEN
));
3187 MD5Update(&ctx
, sp
->myauth
.challenge
, AUTHKEYLEN
);
3188 MD5Final(digest
, &ctx
);
3190 #define FAILMSG "Failed..."
3191 #define SUCCMSG "Welcome!"
3193 if (value_len
!= sizeof digest
||
3194 bcmp(digest
, value
, value_len
) != 0) {
3195 /* action scn, tld */
3196 sppp_auth_send(&chap
, sp
, CHAP_FAILURE
, h
->ident
,
3197 sizeof(FAILMSG
) - 1, (u_char
*)FAILMSG
,
3202 /* action sca, perhaps tlu */
3203 if (sp
->state
[IDX_CHAP
] == STATE_REQ_SENT
||
3204 sp
->state
[IDX_CHAP
] == STATE_OPENED
)
3205 sppp_auth_send(&chap
, sp
, CHAP_SUCCESS
, h
->ident
,
3206 sizeof(SUCCMSG
) - 1, (u_char
*)SUCCMSG
,
3208 if (sp
->state
[IDX_CHAP
] == STATE_REQ_SENT
) {
3209 sppp_cp_change_state(&chap
, sp
, STATE_OPENED
);
3215 /* Unknown CHAP packet type -- ignore. */
3217 log(LOG_DEBUG
, SPP_FMT
"chap unknown input(%s) "
3218 "<0x%x id=0x%xh len=%d",
3220 sppp_state_name(sp
->state
[IDX_CHAP
]),
3221 h
->type
, h
->ident
, ntohs(h
->len
));
3223 sppp_print_bytes((u_char
*)(h
+1), len
-4);
3232 sppp_chap_init(struct sppp
*sp
)
3234 /* Chap doesn't have STATE_INITIAL at all. */
3235 sp
->state
[IDX_CHAP
] = STATE_CLOSED
;
3236 sp
->fail_counter
[IDX_CHAP
] = 0;
3237 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
3238 callout_handle_init(&sp
->ch
[IDX_CHAP
]);
3243 sppp_chap_open(struct sppp
*sp
)
3245 if (sp
->myauth
.proto
== PPP_CHAP
&&
3246 (sp
->lcp
.opts
& (1 << LCP_OPT_AUTH_PROTO
)) != 0) {
3247 /* we are authenticator for CHAP, start it */
3249 sp
->rst_counter
[IDX_CHAP
] = sp
->lcp
.max_configure
;
3250 sppp_cp_change_state(&chap
, sp
, STATE_REQ_SENT
);
3252 /* nothing to be done if we are peer, await a challenge */
3256 sppp_chap_close(struct sppp
*sp
)
3258 if (sp
->state
[IDX_CHAP
] != STATE_CLOSED
)
3259 sppp_cp_change_state(&chap
, sp
, STATE_CLOSED
);
3263 sppp_chap_TO(void *cookie
)
3265 struct sppp
*sp
= (struct sppp
*)cookie
;
3271 log(LOG_DEBUG
, SPP_FMT
"chap TO(%s) rst_counter = %d\n",
3273 sppp_state_name(sp
->state
[IDX_CHAP
]),
3274 sp
->rst_counter
[IDX_CHAP
]);
3276 if (--sp
->rst_counter
[IDX_CHAP
] < 0)
3278 switch (sp
->state
[IDX_CHAP
]) {
3279 case STATE_REQ_SENT
:
3281 sppp_cp_change_state(&chap
, sp
, STATE_CLOSED
);
3285 /* TO+ (or TO*) event */
3286 switch (sp
->state
[IDX_CHAP
]) {
3289 sp
->rst_counter
[IDX_CHAP
] = sp
->lcp
.max_configure
;
3291 case STATE_REQ_SENT
:
3293 /* sppp_cp_change_state() will restart the timer */
3294 sppp_cp_change_state(&chap
, sp
, STATE_REQ_SENT
);
3302 sppp_chap_tlu(struct sppp
*sp
)
3308 sp
->rst_counter
[IDX_CHAP
] = sp
->lcp
.max_configure
;
3311 * Some broken CHAP implementations (Conware CoNet, firmware
3312 * 4.0.?) don't want to re-authenticate their CHAP once the
3313 * initial challenge-response exchange has taken place.
3314 * Provide for an option to avoid rechallenges.
3316 if ((sp
->hisauth
.flags
& AUTHFLAG_NORECHALLENGE
) == 0) {
3318 * Compute the re-challenge timeout. This will yield
3319 * a number between 300 and 810 seconds.
3321 i
= 300 + ((unsigned)(random() & 0xff00) >> 7);
3322 TIMEOUT(chap
.TO
, (void *)sp
, i
* hz
, sp
->ch
[IDX_CHAP
]);
3327 SPP_FMT
"chap %s, ",
3329 sp
->pp_phase
== PHASE_NETWORK
? "reconfirmed": "tlu");
3330 if ((sp
->hisauth
.flags
& AUTHFLAG_NORECHALLENGE
) == 0)
3331 addlog("next re-challenge in %d seconds\n", i
);
3333 addlog("re-challenging supressed\n");
3337 /* indicate to LCP that we need to be closed down */
3338 sp
->lcp
.protos
|= (1 << IDX_CHAP
);
3340 if (sp
->pp_flags
& PP_NEEDAUTH
) {
3342 * Remote is authenticator, but his auth proto didn't
3343 * complete yet. Defer the transition to network
3352 * If we are already in phase network, we are done here. This
3353 * is the case if this is a dummy tlu event after a re-challenge.
3355 if (sp
->pp_phase
!= PHASE_NETWORK
)
3356 sppp_phase_network(sp
);
3360 sppp_chap_tld(struct sppp
*sp
)
3365 log(LOG_DEBUG
, SPP_FMT
"chap tld\n", SPP_ARGS(ifp
));
3366 UNTIMEOUT(chap
.TO
, (void *)sp
, sp
->ch
[IDX_CHAP
]);
3367 sp
->lcp
.protos
&= ~(1 << IDX_CHAP
);
3373 sppp_chap_scr(struct sppp
*sp
)
3378 /* Compute random challenge. */
3379 ch
= (u_long
*)sp
->myauth
.challenge
;
3380 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
3381 read_random(&seed
, sizeof seed
);
3386 seed
= tv
.tv_sec
^ tv
.tv_usec
;
3389 ch
[0] = seed
^ random();
3390 ch
[1] = seed
^ random();
3391 ch
[2] = seed
^ random();
3392 ch
[3] = seed
^ random();
3395 sp
->confid
[IDX_CHAP
] = ++sp
->pp_seq
;
3397 sppp_auth_send(&chap
, sp
, CHAP_CHALLENGE
, sp
->confid
[IDX_CHAP
],
3398 sizeof clen
, (const char *)&clen
,
3399 (size_t)AUTHKEYLEN
, sp
->myauth
.challenge
,
3400 (size_t)sppp_strnlen(sp
->myauth
.name
, AUTHNAMELEN
),
3405 *--------------------------------------------------------------------------*
3407 * The PAP implementation. *
3409 *--------------------------------------------------------------------------*
3412 * For PAP, we need to keep a little state also if we are the peer, not the
3413 * authenticator. This is since we don't get a request to authenticate, but
3414 * have to repeatedly authenticate ourself until we got a response (or the
3415 * retry counter is expired).
3419 * Handle incoming PAP packets. */
3421 sppp_pap_input(struct sppp
*sp
, struct mbuf
*m
)
3424 struct lcp_header
*h
;
3426 u_char
*name
, *passwd
, mlen
;
3427 int name_len
, passwd_len
;
3429 len
= m
->m_pkthdr
.len
;
3433 SPP_FMT
"pap invalid packet length: %d bytes\n",
3434 SPP_ARGS(ifp
), len
);
3437 h
= mtod (m
, struct lcp_header
*);
3438 if (len
> ntohs (h
->len
))
3439 len
= ntohs (h
->len
);
3441 /* PAP request is my authproto */
3443 name
= 1 + (u_char
*)(h
+1);
3444 name_len
= name
[-1];
3445 passwd
= name
+ name_len
+ 1;
3446 if (name_len
> len
- 6 ||
3447 (passwd_len
= passwd
[-1]) > len
- 6 - name_len
) {
3449 log(LOG_DEBUG
, SPP_FMT
"pap corrupted input "
3450 "<%s id=0x%x len=%d",
3452 sppp_auth_type_name(PPP_PAP
, h
->type
),
3453 h
->ident
, ntohs(h
->len
));
3455 sppp_print_bytes((u_char
*)(h
+1), len
-4);
3461 log(LOG_DEBUG
, SPP_FMT
"pap input(%s) "
3462 "<%s id=0x%x len=%d name=",
3464 sppp_state_name(sp
->state
[IDX_PAP
]),
3465 sppp_auth_type_name(PPP_PAP
, h
->type
),
3466 h
->ident
, ntohs(h
->len
));
3467 sppp_print_string((char*)name
, name_len
);
3469 sppp_print_string((char*)passwd
, passwd_len
);
3472 if (name_len
> AUTHNAMELEN
||
3473 passwd_len
> AUTHKEYLEN
||
3474 bcmp(name
, sp
->hisauth
.name
, name_len
) != 0 ||
3475 bcmp(passwd
, sp
->hisauth
.secret
, passwd_len
) != 0) {
3476 /* action scn, tld */
3477 mlen
= sizeof(FAILMSG
) - 1;
3478 sppp_auth_send(&pap
, sp
, PAP_NAK
, h
->ident
,
3479 sizeof mlen
, (const char *)&mlen
,
3480 sizeof(FAILMSG
) - 1, (u_char
*)FAILMSG
,
3485 /* action sca, perhaps tlu */
3486 if (sp
->state
[IDX_PAP
] == STATE_REQ_SENT
||
3487 sp
->state
[IDX_PAP
] == STATE_OPENED
) {
3488 mlen
= sizeof(SUCCMSG
) - 1;
3489 sppp_auth_send(&pap
, sp
, PAP_ACK
, h
->ident
,
3490 sizeof mlen
, (const char *)&mlen
,
3491 sizeof(SUCCMSG
) - 1, (u_char
*)SUCCMSG
,
3494 if (sp
->state
[IDX_PAP
] == STATE_REQ_SENT
) {
3495 sppp_cp_change_state(&pap
, sp
, STATE_OPENED
);
3500 /* ack and nak are his authproto */
3502 UNTIMEOUT(sppp_pap_my_TO
, (void *)sp
, sp
->pap_my_to_ch
);
3504 log(LOG_DEBUG
, SPP_FMT
"pap success",
3506 name_len
= *((char *)h
);
3507 if (len
> 5 && name_len
) {
3509 sppp_print_string((char*)(h
+1), name_len
);
3514 sp
->pp_flags
&= ~PP_NEEDAUTH
;
3515 if (sp
->myauth
.proto
== PPP_PAP
&&
3516 (sp
->lcp
.opts
& (1 << LCP_OPT_AUTH_PROTO
)) &&
3517 (sp
->lcp
.protos
& (1 << IDX_PAP
)) == 0) {
3519 * We are authenticator for PAP but didn't
3520 * complete yet. Leave it to tlu to proceed
3527 sppp_phase_network(sp
);
3531 UNTIMEOUT(sppp_pap_my_TO
, (void *)sp
, sp
->pap_my_to_ch
);
3533 log(LOG_INFO
, SPP_FMT
"pap failure",
3535 name_len
= *((char *)h
);
3536 if (len
> 5 && name_len
) {
3538 sppp_print_string((char*)(h
+1), name_len
);
3542 log(LOG_INFO
, SPP_FMT
"pap failure\n",
3544 /* await LCP shutdown by authenticator */
3548 /* Unknown PAP packet type -- ignore. */
3550 log(LOG_DEBUG
, SPP_FMT
"pap corrupted input "
3551 "<0x%x id=0x%x len=%d",
3553 h
->type
, h
->ident
, ntohs(h
->len
));
3555 sppp_print_bytes((u_char
*)(h
+1), len
-4);
3564 sppp_pap_init(struct sppp
*sp
)
3566 /* PAP doesn't have STATE_INITIAL at all. */
3567 sp
->state
[IDX_PAP
] = STATE_CLOSED
;
3568 sp
->fail_counter
[IDX_PAP
] = 0;
3569 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
3570 callout_handle_init(&sp
->ch
[IDX_PAP
]);
3571 callout_handle_init(&sp
->pap_my_to_ch
);
3576 sppp_pap_open(struct sppp
*sp
)
3578 if (sp
->hisauth
.proto
== PPP_PAP
&&
3579 (sp
->lcp
.opts
& (1 << LCP_OPT_AUTH_PROTO
)) != 0) {
3580 /* we are authenticator for PAP, start our timer */
3581 sp
->rst_counter
[IDX_PAP
] = sp
->lcp
.max_configure
;
3582 sppp_cp_change_state(&pap
, sp
, STATE_REQ_SENT
);
3584 if (sp
->myauth
.proto
== PPP_PAP
) {
3585 /* we are peer, send a request, and start a timer */
3587 TIMEOUT(sppp_pap_my_TO
, (void *)sp
, sp
->lcp
.timeout
,
3593 sppp_pap_close(struct sppp
*sp
)
3595 if (sp
->state
[IDX_PAP
] != STATE_CLOSED
)
3596 sppp_cp_change_state(&pap
, sp
, STATE_CLOSED
);
3600 * That's the timeout routine if we are authenticator. Since the
3601 * authenticator is basically passive in PAP, we can't do much here.
3604 sppp_pap_TO(void *cookie
)
3606 struct sppp
*sp
= (struct sppp
*)cookie
;
3612 log(LOG_DEBUG
, SPP_FMT
"pap TO(%s) rst_counter = %d\n",
3614 sppp_state_name(sp
->state
[IDX_PAP
]),
3615 sp
->rst_counter
[IDX_PAP
]);
3617 if (--sp
->rst_counter
[IDX_PAP
] < 0)
3619 switch (sp
->state
[IDX_PAP
]) {
3620 case STATE_REQ_SENT
:
3622 sppp_cp_change_state(&pap
, sp
, STATE_CLOSED
);
3626 /* TO+ event, not very much we could do */
3627 switch (sp
->state
[IDX_PAP
]) {
3628 case STATE_REQ_SENT
:
3629 /* sppp_cp_change_state() will restart the timer */
3630 sppp_cp_change_state(&pap
, sp
, STATE_REQ_SENT
);
3638 * That's the timeout handler if we are peer. Since the peer is active,
3639 * we need to retransmit our PAP request since it is apparently lost.
3640 * XXX We should impose a max counter.
3643 sppp_pap_my_TO(void *cookie
)
3645 struct sppp
*sp
= (struct sppp
*)cookie
;
3649 log(LOG_DEBUG
, SPP_FMT
"pap peer TO\n",
3656 sppp_pap_tlu(struct sppp
*sp
)
3661 sp
->rst_counter
[IDX_PAP
] = sp
->lcp
.max_configure
;
3664 log(LOG_DEBUG
, SPP_FMT
"%s tlu\n",
3665 SPP_ARGS(ifp
), pap
.name
);
3668 /* indicate to LCP that we need to be closed down */
3669 sp
->lcp
.protos
|= (1 << IDX_PAP
);
3671 if (sp
->pp_flags
& PP_NEEDAUTH
) {
3673 * Remote is authenticator, but his auth proto didn't
3674 * complete yet. Defer the transition to network
3681 sppp_phase_network(sp
);
3685 sppp_pap_tld(struct sppp
*sp
)
3690 log(LOG_DEBUG
, SPP_FMT
"pap tld\n", SPP_ARGS(ifp
));
3691 UNTIMEOUT(pap
.TO
, (void *)sp
, sp
->ch
[IDX_PAP
]);
3692 UNTIMEOUT(sppp_pap_my_TO
, (void *)sp
, sp
->pap_my_to_ch
);
3693 sp
->lcp
.protos
&= ~(1 << IDX_PAP
);
3699 sppp_pap_scr(struct sppp
*sp
)
3701 u_char idlen
, pwdlen
;
3703 sp
->confid
[IDX_PAP
] = ++sp
->pp_seq
;
3704 pwdlen
= sppp_strnlen(sp
->myauth
.secret
, AUTHKEYLEN
);
3705 idlen
= sppp_strnlen(sp
->myauth
.name
, AUTHNAMELEN
);
3707 sppp_auth_send(&pap
, sp
, PAP_REQ
, sp
->confid
[IDX_PAP
],
3708 sizeof idlen
, (const char *)&idlen
,
3709 (size_t)idlen
, sp
->myauth
.name
,
3710 sizeof pwdlen
, (const char *)&pwdlen
,
3711 (size_t)pwdlen
, sp
->myauth
.secret
,
3715 * Random miscellaneous functions.
3719 * Send a PAP or CHAP proto packet.
3721 * Varadic function, each of the elements for the ellipsis is of type
3722 * ``size_t mlen, const u_char *msg''. Processing will stop iff
3724 * NOTE: never declare variadic functions with types subject to type
3725 * promotion (i.e. u_char). This is asking for big trouble depending
3726 * on the architecture you are on...
3730 sppp_auth_send(const struct cp
*cp
, struct sppp
*sp
,
3731 unsigned int type
, unsigned int id
,
3735 struct ppp_header
*h
;
3736 struct lcp_header
*lh
;
3744 MGETHDR (m
, M_DONTWAIT
, MT_DATA
);
3747 m
->m_pkthdr
.rcvif
= 0;
3749 h
= mtod (m
, struct ppp_header
*);
3750 h
->address
= PPP_ALLSTATIONS
; /* broadcast address */
3751 h
->control
= PPP_UI
; /* Unnumbered Info */
3752 h
->protocol
= htons(cp
->proto
);
3754 lh
= (struct lcp_header
*)(h
+ 1);
3757 p
= (u_char
*) (lh
+1);
3762 while ((mlen
= (unsigned int)va_arg(ap
, size_t)) != 0) {
3763 msg
= va_arg(ap
, const char *);
3765 if (len
> MHLEN
- PPP_HEADER_LEN
- LCP_HEADER_LEN
) {
3771 bcopy(msg
, p
, mlen
);
3776 m
->m_pkthdr
.len
= m
->m_len
= PPP_HEADER_LEN
+ LCP_HEADER_LEN
+ len
;
3777 lh
->len
= htons (LCP_HEADER_LEN
+ len
);
3780 log(LOG_DEBUG
, SPP_FMT
"%s output <%s id=0x%x len=%d",
3781 SPP_ARGS(ifp
), cp
->name
,
3782 sppp_auth_type_name(cp
->proto
, lh
->type
),
3783 lh
->ident
, ntohs(lh
->len
));
3785 sppp_print_bytes((u_char
*) (lh
+1), len
);
3788 if (IF_QFULL (&sp
->pp_cpq
)) {
3789 IF_DROP (&sp
->pp_fastq
);
3790 IF_DROP (&ifp
->if_snd
);
3794 IF_ENQUEUE (&sp
->pp_cpq
, m
);
3795 if (! (ifp
->if_flags
& IFF_OACTIVE
))
3796 (*ifp
->if_start
) (ifp
);
3797 ifp
->if_obytes
+= m
->m_pkthdr
.len
+ 3;
3801 * Flush interface queue.
3804 sppp_qflush(struct ifqueue
*ifq
)
3819 * Send keepalive packets, every 10 seconds.
3822 sppp_keepalive(void *dummy
)
3828 for (sp
=spppq
; sp
; sp
=sp
->pp_next
) {
3829 struct ifnet
*ifp
= &sp
->pp_if
;
3831 /* Keepalive mode disabled or channel down? */
3832 if (! (sp
->pp_flags
& PP_KEEPALIVE
) ||
3833 ! (ifp
->if_flags
& IFF_RUNNING
))
3836 /* No keepalive in PPP mode if LCP not opened yet. */
3837 if (! (sp
->pp_flags
& PP_CISCO
) &&
3838 sp
->pp_phase
< PHASE_AUTHENTICATE
)
3841 if (sp
->pp_alivecnt
== MAXALIVECNT
) {
3842 /* No keepalive packets got. Stop the interface. */
3843 printf (SPP_FMT
"down\n", SPP_ARGS(ifp
));
3845 sppp_qflush (&sp
->pp_cpq
);
3846 if (! (sp
->pp_flags
& PP_CISCO
)) {
3848 /* Shut down the PPP link. */
3850 /* Initiate negotiation. XXX */
3854 if (sp
->pp_alivecnt
<= MAXALIVECNT
)
3856 if (sp
->pp_flags
& PP_CISCO
)
3857 sppp_cisco_send (sp
, CISCO_KEEPALIVE_REQ
, ++sp
->pp_seq
,
3859 else if (sp
->pp_phase
>= PHASE_AUTHENTICATE
) {
3860 long nmagic
= htonl (sp
->lcp
.magic
);
3861 sp
->lcp
.echoid
= ++sp
->pp_seq
;
3862 sppp_cp_send (sp
, PPP_LCP
, ECHO_REQ
,
3863 sp
->lcp
.echoid
, 4, &nmagic
);
3867 TIMEOUT(sppp_keepalive
, 0, hz
* 10, keepalive_ch
);
3871 * Get both IP addresses.
3874 sppp_get_ip_addrs(struct sppp
*sp
, u_long
*src
, u_long
*dst
, u_long
*srcmask
)
3876 struct ifnet
*ifp
= &sp
->pp_if
;
3878 struct sockaddr_in
*si
, *sm
;
3884 * Pick the first AF_INET address from the list,
3885 * aliases don't make any sense on a p2p link anyway.
3888 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
3889 TAILQ_FOREACH(ifa
, &ifp
->if_addrhead
, ifa_link
)
3890 #elif defined(__NetBSD__) || defined (__OpenBSD__)
3891 for (ifa
= ifp
->if_addrlist
.tqh_first
;
3893 ifa
= ifa
->ifa_list
.tqe_next
)
3895 for (ifa
= ifp
->if_addrlist
;
3897 ifa
= ifa
->ifa_next
)
3899 if (ifa
->ifa_addr
->sa_family
== AF_INET
) {
3900 si
= (struct sockaddr_in
*)ifa
->ifa_addr
;
3901 sm
= (struct sockaddr_in
*)ifa
->ifa_netmask
;
3906 if (si
&& si
->sin_addr
.s_addr
) {
3907 ssrc
= si
->sin_addr
.s_addr
;
3909 *srcmask
= ntohl(sm
->sin_addr
.s_addr
);
3912 si
= (struct sockaddr_in
*)ifa
->ifa_dstaddr
;
3913 if (si
&& si
->sin_addr
.s_addr
)
3914 ddst
= si
->sin_addr
.s_addr
;
3917 if (dst
) *dst
= ntohl(ddst
);
3918 if (src
) *src
= ntohl(ssrc
);
3922 * Set my IP address. Must be called at splimp.
3925 sppp_set_ip_addr(struct sppp
*sp
, u_long src
)
3929 struct sockaddr_in
*si
;
3932 * Pick the first AF_INET address from the list,
3933 * aliases don't make any sense on a p2p link anyway.
3936 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
3937 TAILQ_FOREACH(ifa
, &ifp
->if_addrhead
, ifa_link
)
3938 #elif defined(__NetBSD__) || defined (__OpenBSD__)
3939 for (ifa
= ifp
->if_addrlist
.tqh_first
;
3941 ifa
= ifa
->ifa_list
.tqe_next
)
3943 for (ifa
= ifp
->if_addrlist
;
3945 ifa
= ifa
->ifa_next
)
3948 if (ifa
->ifa_addr
->sa_family
== AF_INET
)
3950 si
= (struct sockaddr_in
*)ifa
->ifa_addr
;
3959 #if __NetBSD_Version__ >= 103080000
3960 struct sockaddr_in new_sin
= *si
;
3962 new_sin
.sin_addr
.s_addr
= htonl(src
);
3963 error
= in_ifinit(ifp
, ifatoia(ifa
), &new_sin
, 1);
3966 log(LOG_DEBUG
, SPP_FMT
"sppp_set_ip_addr: in_ifinit "
3967 " failed, error=%d\n", SPP_ARGS(ifp
), error
);
3970 /* delete old route */
3971 error
= rtinit(ifa
, (int)RTM_DELETE
, RTF_HOST
);
3974 log(LOG_DEBUG
, SPP_FMT
"sppp_set_ip_addr: rtinit DEL failed, error=%d\n",
3975 SPP_ARGS(ifp
), error
);
3978 /* set new address */
3979 si
->sin_addr
.s_addr
= htonl(src
);
3982 error
= rtinit(ifa
, (int)RTM_ADD
, RTF_HOST
);
3985 log(LOG_DEBUG
, SPP_FMT
"sppp_set_ip_addr: rtinit ADD failed, error=%d",
3986 SPP_ARGS(ifp
), error
);
3993 sppp_params(struct sppp
*sp
, u_long cmd
, void *data
)
3996 struct ifreq
*ifr
= (struct ifreq
*)data
;
4000 * ifr->ifr_data is supposed to point to a struct spppreq.
4001 * Check the cmd word first before attempting to fetch all the
4004 if ((subcmd
= fuword(ifr
->ifr_data
)) == -1)
4007 if (copyin((caddr_t
)ifr
->ifr_data
, &spr
, sizeof spr
) != 0)
4012 if (cmd
!= SIOCGIFGENERIC
)
4015 * We copy over the entire current state, but clean
4016 * out some of the stuff we don't wanna pass up.
4017 * Remember, SIOCGIFGENERIC is unprotected, and can be
4018 * called by any user. No need to ever get PAP or
4019 * CHAP secrets back to userland anyway.
4021 bcopy(sp
, &spr
.defs
, sizeof(struct sppp
));
4022 bzero(spr
.defs
.myauth
.secret
, AUTHKEYLEN
);
4023 bzero(spr
.defs
.myauth
.challenge
, AUTHKEYLEN
);
4024 bzero(spr
.defs
.hisauth
.secret
, AUTHKEYLEN
);
4025 bzero(spr
.defs
.hisauth
.challenge
, AUTHKEYLEN
);
4026 return copyout(&spr
, (caddr_t
)ifr
->ifr_data
, sizeof spr
);
4029 if (cmd
!= SIOCSIFGENERIC
)
4032 * We have a very specific idea of which fields we allow
4033 * being passed back from userland, so to not clobber our
4034 * current state. For one, we only allow setting
4035 * anything if LCP is in dead phase. Once the LCP
4036 * negotiations started, the authentication settings must
4037 * not be changed again. (The administrator can force an
4038 * ifconfig down in order to get LCP back into dead
4041 * Also, we only allow for authentication parameters to be
4044 * XXX Should allow to set or clear pp_flags.
4046 * Finally, if the respective authentication protocol to
4047 * be used is set differently than 0, but the secret is
4048 * passed as all zeros, we don't trash the existing secret.
4049 * This allows an administrator to change the system name
4050 * only without clobbering the secret (which he didn't get
4051 * back in a previous SPPPIOGDEFS call). However, the
4052 * secrets are cleared if the authentication protocol is
4055 if (sp
->pp_phase
!= PHASE_DEAD
)
4058 if ((spr
.defs
.myauth
.proto
!= 0 && spr
.defs
.myauth
.proto
!= PPP_PAP
&&
4059 spr
.defs
.myauth
.proto
!= PPP_CHAP
) ||
4060 (spr
.defs
.hisauth
.proto
!= 0 && spr
.defs
.hisauth
.proto
!= PPP_PAP
&&
4061 spr
.defs
.hisauth
.proto
!= PPP_CHAP
))
4064 if (spr
.defs
.myauth
.proto
== 0)
4065 /* resetting myauth */
4066 bzero(&sp
->myauth
, sizeof sp
->myauth
);
4068 /* setting/changing myauth */
4069 sp
->myauth
.proto
= spr
.defs
.myauth
.proto
;
4070 bcopy(spr
.defs
.myauth
.name
, sp
->myauth
.name
, AUTHNAMELEN
);
4071 if (spr
.defs
.myauth
.secret
[0] != '\0')
4072 bcopy(spr
.defs
.myauth
.secret
, sp
->myauth
.secret
,
4075 if (spr
.defs
.hisauth
.proto
== 0)
4076 /* resetting hisauth */
4077 bzero(&sp
->hisauth
, sizeof sp
->hisauth
);
4079 /* setting/changing hisauth */
4080 sp
->hisauth
.proto
= spr
.defs
.hisauth
.proto
;
4081 sp
->hisauth
.flags
= spr
.defs
.hisauth
.flags
;
4082 bcopy(spr
.defs
.hisauth
.name
, sp
->hisauth
.name
, AUTHNAMELEN
);
4083 if (spr
.defs
.hisauth
.secret
[0] != '\0')
4084 bcopy(spr
.defs
.hisauth
.secret
, sp
->hisauth
.secret
,
4097 sppp_phase_network(struct sppp
*sp
)
4103 sp
->pp_phase
= PHASE_NETWORK
;
4106 log(LOG_DEBUG
, SPP_FMT
"phase %s\n", SPP_ARGS(ifp
),
4107 sppp_phase_name(sp
->pp_phase
));
4109 /* Notify NCPs now. */
4110 for (i
= 0; i
< IDX_COUNT
; i
++)
4111 if ((cps
[i
])->flags
& CP_NCP
)
4114 /* Send Up events to all NCPs. */
4115 for (i
= 0, mask
= 1; i
< IDX_COUNT
; i
++, mask
<<= 1)
4116 if (sp
->lcp
.protos
& mask
&& ((cps
[i
])->flags
& CP_NCP
))
4119 /* if no NCP is starting, all this was in vain, close down */
4120 sppp_lcp_check_and_close(sp
);
4125 sppp_cp_type_name(u_char type
)
4127 static char buf
[12];
4129 case CONF_REQ
: return "conf-req";
4130 case CONF_ACK
: return "conf-ack";
4131 case CONF_NAK
: return "conf-nak";
4132 case CONF_REJ
: return "conf-rej";
4133 case TERM_REQ
: return "term-req";
4134 case TERM_ACK
: return "term-ack";
4135 case CODE_REJ
: return "code-rej";
4136 case PROTO_REJ
: return "proto-rej";
4137 case ECHO_REQ
: return "echo-req";
4138 case ECHO_REPLY
: return "echo-reply";
4139 case DISC_REQ
: return "discard-req";
4141 snprintf (buf
, sizeof(buf
), "0x%x", type
);
4146 sppp_auth_type_name(u_short proto
, u_char type
)
4148 static char buf
[12];
4152 case CHAP_CHALLENGE
: return "challenge";
4153 case CHAP_RESPONSE
: return "response";
4154 case CHAP_SUCCESS
: return "success";
4155 case CHAP_FAILURE
: return "failure";
4159 case PAP_REQ
: return "req";
4160 case PAP_ACK
: return "ack";
4161 case PAP_NAK
: return "nak";
4164 snprintf (buf
, sizeof(buf
), "0x%x", type
);
4169 sppp_lcp_opt_name(u_char opt
)
4171 static char buf
[12];
4173 case LCP_OPT_MRU
: return "mru";
4174 case LCP_OPT_ASYNC_MAP
: return "async-map";
4175 case LCP_OPT_AUTH_PROTO
: return "auth-proto";
4176 case LCP_OPT_QUAL_PROTO
: return "qual-proto";
4177 case LCP_OPT_MAGIC
: return "magic";
4178 case LCP_OPT_PROTO_COMP
: return "proto-comp";
4179 case LCP_OPT_ADDR_COMP
: return "addr-comp";
4181 snprintf (buf
, sizeof(buf
), "0x%x", opt
);
4186 sppp_ipcp_opt_name(u_char opt
)
4188 static char buf
[12];
4190 case IPCP_OPT_ADDRESSES
: return "addresses";
4191 case IPCP_OPT_COMPRESSION
: return "compression";
4192 case IPCP_OPT_ADDRESS
: return "address";
4194 snprintf (buf
, sizeof(buf
), "0x%x", opt
);
4199 sppp_state_name(int state
)
4202 case STATE_INITIAL
: return "initial";
4203 case STATE_STARTING
: return "starting";
4204 case STATE_CLOSED
: return "closed";
4205 case STATE_STOPPED
: return "stopped";
4206 case STATE_CLOSING
: return "closing";
4207 case STATE_STOPPING
: return "stopping";
4208 case STATE_REQ_SENT
: return "req-sent";
4209 case STATE_ACK_RCVD
: return "ack-rcvd";
4210 case STATE_ACK_SENT
: return "ack-sent";
4211 case STATE_OPENED
: return "opened";
4217 sppp_phase_name(enum ppp_phase phase
)
4220 case PHASE_DEAD
: return "dead";
4221 case PHASE_ESTABLISH
: return "establish";
4222 case PHASE_TERMINATE
: return "terminate";
4223 case PHASE_AUTHENTICATE
: return "authenticate";
4224 case PHASE_NETWORK
: return "network";
4230 sppp_proto_name(u_short proto
)
4232 static char buf
[12];
4234 case PPP_LCP
: return "lcp";
4235 case PPP_IPCP
: return "ipcp";
4236 case PPP_PAP
: return "pap";
4237 case PPP_CHAP
: return "chap";
4239 snprintf(buf
, sizeof(buf
), "0x%x", (unsigned)proto
);
4244 sppp_print_bytes(const u_char
*p
, u_short len
)
4246 addlog(" %02x", *p
++);
4248 addlog("-%02x", *p
++);
4252 sppp_print_string(const char *p
, u_short len
)
4259 * Print only ASCII chars directly. RFC 1994 recommends
4260 * using only them, but we don't rely on it. */
4261 if (c
< ' ' || c
> '~')
4269 sppp_dotted_quad(u_long addr
)
4272 sprintf(s
, "%d.%d.%d.%d",
4273 (int)((addr
>> 24) & 0xff),
4274 (int)((addr
>> 16) & 0xff),
4275 (int)((addr
>> 8) & 0xff),
4276 (int)(addr
& 0xff));
4281 sppp_strnlen(u_char
*p
, int max
)
4285 for (len
= 0; len
< max
&& *p
; ++p
)
4290 /* a dummy, used to drop uninteresting events */
4292 sppp_null(struct sppp
*unused
)
4294 /* do just nothing */