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