| @@ -1,1991 +1,1988 @@ | | | @@ -1,1991 +1,1988 @@ |
1 | /* $NetBSD: if_spppsubr.c,v 1.186 2020/02/04 05:46:32 thorpej Exp $ */ | | 1 | /* $NetBSD: if_spppsubr.c,v 1.187 2020/03/06 10:26:59 knakahara Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Synchronous PPP/Cisco link level subroutines. | | 4 | * Synchronous PPP/Cisco link level subroutines. |
5 | * Keepalive protocol implemented in both Cisco and PPP modes. | | 5 | * Keepalive protocol implemented in both Cisco and PPP modes. |
6 | * | | 6 | * |
7 | * Copyright (C) 1994-1996 Cronyx Engineering Ltd. | | 7 | * Copyright (C) 1994-1996 Cronyx Engineering Ltd. |
8 | * Author: Serge Vakulenko, <vak@cronyx.ru> | | 8 | * Author: Serge Vakulenko, <vak@cronyx.ru> |
9 | * | | 9 | * |
10 | * Heavily revamped to conform to RFC 1661. | | 10 | * Heavily revamped to conform to RFC 1661. |
11 | * Copyright (C) 1997, Joerg Wunsch. | | 11 | * Copyright (C) 1997, Joerg Wunsch. |
12 | * | | 12 | * |
13 | * RFC2472 IPv6CP support. | | 13 | * RFC2472 IPv6CP support. |
14 | * Copyright (C) 2000, Jun-ichiro itojun Hagino <itojun@iijlab.net>. | | 14 | * Copyright (C) 2000, Jun-ichiro itojun Hagino <itojun@iijlab.net>. |
15 | * | | 15 | * |
16 | * Redistribution and use in source and binary forms, with or without | | 16 | * Redistribution and use in source and binary forms, with or without |
17 | * modification, are permitted provided that the following conditions are met: | | 17 | * modification, are permitted provided that the following conditions are met: |
18 | * 1. Redistributions of source code must retain the above copyright notice, | | 18 | * 1. Redistributions of source code must retain the above copyright notice, |
19 | * this list of conditions and the following disclaimer. | | 19 | * this list of conditions and the following disclaimer. |
20 | * 2. Redistributions in binary form must reproduce the above copyright notice, | | 20 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
21 | * this list of conditions and the following disclaimer in the documentation | | 21 | * this list of conditions and the following disclaimer in the documentation |
22 | * and/or other materials provided with the distribution. | | 22 | * and/or other materials provided with the distribution. |
23 | * | | 23 | * |
24 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY | | 24 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY |
25 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 25 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE | | 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE |
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
34 | * POSSIBILITY OF SUCH DAMAGE. | | 34 | * POSSIBILITY OF SUCH DAMAGE. |
35 | * | | 35 | * |
36 | * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997 | | 36 | * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997 |
37 | * | | 37 | * |
38 | * From: if_spppsubr.c,v 1.39 1998/04/04 13:26:03 phk Exp | | 38 | * From: if_spppsubr.c,v 1.39 1998/04/04 13:26:03 phk Exp |
39 | * | | 39 | * |
40 | * From: Id: if_spppsubr.c,v 1.23 1999/02/23 14:47:50 hm Exp | | 40 | * From: Id: if_spppsubr.c,v 1.23 1999/02/23 14:47:50 hm Exp |
41 | */ | | 41 | */ |
42 | | | 42 | |
43 | #include <sys/cdefs.h> | | 43 | #include <sys/cdefs.h> |
44 | __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.186 2020/02/04 05:46:32 thorpej Exp $"); | | 44 | __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.187 2020/03/06 10:26:59 knakahara Exp $"); |
45 | | | 45 | |
46 | #if defined(_KERNEL_OPT) | | 46 | #if defined(_KERNEL_OPT) |
47 | #include "opt_inet.h" | | 47 | #include "opt_inet.h" |
48 | #include "opt_modular.h" | | 48 | #include "opt_modular.h" |
49 | #include "opt_compat_netbsd.h" | | 49 | #include "opt_compat_netbsd.h" |
50 | #include "opt_net_mpsafe.h" | | 50 | #include "opt_net_mpsafe.h" |
51 | #endif | | 51 | #endif |
52 | | | 52 | |
53 | | | 53 | |
54 | #include <sys/param.h> | | 54 | #include <sys/param.h> |
55 | #include <sys/proc.h> | | 55 | #include <sys/proc.h> |
56 | #include <sys/systm.h> | | 56 | #include <sys/systm.h> |
57 | #include <sys/kernel.h> | | 57 | #include <sys/kernel.h> |
58 | #include <sys/sockio.h> | | 58 | #include <sys/sockio.h> |
59 | #include <sys/socket.h> | | 59 | #include <sys/socket.h> |
60 | #include <sys/syslog.h> | | 60 | #include <sys/syslog.h> |
61 | #include <sys/malloc.h> | | 61 | #include <sys/malloc.h> |
62 | #include <sys/mbuf.h> | | 62 | #include <sys/mbuf.h> |
63 | #include <sys/callout.h> | | 63 | #include <sys/callout.h> |
64 | #include <sys/md5.h> | | 64 | #include <sys/md5.h> |
65 | #include <sys/inttypes.h> | | 65 | #include <sys/inttypes.h> |
66 | #include <sys/kauth.h> | | 66 | #include <sys/kauth.h> |
67 | #include <sys/cprng.h> | | 67 | #include <sys/cprng.h> |
68 | #include <sys/module.h> | | 68 | #include <sys/module.h> |
69 | #include <sys/workqueue.h> | | 69 | #include <sys/workqueue.h> |
70 | #include <sys/atomic.h> | | 70 | #include <sys/atomic.h> |
71 | #include <sys/compat_stub.h> | | 71 | #include <sys/compat_stub.h> |
72 | | | 72 | |
73 | #include <net/if.h> | | 73 | #include <net/if.h> |
74 | #include <net/netisr.h> | | 74 | #include <net/netisr.h> |
75 | #include <net/if_types.h> | | 75 | #include <net/if_types.h> |
76 | #include <net/route.h> | | 76 | #include <net/route.h> |
77 | #include <net/ppp_defs.h> | | 77 | #include <net/ppp_defs.h> |
78 | | | 78 | |
79 | #include <netinet/in.h> | | 79 | #include <netinet/in.h> |
80 | #include <netinet/in_systm.h> | | 80 | #include <netinet/in_systm.h> |
81 | #include <netinet/in_var.h> | | 81 | #include <netinet/in_var.h> |
82 | #ifdef INET | | 82 | #ifdef INET |
83 | #include <netinet/ip.h> | | 83 | #include <netinet/ip.h> |
84 | #include <netinet/tcp.h> | | 84 | #include <netinet/tcp.h> |
85 | #endif | | 85 | #endif |
86 | #include <net/ethertypes.h> | | 86 | #include <net/ethertypes.h> |
87 | | | 87 | |
88 | #ifdef INET6 | | 88 | #ifdef INET6 |
89 | #include <netinet6/scope6_var.h> | | 89 | #include <netinet6/scope6_var.h> |
90 | #endif | | 90 | #endif |
91 | | | 91 | |
92 | #include <net/if_sppp.h> | | 92 | #include <net/if_sppp.h> |
93 | #include <net/if_spppvar.h> | | 93 | #include <net/if_spppvar.h> |
94 | | | 94 | |
95 | #ifdef NET_MPSAFE | | 95 | #ifdef NET_MPSAFE |
96 | #define SPPPSUBR_MPSAFE 1 | | 96 | #define SPPPSUBR_MPSAFE 1 |
97 | #endif | | 97 | #endif |
98 | | | 98 | |
99 | #define LCP_KEEPALIVE_INTERVAL 10 /* seconds between checks */ | | 99 | #define LCP_KEEPALIVE_INTERVAL 10 /* seconds between checks */ |
100 | #define LOOPALIVECNT 3 /* loopback detection tries */ | | 100 | #define LOOPALIVECNT 3 /* loopback detection tries */ |
101 | #define DEFAULT_MAXALIVECNT 3 /* max. missed alive packets */ | | 101 | #define DEFAULT_MAXALIVECNT 3 /* max. missed alive packets */ |
102 | #define DEFAULT_NORECV_TIME 15 /* before we get worried */ | | 102 | #define DEFAULT_NORECV_TIME 15 /* before we get worried */ |
103 | #define DEFAULT_MAX_AUTH_FAILURES 5 /* max. auth. failures */ | | 103 | #define DEFAULT_MAX_AUTH_FAILURES 5 /* max. auth. failures */ |
104 | | | 104 | |
105 | /* | | 105 | /* |
106 | * Interface flags that can be set in an ifconfig command. | | 106 | * Interface flags that can be set in an ifconfig command. |
107 | * | | 107 | * |
108 | * Setting link0 will make the link passive, i.e. it will be marked | | 108 | * Setting link0 will make the link passive, i.e. it will be marked |
109 | * as being administrative openable, but won't be opened to begin | | 109 | * as being administrative openable, but won't be opened to begin |
110 | * with. Incoming calls will be answered, or subsequent calls with | | 110 | * with. Incoming calls will be answered, or subsequent calls with |
111 | * -link1 will cause the administrative open of the LCP layer. | | 111 | * -link1 will cause the administrative open of the LCP layer. |
112 | * | | 112 | * |
113 | * Setting link1 will cause the link to auto-dial only as packets | | 113 | * Setting link1 will cause the link to auto-dial only as packets |
114 | * arrive to be sent. | | 114 | * arrive to be sent. |
115 | * | | 115 | * |
116 | * Setting IFF_DEBUG will syslog the option negotiation and state | | 116 | * Setting IFF_DEBUG will syslog the option negotiation and state |
117 | * transitions at level kern.debug. Note: all logs consistently look | | 117 | * transitions at level kern.debug. Note: all logs consistently look |
118 | * like | | 118 | * like |
119 | * | | 119 | * |
120 | * <if-name><unit>: <proto-name> <additional info...> | | 120 | * <if-name><unit>: <proto-name> <additional info...> |
121 | * | | 121 | * |
122 | * with <if-name><unit> being something like "bppp0", and <proto-name> | | 122 | * with <if-name><unit> being something like "bppp0", and <proto-name> |
123 | * being one of "lcp", "ipcp", "cisco", "chap", "pap", etc. | | 123 | * being one of "lcp", "ipcp", "cisco", "chap", "pap", etc. |
124 | */ | | 124 | */ |
125 | | | 125 | |
126 | #define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */ | | 126 | #define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */ |
127 | #define IFF_AUTO IFF_LINK1 /* auto-dial on output */ | | 127 | #define IFF_AUTO IFF_LINK1 /* auto-dial on output */ |
128 | | | 128 | |
129 | #define CONF_REQ 1 /* PPP configure request */ | | 129 | #define CONF_REQ 1 /* PPP configure request */ |
130 | #define CONF_ACK 2 /* PPP configure acknowledge */ | | 130 | #define CONF_ACK 2 /* PPP configure acknowledge */ |
131 | #define CONF_NAK 3 /* PPP configure negative ack */ | | 131 | #define CONF_NAK 3 /* PPP configure negative ack */ |
132 | #define CONF_REJ 4 /* PPP configure reject */ | | 132 | #define CONF_REJ 4 /* PPP configure reject */ |
133 | #define TERM_REQ 5 /* PPP terminate request */ | | 133 | #define TERM_REQ 5 /* PPP terminate request */ |
134 | #define TERM_ACK 6 /* PPP terminate acknowledge */ | | 134 | #define TERM_ACK 6 /* PPP terminate acknowledge */ |
135 | #define CODE_REJ 7 /* PPP code reject */ | | 135 | #define CODE_REJ 7 /* PPP code reject */ |
136 | #define PROTO_REJ 8 /* PPP protocol reject */ | | 136 | #define PROTO_REJ 8 /* PPP protocol reject */ |
137 | #define ECHO_REQ 9 /* PPP echo request */ | | 137 | #define ECHO_REQ 9 /* PPP echo request */ |
138 | #define ECHO_REPLY 10 /* PPP echo reply */ | | 138 | #define ECHO_REPLY 10 /* PPP echo reply */ |
139 | #define DISC_REQ 11 /* PPP discard request */ | | 139 | #define DISC_REQ 11 /* PPP discard request */ |
140 | | | 140 | |
141 | #define LCP_OPT_MRU 1 /* maximum receive unit */ | | 141 | #define LCP_OPT_MRU 1 /* maximum receive unit */ |
142 | #define LCP_OPT_ASYNC_MAP 2 /* async control character map */ | | 142 | #define LCP_OPT_ASYNC_MAP 2 /* async control character map */ |
143 | #define LCP_OPT_AUTH_PROTO 3 /* authentication protocol */ | | 143 | #define LCP_OPT_AUTH_PROTO 3 /* authentication protocol */ |
144 | #define LCP_OPT_QUAL_PROTO 4 /* quality protocol */ | | 144 | #define LCP_OPT_QUAL_PROTO 4 /* quality protocol */ |
145 | #define LCP_OPT_MAGIC 5 /* magic number */ | | 145 | #define LCP_OPT_MAGIC 5 /* magic number */ |
146 | #define LCP_OPT_RESERVED 6 /* reserved */ | | 146 | #define LCP_OPT_RESERVED 6 /* reserved */ |
147 | #define LCP_OPT_PROTO_COMP 7 /* protocol field compression */ | | 147 | #define LCP_OPT_PROTO_COMP 7 /* protocol field compression */ |
148 | #define LCP_OPT_ADDR_COMP 8 /* address/control field compression */ | | 148 | #define LCP_OPT_ADDR_COMP 8 /* address/control field compression */ |
149 | | | 149 | |
150 | #define IPCP_OPT_ADDRESSES 1 /* both IP addresses; deprecated */ | | 150 | #define IPCP_OPT_ADDRESSES 1 /* both IP addresses; deprecated */ |
151 | #define IPCP_OPT_COMPRESSION 2 /* IP compression protocol */ | | 151 | #define IPCP_OPT_COMPRESSION 2 /* IP compression protocol */ |
152 | #define IPCP_OPT_ADDRESS 3 /* local IP address */ | | 152 | #define IPCP_OPT_ADDRESS 3 /* local IP address */ |
153 | #define IPCP_OPT_PRIMDNS 129 /* primary remote dns address */ | | 153 | #define IPCP_OPT_PRIMDNS 129 /* primary remote dns address */ |
154 | #define IPCP_OPT_SECDNS 131 /* secondary remote dns address */ | | 154 | #define IPCP_OPT_SECDNS 131 /* secondary remote dns address */ |
155 | | | 155 | |
156 | #define IPCP_UPDATE_LIMIT 8 /* limit of pending IP updating job */ | | 156 | #define IPCP_UPDATE_LIMIT 8 /* limit of pending IP updating job */ |
157 | #define IPCP_SET_ADDRS 1 /* marker for IP address setting job */ | | 157 | #define IPCP_SET_ADDRS 1 /* marker for IP address setting job */ |
158 | #define IPCP_CLEAR_ADDRS 2 /* marker for IP address clearing job */ | | 158 | #define IPCP_CLEAR_ADDRS 2 /* marker for IP address clearing job */ |
159 | | | 159 | |
160 | #define IPV6CP_OPT_IFID 1 /* interface identifier */ | | 160 | #define IPV6CP_OPT_IFID 1 /* interface identifier */ |
161 | #define IPV6CP_OPT_COMPRESSION 2 /* IPv6 compression protocol */ | | 161 | #define IPV6CP_OPT_COMPRESSION 2 /* IPv6 compression protocol */ |
162 | | | 162 | |
163 | #define PAP_REQ 1 /* PAP name/password request */ | | 163 | #define PAP_REQ 1 /* PAP name/password request */ |
164 | #define PAP_ACK 2 /* PAP acknowledge */ | | 164 | #define PAP_ACK 2 /* PAP acknowledge */ |
165 | #define PAP_NAK 3 /* PAP fail */ | | 165 | #define PAP_NAK 3 /* PAP fail */ |
166 | | | 166 | |
167 | #define CHAP_CHALLENGE 1 /* CHAP challenge request */ | | 167 | #define CHAP_CHALLENGE 1 /* CHAP challenge request */ |
168 | #define CHAP_RESPONSE 2 /* CHAP challenge response */ | | 168 | #define CHAP_RESPONSE 2 /* CHAP challenge response */ |
169 | #define CHAP_SUCCESS 3 /* CHAP response ok */ | | 169 | #define CHAP_SUCCESS 3 /* CHAP response ok */ |
170 | #define CHAP_FAILURE 4 /* CHAP response failed */ | | 170 | #define CHAP_FAILURE 4 /* CHAP response failed */ |
171 | | | 171 | |
172 | #define CHAP_MD5 5 /* hash algorithm - MD5 */ | | 172 | #define CHAP_MD5 5 /* hash algorithm - MD5 */ |
173 | | | 173 | |
174 | #define CISCO_MULTICAST 0x8f /* Cisco multicast address */ | | 174 | #define CISCO_MULTICAST 0x8f /* Cisco multicast address */ |
175 | #define CISCO_UNICAST 0x0f /* Cisco unicast address */ | | 175 | #define CISCO_UNICAST 0x0f /* Cisco unicast address */ |
176 | #define CISCO_KEEPALIVE 0x8035 /* Cisco keepalive protocol */ | | 176 | #define CISCO_KEEPALIVE 0x8035 /* Cisco keepalive protocol */ |
177 | #define CISCO_ADDR_REQ 0 /* Cisco address request */ | | 177 | #define CISCO_ADDR_REQ 0 /* Cisco address request */ |
178 | #define CISCO_ADDR_REPLY 1 /* Cisco address reply */ | | 178 | #define CISCO_ADDR_REPLY 1 /* Cisco address reply */ |
179 | #define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */ | | 179 | #define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */ |
180 | | | 180 | |
181 | /* states are named and numbered according to RFC 1661 */ | | 181 | /* states are named and numbered according to RFC 1661 */ |
182 | #define STATE_INITIAL 0 | | 182 | #define STATE_INITIAL 0 |
183 | #define STATE_STARTING 1 | | 183 | #define STATE_STARTING 1 |
184 | #define STATE_CLOSED 2 | | 184 | #define STATE_CLOSED 2 |
185 | #define STATE_STOPPED 3 | | 185 | #define STATE_STOPPED 3 |
186 | #define STATE_CLOSING 4 | | 186 | #define STATE_CLOSING 4 |
187 | #define STATE_STOPPING 5 | | 187 | #define STATE_STOPPING 5 |
188 | #define STATE_REQ_SENT 6 | | 188 | #define STATE_REQ_SENT 6 |
189 | #define STATE_ACK_RCVD 7 | | 189 | #define STATE_ACK_RCVD 7 |
190 | #define STATE_ACK_SENT 8 | | 190 | #define STATE_ACK_SENT 8 |
191 | #define STATE_OPENED 9 | | 191 | #define STATE_OPENED 9 |
192 | | | 192 | |
193 | struct ppp_header { | | 193 | struct ppp_header { |
194 | uint8_t address; | | 194 | uint8_t address; |
195 | uint8_t control; | | 195 | uint8_t control; |
196 | uint16_t protocol; | | 196 | uint16_t protocol; |
197 | } __packed; | | 197 | } __packed; |
198 | #define PPP_HEADER_LEN sizeof (struct ppp_header) | | 198 | #define PPP_HEADER_LEN sizeof (struct ppp_header) |
199 | | | 199 | |
200 | struct lcp_header { | | 200 | struct lcp_header { |
201 | uint8_t type; | | 201 | uint8_t type; |
202 | uint8_t ident; | | 202 | uint8_t ident; |
203 | uint16_t len; | | 203 | uint16_t len; |
204 | } __packed; | | 204 | } __packed; |
205 | #define LCP_HEADER_LEN sizeof (struct lcp_header) | | 205 | #define LCP_HEADER_LEN sizeof (struct lcp_header) |
206 | | | 206 | |
207 | struct cisco_packet { | | 207 | struct cisco_packet { |
208 | uint32_t type; | | 208 | uint32_t type; |
209 | uint32_t par1; | | 209 | uint32_t par1; |
210 | uint32_t par2; | | 210 | uint32_t par2; |
211 | uint16_t rel; | | 211 | uint16_t rel; |
212 | uint16_t time0; | | 212 | uint16_t time0; |
213 | uint16_t time1; | | 213 | uint16_t time1; |
214 | } __packed; | | 214 | } __packed; |
215 | #define CISCO_PACKET_LEN 18 | | 215 | #define CISCO_PACKET_LEN 18 |
216 | | | 216 | |
217 | /* | | 217 | /* |
218 | * We follow the spelling and capitalization of RFC 1661 here, to make | | 218 | * We follow the spelling and capitalization of RFC 1661 here, to make |
219 | * it easier comparing with the standard. Please refer to this RFC in | | 219 | * it easier comparing with the standard. Please refer to this RFC in |
220 | * case you can't make sense out of these abbreviation; it will also | | 220 | * case you can't make sense out of these abbreviation; it will also |
221 | * explain the semantics related to the various events and actions. | | 221 | * explain the semantics related to the various events and actions. |
222 | */ | | 222 | */ |
223 | struct cp { | | 223 | struct cp { |
224 | u_short proto; /* PPP control protocol number */ | | 224 | u_short proto; /* PPP control protocol number */ |
225 | u_char protoidx; /* index into state table in struct sppp */ | | 225 | u_char protoidx; /* index into state table in struct sppp */ |
226 | u_char flags; | | 226 | u_char flags; |
227 | #define CP_LCP 0x01 /* this is the LCP */ | | 227 | #define CP_LCP 0x01 /* this is the LCP */ |
228 | #define CP_AUTH 0x02 /* this is an authentication protocol */ | | 228 | #define CP_AUTH 0x02 /* this is an authentication protocol */ |
229 | #define CP_NCP 0x04 /* this is a NCP */ | | 229 | #define CP_NCP 0x04 /* this is a NCP */ |
230 | #define CP_QUAL 0x08 /* this is a quality reporting protocol */ | | 230 | #define CP_QUAL 0x08 /* this is a quality reporting protocol */ |
231 | const char *name; /* name of this control protocol */ | | 231 | const char *name; /* name of this control protocol */ |
232 | /* event handlers */ | | 232 | /* event handlers */ |
233 | void (*Up)(struct sppp *sp); | | 233 | void (*Up)(struct sppp *sp); |
234 | void (*Down)(struct sppp *sp); | | 234 | void (*Down)(struct sppp *sp); |
235 | void (*Open)(struct sppp *sp); | | 235 | void (*Open)(struct sppp *sp); |
236 | void (*Close)(struct sppp *sp); | | 236 | void (*Close)(struct sppp *sp); |
237 | void (*TO)(void *sp); | | 237 | void (*TO)(void *sp); |
238 | int (*RCR)(struct sppp *sp, struct lcp_header *h, int len); | | 238 | int (*RCR)(struct sppp *sp, struct lcp_header *h, int len); |
239 | void (*RCN_rej)(struct sppp *sp, struct lcp_header *h, int len); | | 239 | void (*RCN_rej)(struct sppp *sp, struct lcp_header *h, int len); |
240 | void (*RCN_nak)(struct sppp *sp, struct lcp_header *h, int len); | | 240 | void (*RCN_nak)(struct sppp *sp, struct lcp_header *h, int len); |
241 | /* actions */ | | 241 | /* actions */ |
242 | void (*tlu)(struct sppp *sp); | | 242 | void (*tlu)(struct sppp *sp); |
243 | void (*tld)(struct sppp *sp); | | 243 | void (*tld)(struct sppp *sp); |
244 | void (*tls)(struct sppp *sp); | | 244 | void (*tls)(struct sppp *sp); |
245 | void (*tlf)(struct sppp *sp); | | 245 | void (*tlf)(struct sppp *sp); |
246 | void (*scr)(struct sppp *sp); | | 246 | void (*scr)(struct sppp *sp); |
247 | }; | | 247 | }; |
248 | | | 248 | |
249 | static struct sppp *spppq; | | 249 | static struct sppp *spppq; |
250 | static kmutex_t *spppq_lock = NULL; | | 250 | static kmutex_t *spppq_lock = NULL; |
251 | static callout_t keepalive_ch; | | 251 | static callout_t keepalive_ch; |
252 | | | 252 | |
253 | #define SPPPQ_LOCK() if (spppq_lock) \ | | 253 | #define SPPPQ_LOCK() if (spppq_lock) \ |
254 | mutex_enter(spppq_lock); | | 254 | mutex_enter(spppq_lock); |
255 | #define SPPPQ_UNLOCK() if (spppq_lock) \ | | 255 | #define SPPPQ_UNLOCK() if (spppq_lock) \ |
256 | mutex_exit(spppq_lock); | | 256 | mutex_exit(spppq_lock); |
257 | | | 257 | |
258 | #define SPPP_LOCK(_sp, _op) rw_enter(&(_sp)->pp_lock, (_op)) | | 258 | #define SPPP_LOCK(_sp, _op) rw_enter(&(_sp)->pp_lock, (_op)) |
259 | #define SPPP_UNLOCK(_sp) rw_exit(&(_sp)->pp_lock) | | 259 | #define SPPP_UNLOCK(_sp) rw_exit(&(_sp)->pp_lock) |
260 | #define SPPP_WLOCKED(_sp) rw_write_held(&(_sp)->pp_lock) | | 260 | #define SPPP_WLOCKED(_sp) rw_write_held(&(_sp)->pp_lock) |
261 | #define SPPP_UPGRADE(_sp) do{ \ | | 261 | #define SPPP_UPGRADE(_sp) do{ \ |
262 | SPPP_UNLOCK(_sp); \ | | 262 | SPPP_UNLOCK(_sp); \ |
263 | SPPP_LOCK(_sp, RW_WRITER); \ | | 263 | SPPP_LOCK(_sp, RW_WRITER); \ |
264 | }while (0) | | 264 | }while (0) |
265 | #define SPPP_DOWNGRADE(_sp) rw_downgrade(&(_sp)->pp_lock) | | 265 | #define SPPP_DOWNGRADE(_sp) rw_downgrade(&(_sp)->pp_lock) |
266 | | | 266 | |
267 | #ifdef INET | | 267 | #ifdef INET |
268 | #ifndef SPPPSUBR_MPSAFE | | 268 | #ifndef SPPPSUBR_MPSAFE |
269 | /* | | 269 | /* |
270 | * The following disgusting hack gets around the problem that IP TOS | | 270 | * The following disgusting hack gets around the problem that IP TOS |
271 | * can't be set yet. We want to put "interactive" traffic on a high | | 271 | * can't be set yet. We want to put "interactive" traffic on a high |
272 | * priority queue. To decide if traffic is interactive, we check that | | 272 | * priority queue. To decide if traffic is interactive, we check that |
273 | * a) it is TCP and b) one of its ports is telnet, rlogin or ftp control. | | 273 | * a) it is TCP and b) one of its ports is telnet, rlogin or ftp control. |
274 | * | | 274 | * |
275 | * XXX is this really still necessary? - joerg - | | 275 | * XXX is this really still necessary? - joerg - |
276 | */ | | 276 | */ |
277 | static u_short interactive_ports[8] = { | | 277 | static u_short interactive_ports[8] = { |
278 | 0, 513, 0, 0, | | 278 | 0, 513, 0, 0, |
279 | 0, 21, 0, 23, | | 279 | 0, 21, 0, 23, |
280 | }; | | 280 | }; |
281 | #define INTERACTIVE(p) (interactive_ports[(p) & 7] == (p)) | | 281 | #define INTERACTIVE(p) (interactive_ports[(p) & 7] == (p)) |
282 | #endif /* SPPPSUBR_MPSAFE */ | | 282 | #endif /* SPPPSUBR_MPSAFE */ |
283 | #endif | | 283 | #endif |
284 | | | 284 | |
285 | /* almost every function needs these */ | | 285 | /* almost every function needs these */ |
286 | #define STDDCL \ | | 286 | #define STDDCL \ |
287 | struct ifnet *ifp = &sp->pp_if; \ | | 287 | struct ifnet *ifp = &sp->pp_if; \ |
288 | int debug = ifp->if_flags & IFF_DEBUG | | 288 | int debug = ifp->if_flags & IFF_DEBUG |
289 | | | 289 | |
290 | static int sppp_output(struct ifnet *ifp, struct mbuf *m, | | 290 | static int sppp_output(struct ifnet *ifp, struct mbuf *m, |
291 | const struct sockaddr *dst, const struct rtentry *rt); | | 291 | const struct sockaddr *dst, const struct rtentry *rt); |
292 | | | 292 | |
293 | static void sppp_cisco_send(struct sppp *sp, int type, int32_t par1, int32_t par2); | | 293 | static void sppp_cisco_send(struct sppp *sp, int type, int32_t par1, int32_t par2); |
294 | static void sppp_cisco_input(struct sppp *sp, struct mbuf *m); | | 294 | static void sppp_cisco_input(struct sppp *sp, struct mbuf *m); |
295 | | | 295 | |
296 | static void sppp_cp_input(const struct cp *cp, struct sppp *sp, | | 296 | static void sppp_cp_input(const struct cp *cp, struct sppp *sp, |
297 | struct mbuf *m); | | 297 | struct mbuf *m); |
298 | static void sppp_cp_send(struct sppp *sp, u_short proto, u_char type, | | 298 | static void sppp_cp_send(struct sppp *sp, u_short proto, u_char type, |
299 | u_char ident, u_short len, void *data); | | 299 | u_char ident, u_short len, void *data); |
300 | /* static void sppp_cp_timeout(void *arg); */ | | 300 | /* static void sppp_cp_timeout(void *arg); */ |
301 | static void sppp_cp_change_state(const struct cp *cp, struct sppp *sp, | | 301 | static void sppp_cp_change_state(const struct cp *cp, struct sppp *sp, |
302 | int newstate); | | 302 | int newstate); |
303 | static void sppp_auth_send(const struct cp *cp, | | 303 | static void sppp_auth_send(const struct cp *cp, |
304 | struct sppp *sp, unsigned int type, unsigned int id, | | 304 | struct sppp *sp, unsigned int type, unsigned int id, |
305 | ...); | | 305 | ...); |
306 | | | 306 | |
307 | static void sppp_up_event(const struct cp *cp, struct sppp *sp); | | 307 | static void sppp_up_event(const struct cp *cp, struct sppp *sp); |
308 | static void sppp_down_event(const struct cp *cp, struct sppp *sp); | | 308 | static void sppp_down_event(const struct cp *cp, struct sppp *sp); |
309 | static void sppp_open_event(const struct cp *cp, struct sppp *sp); | | 309 | static void sppp_open_event(const struct cp *cp, struct sppp *sp); |
310 | static void sppp_close_event(const struct cp *cp, struct sppp *sp); | | 310 | static void sppp_close_event(const struct cp *cp, struct sppp *sp); |
311 | static void sppp_to_event(const struct cp *cp, struct sppp *sp); | | 311 | static void sppp_to_event(const struct cp *cp, struct sppp *sp); |
312 | | | 312 | |
313 | static void sppp_null(struct sppp *sp); | | 313 | static void sppp_null(struct sppp *sp); |
314 | | | 314 | |
315 | static void sppp_lcp_init(struct sppp *sp); | | 315 | static void sppp_lcp_init(struct sppp *sp); |
316 | static void sppp_lcp_up(struct sppp *sp); | | 316 | static void sppp_lcp_up(struct sppp *sp); |
317 | static void sppp_lcp_down(struct sppp *sp); | | 317 | static void sppp_lcp_down(struct sppp *sp); |
318 | static void sppp_lcp_open(struct sppp *sp); | | 318 | static void sppp_lcp_open(struct sppp *sp); |
319 | static void sppp_lcp_close(struct sppp *sp); | | 319 | static void sppp_lcp_close(struct sppp *sp); |
320 | static void sppp_lcp_TO(void *sp); | | 320 | static void sppp_lcp_TO(void *sp); |
321 | static int sppp_lcp_RCR(struct sppp *sp, struct lcp_header *h, int len); | | 321 | static int sppp_lcp_RCR(struct sppp *sp, struct lcp_header *h, int len); |
322 | static void sppp_lcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len); | | 322 | static void sppp_lcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len); |
323 | static void sppp_lcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len); | | 323 | static void sppp_lcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len); |
324 | static void sppp_lcp_tlu(struct sppp *sp); | | 324 | static void sppp_lcp_tlu(struct sppp *sp); |
325 | static void sppp_lcp_tld(struct sppp *sp); | | 325 | static void sppp_lcp_tld(struct sppp *sp); |
326 | static void sppp_lcp_tls(struct sppp *sp); | | 326 | static void sppp_lcp_tls(struct sppp *sp); |
327 | static void sppp_lcp_tlf(struct sppp *sp); | | 327 | static void sppp_lcp_tlf(struct sppp *sp); |
328 | static void sppp_lcp_scr(struct sppp *sp); | | 328 | static void sppp_lcp_scr(struct sppp *sp); |
329 | static void sppp_lcp_check_and_close(struct sppp *sp); | | 329 | static void sppp_lcp_check_and_close(struct sppp *sp); |
330 | static int sppp_ncp_check(struct sppp *sp); | | 330 | static int sppp_ncp_check(struct sppp *sp); |
331 | | | 331 | |
332 | static void sppp_ipcp_init(struct sppp *sp); | | 332 | static void sppp_ipcp_init(struct sppp *sp); |
333 | static void sppp_ipcp_up(struct sppp *sp); | | 333 | static void sppp_ipcp_up(struct sppp *sp); |
334 | static void sppp_ipcp_down(struct sppp *sp); | | 334 | static void sppp_ipcp_down(struct sppp *sp); |
335 | static void sppp_ipcp_open(struct sppp *sp); | | 335 | static void sppp_ipcp_open(struct sppp *sp); |
336 | static void sppp_ipcp_close(struct sppp *sp); | | 336 | static void sppp_ipcp_close(struct sppp *sp); |
337 | static void sppp_ipcp_TO(void *sp); | | 337 | static void sppp_ipcp_TO(void *sp); |
338 | static int sppp_ipcp_RCR(struct sppp *sp, struct lcp_header *h, int len); | | 338 | static int sppp_ipcp_RCR(struct sppp *sp, struct lcp_header *h, int len); |
339 | static void sppp_ipcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len); | | 339 | static void sppp_ipcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len); |
340 | static void sppp_ipcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len); | | 340 | static void sppp_ipcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len); |
341 | static void sppp_ipcp_tlu(struct sppp *sp); | | 341 | static void sppp_ipcp_tlu(struct sppp *sp); |
342 | static void sppp_ipcp_tld(struct sppp *sp); | | 342 | static void sppp_ipcp_tld(struct sppp *sp); |
343 | static void sppp_ipcp_tls(struct sppp *sp); | | 343 | static void sppp_ipcp_tls(struct sppp *sp); |
344 | static void sppp_ipcp_tlf(struct sppp *sp); | | 344 | static void sppp_ipcp_tlf(struct sppp *sp); |
345 | static void sppp_ipcp_scr(struct sppp *sp); | | 345 | static void sppp_ipcp_scr(struct sppp *sp); |
346 | | | 346 | |
347 | static void sppp_ipv6cp_init(struct sppp *sp); | | 347 | static void sppp_ipv6cp_init(struct sppp *sp); |
348 | static void sppp_ipv6cp_up(struct sppp *sp); | | 348 | static void sppp_ipv6cp_up(struct sppp *sp); |
349 | static void sppp_ipv6cp_down(struct sppp *sp); | | 349 | static void sppp_ipv6cp_down(struct sppp *sp); |
350 | static void sppp_ipv6cp_open(struct sppp *sp); | | 350 | static void sppp_ipv6cp_open(struct sppp *sp); |
351 | static void sppp_ipv6cp_close(struct sppp *sp); | | 351 | static void sppp_ipv6cp_close(struct sppp *sp); |
352 | static void sppp_ipv6cp_TO(void *sp); | | 352 | static void sppp_ipv6cp_TO(void *sp); |
353 | static int sppp_ipv6cp_RCR(struct sppp *sp, struct lcp_header *h, int len); | | 353 | static int sppp_ipv6cp_RCR(struct sppp *sp, struct lcp_header *h, int len); |
354 | static void sppp_ipv6cp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len); | | 354 | static void sppp_ipv6cp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len); |
355 | static void sppp_ipv6cp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len); | | 355 | static void sppp_ipv6cp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len); |
356 | static void sppp_ipv6cp_tlu(struct sppp *sp); | | 356 | static void sppp_ipv6cp_tlu(struct sppp *sp); |
357 | static void sppp_ipv6cp_tld(struct sppp *sp); | | 357 | static void sppp_ipv6cp_tld(struct sppp *sp); |
358 | static void sppp_ipv6cp_tls(struct sppp *sp); | | 358 | static void sppp_ipv6cp_tls(struct sppp *sp); |
359 | static void sppp_ipv6cp_tlf(struct sppp *sp); | | 359 | static void sppp_ipv6cp_tlf(struct sppp *sp); |
360 | static void sppp_ipv6cp_scr(struct sppp *sp); | | 360 | static void sppp_ipv6cp_scr(struct sppp *sp); |
361 | | | 361 | |
362 | static void sppp_pap_input(struct sppp *sp, struct mbuf *m); | | 362 | static void sppp_pap_input(struct sppp *sp, struct mbuf *m); |
363 | static void sppp_pap_init(struct sppp *sp); | | 363 | static void sppp_pap_init(struct sppp *sp); |
364 | static void sppp_pap_open(struct sppp *sp); | | 364 | static void sppp_pap_open(struct sppp *sp); |
365 | static void sppp_pap_close(struct sppp *sp); | | 365 | static void sppp_pap_close(struct sppp *sp); |
366 | static void sppp_pap_TO(void *sp); | | 366 | static void sppp_pap_TO(void *sp); |
367 | static void sppp_pap_my_TO(void *sp); | | 367 | static void sppp_pap_my_TO(void *sp); |
368 | static void sppp_pap_tlu(struct sppp *sp); | | 368 | static void sppp_pap_tlu(struct sppp *sp); |
369 | static void sppp_pap_tld(struct sppp *sp); | | 369 | static void sppp_pap_tld(struct sppp *sp); |
370 | static void sppp_pap_scr(struct sppp *sp); | | 370 | static void sppp_pap_scr(struct sppp *sp); |
371 | | | 371 | |
372 | static void sppp_chap_input(struct sppp *sp, struct mbuf *m); | | 372 | static void sppp_chap_input(struct sppp *sp, struct mbuf *m); |
373 | static void sppp_chap_init(struct sppp *sp); | | 373 | static void sppp_chap_init(struct sppp *sp); |
374 | static void sppp_chap_open(struct sppp *sp); | | 374 | static void sppp_chap_open(struct sppp *sp); |
375 | static void sppp_chap_close(struct sppp *sp); | | 375 | static void sppp_chap_close(struct sppp *sp); |
376 | static void sppp_chap_TO(void *sp); | | 376 | static void sppp_chap_TO(void *sp); |
377 | static void sppp_chap_tlu(struct sppp *sp); | | 377 | static void sppp_chap_tlu(struct sppp *sp); |
378 | static void sppp_chap_tld(struct sppp *sp); | | 378 | static void sppp_chap_tld(struct sppp *sp); |
379 | static void sppp_chap_scr(struct sppp *sp); | | 379 | static void sppp_chap_scr(struct sppp *sp); |
380 | | | 380 | |
381 | static const char *sppp_auth_type_name(u_short proto, u_char type); | | 381 | static const char *sppp_auth_type_name(u_short proto, u_char type); |
382 | static const char *sppp_cp_type_name(u_char type); | | 382 | static const char *sppp_cp_type_name(u_char type); |
383 | static const char *sppp_dotted_quad(uint32_t addr); | | 383 | static const char *sppp_dotted_quad(uint32_t addr); |
384 | static const char *sppp_ipcp_opt_name(u_char opt); | | 384 | static const char *sppp_ipcp_opt_name(u_char opt); |
385 | #ifdef INET6 | | 385 | #ifdef INET6 |
386 | static const char *sppp_ipv6cp_opt_name(u_char opt); | | 386 | static const char *sppp_ipv6cp_opt_name(u_char opt); |
387 | #endif | | 387 | #endif |
388 | static const char *sppp_lcp_opt_name(u_char opt); | | 388 | static const char *sppp_lcp_opt_name(u_char opt); |
389 | static const char *sppp_phase_name(int phase); | | 389 | static const char *sppp_phase_name(int phase); |
390 | static const char *sppp_proto_name(u_short proto); | | 390 | static const char *sppp_proto_name(u_short proto); |
391 | static const char *sppp_state_name(int state); | | 391 | static const char *sppp_state_name(int state); |
392 | static int sppp_params(struct sppp *sp, u_long cmd, void *data); | | 392 | static int sppp_params(struct sppp *sp, u_long cmd, void *data); |
393 | #ifdef INET | | 393 | #ifdef INET |
394 | static void sppp_get_ip_addrs(struct sppp *sp, uint32_t *src, uint32_t *dst, | | 394 | static void sppp_get_ip_addrs(struct sppp *sp, uint32_t *src, uint32_t *dst, |
395 | uint32_t *srcmask); | | 395 | uint32_t *srcmask); |
396 | static void sppp_set_ip_addrs_work(struct work *wk, struct sppp *sp); | | 396 | static void sppp_set_ip_addrs_work(struct work *wk, struct sppp *sp); |
397 | static void sppp_set_ip_addrs(struct sppp *sp); | | 397 | static void sppp_set_ip_addrs(struct sppp *sp); |
398 | static void sppp_clear_ip_addrs_work(struct work *wk, struct sppp *sp); | | 398 | static void sppp_clear_ip_addrs_work(struct work *wk, struct sppp *sp); |
399 | static void sppp_clear_ip_addrs(struct sppp *sp); | | 399 | static void sppp_clear_ip_addrs(struct sppp *sp); |
400 | static void sppp_update_ip_addrs_work(struct work *wk, void *arg); | | 400 | static void sppp_update_ip_addrs_work(struct work *wk, void *arg); |
401 | #endif | | 401 | #endif |
402 | static void sppp_keepalive(void *dummy); | | 402 | static void sppp_keepalive(void *dummy); |
403 | static void sppp_phase_network(struct sppp *sp); | | 403 | static void sppp_phase_network(struct sppp *sp); |
404 | static void sppp_print_bytes(const u_char *p, u_short len); | | 404 | static void sppp_print_bytes(const u_char *p, u_short len); |
405 | static void sppp_print_string(const char *p, u_short len); | | 405 | static void sppp_print_string(const char *p, u_short len); |
406 | #ifdef INET6 | | 406 | #ifdef INET6 |
407 | static void sppp_get_ip6_addrs(struct sppp *sp, struct in6_addr *src, | | 407 | static void sppp_get_ip6_addrs(struct sppp *sp, struct in6_addr *src, |
408 | struct in6_addr *dst, struct in6_addr *srcmask); | | 408 | struct in6_addr *dst, struct in6_addr *srcmask); |
409 | #ifdef IPV6CP_MYIFID_DYN | | 409 | #ifdef IPV6CP_MYIFID_DYN |
410 | static void sppp_set_ip6_addr(struct sppp *sp, const struct in6_addr *src); | | 410 | static void sppp_set_ip6_addr(struct sppp *sp, const struct in6_addr *src); |
411 | static void sppp_gen_ip6_addr(struct sppp *sp, const struct in6_addr *src); | | 411 | static void sppp_gen_ip6_addr(struct sppp *sp, const struct in6_addr *src); |
412 | #endif | | 412 | #endif |
413 | static void sppp_suggest_ip6_addr(struct sppp *sp, struct in6_addr *src); | | 413 | static void sppp_suggest_ip6_addr(struct sppp *sp, struct in6_addr *src); |
414 | #endif | | 414 | #endif |
415 | | | 415 | |
416 | static void sppp_notify_up(struct sppp *); | | 416 | static void sppp_notify_up(struct sppp *); |
417 | static void sppp_notify_down(struct sppp *); | | 417 | static void sppp_notify_down(struct sppp *); |
418 | static void sppp_notify_tls_wlocked(struct sppp *); | | 418 | static void sppp_notify_tls_wlocked(struct sppp *); |
419 | static void sppp_notify_tlf_wlocked(struct sppp *); | | 419 | static void sppp_notify_tlf_wlocked(struct sppp *); |
420 | #ifdef INET6 | | 420 | #ifdef INET6 |
421 | static void sppp_notify_con_wlocked(struct sppp *); | | 421 | static void sppp_notify_con_wlocked(struct sppp *); |
422 | #endif | | 422 | #endif |
423 | static void sppp_notify_con(struct sppp *); | | 423 | static void sppp_notify_con(struct sppp *); |
424 | | | 424 | |
425 | static void sppp_notify_chg_wlocked(struct sppp *); | | 425 | static void sppp_notify_chg_wlocked(struct sppp *); |
426 | | | 426 | |
427 | | | 427 | |
428 | /* our control protocol descriptors */ | | 428 | /* our control protocol descriptors */ |
429 | static const struct cp lcp = { | | 429 | static const struct cp lcp = { |
430 | PPP_LCP, IDX_LCP, CP_LCP, "lcp", | | 430 | PPP_LCP, IDX_LCP, CP_LCP, "lcp", |
431 | sppp_lcp_up, sppp_lcp_down, sppp_lcp_open, sppp_lcp_close, | | 431 | sppp_lcp_up, sppp_lcp_down, sppp_lcp_open, sppp_lcp_close, |
432 | sppp_lcp_TO, sppp_lcp_RCR, sppp_lcp_RCN_rej, sppp_lcp_RCN_nak, | | 432 | sppp_lcp_TO, sppp_lcp_RCR, sppp_lcp_RCN_rej, sppp_lcp_RCN_nak, |
433 | sppp_lcp_tlu, sppp_lcp_tld, sppp_lcp_tls, sppp_lcp_tlf, | | 433 | sppp_lcp_tlu, sppp_lcp_tld, sppp_lcp_tls, sppp_lcp_tlf, |
434 | sppp_lcp_scr | | 434 | sppp_lcp_scr |
435 | }; | | 435 | }; |
436 | | | 436 | |
437 | static const struct cp ipcp = { | | 437 | static const struct cp ipcp = { |
438 | PPP_IPCP, IDX_IPCP, | | 438 | PPP_IPCP, IDX_IPCP, |
439 | #ifdef INET | | 439 | #ifdef INET |
440 | CP_NCP, /*don't run IPCP if there's no IPv4 support*/ | | 440 | CP_NCP, /*don't run IPCP if there's no IPv4 support*/ |
441 | #else | | 441 | #else |
442 | 0, | | 442 | 0, |
443 | #endif | | 443 | #endif |
444 | "ipcp", | | 444 | "ipcp", |
445 | sppp_ipcp_up, sppp_ipcp_down, sppp_ipcp_open, sppp_ipcp_close, | | 445 | sppp_ipcp_up, sppp_ipcp_down, sppp_ipcp_open, sppp_ipcp_close, |
446 | sppp_ipcp_TO, sppp_ipcp_RCR, sppp_ipcp_RCN_rej, sppp_ipcp_RCN_nak, | | 446 | sppp_ipcp_TO, sppp_ipcp_RCR, sppp_ipcp_RCN_rej, sppp_ipcp_RCN_nak, |
447 | sppp_ipcp_tlu, sppp_ipcp_tld, sppp_ipcp_tls, sppp_ipcp_tlf, | | 447 | sppp_ipcp_tlu, sppp_ipcp_tld, sppp_ipcp_tls, sppp_ipcp_tlf, |
448 | sppp_ipcp_scr | | 448 | sppp_ipcp_scr |
449 | }; | | 449 | }; |
450 | | | 450 | |
451 | static const struct cp ipv6cp = { | | 451 | static const struct cp ipv6cp = { |
452 | PPP_IPV6CP, IDX_IPV6CP, | | 452 | PPP_IPV6CP, IDX_IPV6CP, |
453 | #ifdef INET6 /*don't run IPv6CP if there's no IPv6 support*/ | | 453 | #ifdef INET6 /*don't run IPv6CP if there's no IPv6 support*/ |
454 | CP_NCP, | | 454 | CP_NCP, |
455 | #else | | 455 | #else |
456 | 0, | | 456 | 0, |
457 | #endif | | 457 | #endif |
458 | "ipv6cp", | | 458 | "ipv6cp", |
459 | sppp_ipv6cp_up, sppp_ipv6cp_down, sppp_ipv6cp_open, sppp_ipv6cp_close, | | 459 | sppp_ipv6cp_up, sppp_ipv6cp_down, sppp_ipv6cp_open, sppp_ipv6cp_close, |
460 | sppp_ipv6cp_TO, sppp_ipv6cp_RCR, sppp_ipv6cp_RCN_rej, sppp_ipv6cp_RCN_nak, | | 460 | sppp_ipv6cp_TO, sppp_ipv6cp_RCR, sppp_ipv6cp_RCN_rej, sppp_ipv6cp_RCN_nak, |
461 | sppp_ipv6cp_tlu, sppp_ipv6cp_tld, sppp_ipv6cp_tls, sppp_ipv6cp_tlf, | | 461 | sppp_ipv6cp_tlu, sppp_ipv6cp_tld, sppp_ipv6cp_tls, sppp_ipv6cp_tlf, |
462 | sppp_ipv6cp_scr | | 462 | sppp_ipv6cp_scr |
463 | }; | | 463 | }; |
464 | | | 464 | |
465 | static const struct cp pap = { | | 465 | static const struct cp pap = { |
466 | PPP_PAP, IDX_PAP, CP_AUTH, "pap", | | 466 | PPP_PAP, IDX_PAP, CP_AUTH, "pap", |
467 | sppp_null, sppp_null, sppp_pap_open, sppp_pap_close, | | 467 | sppp_null, sppp_null, sppp_pap_open, sppp_pap_close, |
468 | sppp_pap_TO, 0, 0, 0, | | 468 | sppp_pap_TO, 0, 0, 0, |
469 | sppp_pap_tlu, sppp_pap_tld, sppp_null, sppp_null, | | 469 | sppp_pap_tlu, sppp_pap_tld, sppp_null, sppp_null, |
470 | sppp_pap_scr | | 470 | sppp_pap_scr |
471 | }; | | 471 | }; |
472 | | | 472 | |
473 | static const struct cp chap = { | | 473 | static const struct cp chap = { |
474 | PPP_CHAP, IDX_CHAP, CP_AUTH, "chap", | | 474 | PPP_CHAP, IDX_CHAP, CP_AUTH, "chap", |
475 | sppp_null, sppp_null, sppp_chap_open, sppp_chap_close, | | 475 | sppp_null, sppp_null, sppp_chap_open, sppp_chap_close, |
476 | sppp_chap_TO, 0, 0, 0, | | 476 | sppp_chap_TO, 0, 0, 0, |
477 | sppp_chap_tlu, sppp_chap_tld, sppp_null, sppp_null, | | 477 | sppp_chap_tlu, sppp_chap_tld, sppp_null, sppp_null, |
478 | sppp_chap_scr | | 478 | sppp_chap_scr |
479 | }; | | 479 | }; |
480 | | | 480 | |
481 | static const struct cp *cps[IDX_COUNT] = { | | 481 | static const struct cp *cps[IDX_COUNT] = { |
482 | &lcp, /* IDX_LCP */ | | 482 | &lcp, /* IDX_LCP */ |
483 | &ipcp, /* IDX_IPCP */ | | 483 | &ipcp, /* IDX_IPCP */ |
484 | &ipv6cp, /* IDX_IPV6CP */ | | 484 | &ipv6cp, /* IDX_IPV6CP */ |
485 | &pap, /* IDX_PAP */ | | 485 | &pap, /* IDX_PAP */ |
486 | &chap, /* IDX_CHAP */ | | 486 | &chap, /* IDX_CHAP */ |
487 | }; | | 487 | }; |
488 | | | 488 | |
489 | static void | | 489 | static void |
490 | sppp_change_phase(struct sppp *sp, int phase) | | 490 | sppp_change_phase(struct sppp *sp, int phase) |
491 | { | | 491 | { |
492 | STDDCL; | | 492 | STDDCL; |
493 | | | 493 | |
494 | KASSERT(SPPP_WLOCKED(sp)); | | 494 | KASSERT(SPPP_WLOCKED(sp)); |
495 | | | 495 | |
496 | if (sp->pp_phase == phase) | | 496 | if (sp->pp_phase == phase) |
497 | return; | | 497 | return; |
498 | | | 498 | |
499 | sp->pp_phase = phase; | | 499 | sp->pp_phase = phase; |
500 | | | 500 | |
501 | if (phase == SPPP_PHASE_NETWORK) | | 501 | if (phase == SPPP_PHASE_NETWORK) |
502 | if_link_state_change(ifp, LINK_STATE_UP); | | 502 | if_link_state_change(ifp, LINK_STATE_UP); |
503 | else | | 503 | else |
504 | if_link_state_change(ifp, LINK_STATE_DOWN); | | 504 | if_link_state_change(ifp, LINK_STATE_DOWN); |
505 | | | 505 | |
506 | if (debug) | | 506 | if (debug) |
507 | { | | 507 | { |
508 | log(LOG_INFO, "%s: phase %s\n", ifp->if_xname, | | 508 | log(LOG_INFO, "%s: phase %s\n", ifp->if_xname, |
509 | sppp_phase_name(sp->pp_phase)); | | 509 | sppp_phase_name(sp->pp_phase)); |
510 | } | | 510 | } |
511 | } | | 511 | } |
512 | | | 512 | |
513 | /* | | 513 | /* |
514 | * Exported functions, comprising our interface to the lower layer. | | 514 | * Exported functions, comprising our interface to the lower layer. |
515 | */ | | 515 | */ |
516 | | | 516 | |
517 | /* | | 517 | /* |
518 | * Process the received packet. | | 518 | * Process the received packet. |
519 | */ | | 519 | */ |
520 | void | | 520 | void |
521 | sppp_input(struct ifnet *ifp, struct mbuf *m) | | 521 | sppp_input(struct ifnet *ifp, struct mbuf *m) |
522 | { | | 522 | { |
523 | struct ppp_header *h = NULL; | | 523 | struct ppp_header *h = NULL; |
524 | pktqueue_t *pktq = NULL; | | 524 | pktqueue_t *pktq = NULL; |
525 | struct ifqueue *inq = NULL; | | 525 | struct ifqueue *inq = NULL; |
526 | uint16_t protocol; | | 526 | uint16_t protocol; |
527 | struct sppp *sp = (struct sppp *)ifp; | | 527 | struct sppp *sp = (struct sppp *)ifp; |
528 | int debug = ifp->if_flags & IFF_DEBUG; | | 528 | int debug = ifp->if_flags & IFF_DEBUG; |
529 | int isr = 0; | | 529 | int isr = 0; |
530 | | | 530 | |
531 | SPPP_LOCK(sp, RW_READER); | | 531 | SPPP_LOCK(sp, RW_READER); |
532 | | | 532 | |
533 | if (ifp->if_flags & IFF_UP) { | | 533 | if (ifp->if_flags & IFF_UP) { |
534 | /* Count received bytes, add hardware framing */ | | 534 | /* Count received bytes, add hardware framing */ |
535 | if_statadd(ifp, if_ibytes, m->m_pkthdr.len + sp->pp_framebytes); | | 535 | if_statadd(ifp, if_ibytes, m->m_pkthdr.len + sp->pp_framebytes); |
536 | /* Note time of last receive */ | | 536 | /* Note time of last receive */ |
537 | sp->pp_last_receive = time_uptime; | | 537 | sp->pp_last_receive = time_uptime; |
538 | } | | 538 | } |
539 | | | 539 | |
540 | if (m->m_pkthdr.len <= PPP_HEADER_LEN) { | | 540 | if (m->m_pkthdr.len <= PPP_HEADER_LEN) { |
541 | /* Too small packet, drop it. */ | | 541 | /* Too small packet, drop it. */ |
542 | if (debug) | | 542 | if (debug) |
543 | log(LOG_DEBUG, | | 543 | log(LOG_DEBUG, |
544 | "%s: input packet is too small, %d bytes\n", | | 544 | "%s: input packet is too small, %d bytes\n", |
545 | ifp->if_xname, m->m_pkthdr.len); | | 545 | ifp->if_xname, m->m_pkthdr.len); |
546 | drop: | | 546 | drop: |
547 | if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1); | | 547 | if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1); |
548 | m_freem(m); | | 548 | m_freem(m); |
549 | SPPP_UNLOCK(sp); | | 549 | SPPP_UNLOCK(sp); |
550 | return; | | 550 | return; |
551 | } | | 551 | } |
552 | | | 552 | |
553 | if (sp->pp_flags & PP_NOFRAMING) { | | 553 | if (sp->pp_flags & PP_NOFRAMING) { |
554 | memcpy(&protocol, mtod(m, void *), 2); | | 554 | memcpy(&protocol, mtod(m, void *), 2); |
555 | protocol = ntohs(protocol); | | 555 | protocol = ntohs(protocol); |
556 | m_adj(m, 2); | | 556 | m_adj(m, 2); |
557 | } else { | | 557 | } else { |
558 | | | 558 | |
559 | /* Get PPP header. */ | | 559 | /* Get PPP header. */ |
560 | h = mtod(m, struct ppp_header *); | | 560 | h = mtod(m, struct ppp_header *); |
561 | m_adj(m, PPP_HEADER_LEN); | | 561 | m_adj(m, PPP_HEADER_LEN); |
562 | | | 562 | |
563 | switch (h->address) { | | 563 | switch (h->address) { |
564 | case PPP_ALLSTATIONS: | | 564 | case PPP_ALLSTATIONS: |
565 | if (h->control != PPP_UI) | | 565 | if (h->control != PPP_UI) |
566 | goto invalid; | | 566 | goto invalid; |
567 | if (sp->pp_flags & PP_CISCO) { | | 567 | if (sp->pp_flags & PP_CISCO) { |
568 | if (debug) | | 568 | if (debug) |
569 | log(LOG_DEBUG, | | 569 | log(LOG_DEBUG, |
570 | "%s: PPP packet in Cisco mode " | | 570 | "%s: PPP packet in Cisco mode " |
571 | "<addr=0x%x ctrl=0x%x proto=0x%x>\n", | | 571 | "<addr=0x%x ctrl=0x%x proto=0x%x>\n", |
572 | ifp->if_xname, | | 572 | ifp->if_xname, |
573 | h->address, h->control, ntohs(h->protocol)); | | 573 | h->address, h->control, ntohs(h->protocol)); |
574 | goto drop; | | 574 | goto drop; |
575 | } | | 575 | } |
576 | break; | | 576 | break; |
577 | case CISCO_MULTICAST: | | 577 | case CISCO_MULTICAST: |
578 | case CISCO_UNICAST: | | 578 | case CISCO_UNICAST: |
579 | /* Don't check the control field here (RFC 1547). */ | | 579 | /* Don't check the control field here (RFC 1547). */ |
580 | if (! (sp->pp_flags & PP_CISCO)) { | | 580 | if (! (sp->pp_flags & PP_CISCO)) { |
581 | if (debug) | | 581 | if (debug) |
582 | log(LOG_DEBUG, | | 582 | log(LOG_DEBUG, |
583 | "%s: Cisco packet in PPP mode " | | 583 | "%s: Cisco packet in PPP mode " |
584 | "<addr=0x%x ctrl=0x%x proto=0x%x>\n", | | 584 | "<addr=0x%x ctrl=0x%x proto=0x%x>\n", |
585 | ifp->if_xname, | | 585 | ifp->if_xname, |
586 | h->address, h->control, ntohs(h->protocol)); | | 586 | h->address, h->control, ntohs(h->protocol)); |
587 | goto drop; | | 587 | goto drop; |
588 | } | | 588 | } |
589 | switch (ntohs(h->protocol)) { | | 589 | switch (ntohs(h->protocol)) { |
590 | default: | | 590 | default: |
591 | if_statinc(ifp, if_noproto); | | 591 | if_statinc(ifp, if_noproto); |
592 | goto invalid; | | 592 | goto invalid; |
593 | case CISCO_KEEPALIVE: | | 593 | case CISCO_KEEPALIVE: |
594 | SPPP_UNLOCK(sp); | | 594 | SPPP_UNLOCK(sp); |
595 | sppp_cisco_input((struct sppp *) ifp, m); | | 595 | sppp_cisco_input((struct sppp *) ifp, m); |
596 | m_freem(m); | | 596 | m_freem(m); |
597 | return; | | 597 | return; |
598 | #ifdef INET | | 598 | #ifdef INET |
599 | case ETHERTYPE_IP: | | 599 | case ETHERTYPE_IP: |
600 | pktq = ip_pktq; | | 600 | pktq = ip_pktq; |
601 | break; | | 601 | break; |
602 | #endif | | 602 | #endif |
603 | #ifdef INET6 | | 603 | #ifdef INET6 |
604 | case ETHERTYPE_IPV6: | | 604 | case ETHERTYPE_IPV6: |
605 | pktq = ip6_pktq; | | 605 | pktq = ip6_pktq; |
606 | break; | | 606 | break; |
607 | #endif | | 607 | #endif |
608 | } | | 608 | } |
609 | goto queue_pkt; | | 609 | goto queue_pkt; |
610 | default: /* Invalid PPP packet. */ | | 610 | default: /* Invalid PPP packet. */ |
611 | invalid: | | 611 | invalid: |
612 | if (debug) | | 612 | if (debug) |
613 | log(LOG_DEBUG, | | 613 | log(LOG_DEBUG, |
614 | "%s: invalid input packet " | | 614 | "%s: invalid input packet " |
615 | "<addr=0x%x ctrl=0x%x proto=0x%x>\n", | | 615 | "<addr=0x%x ctrl=0x%x proto=0x%x>\n", |
616 | ifp->if_xname, | | 616 | ifp->if_xname, |
617 | h->address, h->control, ntohs(h->protocol)); | | 617 | h->address, h->control, ntohs(h->protocol)); |
618 | goto drop; | | 618 | goto drop; |
619 | } | | 619 | } |
620 | protocol = ntohs(h->protocol); | | 620 | protocol = ntohs(h->protocol); |
621 | } | | 621 | } |
622 | | | 622 | |
623 | switch (protocol) { | | 623 | switch (protocol) { |
624 | default: | | 624 | default: |
625 | if (sp->state[IDX_LCP] == STATE_OPENED) { | | 625 | if (sp->state[IDX_LCP] == STATE_OPENED) { |
626 | uint16_t prot = htons(protocol); | | 626 | uint16_t prot = htons(protocol); |
627 | | | 627 | |
628 | SPPP_UPGRADE(sp); | | 628 | SPPP_UPGRADE(sp); |
629 | sppp_cp_send(sp, PPP_LCP, PROTO_REJ, | | 629 | sppp_cp_send(sp, PPP_LCP, PROTO_REJ, |
630 | ++sp->pp_seq[IDX_LCP], m->m_pkthdr.len + 2, | | 630 | ++sp->pp_seq[IDX_LCP], m->m_pkthdr.len + 2, |
631 | &prot); | | 631 | &prot); |
632 | SPPP_DOWNGRADE(sp); | | 632 | SPPP_DOWNGRADE(sp); |
633 | } | | 633 | } |
634 | if (debug) | | 634 | if (debug) |
635 | log(LOG_DEBUG, | | 635 | log(LOG_DEBUG, |
636 | "%s: invalid input protocol " | | 636 | "%s: invalid input protocol " |
637 | "<proto=0x%x>\n", ifp->if_xname, ntohs(protocol)); | | 637 | "<proto=0x%x>\n", ifp->if_xname, ntohs(protocol)); |
638 | if_statinc(ifp, if_noproto); | | 638 | if_statinc(ifp, if_noproto); |
639 | goto drop; | | 639 | goto drop; |
640 | case PPP_LCP: | | 640 | case PPP_LCP: |
641 | SPPP_UNLOCK(sp); | | 641 | SPPP_UNLOCK(sp); |
642 | sppp_cp_input(&lcp, sp, m); | | 642 | sppp_cp_input(&lcp, sp, m); |
643 | m_freem(m); | | 643 | m_freem(m); |
644 | return; | | 644 | return; |
645 | case PPP_PAP: | | 645 | case PPP_PAP: |
646 | SPPP_UNLOCK(sp); | | 646 | SPPP_UNLOCK(sp); |
647 | if (sp->pp_phase >= SPPP_PHASE_AUTHENTICATE) { | | 647 | if (sp->pp_phase >= SPPP_PHASE_AUTHENTICATE) { |
648 | sppp_pap_input(sp, m); | | 648 | sppp_pap_input(sp, m); |
649 | } | | 649 | } |
650 | m_freem(m); | | 650 | m_freem(m); |
651 | return; | | 651 | return; |
652 | case PPP_CHAP: | | 652 | case PPP_CHAP: |
653 | SPPP_UNLOCK(sp); | | 653 | SPPP_UNLOCK(sp); |
654 | if (sp->pp_phase >= SPPP_PHASE_AUTHENTICATE) { | | 654 | if (sp->pp_phase >= SPPP_PHASE_AUTHENTICATE) { |
655 | sppp_chap_input(sp, m); | | 655 | sppp_chap_input(sp, m); |
656 | } | | 656 | } |
657 | m_freem(m); | | 657 | m_freem(m); |
658 | return; | | 658 | return; |
659 | #ifdef INET | | 659 | #ifdef INET |
660 | case PPP_IPCP: | | 660 | case PPP_IPCP: |
661 | SPPP_UNLOCK(sp); | | 661 | SPPP_UNLOCK(sp); |
662 | if (sp->pp_phase == SPPP_PHASE_NETWORK) { | | 662 | if (sp->pp_phase == SPPP_PHASE_NETWORK) { |
663 | sppp_cp_input(&ipcp, sp, m); | | 663 | sppp_cp_input(&ipcp, sp, m); |
664 | } | | 664 | } |
665 | m_freem(m); | | 665 | m_freem(m); |
666 | return; | | 666 | return; |
667 | case PPP_IP: | | 667 | case PPP_IP: |
668 | if (sp->state[IDX_IPCP] == STATE_OPENED) { | | 668 | if (sp->state[IDX_IPCP] == STATE_OPENED) { |
669 | sp->pp_last_activity = time_uptime; | | 669 | sp->pp_last_activity = time_uptime; |
670 | pktq = ip_pktq; | | 670 | pktq = ip_pktq; |
671 | } | | 671 | } |
672 | break; | | 672 | break; |
673 | #endif | | 673 | #endif |
674 | #ifdef INET6 | | 674 | #ifdef INET6 |
675 | case PPP_IPV6CP: | | 675 | case PPP_IPV6CP: |
676 | SPPP_UNLOCK(sp); | | 676 | SPPP_UNLOCK(sp); |
677 | if (sp->pp_phase == SPPP_PHASE_NETWORK) { | | 677 | if (sp->pp_phase == SPPP_PHASE_NETWORK) { |
678 | sppp_cp_input(&ipv6cp, sp, m); | | 678 | sppp_cp_input(&ipv6cp, sp, m); |
679 | } | | 679 | } |
680 | m_freem(m); | | 680 | m_freem(m); |
681 | return; | | 681 | return; |
682 | | | 682 | |
683 | case PPP_IPV6: | | 683 | case PPP_IPV6: |
684 | if (sp->state[IDX_IPV6CP] == STATE_OPENED) { | | 684 | if (sp->state[IDX_IPV6CP] == STATE_OPENED) { |
685 | sp->pp_last_activity = time_uptime; | | 685 | sp->pp_last_activity = time_uptime; |
686 | pktq = ip6_pktq; | | 686 | pktq = ip6_pktq; |
687 | } | | 687 | } |
688 | break; | | 688 | break; |
689 | #endif | | 689 | #endif |
690 | } | | 690 | } |
691 | | | 691 | |
692 | queue_pkt: | | 692 | queue_pkt: |
693 | if ((ifp->if_flags & IFF_UP) == 0 || (!inq && !pktq)) { | | 693 | if ((ifp->if_flags & IFF_UP) == 0 || (!inq && !pktq)) { |
694 | goto drop; | | 694 | goto drop; |
695 | } | | 695 | } |
696 | | | 696 | |
697 | /* Check queue. */ | | 697 | /* Check queue. */ |
698 | if (__predict_true(pktq)) { | | 698 | if (__predict_true(pktq)) { |
699 | if (__predict_false(!pktq_enqueue(pktq, m, 0))) { | | 699 | if (__predict_false(!pktq_enqueue(pktq, m, 0))) { |
700 | goto drop; | | 700 | goto drop; |
701 | } | | 701 | } |
702 | SPPP_UNLOCK(sp); | | 702 | SPPP_UNLOCK(sp); |
703 | return; | | 703 | return; |
704 | } | | 704 | } |
705 | | | 705 | |
706 | SPPP_UNLOCK(sp); | | 706 | SPPP_UNLOCK(sp); |
707 | | | 707 | |
708 | IFQ_LOCK(inq); | | 708 | IFQ_LOCK(inq); |
709 | if (IF_QFULL(inq)) { | | 709 | if (IF_QFULL(inq)) { |
710 | /* Queue overflow. */ | | 710 | /* Queue overflow. */ |
711 | IF_DROP(inq); | | 711 | IF_DROP(inq); |
712 | IFQ_UNLOCK(inq); | | 712 | IFQ_UNLOCK(inq); |
713 | if (debug) | | 713 | if (debug) |
714 | log(LOG_DEBUG, "%s: protocol queue overflow\n", | | 714 | log(LOG_DEBUG, "%s: protocol queue overflow\n", |
715 | ifp->if_xname); | | 715 | ifp->if_xname); |
716 | | | 716 | |
717 | SPPP_LOCK(sp, RW_READER); | | 717 | SPPP_LOCK(sp, RW_READER); |
718 | goto drop; | | 718 | goto drop; |
719 | } | | 719 | } |
720 | IF_ENQUEUE(inq, m); | | 720 | IF_ENQUEUE(inq, m); |
721 | IFQ_UNLOCK(inq); | | 721 | IFQ_UNLOCK(inq); |
722 | schednetisr(isr); | | 722 | schednetisr(isr); |
723 | } | | 723 | } |
724 | | | 724 | |
725 | /* | | 725 | /* |
726 | * Enqueue transmit packet. | | 726 | * Enqueue transmit packet. |
727 | */ | | 727 | */ |
728 | static int | | 728 | static int |
729 | sppp_output(struct ifnet *ifp, struct mbuf *m, | | 729 | sppp_output(struct ifnet *ifp, struct mbuf *m, |
730 | const struct sockaddr *dst, const struct rtentry *rt) | | 730 | const struct sockaddr *dst, const struct rtentry *rt) |
731 | { | | 731 | { |
732 | struct sppp *sp = (struct sppp *) ifp; | | 732 | struct sppp *sp = (struct sppp *) ifp; |
733 | struct ppp_header *h = NULL; | | 733 | struct ppp_header *h = NULL; |
734 | #ifndef SPPPSUBR_MPSAFE | | 734 | #ifndef SPPPSUBR_MPSAFE |
735 | struct ifqueue *ifq = NULL; /* XXX */ | | 735 | struct ifqueue *ifq = NULL; /* XXX */ |
736 | #endif | | 736 | #endif |
737 | int s, error = 0; | | 737 | int s, error = 0; |
738 | uint16_t protocol; | | 738 | uint16_t protocol; |
739 | size_t pktlen; | | 739 | size_t pktlen; |
740 | | | 740 | |
741 | s = splnet(); | | 741 | s = splnet(); |
742 | SPPP_LOCK(sp, RW_READER); | | 742 | SPPP_LOCK(sp, RW_READER); |
743 | | | 743 | |
744 | sp->pp_last_activity = time_uptime; | | 744 | sp->pp_last_activity = time_uptime; |
745 | | | 745 | |
746 | if ((ifp->if_flags & IFF_UP) == 0 || | | 746 | if ((ifp->if_flags & IFF_UP) == 0 || |
747 | (ifp->if_flags & (IFF_RUNNING | IFF_AUTO)) == 0) { | | 747 | (ifp->if_flags & (IFF_RUNNING | IFF_AUTO)) == 0) { |
748 | SPPP_UNLOCK(sp); | | 748 | SPPP_UNLOCK(sp); |
749 | splx(s); | | 749 | splx(s); |
750 | | | 750 | |
751 | m_freem(m); | | 751 | m_freem(m); |
752 | | | 752 | |
753 | return (ENETDOWN); | | 753 | return (ENETDOWN); |
754 | } | | 754 | } |
755 | | | 755 | |
756 | if ((ifp->if_flags & (IFF_RUNNING | IFF_AUTO)) == IFF_AUTO) { | | 756 | if ((ifp->if_flags & (IFF_RUNNING | IFF_AUTO)) == IFF_AUTO) { |
757 | /* | | 757 | /* |
758 | * Interface is not yet running, but auto-dial. Need | | 758 | * Interface is not yet running, but auto-dial. Need |
759 | * to start LCP for it. | | 759 | * to start LCP for it. |
760 | */ | | 760 | */ |
761 | ifp->if_flags |= IFF_RUNNING; | | 761 | ifp->if_flags |= IFF_RUNNING; |
762 | | | 762 | |
763 | SPPP_UNLOCK(sp); | | 763 | SPPP_UNLOCK(sp); |
764 | splx(s); | | 764 | splx(s); |
765 | | | 765 | |
766 | SPPP_LOCK(sp, RW_WRITER); | | 766 | SPPP_LOCK(sp, RW_WRITER); |
767 | lcp.Open(sp); | | 767 | lcp.Open(sp); |
768 | SPPP_UNLOCK(sp); | | 768 | SPPP_UNLOCK(sp); |
769 | | | 769 | |
770 | s = splnet(); | | 770 | s = splnet(); |
771 | SPPP_LOCK(sp, RW_READER); | | 771 | SPPP_LOCK(sp, RW_READER); |
772 | } | | 772 | } |
773 | | | 773 | |
774 | /* | | 774 | /* |
775 | * If the queueing discipline needs packet classification, | | 775 | * If the queueing discipline needs packet classification, |
776 | * do it before prepending link headers. | | 776 | * do it before prepending link headers. |
777 | */ | | 777 | */ |
778 | IFQ_CLASSIFY(&ifp->if_snd, m, dst->sa_family); | | 778 | IFQ_CLASSIFY(&ifp->if_snd, m, dst->sa_family); |
779 | | | 779 | |
780 | #ifdef INET | | 780 | #ifdef INET |
781 | if (dst->sa_family == AF_INET) { | | 781 | if (dst->sa_family == AF_INET) { |
782 | struct ip *ip = NULL; | | 782 | struct ip *ip = NULL; |
783 | #ifndef SPPPSUBR_MPSAFE | | 783 | #ifndef SPPPSUBR_MPSAFE |
784 | struct tcphdr *th = NULL; | | 784 | struct tcphdr *th = NULL; |
785 | #endif | | 785 | #endif |
786 | | | 786 | |
787 | if (m->m_len >= sizeof(struct ip)) { | | 787 | if (m->m_len >= sizeof(struct ip)) { |
788 | ip = mtod(m, struct ip *); | | 788 | ip = mtod(m, struct ip *); |
789 | #ifndef SPPPSUBR_MPSAFE | | 789 | #ifndef SPPPSUBR_MPSAFE |
790 | if (ip->ip_p == IPPROTO_TCP && | | 790 | if (ip->ip_p == IPPROTO_TCP && |
791 | m->m_len >= sizeof(struct ip) + (ip->ip_hl << 2) + | | 791 | m->m_len >= sizeof(struct ip) + (ip->ip_hl << 2) + |
792 | sizeof(struct tcphdr)) { | | 792 | sizeof(struct tcphdr)) { |
793 | th = (struct tcphdr *) | | 793 | th = (struct tcphdr *) |
794 | ((char *)ip + (ip->ip_hl << 2)); | | 794 | ((char *)ip + (ip->ip_hl << 2)); |
795 | } | | 795 | } |
796 | #endif | | 796 | #endif |
797 | } else | | 797 | } else |
798 | ip = NULL; | | 798 | ip = NULL; |
799 | | | 799 | |
800 | /* | | 800 | /* |
801 | * When using dynamic local IP address assignment by using | | 801 | * When using dynamic local IP address assignment by using |
802 | * 0.0.0.0 as a local address, the first TCP session will | | 802 | * 0.0.0.0 as a local address, the first TCP session will |
803 | * not connect because the local TCP checksum is computed | | 803 | * not connect because the local TCP checksum is computed |
804 | * using 0.0.0.0 which will later become our real IP address | | 804 | * using 0.0.0.0 which will later become our real IP address |
805 | * so the TCP checksum computed at the remote end will | | 805 | * so the TCP checksum computed at the remote end will |
806 | * become invalid. So we | | 806 | * become invalid. So we |
807 | * - don't let packets with src ip addr 0 thru | | 807 | * - don't let packets with src ip addr 0 thru |
808 | * - we flag TCP packets with src ip 0 as an error | | 808 | * - we flag TCP packets with src ip 0 as an error |
809 | */ | | 809 | */ |
810 | if (ip && ip->ip_src.s_addr == INADDR_ANY) { | | 810 | if (ip && ip->ip_src.s_addr == INADDR_ANY) { |
811 | uint8_t proto = ip->ip_p; | | 811 | uint8_t proto = ip->ip_p; |
812 | | | 812 | |
813 | SPPP_UNLOCK(sp); | | 813 | SPPP_UNLOCK(sp); |
814 | splx(s); | | 814 | splx(s); |
815 | | | 815 | |
816 | m_freem(m); | | 816 | m_freem(m); |
817 | if (proto == IPPROTO_TCP) | | 817 | if (proto == IPPROTO_TCP) |
818 | return (EADDRNOTAVAIL); | | 818 | return (EADDRNOTAVAIL); |
819 | else | | 819 | else |
820 | return (0); | | 820 | return (0); |
821 | } | | 821 | } |
822 | | | 822 | |
823 | #ifndef SPPPSUBR_MPSAFE | | 823 | #ifndef SPPPSUBR_MPSAFE |
824 | /* | | 824 | /* |
825 | * Put low delay, telnet, rlogin and ftp control packets | | 825 | * Put low delay, telnet, rlogin and ftp control packets |
826 | * in front of the queue. | | 826 | * in front of the queue. |
827 | */ | | 827 | */ |
828 | if (!IF_QFULL(&sp->pp_fastq) && | | 828 | if (!IF_QFULL(&sp->pp_fastq) && |
829 | ((ip && (ip->ip_tos & IPTOS_LOWDELAY)) || | | 829 | ((ip && (ip->ip_tos & IPTOS_LOWDELAY)) || |
830 | (th && (INTERACTIVE(ntohs(th->th_sport)) || | | 830 | (th && (INTERACTIVE(ntohs(th->th_sport)) || |
831 | INTERACTIVE(ntohs(th->th_dport)))))) | | 831 | INTERACTIVE(ntohs(th->th_dport)))))) |
832 | ifq = &sp->pp_fastq; | | 832 | ifq = &sp->pp_fastq; |
833 | #endif /* !SPPPSUBR_MPSAFE */ | | 833 | #endif /* !SPPPSUBR_MPSAFE */ |
834 | } | | 834 | } |
835 | #endif | | 835 | #endif |
836 | | | 836 | |
837 | #ifdef INET6 | | 837 | #ifdef INET6 |
838 | if (dst->sa_family == AF_INET6) { | | 838 | if (dst->sa_family == AF_INET6) { |
839 | /* XXX do something tricky here? */ | | 839 | /* XXX do something tricky here? */ |
840 | } | | 840 | } |
841 | #endif | | 841 | #endif |
842 | | | 842 | |
843 | if ((sp->pp_flags & PP_NOFRAMING) == 0) { | | 843 | if ((sp->pp_flags & PP_NOFRAMING) == 0) { |
844 | /* | | 844 | /* |
845 | * Prepend general data packet PPP header. For now, IP only. | | 845 | * Prepend general data packet PPP header. For now, IP only. |
846 | */ | | 846 | */ |
847 | M_PREPEND(m, PPP_HEADER_LEN, M_DONTWAIT); | | 847 | M_PREPEND(m, PPP_HEADER_LEN, M_DONTWAIT); |
848 | if (! m) { | | 848 | if (! m) { |
849 | if (ifp->if_flags & IFF_DEBUG) | | 849 | if (ifp->if_flags & IFF_DEBUG) |
850 | log(LOG_DEBUG, "%s: no memory for transmit header\n", | | 850 | log(LOG_DEBUG, "%s: no memory for transmit header\n", |
851 | ifp->if_xname); | | 851 | ifp->if_xname); |
852 | if_statinc(ifp, if_oerrors); | | 852 | if_statinc(ifp, if_oerrors); |
853 | SPPP_UNLOCK(sp); | | 853 | SPPP_UNLOCK(sp); |
854 | splx(s); | | 854 | splx(s); |
855 | return (ENOBUFS); | | 855 | return (ENOBUFS); |
856 | } | | 856 | } |
857 | /* | | 857 | /* |
858 | * May want to check size of packet | | 858 | * May want to check size of packet |
859 | * (albeit due to the implementation it's always enough) | | 859 | * (albeit due to the implementation it's always enough) |
860 | */ | | 860 | */ |
861 | h = mtod(m, struct ppp_header *); | | 861 | h = mtod(m, struct ppp_header *); |
862 | if (sp->pp_flags & PP_CISCO) { | | 862 | if (sp->pp_flags & PP_CISCO) { |
863 | h->address = CISCO_UNICAST; /* unicast address */ | | 863 | h->address = CISCO_UNICAST; /* unicast address */ |
864 | h->control = 0; | | 864 | h->control = 0; |
865 | } else { | | 865 | } else { |
866 | h->address = PPP_ALLSTATIONS; /* broadcast address */ | | 866 | h->address = PPP_ALLSTATIONS; /* broadcast address */ |
867 | h->control = PPP_UI; /* Unnumbered Info */ | | 867 | h->control = PPP_UI; /* Unnumbered Info */ |
868 | } | | 868 | } |
869 | } | | 869 | } |
870 | | | 870 | |
871 | switch (dst->sa_family) { | | 871 | switch (dst->sa_family) { |
872 | #ifdef INET | | 872 | #ifdef INET |
873 | case AF_INET: /* Internet Protocol */ | | 873 | case AF_INET: /* Internet Protocol */ |
874 | if (sp->pp_flags & PP_CISCO) | | 874 | if (sp->pp_flags & PP_CISCO) |
875 | protocol = htons(ETHERTYPE_IP); | | 875 | protocol = htons(ETHERTYPE_IP); |
876 | else { | | 876 | else { |
877 | /* | | 877 | /* |
878 | * Don't choke with an ENETDOWN early. It's | | 878 | * Don't choke with an ENETDOWN early. It's |
879 | * possible that we just started dialing out, | | 879 | * possible that we just started dialing out, |
880 | * so don't drop the packet immediately. If | | 880 | * so don't drop the packet immediately. If |
881 | * we notice that we run out of buffer space | | 881 | * we notice that we run out of buffer space |
882 | * below, we will however remember that we are | | 882 | * below, we will however remember that we are |
883 | * not ready to carry IP packets, and return | | 883 | * not ready to carry IP packets, and return |
884 | * ENETDOWN, as opposed to ENOBUFS. | | 884 | * ENETDOWN, as opposed to ENOBUFS. |
885 | */ | | 885 | */ |
886 | protocol = htons(PPP_IP); | | 886 | protocol = htons(PPP_IP); |
887 | if (sp->state[IDX_IPCP] != STATE_OPENED) | | 887 | if (sp->state[IDX_IPCP] != STATE_OPENED) |
888 | error = ENETDOWN; | | 888 | error = ENETDOWN; |
889 | } | | 889 | } |
890 | break; | | 890 | break; |
891 | #endif | | 891 | #endif |
892 | #ifdef INET6 | | 892 | #ifdef INET6 |
893 | case AF_INET6: /* Internet Protocol version 6 */ | | 893 | case AF_INET6: /* Internet Protocol version 6 */ |
894 | if (sp->pp_flags & PP_CISCO) | | 894 | if (sp->pp_flags & PP_CISCO) |
895 | protocol = htons(ETHERTYPE_IPV6); | | 895 | protocol = htons(ETHERTYPE_IPV6); |
896 | else { | | 896 | else { |
897 | /* | | 897 | /* |
898 | * Don't choke with an ENETDOWN early. It's | | 898 | * Don't choke with an ENETDOWN early. It's |
899 | * possible that we just started dialing out, | | 899 | * possible that we just started dialing out, |
900 | * so don't drop the packet immediately. If | | 900 | * so don't drop the packet immediately. If |
901 | * we notice that we run out of buffer space | | 901 | * we notice that we run out of buffer space |
902 | * below, we will however remember that we are | | 902 | * below, we will however remember that we are |
903 | * not ready to carry IP packets, and return | | 903 | * not ready to carry IP packets, and return |
904 | * ENETDOWN, as opposed to ENOBUFS. | | 904 | * ENETDOWN, as opposed to ENOBUFS. |
905 | */ | | 905 | */ |
906 | protocol = htons(PPP_IPV6); | | 906 | protocol = htons(PPP_IPV6); |
907 | if (sp->state[IDX_IPV6CP] != STATE_OPENED) | | 907 | if (sp->state[IDX_IPV6CP] != STATE_OPENED) |
908 | error = ENETDOWN; | | 908 | error = ENETDOWN; |
909 | } | | 909 | } |
910 | break; | | 910 | break; |
911 | #endif | | 911 | #endif |
912 | default: | | 912 | default: |
913 | m_freem(m); | | 913 | m_freem(m); |
914 | if_statinc(ifp, if_oerrors); | | 914 | if_statinc(ifp, if_oerrors); |
915 | SPPP_UNLOCK(sp); | | 915 | SPPP_UNLOCK(sp); |
916 | splx(s); | | 916 | splx(s); |
917 | return (EAFNOSUPPORT); | | 917 | return (EAFNOSUPPORT); |
918 | } | | 918 | } |
919 | | | 919 | |
920 | if (sp->pp_flags & PP_NOFRAMING) { | | 920 | if (sp->pp_flags & PP_NOFRAMING) { |
921 | M_PREPEND(m, 2, M_DONTWAIT); | | 921 | M_PREPEND(m, 2, M_DONTWAIT); |
922 | if (m == NULL) { | | 922 | if (m == NULL) { |
923 | if (ifp->if_flags & IFF_DEBUG) | | 923 | if (ifp->if_flags & IFF_DEBUG) |
924 | log(LOG_DEBUG, "%s: no memory for transmit header\n", | | 924 | log(LOG_DEBUG, "%s: no memory for transmit header\n", |
925 | ifp->if_xname); | | 925 | ifp->if_xname); |
926 | if_statinc(ifp, if_oerrors); | | 926 | if_statinc(ifp, if_oerrors); |
927 | SPPP_UNLOCK(sp); | | 927 | SPPP_UNLOCK(sp); |
928 | splx(s); | | 928 | splx(s); |
929 | return (ENOBUFS); | | 929 | return (ENOBUFS); |
930 | } | | 930 | } |
931 | *mtod(m, uint16_t *) = protocol; | | 931 | *mtod(m, uint16_t *) = protocol; |
932 | } else { | | 932 | } else { |
933 | h->protocol = protocol; | | 933 | h->protocol = protocol; |
934 | } | | 934 | } |
935 | | | 935 | |
936 | pktlen = m->m_pkthdr.len; | | 936 | pktlen = m->m_pkthdr.len; |
937 | #ifdef SPPPSUBR_MPSAFE | | 937 | #ifdef SPPPSUBR_MPSAFE |
938 | SPPP_UNLOCK(sp); | | 938 | SPPP_UNLOCK(sp); |
939 | error = if_transmit_lock(ifp, m); | | 939 | error = if_transmit_lock(ifp, m); |
940 | SPPP_LOCK(sp, RW_READER); | | 940 | SPPP_LOCK(sp, RW_READER); |
941 | if (error == 0) | | 941 | if (error == 0) |
942 | if_statadd(ifp, if_obytes, pktlen + sp->pp_framebytes); | | 942 | if_statadd(ifp, if_obytes, pktlen + sp->pp_framebytes); |
943 | #else /* !SPPPSUBR_MPSAFE */ | | 943 | #else /* !SPPPSUBR_MPSAFE */ |
944 | error = ifq_enqueue2(ifp, ifq, m); | | 944 | error = ifq_enqueue2(ifp, ifq, m); |
945 | | | 945 | |
946 | if (error == 0) { | | 946 | if (error == 0) { |
947 | /* | | 947 | /* |
948 | * Count output packets and bytes. | | 948 | * Count output packets and bytes. |
949 | * The packet length includes header + additional hardware | | 949 | * The packet length includes header + additional hardware |
950 | * framing according to RFC 1333. | | 950 | * framing according to RFC 1333. |
951 | */ | | 951 | */ |
952 | if (!(ifp->if_flags & IFF_OACTIVE)) { | | 952 | if (!(ifp->if_flags & IFF_OACTIVE)) { |
953 | SPPP_UNLOCK(sp); | | 953 | SPPP_UNLOCK(sp); |
954 | if_start_lock(ifp); | | 954 | if_start_lock(ifp); |
955 | SPPP_LOCK(sp, RW_READER); | | 955 | SPPP_LOCK(sp, RW_READER); |
956 | } | | 956 | } |
957 | if_statadd(ifp, if_obytes, pktlen + sp->pp_framebytes); | | 957 | if_statadd(ifp, if_obytes, pktlen + sp->pp_framebytes); |
958 | } | | 958 | } |
959 | #endif /* !SPPPSUBR_MPSAFE */ | | 959 | #endif /* !SPPPSUBR_MPSAFE */ |
960 | SPPP_UNLOCK(sp); | | 960 | SPPP_UNLOCK(sp); |
961 | splx(s); | | 961 | splx(s); |
962 | return error; | | 962 | return error; |
963 | } | | 963 | } |
964 | | | 964 | |
965 | static int | | 965 | static int |
966 | sppp_mediachange(struct ifnet *ifp) | | 966 | sppp_mediachange(struct ifnet *ifp) |
967 | { | | 967 | { |
968 | | | 968 | |
969 | return (0); | | 969 | return (0); |
970 | } | | 970 | } |
971 | | | 971 | |
972 | static void | | 972 | static void |
973 | sppp_mediastatus(struct ifnet *ifp, struct ifmediareq *imr) | | 973 | sppp_mediastatus(struct ifnet *ifp, struct ifmediareq *imr) |
974 | { | | 974 | { |
975 | struct sppp *sp = (struct sppp *)ifp; | | 975 | int link_state; |
976 | | | | |
977 | SPPP_LOCK(sp, RW_WRITER); | | | |
978 | | | 976 | |
979 | switch (ifp->if_link_state) { | | 977 | link_state = atomic_load_relaxed(&ifp->if_link_state); |
| | | 978 | switch (link_state) { |
980 | case LINK_STATE_UP: | | 979 | case LINK_STATE_UP: |
981 | imr->ifm_status = IFM_AVALID | IFM_ACTIVE; | | 980 | imr->ifm_status = IFM_AVALID | IFM_ACTIVE; |
982 | break; | | 981 | break; |
983 | case LINK_STATE_DOWN: | | 982 | case LINK_STATE_DOWN: |
984 | imr->ifm_status = IFM_AVALID; | | 983 | imr->ifm_status = IFM_AVALID; |
985 | break; | | 984 | break; |
986 | default: | | 985 | default: |
987 | /* Should be impossible as we set link state down in attach. */ | | 986 | /* Should be impossible as we set link state down in attach. */ |
988 | imr->ifm_status = 0; | | 987 | imr->ifm_status = 0; |
989 | break; | | 988 | break; |
990 | } | | 989 | } |
991 | | | | |
992 | SPPP_UNLOCK(sp); | | | |
993 | } | | 990 | } |
994 | | | 991 | |
995 | void | | 992 | void |
996 | sppp_attach(struct ifnet *ifp) | | 993 | sppp_attach(struct ifnet *ifp) |
997 | { | | 994 | { |
998 | struct sppp *sp = (struct sppp *) ifp; | | 995 | struct sppp *sp = (struct sppp *) ifp; |
999 | | | 996 | |
1000 | /* Initialize keepalive handler. */ | | 997 | /* Initialize keepalive handler. */ |
1001 | if (! spppq) { | | 998 | if (! spppq) { |
1002 | callout_init(&keepalive_ch, CALLOUT_MPSAFE); | | 999 | callout_init(&keepalive_ch, CALLOUT_MPSAFE); |
1003 | callout_reset(&keepalive_ch, hz * LCP_KEEPALIVE_INTERVAL, sppp_keepalive, NULL); | | 1000 | callout_reset(&keepalive_ch, hz * LCP_KEEPALIVE_INTERVAL, sppp_keepalive, NULL); |
1004 | } | | 1001 | } |
1005 | | | 1002 | |
1006 | if (! spppq_lock) | | 1003 | if (! spppq_lock) |
1007 | spppq_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SOFTNET); | | 1004 | spppq_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SOFTNET); |
1008 | | | 1005 | |
1009 | /* Insert new entry into the keepalive list. */ | | 1006 | /* Insert new entry into the keepalive list. */ |
1010 | sp->pp_next = spppq; | | 1007 | sp->pp_next = spppq; |
1011 | spppq = sp; | | 1008 | spppq = sp; |
1012 | | | 1009 | |
1013 | sp->pp_if.if_type = IFT_PPP; | | 1010 | sp->pp_if.if_type = IFT_PPP; |
1014 | sp->pp_if.if_output = sppp_output; | | 1011 | sp->pp_if.if_output = sppp_output; |
1015 | sp->pp_fastq.ifq_maxlen = 32; | | 1012 | sp->pp_fastq.ifq_maxlen = 32; |
1016 | sp->pp_cpq.ifq_maxlen = 20; | | 1013 | sp->pp_cpq.ifq_maxlen = 20; |
1017 | sp->pp_loopcnt = 0; | | 1014 | sp->pp_loopcnt = 0; |
1018 | sp->pp_alivecnt = 0; | | 1015 | sp->pp_alivecnt = 0; |
1019 | sp->pp_last_activity = 0; | | 1016 | sp->pp_last_activity = 0; |
1020 | sp->pp_last_receive = 0; | | 1017 | sp->pp_last_receive = 0; |
1021 | sp->pp_maxalive = DEFAULT_MAXALIVECNT; | | 1018 | sp->pp_maxalive = DEFAULT_MAXALIVECNT; |
1022 | sp->pp_max_noreceive = DEFAULT_NORECV_TIME; | | 1019 | sp->pp_max_noreceive = DEFAULT_NORECV_TIME; |
1023 | sp->pp_idle_timeout = 0; | | 1020 | sp->pp_idle_timeout = 0; |
1024 | memset(&sp->pp_seq[0], 0, sizeof(sp->pp_seq)); | | 1021 | memset(&sp->pp_seq[0], 0, sizeof(sp->pp_seq)); |
1025 | memset(&sp->pp_rseq[0], 0, sizeof(sp->pp_rseq)); | | 1022 | memset(&sp->pp_rseq[0], 0, sizeof(sp->pp_rseq)); |
1026 | sp->pp_auth_failures = 0; | | 1023 | sp->pp_auth_failures = 0; |
1027 | sp->pp_max_auth_fail = DEFAULT_MAX_AUTH_FAILURES; | | 1024 | sp->pp_max_auth_fail = DEFAULT_MAX_AUTH_FAILURES; |
1028 | sp->pp_phase = SPPP_PHASE_DEAD; | | 1025 | sp->pp_phase = SPPP_PHASE_DEAD; |
1029 | sp->pp_up = sppp_notify_up; | | 1026 | sp->pp_up = sppp_notify_up; |
1030 | sp->pp_down = sppp_notify_down; | | 1027 | sp->pp_down = sppp_notify_down; |
1031 | rw_init(&sp->pp_lock); | | 1028 | rw_init(&sp->pp_lock); |
1032 | | | 1029 | |
1033 | if_alloc_sadl(ifp); | | 1030 | if_alloc_sadl(ifp); |
1034 | | | 1031 | |
1035 | /* Lets not beat about the bush, we know we're down. */ | | 1032 | /* Lets not beat about the bush, we know we're down. */ |
1036 | ifp->if_link_state = LINK_STATE_DOWN; | | 1033 | ifp->if_link_state = LINK_STATE_DOWN; |
1037 | /* There is no media for PPP, but it's needed to report link status. */ | | 1034 | /* There is no media for PPP, but it's needed to report link status. */ |
1038 | ifmedia_init(&sp->pp_im, 0, sppp_mediachange, sppp_mediastatus); | | 1035 | ifmedia_init(&sp->pp_im, 0, sppp_mediachange, sppp_mediastatus); |
1039 | | | 1036 | |
1040 | memset(&sp->myauth, 0, sizeof sp->myauth); | | 1037 | memset(&sp->myauth, 0, sizeof sp->myauth); |
1041 | memset(&sp->hisauth, 0, sizeof sp->hisauth); | | 1038 | memset(&sp->hisauth, 0, sizeof sp->hisauth); |
1042 | SPPP_LOCK(sp, RW_WRITER); | | 1039 | SPPP_LOCK(sp, RW_WRITER); |
1043 | sppp_lcp_init(sp); | | 1040 | sppp_lcp_init(sp); |
1044 | sppp_ipcp_init(sp); | | 1041 | sppp_ipcp_init(sp); |
1045 | sppp_ipv6cp_init(sp); | | 1042 | sppp_ipv6cp_init(sp); |
1046 | sppp_pap_init(sp); | | 1043 | sppp_pap_init(sp); |
1047 | sppp_chap_init(sp); | | 1044 | sppp_chap_init(sp); |
1048 | SPPP_UNLOCK(sp); | | 1045 | SPPP_UNLOCK(sp); |
1049 | } | | 1046 | } |
1050 | | | 1047 | |
1051 | void | | 1048 | void |
1052 | sppp_detach(struct ifnet *ifp) | | 1049 | sppp_detach(struct ifnet *ifp) |
1053 | { | | 1050 | { |
1054 | struct sppp **q, *p, *sp = (struct sppp *) ifp; | | 1051 | struct sppp **q, *p, *sp = (struct sppp *) ifp; |
1055 | | | 1052 | |
1056 | /* Remove the entry from the keepalive list. */ | | 1053 | /* Remove the entry from the keepalive list. */ |
1057 | SPPPQ_LOCK(); | | 1054 | SPPPQ_LOCK(); |
1058 | for (q = &spppq; (p = *q); q = &p->pp_next) | | 1055 | for (q = &spppq; (p = *q); q = &p->pp_next) |
1059 | if (p == sp) { | | 1056 | if (p == sp) { |
1060 | *q = p->pp_next; | | 1057 | *q = p->pp_next; |
1061 | break; | | 1058 | break; |
1062 | } | | 1059 | } |
1063 | SPPPQ_UNLOCK(); | | 1060 | SPPPQ_UNLOCK(); |
1064 | | | 1061 | |
1065 | if (! spppq) { | | 1062 | if (! spppq) { |
1066 | /* Stop keepalive handler. */ | | 1063 | /* Stop keepalive handler. */ |
1067 | callout_stop(&keepalive_ch); | | 1064 | callout_stop(&keepalive_ch); |
1068 | mutex_obj_free(spppq_lock); | | 1065 | mutex_obj_free(spppq_lock); |
1069 | spppq_lock = NULL; | | 1066 | spppq_lock = NULL; |
1070 | } | | 1067 | } |
1071 | | | 1068 | |
1072 | SPPP_LOCK(sp, RW_WRITER); | | 1069 | SPPP_LOCK(sp, RW_WRITER); |
1073 | | | 1070 | |
1074 | /* to avoid workqueue enqueued */ | | 1071 | /* to avoid workqueue enqueued */ |
1075 | atomic_swap_uint(&sp->ipcp.update_addrs_enqueued, 1); | | 1072 | atomic_swap_uint(&sp->ipcp.update_addrs_enqueued, 1); |
1076 | workqueue_wait(sp->ipcp.update_addrs_wq, &sp->ipcp.update_addrs_wk); | | 1073 | workqueue_wait(sp->ipcp.update_addrs_wq, &sp->ipcp.update_addrs_wk); |
1077 | workqueue_destroy(sp->ipcp.update_addrs_wq); | | 1074 | workqueue_destroy(sp->ipcp.update_addrs_wq); |
1078 | pcq_destroy(sp->ipcp.update_addrs_q); | | 1075 | pcq_destroy(sp->ipcp.update_addrs_q); |
1079 | | | 1076 | |
1080 | callout_stop(&sp->ch[IDX_LCP]); | | 1077 | callout_stop(&sp->ch[IDX_LCP]); |
1081 | callout_stop(&sp->ch[IDX_IPCP]); | | 1078 | callout_stop(&sp->ch[IDX_IPCP]); |
1082 | callout_stop(&sp->ch[IDX_PAP]); | | 1079 | callout_stop(&sp->ch[IDX_PAP]); |
1083 | callout_stop(&sp->ch[IDX_CHAP]); | | 1080 | callout_stop(&sp->ch[IDX_CHAP]); |
1084 | #ifdef INET6 | | 1081 | #ifdef INET6 |
1085 | callout_stop(&sp->ch[IDX_IPV6CP]); | | 1082 | callout_stop(&sp->ch[IDX_IPV6CP]); |
1086 | #endif | | 1083 | #endif |
1087 | callout_stop(&sp->pap_my_to_ch); | | 1084 | callout_stop(&sp->pap_my_to_ch); |
1088 | | | 1085 | |
1089 | /* free authentication info */ | | 1086 | /* free authentication info */ |
1090 | if (sp->myauth.name) free(sp->myauth.name, M_DEVBUF); | | 1087 | if (sp->myauth.name) free(sp->myauth.name, M_DEVBUF); |
1091 | if (sp->myauth.secret) free(sp->myauth.secret, M_DEVBUF); | | 1088 | if (sp->myauth.secret) free(sp->myauth.secret, M_DEVBUF); |
1092 | if (sp->hisauth.name) free(sp->hisauth.name, M_DEVBUF); | | 1089 | if (sp->hisauth.name) free(sp->hisauth.name, M_DEVBUF); |
1093 | if (sp->hisauth.secret) free(sp->hisauth.secret, M_DEVBUF); | | 1090 | if (sp->hisauth.secret) free(sp->hisauth.secret, M_DEVBUF); |
1094 | SPPP_UNLOCK(sp); | | 1091 | SPPP_UNLOCK(sp); |
1095 | rw_destroy(&sp->pp_lock); | | 1092 | rw_destroy(&sp->pp_lock); |
1096 | | | 1093 | |
1097 | ifmedia_fini(&sp->pp_im); | | 1094 | ifmedia_fini(&sp->pp_im); |
1098 | } | | 1095 | } |
1099 | | | 1096 | |
1100 | /* | | 1097 | /* |
1101 | * Flush the interface output queue. | | 1098 | * Flush the interface output queue. |
1102 | */ | | 1099 | */ |
1103 | void | | 1100 | void |
1104 | sppp_flush(struct ifnet *ifp) | | 1101 | sppp_flush(struct ifnet *ifp) |
1105 | { | | 1102 | { |
1106 | struct sppp *sp = (struct sppp *) ifp; | | 1103 | struct sppp *sp = (struct sppp *) ifp; |
1107 | | | 1104 | |
1108 | SPPP_LOCK(sp, RW_WRITER); | | 1105 | SPPP_LOCK(sp, RW_WRITER); |
1109 | IFQ_PURGE(&sp->pp_if.if_snd); | | 1106 | IFQ_PURGE(&sp->pp_if.if_snd); |
1110 | IF_PURGE(&sp->pp_fastq); | | 1107 | IF_PURGE(&sp->pp_fastq); |
1111 | IF_PURGE(&sp->pp_cpq); | | 1108 | IF_PURGE(&sp->pp_cpq); |
1112 | SPPP_UNLOCK(sp); | | 1109 | SPPP_UNLOCK(sp); |
1113 | } | | 1110 | } |
1114 | | | 1111 | |
1115 | /* | | 1112 | /* |
1116 | * Check if the output queue is empty. | | 1113 | * Check if the output queue is empty. |
1117 | */ | | 1114 | */ |
1118 | int | | 1115 | int |
1119 | sppp_isempty(struct ifnet *ifp) | | 1116 | sppp_isempty(struct ifnet *ifp) |
1120 | { | | 1117 | { |
1121 | struct sppp *sp = (struct sppp *) ifp; | | 1118 | struct sppp *sp = (struct sppp *) ifp; |
1122 | int empty, s; | | 1119 | int empty, s; |
1123 | | | 1120 | |
1124 | s = splnet(); | | 1121 | s = splnet(); |
1125 | SPPP_LOCK(sp, RW_READER); | | 1122 | SPPP_LOCK(sp, RW_READER); |
1126 | empty = IF_IS_EMPTY(&sp->pp_fastq) && IF_IS_EMPTY(&sp->pp_cpq) && | | 1123 | empty = IF_IS_EMPTY(&sp->pp_fastq) && IF_IS_EMPTY(&sp->pp_cpq) && |
1127 | IFQ_IS_EMPTY(&sp->pp_if.if_snd); | | 1124 | IFQ_IS_EMPTY(&sp->pp_if.if_snd); |
1128 | SPPP_UNLOCK(sp); | | 1125 | SPPP_UNLOCK(sp); |
1129 | splx(s); | | 1126 | splx(s); |
1130 | return (empty); | | 1127 | return (empty); |
1131 | } | | 1128 | } |
1132 | | | 1129 | |
1133 | /* | | 1130 | /* |
1134 | * Get next packet to send. | | 1131 | * Get next packet to send. |
1135 | */ | | 1132 | */ |
1136 | struct mbuf * | | 1133 | struct mbuf * |
1137 | sppp_dequeue(struct ifnet *ifp) | | 1134 | sppp_dequeue(struct ifnet *ifp) |
1138 | { | | 1135 | { |
1139 | struct sppp *sp = (struct sppp *) ifp; | | 1136 | struct sppp *sp = (struct sppp *) ifp; |
1140 | struct mbuf *m; | | 1137 | struct mbuf *m; |
1141 | int s; | | 1138 | int s; |
1142 | | | 1139 | |
1143 | s = splnet(); | | 1140 | s = splnet(); |
1144 | SPPP_LOCK(sp, RW_WRITER); | | 1141 | SPPP_LOCK(sp, RW_WRITER); |
1145 | /* | | 1142 | /* |
1146 | * Process only the control protocol queue until we have at | | 1143 | * Process only the control protocol queue until we have at |
1147 | * least one NCP open. | | 1144 | * least one NCP open. |
1148 | * | | 1145 | * |
1149 | * Do always serve all three queues in Cisco mode. | | 1146 | * Do always serve all three queues in Cisco mode. |
1150 | */ | | 1147 | */ |
1151 | IF_DEQUEUE(&sp->pp_cpq, m); | | 1148 | IF_DEQUEUE(&sp->pp_cpq, m); |
1152 | if (m == NULL && | | 1149 | if (m == NULL && |
1153 | (sppp_ncp_check(sp) || (sp->pp_flags & PP_CISCO) != 0)) { | | 1150 | (sppp_ncp_check(sp) || (sp->pp_flags & PP_CISCO) != 0)) { |
1154 | IF_DEQUEUE(&sp->pp_fastq, m); | | 1151 | IF_DEQUEUE(&sp->pp_fastq, m); |
1155 | if (m == NULL) | | 1152 | if (m == NULL) |
1156 | IFQ_DEQUEUE(&sp->pp_if.if_snd, m); | | 1153 | IFQ_DEQUEUE(&sp->pp_if.if_snd, m); |
1157 | } | | 1154 | } |
1158 | SPPP_UNLOCK(sp); | | 1155 | SPPP_UNLOCK(sp); |
1159 | splx(s); | | 1156 | splx(s); |
1160 | return m; | | 1157 | return m; |
1161 | } | | 1158 | } |
1162 | | | 1159 | |
1163 | /* | | 1160 | /* |
1164 | * Process an ioctl request. Called on low priority level. | | 1161 | * Process an ioctl request. Called on low priority level. |
1165 | */ | | 1162 | */ |
1166 | int | | 1163 | int |
1167 | sppp_ioctl(struct ifnet *ifp, u_long cmd, void *data) | | 1164 | sppp_ioctl(struct ifnet *ifp, u_long cmd, void *data) |
1168 | { | | 1165 | { |
1169 | struct lwp *l = curlwp; /* XXX */ | | 1166 | struct lwp *l = curlwp; /* XXX */ |
1170 | struct ifreq *ifr = (struct ifreq *) data; | | 1167 | struct ifreq *ifr = (struct ifreq *) data; |
1171 | struct ifaddr *ifa = (struct ifaddr *) data; | | 1168 | struct ifaddr *ifa = (struct ifaddr *) data; |
1172 | struct sppp *sp = (struct sppp *) ifp; | | 1169 | struct sppp *sp = (struct sppp *) ifp; |
1173 | int s, error=0, going_up, going_down; | | 1170 | int s, error=0, going_up, going_down; |
1174 | u_short newmode; | | 1171 | u_short newmode; |
1175 | | | 1172 | |
1176 | s = splnet(); | | 1173 | s = splnet(); |
1177 | switch (cmd) { | | 1174 | switch (cmd) { |
1178 | case SIOCINITIFADDR: | | 1175 | case SIOCINITIFADDR: |
1179 | ifa->ifa_rtrequest = p2p_rtrequest; | | 1176 | ifa->ifa_rtrequest = p2p_rtrequest; |
1180 | break; | | 1177 | break; |
1181 | | | 1178 | |
1182 | case SIOCSIFFLAGS: | | 1179 | case SIOCSIFFLAGS: |
1183 | if ((error = ifioctl_common(ifp, cmd, data)) != 0) | | 1180 | if ((error = ifioctl_common(ifp, cmd, data)) != 0) |
1184 | break; | | 1181 | break; |
1185 | | | 1182 | |
1186 | SPPP_LOCK(sp, RW_WRITER); | | 1183 | SPPP_LOCK(sp, RW_WRITER); |
1187 | going_up = ifp->if_flags & IFF_UP && | | 1184 | going_up = ifp->if_flags & IFF_UP && |
1188 | (ifp->if_flags & IFF_RUNNING) == 0; | | 1185 | (ifp->if_flags & IFF_RUNNING) == 0; |
1189 | going_down = (ifp->if_flags & IFF_UP) == 0 && | | 1186 | going_down = (ifp->if_flags & IFF_UP) == 0 && |
1190 | ifp->if_flags & IFF_RUNNING; | | 1187 | ifp->if_flags & IFF_RUNNING; |
1191 | newmode = ifp->if_flags & (IFF_AUTO | IFF_PASSIVE); | | 1188 | newmode = ifp->if_flags & (IFF_AUTO | IFF_PASSIVE); |
1192 | if (newmode == (IFF_AUTO | IFF_PASSIVE)) { | | 1189 | if (newmode == (IFF_AUTO | IFF_PASSIVE)) { |
1193 | /* sanity */ | | 1190 | /* sanity */ |
1194 | newmode = IFF_PASSIVE; | | 1191 | newmode = IFF_PASSIVE; |
1195 | ifp->if_flags &= ~IFF_AUTO; | | 1192 | ifp->if_flags &= ~IFF_AUTO; |
1196 | } | | 1193 | } |
1197 | | | 1194 | |
1198 | if (going_up || going_down) { | | 1195 | if (going_up || going_down) { |
1199 | lcp.Close(sp); | | 1196 | lcp.Close(sp); |
1200 | } | | 1197 | } |
1201 | if (going_up && newmode == 0) { | | 1198 | if (going_up && newmode == 0) { |
1202 | /* neither auto-dial nor passive */ | | 1199 | /* neither auto-dial nor passive */ |
1203 | ifp->if_flags |= IFF_RUNNING; | | 1200 | ifp->if_flags |= IFF_RUNNING; |
1204 | if (!(sp->pp_flags & PP_CISCO)) | | 1201 | if (!(sp->pp_flags & PP_CISCO)) |
1205 | lcp.Open(sp); | | 1202 | lcp.Open(sp); |
1206 | } else if (going_down) { | | 1203 | } else if (going_down) { |
1207 | SPPP_UNLOCK(sp); | | 1204 | SPPP_UNLOCK(sp); |
1208 | sppp_flush(ifp); | | 1205 | sppp_flush(ifp); |
1209 | SPPP_LOCK(sp, RW_WRITER); | | 1206 | SPPP_LOCK(sp, RW_WRITER); |
1210 | | | 1207 | |
1211 | ifp->if_flags &= ~IFF_RUNNING; | | 1208 | ifp->if_flags &= ~IFF_RUNNING; |
1212 | } | | 1209 | } |
1213 | SPPP_UNLOCK(sp); | | 1210 | SPPP_UNLOCK(sp); |
1214 | break; | | 1211 | break; |
1215 | | | 1212 | |
1216 | case SIOCSIFMTU: | | 1213 | case SIOCSIFMTU: |
1217 | if (ifr->ifr_mtu < PPP_MINMRU || | | 1214 | if (ifr->ifr_mtu < PPP_MINMRU || |
1218 | ifr->ifr_mtu > sp->lcp.their_mru) { | | 1215 | ifr->ifr_mtu > sp->lcp.their_mru) { |
1219 | error = EINVAL; | | 1216 | error = EINVAL; |
1220 | break; | | 1217 | break; |
1221 | } | | 1218 | } |
1222 | /*FALLTHROUGH*/ | | 1219 | /*FALLTHROUGH*/ |
1223 | case SIOCGIFMTU: | | 1220 | case SIOCGIFMTU: |
1224 | if ((error = ifioctl_common(ifp, cmd, data)) == ENETRESET) | | 1221 | if ((error = ifioctl_common(ifp, cmd, data)) == ENETRESET) |
1225 | error = 0; | | 1222 | error = 0; |
1226 | break; | | 1223 | break; |
1227 | case SIOCADDMULTI: | | 1224 | case SIOCADDMULTI: |
1228 | case SIOCDELMULTI: | | 1225 | case SIOCDELMULTI: |
1229 | break; | | 1226 | break; |
1230 | | | 1227 | |
1231 | case SPPPSETAUTHCFG: | | 1228 | case SPPPSETAUTHCFG: |
1232 | case SPPPSETLCPCFG: | | 1229 | case SPPPSETLCPCFG: |
1233 | case SPPPSETIDLETO: | | 1230 | case SPPPSETIDLETO: |
1234 | case SPPPSETAUTHFAILURE: | | 1231 | case SPPPSETAUTHFAILURE: |
1235 | case SPPPSETDNSOPTS: | | 1232 | case SPPPSETDNSOPTS: |
1236 | case SPPPSETKEEPALIVE: | | 1233 | case SPPPSETKEEPALIVE: |
1237 | #if defined(COMPAT_50) || defined(MODULAR) | | 1234 | #if defined(COMPAT_50) || defined(MODULAR) |
1238 | case __SPPPSETIDLETO50: | | 1235 | case __SPPPSETIDLETO50: |
1239 | case __SPPPSETKEEPALIVE50: | | 1236 | case __SPPPSETKEEPALIVE50: |
1240 | #endif /* COMPAT_50 || MODULAR */ | | 1237 | #endif /* COMPAT_50 || MODULAR */ |
1241 | error = kauth_authorize_network(l->l_cred, | | 1238 | error = kauth_authorize_network(l->l_cred, |
1242 | KAUTH_NETWORK_INTERFACE, | | 1239 | KAUTH_NETWORK_INTERFACE, |
1243 | KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, (void *)cmd, | | 1240 | KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, (void *)cmd, |
1244 | NULL); | | 1241 | NULL); |
1245 | if (error) | | 1242 | if (error) |
1246 | break; | | 1243 | break; |
1247 | error = sppp_params(sp, cmd, data); | | 1244 | error = sppp_params(sp, cmd, data); |
1248 | break; | | 1245 | break; |
1249 | | | 1246 | |
1250 | case SPPPGETAUTHCFG: | | 1247 | case SPPPGETAUTHCFG: |
1251 | case SPPPGETLCPCFG: | | 1248 | case SPPPGETLCPCFG: |
1252 | case SPPPGETAUTHFAILURES: | | 1249 | case SPPPGETAUTHFAILURES: |
1253 | error = kauth_authorize_network(l->l_cred, | | 1250 | error = kauth_authorize_network(l->l_cred, |
1254 | KAUTH_NETWORK_INTERFACE, | | 1251 | KAUTH_NETWORK_INTERFACE, |
1255 | KAUTH_REQ_NETWORK_INTERFACE_GETPRIV, ifp, (void *)cmd, | | 1252 | KAUTH_REQ_NETWORK_INTERFACE_GETPRIV, ifp, (void *)cmd, |
1256 | NULL); | | 1253 | NULL); |
1257 | if (error) | | 1254 | if (error) |
1258 | break; | | 1255 | break; |
1259 | error = sppp_params(sp, cmd, data); | | 1256 | error = sppp_params(sp, cmd, data); |
1260 | break; | | 1257 | break; |
1261 | | | 1258 | |
1262 | case SPPPGETSTATUS: | | 1259 | case SPPPGETSTATUS: |
1263 | case SPPPGETSTATUSNCP: | | 1260 | case SPPPGETSTATUSNCP: |
1264 | case SPPPGETIDLETO: | | 1261 | case SPPPGETIDLETO: |
1265 | case SPPPGETDNSOPTS: | | 1262 | case SPPPGETDNSOPTS: |
1266 | case SPPPGETDNSADDRS: | | 1263 | case SPPPGETDNSADDRS: |
1267 | case SPPPGETKEEPALIVE: | | 1264 | case SPPPGETKEEPALIVE: |
1268 | #if defined(COMPAT_50) || defined(MODULAR) | | 1265 | #if defined(COMPAT_50) || defined(MODULAR) |
1269 | case __SPPPGETIDLETO50: | | 1266 | case __SPPPGETIDLETO50: |
1270 | case __SPPPGETKEEPALIVE50: | | 1267 | case __SPPPGETKEEPALIVE50: |
1271 | #endif /* COMPAT_50 || MODULAR */ | | 1268 | #endif /* COMPAT_50 || MODULAR */ |
1272 | error = sppp_params(sp, cmd, data); | | 1269 | error = sppp_params(sp, cmd, data); |
1273 | break; | | 1270 | break; |
1274 | | | 1271 | |
1275 | case SIOCGIFMEDIA: | | 1272 | case SIOCGIFMEDIA: |
1276 | error = ifmedia_ioctl(ifp, ifr, &sp->pp_im, cmd); | | 1273 | error = ifmedia_ioctl(ifp, ifr, &sp->pp_im, cmd); |
1277 | break; | | 1274 | break; |
1278 | | | 1275 | |
1279 | default: | | 1276 | default: |
1280 | error = ifioctl_common(ifp, cmd, data); | | 1277 | error = ifioctl_common(ifp, cmd, data); |
1281 | break; | | 1278 | break; |
1282 | } | | 1279 | } |
1283 | splx(s); | | 1280 | splx(s); |
1284 | return (error); | | 1281 | return (error); |
1285 | } | | 1282 | } |
1286 | | | 1283 | |
1287 | | | 1284 | |
1288 | /* | | 1285 | /* |
1289 | * Cisco framing implementation. | | 1286 | * Cisco framing implementation. |
1290 | */ | | 1287 | */ |
1291 | | | 1288 | |
1292 | /* | | 1289 | /* |
1293 | * Handle incoming Cisco keepalive protocol packets. | | 1290 | * Handle incoming Cisco keepalive protocol packets. |
1294 | */ | | 1291 | */ |
1295 | static void | | 1292 | static void |
1296 | sppp_cisco_input(struct sppp *sp, struct mbuf *m) | | 1293 | sppp_cisco_input(struct sppp *sp, struct mbuf *m) |
1297 | { | | 1294 | { |
1298 | STDDCL; | | 1295 | STDDCL; |
1299 | struct cisco_packet *h; | | 1296 | struct cisco_packet *h; |
1300 | #ifdef INET | | 1297 | #ifdef INET |
1301 | uint32_t me, mymask = 0; /* XXX: GCC */ | | 1298 | uint32_t me, mymask = 0; /* XXX: GCC */ |
1302 | #endif | | 1299 | #endif |
1303 | | | 1300 | |
1304 | SPPP_LOCK(sp, RW_WRITER); | | 1301 | SPPP_LOCK(sp, RW_WRITER); |
1305 | | | 1302 | |
1306 | if (m->m_pkthdr.len < CISCO_PACKET_LEN) { | | 1303 | if (m->m_pkthdr.len < CISCO_PACKET_LEN) { |
1307 | if (debug) | | 1304 | if (debug) |
1308 | log(LOG_DEBUG, | | 1305 | log(LOG_DEBUG, |
1309 | "%s: cisco invalid packet length: %d bytes\n", | | 1306 | "%s: cisco invalid packet length: %d bytes\n", |
1310 | ifp->if_xname, m->m_pkthdr.len); | | 1307 | ifp->if_xname, m->m_pkthdr.len); |
1311 | SPPP_UNLOCK(sp); | | 1308 | SPPP_UNLOCK(sp); |
1312 | return; | | 1309 | return; |
1313 | } | | 1310 | } |
1314 | h = mtod(m, struct cisco_packet *); | | 1311 | h = mtod(m, struct cisco_packet *); |
1315 | if (debug) | | 1312 | if (debug) |
1316 | log(LOG_DEBUG, | | 1313 | log(LOG_DEBUG, |
1317 | "%s: cisco input: %d bytes " | | 1314 | "%s: cisco input: %d bytes " |
1318 | "<0x%x 0x%x 0x%x 0x%x 0x%x-0x%x>\n", | | 1315 | "<0x%x 0x%x 0x%x 0x%x 0x%x-0x%x>\n", |
1319 | ifp->if_xname, m->m_pkthdr.len, | | 1316 | ifp->if_xname, m->m_pkthdr.len, |
1320 | ntohl(h->type), h->par1, h->par2, (u_int)h->rel, | | 1317 | ntohl(h->type), h->par1, h->par2, (u_int)h->rel, |
1321 | (u_int)h->time0, (u_int)h->time1); | | 1318 | (u_int)h->time0, (u_int)h->time1); |
1322 | switch (ntohl(h->type)) { | | 1319 | switch (ntohl(h->type)) { |
1323 | default: | | 1320 | default: |
1324 | if (debug) | | 1321 | if (debug) |
1325 | addlog("%s: cisco unknown packet type: 0x%x\n", | | 1322 | addlog("%s: cisco unknown packet type: 0x%x\n", |
1326 | ifp->if_xname, ntohl(h->type)); | | 1323 | ifp->if_xname, ntohl(h->type)); |
1327 | break; | | 1324 | break; |
1328 | case CISCO_ADDR_REPLY: | | 1325 | case CISCO_ADDR_REPLY: |
1329 | /* Reply on address request, ignore */ | | 1326 | /* Reply on address request, ignore */ |
1330 | break; | | 1327 | break; |
1331 | case CISCO_KEEPALIVE_REQ: | | 1328 | case CISCO_KEEPALIVE_REQ: |
1332 | sp->pp_alivecnt = 0; | | 1329 | sp->pp_alivecnt = 0; |
1333 | sp->pp_rseq[IDX_LCP] = ntohl(h->par1); | | 1330 | sp->pp_rseq[IDX_LCP] = ntohl(h->par1); |
1334 | if (sp->pp_seq[IDX_LCP] == sp->pp_rseq[IDX_LCP]) { | | 1331 | if (sp->pp_seq[IDX_LCP] == sp->pp_rseq[IDX_LCP]) { |
1335 | /* Local and remote sequence numbers are equal. | | 1332 | /* Local and remote sequence numbers are equal. |
1336 | * Probably, the line is in loopback mode. */ | | 1333 | * Probably, the line is in loopback mode. */ |
1337 | if (sp->pp_loopcnt >= LOOPALIVECNT) { | | 1334 | if (sp->pp_loopcnt >= LOOPALIVECNT) { |
1338 | printf ("%s: loopback\n", | | 1335 | printf ("%s: loopback\n", |
1339 | ifp->if_xname); | | 1336 | ifp->if_xname); |
1340 | sp->pp_loopcnt = 0; | | 1337 | sp->pp_loopcnt = 0; |
1341 | if (ifp->if_flags & IFF_UP) { | | 1338 | if (ifp->if_flags & IFF_UP) { |
1342 | SPPP_UNLOCK(sp); | | 1339 | SPPP_UNLOCK(sp); |
1343 | if_down(ifp); | | 1340 | if_down(ifp); |
1344 | SPPP_LOCK(sp, RW_WRITER); | | 1341 | SPPP_LOCK(sp, RW_WRITER); |
1345 | | | 1342 | |
1346 | IF_PURGE(&sp->pp_cpq); | | 1343 | IF_PURGE(&sp->pp_cpq); |
1347 | } | | 1344 | } |
1348 | } | | 1345 | } |
1349 | ++sp->pp_loopcnt; | | 1346 | ++sp->pp_loopcnt; |
1350 | | | 1347 | |
1351 | /* Generate new local sequence number */ | | 1348 | /* Generate new local sequence number */ |
1352 | sp->pp_seq[IDX_LCP] = cprng_fast32(); | | 1349 | sp->pp_seq[IDX_LCP] = cprng_fast32(); |
1353 | break; | | 1350 | break; |
1354 | } | | 1351 | } |
1355 | sp->pp_loopcnt = 0; | | 1352 | sp->pp_loopcnt = 0; |
1356 | if (! (ifp->if_flags & IFF_UP) && | | 1353 | if (! (ifp->if_flags & IFF_UP) && |
1357 | (ifp->if_flags & IFF_RUNNING)) { | | 1354 | (ifp->if_flags & IFF_RUNNING)) { |
1358 | SPPP_UNLOCK(sp); | | 1355 | SPPP_UNLOCK(sp); |
1359 | if_up(ifp); | | 1356 | if_up(ifp); |
1360 | SPPP_LOCK(sp, RW_WRITER); | | 1357 | SPPP_LOCK(sp, RW_WRITER); |
1361 | } | | 1358 | } |
1362 | break; | | 1359 | break; |
1363 | case CISCO_ADDR_REQ: | | 1360 | case CISCO_ADDR_REQ: |
1364 | #ifdef INET | | 1361 | #ifdef INET |
1365 | sppp_get_ip_addrs(sp, &me, 0, &mymask); | | 1362 | sppp_get_ip_addrs(sp, &me, 0, &mymask); |
1366 | if (me != 0L) | | 1363 | if (me != 0L) |
1367 | sppp_cisco_send(sp, CISCO_ADDR_REPLY, me, mymask); | | 1364 | sppp_cisco_send(sp, CISCO_ADDR_REPLY, me, mymask); |
1368 | #endif | | 1365 | #endif |
1369 | break; | | 1366 | break; |
1370 | } | | 1367 | } |
1371 | SPPP_UNLOCK(sp); | | 1368 | SPPP_UNLOCK(sp); |
1372 | } | | 1369 | } |
1373 | | | 1370 | |
1374 | /* | | 1371 | /* |
1375 | * Send Cisco keepalive packet. | | 1372 | * Send Cisco keepalive packet. |
1376 | */ | | 1373 | */ |
1377 | static void | | 1374 | static void |
1378 | sppp_cisco_send(struct sppp *sp, int type, int32_t par1, int32_t par2) | | 1375 | sppp_cisco_send(struct sppp *sp, int type, int32_t par1, int32_t par2) |
1379 | { | | 1376 | { |
1380 | STDDCL; | | 1377 | STDDCL; |
1381 | struct ppp_header *h; | | 1378 | struct ppp_header *h; |
1382 | struct cisco_packet *ch; | | 1379 | struct cisco_packet *ch; |
1383 | struct mbuf *m; | | 1380 | struct mbuf *m; |
1384 | uint32_t t; | | 1381 | uint32_t t; |
1385 | | | 1382 | |
1386 | KASSERT(SPPP_WLOCKED(sp)); | | 1383 | KASSERT(SPPP_WLOCKED(sp)); |
1387 | | | 1384 | |
1388 | t = time_uptime * 1000; | | 1385 | t = time_uptime * 1000; |
1389 | MGETHDR(m, M_DONTWAIT, MT_DATA); | | 1386 | MGETHDR(m, M_DONTWAIT, MT_DATA); |
1390 | if (! m) | | 1387 | if (! m) |
1391 | return; | | 1388 | return; |
1392 | m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + CISCO_PACKET_LEN; | | 1389 | m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + CISCO_PACKET_LEN; |
1393 | m_reset_rcvif(m); | | 1390 | m_reset_rcvif(m); |
1394 | | | 1391 | |
1395 | h = mtod(m, struct ppp_header *); | | 1392 | h = mtod(m, struct ppp_header *); |
1396 | h->address = CISCO_MULTICAST; | | 1393 | h->address = CISCO_MULTICAST; |
1397 | h->control = 0; | | 1394 | h->control = 0; |
1398 | h->protocol = htons(CISCO_KEEPALIVE); | | 1395 | h->protocol = htons(CISCO_KEEPALIVE); |
1399 | | | 1396 | |
1400 | ch = (struct cisco_packet *)(h + 1); | | 1397 | ch = (struct cisco_packet *)(h + 1); |
1401 | ch->type = htonl(type); | | 1398 | ch->type = htonl(type); |
1402 | ch->par1 = htonl(par1); | | 1399 | ch->par1 = htonl(par1); |
1403 | ch->par2 = htonl(par2); | | 1400 | ch->par2 = htonl(par2); |
1404 | ch->rel = -1; | | 1401 | ch->rel = -1; |
1405 | | | 1402 | |
1406 | ch->time0 = htons((u_short)(t >> 16)); | | 1403 | ch->time0 = htons((u_short)(t >> 16)); |
1407 | ch->time1 = htons((u_short) t); | | 1404 | ch->time1 = htons((u_short) t); |
1408 | | | 1405 | |
1409 | if (debug) | | 1406 | if (debug) |
1410 | log(LOG_DEBUG, | | 1407 | log(LOG_DEBUG, |
1411 | "%s: cisco output: <0x%x 0x%x 0x%x 0x%x 0x%x-0x%x>\n", | | 1408 | "%s: cisco output: <0x%x 0x%x 0x%x 0x%x 0x%x-0x%x>\n", |
1412 | ifp->if_xname, ntohl(ch->type), ch->par1, | | 1409 | ifp->if_xname, ntohl(ch->type), ch->par1, |
1413 | ch->par2, (u_int)ch->rel, (u_int)ch->time0, | | 1410 | ch->par2, (u_int)ch->rel, (u_int)ch->time0, |
1414 | (u_int)ch->time1); | | 1411 | (u_int)ch->time1); |
1415 | | | 1412 | |
1416 | if (IF_QFULL(&sp->pp_cpq)) { | | 1413 | if (IF_QFULL(&sp->pp_cpq)) { |
1417 | IF_DROP(&sp->pp_fastq); | | 1414 | IF_DROP(&sp->pp_fastq); |
1418 | IF_DROP(&ifp->if_snd); | | 1415 | IF_DROP(&ifp->if_snd); |
1419 | m_freem(m); | | 1416 | m_freem(m); |
1420 | if_statinc(ifp, if_oerrors); | | 1417 | if_statinc(ifp, if_oerrors); |
1421 | return; | | 1418 | return; |
1422 | } | | 1419 | } |
1423 | | | 1420 | |
1424 | if_statadd(ifp, if_obytes, m->m_pkthdr.len + sp->pp_framebytes); | | 1421 | if_statadd(ifp, if_obytes, m->m_pkthdr.len + sp->pp_framebytes); |
1425 | IF_ENQUEUE(&sp->pp_cpq, m); | | 1422 | IF_ENQUEUE(&sp->pp_cpq, m); |
1426 | | | 1423 | |
1427 | if (! (ifp->if_flags & IFF_OACTIVE)) { | | 1424 | if (! (ifp->if_flags & IFF_OACTIVE)) { |
1428 | SPPP_UNLOCK(sp); | | 1425 | SPPP_UNLOCK(sp); |
1429 | if_start_lock(ifp); | | 1426 | if_start_lock(ifp); |
1430 | SPPP_LOCK(sp, RW_WRITER); | | 1427 | SPPP_LOCK(sp, RW_WRITER); |
1431 | } | | 1428 | } |
1432 | } | | 1429 | } |
1433 | | | 1430 | |
1434 | /* | | 1431 | /* |
1435 | * PPP protocol implementation. | | 1432 | * PPP protocol implementation. |
1436 | */ | | 1433 | */ |
1437 | | | 1434 | |
1438 | /* | | 1435 | /* |
1439 | * Send PPP control protocol packet. | | 1436 | * Send PPP control protocol packet. |
1440 | */ | | 1437 | */ |
1441 | static void | | 1438 | static void |
1442 | sppp_cp_send(struct sppp *sp, u_short proto, u_char type, | | 1439 | sppp_cp_send(struct sppp *sp, u_short proto, u_char type, |
1443 | u_char ident, u_short len, void *data) | | 1440 | u_char ident, u_short len, void *data) |
1444 | { | | 1441 | { |
1445 | STDDCL; | | 1442 | STDDCL; |
1446 | struct lcp_header *lh; | | 1443 | struct lcp_header *lh; |
1447 | struct mbuf *m; | | 1444 | struct mbuf *m; |
1448 | size_t pkthdrlen; | | 1445 | size_t pkthdrlen; |
1449 | | | 1446 | |
1450 | KASSERT(SPPP_WLOCKED(sp)); | | 1447 | KASSERT(SPPP_WLOCKED(sp)); |
1451 | | | 1448 | |
1452 | pkthdrlen = (sp->pp_flags & PP_NOFRAMING) ? 2 : PPP_HEADER_LEN; | | 1449 | pkthdrlen = (sp->pp_flags & PP_NOFRAMING) ? 2 : PPP_HEADER_LEN; |
1453 | | | 1450 | |
1454 | if (len > MHLEN - pkthdrlen - LCP_HEADER_LEN) | | 1451 | if (len > MHLEN - pkthdrlen - LCP_HEADER_LEN) |
1455 | len = MHLEN - pkthdrlen - LCP_HEADER_LEN; | | 1452 | len = MHLEN - pkthdrlen - LCP_HEADER_LEN; |
1456 | MGETHDR(m, M_DONTWAIT, MT_DATA); | | 1453 | MGETHDR(m, M_DONTWAIT, MT_DATA); |
1457 | if (! m) { | | 1454 | if (! m) { |
1458 | return; | | 1455 | return; |
1459 | } | | 1456 | } |
1460 | m->m_pkthdr.len = m->m_len = pkthdrlen + LCP_HEADER_LEN + len; | | 1457 | m->m_pkthdr.len = m->m_len = pkthdrlen + LCP_HEADER_LEN + len; |
1461 | m_reset_rcvif(m); | | 1458 | m_reset_rcvif(m); |
1462 | | | 1459 | |
1463 | if (sp->pp_flags & PP_NOFRAMING) { | | 1460 | if (sp->pp_flags & PP_NOFRAMING) { |
1464 | *mtod(m, uint16_t *) = htons(proto); | | 1461 | *mtod(m, uint16_t *) = htons(proto); |
1465 | lh = (struct lcp_header *)(mtod(m, uint8_t *) + 2); | | 1462 | lh = (struct lcp_header *)(mtod(m, uint8_t *) + 2); |
1466 | } else { | | 1463 | } else { |
1467 | struct ppp_header *h; | | 1464 | struct ppp_header *h; |
1468 | h = mtod(m, struct ppp_header *); | | 1465 | h = mtod(m, struct ppp_header *); |
1469 | h->address = PPP_ALLSTATIONS; /* broadcast address */ | | 1466 | h->address = PPP_ALLSTATIONS; /* broadcast address */ |
1470 | h->control = PPP_UI; /* Unnumbered Info */ | | 1467 | h->control = PPP_UI; /* Unnumbered Info */ |
1471 | h->protocol = htons(proto); /* Link Control Protocol */ | | 1468 | h->protocol = htons(proto); /* Link Control Protocol */ |
1472 | lh = (struct lcp_header *)(h + 1); | | 1469 | lh = (struct lcp_header *)(h + 1); |
1473 | } | | 1470 | } |
1474 | lh->type = type; | | 1471 | lh->type = type; |
1475 | lh->ident = ident; | | 1472 | lh->ident = ident; |
1476 | lh->len = htons(LCP_HEADER_LEN + len); | | 1473 | lh->len = htons(LCP_HEADER_LEN + len); |
1477 | if (len) | | 1474 | if (len) |
1478 | memcpy(lh + 1, data, len); | | 1475 | memcpy(lh + 1, data, len); |
1479 | | | 1476 | |
1480 | if (debug) { | | 1477 | if (debug) { |
1481 | log(LOG_DEBUG, "%s: %s output <%s id=0x%x len=%d", | | 1478 | log(LOG_DEBUG, "%s: %s output <%s id=0x%x len=%d", |
1482 | ifp->if_xname, | | 1479 | ifp->if_xname, |
1483 | sppp_proto_name(proto), | | 1480 | sppp_proto_name(proto), |
1484 | sppp_cp_type_name(lh->type), lh->ident, ntohs(lh->len)); | | 1481 | sppp_cp_type_name(lh->type), lh->ident, ntohs(lh->len)); |
1485 | if (len) | | 1482 | if (len) |
1486 | sppp_print_bytes((u_char *)(lh + 1), len); | | 1483 | sppp_print_bytes((u_char *)(lh + 1), len); |
1487 | addlog(">\n"); | | 1484 | addlog(">\n"); |
1488 | } | | 1485 | } |
1489 | if (IF_QFULL(&sp->pp_cpq)) { | | 1486 | if (IF_QFULL(&sp->pp_cpq)) { |
1490 | IF_DROP(&sp->pp_fastq); | | 1487 | IF_DROP(&sp->pp_fastq); |
1491 | IF_DROP(&ifp->if_snd); | | 1488 | IF_DROP(&ifp->if_snd); |
1492 | m_freem(m); | | 1489 | m_freem(m); |
1493 | if_statinc(ifp, if_oerrors); | | 1490 | if_statinc(ifp, if_oerrors); |
1494 | return; | | 1491 | return; |
1495 | } | | 1492 | } |
1496 | | | 1493 | |
1497 | if_statadd(ifp, if_obytes, m->m_pkthdr.len + sp->pp_framebytes); | | 1494 | if_statadd(ifp, if_obytes, m->m_pkthdr.len + sp->pp_framebytes); |
1498 | IF_ENQUEUE(&sp->pp_cpq, m); | | 1495 | IF_ENQUEUE(&sp->pp_cpq, m); |
1499 | | | 1496 | |
1500 | | | 1497 | |
1501 | if (! (ifp->if_flags & IFF_OACTIVE)) { | | 1498 | if (! (ifp->if_flags & IFF_OACTIVE)) { |
1502 | SPPP_UNLOCK(sp); | | 1499 | SPPP_UNLOCK(sp); |
1503 | if_start_lock(ifp); | | 1500 | if_start_lock(ifp); |
1504 | SPPP_LOCK(sp, RW_WRITER); | | 1501 | SPPP_LOCK(sp, RW_WRITER); |
1505 | } | | 1502 | } |
1506 | } | | 1503 | } |
1507 | | | 1504 | |
1508 | /* | | 1505 | /* |
1509 | * Handle incoming PPP control protocol packets. | | 1506 | * Handle incoming PPP control protocol packets. |
1510 | */ | | 1507 | */ |
1511 | static void | | 1508 | static void |
1512 | sppp_cp_input(const struct cp *cp, struct sppp *sp, struct mbuf *m) | | 1509 | sppp_cp_input(const struct cp *cp, struct sppp *sp, struct mbuf *m) |
1513 | { | | 1510 | { |
1514 | STDDCL; | | 1511 | STDDCL; |
1515 | struct lcp_header *h; | | 1512 | struct lcp_header *h; |
1516 | int printlen, len = m->m_pkthdr.len; | | 1513 | int printlen, len = m->m_pkthdr.len; |
1517 | int rv; | | 1514 | int rv; |
1518 | u_char *p; | | 1515 | u_char *p; |
1519 | uint32_t u32; | | 1516 | uint32_t u32; |
1520 | | | 1517 | |
1521 | SPPP_LOCK(sp, RW_WRITER); | | 1518 | SPPP_LOCK(sp, RW_WRITER); |
1522 | | | 1519 | |
1523 | if (len < 4) { | | 1520 | if (len < 4) { |
1524 | if (debug) | | 1521 | if (debug) |
1525 | log(LOG_DEBUG, | | 1522 | log(LOG_DEBUG, |
1526 | "%s: %s invalid packet length: %d bytes\n", | | 1523 | "%s: %s invalid packet length: %d bytes\n", |
1527 | ifp->if_xname, cp->name, len); | | 1524 | ifp->if_xname, cp->name, len); |
1528 | SPPP_UNLOCK(sp); | | 1525 | SPPP_UNLOCK(sp); |
1529 | return; | | 1526 | return; |
1530 | } | | 1527 | } |
1531 | h = mtod(m, struct lcp_header *); | | 1528 | h = mtod(m, struct lcp_header *); |
1532 | if (debug) { | | 1529 | if (debug) { |
1533 | printlen = ntohs(h->len); | | 1530 | printlen = ntohs(h->len); |
1534 | log(LOG_DEBUG, | | 1531 | log(LOG_DEBUG, |
1535 | "%s: %s input(%s): <%s id=0x%x len=%d", | | 1532 | "%s: %s input(%s): <%s id=0x%x len=%d", |
1536 | ifp->if_xname, cp->name, | | 1533 | ifp->if_xname, cp->name, |
1537 | sppp_state_name(sp->state[cp->protoidx]), | | 1534 | sppp_state_name(sp->state[cp->protoidx]), |
1538 | sppp_cp_type_name(h->type), h->ident, printlen); | | 1535 | sppp_cp_type_name(h->type), h->ident, printlen); |
1539 | if (len < printlen) | | 1536 | if (len < printlen) |
1540 | printlen = len; | | 1537 | printlen = len; |
1541 | if (printlen > 4) | | 1538 | if (printlen > 4) |
1542 | sppp_print_bytes((u_char *)(h + 1), printlen - 4); | | 1539 | sppp_print_bytes((u_char *)(h + 1), printlen - 4); |
1543 | addlog(">\n"); | | 1540 | addlog(">\n"); |
1544 | } | | 1541 | } |
1545 | if (len > ntohs(h->len)) | | 1542 | if (len > ntohs(h->len)) |
1546 | len = ntohs(h->len); | | 1543 | len = ntohs(h->len); |
1547 | p = (u_char *)(h + 1); | | 1544 | p = (u_char *)(h + 1); |
1548 | switch (h->type) { | | 1545 | switch (h->type) { |
1549 | case CONF_REQ: | | 1546 | case CONF_REQ: |
1550 | if (len < 4) { | | 1547 | if (len < 4) { |
1551 | if (debug) | | 1548 | if (debug) |
1552 | addlog("%s: %s invalid conf-req length %d\n", | | 1549 | addlog("%s: %s invalid conf-req length %d\n", |
1553 | ifp->if_xname, cp->name, | | 1550 | ifp->if_xname, cp->name, |
1554 | len); | | 1551 | len); |
1555 | if_statinc(ifp, if_ierrors); | | 1552 | if_statinc(ifp, if_ierrors); |
1556 | break; | | 1553 | break; |
1557 | } | | 1554 | } |
1558 | /* handle states where RCR doesn't get a SCA/SCN */ | | 1555 | /* handle states where RCR doesn't get a SCA/SCN */ |
1559 | switch (sp->state[cp->protoidx]) { | | 1556 | switch (sp->state[cp->protoidx]) { |
1560 | case STATE_CLOSING: | | 1557 | case STATE_CLOSING: |
1561 | case STATE_STOPPING: | | 1558 | case STATE_STOPPING: |
1562 | SPPP_UNLOCK(sp); | | 1559 | SPPP_UNLOCK(sp); |
1563 | return; | | 1560 | return; |
1564 | case STATE_CLOSED: | | 1561 | case STATE_CLOSED: |
1565 | sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, | | 1562 | sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, |
1566 | 0, 0); | | 1563 | 0, 0); |
1567 | SPPP_UNLOCK(sp); | | 1564 | SPPP_UNLOCK(sp); |
1568 | return; | | 1565 | return; |
1569 | } | | 1566 | } |
1570 | rv = (cp->RCR)(sp, h, len); | | 1567 | rv = (cp->RCR)(sp, h, len); |
1571 | if (rv < 0) { | | 1568 | if (rv < 0) { |
1572 | /* fatal error, shut down */ | | 1569 | /* fatal error, shut down */ |
1573 | (cp->tld)(sp); | | 1570 | (cp->tld)(sp); |
1574 | sppp_lcp_tlf(sp); | | 1571 | sppp_lcp_tlf(sp); |
1575 | SPPP_UNLOCK(sp); | | 1572 | SPPP_UNLOCK(sp); |
1576 | return; | | 1573 | return; |
1577 | } | | 1574 | } |
1578 | switch (sp->state[cp->protoidx]) { | | 1575 | switch (sp->state[cp->protoidx]) { |
1579 | case STATE_OPENED: | | 1576 | case STATE_OPENED: |
1580 | (cp->tld)(sp); | | 1577 | (cp->tld)(sp); |
1581 | (cp->scr)(sp); | | 1578 | (cp->scr)(sp); |
1582 | /* fall through... */ | | 1579 | /* fall through... */ |
1583 | case STATE_ACK_SENT: | | 1580 | case STATE_ACK_SENT: |
1584 | case STATE_REQ_SENT: | | 1581 | case STATE_REQ_SENT: |
1585 | sppp_cp_change_state(cp, sp, rv? | | 1582 | sppp_cp_change_state(cp, sp, rv? |
1586 | STATE_ACK_SENT: STATE_REQ_SENT); | | 1583 | STATE_ACK_SENT: STATE_REQ_SENT); |
1587 | break; | | 1584 | break; |
1588 | case STATE_STOPPED: | | 1585 | case STATE_STOPPED: |
1589 | sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; | | 1586 | sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; |
1590 | (cp->scr)(sp); | | 1587 | (cp->scr)(sp); |
1591 | sppp_cp_change_state(cp, sp, rv? | | 1588 | sppp_cp_change_state(cp, sp, rv? |
1592 | STATE_ACK_SENT: STATE_REQ_SENT); | | 1589 | STATE_ACK_SENT: STATE_REQ_SENT); |
1593 | break; | | 1590 | break; |
1594 | case STATE_ACK_RCVD: | | 1591 | case STATE_ACK_RCVD: |
1595 | if (rv) { | | 1592 | if (rv) { |
1596 | sppp_cp_change_state(cp, sp, STATE_OPENED); | | 1593 | sppp_cp_change_state(cp, sp, STATE_OPENED); |
1597 | if (debug) | | 1594 | if (debug) |
1598 | log(LOG_DEBUG, "%s: %s tlu\n", | | 1595 | log(LOG_DEBUG, "%s: %s tlu\n", |
1599 | ifp->if_xname, | | 1596 | ifp->if_xname, |
1600 | cp->name); | | 1597 | cp->name); |
1601 | (cp->tlu)(sp); | | 1598 | (cp->tlu)(sp); |
1602 | } else | | 1599 | } else |
1603 | sppp_cp_change_state(cp, sp, STATE_ACK_RCVD); | | 1600 | sppp_cp_change_state(cp, sp, STATE_ACK_RCVD); |
1604 | break; | | 1601 | break; |
1605 | default: | | 1602 | default: |
1606 | printf("%s: %s illegal %s in state %s\n", | | 1603 | printf("%s: %s illegal %s in state %s\n", |
1607 | ifp->if_xname, cp->name, | | 1604 | ifp->if_xname, cp->name, |
1608 | sppp_cp_type_name(h->type), | | 1605 | sppp_cp_type_name(h->type), |
1609 | sppp_state_name(sp->state[cp->protoidx])); | | 1606 | sppp_state_name(sp->state[cp->protoidx])); |
1610 | if_statinc(ifp, if_ierrors); | | 1607 | if_statinc(ifp, if_ierrors); |
1611 | } | | 1608 | } |
1612 | break; | | 1609 | break; |
1613 | case CONF_ACK: | | 1610 | case CONF_ACK: |
1614 | if (h->ident != sp->confid[cp->protoidx]) { | | 1611 | if (h->ident != sp->confid[cp->protoidx]) { |
1615 | if (debug) | | 1612 | if (debug) |
1616 | addlog("%s: %s id mismatch 0x%x != 0x%x\n", | | 1613 | addlog("%s: %s id mismatch 0x%x != 0x%x\n", |
1617 | ifp->if_xname, cp->name, | | 1614 | ifp->if_xname, cp->name, |
1618 | h->ident, sp->confid[cp->protoidx]); | | 1615 | h->ident, sp->confid[cp->protoidx]); |
1619 | if_statinc(ifp, if_ierrors); | | 1616 | if_statinc(ifp, if_ierrors); |
1620 | break; | | 1617 | break; |
1621 | } | | 1618 | } |
1622 | switch (sp->state[cp->protoidx]) { | | 1619 | switch (sp->state[cp->protoidx]) { |
1623 | case STATE_CLOSED: | | 1620 | case STATE_CLOSED: |
1624 | case STATE_STOPPED: | | 1621 | case STATE_STOPPED: |
1625 | sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0); | | 1622 | sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0); |
1626 | break; | | 1623 | break; |
1627 | case STATE_CLOSING: | | 1624 | case STATE_CLOSING: |
1628 | case STATE_STOPPING: | | 1625 | case STATE_STOPPING: |
1629 | break; | | 1626 | break; |
1630 | case STATE_REQ_SENT: | | 1627 | case STATE_REQ_SENT: |
1631 | sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; | | 1628 | sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; |
1632 | sppp_cp_change_state(cp, sp, STATE_ACK_RCVD); | | 1629 | sppp_cp_change_state(cp, sp, STATE_ACK_RCVD); |
1633 | break; | | 1630 | break; |
1634 | case STATE_OPENED: | | 1631 | case STATE_OPENED: |
1635 | (cp->tld)(sp); | | 1632 | (cp->tld)(sp); |
1636 | /* fall through */ | | 1633 | /* fall through */ |
1637 | case STATE_ACK_RCVD: | | 1634 | case STATE_ACK_RCVD: |
1638 | (cp->scr)(sp); | | 1635 | (cp->scr)(sp); |
1639 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); | | 1636 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); |
1640 | break; | | 1637 | break; |
1641 | case STATE_ACK_SENT: | | 1638 | case STATE_ACK_SENT: |
1642 | sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; | | 1639 | sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; |
1643 | sppp_cp_change_state(cp, sp, STATE_OPENED); | | 1640 | sppp_cp_change_state(cp, sp, STATE_OPENED); |
1644 | if (debug) | | 1641 | if (debug) |
1645 | log(LOG_DEBUG, "%s: %s tlu\n", | | 1642 | log(LOG_DEBUG, "%s: %s tlu\n", |
1646 | ifp->if_xname, cp->name); | | 1643 | ifp->if_xname, cp->name); |
1647 | (cp->tlu)(sp); | | 1644 | (cp->tlu)(sp); |
1648 | break; | | 1645 | break; |
1649 | default: | | 1646 | default: |
1650 | printf("%s: %s illegal %s in state %s\n", | | 1647 | printf("%s: %s illegal %s in state %s\n", |
1651 | ifp->if_xname, cp->name, | | 1648 | ifp->if_xname, cp->name, |
1652 | sppp_cp_type_name(h->type), | | 1649 | sppp_cp_type_name(h->type), |
1653 | sppp_state_name(sp->state[cp->protoidx])); | | 1650 | sppp_state_name(sp->state[cp->protoidx])); |
1654 | if_statinc(ifp, if_ierrors); | | 1651 | if_statinc(ifp, if_ierrors); |
1655 | } | | 1652 | } |
1656 | break; | | 1653 | break; |
1657 | case CONF_NAK: | | 1654 | case CONF_NAK: |
1658 | case CONF_REJ: | | 1655 | case CONF_REJ: |
1659 | if (h->ident != sp->confid[cp->protoidx]) { | | 1656 | if (h->ident != sp->confid[cp->protoidx]) { |
1660 | if (debug) | | 1657 | if (debug) |
1661 | addlog("%s: %s id mismatch 0x%x != 0x%x\n", | | 1658 | addlog("%s: %s id mismatch 0x%x != 0x%x\n", |
1662 | ifp->if_xname, cp->name, | | 1659 | ifp->if_xname, cp->name, |
1663 | h->ident, sp->confid[cp->protoidx]); | | 1660 | h->ident, sp->confid[cp->protoidx]); |
1664 | if_statinc(ifp, if_ierrors); | | 1661 | if_statinc(ifp, if_ierrors); |
1665 | break; | | 1662 | break; |
1666 | } | | 1663 | } |
1667 | if (h->type == CONF_NAK) | | 1664 | if (h->type == CONF_NAK) |
1668 | (cp->RCN_nak)(sp, h, len); | | 1665 | (cp->RCN_nak)(sp, h, len); |
1669 | else /* CONF_REJ */ | | 1666 | else /* CONF_REJ */ |
1670 | (cp->RCN_rej)(sp, h, len); | | 1667 | (cp->RCN_rej)(sp, h, len); |
1671 | | | 1668 | |
1672 | switch (sp->state[cp->protoidx]) { | | 1669 | switch (sp->state[cp->protoidx]) { |
1673 | case STATE_CLOSED: | | 1670 | case STATE_CLOSED: |
1674 | case STATE_STOPPED: | | 1671 | case STATE_STOPPED: |
1675 | sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0); | | 1672 | sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0); |
1676 | break; | | 1673 | break; |
1677 | case STATE_REQ_SENT: | | 1674 | case STATE_REQ_SENT: |
1678 | case STATE_ACK_SENT: | | 1675 | case STATE_ACK_SENT: |
1679 | sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; | | 1676 | sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; |
1680 | (cp->scr)(sp); | | 1677 | (cp->scr)(sp); |
1681 | break; | | 1678 | break; |
1682 | case STATE_OPENED: | | 1679 | case STATE_OPENED: |
1683 | (cp->tld)(sp); | | 1680 | (cp->tld)(sp); |
1684 | /* fall through */ | | 1681 | /* fall through */ |
1685 | case STATE_ACK_RCVD: | | 1682 | case STATE_ACK_RCVD: |
1686 | sppp_cp_change_state(cp, sp, STATE_ACK_SENT); | | 1683 | sppp_cp_change_state(cp, sp, STATE_ACK_SENT); |
1687 | (cp->scr)(sp); | | 1684 | (cp->scr)(sp); |
1688 | break; | | 1685 | break; |
1689 | case STATE_CLOSING: | | 1686 | case STATE_CLOSING: |
1690 | case STATE_STOPPING: | | 1687 | case STATE_STOPPING: |
1691 | break; | | 1688 | break; |
1692 | default: | | 1689 | default: |
1693 | printf("%s: %s illegal %s in state %s\n", | | 1690 | printf("%s: %s illegal %s in state %s\n", |
1694 | ifp->if_xname, cp->name, | | 1691 | ifp->if_xname, cp->name, |
1695 | sppp_cp_type_name(h->type), | | 1692 | sppp_cp_type_name(h->type), |
1696 | sppp_state_name(sp->state[cp->protoidx])); | | 1693 | sppp_state_name(sp->state[cp->protoidx])); |
1697 | if_statinc(ifp, if_ierrors); | | 1694 | if_statinc(ifp, if_ierrors); |
1698 | } | | 1695 | } |
1699 | break; | | 1696 | break; |
1700 | | | 1697 | |
1701 | case TERM_REQ: | | 1698 | case TERM_REQ: |
1702 | switch (sp->state[cp->protoidx]) { | | 1699 | switch (sp->state[cp->protoidx]) { |
1703 | case STATE_ACK_RCVD: | | 1700 | case STATE_ACK_RCVD: |
1704 | case STATE_ACK_SENT: | | 1701 | case STATE_ACK_SENT: |
1705 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); | | 1702 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); |
1706 | /* fall through */ | | 1703 | /* fall through */ |
1707 | case STATE_CLOSED: | | 1704 | case STATE_CLOSED: |
1708 | case STATE_STOPPED: | | 1705 | case STATE_STOPPED: |
1709 | case STATE_CLOSING: | | 1706 | case STATE_CLOSING: |
1710 | case STATE_STOPPING: | | 1707 | case STATE_STOPPING: |
1711 | case STATE_REQ_SENT: | | 1708 | case STATE_REQ_SENT: |
1712 | sta: | | 1709 | sta: |
1713 | /* Send Terminate-Ack packet. */ | | 1710 | /* Send Terminate-Ack packet. */ |
1714 | if (debug) | | 1711 | if (debug) |
1715 | log(LOG_DEBUG, "%s: %s send terminate-ack\n", | | 1712 | log(LOG_DEBUG, "%s: %s send terminate-ack\n", |
1716 | ifp->if_xname, cp->name); | | 1713 | ifp->if_xname, cp->name); |
1717 | sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0); | | 1714 | sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0); |
1718 | break; | | 1715 | break; |
1719 | case STATE_OPENED: | | 1716 | case STATE_OPENED: |
1720 | (cp->tld)(sp); | | 1717 | (cp->tld)(sp); |
1721 | sp->rst_counter[cp->protoidx] = 0; | | 1718 | sp->rst_counter[cp->protoidx] = 0; |
1722 | sppp_cp_change_state(cp, sp, STATE_STOPPING); | | 1719 | sppp_cp_change_state(cp, sp, STATE_STOPPING); |
1723 | goto sta; | | 1720 | goto sta; |
1724 | default: | | 1721 | default: |
1725 | printf("%s: %s illegal %s in state %s\n", | | 1722 | printf("%s: %s illegal %s in state %s\n", |
1726 | ifp->if_xname, cp->name, | | 1723 | ifp->if_xname, cp->name, |
1727 | sppp_cp_type_name(h->type), | | 1724 | sppp_cp_type_name(h->type), |
1728 | sppp_state_name(sp->state[cp->protoidx])); | | 1725 | sppp_state_name(sp->state[cp->protoidx])); |
1729 | if_statinc(ifp, if_ierrors); | | 1726 | if_statinc(ifp, if_ierrors); |
1730 | } | | 1727 | } |
1731 | break; | | 1728 | break; |
1732 | case TERM_ACK: | | 1729 | case TERM_ACK: |
1733 | switch (sp->state[cp->protoidx]) { | | 1730 | switch (sp->state[cp->protoidx]) { |
1734 | case STATE_CLOSED: | | 1731 | case STATE_CLOSED: |
1735 | case STATE_STOPPED: | | 1732 | case STATE_STOPPED: |
1736 | case STATE_REQ_SENT: | | 1733 | case STATE_REQ_SENT: |
1737 | case STATE_ACK_SENT: | | 1734 | case STATE_ACK_SENT: |
1738 | break; | | 1735 | break; |
1739 | case STATE_CLOSING: | | 1736 | case STATE_CLOSING: |
1740 | (cp->tlf)(sp); | | 1737 | (cp->tlf)(sp); |
1741 | sppp_cp_change_state(cp, sp, STATE_CLOSED); | | 1738 | sppp_cp_change_state(cp, sp, STATE_CLOSED); |
1742 | sppp_lcp_check_and_close(sp); | | 1739 | sppp_lcp_check_and_close(sp); |
1743 | break; | | 1740 | break; |
1744 | case STATE_STOPPING: | | 1741 | case STATE_STOPPING: |
1745 | (cp->tlf)(sp); | | 1742 | (cp->tlf)(sp); |
1746 | sppp_cp_change_state(cp, sp, STATE_STOPPED); | | 1743 | sppp_cp_change_state(cp, sp, STATE_STOPPED); |
1747 | sppp_lcp_check_and_close(sp); | | 1744 | sppp_lcp_check_and_close(sp); |
1748 | break; | | 1745 | break; |
1749 | case STATE_ACK_RCVD: | | 1746 | case STATE_ACK_RCVD: |
1750 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); | | 1747 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); |
1751 | break; | | 1748 | break; |
1752 | case STATE_OPENED: | | 1749 | case STATE_OPENED: |
1753 | (cp->tld)(sp); | | 1750 | (cp->tld)(sp); |
1754 | (cp->scr)(sp); | | 1751 | (cp->scr)(sp); |
1755 | sppp_cp_change_state(cp, sp, STATE_ACK_RCVD); | | 1752 | sppp_cp_change_state(cp, sp, STATE_ACK_RCVD); |
1756 | break; | | 1753 | break; |
1757 | default: | | 1754 | default: |
1758 | printf("%s: %s illegal %s in state %s\n", | | 1755 | printf("%s: %s illegal %s in state %s\n", |
1759 | ifp->if_xname, cp->name, | | 1756 | ifp->if_xname, cp->name, |
1760 | sppp_cp_type_name(h->type), | | 1757 | sppp_cp_type_name(h->type), |
1761 | sppp_state_name(sp->state[cp->protoidx])); | | 1758 | sppp_state_name(sp->state[cp->protoidx])); |
1762 | if_statinc(ifp, if_ierrors); | | 1759 | if_statinc(ifp, if_ierrors); |
1763 | } | | 1760 | } |
1764 | break; | | 1761 | break; |
1765 | case CODE_REJ: | | 1762 | case CODE_REJ: |
1766 | /* XXX catastrophic rejects (RXJ-) aren't handled yet. */ | | 1763 | /* XXX catastrophic rejects (RXJ-) aren't handled yet. */ |
1767 | log(LOG_INFO, | | 1764 | log(LOG_INFO, |
1768 | "%s: %s: ignoring RXJ (%s) for code ?, " | | 1765 | "%s: %s: ignoring RXJ (%s) for code ?, " |
1769 | "danger will robinson\n", | | 1766 | "danger will robinson\n", |
1770 | ifp->if_xname, cp->name, | | 1767 | ifp->if_xname, cp->name, |
1771 | sppp_cp_type_name(h->type)); | | 1768 | sppp_cp_type_name(h->type)); |
1772 | switch (sp->state[cp->protoidx]) { | | 1769 | switch (sp->state[cp->protoidx]) { |
1773 | case STATE_CLOSED: | | 1770 | case STATE_CLOSED: |
1774 | case STATE_STOPPED: | | 1771 | case STATE_STOPPED: |
1775 | case STATE_REQ_SENT: | | 1772 | case STATE_REQ_SENT: |
1776 | case STATE_ACK_SENT: | | 1773 | case STATE_ACK_SENT: |
1777 | case STATE_CLOSING: | | 1774 | case STATE_CLOSING: |
1778 | case STATE_STOPPING: | | 1775 | case STATE_STOPPING: |
1779 | case STATE_OPENED: | | 1776 | case STATE_OPENED: |
1780 | break; | | 1777 | break; |
1781 | case STATE_ACK_RCVD: | | 1778 | case STATE_ACK_RCVD: |
1782 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); | | 1779 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); |
1783 | break; | | 1780 | break; |
1784 | default: | | 1781 | default: |
1785 | printf("%s: %s illegal %s in state %s\n", | | 1782 | printf("%s: %s illegal %s in state %s\n", |
1786 | ifp->if_xname, cp->name, | | 1783 | ifp->if_xname, cp->name, |
1787 | sppp_cp_type_name(h->type), | | 1784 | sppp_cp_type_name(h->type), |
1788 | sppp_state_name(sp->state[cp->protoidx])); | | 1785 | sppp_state_name(sp->state[cp->protoidx])); |
1789 | if_statinc(ifp, if_ierrors); | | 1786 | if_statinc(ifp, if_ierrors); |
1790 | } | | 1787 | } |
1791 | break; | | 1788 | break; |
1792 | case PROTO_REJ: | | 1789 | case PROTO_REJ: |
1793 | { | | 1790 | { |
1794 | int catastrophic; | | 1791 | int catastrophic; |
1795 | const struct cp *upper; | | 1792 | const struct cp *upper; |
1796 | int i; | | 1793 | int i; |
1797 | uint16_t proto; | | 1794 | uint16_t proto; |
1798 | | | 1795 | |
1799 | catastrophic = 0; | | 1796 | catastrophic = 0; |
1800 | upper = NULL; | | 1797 | upper = NULL; |
1801 | proto = p[0] << 8 | p[1]; | | 1798 | proto = p[0] << 8 | p[1]; |
1802 | for (i = 0; i < IDX_COUNT; i++) { | | 1799 | for (i = 0; i < IDX_COUNT; i++) { |
1803 | if (cps[i]->proto == proto) { | | 1800 | if (cps[i]->proto == proto) { |
1804 | upper = cps[i]; | | 1801 | upper = cps[i]; |
1805 | break; | | 1802 | break; |
1806 | } | | 1803 | } |
1807 | } | | 1804 | } |
1808 | if (upper == NULL) | | 1805 | if (upper == NULL) |
1809 | catastrophic++; | | 1806 | catastrophic++; |
1810 | | | 1807 | |
1811 | if (debug) | | 1808 | if (debug) |
1812 | log(LOG_INFO, | | 1809 | log(LOG_INFO, |
1813 | "%s: %s: RXJ%c (%s) for proto 0x%x (%s/%s)\n", | | 1810 | "%s: %s: RXJ%c (%s) for proto 0x%x (%s/%s)\n", |
1814 | ifp->if_xname, cp->name, catastrophic ? '-' : '+', | | 1811 | ifp->if_xname, cp->name, catastrophic ? '-' : '+', |
1815 | sppp_cp_type_name(h->type), proto, | | 1812 | sppp_cp_type_name(h->type), proto, |
1816 | upper ? upper->name : "unknown", | | 1813 | upper ? upper->name : "unknown", |
1817 | upper ? sppp_state_name(sp->state[upper->protoidx]) : "?"); | | 1814 | upper ? sppp_state_name(sp->state[upper->protoidx]) : "?"); |
1818 | | | 1815 | |
1819 | /* | | 1816 | /* |
1820 | * if we got RXJ+ against conf-req, the peer does not implement | | 1817 | * if we got RXJ+ against conf-req, the peer does not implement |
1821 | * this particular protocol type. terminate the protocol. | | 1818 | * this particular protocol type. terminate the protocol. |
1822 | */ | | 1819 | */ |
1823 | if (upper && !catastrophic) { | | 1820 | if (upper && !catastrophic) { |
1824 | if (sp->state[upper->protoidx] == STATE_REQ_SENT) { | | 1821 | if (sp->state[upper->protoidx] == STATE_REQ_SENT) { |
1825 | upper->Close(sp); | | 1822 | upper->Close(sp); |
1826 | break; | | 1823 | break; |
1827 | } | | 1824 | } |
1828 | } | | 1825 | } |
1829 | | | 1826 | |
1830 | /* XXX catastrophic rejects (RXJ-) aren't handled yet. */ | | 1827 | /* XXX catastrophic rejects (RXJ-) aren't handled yet. */ |
1831 | switch (sp->state[cp->protoidx]) { | | 1828 | switch (sp->state[cp->protoidx]) { |
1832 | case STATE_CLOSED: | | 1829 | case STATE_CLOSED: |
1833 | case STATE_STOPPED: | | 1830 | case STATE_STOPPED: |
1834 | case STATE_REQ_SENT: | | 1831 | case STATE_REQ_SENT: |
1835 | case STATE_ACK_SENT: | | 1832 | case STATE_ACK_SENT: |
1836 | case STATE_CLOSING: | | 1833 | case STATE_CLOSING: |
1837 | case STATE_STOPPING: | | 1834 | case STATE_STOPPING: |
1838 | case STATE_OPENED: | | 1835 | case STATE_OPENED: |
1839 | break; | | 1836 | break; |
1840 | case STATE_ACK_RCVD: | | 1837 | case STATE_ACK_RCVD: |
1841 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); | | 1838 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); |
1842 | break; | | 1839 | break; |
1843 | default: | | 1840 | default: |
1844 | printf("%s: %s illegal %s in state %s\n", | | 1841 | printf("%s: %s illegal %s in state %s\n", |
1845 | ifp->if_xname, cp->name, | | 1842 | ifp->if_xname, cp->name, |
1846 | sppp_cp_type_name(h->type), | | 1843 | sppp_cp_type_name(h->type), |
1847 | sppp_state_name(sp->state[cp->protoidx])); | | 1844 | sppp_state_name(sp->state[cp->protoidx])); |
1848 | if_statinc(ifp, if_ierrors); | | 1845 | if_statinc(ifp, if_ierrors); |
1849 | } | | 1846 | } |
1850 | break; | | 1847 | break; |
1851 | } | | 1848 | } |
1852 | case DISC_REQ: | | 1849 | case DISC_REQ: |
1853 | if (cp->proto != PPP_LCP) | | 1850 | if (cp->proto != PPP_LCP) |
1854 | goto illegal; | | 1851 | goto illegal; |
1855 | /* Discard the packet. */ | | 1852 | /* Discard the packet. */ |
1856 | break; | | 1853 | break; |
1857 | case ECHO_REQ: | | 1854 | case ECHO_REQ: |
1858 | if (cp->proto != PPP_LCP) | | 1855 | if (cp->proto != PPP_LCP) |
1859 | goto illegal; | | 1856 | goto illegal; |
1860 | if (sp->state[cp->protoidx] != STATE_OPENED) { | | 1857 | if (sp->state[cp->protoidx] != STATE_OPENED) { |
1861 | if (debug) | | 1858 | if (debug) |
1862 | addlog("%s: lcp echo req but lcp closed\n", | | 1859 | addlog("%s: lcp echo req but lcp closed\n", |
1863 | ifp->if_xname); | | 1860 | ifp->if_xname); |
1864 | if_statinc(ifp, if_ierrors); | | 1861 | if_statinc(ifp, if_ierrors); |
1865 | break; | | 1862 | break; |
1866 | } | | 1863 | } |
1867 | if (len < 8) { | | 1864 | if (len < 8) { |
1868 | if (debug) | | 1865 | if (debug) |
1869 | addlog("%s: invalid lcp echo request " | | 1866 | addlog("%s: invalid lcp echo request " |
1870 | "packet length: %d bytes\n", | | 1867 | "packet length: %d bytes\n", |
1871 | ifp->if_xname, len); | | 1868 | ifp->if_xname, len); |
1872 | break; | | 1869 | break; |
1873 | } | | 1870 | } |
1874 | memcpy(&u32, h + 1, sizeof u32); | | 1871 | memcpy(&u32, h + 1, sizeof u32); |
1875 | if (ntohl(u32) == sp->lcp.magic) { | | 1872 | if (ntohl(u32) == sp->lcp.magic) { |
1876 | /* Line loopback mode detected. */ | | 1873 | /* Line loopback mode detected. */ |
1877 | printf("%s: loopback\n", ifp->if_xname); | | 1874 | printf("%s: loopback\n", ifp->if_xname); |
1878 | SPPP_UNLOCK(sp); | | 1875 | SPPP_UNLOCK(sp); |
1879 | if_down(ifp); | | 1876 | if_down(ifp); |
1880 | SPPP_LOCK(sp, RW_WRITER); | | 1877 | SPPP_LOCK(sp, RW_WRITER); |
1881 | | | 1878 | |
1882 | IF_PURGE(&sp->pp_cpq); | | 1879 | IF_PURGE(&sp->pp_cpq); |
1883 | | | 1880 | |
1884 | /* Shut down the PPP link. */ | | 1881 | /* Shut down the PPP link. */ |
1885 | /* XXX */ | | 1882 | /* XXX */ |
1886 | lcp.Down(sp); | | 1883 | lcp.Down(sp); |
1887 | lcp.Up(sp); | | 1884 | lcp.Up(sp); |
1888 | break; | | 1885 | break; |
1889 | } | | 1886 | } |
1890 | u32 = htonl(sp->lcp.magic); | | 1887 | u32 = htonl(sp->lcp.magic); |
1891 | memcpy(h + 1, &u32, sizeof u32); | | 1888 | memcpy(h + 1, &u32, sizeof u32); |
1892 | if (debug) | | 1889 | if (debug) |
1893 | addlog("%s: got lcp echo req, sending echo rep\n", | | 1890 | addlog("%s: got lcp echo req, sending echo rep\n", |
1894 | ifp->if_xname); | | 1891 | ifp->if_xname); |
1895 | sppp_cp_send(sp, PPP_LCP, ECHO_REPLY, h->ident, len - 4, | | 1892 | sppp_cp_send(sp, PPP_LCP, ECHO_REPLY, h->ident, len - 4, |
1896 | h + 1); | | 1893 | h + 1); |
1897 | break; | | 1894 | break; |
1898 | case ECHO_REPLY: | | 1895 | case ECHO_REPLY: |
1899 | if (cp->proto != PPP_LCP) | | 1896 | if (cp->proto != PPP_LCP) |
1900 | goto illegal; | | 1897 | goto illegal; |
1901 | if (h->ident != sp->lcp.echoid) { | | 1898 | if (h->ident != sp->lcp.echoid) { |
1902 | if_statinc(ifp, if_ierrors); | | 1899 | if_statinc(ifp, if_ierrors); |
1903 | break; | | 1900 | break; |
1904 | } | | 1901 | } |
1905 | if (len < 8) { | | 1902 | if (len < 8) { |
1906 | if (debug) | | 1903 | if (debug) |
1907 | addlog("%s: lcp invalid echo reply " | | 1904 | addlog("%s: lcp invalid echo reply " |
1908 | "packet length: %d bytes\n", | | 1905 | "packet length: %d bytes\n", |
1909 | ifp->if_xname, len); | | 1906 | ifp->if_xname, len); |
1910 | break; | | 1907 | break; |
1911 | } | | 1908 | } |
1912 | if (debug) | | 1909 | if (debug) |
1913 | addlog("%s: lcp got echo rep\n", | | 1910 | addlog("%s: lcp got echo rep\n", |
1914 | ifp->if_xname); | | 1911 | ifp->if_xname); |
1915 | memcpy(&u32, h + 1, sizeof u32); | | 1912 | memcpy(&u32, h + 1, sizeof u32); |
1916 | if (ntohl(u32) != sp->lcp.magic) | | 1913 | if (ntohl(u32) != sp->lcp.magic) |
1917 | sp->pp_alivecnt = 0; | | 1914 | sp->pp_alivecnt = 0; |
1918 | break; | | 1915 | break; |
1919 | default: | | 1916 | default: |
1920 | /* Unknown packet type -- send Code-Reject packet. */ | | 1917 | /* Unknown packet type -- send Code-Reject packet. */ |
1921 | illegal: | | 1918 | illegal: |
1922 | if (debug) | | 1919 | if (debug) |
1923 | addlog("%s: %s send code-rej for 0x%x\n", | | 1920 | addlog("%s: %s send code-rej for 0x%x\n", |
1924 | ifp->if_xname, cp->name, h->type); | | 1921 | ifp->if_xname, cp->name, h->type); |
1925 | sppp_cp_send(sp, cp->proto, CODE_REJ, | | 1922 | sppp_cp_send(sp, cp->proto, CODE_REJ, |
1926 | ++sp->pp_seq[cp->protoidx], m->m_pkthdr.len, h); | | 1923 | ++sp->pp_seq[cp->protoidx], m->m_pkthdr.len, h); |
1927 | if_statinc(ifp, if_ierrors); | | 1924 | if_statinc(ifp, if_ierrors); |
1928 | } | | 1925 | } |
1929 | | | 1926 | |
1930 | SPPP_UNLOCK(sp); | | 1927 | SPPP_UNLOCK(sp); |
1931 | } | | 1928 | } |
1932 | | | 1929 | |
1933 | | | 1930 | |
1934 | /* | | 1931 | /* |
1935 | * The generic part of all Up/Down/Open/Close/TO event handlers. | | 1932 | * The generic part of all Up/Down/Open/Close/TO event handlers. |
1936 | * Basically, the state transition handling in the automaton. | | 1933 | * Basically, the state transition handling in the automaton. |
1937 | */ | | 1934 | */ |
1938 | static void | | 1935 | static void |
1939 | sppp_up_event(const struct cp *cp, struct sppp *sp) | | 1936 | sppp_up_event(const struct cp *cp, struct sppp *sp) |
1940 | { | | 1937 | { |
1941 | STDDCL; | | 1938 | STDDCL; |
1942 | | | 1939 | |
1943 | KASSERT(SPPP_WLOCKED(sp)); | | 1940 | KASSERT(SPPP_WLOCKED(sp)); |
1944 | | | 1941 | |
1945 | if (debug) | | 1942 | if (debug) |
1946 | log(LOG_DEBUG, "%s: %s up(%s)\n", | | 1943 | log(LOG_DEBUG, "%s: %s up(%s)\n", |
1947 | ifp->if_xname, cp->name, | | 1944 | ifp->if_xname, cp->name, |
1948 | sppp_state_name(sp->state[cp->protoidx])); | | 1945 | sppp_state_name(sp->state[cp->protoidx])); |
1949 | | | 1946 | |
1950 | switch (sp->state[cp->protoidx]) { | | 1947 | switch (sp->state[cp->protoidx]) { |
1951 | case STATE_INITIAL: | | 1948 | case STATE_INITIAL: |
1952 | sppp_cp_change_state(cp, sp, STATE_CLOSED); | | 1949 | sppp_cp_change_state(cp, sp, STATE_CLOSED); |
1953 | break; | | 1950 | break; |
1954 | case STATE_STARTING: | | 1951 | case STATE_STARTING: |
1955 | sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; | | 1952 | sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; |
1956 | (cp->scr)(sp); | | 1953 | (cp->scr)(sp); |
1957 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); | | 1954 | sppp_cp_change_state(cp, sp, STATE_REQ_SENT); |
1958 | break; | | 1955 | break; |
1959 | default: | | 1956 | default: |
1960 | printf("%s: %s illegal up in state %s\n", | | 1957 | printf("%s: %s illegal up in state %s\n", |
1961 | ifp->if_xname, cp->name, | | 1958 | ifp->if_xname, cp->name, |
1962 | sppp_state_name(sp->state[cp->protoidx])); | | 1959 | sppp_state_name(sp->state[cp->protoidx])); |
1963 | } | | 1960 | } |
1964 | } | | 1961 | } |
1965 | | | 1962 | |
1966 | static void | | 1963 | static void |
1967 | sppp_down_event(const struct cp *cp, struct sppp *sp) | | 1964 | sppp_down_event(const struct cp *cp, struct sppp *sp) |
1968 | { | | 1965 | { |
1969 | STDDCL; | | 1966 | STDDCL; |
1970 | | | 1967 | |
1971 | KASSERT(SPPP_WLOCKED(sp)); | | 1968 | KASSERT(SPPP_WLOCKED(sp)); |
1972 | | | 1969 | |
1973 | if (debug) | | 1970 | if (debug) |
1974 | log(LOG_DEBUG, "%s: %s down(%s)\n", | | 1971 | log(LOG_DEBUG, "%s: %s down(%s)\n", |
1975 | ifp->if_xname, cp->name, | | 1972 | ifp->if_xname, cp->name, |
1976 | sppp_state_name(sp->state[cp->protoidx])); | | 1973 | sppp_state_name(sp->state[cp->protoidx])); |
1977 | | | 1974 | |
1978 | switch (sp->state[cp->protoidx]) { | | 1975 | switch (sp->state[cp->protoidx]) { |
1979 | case STATE_CLOSED: | | 1976 | case STATE_CLOSED: |
1980 | case STATE_CLOSING: | | 1977 | case STATE_CLOSING: |
1981 | sppp_cp_change_state(cp, sp, STATE_INITIAL); | | 1978 | sppp_cp_change_state(cp, sp, STATE_INITIAL); |
1982 | break; | | 1979 | break; |
1983 | case STATE_STOPPED: | | 1980 | case STATE_STOPPED: |
1984 | (cp->tls)(sp); | | 1981 | (cp->tls)(sp); |
1985 | /* fall through */ | | 1982 | /* fall through */ |
1986 | case STATE_STOPPING: | | 1983 | case STATE_STOPPING: |
1987 | case STATE_REQ_SENT: | | 1984 | case STATE_REQ_SENT: |
1988 | case STATE_ACK_RCVD: | | 1985 | case STATE_ACK_RCVD: |
1989 | case STATE_ACK_SENT: | | 1986 | case STATE_ACK_SENT: |
1990 | sppp_cp_change_state(cp, sp, STATE_STARTING); | | 1987 | sppp_cp_change_state(cp, sp, STATE_STARTING); |
1991 | break; | | 1988 | break; |