EthernetNetIf Compatibility.

Dependents:   XBeeWiFi_SPI_example

Fork of NetServicesSource by Donatien Garnier

Committer:
donatien
Date:
Fri Jul 09 14:46:47 2010 +0000
Revision:
4:fd826cad83c0
Parent:
0:632c9925f013

        

Who changed what in which revision?

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