Forked from the DieterGraef Library

Fork of F7_Ethernet by Dieter Graef

Committer:
EmbeddedSam
Date:
Fri Nov 18 12:48:10 2016 +0000
Revision:
2:fdef48f830c0
Parent:
0:d26c1b55cfca
Linking MQTT together, starting with mbed-cli

Who changed what in which revision?

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