Port to C027 (using AppShield and Ethernet)

Dependencies:   C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

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