SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lorcansmith 0:2a53a4c3238c 1 /** In contrast to pppd 2.3.1, DNS support has been added, proxy-ARP and
lorcansmith 0:2a53a4c3238c 2 dial-on-demand has been stripped. */
lorcansmith 0:2a53a4c3238c 3 /*****************************************************************************
lorcansmith 0:2a53a4c3238c 4 * ipcp.c - Network PPP IP Control Protocol program file.
lorcansmith 0:2a53a4c3238c 5 *
lorcansmith 0:2a53a4c3238c 6 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
lorcansmith 0:2a53a4c3238c 7 * portions Copyright (c) 1997 by Global Election Systems Inc.
lorcansmith 0:2a53a4c3238c 8 *
lorcansmith 0:2a53a4c3238c 9 * The authors hereby grant permission to use, copy, modify, distribute,
lorcansmith 0:2a53a4c3238c 10 * and license this software and its documentation for any purpose, provided
lorcansmith 0:2a53a4c3238c 11 * that existing copyright notices are retained in all copies and that this
lorcansmith 0:2a53a4c3238c 12 * notice and the following disclaimer are included verbatim in any
lorcansmith 0:2a53a4c3238c 13 * distributions. No written agreement, license, or royalty fee is required
lorcansmith 0:2a53a4c3238c 14 * for any of the authorized uses.
lorcansmith 0:2a53a4c3238c 15 *
lorcansmith 0:2a53a4c3238c 16 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
lorcansmith 0:2a53a4c3238c 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
lorcansmith 0:2a53a4c3238c 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
lorcansmith 0:2a53a4c3238c 19 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
lorcansmith 0:2a53a4c3238c 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
lorcansmith 0:2a53a4c3238c 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
lorcansmith 0:2a53a4c3238c 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
lorcansmith 0:2a53a4c3238c 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
lorcansmith 0:2a53a4c3238c 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
lorcansmith 0:2a53a4c3238c 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lorcansmith 0:2a53a4c3238c 26 *
lorcansmith 0:2a53a4c3238c 27 ******************************************************************************
lorcansmith 0:2a53a4c3238c 28 * REVISION HISTORY
lorcansmith 0:2a53a4c3238c 29 *
lorcansmith 0:2a53a4c3238c 30 * 03-01-01 Marc Boucher <marc@mbsi.ca>
lorcansmith 0:2a53a4c3238c 31 * Ported to lwIP.
lorcansmith 0:2a53a4c3238c 32 * 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
lorcansmith 0:2a53a4c3238c 33 * Original.
lorcansmith 0:2a53a4c3238c 34 *****************************************************************************/
lorcansmith 0:2a53a4c3238c 35 /*
lorcansmith 0:2a53a4c3238c 36 * ipcp.c - PPP IP Control Protocol.
lorcansmith 0:2a53a4c3238c 37 *
lorcansmith 0:2a53a4c3238c 38 * Copyright (c) 1989 Carnegie Mellon University.
lorcansmith 0:2a53a4c3238c 39 * All rights reserved.
lorcansmith 0:2a53a4c3238c 40 *
lorcansmith 0:2a53a4c3238c 41 * Redistribution and use in source and binary forms are permitted
lorcansmith 0:2a53a4c3238c 42 * provided that the above copyright notice and this paragraph are
lorcansmith 0:2a53a4c3238c 43 * duplicated in all such forms and that any documentation,
lorcansmith 0:2a53a4c3238c 44 * advertising materials, and other materials related to such
lorcansmith 0:2a53a4c3238c 45 * distribution and use acknowledge that the software was developed
lorcansmith 0:2a53a4c3238c 46 * by Carnegie Mellon University. The name of the
lorcansmith 0:2a53a4c3238c 47 * University may not be used to endorse or promote products derived
lorcansmith 0:2a53a4c3238c 48 * from this software without specific prior written permission.
lorcansmith 0:2a53a4c3238c 49 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
lorcansmith 0:2a53a4c3238c 50 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
lorcansmith 0:2a53a4c3238c 51 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
lorcansmith 0:2a53a4c3238c 52 */
lorcansmith 0:2a53a4c3238c 53
lorcansmith 0:2a53a4c3238c 54 #include "lwip/opt.h"
lorcansmith 0:2a53a4c3238c 55
lorcansmith 0:2a53a4c3238c 56 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
lorcansmith 0:2a53a4c3238c 57
lorcansmith 0:2a53a4c3238c 58 #include "ppp.h"
lorcansmith 0:2a53a4c3238c 59 #include "pppdebug.h"
lorcansmith 0:2a53a4c3238c 60
lorcansmith 0:2a53a4c3238c 61 #include "auth.h"
lorcansmith 0:2a53a4c3238c 62 #include "fsm.h"
lorcansmith 0:2a53a4c3238c 63 #include "vj.h"
lorcansmith 0:2a53a4c3238c 64 #include "ipcp.h"
lorcansmith 0:2a53a4c3238c 65
lorcansmith 0:2a53a4c3238c 66 #include "lwip/inet.h"
lorcansmith 0:2a53a4c3238c 67
lorcansmith 0:2a53a4c3238c 68 #include <string.h>
lorcansmith 0:2a53a4c3238c 69
lorcansmith 0:2a53a4c3238c 70 /* #define OLD_CI_ADDRS 1 */ /* Support deprecated address negotiation. */
lorcansmith 0:2a53a4c3238c 71
lorcansmith 0:2a53a4c3238c 72 /* global vars */
lorcansmith 0:2a53a4c3238c 73 ipcp_options ipcp_wantoptions[NUM_PPP]; /* Options that we want to request */
lorcansmith 0:2a53a4c3238c 74 ipcp_options ipcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
lorcansmith 0:2a53a4c3238c 75 ipcp_options ipcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
lorcansmith 0:2a53a4c3238c 76 ipcp_options ipcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
lorcansmith 0:2a53a4c3238c 77
lorcansmith 0:2a53a4c3238c 78 /* local vars */
lorcansmith 0:2a53a4c3238c 79 static int default_route_set[NUM_PPP]; /* Have set up a default route */
lorcansmith 0:2a53a4c3238c 80 static int cis_received[NUM_PPP]; /* # Conf-Reqs received */
lorcansmith 0:2a53a4c3238c 81
lorcansmith 0:2a53a4c3238c 82
lorcansmith 0:2a53a4c3238c 83 /*
lorcansmith 0:2a53a4c3238c 84 * Callbacks for fsm code. (CI = Configuration Information)
lorcansmith 0:2a53a4c3238c 85 */
lorcansmith 0:2a53a4c3238c 86 static void ipcp_resetci (fsm *); /* Reset our CI */
lorcansmith 0:2a53a4c3238c 87 static int ipcp_cilen (fsm *); /* Return length of our CI */
lorcansmith 0:2a53a4c3238c 88 static void ipcp_addci (fsm *, u_char *, int *); /* Add our CI */
lorcansmith 0:2a53a4c3238c 89 static int ipcp_ackci (fsm *, u_char *, int); /* Peer ack'd our CI */
lorcansmith 0:2a53a4c3238c 90 static int ipcp_nakci (fsm *, u_char *, int); /* Peer nak'd our CI */
lorcansmith 0:2a53a4c3238c 91 static int ipcp_rejci (fsm *, u_char *, int); /* Peer rej'd our CI */
lorcansmith 0:2a53a4c3238c 92 static int ipcp_reqci (fsm *, u_char *, int *, int); /* Rcv CI */
lorcansmith 0:2a53a4c3238c 93 static void ipcp_up (fsm *); /* We're UP */
lorcansmith 0:2a53a4c3238c 94 static void ipcp_down (fsm *); /* We're DOWN */
lorcansmith 0:2a53a4c3238c 95 #if PPP_ADDITIONAL_CALLBACKS
lorcansmith 0:2a53a4c3238c 96 static void ipcp_script (fsm *, char *); /* Run an up/down script */
lorcansmith 0:2a53a4c3238c 97 #endif
lorcansmith 0:2a53a4c3238c 98 static void ipcp_finished (fsm *); /* Don't need lower layer */
lorcansmith 0:2a53a4c3238c 99
lorcansmith 0:2a53a4c3238c 100
lorcansmith 0:2a53a4c3238c 101 fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
lorcansmith 0:2a53a4c3238c 102
lorcansmith 0:2a53a4c3238c 103
lorcansmith 0:2a53a4c3238c 104 static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
lorcansmith 0:2a53a4c3238c 105 ipcp_resetci, /* Reset our Configuration Information */
lorcansmith 0:2a53a4c3238c 106 ipcp_cilen, /* Length of our Configuration Information */
lorcansmith 0:2a53a4c3238c 107 ipcp_addci, /* Add our Configuration Information */
lorcansmith 0:2a53a4c3238c 108 ipcp_ackci, /* ACK our Configuration Information */
lorcansmith 0:2a53a4c3238c 109 ipcp_nakci, /* NAK our Configuration Information */
lorcansmith 0:2a53a4c3238c 110 ipcp_rejci, /* Reject our Configuration Information */
lorcansmith 0:2a53a4c3238c 111 ipcp_reqci, /* Request peer's Configuration Information */
lorcansmith 0:2a53a4c3238c 112 ipcp_up, /* Called when fsm reaches LS_OPENED state */
lorcansmith 0:2a53a4c3238c 113 ipcp_down, /* Called when fsm leaves LS_OPENED state */
lorcansmith 0:2a53a4c3238c 114 NULL, /* Called when we want the lower layer up */
lorcansmith 0:2a53a4c3238c 115 ipcp_finished, /* Called when we want the lower layer down */
lorcansmith 0:2a53a4c3238c 116 NULL, /* Called when Protocol-Reject received */
lorcansmith 0:2a53a4c3238c 117 NULL, /* Retransmission is necessary */
lorcansmith 0:2a53a4c3238c 118 NULL, /* Called to handle protocol-specific codes */
lorcansmith 0:2a53a4c3238c 119 "IPCP" /* String name of protocol */
lorcansmith 0:2a53a4c3238c 120 };
lorcansmith 0:2a53a4c3238c 121
lorcansmith 0:2a53a4c3238c 122 /*
lorcansmith 0:2a53a4c3238c 123 * Protocol entry points from main code.
lorcansmith 0:2a53a4c3238c 124 */
lorcansmith 0:2a53a4c3238c 125 static void ipcp_init (int);
lorcansmith 0:2a53a4c3238c 126 static void ipcp_open (int);
lorcansmith 0:2a53a4c3238c 127 static void ipcp_close (int, char *);
lorcansmith 0:2a53a4c3238c 128 static void ipcp_lowerup (int);
lorcansmith 0:2a53a4c3238c 129 static void ipcp_lowerdown (int);
lorcansmith 0:2a53a4c3238c 130 static void ipcp_input (int, u_char *, int);
lorcansmith 0:2a53a4c3238c 131 static void ipcp_protrej (int);
lorcansmith 0:2a53a4c3238c 132
lorcansmith 0:2a53a4c3238c 133
lorcansmith 0:2a53a4c3238c 134 struct protent ipcp_protent = {
lorcansmith 0:2a53a4c3238c 135 PPP_IPCP,
lorcansmith 0:2a53a4c3238c 136 ipcp_init,
lorcansmith 0:2a53a4c3238c 137 ipcp_input,
lorcansmith 0:2a53a4c3238c 138 ipcp_protrej,
lorcansmith 0:2a53a4c3238c 139 ipcp_lowerup,
lorcansmith 0:2a53a4c3238c 140 ipcp_lowerdown,
lorcansmith 0:2a53a4c3238c 141 ipcp_open,
lorcansmith 0:2a53a4c3238c 142 ipcp_close,
lorcansmith 0:2a53a4c3238c 143 #if PPP_ADDITIONAL_CALLBACKS
lorcansmith 0:2a53a4c3238c 144 ipcp_printpkt,
lorcansmith 0:2a53a4c3238c 145 NULL,
lorcansmith 0:2a53a4c3238c 146 #endif /* PPP_ADDITIONAL_CALLBACKS */
lorcansmith 0:2a53a4c3238c 147 1,
lorcansmith 0:2a53a4c3238c 148 "IPCP",
lorcansmith 0:2a53a4c3238c 149 #if PPP_ADDITIONAL_CALLBACKS
lorcansmith 0:2a53a4c3238c 150 ip_check_options,
lorcansmith 0:2a53a4c3238c 151 NULL,
lorcansmith 0:2a53a4c3238c 152 ip_active_pkt
lorcansmith 0:2a53a4c3238c 153 #endif /* PPP_ADDITIONAL_CALLBACKS */
lorcansmith 0:2a53a4c3238c 154 };
lorcansmith 0:2a53a4c3238c 155
lorcansmith 0:2a53a4c3238c 156 static void ipcp_clear_addrs (int);
lorcansmith 0:2a53a4c3238c 157
lorcansmith 0:2a53a4c3238c 158 /*
lorcansmith 0:2a53a4c3238c 159 * Lengths of configuration options.
lorcansmith 0:2a53a4c3238c 160 */
lorcansmith 0:2a53a4c3238c 161 #define CILEN_VOID 2
lorcansmith 0:2a53a4c3238c 162 #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
lorcansmith 0:2a53a4c3238c 163 #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
lorcansmith 0:2a53a4c3238c 164 #define CILEN_ADDR 6 /* new-style single address option */
lorcansmith 0:2a53a4c3238c 165 #define CILEN_ADDRS 10 /* old-style dual address option */
lorcansmith 0:2a53a4c3238c 166
lorcansmith 0:2a53a4c3238c 167
lorcansmith 0:2a53a4c3238c 168 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
lorcansmith 0:2a53a4c3238c 169 (x) == CONFNAK ? "NAK" : "REJ")
lorcansmith 0:2a53a4c3238c 170
lorcansmith 0:2a53a4c3238c 171
lorcansmith 0:2a53a4c3238c 172 /*
lorcansmith 0:2a53a4c3238c 173 * ipcp_init - Initialize IPCP.
lorcansmith 0:2a53a4c3238c 174 */
lorcansmith 0:2a53a4c3238c 175 static void
lorcansmith 0:2a53a4c3238c 176 ipcp_init(int unit)
lorcansmith 0:2a53a4c3238c 177 {
lorcansmith 0:2a53a4c3238c 178 fsm *f = &ipcp_fsm[unit];
lorcansmith 0:2a53a4c3238c 179 ipcp_options *wo = &ipcp_wantoptions[unit];
lorcansmith 0:2a53a4c3238c 180 ipcp_options *ao = &ipcp_allowoptions[unit];
lorcansmith 0:2a53a4c3238c 181
lorcansmith 0:2a53a4c3238c 182 f->unit = unit;
lorcansmith 0:2a53a4c3238c 183 f->protocol = PPP_IPCP;
lorcansmith 0:2a53a4c3238c 184 f->callbacks = &ipcp_callbacks;
lorcansmith 0:2a53a4c3238c 185 fsm_init(&ipcp_fsm[unit]);
lorcansmith 0:2a53a4c3238c 186
lorcansmith 0:2a53a4c3238c 187 memset(wo, 0, sizeof(*wo));
lorcansmith 0:2a53a4c3238c 188 memset(ao, 0, sizeof(*ao));
lorcansmith 0:2a53a4c3238c 189
lorcansmith 0:2a53a4c3238c 190 wo->neg_addr = 1;
lorcansmith 0:2a53a4c3238c 191 wo->ouraddr = 0;
lorcansmith 0:2a53a4c3238c 192 #if VJ_SUPPORT
lorcansmith 0:2a53a4c3238c 193 wo->neg_vj = 1;
lorcansmith 0:2a53a4c3238c 194 #else /* VJ_SUPPORT */
lorcansmith 0:2a53a4c3238c 195 wo->neg_vj = 0;
lorcansmith 0:2a53a4c3238c 196 #endif /* VJ_SUPPORT */
lorcansmith 0:2a53a4c3238c 197 wo->vj_protocol = IPCP_VJ_COMP;
lorcansmith 0:2a53a4c3238c 198 wo->maxslotindex = MAX_SLOTS - 1;
lorcansmith 0:2a53a4c3238c 199 wo->cflag = 0;
lorcansmith 0:2a53a4c3238c 200 wo->default_route = 1;
lorcansmith 0:2a53a4c3238c 201
lorcansmith 0:2a53a4c3238c 202 ao->neg_addr = 1;
lorcansmith 0:2a53a4c3238c 203 #if VJ_SUPPORT
lorcansmith 0:2a53a4c3238c 204 ao->neg_vj = 1;
lorcansmith 0:2a53a4c3238c 205 #else /* VJ_SUPPORT */
lorcansmith 0:2a53a4c3238c 206 ao->neg_vj = 0;
lorcansmith 0:2a53a4c3238c 207 #endif /* VJ_SUPPORT */
lorcansmith 0:2a53a4c3238c 208 ao->maxslotindex = MAX_SLOTS - 1;
lorcansmith 0:2a53a4c3238c 209 ao->cflag = 1;
lorcansmith 0:2a53a4c3238c 210 ao->default_route = 1;
lorcansmith 0:2a53a4c3238c 211 }
lorcansmith 0:2a53a4c3238c 212
lorcansmith 0:2a53a4c3238c 213
lorcansmith 0:2a53a4c3238c 214 /*
lorcansmith 0:2a53a4c3238c 215 * ipcp_open - IPCP is allowed to come up.
lorcansmith 0:2a53a4c3238c 216 */
lorcansmith 0:2a53a4c3238c 217 static void
lorcansmith 0:2a53a4c3238c 218 ipcp_open(int unit)
lorcansmith 0:2a53a4c3238c 219 {
lorcansmith 0:2a53a4c3238c 220 fsm_open(&ipcp_fsm[unit]);
lorcansmith 0:2a53a4c3238c 221 }
lorcansmith 0:2a53a4c3238c 222
lorcansmith 0:2a53a4c3238c 223
lorcansmith 0:2a53a4c3238c 224 /*
lorcansmith 0:2a53a4c3238c 225 * ipcp_close - Take IPCP down.
lorcansmith 0:2a53a4c3238c 226 */
lorcansmith 0:2a53a4c3238c 227 static void
lorcansmith 0:2a53a4c3238c 228 ipcp_close(int unit, char *reason)
lorcansmith 0:2a53a4c3238c 229 {
lorcansmith 0:2a53a4c3238c 230 fsm_close(&ipcp_fsm[unit], reason);
lorcansmith 0:2a53a4c3238c 231 }
lorcansmith 0:2a53a4c3238c 232
lorcansmith 0:2a53a4c3238c 233
lorcansmith 0:2a53a4c3238c 234 /*
lorcansmith 0:2a53a4c3238c 235 * ipcp_lowerup - The lower layer is up.
lorcansmith 0:2a53a4c3238c 236 */
lorcansmith 0:2a53a4c3238c 237 static void
lorcansmith 0:2a53a4c3238c 238 ipcp_lowerup(int unit)
lorcansmith 0:2a53a4c3238c 239 {
lorcansmith 0:2a53a4c3238c 240 fsm_lowerup(&ipcp_fsm[unit]);
lorcansmith 0:2a53a4c3238c 241 }
lorcansmith 0:2a53a4c3238c 242
lorcansmith 0:2a53a4c3238c 243
lorcansmith 0:2a53a4c3238c 244 /*
lorcansmith 0:2a53a4c3238c 245 * ipcp_lowerdown - The lower layer is down.
lorcansmith 0:2a53a4c3238c 246 */
lorcansmith 0:2a53a4c3238c 247 static void
lorcansmith 0:2a53a4c3238c 248 ipcp_lowerdown(int unit)
lorcansmith 0:2a53a4c3238c 249 {
lorcansmith 0:2a53a4c3238c 250 fsm_lowerdown(&ipcp_fsm[unit]);
lorcansmith 0:2a53a4c3238c 251 }
lorcansmith 0:2a53a4c3238c 252
lorcansmith 0:2a53a4c3238c 253
lorcansmith 0:2a53a4c3238c 254 /*
lorcansmith 0:2a53a4c3238c 255 * ipcp_input - Input IPCP packet.
lorcansmith 0:2a53a4c3238c 256 */
lorcansmith 0:2a53a4c3238c 257 static void
lorcansmith 0:2a53a4c3238c 258 ipcp_input(int unit, u_char *p, int len)
lorcansmith 0:2a53a4c3238c 259 {
lorcansmith 0:2a53a4c3238c 260 fsm_input(&ipcp_fsm[unit], p, len);
lorcansmith 0:2a53a4c3238c 261 }
lorcansmith 0:2a53a4c3238c 262
lorcansmith 0:2a53a4c3238c 263
lorcansmith 0:2a53a4c3238c 264 /*
lorcansmith 0:2a53a4c3238c 265 * ipcp_protrej - A Protocol-Reject was received for IPCP.
lorcansmith 0:2a53a4c3238c 266 *
lorcansmith 0:2a53a4c3238c 267 * Pretend the lower layer went down, so we shut up.
lorcansmith 0:2a53a4c3238c 268 */
lorcansmith 0:2a53a4c3238c 269 static void
lorcansmith 0:2a53a4c3238c 270 ipcp_protrej(int unit)
lorcansmith 0:2a53a4c3238c 271 {
lorcansmith 0:2a53a4c3238c 272 fsm_lowerdown(&ipcp_fsm[unit]);
lorcansmith 0:2a53a4c3238c 273 }
lorcansmith 0:2a53a4c3238c 274
lorcansmith 0:2a53a4c3238c 275
lorcansmith 0:2a53a4c3238c 276 /*
lorcansmith 0:2a53a4c3238c 277 * ipcp_resetci - Reset our CI.
lorcansmith 0:2a53a4c3238c 278 */
lorcansmith 0:2a53a4c3238c 279 static void
lorcansmith 0:2a53a4c3238c 280 ipcp_resetci(fsm *f)
lorcansmith 0:2a53a4c3238c 281 {
lorcansmith 0:2a53a4c3238c 282 ipcp_options *wo = &ipcp_wantoptions[f->unit];
lorcansmith 0:2a53a4c3238c 283
lorcansmith 0:2a53a4c3238c 284 wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
lorcansmith 0:2a53a4c3238c 285 if (wo->ouraddr == 0) {
lorcansmith 0:2a53a4c3238c 286 wo->accept_local = 1;
lorcansmith 0:2a53a4c3238c 287 }
lorcansmith 0:2a53a4c3238c 288 if (wo->hisaddr == 0) {
lorcansmith 0:2a53a4c3238c 289 wo->accept_remote = 1;
lorcansmith 0:2a53a4c3238c 290 }
lorcansmith 0:2a53a4c3238c 291 /* Request DNS addresses from the peer */
lorcansmith 0:2a53a4c3238c 292 wo->req_dns1 = ppp_settings.usepeerdns;
lorcansmith 0:2a53a4c3238c 293 wo->req_dns2 = ppp_settings.usepeerdns;
lorcansmith 0:2a53a4c3238c 294 ipcp_gotoptions[f->unit] = *wo;
lorcansmith 0:2a53a4c3238c 295 cis_received[f->unit] = 0;
lorcansmith 0:2a53a4c3238c 296 }
lorcansmith 0:2a53a4c3238c 297
lorcansmith 0:2a53a4c3238c 298
lorcansmith 0:2a53a4c3238c 299 /*
lorcansmith 0:2a53a4c3238c 300 * ipcp_cilen - Return length of our CI.
lorcansmith 0:2a53a4c3238c 301 */
lorcansmith 0:2a53a4c3238c 302 static int
lorcansmith 0:2a53a4c3238c 303 ipcp_cilen(fsm *f)
lorcansmith 0:2a53a4c3238c 304 {
lorcansmith 0:2a53a4c3238c 305 ipcp_options *go = &ipcp_gotoptions[f->unit];
lorcansmith 0:2a53a4c3238c 306 ipcp_options *wo = &ipcp_wantoptions[f->unit];
lorcansmith 0:2a53a4c3238c 307 ipcp_options *ho = &ipcp_hisoptions[f->unit];
lorcansmith 0:2a53a4c3238c 308
lorcansmith 0:2a53a4c3238c 309 #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
lorcansmith 0:2a53a4c3238c 310 #define LENCIADDR(neg, old) (neg ? (old? CILEN_ADDRS : CILEN_ADDR) : 0)
lorcansmith 0:2a53a4c3238c 311 #define LENCIDNS(neg) (neg ? (CILEN_ADDR) : 0)
lorcansmith 0:2a53a4c3238c 312
lorcansmith 0:2a53a4c3238c 313 /*
lorcansmith 0:2a53a4c3238c 314 * First see if we want to change our options to the old
lorcansmith 0:2a53a4c3238c 315 * forms because we have received old forms from the peer.
lorcansmith 0:2a53a4c3238c 316 */
lorcansmith 0:2a53a4c3238c 317 if (wo->neg_addr && !go->neg_addr && !go->old_addrs) {
lorcansmith 0:2a53a4c3238c 318 /* use the old style of address negotiation */
lorcansmith 0:2a53a4c3238c 319 go->neg_addr = 1;
lorcansmith 0:2a53a4c3238c 320 go->old_addrs = 1;
lorcansmith 0:2a53a4c3238c 321 }
lorcansmith 0:2a53a4c3238c 322 if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
lorcansmith 0:2a53a4c3238c 323 /* try an older style of VJ negotiation */
lorcansmith 0:2a53a4c3238c 324 if (cis_received[f->unit] == 0) {
lorcansmith 0:2a53a4c3238c 325 /* keep trying the new style until we see some CI from the peer */
lorcansmith 0:2a53a4c3238c 326 go->neg_vj = 1;
lorcansmith 0:2a53a4c3238c 327 } else {
lorcansmith 0:2a53a4c3238c 328 /* use the old style only if the peer did */
lorcansmith 0:2a53a4c3238c 329 if (ho->neg_vj && ho->old_vj) {
lorcansmith 0:2a53a4c3238c 330 go->neg_vj = 1;
lorcansmith 0:2a53a4c3238c 331 go->old_vj = 1;
lorcansmith 0:2a53a4c3238c 332 go->vj_protocol = ho->vj_protocol;
lorcansmith 0:2a53a4c3238c 333 }
lorcansmith 0:2a53a4c3238c 334 }
lorcansmith 0:2a53a4c3238c 335 }
lorcansmith 0:2a53a4c3238c 336
lorcansmith 0:2a53a4c3238c 337 return (LENCIADDR(go->neg_addr, go->old_addrs) +
lorcansmith 0:2a53a4c3238c 338 LENCIVJ(go->neg_vj, go->old_vj) +
lorcansmith 0:2a53a4c3238c 339 LENCIDNS(go->req_dns1) +
lorcansmith 0:2a53a4c3238c 340 LENCIDNS(go->req_dns2));
lorcansmith 0:2a53a4c3238c 341 }
lorcansmith 0:2a53a4c3238c 342
lorcansmith 0:2a53a4c3238c 343
lorcansmith 0:2a53a4c3238c 344 /*
lorcansmith 0:2a53a4c3238c 345 * ipcp_addci - Add our desired CIs to a packet.
lorcansmith 0:2a53a4c3238c 346 */
lorcansmith 0:2a53a4c3238c 347 static void
lorcansmith 0:2a53a4c3238c 348 ipcp_addci(fsm *f, u_char *ucp, int *lenp)
lorcansmith 0:2a53a4c3238c 349 {
lorcansmith 0:2a53a4c3238c 350 ipcp_options *go = &ipcp_gotoptions[f->unit];
lorcansmith 0:2a53a4c3238c 351 int len = *lenp;
lorcansmith 0:2a53a4c3238c 352
lorcansmith 0:2a53a4c3238c 353 #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
lorcansmith 0:2a53a4c3238c 354 if (neg) { \
lorcansmith 0:2a53a4c3238c 355 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
lorcansmith 0:2a53a4c3238c 356 if (len >= vjlen) { \
lorcansmith 0:2a53a4c3238c 357 PUTCHAR(opt, ucp); \
lorcansmith 0:2a53a4c3238c 358 PUTCHAR(vjlen, ucp); \
lorcansmith 0:2a53a4c3238c 359 PUTSHORT(val, ucp); \
lorcansmith 0:2a53a4c3238c 360 if (!old) { \
lorcansmith 0:2a53a4c3238c 361 PUTCHAR(maxslotindex, ucp); \
lorcansmith 0:2a53a4c3238c 362 PUTCHAR(cflag, ucp); \
lorcansmith 0:2a53a4c3238c 363 } \
lorcansmith 0:2a53a4c3238c 364 len -= vjlen; \
lorcansmith 0:2a53a4c3238c 365 } else { \
lorcansmith 0:2a53a4c3238c 366 neg = 0; \
lorcansmith 0:2a53a4c3238c 367 } \
lorcansmith 0:2a53a4c3238c 368 }
lorcansmith 0:2a53a4c3238c 369
lorcansmith 0:2a53a4c3238c 370 #define ADDCIADDR(opt, neg, old, val1, val2) \
lorcansmith 0:2a53a4c3238c 371 if (neg) { \
lorcansmith 0:2a53a4c3238c 372 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
lorcansmith 0:2a53a4c3238c 373 if (len >= addrlen) { \
lorcansmith 0:2a53a4c3238c 374 u32_t l; \
lorcansmith 0:2a53a4c3238c 375 PUTCHAR(opt, ucp); \
lorcansmith 0:2a53a4c3238c 376 PUTCHAR(addrlen, ucp); \
lorcansmith 0:2a53a4c3238c 377 l = ntohl(val1); \
lorcansmith 0:2a53a4c3238c 378 PUTLONG(l, ucp); \
lorcansmith 0:2a53a4c3238c 379 if (old) { \
lorcansmith 0:2a53a4c3238c 380 l = ntohl(val2); \
lorcansmith 0:2a53a4c3238c 381 PUTLONG(l, ucp); \
lorcansmith 0:2a53a4c3238c 382 } \
lorcansmith 0:2a53a4c3238c 383 len -= addrlen; \
lorcansmith 0:2a53a4c3238c 384 } else { \
lorcansmith 0:2a53a4c3238c 385 neg = 0; \
lorcansmith 0:2a53a4c3238c 386 } \
lorcansmith 0:2a53a4c3238c 387 }
lorcansmith 0:2a53a4c3238c 388
lorcansmith 0:2a53a4c3238c 389 #define ADDCIDNS(opt, neg, addr) \
lorcansmith 0:2a53a4c3238c 390 if (neg) { \
lorcansmith 0:2a53a4c3238c 391 if (len >= CILEN_ADDR) { \
lorcansmith 0:2a53a4c3238c 392 u32_t l; \
lorcansmith 0:2a53a4c3238c 393 PUTCHAR(opt, ucp); \
lorcansmith 0:2a53a4c3238c 394 PUTCHAR(CILEN_ADDR, ucp); \
lorcansmith 0:2a53a4c3238c 395 l = ntohl(addr); \
lorcansmith 0:2a53a4c3238c 396 PUTLONG(l, ucp); \
lorcansmith 0:2a53a4c3238c 397 len -= CILEN_ADDR; \
lorcansmith 0:2a53a4c3238c 398 } else { \
lorcansmith 0:2a53a4c3238c 399 neg = 0; \
lorcansmith 0:2a53a4c3238c 400 } \
lorcansmith 0:2a53a4c3238c 401 }
lorcansmith 0:2a53a4c3238c 402
lorcansmith 0:2a53a4c3238c 403 ADDCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
lorcansmith 0:2a53a4c3238c 404 go->old_addrs, go->ouraddr, go->hisaddr);
lorcansmith 0:2a53a4c3238c 405
lorcansmith 0:2a53a4c3238c 406 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
lorcansmith 0:2a53a4c3238c 407 go->maxslotindex, go->cflag);
lorcansmith 0:2a53a4c3238c 408
lorcansmith 0:2a53a4c3238c 409 ADDCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
lorcansmith 0:2a53a4c3238c 410
lorcansmith 0:2a53a4c3238c 411 ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
lorcansmith 0:2a53a4c3238c 412
lorcansmith 0:2a53a4c3238c 413 *lenp -= len;
lorcansmith 0:2a53a4c3238c 414 }
lorcansmith 0:2a53a4c3238c 415
lorcansmith 0:2a53a4c3238c 416
lorcansmith 0:2a53a4c3238c 417 /*
lorcansmith 0:2a53a4c3238c 418 * ipcp_ackci - Ack our CIs.
lorcansmith 0:2a53a4c3238c 419 *
lorcansmith 0:2a53a4c3238c 420 * Returns:
lorcansmith 0:2a53a4c3238c 421 * 0 - Ack was bad.
lorcansmith 0:2a53a4c3238c 422 * 1 - Ack was good.
lorcansmith 0:2a53a4c3238c 423 */
lorcansmith 0:2a53a4c3238c 424 static int
lorcansmith 0:2a53a4c3238c 425 ipcp_ackci(fsm *f, u_char *p, int len)
lorcansmith 0:2a53a4c3238c 426 {
lorcansmith 0:2a53a4c3238c 427 ipcp_options *go = &ipcp_gotoptions[f->unit];
lorcansmith 0:2a53a4c3238c 428 u_short cilen, citype, cishort;
lorcansmith 0:2a53a4c3238c 429 u32_t cilong;
lorcansmith 0:2a53a4c3238c 430 u_char cimaxslotindex, cicflag;
lorcansmith 0:2a53a4c3238c 431
lorcansmith 0:2a53a4c3238c 432 /*
lorcansmith 0:2a53a4c3238c 433 * CIs must be in exactly the same order that we sent...
lorcansmith 0:2a53a4c3238c 434 * Check packet length and CI length at each step.
lorcansmith 0:2a53a4c3238c 435 * If we find any deviations, then this packet is bad.
lorcansmith 0:2a53a4c3238c 436 */
lorcansmith 0:2a53a4c3238c 437
lorcansmith 0:2a53a4c3238c 438 #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
lorcansmith 0:2a53a4c3238c 439 if (neg) { \
lorcansmith 0:2a53a4c3238c 440 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
lorcansmith 0:2a53a4c3238c 441 if ((len -= vjlen) < 0) { \
lorcansmith 0:2a53a4c3238c 442 goto bad; \
lorcansmith 0:2a53a4c3238c 443 } \
lorcansmith 0:2a53a4c3238c 444 GETCHAR(citype, p); \
lorcansmith 0:2a53a4c3238c 445 GETCHAR(cilen, p); \
lorcansmith 0:2a53a4c3238c 446 if (cilen != vjlen || \
lorcansmith 0:2a53a4c3238c 447 citype != opt) { \
lorcansmith 0:2a53a4c3238c 448 goto bad; \
lorcansmith 0:2a53a4c3238c 449 } \
lorcansmith 0:2a53a4c3238c 450 GETSHORT(cishort, p); \
lorcansmith 0:2a53a4c3238c 451 if (cishort != val) { \
lorcansmith 0:2a53a4c3238c 452 goto bad; \
lorcansmith 0:2a53a4c3238c 453 } \
lorcansmith 0:2a53a4c3238c 454 if (!old) { \
lorcansmith 0:2a53a4c3238c 455 GETCHAR(cimaxslotindex, p); \
lorcansmith 0:2a53a4c3238c 456 if (cimaxslotindex != maxslotindex) { \
lorcansmith 0:2a53a4c3238c 457 goto bad; \
lorcansmith 0:2a53a4c3238c 458 } \
lorcansmith 0:2a53a4c3238c 459 GETCHAR(cicflag, p); \
lorcansmith 0:2a53a4c3238c 460 if (cicflag != cflag) { \
lorcansmith 0:2a53a4c3238c 461 goto bad; \
lorcansmith 0:2a53a4c3238c 462 } \
lorcansmith 0:2a53a4c3238c 463 } \
lorcansmith 0:2a53a4c3238c 464 }
lorcansmith 0:2a53a4c3238c 465
lorcansmith 0:2a53a4c3238c 466 #define ACKCIADDR(opt, neg, old, val1, val2) \
lorcansmith 0:2a53a4c3238c 467 if (neg) { \
lorcansmith 0:2a53a4c3238c 468 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
lorcansmith 0:2a53a4c3238c 469 u32_t l; \
lorcansmith 0:2a53a4c3238c 470 if ((len -= addrlen) < 0) { \
lorcansmith 0:2a53a4c3238c 471 goto bad; \
lorcansmith 0:2a53a4c3238c 472 } \
lorcansmith 0:2a53a4c3238c 473 GETCHAR(citype, p); \
lorcansmith 0:2a53a4c3238c 474 GETCHAR(cilen, p); \
lorcansmith 0:2a53a4c3238c 475 if (cilen != addrlen || \
lorcansmith 0:2a53a4c3238c 476 citype != opt) { \
lorcansmith 0:2a53a4c3238c 477 goto bad; \
lorcansmith 0:2a53a4c3238c 478 } \
lorcansmith 0:2a53a4c3238c 479 GETLONG(l, p); \
lorcansmith 0:2a53a4c3238c 480 cilong = htonl(l); \
lorcansmith 0:2a53a4c3238c 481 if (val1 != cilong) { \
lorcansmith 0:2a53a4c3238c 482 goto bad; \
lorcansmith 0:2a53a4c3238c 483 } \
lorcansmith 0:2a53a4c3238c 484 if (old) { \
lorcansmith 0:2a53a4c3238c 485 GETLONG(l, p); \
lorcansmith 0:2a53a4c3238c 486 cilong = htonl(l); \
lorcansmith 0:2a53a4c3238c 487 if (val2 != cilong) { \
lorcansmith 0:2a53a4c3238c 488 goto bad; \
lorcansmith 0:2a53a4c3238c 489 } \
lorcansmith 0:2a53a4c3238c 490 } \
lorcansmith 0:2a53a4c3238c 491 }
lorcansmith 0:2a53a4c3238c 492
lorcansmith 0:2a53a4c3238c 493 #define ACKCIDNS(opt, neg, addr) \
lorcansmith 0:2a53a4c3238c 494 if (neg) { \
lorcansmith 0:2a53a4c3238c 495 u32_t l; \
lorcansmith 0:2a53a4c3238c 496 if ((len -= CILEN_ADDR) < 0) { \
lorcansmith 0:2a53a4c3238c 497 goto bad; \
lorcansmith 0:2a53a4c3238c 498 } \
lorcansmith 0:2a53a4c3238c 499 GETCHAR(citype, p); \
lorcansmith 0:2a53a4c3238c 500 GETCHAR(cilen, p); \
lorcansmith 0:2a53a4c3238c 501 if (cilen != CILEN_ADDR || \
lorcansmith 0:2a53a4c3238c 502 citype != opt) { \
lorcansmith 0:2a53a4c3238c 503 goto bad; \
lorcansmith 0:2a53a4c3238c 504 } \
lorcansmith 0:2a53a4c3238c 505 GETLONG(l, p); \
lorcansmith 0:2a53a4c3238c 506 cilong = htonl(l); \
lorcansmith 0:2a53a4c3238c 507 if (addr != cilong) { \
lorcansmith 0:2a53a4c3238c 508 goto bad; \
lorcansmith 0:2a53a4c3238c 509 } \
lorcansmith 0:2a53a4c3238c 510 }
lorcansmith 0:2a53a4c3238c 511
lorcansmith 0:2a53a4c3238c 512 ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
lorcansmith 0:2a53a4c3238c 513 go->old_addrs, go->ouraddr, go->hisaddr);
lorcansmith 0:2a53a4c3238c 514
lorcansmith 0:2a53a4c3238c 515 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
lorcansmith 0:2a53a4c3238c 516 go->maxslotindex, go->cflag);
lorcansmith 0:2a53a4c3238c 517
lorcansmith 0:2a53a4c3238c 518 ACKCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
lorcansmith 0:2a53a4c3238c 519
lorcansmith 0:2a53a4c3238c 520 ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
lorcansmith 0:2a53a4c3238c 521
lorcansmith 0:2a53a4c3238c 522 /*
lorcansmith 0:2a53a4c3238c 523 * If there are any remaining CIs, then this packet is bad.
lorcansmith 0:2a53a4c3238c 524 */
lorcansmith 0:2a53a4c3238c 525 if (len != 0) {
lorcansmith 0:2a53a4c3238c 526 goto bad;
lorcansmith 0:2a53a4c3238c 527 }
lorcansmith 0:2a53a4c3238c 528 return (1);
lorcansmith 0:2a53a4c3238c 529
lorcansmith 0:2a53a4c3238c 530 bad:
lorcansmith 0:2a53a4c3238c 531 IPCPDEBUG(LOG_INFO, ("ipcp_ackci: received bad Ack!\n"));
lorcansmith 0:2a53a4c3238c 532 return (0);
lorcansmith 0:2a53a4c3238c 533 }
lorcansmith 0:2a53a4c3238c 534
lorcansmith 0:2a53a4c3238c 535 /*
lorcansmith 0:2a53a4c3238c 536 * ipcp_nakci - Peer has sent a NAK for some of our CIs.
lorcansmith 0:2a53a4c3238c 537 * This should not modify any state if the Nak is bad
lorcansmith 0:2a53a4c3238c 538 * or if IPCP is in the LS_OPENED state.
lorcansmith 0:2a53a4c3238c 539 *
lorcansmith 0:2a53a4c3238c 540 * Returns:
lorcansmith 0:2a53a4c3238c 541 * 0 - Nak was bad.
lorcansmith 0:2a53a4c3238c 542 * 1 - Nak was good.
lorcansmith 0:2a53a4c3238c 543 */
lorcansmith 0:2a53a4c3238c 544 static int
lorcansmith 0:2a53a4c3238c 545 ipcp_nakci(fsm *f, u_char *p, int len)
lorcansmith 0:2a53a4c3238c 546 {
lorcansmith 0:2a53a4c3238c 547 ipcp_options *go = &ipcp_gotoptions[f->unit];
lorcansmith 0:2a53a4c3238c 548 u_char cimaxslotindex, cicflag;
lorcansmith 0:2a53a4c3238c 549 u_char citype, cilen, *next;
lorcansmith 0:2a53a4c3238c 550 u_short cishort;
lorcansmith 0:2a53a4c3238c 551 u32_t ciaddr1, ciaddr2, l, cidnsaddr;
lorcansmith 0:2a53a4c3238c 552 ipcp_options no; /* options we've seen Naks for */
lorcansmith 0:2a53a4c3238c 553 ipcp_options try; /* options to request next time */
lorcansmith 0:2a53a4c3238c 554
lorcansmith 0:2a53a4c3238c 555 BZERO(&no, sizeof(no));
lorcansmith 0:2a53a4c3238c 556 try = *go;
lorcansmith 0:2a53a4c3238c 557
lorcansmith 0:2a53a4c3238c 558 /*
lorcansmith 0:2a53a4c3238c 559 * Any Nak'd CIs must be in exactly the same order that we sent.
lorcansmith 0:2a53a4c3238c 560 * Check packet length and CI length at each step.
lorcansmith 0:2a53a4c3238c 561 * If we find any deviations, then this packet is bad.
lorcansmith 0:2a53a4c3238c 562 */
lorcansmith 0:2a53a4c3238c 563 #define NAKCIADDR(opt, neg, old, code) \
lorcansmith 0:2a53a4c3238c 564 if (go->neg && \
lorcansmith 0:2a53a4c3238c 565 len >= (cilen = (old? CILEN_ADDRS: CILEN_ADDR)) && \
lorcansmith 0:2a53a4c3238c 566 p[1] == cilen && \
lorcansmith 0:2a53a4c3238c 567 p[0] == opt) { \
lorcansmith 0:2a53a4c3238c 568 len -= cilen; \
lorcansmith 0:2a53a4c3238c 569 INCPTR(2, p); \
lorcansmith 0:2a53a4c3238c 570 GETLONG(l, p); \
lorcansmith 0:2a53a4c3238c 571 ciaddr1 = htonl(l); \
lorcansmith 0:2a53a4c3238c 572 if (old) { \
lorcansmith 0:2a53a4c3238c 573 GETLONG(l, p); \
lorcansmith 0:2a53a4c3238c 574 ciaddr2 = htonl(l); \
lorcansmith 0:2a53a4c3238c 575 no.old_addrs = 1; \
lorcansmith 0:2a53a4c3238c 576 } else { \
lorcansmith 0:2a53a4c3238c 577 ciaddr2 = 0; \
lorcansmith 0:2a53a4c3238c 578 } \
lorcansmith 0:2a53a4c3238c 579 no.neg = 1; \
lorcansmith 0:2a53a4c3238c 580 code \
lorcansmith 0:2a53a4c3238c 581 }
lorcansmith 0:2a53a4c3238c 582
lorcansmith 0:2a53a4c3238c 583 #define NAKCIVJ(opt, neg, code) \
lorcansmith 0:2a53a4c3238c 584 if (go->neg && \
lorcansmith 0:2a53a4c3238c 585 ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
lorcansmith 0:2a53a4c3238c 586 len >= cilen && \
lorcansmith 0:2a53a4c3238c 587 p[0] == opt) { \
lorcansmith 0:2a53a4c3238c 588 len -= cilen; \
lorcansmith 0:2a53a4c3238c 589 INCPTR(2, p); \
lorcansmith 0:2a53a4c3238c 590 GETSHORT(cishort, p); \
lorcansmith 0:2a53a4c3238c 591 no.neg = 1; \
lorcansmith 0:2a53a4c3238c 592 code \
lorcansmith 0:2a53a4c3238c 593 }
lorcansmith 0:2a53a4c3238c 594
lorcansmith 0:2a53a4c3238c 595 #define NAKCIDNS(opt, neg, code) \
lorcansmith 0:2a53a4c3238c 596 if (go->neg && \
lorcansmith 0:2a53a4c3238c 597 ((cilen = p[1]) == CILEN_ADDR) && \
lorcansmith 0:2a53a4c3238c 598 len >= cilen && \
lorcansmith 0:2a53a4c3238c 599 p[0] == opt) { \
lorcansmith 0:2a53a4c3238c 600 len -= cilen; \
lorcansmith 0:2a53a4c3238c 601 INCPTR(2, p); \
lorcansmith 0:2a53a4c3238c 602 GETLONG(l, p); \
lorcansmith 0:2a53a4c3238c 603 cidnsaddr = htonl(l); \
lorcansmith 0:2a53a4c3238c 604 no.neg = 1; \
lorcansmith 0:2a53a4c3238c 605 code \
lorcansmith 0:2a53a4c3238c 606 }
lorcansmith 0:2a53a4c3238c 607
lorcansmith 0:2a53a4c3238c 608 /*
lorcansmith 0:2a53a4c3238c 609 * Accept the peer's idea of {our,his} address, if different
lorcansmith 0:2a53a4c3238c 610 * from our idea, only if the accept_{local,remote} flag is set.
lorcansmith 0:2a53a4c3238c 611 */
lorcansmith 0:2a53a4c3238c 612 NAKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr, go->old_addrs,
lorcansmith 0:2a53a4c3238c 613 if (go->accept_local && ciaddr1) { /* Do we know our address? */
lorcansmith 0:2a53a4c3238c 614 try.ouraddr = ciaddr1;
lorcansmith 0:2a53a4c3238c 615 IPCPDEBUG(LOG_INFO, ("local IP address %s\n",
lorcansmith 0:2a53a4c3238c 616 inet_ntoa(ciaddr1)));
lorcansmith 0:2a53a4c3238c 617 }
lorcansmith 0:2a53a4c3238c 618 if (go->accept_remote && ciaddr2) { /* Does he know his? */
lorcansmith 0:2a53a4c3238c 619 try.hisaddr = ciaddr2;
lorcansmith 0:2a53a4c3238c 620 IPCPDEBUG(LOG_INFO, ("remote IP address %s\n",
lorcansmith 0:2a53a4c3238c 621 inet_ntoa(ciaddr2)));
lorcansmith 0:2a53a4c3238c 622 }
lorcansmith 0:2a53a4c3238c 623 );
lorcansmith 0:2a53a4c3238c 624
lorcansmith 0:2a53a4c3238c 625 /*
lorcansmith 0:2a53a4c3238c 626 * Accept the peer's value of maxslotindex provided that it
lorcansmith 0:2a53a4c3238c 627 * is less than what we asked for. Turn off slot-ID compression
lorcansmith 0:2a53a4c3238c 628 * if the peer wants. Send old-style compress-type option if
lorcansmith 0:2a53a4c3238c 629 * the peer wants.
lorcansmith 0:2a53a4c3238c 630 */
lorcansmith 0:2a53a4c3238c 631 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
lorcansmith 0:2a53a4c3238c 632 if (cilen == CILEN_VJ) {
lorcansmith 0:2a53a4c3238c 633 GETCHAR(cimaxslotindex, p);
lorcansmith 0:2a53a4c3238c 634 GETCHAR(cicflag, p);
lorcansmith 0:2a53a4c3238c 635 if (cishort == IPCP_VJ_COMP) {
lorcansmith 0:2a53a4c3238c 636 try.old_vj = 0;
lorcansmith 0:2a53a4c3238c 637 if (cimaxslotindex < go->maxslotindex) {
lorcansmith 0:2a53a4c3238c 638 try.maxslotindex = cimaxslotindex;
lorcansmith 0:2a53a4c3238c 639 }
lorcansmith 0:2a53a4c3238c 640 if (!cicflag) {
lorcansmith 0:2a53a4c3238c 641 try.cflag = 0;
lorcansmith 0:2a53a4c3238c 642 }
lorcansmith 0:2a53a4c3238c 643 } else {
lorcansmith 0:2a53a4c3238c 644 try.neg_vj = 0;
lorcansmith 0:2a53a4c3238c 645 }
lorcansmith 0:2a53a4c3238c 646 } else {
lorcansmith 0:2a53a4c3238c 647 if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
lorcansmith 0:2a53a4c3238c 648 try.old_vj = 1;
lorcansmith 0:2a53a4c3238c 649 try.vj_protocol = cishort;
lorcansmith 0:2a53a4c3238c 650 } else {
lorcansmith 0:2a53a4c3238c 651 try.neg_vj = 0;
lorcansmith 0:2a53a4c3238c 652 }
lorcansmith 0:2a53a4c3238c 653 }
lorcansmith 0:2a53a4c3238c 654 );
lorcansmith 0:2a53a4c3238c 655
lorcansmith 0:2a53a4c3238c 656 NAKCIDNS(CI_MS_DNS1, req_dns1,
lorcansmith 0:2a53a4c3238c 657 try.dnsaddr[0] = cidnsaddr;
lorcansmith 0:2a53a4c3238c 658 IPCPDEBUG(LOG_INFO, ("primary DNS address %s\n", inet_ntoa(cidnsaddr)));
lorcansmith 0:2a53a4c3238c 659 );
lorcansmith 0:2a53a4c3238c 660
lorcansmith 0:2a53a4c3238c 661 NAKCIDNS(CI_MS_DNS2, req_dns2,
lorcansmith 0:2a53a4c3238c 662 try.dnsaddr[1] = cidnsaddr;
lorcansmith 0:2a53a4c3238c 663 IPCPDEBUG(LOG_INFO, ("secondary DNS address %s\n", inet_ntoa(cidnsaddr)));
lorcansmith 0:2a53a4c3238c 664 );
lorcansmith 0:2a53a4c3238c 665
lorcansmith 0:2a53a4c3238c 666 /*
lorcansmith 0:2a53a4c3238c 667 * There may be remaining CIs, if the peer is requesting negotiation
lorcansmith 0:2a53a4c3238c 668 * on an option that we didn't include in our request packet.
lorcansmith 0:2a53a4c3238c 669 * If they want to negotiate about IP addresses, we comply.
lorcansmith 0:2a53a4c3238c 670 * If they want us to ask for compression, we refuse.
lorcansmith 0:2a53a4c3238c 671 */
lorcansmith 0:2a53a4c3238c 672 while (len > CILEN_VOID) {
lorcansmith 0:2a53a4c3238c 673 GETCHAR(citype, p);
lorcansmith 0:2a53a4c3238c 674 GETCHAR(cilen, p);
lorcansmith 0:2a53a4c3238c 675 if( (len -= cilen) < 0 ) {
lorcansmith 0:2a53a4c3238c 676 goto bad;
lorcansmith 0:2a53a4c3238c 677 }
lorcansmith 0:2a53a4c3238c 678 next = p + cilen - 2;
lorcansmith 0:2a53a4c3238c 679
lorcansmith 0:2a53a4c3238c 680 switch (citype) {
lorcansmith 0:2a53a4c3238c 681 case CI_COMPRESSTYPE:
lorcansmith 0:2a53a4c3238c 682 if (go->neg_vj || no.neg_vj ||
lorcansmith 0:2a53a4c3238c 683 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
lorcansmith 0:2a53a4c3238c 684 goto bad;
lorcansmith 0:2a53a4c3238c 685 }
lorcansmith 0:2a53a4c3238c 686 no.neg_vj = 1;
lorcansmith 0:2a53a4c3238c 687 break;
lorcansmith 0:2a53a4c3238c 688 case CI_ADDRS:
lorcansmith 0:2a53a4c3238c 689 if ((go->neg_addr && go->old_addrs) || no.old_addrs
lorcansmith 0:2a53a4c3238c 690 || cilen != CILEN_ADDRS) {
lorcansmith 0:2a53a4c3238c 691 goto bad;
lorcansmith 0:2a53a4c3238c 692 }
lorcansmith 0:2a53a4c3238c 693 try.neg_addr = 1;
lorcansmith 0:2a53a4c3238c 694 try.old_addrs = 1;
lorcansmith 0:2a53a4c3238c 695 GETLONG(l, p);
lorcansmith 0:2a53a4c3238c 696 ciaddr1 = htonl(l);
lorcansmith 0:2a53a4c3238c 697 if (ciaddr1 && go->accept_local) {
lorcansmith 0:2a53a4c3238c 698 try.ouraddr = ciaddr1;
lorcansmith 0:2a53a4c3238c 699 }
lorcansmith 0:2a53a4c3238c 700 GETLONG(l, p);
lorcansmith 0:2a53a4c3238c 701 ciaddr2 = htonl(l);
lorcansmith 0:2a53a4c3238c 702 if (ciaddr2 && go->accept_remote) {
lorcansmith 0:2a53a4c3238c 703 try.hisaddr = ciaddr2;
lorcansmith 0:2a53a4c3238c 704 }
lorcansmith 0:2a53a4c3238c 705 no.old_addrs = 1;
lorcansmith 0:2a53a4c3238c 706 break;
lorcansmith 0:2a53a4c3238c 707 case CI_ADDR:
lorcansmith 0:2a53a4c3238c 708 if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR) {
lorcansmith 0:2a53a4c3238c 709 goto bad;
lorcansmith 0:2a53a4c3238c 710 }
lorcansmith 0:2a53a4c3238c 711 try.old_addrs = 0;
lorcansmith 0:2a53a4c3238c 712 GETLONG(l, p);
lorcansmith 0:2a53a4c3238c 713 ciaddr1 = htonl(l);
lorcansmith 0:2a53a4c3238c 714 if (ciaddr1 && go->accept_local) {
lorcansmith 0:2a53a4c3238c 715 try.ouraddr = ciaddr1;
lorcansmith 0:2a53a4c3238c 716 }
lorcansmith 0:2a53a4c3238c 717 if (try.ouraddr != 0) {
lorcansmith 0:2a53a4c3238c 718 try.neg_addr = 1;
lorcansmith 0:2a53a4c3238c 719 }
lorcansmith 0:2a53a4c3238c 720 no.neg_addr = 1;
lorcansmith 0:2a53a4c3238c 721 break;
lorcansmith 0:2a53a4c3238c 722 }
lorcansmith 0:2a53a4c3238c 723 p = next;
lorcansmith 0:2a53a4c3238c 724 }
lorcansmith 0:2a53a4c3238c 725
lorcansmith 0:2a53a4c3238c 726 /* If there is still anything left, this packet is bad. */
lorcansmith 0:2a53a4c3238c 727 if (len != 0) {
lorcansmith 0:2a53a4c3238c 728 goto bad;
lorcansmith 0:2a53a4c3238c 729 }
lorcansmith 0:2a53a4c3238c 730
lorcansmith 0:2a53a4c3238c 731 /*
lorcansmith 0:2a53a4c3238c 732 * OK, the Nak is good. Now we can update state.
lorcansmith 0:2a53a4c3238c 733 */
lorcansmith 0:2a53a4c3238c 734 if (f->state != LS_OPENED) {
lorcansmith 0:2a53a4c3238c 735 *go = try;
lorcansmith 0:2a53a4c3238c 736 }
lorcansmith 0:2a53a4c3238c 737
lorcansmith 0:2a53a4c3238c 738 return 1;
lorcansmith 0:2a53a4c3238c 739
lorcansmith 0:2a53a4c3238c 740 bad:
lorcansmith 0:2a53a4c3238c 741 IPCPDEBUG(LOG_INFO, ("ipcp_nakci: received bad Nak!\n"));
lorcansmith 0:2a53a4c3238c 742 return 0;
lorcansmith 0:2a53a4c3238c 743 }
lorcansmith 0:2a53a4c3238c 744
lorcansmith 0:2a53a4c3238c 745
lorcansmith 0:2a53a4c3238c 746 /*
lorcansmith 0:2a53a4c3238c 747 * ipcp_rejci - Reject some of our CIs.
lorcansmith 0:2a53a4c3238c 748 */
lorcansmith 0:2a53a4c3238c 749 static int
lorcansmith 0:2a53a4c3238c 750 ipcp_rejci(fsm *f, u_char *p, int len)
lorcansmith 0:2a53a4c3238c 751 {
lorcansmith 0:2a53a4c3238c 752 ipcp_options *go = &ipcp_gotoptions[f->unit];
lorcansmith 0:2a53a4c3238c 753 u_char cimaxslotindex, ciflag, cilen;
lorcansmith 0:2a53a4c3238c 754 u_short cishort;
lorcansmith 0:2a53a4c3238c 755 u32_t cilong;
lorcansmith 0:2a53a4c3238c 756 ipcp_options try; /* options to request next time */
lorcansmith 0:2a53a4c3238c 757
lorcansmith 0:2a53a4c3238c 758 try = *go;
lorcansmith 0:2a53a4c3238c 759 /*
lorcansmith 0:2a53a4c3238c 760 * Any Rejected CIs must be in exactly the same order that we sent.
lorcansmith 0:2a53a4c3238c 761 * Check packet length and CI length at each step.
lorcansmith 0:2a53a4c3238c 762 * If we find any deviations, then this packet is bad.
lorcansmith 0:2a53a4c3238c 763 */
lorcansmith 0:2a53a4c3238c 764 #define REJCIADDR(opt, neg, old, val1, val2) \
lorcansmith 0:2a53a4c3238c 765 if (go->neg && \
lorcansmith 0:2a53a4c3238c 766 len >= (cilen = old? CILEN_ADDRS: CILEN_ADDR) && \
lorcansmith 0:2a53a4c3238c 767 p[1] == cilen && \
lorcansmith 0:2a53a4c3238c 768 p[0] == opt) { \
lorcansmith 0:2a53a4c3238c 769 u32_t l; \
lorcansmith 0:2a53a4c3238c 770 len -= cilen; \
lorcansmith 0:2a53a4c3238c 771 INCPTR(2, p); \
lorcansmith 0:2a53a4c3238c 772 GETLONG(l, p); \
lorcansmith 0:2a53a4c3238c 773 cilong = htonl(l); \
lorcansmith 0:2a53a4c3238c 774 /* Check rejected value. */ \
lorcansmith 0:2a53a4c3238c 775 if (cilong != val1) { \
lorcansmith 0:2a53a4c3238c 776 goto bad; \
lorcansmith 0:2a53a4c3238c 777 } \
lorcansmith 0:2a53a4c3238c 778 if (old) { \
lorcansmith 0:2a53a4c3238c 779 GETLONG(l, p); \
lorcansmith 0:2a53a4c3238c 780 cilong = htonl(l); \
lorcansmith 0:2a53a4c3238c 781 /* Check rejected value. */ \
lorcansmith 0:2a53a4c3238c 782 if (cilong != val2) { \
lorcansmith 0:2a53a4c3238c 783 goto bad; \
lorcansmith 0:2a53a4c3238c 784 } \
lorcansmith 0:2a53a4c3238c 785 } \
lorcansmith 0:2a53a4c3238c 786 try.neg = 0; \
lorcansmith 0:2a53a4c3238c 787 }
lorcansmith 0:2a53a4c3238c 788
lorcansmith 0:2a53a4c3238c 789 #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
lorcansmith 0:2a53a4c3238c 790 if (go->neg && \
lorcansmith 0:2a53a4c3238c 791 p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
lorcansmith 0:2a53a4c3238c 792 len >= p[1] && \
lorcansmith 0:2a53a4c3238c 793 p[0] == opt) { \
lorcansmith 0:2a53a4c3238c 794 len -= p[1]; \
lorcansmith 0:2a53a4c3238c 795 INCPTR(2, p); \
lorcansmith 0:2a53a4c3238c 796 GETSHORT(cishort, p); \
lorcansmith 0:2a53a4c3238c 797 /* Check rejected value. */ \
lorcansmith 0:2a53a4c3238c 798 if (cishort != val) { \
lorcansmith 0:2a53a4c3238c 799 goto bad; \
lorcansmith 0:2a53a4c3238c 800 } \
lorcansmith 0:2a53a4c3238c 801 if (!old) { \
lorcansmith 0:2a53a4c3238c 802 GETCHAR(cimaxslotindex, p); \
lorcansmith 0:2a53a4c3238c 803 if (cimaxslotindex != maxslot) { \
lorcansmith 0:2a53a4c3238c 804 goto bad; \
lorcansmith 0:2a53a4c3238c 805 } \
lorcansmith 0:2a53a4c3238c 806 GETCHAR(ciflag, p); \
lorcansmith 0:2a53a4c3238c 807 if (ciflag != cflag) { \
lorcansmith 0:2a53a4c3238c 808 goto bad; \
lorcansmith 0:2a53a4c3238c 809 } \
lorcansmith 0:2a53a4c3238c 810 } \
lorcansmith 0:2a53a4c3238c 811 try.neg = 0; \
lorcansmith 0:2a53a4c3238c 812 }
lorcansmith 0:2a53a4c3238c 813
lorcansmith 0:2a53a4c3238c 814 #define REJCIDNS(opt, neg, dnsaddr) \
lorcansmith 0:2a53a4c3238c 815 if (go->neg && \
lorcansmith 0:2a53a4c3238c 816 ((cilen = p[1]) == CILEN_ADDR) && \
lorcansmith 0:2a53a4c3238c 817 len >= cilen && \
lorcansmith 0:2a53a4c3238c 818 p[0] == opt) { \
lorcansmith 0:2a53a4c3238c 819 u32_t l; \
lorcansmith 0:2a53a4c3238c 820 len -= cilen; \
lorcansmith 0:2a53a4c3238c 821 INCPTR(2, p); \
lorcansmith 0:2a53a4c3238c 822 GETLONG(l, p); \
lorcansmith 0:2a53a4c3238c 823 cilong = htonl(l); \
lorcansmith 0:2a53a4c3238c 824 /* Check rejected value. */ \
lorcansmith 0:2a53a4c3238c 825 if (cilong != dnsaddr) { \
lorcansmith 0:2a53a4c3238c 826 goto bad; \
lorcansmith 0:2a53a4c3238c 827 } \
lorcansmith 0:2a53a4c3238c 828 try.neg = 0; \
lorcansmith 0:2a53a4c3238c 829 }
lorcansmith 0:2a53a4c3238c 830
lorcansmith 0:2a53a4c3238c 831 REJCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr,
lorcansmith 0:2a53a4c3238c 832 go->old_addrs, go->ouraddr, go->hisaddr);
lorcansmith 0:2a53a4c3238c 833
lorcansmith 0:2a53a4c3238c 834 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
lorcansmith 0:2a53a4c3238c 835 go->maxslotindex, go->cflag);
lorcansmith 0:2a53a4c3238c 836
lorcansmith 0:2a53a4c3238c 837 REJCIDNS(CI_MS_DNS1, req_dns1, go->dnsaddr[0]);
lorcansmith 0:2a53a4c3238c 838
lorcansmith 0:2a53a4c3238c 839 REJCIDNS(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
lorcansmith 0:2a53a4c3238c 840
lorcansmith 0:2a53a4c3238c 841 /*
lorcansmith 0:2a53a4c3238c 842 * If there are any remaining CIs, then this packet is bad.
lorcansmith 0:2a53a4c3238c 843 */
lorcansmith 0:2a53a4c3238c 844 if (len != 0) {
lorcansmith 0:2a53a4c3238c 845 goto bad;
lorcansmith 0:2a53a4c3238c 846 }
lorcansmith 0:2a53a4c3238c 847 /*
lorcansmith 0:2a53a4c3238c 848 * Now we can update state.
lorcansmith 0:2a53a4c3238c 849 */
lorcansmith 0:2a53a4c3238c 850 if (f->state != LS_OPENED) {
lorcansmith 0:2a53a4c3238c 851 *go = try;
lorcansmith 0:2a53a4c3238c 852 }
lorcansmith 0:2a53a4c3238c 853 return 1;
lorcansmith 0:2a53a4c3238c 854
lorcansmith 0:2a53a4c3238c 855 bad:
lorcansmith 0:2a53a4c3238c 856 IPCPDEBUG(LOG_INFO, ("ipcp_rejci: received bad Reject!\n"));
lorcansmith 0:2a53a4c3238c 857 return 0;
lorcansmith 0:2a53a4c3238c 858 }
lorcansmith 0:2a53a4c3238c 859
lorcansmith 0:2a53a4c3238c 860
lorcansmith 0:2a53a4c3238c 861 /*
lorcansmith 0:2a53a4c3238c 862 * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
lorcansmith 0:2a53a4c3238c 863 *
lorcansmith 0:2a53a4c3238c 864 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
lorcansmith 0:2a53a4c3238c 865 * appropriately. If reject_if_disagree is non-zero, doesn't return
lorcansmith 0:2a53a4c3238c 866 * CONFNAK; returns CONFREJ if it can't return CONFACK.
lorcansmith 0:2a53a4c3238c 867 */
lorcansmith 0:2a53a4c3238c 868 static int
lorcansmith 0:2a53a4c3238c 869 ipcp_reqci(fsm *f, u_char *inp/* Requested CIs */,int *len/* Length of requested CIs */,int reject_if_disagree)
lorcansmith 0:2a53a4c3238c 870 {
lorcansmith 0:2a53a4c3238c 871 ipcp_options *wo = &ipcp_wantoptions[f->unit];
lorcansmith 0:2a53a4c3238c 872 ipcp_options *ho = &ipcp_hisoptions[f->unit];
lorcansmith 0:2a53a4c3238c 873 ipcp_options *ao = &ipcp_allowoptions[f->unit];
lorcansmith 0:2a53a4c3238c 874 #ifdef OLD_CI_ADDRS
lorcansmith 0:2a53a4c3238c 875 ipcp_options *go = &ipcp_gotoptions[f->unit];
lorcansmith 0:2a53a4c3238c 876 #endif
lorcansmith 0:2a53a4c3238c 877 u_char *cip, *next; /* Pointer to current and next CIs */
lorcansmith 0:2a53a4c3238c 878 u_short cilen, citype; /* Parsed len, type */
lorcansmith 0:2a53a4c3238c 879 u_short cishort; /* Parsed short value */
lorcansmith 0:2a53a4c3238c 880 u32_t tl, ciaddr1; /* Parsed address values */
lorcansmith 0:2a53a4c3238c 881 #ifdef OLD_CI_ADDRS
lorcansmith 0:2a53a4c3238c 882 u32_t ciaddr2; /* Parsed address values */
lorcansmith 0:2a53a4c3238c 883 #endif
lorcansmith 0:2a53a4c3238c 884 int rc = CONFACK; /* Final packet return code */
lorcansmith 0:2a53a4c3238c 885 int orc; /* Individual option return code */
lorcansmith 0:2a53a4c3238c 886 u_char *p; /* Pointer to next char to parse */
lorcansmith 0:2a53a4c3238c 887 u_char *ucp = inp; /* Pointer to current output char */
lorcansmith 0:2a53a4c3238c 888 int l = *len; /* Length left */
lorcansmith 0:2a53a4c3238c 889 u_char maxslotindex, cflag;
lorcansmith 0:2a53a4c3238c 890 int d;
lorcansmith 0:2a53a4c3238c 891
lorcansmith 0:2a53a4c3238c 892 cis_received[f->unit] = 1;
lorcansmith 0:2a53a4c3238c 893
lorcansmith 0:2a53a4c3238c 894 /*
lorcansmith 0:2a53a4c3238c 895 * Reset all his options.
lorcansmith 0:2a53a4c3238c 896 */
lorcansmith 0:2a53a4c3238c 897 BZERO(ho, sizeof(*ho));
lorcansmith 0:2a53a4c3238c 898
lorcansmith 0:2a53a4c3238c 899 /*
lorcansmith 0:2a53a4c3238c 900 * Process all his options.
lorcansmith 0:2a53a4c3238c 901 */
lorcansmith 0:2a53a4c3238c 902 next = inp;
lorcansmith 0:2a53a4c3238c 903 while (l) {
lorcansmith 0:2a53a4c3238c 904 orc = CONFACK; /* Assume success */
lorcansmith 0:2a53a4c3238c 905 cip = p = next; /* Remember begining of CI */
lorcansmith 0:2a53a4c3238c 906 if (l < 2 || /* Not enough data for CI header or */
lorcansmith 0:2a53a4c3238c 907 p[1] < 2 || /* CI length too small or */
lorcansmith 0:2a53a4c3238c 908 p[1] > l) { /* CI length too big? */
lorcansmith 0:2a53a4c3238c 909 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: bad CI length!\n"));
lorcansmith 0:2a53a4c3238c 910 orc = CONFREJ; /* Reject bad CI */
lorcansmith 0:2a53a4c3238c 911 cilen = (u_short)l;/* Reject till end of packet */
lorcansmith 0:2a53a4c3238c 912 l = 0; /* Don't loop again */
lorcansmith 0:2a53a4c3238c 913 goto endswitch;
lorcansmith 0:2a53a4c3238c 914 }
lorcansmith 0:2a53a4c3238c 915 GETCHAR(citype, p); /* Parse CI type */
lorcansmith 0:2a53a4c3238c 916 GETCHAR(cilen, p); /* Parse CI length */
lorcansmith 0:2a53a4c3238c 917 l -= cilen; /* Adjust remaining length */
lorcansmith 0:2a53a4c3238c 918 next += cilen; /* Step to next CI */
lorcansmith 0:2a53a4c3238c 919
lorcansmith 0:2a53a4c3238c 920 switch (citype) { /* Check CI type */
lorcansmith 0:2a53a4c3238c 921 #ifdef OLD_CI_ADDRS /* Need to save space... */
lorcansmith 0:2a53a4c3238c 922 case CI_ADDRS:
lorcansmith 0:2a53a4c3238c 923 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: received ADDRS\n"));
lorcansmith 0:2a53a4c3238c 924 if (!ao->neg_addr ||
lorcansmith 0:2a53a4c3238c 925 cilen != CILEN_ADDRS) { /* Check CI length */
lorcansmith 0:2a53a4c3238c 926 orc = CONFREJ; /* Reject CI */
lorcansmith 0:2a53a4c3238c 927 break;
lorcansmith 0:2a53a4c3238c 928 }
lorcansmith 0:2a53a4c3238c 929
lorcansmith 0:2a53a4c3238c 930 /*
lorcansmith 0:2a53a4c3238c 931 * If he has no address, or if we both have his address but
lorcansmith 0:2a53a4c3238c 932 * disagree about it, then NAK it with our idea.
lorcansmith 0:2a53a4c3238c 933 * In particular, if we don't know his address, but he does,
lorcansmith 0:2a53a4c3238c 934 * then accept it.
lorcansmith 0:2a53a4c3238c 935 */
lorcansmith 0:2a53a4c3238c 936 GETLONG(tl, p); /* Parse source address (his) */
lorcansmith 0:2a53a4c3238c 937 ciaddr1 = htonl(tl);
lorcansmith 0:2a53a4c3238c 938 IPCPDEBUG(LOG_INFO, ("his addr %s\n", inet_ntoa(ciaddr1)));
lorcansmith 0:2a53a4c3238c 939 if (ciaddr1 != wo->hisaddr
lorcansmith 0:2a53a4c3238c 940 && (ciaddr1 == 0 || !wo->accept_remote)) {
lorcansmith 0:2a53a4c3238c 941 orc = CONFNAK;
lorcansmith 0:2a53a4c3238c 942 if (!reject_if_disagree) {
lorcansmith 0:2a53a4c3238c 943 DECPTR(sizeof(u32_t), p);
lorcansmith 0:2a53a4c3238c 944 tl = ntohl(wo->hisaddr);
lorcansmith 0:2a53a4c3238c 945 PUTLONG(tl, p);
lorcansmith 0:2a53a4c3238c 946 }
lorcansmith 0:2a53a4c3238c 947 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
lorcansmith 0:2a53a4c3238c 948 /*
lorcansmith 0:2a53a4c3238c 949 * If neither we nor he knows his address, reject the option.
lorcansmith 0:2a53a4c3238c 950 */
lorcansmith 0:2a53a4c3238c 951 orc = CONFREJ;
lorcansmith 0:2a53a4c3238c 952 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
lorcansmith 0:2a53a4c3238c 953 break;
lorcansmith 0:2a53a4c3238c 954 }
lorcansmith 0:2a53a4c3238c 955
lorcansmith 0:2a53a4c3238c 956 /*
lorcansmith 0:2a53a4c3238c 957 * If he doesn't know our address, or if we both have our address
lorcansmith 0:2a53a4c3238c 958 * but disagree about it, then NAK it with our idea.
lorcansmith 0:2a53a4c3238c 959 */
lorcansmith 0:2a53a4c3238c 960 GETLONG(tl, p); /* Parse desination address (ours) */
lorcansmith 0:2a53a4c3238c 961 ciaddr2 = htonl(tl);
lorcansmith 0:2a53a4c3238c 962 IPCPDEBUG(LOG_INFO, ("our addr %s\n", inet_ntoa(ciaddr2)));
lorcansmith 0:2a53a4c3238c 963 if (ciaddr2 != wo->ouraddr) {
lorcansmith 0:2a53a4c3238c 964 if (ciaddr2 == 0 || !wo->accept_local) {
lorcansmith 0:2a53a4c3238c 965 orc = CONFNAK;
lorcansmith 0:2a53a4c3238c 966 if (!reject_if_disagree) {
lorcansmith 0:2a53a4c3238c 967 DECPTR(sizeof(u32_t), p);
lorcansmith 0:2a53a4c3238c 968 tl = ntohl(wo->ouraddr);
lorcansmith 0:2a53a4c3238c 969 PUTLONG(tl, p);
lorcansmith 0:2a53a4c3238c 970 }
lorcansmith 0:2a53a4c3238c 971 } else {
lorcansmith 0:2a53a4c3238c 972 go->ouraddr = ciaddr2; /* accept peer's idea */
lorcansmith 0:2a53a4c3238c 973 }
lorcansmith 0:2a53a4c3238c 974 }
lorcansmith 0:2a53a4c3238c 975
lorcansmith 0:2a53a4c3238c 976 ho->neg_addr = 1;
lorcansmith 0:2a53a4c3238c 977 ho->old_addrs = 1;
lorcansmith 0:2a53a4c3238c 978 ho->hisaddr = ciaddr1;
lorcansmith 0:2a53a4c3238c 979 ho->ouraddr = ciaddr2;
lorcansmith 0:2a53a4c3238c 980 break;
lorcansmith 0:2a53a4c3238c 981 #endif
lorcansmith 0:2a53a4c3238c 982
lorcansmith 0:2a53a4c3238c 983 case CI_ADDR:
lorcansmith 0:2a53a4c3238c 984 if (!ao->neg_addr) {
lorcansmith 0:2a53a4c3238c 985 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Reject ADDR not allowed\n"));
lorcansmith 0:2a53a4c3238c 986 orc = CONFREJ; /* Reject CI */
lorcansmith 0:2a53a4c3238c 987 break;
lorcansmith 0:2a53a4c3238c 988 } else if (cilen != CILEN_ADDR) { /* Check CI length */
lorcansmith 0:2a53a4c3238c 989 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Reject ADDR bad len\n"));
lorcansmith 0:2a53a4c3238c 990 orc = CONFREJ; /* Reject CI */
lorcansmith 0:2a53a4c3238c 991 break;
lorcansmith 0:2a53a4c3238c 992 }
lorcansmith 0:2a53a4c3238c 993
lorcansmith 0:2a53a4c3238c 994 /*
lorcansmith 0:2a53a4c3238c 995 * If he has no address, or if we both have his address but
lorcansmith 0:2a53a4c3238c 996 * disagree about it, then NAK it with our idea.
lorcansmith 0:2a53a4c3238c 997 * In particular, if we don't know his address, but he does,
lorcansmith 0:2a53a4c3238c 998 * then accept it.
lorcansmith 0:2a53a4c3238c 999 */
lorcansmith 0:2a53a4c3238c 1000 GETLONG(tl, p); /* Parse source address (his) */
lorcansmith 0:2a53a4c3238c 1001 ciaddr1 = htonl(tl);
lorcansmith 0:2a53a4c3238c 1002 if (ciaddr1 != wo->hisaddr
lorcansmith 0:2a53a4c3238c 1003 && (ciaddr1 == 0 || !wo->accept_remote)) {
lorcansmith 0:2a53a4c3238c 1004 orc = CONFNAK;
lorcansmith 0:2a53a4c3238c 1005 if (!reject_if_disagree) {
lorcansmith 0:2a53a4c3238c 1006 DECPTR(sizeof(u32_t), p);
lorcansmith 0:2a53a4c3238c 1007 tl = ntohl(wo->hisaddr);
lorcansmith 0:2a53a4c3238c 1008 PUTLONG(tl, p);
lorcansmith 0:2a53a4c3238c 1009 }
lorcansmith 0:2a53a4c3238c 1010 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Nak ADDR %s\n", inet_ntoa(ciaddr1)));
lorcansmith 0:2a53a4c3238c 1011 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
lorcansmith 0:2a53a4c3238c 1012 /*
lorcansmith 0:2a53a4c3238c 1013 * Don't ACK an address of 0.0.0.0 - reject it instead.
lorcansmith 0:2a53a4c3238c 1014 */
lorcansmith 0:2a53a4c3238c 1015 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Reject ADDR %s\n", inet_ntoa(ciaddr1)));
lorcansmith 0:2a53a4c3238c 1016 orc = CONFREJ;
lorcansmith 0:2a53a4c3238c 1017 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
lorcansmith 0:2a53a4c3238c 1018 break;
lorcansmith 0:2a53a4c3238c 1019 }
lorcansmith 0:2a53a4c3238c 1020
lorcansmith 0:2a53a4c3238c 1021 ho->neg_addr = 1;
lorcansmith 0:2a53a4c3238c 1022 ho->hisaddr = ciaddr1;
lorcansmith 0:2a53a4c3238c 1023 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: ADDR %s\n", inet_ntoa(ciaddr1)));
lorcansmith 0:2a53a4c3238c 1024 break;
lorcansmith 0:2a53a4c3238c 1025
lorcansmith 0:2a53a4c3238c 1026 case CI_MS_DNS1:
lorcansmith 0:2a53a4c3238c 1027 case CI_MS_DNS2:
lorcansmith 0:2a53a4c3238c 1028 /* Microsoft primary or secondary DNS request */
lorcansmith 0:2a53a4c3238c 1029 d = citype == CI_MS_DNS2;
lorcansmith 0:2a53a4c3238c 1030
lorcansmith 0:2a53a4c3238c 1031 /* If we do not have a DNS address then we cannot send it */
lorcansmith 0:2a53a4c3238c 1032 if (ao->dnsaddr[d] == 0 ||
lorcansmith 0:2a53a4c3238c 1033 cilen != CILEN_ADDR) { /* Check CI length */
lorcansmith 0:2a53a4c3238c 1034 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting DNS%d Request\n", d+1));
lorcansmith 0:2a53a4c3238c 1035 orc = CONFREJ; /* Reject CI */
lorcansmith 0:2a53a4c3238c 1036 break;
lorcansmith 0:2a53a4c3238c 1037 }
lorcansmith 0:2a53a4c3238c 1038 GETLONG(tl, p);
lorcansmith 0:2a53a4c3238c 1039 if (htonl(tl) != ao->dnsaddr[d]) {
lorcansmith 0:2a53a4c3238c 1040 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Naking DNS%d Request %s\n",
lorcansmith 0:2a53a4c3238c 1041 d+1, inet_ntoa(tl)));
lorcansmith 0:2a53a4c3238c 1042 DECPTR(sizeof(u32_t), p);
lorcansmith 0:2a53a4c3238c 1043 tl = ntohl(ao->dnsaddr[d]);
lorcansmith 0:2a53a4c3238c 1044 PUTLONG(tl, p);
lorcansmith 0:2a53a4c3238c 1045 orc = CONFNAK;
lorcansmith 0:2a53a4c3238c 1046 }
lorcansmith 0:2a53a4c3238c 1047 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: received DNS%d Request\n", d+1));
lorcansmith 0:2a53a4c3238c 1048 break;
lorcansmith 0:2a53a4c3238c 1049
lorcansmith 0:2a53a4c3238c 1050 case CI_MS_WINS1:
lorcansmith 0:2a53a4c3238c 1051 case CI_MS_WINS2:
lorcansmith 0:2a53a4c3238c 1052 /* Microsoft primary or secondary WINS request */
lorcansmith 0:2a53a4c3238c 1053 d = citype == CI_MS_WINS2;
lorcansmith 0:2a53a4c3238c 1054 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: received WINS%d Request\n", d+1));
lorcansmith 0:2a53a4c3238c 1055
lorcansmith 0:2a53a4c3238c 1056 /* If we do not have a DNS address then we cannot send it */
lorcansmith 0:2a53a4c3238c 1057 if (ao->winsaddr[d] == 0 ||
lorcansmith 0:2a53a4c3238c 1058 cilen != CILEN_ADDR) { /* Check CI length */
lorcansmith 0:2a53a4c3238c 1059 orc = CONFREJ; /* Reject CI */
lorcansmith 0:2a53a4c3238c 1060 break;
lorcansmith 0:2a53a4c3238c 1061 }
lorcansmith 0:2a53a4c3238c 1062 GETLONG(tl, p);
lorcansmith 0:2a53a4c3238c 1063 if (htonl(tl) != ao->winsaddr[d]) {
lorcansmith 0:2a53a4c3238c 1064 DECPTR(sizeof(u32_t), p);
lorcansmith 0:2a53a4c3238c 1065 tl = ntohl(ao->winsaddr[d]);
lorcansmith 0:2a53a4c3238c 1066 PUTLONG(tl, p);
lorcansmith 0:2a53a4c3238c 1067 orc = CONFNAK;
lorcansmith 0:2a53a4c3238c 1068 }
lorcansmith 0:2a53a4c3238c 1069 break;
lorcansmith 0:2a53a4c3238c 1070
lorcansmith 0:2a53a4c3238c 1071 case CI_COMPRESSTYPE:
lorcansmith 0:2a53a4c3238c 1072 if (!ao->neg_vj) {
lorcansmith 0:2a53a4c3238c 1073 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting COMPRESSTYPE not allowed\n"));
lorcansmith 0:2a53a4c3238c 1074 orc = CONFREJ;
lorcansmith 0:2a53a4c3238c 1075 break;
lorcansmith 0:2a53a4c3238c 1076 } else if (cilen != CILEN_VJ && cilen != CILEN_COMPRESS) {
lorcansmith 0:2a53a4c3238c 1077 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting COMPRESSTYPE len=%d\n", cilen));
lorcansmith 0:2a53a4c3238c 1078 orc = CONFREJ;
lorcansmith 0:2a53a4c3238c 1079 break;
lorcansmith 0:2a53a4c3238c 1080 }
lorcansmith 0:2a53a4c3238c 1081 GETSHORT(cishort, p);
lorcansmith 0:2a53a4c3238c 1082
lorcansmith 0:2a53a4c3238c 1083 if (!(cishort == IPCP_VJ_COMP ||
lorcansmith 0:2a53a4c3238c 1084 (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) {
lorcansmith 0:2a53a4c3238c 1085 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting COMPRESSTYPE %d\n", cishort));
lorcansmith 0:2a53a4c3238c 1086 orc = CONFREJ;
lorcansmith 0:2a53a4c3238c 1087 break;
lorcansmith 0:2a53a4c3238c 1088 }
lorcansmith 0:2a53a4c3238c 1089
lorcansmith 0:2a53a4c3238c 1090 ho->neg_vj = 1;
lorcansmith 0:2a53a4c3238c 1091 ho->vj_protocol = cishort;
lorcansmith 0:2a53a4c3238c 1092 if (cilen == CILEN_VJ) {
lorcansmith 0:2a53a4c3238c 1093 GETCHAR(maxslotindex, p);
lorcansmith 0:2a53a4c3238c 1094 if (maxslotindex > ao->maxslotindex) {
lorcansmith 0:2a53a4c3238c 1095 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Naking VJ max slot %d\n", maxslotindex));
lorcansmith 0:2a53a4c3238c 1096 orc = CONFNAK;
lorcansmith 0:2a53a4c3238c 1097 if (!reject_if_disagree) {
lorcansmith 0:2a53a4c3238c 1098 DECPTR(1, p);
lorcansmith 0:2a53a4c3238c 1099 PUTCHAR(ao->maxslotindex, p);
lorcansmith 0:2a53a4c3238c 1100 }
lorcansmith 0:2a53a4c3238c 1101 }
lorcansmith 0:2a53a4c3238c 1102 GETCHAR(cflag, p);
lorcansmith 0:2a53a4c3238c 1103 if (cflag && !ao->cflag) {
lorcansmith 0:2a53a4c3238c 1104 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Naking VJ cflag %d\n", cflag));
lorcansmith 0:2a53a4c3238c 1105 orc = CONFNAK;
lorcansmith 0:2a53a4c3238c 1106 if (!reject_if_disagree) {
lorcansmith 0:2a53a4c3238c 1107 DECPTR(1, p);
lorcansmith 0:2a53a4c3238c 1108 PUTCHAR(wo->cflag, p);
lorcansmith 0:2a53a4c3238c 1109 }
lorcansmith 0:2a53a4c3238c 1110 }
lorcansmith 0:2a53a4c3238c 1111 ho->maxslotindex = maxslotindex;
lorcansmith 0:2a53a4c3238c 1112 ho->cflag = cflag;
lorcansmith 0:2a53a4c3238c 1113 } else {
lorcansmith 0:2a53a4c3238c 1114 ho->old_vj = 1;
lorcansmith 0:2a53a4c3238c 1115 ho->maxslotindex = MAX_SLOTS - 1;
lorcansmith 0:2a53a4c3238c 1116 ho->cflag = 1;
lorcansmith 0:2a53a4c3238c 1117 }
lorcansmith 0:2a53a4c3238c 1118 IPCPDEBUG(LOG_INFO, (
lorcansmith 0:2a53a4c3238c 1119 "ipcp_reqci: received COMPRESSTYPE p=%d old=%d maxslot=%d cflag=%d\n",
lorcansmith 0:2a53a4c3238c 1120 ho->vj_protocol, ho->old_vj, ho->maxslotindex, ho->cflag));
lorcansmith 0:2a53a4c3238c 1121 break;
lorcansmith 0:2a53a4c3238c 1122
lorcansmith 0:2a53a4c3238c 1123 default:
lorcansmith 0:2a53a4c3238c 1124 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting unknown CI type %d\n", citype));
lorcansmith 0:2a53a4c3238c 1125 orc = CONFREJ;
lorcansmith 0:2a53a4c3238c 1126 break;
lorcansmith 0:2a53a4c3238c 1127 }
lorcansmith 0:2a53a4c3238c 1128
lorcansmith 0:2a53a4c3238c 1129 endswitch:
lorcansmith 0:2a53a4c3238c 1130 if (orc == CONFACK && /* Good CI */
lorcansmith 0:2a53a4c3238c 1131 rc != CONFACK) { /* but prior CI wasnt? */
lorcansmith 0:2a53a4c3238c 1132 continue; /* Don't send this one */
lorcansmith 0:2a53a4c3238c 1133 }
lorcansmith 0:2a53a4c3238c 1134
lorcansmith 0:2a53a4c3238c 1135 if (orc == CONFNAK) { /* Nak this CI? */
lorcansmith 0:2a53a4c3238c 1136 if (reject_if_disagree) { /* Getting fed up with sending NAKs? */
lorcansmith 0:2a53a4c3238c 1137 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting too many naks\n"));
lorcansmith 0:2a53a4c3238c 1138 orc = CONFREJ; /* Get tough if so */
lorcansmith 0:2a53a4c3238c 1139 } else {
lorcansmith 0:2a53a4c3238c 1140 if (rc == CONFREJ) { /* Rejecting prior CI? */
lorcansmith 0:2a53a4c3238c 1141 continue; /* Don't send this one */
lorcansmith 0:2a53a4c3238c 1142 }
lorcansmith 0:2a53a4c3238c 1143 if (rc == CONFACK) { /* Ack'd all prior CIs? */
lorcansmith 0:2a53a4c3238c 1144 rc = CONFNAK; /* Not anymore... */
lorcansmith 0:2a53a4c3238c 1145 ucp = inp; /* Backup */
lorcansmith 0:2a53a4c3238c 1146 }
lorcansmith 0:2a53a4c3238c 1147 }
lorcansmith 0:2a53a4c3238c 1148 }
lorcansmith 0:2a53a4c3238c 1149
lorcansmith 0:2a53a4c3238c 1150 if (orc == CONFREJ && /* Reject this CI */
lorcansmith 0:2a53a4c3238c 1151 rc != CONFREJ) { /* but no prior ones? */
lorcansmith 0:2a53a4c3238c 1152 rc = CONFREJ;
lorcansmith 0:2a53a4c3238c 1153 ucp = inp; /* Backup */
lorcansmith 0:2a53a4c3238c 1154 }
lorcansmith 0:2a53a4c3238c 1155
lorcansmith 0:2a53a4c3238c 1156 /* Need to move CI? */
lorcansmith 0:2a53a4c3238c 1157 if (ucp != cip) {
lorcansmith 0:2a53a4c3238c 1158 BCOPY(cip, ucp, cilen); /* Move it */
lorcansmith 0:2a53a4c3238c 1159 }
lorcansmith 0:2a53a4c3238c 1160
lorcansmith 0:2a53a4c3238c 1161 /* Update output pointer */
lorcansmith 0:2a53a4c3238c 1162 INCPTR(cilen, ucp);
lorcansmith 0:2a53a4c3238c 1163 }
lorcansmith 0:2a53a4c3238c 1164
lorcansmith 0:2a53a4c3238c 1165 /*
lorcansmith 0:2a53a4c3238c 1166 * If we aren't rejecting this packet, and we want to negotiate
lorcansmith 0:2a53a4c3238c 1167 * their address, and they didn't send their address, then we
lorcansmith 0:2a53a4c3238c 1168 * send a NAK with a CI_ADDR option appended. We assume the
lorcansmith 0:2a53a4c3238c 1169 * input buffer is long enough that we can append the extra
lorcansmith 0:2a53a4c3238c 1170 * option safely.
lorcansmith 0:2a53a4c3238c 1171 */
lorcansmith 0:2a53a4c3238c 1172 if (rc != CONFREJ && !ho->neg_addr &&
lorcansmith 0:2a53a4c3238c 1173 wo->req_addr && !reject_if_disagree) {
lorcansmith 0:2a53a4c3238c 1174 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Requesting peer address\n"));
lorcansmith 0:2a53a4c3238c 1175 if (rc == CONFACK) {
lorcansmith 0:2a53a4c3238c 1176 rc = CONFNAK;
lorcansmith 0:2a53a4c3238c 1177 ucp = inp; /* reset pointer */
lorcansmith 0:2a53a4c3238c 1178 wo->req_addr = 0; /* don't ask again */
lorcansmith 0:2a53a4c3238c 1179 }
lorcansmith 0:2a53a4c3238c 1180 PUTCHAR(CI_ADDR, ucp);
lorcansmith 0:2a53a4c3238c 1181 PUTCHAR(CILEN_ADDR, ucp);
lorcansmith 0:2a53a4c3238c 1182 tl = ntohl(wo->hisaddr);
lorcansmith 0:2a53a4c3238c 1183 PUTLONG(tl, ucp);
lorcansmith 0:2a53a4c3238c 1184 }
lorcansmith 0:2a53a4c3238c 1185
lorcansmith 0:2a53a4c3238c 1186 *len = (int)(ucp - inp); /* Compute output length */
lorcansmith 0:2a53a4c3238c 1187 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: returning Configure-%s\n", CODENAME(rc)));
lorcansmith 0:2a53a4c3238c 1188 return (rc); /* Return final code */
lorcansmith 0:2a53a4c3238c 1189 }
lorcansmith 0:2a53a4c3238c 1190
lorcansmith 0:2a53a4c3238c 1191
lorcansmith 0:2a53a4c3238c 1192 #if 0
lorcansmith 0:2a53a4c3238c 1193 /*
lorcansmith 0:2a53a4c3238c 1194 * ip_check_options - check that any IP-related options are OK,
lorcansmith 0:2a53a4c3238c 1195 * and assign appropriate defaults.
lorcansmith 0:2a53a4c3238c 1196 */
lorcansmith 0:2a53a4c3238c 1197 static void
lorcansmith 0:2a53a4c3238c 1198 ip_check_options(u_long localAddr)
lorcansmith 0:2a53a4c3238c 1199 {
lorcansmith 0:2a53a4c3238c 1200 ipcp_options *wo = &ipcp_wantoptions[0];
lorcansmith 0:2a53a4c3238c 1201
lorcansmith 0:2a53a4c3238c 1202 /*
lorcansmith 0:2a53a4c3238c 1203 * Load our default IP address but allow the remote host to give us
lorcansmith 0:2a53a4c3238c 1204 * a new address.
lorcansmith 0:2a53a4c3238c 1205 */
lorcansmith 0:2a53a4c3238c 1206 if (wo->ouraddr == 0 && !ppp_settings.disable_defaultip) {
lorcansmith 0:2a53a4c3238c 1207 wo->accept_local = 1; /* don't insist on this default value */
lorcansmith 0:2a53a4c3238c 1208 wo->ouraddr = htonl(localAddr);
lorcansmith 0:2a53a4c3238c 1209 }
lorcansmith 0:2a53a4c3238c 1210 }
lorcansmith 0:2a53a4c3238c 1211 #endif
lorcansmith 0:2a53a4c3238c 1212
lorcansmith 0:2a53a4c3238c 1213
lorcansmith 0:2a53a4c3238c 1214 /*
lorcansmith 0:2a53a4c3238c 1215 * ipcp_up - IPCP has come UP.
lorcansmith 0:2a53a4c3238c 1216 *
lorcansmith 0:2a53a4c3238c 1217 * Configure the IP network interface appropriately and bring it up.
lorcansmith 0:2a53a4c3238c 1218 */
lorcansmith 0:2a53a4c3238c 1219 static void
lorcansmith 0:2a53a4c3238c 1220 ipcp_up(fsm *f)
lorcansmith 0:2a53a4c3238c 1221 {
lorcansmith 0:2a53a4c3238c 1222 u32_t mask;
lorcansmith 0:2a53a4c3238c 1223 ipcp_options *ho = &ipcp_hisoptions[f->unit];
lorcansmith 0:2a53a4c3238c 1224 ipcp_options *go = &ipcp_gotoptions[f->unit];
lorcansmith 0:2a53a4c3238c 1225 ipcp_options *wo = &ipcp_wantoptions[f->unit];
lorcansmith 0:2a53a4c3238c 1226
lorcansmith 0:2a53a4c3238c 1227 np_up(f->unit, PPP_IP);
lorcansmith 0:2a53a4c3238c 1228 IPCPDEBUG(LOG_INFO, ("ipcp: up\n"));
lorcansmith 0:2a53a4c3238c 1229
lorcansmith 0:2a53a4c3238c 1230 /*
lorcansmith 0:2a53a4c3238c 1231 * We must have a non-zero IP address for both ends of the link.
lorcansmith 0:2a53a4c3238c 1232 */
lorcansmith 0:2a53a4c3238c 1233 if (!ho->neg_addr) {
lorcansmith 0:2a53a4c3238c 1234 ho->hisaddr = wo->hisaddr;
lorcansmith 0:2a53a4c3238c 1235 }
lorcansmith 0:2a53a4c3238c 1236 #ifdef __PPP_STRICT_IMPL__ //DG : Kludge for bad 3g providers PPP impl
lorcansmith 0:2a53a4c3238c 1237 if (ho->hisaddr == 0) {
lorcansmith 0:2a53a4c3238c 1238 IPCPDEBUG(LOG_ERR, ("Could not determine remote IP address\n"));
lorcansmith 0:2a53a4c3238c 1239 ipcp_close(f->unit, "Could not determine remote IP address");
lorcansmith 0:2a53a4c3238c 1240 return;
lorcansmith 0:2a53a4c3238c 1241 }
lorcansmith 0:2a53a4c3238c 1242 #endif
lorcansmith 0:2a53a4c3238c 1243 if (go->ouraddr == 0) {
lorcansmith 0:2a53a4c3238c 1244 IPCPDEBUG(LOG_ERR, ("Could not determine local IP address\n"));
lorcansmith 0:2a53a4c3238c 1245 ipcp_close(f->unit, "Could not determine local IP address");
lorcansmith 0:2a53a4c3238c 1246 return;
lorcansmith 0:2a53a4c3238c 1247 }
lorcansmith 0:2a53a4c3238c 1248
lorcansmith 0:2a53a4c3238c 1249 if (ppp_settings.usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
lorcansmith 0:2a53a4c3238c 1250 /*pppGotDNSAddrs(go->dnsaddr[0], go->dnsaddr[1]);*/
lorcansmith 0:2a53a4c3238c 1251 }
lorcansmith 0:2a53a4c3238c 1252
lorcansmith 0:2a53a4c3238c 1253 /*
lorcansmith 0:2a53a4c3238c 1254 * Check that the peer is allowed to use the IP address it wants.
lorcansmith 0:2a53a4c3238c 1255 */
lorcansmith 0:2a53a4c3238c 1256 if (!auth_ip_addr(f->unit, ho->hisaddr)) {
lorcansmith 0:2a53a4c3238c 1257 IPCPDEBUG(LOG_ERR, ("Peer is not authorized to use remote address %s\n",
lorcansmith 0:2a53a4c3238c 1258 inet_ntoa(ho->hisaddr)));
lorcansmith 0:2a53a4c3238c 1259 ipcp_close(f->unit, "Unauthorized remote IP address");
lorcansmith 0:2a53a4c3238c 1260 return;
lorcansmith 0:2a53a4c3238c 1261 }
lorcansmith 0:2a53a4c3238c 1262
lorcansmith 0:2a53a4c3238c 1263 /* set tcp compression */
lorcansmith 0:2a53a4c3238c 1264 sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex);
lorcansmith 0:2a53a4c3238c 1265
lorcansmith 0:2a53a4c3238c 1266 /*
lorcansmith 0:2a53a4c3238c 1267 * Set IP addresses and (if specified) netmask.
lorcansmith 0:2a53a4c3238c 1268 */
lorcansmith 0:2a53a4c3238c 1269 mask = GetMask(go->ouraddr);
lorcansmith 0:2a53a4c3238c 1270
lorcansmith 0:2a53a4c3238c 1271 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask, go->dnsaddr[0], go->dnsaddr[1])) {
lorcansmith 0:2a53a4c3238c 1272 IPCPDEBUG(LOG_WARNING, ("sifaddr failed\n"));
lorcansmith 0:2a53a4c3238c 1273 ipcp_close(f->unit, "Interface configuration failed");
lorcansmith 0:2a53a4c3238c 1274 return;
lorcansmith 0:2a53a4c3238c 1275 }
lorcansmith 0:2a53a4c3238c 1276
lorcansmith 0:2a53a4c3238c 1277 /* bring the interface up for IP */
lorcansmith 0:2a53a4c3238c 1278 if (!sifup(f->unit)) {
lorcansmith 0:2a53a4c3238c 1279 IPCPDEBUG(LOG_WARNING, ("sifup failed\n"));
lorcansmith 0:2a53a4c3238c 1280 ipcp_close(f->unit, "Interface configuration failed");
lorcansmith 0:2a53a4c3238c 1281 return;
lorcansmith 0:2a53a4c3238c 1282 }
lorcansmith 0:2a53a4c3238c 1283
lorcansmith 0:2a53a4c3238c 1284 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
lorcansmith 0:2a53a4c3238c 1285
lorcansmith 0:2a53a4c3238c 1286 /* assign a default route through the interface if required */
lorcansmith 0:2a53a4c3238c 1287 if (ipcp_wantoptions[f->unit].default_route) {
lorcansmith 0:2a53a4c3238c 1288 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr)) {
lorcansmith 0:2a53a4c3238c 1289 default_route_set[f->unit] = 1;
lorcansmith 0:2a53a4c3238c 1290 }
lorcansmith 0:2a53a4c3238c 1291 }
lorcansmith 0:2a53a4c3238c 1292
lorcansmith 0:2a53a4c3238c 1293 IPCPDEBUG(LOG_NOTICE, ("local IP address %s\n", inet_ntoa(go->ouraddr)));
lorcansmith 0:2a53a4c3238c 1294 IPCPDEBUG(LOG_NOTICE, ("remote IP address %s\n", inet_ntoa(ho->hisaddr)));
lorcansmith 0:2a53a4c3238c 1295 if (go->dnsaddr[0]) {
lorcansmith 0:2a53a4c3238c 1296 IPCPDEBUG(LOG_NOTICE, ("primary DNS address %s\n", inet_ntoa(go->dnsaddr[0])));
lorcansmith 0:2a53a4c3238c 1297 }
lorcansmith 0:2a53a4c3238c 1298 if (go->dnsaddr[1]) {
lorcansmith 0:2a53a4c3238c 1299 IPCPDEBUG(LOG_NOTICE, ("secondary DNS address %s\n", inet_ntoa(go->dnsaddr[1])));
lorcansmith 0:2a53a4c3238c 1300 }
lorcansmith 0:2a53a4c3238c 1301 }
lorcansmith 0:2a53a4c3238c 1302
lorcansmith 0:2a53a4c3238c 1303
lorcansmith 0:2a53a4c3238c 1304 /*
lorcansmith 0:2a53a4c3238c 1305 * ipcp_down - IPCP has gone DOWN.
lorcansmith 0:2a53a4c3238c 1306 *
lorcansmith 0:2a53a4c3238c 1307 * Take the IP network interface down, clear its addresses
lorcansmith 0:2a53a4c3238c 1308 * and delete routes through it.
lorcansmith 0:2a53a4c3238c 1309 */
lorcansmith 0:2a53a4c3238c 1310 static void
lorcansmith 0:2a53a4c3238c 1311 ipcp_down(fsm *f)
lorcansmith 0:2a53a4c3238c 1312 {
lorcansmith 0:2a53a4c3238c 1313 IPCPDEBUG(LOG_INFO, ("ipcp: down\n"));
lorcansmith 0:2a53a4c3238c 1314 np_down(f->unit, PPP_IP);
lorcansmith 0:2a53a4c3238c 1315 sifvjcomp(f->unit, 0, 0, 0);
lorcansmith 0:2a53a4c3238c 1316
lorcansmith 0:2a53a4c3238c 1317 sifdown(f->unit);
lorcansmith 0:2a53a4c3238c 1318 ipcp_clear_addrs(f->unit);
lorcansmith 0:2a53a4c3238c 1319 }
lorcansmith 0:2a53a4c3238c 1320
lorcansmith 0:2a53a4c3238c 1321
lorcansmith 0:2a53a4c3238c 1322 /*
lorcansmith 0:2a53a4c3238c 1323 * ipcp_clear_addrs() - clear the interface addresses, routes, etc.
lorcansmith 0:2a53a4c3238c 1324 */
lorcansmith 0:2a53a4c3238c 1325 static void
lorcansmith 0:2a53a4c3238c 1326 ipcp_clear_addrs(int unit)
lorcansmith 0:2a53a4c3238c 1327 {
lorcansmith 0:2a53a4c3238c 1328 u32_t ouraddr, hisaddr;
lorcansmith 0:2a53a4c3238c 1329
lorcansmith 0:2a53a4c3238c 1330 ouraddr = ipcp_gotoptions[unit].ouraddr;
lorcansmith 0:2a53a4c3238c 1331 hisaddr = ipcp_hisoptions[unit].hisaddr;
lorcansmith 0:2a53a4c3238c 1332 if (default_route_set[unit]) {
lorcansmith 0:2a53a4c3238c 1333 cifdefaultroute(unit, ouraddr, hisaddr);
lorcansmith 0:2a53a4c3238c 1334 default_route_set[unit] = 0;
lorcansmith 0:2a53a4c3238c 1335 }
lorcansmith 0:2a53a4c3238c 1336 cifaddr(unit, ouraddr, hisaddr);
lorcansmith 0:2a53a4c3238c 1337 }
lorcansmith 0:2a53a4c3238c 1338
lorcansmith 0:2a53a4c3238c 1339
lorcansmith 0:2a53a4c3238c 1340 /*
lorcansmith 0:2a53a4c3238c 1341 * ipcp_finished - possibly shut down the lower layers.
lorcansmith 0:2a53a4c3238c 1342 */
lorcansmith 0:2a53a4c3238c 1343 static void
lorcansmith 0:2a53a4c3238c 1344 ipcp_finished(fsm *f)
lorcansmith 0:2a53a4c3238c 1345 {
lorcansmith 0:2a53a4c3238c 1346 np_finished(f->unit, PPP_IP);
lorcansmith 0:2a53a4c3238c 1347 }
lorcansmith 0:2a53a4c3238c 1348
lorcansmith 0:2a53a4c3238c 1349 #if PPP_ADDITIONAL_CALLBACKS
lorcansmith 0:2a53a4c3238c 1350 static int
lorcansmith 0:2a53a4c3238c 1351 ipcp_printpkt(u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg)
lorcansmith 0:2a53a4c3238c 1352 {
lorcansmith 0:2a53a4c3238c 1353 LWIP_UNUSED_ARG(p);
lorcansmith 0:2a53a4c3238c 1354 LWIP_UNUSED_ARG(plen);
lorcansmith 0:2a53a4c3238c 1355 LWIP_UNUSED_ARG(printer);
lorcansmith 0:2a53a4c3238c 1356 LWIP_UNUSED_ARG(arg);
lorcansmith 0:2a53a4c3238c 1357 return 0;
lorcansmith 0:2a53a4c3238c 1358 }
lorcansmith 0:2a53a4c3238c 1359
lorcansmith 0:2a53a4c3238c 1360 /*
lorcansmith 0:2a53a4c3238c 1361 * ip_active_pkt - see if this IP packet is worth bringing the link up for.
lorcansmith 0:2a53a4c3238c 1362 * We don't bring the link up for IP fragments or for TCP FIN packets
lorcansmith 0:2a53a4c3238c 1363 * with no data.
lorcansmith 0:2a53a4c3238c 1364 */
lorcansmith 0:2a53a4c3238c 1365 #define IP_HDRLEN 20 /* bytes */
lorcansmith 0:2a53a4c3238c 1366 #define IP_OFFMASK 0x1fff
lorcansmith 0:2a53a4c3238c 1367 #define IPPROTO_TCP 6
lorcansmith 0:2a53a4c3238c 1368 #define TCP_HDRLEN 20
lorcansmith 0:2a53a4c3238c 1369 #define TH_FIN 0x01
lorcansmith 0:2a53a4c3238c 1370
lorcansmith 0:2a53a4c3238c 1371 /*
lorcansmith 0:2a53a4c3238c 1372 * We use these macros because the IP header may be at an odd address,
lorcansmith 0:2a53a4c3238c 1373 * and some compilers might use word loads to get th_off or ip_hl.
lorcansmith 0:2a53a4c3238c 1374 */
lorcansmith 0:2a53a4c3238c 1375
lorcansmith 0:2a53a4c3238c 1376 #define net_short(x) (((x)[0] << 8) + (x)[1])
lorcansmith 0:2a53a4c3238c 1377 #define get_iphl(x) (((unsigned char *)(x))[0] & 0xF)
lorcansmith 0:2a53a4c3238c 1378 #define get_ipoff(x) net_short((unsigned char *)(x) + 6)
lorcansmith 0:2a53a4c3238c 1379 #define get_ipproto(x) (((unsigned char *)(x))[9])
lorcansmith 0:2a53a4c3238c 1380 #define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
lorcansmith 0:2a53a4c3238c 1381 #define get_tcpflags(x) (((unsigned char *)(x))[13])
lorcansmith 0:2a53a4c3238c 1382
lorcansmith 0:2a53a4c3238c 1383 static int
lorcansmith 0:2a53a4c3238c 1384 ip_active_pkt(u_char *pkt, int len)
lorcansmith 0:2a53a4c3238c 1385 {
lorcansmith 0:2a53a4c3238c 1386 u_char *tcp;
lorcansmith 0:2a53a4c3238c 1387 int hlen;
lorcansmith 0:2a53a4c3238c 1388
lorcansmith 0:2a53a4c3238c 1389 len -= PPP_HDRLEN;
lorcansmith 0:2a53a4c3238c 1390 pkt += PPP_HDRLEN;
lorcansmith 0:2a53a4c3238c 1391 if (len < IP_HDRLEN) {
lorcansmith 0:2a53a4c3238c 1392 return 0;
lorcansmith 0:2a53a4c3238c 1393 }
lorcansmith 0:2a53a4c3238c 1394 if ((get_ipoff(pkt) & IP_OFFMASK) != 0) {
lorcansmith 0:2a53a4c3238c 1395 return 0;
lorcansmith 0:2a53a4c3238c 1396 }
lorcansmith 0:2a53a4c3238c 1397 if (get_ipproto(pkt) != IPPROTO_TCP) {
lorcansmith 0:2a53a4c3238c 1398 return 1;
lorcansmith 0:2a53a4c3238c 1399 }
lorcansmith 0:2a53a4c3238c 1400 hlen = get_iphl(pkt) * 4;
lorcansmith 0:2a53a4c3238c 1401 if (len < hlen + TCP_HDRLEN) {
lorcansmith 0:2a53a4c3238c 1402 return 0;
lorcansmith 0:2a53a4c3238c 1403 }
lorcansmith 0:2a53a4c3238c 1404 tcp = pkt + hlen;
lorcansmith 0:2a53a4c3238c 1405 if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == hlen + get_tcpoff(tcp) * 4) {
lorcansmith 0:2a53a4c3238c 1406 return 0;
lorcansmith 0:2a53a4c3238c 1407 }
lorcansmith 0:2a53a4c3238c 1408 return 1;
lorcansmith 0:2a53a4c3238c 1409 }
lorcansmith 0:2a53a4c3238c 1410 #endif /* PPP_ADDITIONAL_CALLBACKS */
lorcansmith 0:2a53a4c3238c 1411
lorcansmith 0:2a53a4c3238c 1412 #endif /* PPP_SUPPORT */