1 /** In contrast to pppd 2.3.1, DNS support has been added, proxy-ARP and
2 dial-on-demand has been stripped. */
3 /*****************************************************************************
4 * ipcp.c - Network PPP IP Control Protocol program file.
6 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
7 * portions Copyright (c) 1997 by Global Election Systems Inc.
9 * The authors hereby grant permission to use, copy, modify, distribute,
10 * and license this software and its documentation for any purpose, provided
11 * that existing copyright notices are retained in all copies and that this
12 * notice and the following disclaimer are included verbatim in any
13 * distributions. No written agreement, license, or royalty fee is required
14 * for any of the authorized uses.
16 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 ******************************************************************************
30 * 03-01-01 Marc Boucher <marc@mbsi.ca>
32 * 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
34 *****************************************************************************/
36 * ipcp.c - PPP IP Control Protocol.
38 * Copyright (c) 1989 Carnegie Mellon University.
39 * All rights reserved.
41 * Redistribution and use in source and binary forms are permitted
42 * provided that the above copyright notice and this paragraph are
43 * duplicated in all such forms and that any documentation,
44 * advertising materials, and other materials related to such
45 * distribution and use acknowledge that the software was developed
46 * by Carnegie Mellon University. The name of the
47 * University may not be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
50 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
51 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
56 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
66 #include "lwip/inet.h"
70 /* #define OLD_CI_ADDRS 1 */ /* Support deprecated address negotiation. */
73 ipcp_options ipcp_wantoptions
[NUM_PPP
]; /* Options that we want to request */
74 ipcp_options ipcp_gotoptions
[NUM_PPP
]; /* Options that peer ack'd */
75 ipcp_options ipcp_allowoptions
[NUM_PPP
]; /* Options we allow peer to request */
76 ipcp_options ipcp_hisoptions
[NUM_PPP
]; /* Options that we ack'd */
79 static int default_route_set
[NUM_PPP
]; /* Have set up a default route */
80 static int cis_received
[NUM_PPP
]; /* # Conf-Reqs received */
84 * Callbacks for fsm code. (CI = Configuration Information)
86 static void ipcp_resetci (fsm
*); /* Reset our CI */
87 static int ipcp_cilen (fsm
*); /* Return length of our CI */
88 static void ipcp_addci (fsm
*, u_char
*, int *); /* Add our CI */
89 static int ipcp_ackci (fsm
*, u_char
*, int); /* Peer ack'd our CI */
90 static int ipcp_nakci (fsm
*, u_char
*, int); /* Peer nak'd our CI */
91 static int ipcp_rejci (fsm
*, u_char
*, int); /* Peer rej'd our CI */
92 static int ipcp_reqci (fsm
*, u_char
*, int *, int); /* Rcv CI */
93 static void ipcp_up (fsm
*); /* We're UP */
94 static void ipcp_down (fsm
*); /* We're DOWN */
95 #if PPP_ADDITIONAL_CALLBACKS
96 static void ipcp_script (fsm
*, char *); /* Run an up/down script */
98 static void ipcp_finished (fsm
*); /* Don't need lower layer */
101 fsm ipcp_fsm
[NUM_PPP
]; /* IPCP fsm structure */
104 static fsm_callbacks ipcp_callbacks
= { /* IPCP callback routines */
105 ipcp_resetci
, /* Reset our Configuration Information */
106 ipcp_cilen
, /* Length of our Configuration Information */
107 ipcp_addci
, /* Add our Configuration Information */
108 ipcp_ackci
, /* ACK our Configuration Information */
109 ipcp_nakci
, /* NAK our Configuration Information */
110 ipcp_rejci
, /* Reject our Configuration Information */
111 ipcp_reqci
, /* Request peer's Configuration Information */
112 ipcp_up
, /* Called when fsm reaches LS_OPENED state */
113 ipcp_down
, /* Called when fsm leaves LS_OPENED state */
114 NULL
, /* Called when we want the lower layer up */
115 ipcp_finished
, /* Called when we want the lower layer down */
116 NULL
, /* Called when Protocol-Reject received */
117 NULL
, /* Retransmission is necessary */
118 NULL
, /* Called to handle protocol-specific codes */
119 "IPCP" /* String name of protocol */
123 * Protocol entry points from main code.
125 static void ipcp_init (int);
126 static void ipcp_open (int);
127 static void ipcp_close (int, char *);
128 static void ipcp_lowerup (int);
129 static void ipcp_lowerdown (int);
130 static void ipcp_input (int, u_char
*, int);
131 static void ipcp_protrej (int);
134 struct protent ipcp_protent
= {
143 #if PPP_ADDITIONAL_CALLBACKS
146 #endif /* PPP_ADDITIONAL_CALLBACKS */
149 #if PPP_ADDITIONAL_CALLBACKS
153 #endif /* PPP_ADDITIONAL_CALLBACKS */
156 static void ipcp_clear_addrs (int);
159 * Lengths of configuration options.
162 #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
163 #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
164 #define CILEN_ADDR 6 /* new-style single address option */
165 #define CILEN_ADDRS 10 /* old-style dual address option */
168 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
169 (x) == CONFNAK ? "NAK" : "REJ")
173 * ipcp_init - Initialize IPCP.
178 fsm
*f
= &ipcp_fsm
[unit
];
179 ipcp_options
*wo
= &ipcp_wantoptions
[unit
];
180 ipcp_options
*ao
= &ipcp_allowoptions
[unit
];
183 f
->protocol
= PPP_IPCP
;
184 f
->callbacks
= &ipcp_callbacks
;
185 fsm_init(&ipcp_fsm
[unit
]);
187 memset(wo
, 0, sizeof(*wo
));
188 memset(ao
, 0, sizeof(*ao
));
194 #else /* VJ_SUPPORT */
196 #endif /* VJ_SUPPORT */
197 wo
->vj_protocol
= IPCP_VJ_COMP
;
198 wo
->maxslotindex
= MAX_SLOTS
- 1;
200 wo
->default_route
= 1;
205 #else /* VJ_SUPPORT */
207 #endif /* VJ_SUPPORT */
208 ao
->maxslotindex
= MAX_SLOTS
- 1;
210 ao
->default_route
= 1;
215 * ipcp_open - IPCP is allowed to come up.
220 fsm_open(&ipcp_fsm
[unit
]);
225 * ipcp_close - Take IPCP down.
228 ipcp_close(int unit
, char *reason
)
230 fsm_close(&ipcp_fsm
[unit
], reason
);
235 * ipcp_lowerup - The lower layer is up.
238 ipcp_lowerup(int unit
)
240 fsm_lowerup(&ipcp_fsm
[unit
]);
245 * ipcp_lowerdown - The lower layer is down.
248 ipcp_lowerdown(int unit
)
250 fsm_lowerdown(&ipcp_fsm
[unit
]);
255 * ipcp_input - Input IPCP packet.
258 ipcp_input(int unit
, u_char
*p
, int len
)
260 fsm_input(&ipcp_fsm
[unit
], p
, len
);
265 * ipcp_protrej - A Protocol-Reject was received for IPCP.
267 * Pretend the lower layer went down, so we shut up.
270 ipcp_protrej(int unit
)
272 fsm_lowerdown(&ipcp_fsm
[unit
]);
277 * ipcp_resetci - Reset our CI.
282 ipcp_options
*wo
= &ipcp_wantoptions
[f
->unit
];
284 wo
->req_addr
= wo
->neg_addr
&& ipcp_allowoptions
[f
->unit
].neg_addr
;
285 if (wo
->ouraddr
== 0) {
286 wo
->accept_local
= 1;
288 if (wo
->hisaddr
== 0) {
289 wo
->accept_remote
= 1;
291 /* Request DNS addresses from the peer */
292 wo
->req_dns1
= ppp_settings
.usepeerdns
;
293 wo
->req_dns2
= ppp_settings
.usepeerdns
;
294 ipcp_gotoptions
[f
->unit
] = *wo
;
295 cis_received
[f
->unit
] = 0;
300 * ipcp_cilen - Return length of our CI.
305 ipcp_options
*go
= &ipcp_gotoptions
[f
->unit
];
306 ipcp_options
*wo
= &ipcp_wantoptions
[f
->unit
];
307 ipcp_options
*ho
= &ipcp_hisoptions
[f
->unit
];
309 #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
310 #define LENCIADDR(neg, old) (neg ? (old? CILEN_ADDRS : CILEN_ADDR) : 0)
311 #define LENCIDNS(neg) (neg ? (CILEN_ADDR) : 0)
314 * First see if we want to change our options to the old
315 * forms because we have received old forms from the peer.
317 if (wo
->neg_addr
&& !go
->neg_addr
&& !go
->old_addrs
) {
318 /* use the old style of address negotiation */
322 if (wo
->neg_vj
&& !go
->neg_vj
&& !go
->old_vj
) {
323 /* try an older style of VJ negotiation */
324 if (cis_received
[f
->unit
] == 0) {
325 /* keep trying the new style until we see some CI from the peer */
328 /* use the old style only if the peer did */
329 if (ho
->neg_vj
&& ho
->old_vj
) {
332 go
->vj_protocol
= ho
->vj_protocol
;
337 return (LENCIADDR(go
->neg_addr
, go
->old_addrs
) +
338 LENCIVJ(go
->neg_vj
, go
->old_vj
) +
339 LENCIDNS(go
->req_dns1
) +
340 LENCIDNS(go
->req_dns2
));
345 * ipcp_addci - Add our desired CIs to a packet.
348 ipcp_addci(fsm
*f
, u_char
*ucp
, int *lenp
)
350 ipcp_options
*go
= &ipcp_gotoptions
[f
->unit
];
353 #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
355 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
356 if (len >= vjlen) { \
358 PUTCHAR(vjlen, ucp); \
359 PUTSHORT(val, ucp); \
361 PUTCHAR(maxslotindex, ucp); \
362 PUTCHAR(cflag, ucp); \
370 #define ADDCIADDR(opt, neg, old, val1, val2) \
372 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
373 if (len >= addrlen) { \
376 PUTCHAR(addrlen, ucp); \
389 #define ADDCIDNS(opt, neg, addr) \
391 if (len >= CILEN_ADDR) { \
394 PUTCHAR(CILEN_ADDR, ucp); \
403 ADDCIADDR((go
->old_addrs
? CI_ADDRS
: CI_ADDR
), go
->neg_addr
,
404 go
->old_addrs
, go
->ouraddr
, go
->hisaddr
);
406 ADDCIVJ(CI_COMPRESSTYPE
, go
->neg_vj
, go
->vj_protocol
, go
->old_vj
,
407 go
->maxslotindex
, go
->cflag
);
409 ADDCIDNS(CI_MS_DNS1
, go
->req_dns1
, go
->dnsaddr
[0]);
411 ADDCIDNS(CI_MS_DNS2
, go
->req_dns2
, go
->dnsaddr
[1]);
418 * ipcp_ackci - Ack our CIs.
425 ipcp_ackci(fsm
*f
, u_char
*p
, int len
)
427 ipcp_options
*go
= &ipcp_gotoptions
[f
->unit
];
428 u_short cilen
, citype
, cishort
;
430 u_char cimaxslotindex
, cicflag
;
433 * CIs must be in exactly the same order that we sent...
434 * Check packet length and CI length at each step.
435 * If we find any deviations, then this packet is bad.
438 #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
440 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
441 if ((len -= vjlen) < 0) { \
444 GETCHAR(citype, p); \
446 if (cilen != vjlen || \
450 GETSHORT(cishort, p); \
451 if (cishort != val) { \
455 GETCHAR(cimaxslotindex, p); \
456 if (cimaxslotindex != maxslotindex) { \
459 GETCHAR(cicflag, p); \
460 if (cicflag != cflag) { \
466 #define ACKCIADDR(opt, neg, old, val1, val2) \
468 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
470 if ((len -= addrlen) < 0) { \
473 GETCHAR(citype, p); \
475 if (cilen != addrlen || \
481 if (val1 != cilong) { \
487 if (val2 != cilong) { \
493 #define ACKCIDNS(opt, neg, addr) \
496 if ((len -= CILEN_ADDR) < 0) { \
499 GETCHAR(citype, p); \
501 if (cilen != CILEN_ADDR || \
507 if (addr != cilong) { \
512 ACKCIADDR((go
->old_addrs
? CI_ADDRS
: CI_ADDR
), go
->neg_addr
,
513 go
->old_addrs
, go
->ouraddr
, go
->hisaddr
);
515 ACKCIVJ(CI_COMPRESSTYPE
, go
->neg_vj
, go
->vj_protocol
, go
->old_vj
,
516 go
->maxslotindex
, go
->cflag
);
518 ACKCIDNS(CI_MS_DNS1
, go
->req_dns1
, go
->dnsaddr
[0]);
520 ACKCIDNS(CI_MS_DNS2
, go
->req_dns2
, go
->dnsaddr
[1]);
523 * If there are any remaining CIs, then this packet is bad.
531 IPCPDEBUG(LOG_INFO
, ("ipcp_ackci: received bad Ack!\n"));
536 * ipcp_nakci - Peer has sent a NAK for some of our CIs.
537 * This should not modify any state if the Nak is bad
538 * or if IPCP is in the LS_OPENED state.
545 ipcp_nakci(fsm
*f
, u_char
*p
, int len
)
547 ipcp_options
*go
= &ipcp_gotoptions
[f
->unit
];
548 u_char cimaxslotindex
, cicflag
;
549 u_char citype
, cilen
, *next
;
551 u32_t ciaddr1
, ciaddr2
, l
, cidnsaddr
;
552 ipcp_options no
; /* options we've seen Naks for */
553 ipcp_options
try; /* options to request next time */
555 BZERO(&no
, sizeof(no
));
559 * Any Nak'd CIs must be in exactly the same order that we sent.
560 * Check packet length and CI length at each step.
561 * If we find any deviations, then this packet is bad.
563 #define NAKCIADDR(opt, neg, old, code) \
565 len >= (cilen = (old? CILEN_ADDRS: CILEN_ADDR)) && \
571 ciaddr1 = htonl(l); \
574 ciaddr2 = htonl(l); \
583 #define NAKCIVJ(opt, neg, code) \
585 ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
590 GETSHORT(cishort, p); \
595 #define NAKCIDNS(opt, neg, code) \
597 ((cilen = p[1]) == CILEN_ADDR) && \
603 cidnsaddr = htonl(l); \
609 * Accept the peer's idea of {our,his} address, if different
610 * from our idea, only if the accept_{local,remote} flag is set.
612 NAKCIADDR((go
->old_addrs
? CI_ADDRS
: CI_ADDR
), neg_addr
, go
->old_addrs
,
613 if (go
->accept_local
&& ciaddr1
) { /* Do we know our address? */
614 try.ouraddr
= ciaddr1
;
615 IPCPDEBUG(LOG_INFO
, ("local IP address %s\n",
616 inet_ntoa(ciaddr1
)));
618 if (go
->accept_remote
&& ciaddr2
) { /* Does he know his? */
619 try.hisaddr
= ciaddr2
;
620 IPCPDEBUG(LOG_INFO
, ("remote IP address %s\n",
621 inet_ntoa(ciaddr2
)));
626 * Accept the peer's value of maxslotindex provided that it
627 * is less than what we asked for. Turn off slot-ID compression
628 * if the peer wants. Send old-style compress-type option if
631 NAKCIVJ(CI_COMPRESSTYPE
, neg_vj
,
632 if (cilen
== CILEN_VJ
) {
633 GETCHAR(cimaxslotindex
, p
);
635 if (cishort
== IPCP_VJ_COMP
) {
637 if (cimaxslotindex
< go
->maxslotindex
) {
638 try.maxslotindex
= cimaxslotindex
;
647 if (cishort
== IPCP_VJ_COMP
|| cishort
== IPCP_VJ_COMP_OLD
) {
649 try.vj_protocol
= cishort
;
656 NAKCIDNS(CI_MS_DNS1
, req_dns1
,
657 try.dnsaddr
[0] = cidnsaddr
;
658 IPCPDEBUG(LOG_INFO
, ("primary DNS address %s\n", inet_ntoa(cidnsaddr
)));
661 NAKCIDNS(CI_MS_DNS2
, req_dns2
,
662 try.dnsaddr
[1] = cidnsaddr
;
663 IPCPDEBUG(LOG_INFO
, ("secondary DNS address %s\n", inet_ntoa(cidnsaddr
)));
667 * There may be remaining CIs, if the peer is requesting negotiation
668 * on an option that we didn't include in our request packet.
669 * If they want to negotiate about IP addresses, we comply.
670 * If they want us to ask for compression, we refuse.
672 while (len
> CILEN_VOID
) {
675 if( (len
-= cilen
) < 0 ) {
678 next
= p
+ cilen
- 2;
681 case CI_COMPRESSTYPE
:
682 if (go
->neg_vj
|| no
.neg_vj
||
683 (cilen
!= CILEN_VJ
&& cilen
!= CILEN_COMPRESS
)) {
689 if ((go
->neg_addr
&& go
->old_addrs
) || no
.old_addrs
690 || cilen
!= CILEN_ADDRS
) {
697 if (ciaddr1
&& go
->accept_local
) {
698 try.ouraddr
= ciaddr1
;
702 if (ciaddr2
&& go
->accept_remote
) {
703 try.hisaddr
= ciaddr2
;
708 if (go
->neg_addr
|| no
.neg_addr
|| cilen
!= CILEN_ADDR
) {
714 if (ciaddr1
&& go
->accept_local
) {
715 try.ouraddr
= ciaddr1
;
717 if (try.ouraddr
!= 0) {
726 /* If there is still anything left, this packet is bad. */
732 * OK, the Nak is good. Now we can update state.
734 if (f
->state
!= LS_OPENED
) {
741 IPCPDEBUG(LOG_INFO
, ("ipcp_nakci: received bad Nak!\n"));
747 * ipcp_rejci - Reject some of our CIs.
750 ipcp_rejci(fsm
*f
, u_char
*p
, int len
)
752 ipcp_options
*go
= &ipcp_gotoptions
[f
->unit
];
753 u_char cimaxslotindex
, ciflag
, cilen
;
756 ipcp_options
try; /* options to request next time */
760 * Any Rejected CIs must be in exactly the same order that we sent.
761 * Check packet length and CI length at each step.
762 * If we find any deviations, then this packet is bad.
764 #define REJCIADDR(opt, neg, old, val1, val2) \
766 len >= (cilen = old? CILEN_ADDRS: CILEN_ADDR) && \
774 /* Check rejected value. */ \
775 if (cilong != val1) { \
781 /* Check rejected value. */ \
782 if (cilong != val2) { \
789 #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
791 p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
796 GETSHORT(cishort, p); \
797 /* Check rejected value. */ \
798 if (cishort != val) { \
802 GETCHAR(cimaxslotindex, p); \
803 if (cimaxslotindex != maxslot) { \
806 GETCHAR(ciflag, p); \
807 if (ciflag != cflag) { \
814 #define REJCIDNS(opt, neg, dnsaddr) \
816 ((cilen = p[1]) == CILEN_ADDR) && \
824 /* Check rejected value. */ \
825 if (cilong != dnsaddr) { \
831 REJCIADDR((go
->old_addrs
? CI_ADDRS
: CI_ADDR
), neg_addr
,
832 go
->old_addrs
, go
->ouraddr
, go
->hisaddr
);
834 REJCIVJ(CI_COMPRESSTYPE
, neg_vj
, go
->vj_protocol
, go
->old_vj
,
835 go
->maxslotindex
, go
->cflag
);
837 REJCIDNS(CI_MS_DNS1
, req_dns1
, go
->dnsaddr
[0]);
839 REJCIDNS(CI_MS_DNS2
, req_dns2
, go
->dnsaddr
[1]);
842 * If there are any remaining CIs, then this packet is bad.
848 * Now we can update state.
850 if (f
->state
!= LS_OPENED
) {
856 IPCPDEBUG(LOG_INFO
, ("ipcp_rejci: received bad Reject!\n"));
862 * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
864 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
865 * appropriately. If reject_if_disagree is non-zero, doesn't return
866 * CONFNAK; returns CONFREJ if it can't return CONFACK.
869 ipcp_reqci(fsm
*f
, u_char
*inp
/* Requested CIs */,int *len
/* Length of requested CIs */,int reject_if_disagree
)
871 ipcp_options
*wo
= &ipcp_wantoptions
[f
->unit
];
872 ipcp_options
*ho
= &ipcp_hisoptions
[f
->unit
];
873 ipcp_options
*ao
= &ipcp_allowoptions
[f
->unit
];
875 ipcp_options
*go
= &ipcp_gotoptions
[f
->unit
];
877 u_char
*cip
, *next
; /* Pointer to current and next CIs */
878 u_short cilen
, citype
; /* Parsed len, type */
879 u_short cishort
; /* Parsed short value */
880 u32_t tl
, ciaddr1
; /* Parsed address values */
882 u32_t ciaddr2
; /* Parsed address values */
884 int rc
= CONFACK
; /* Final packet return code */
885 int orc
; /* Individual option return code */
886 u_char
*p
; /* Pointer to next char to parse */
887 u_char
*ucp
= inp
; /* Pointer to current output char */
888 int l
= *len
; /* Length left */
889 u_char maxslotindex
, cflag
;
892 cis_received
[f
->unit
] = 1;
895 * Reset all his options.
897 BZERO(ho
, sizeof(*ho
));
900 * Process all his options.
904 orc
= CONFACK
; /* Assume success */
905 cip
= p
= next
; /* Remember begining of CI */
906 if (l
< 2 || /* Not enough data for CI header or */
907 p
[1] < 2 || /* CI length too small or */
908 p
[1] > l
) { /* CI length too big? */
909 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: bad CI length!\n"));
910 orc
= CONFREJ
; /* Reject bad CI */
911 cilen
= (u_short
)l
;/* Reject till end of packet */
912 l
= 0; /* Don't loop again */
915 GETCHAR(citype
, p
); /* Parse CI type */
916 GETCHAR(cilen
, p
); /* Parse CI length */
917 l
-= cilen
; /* Adjust remaining length */
918 next
+= cilen
; /* Step to next CI */
920 switch (citype
) { /* Check CI type */
921 #ifdef OLD_CI_ADDRS /* Need to save space... */
923 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: received ADDRS\n"));
925 cilen
!= CILEN_ADDRS
) { /* Check CI length */
926 orc
= CONFREJ
; /* Reject CI */
931 * If he has no address, or if we both have his address but
932 * disagree about it, then NAK it with our idea.
933 * In particular, if we don't know his address, but he does,
936 GETLONG(tl
, p
); /* Parse source address (his) */
938 IPCPDEBUG(LOG_INFO
, ("his addr %s\n", inet_ntoa(ciaddr1
)));
939 if (ciaddr1
!= wo
->hisaddr
940 && (ciaddr1
== 0 || !wo
->accept_remote
)) {
942 if (!reject_if_disagree
) {
943 DECPTR(sizeof(u32_t
), p
);
944 tl
= ntohl(wo
->hisaddr
);
947 } else if (ciaddr1
== 0 && wo
->hisaddr
== 0) {
949 * If neither we nor he knows his address, reject the option.
952 wo
->req_addr
= 0; /* don't NAK with 0.0.0.0 later */
957 * If he doesn't know our address, or if we both have our address
958 * but disagree about it, then NAK it with our idea.
960 GETLONG(tl
, p
); /* Parse desination address (ours) */
962 IPCPDEBUG(LOG_INFO
, ("our addr %s\n", inet_ntoa(ciaddr2
)));
963 if (ciaddr2
!= wo
->ouraddr
) {
964 if (ciaddr2
== 0 || !wo
->accept_local
) {
966 if (!reject_if_disagree
) {
967 DECPTR(sizeof(u32_t
), p
);
968 tl
= ntohl(wo
->ouraddr
);
972 go
->ouraddr
= ciaddr2
; /* accept peer's idea */
978 ho
->hisaddr
= ciaddr1
;
979 ho
->ouraddr
= ciaddr2
;
985 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Reject ADDR not allowed\n"));
986 orc
= CONFREJ
; /* Reject CI */
988 } else if (cilen
!= CILEN_ADDR
) { /* Check CI length */
989 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Reject ADDR bad len\n"));
990 orc
= CONFREJ
; /* Reject CI */
995 * If he has no address, or if we both have his address but
996 * disagree about it, then NAK it with our idea.
997 * In particular, if we don't know his address, but he does,
1000 GETLONG(tl
, p
); /* Parse source address (his) */
1001 ciaddr1
= htonl(tl
);
1002 if (ciaddr1
!= wo
->hisaddr
1003 && (ciaddr1
== 0 || !wo
->accept_remote
)) {
1005 if (!reject_if_disagree
) {
1006 DECPTR(sizeof(u32_t
), p
);
1007 tl
= ntohl(wo
->hisaddr
);
1010 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Nak ADDR %s\n", inet_ntoa(ciaddr1
)));
1011 } else if (ciaddr1
== 0 && wo
->hisaddr
== 0) {
1013 * Don't ACK an address of 0.0.0.0 - reject it instead.
1015 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Reject ADDR %s\n", inet_ntoa(ciaddr1
)));
1017 wo
->req_addr
= 0; /* don't NAK with 0.0.0.0 later */
1022 ho
->hisaddr
= ciaddr1
;
1023 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: ADDR %s\n", inet_ntoa(ciaddr1
)));
1028 /* Microsoft primary or secondary DNS request */
1029 d
= citype
== CI_MS_DNS2
;
1031 /* If we do not have a DNS address then we cannot send it */
1032 if (ao
->dnsaddr
[d
] == 0 ||
1033 cilen
!= CILEN_ADDR
) { /* Check CI length */
1034 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Rejecting DNS%d Request\n", d
+1));
1035 orc
= CONFREJ
; /* Reject CI */
1039 if (htonl(tl
) != ao
->dnsaddr
[d
]) {
1040 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Naking DNS%d Request %s\n",
1041 d
+1, inet_ntoa(tl
)));
1042 DECPTR(sizeof(u32_t
), p
);
1043 tl
= ntohl(ao
->dnsaddr
[d
]);
1047 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: received DNS%d Request\n", d
+1));
1052 /* Microsoft primary or secondary WINS request */
1053 d
= citype
== CI_MS_WINS2
;
1054 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: received WINS%d Request\n", d
+1));
1056 /* If we do not have a DNS address then we cannot send it */
1057 if (ao
->winsaddr
[d
] == 0 ||
1058 cilen
!= CILEN_ADDR
) { /* Check CI length */
1059 orc
= CONFREJ
; /* Reject CI */
1063 if (htonl(tl
) != ao
->winsaddr
[d
]) {
1064 DECPTR(sizeof(u32_t
), p
);
1065 tl
= ntohl(ao
->winsaddr
[d
]);
1071 case CI_COMPRESSTYPE
:
1073 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Rejecting COMPRESSTYPE not allowed\n"));
1076 } else if (cilen
!= CILEN_VJ
&& cilen
!= CILEN_COMPRESS
) {
1077 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Rejecting COMPRESSTYPE len=%d\n", cilen
));
1081 GETSHORT(cishort
, p
);
1083 if (!(cishort
== IPCP_VJ_COMP
||
1084 (cishort
== IPCP_VJ_COMP_OLD
&& cilen
== CILEN_COMPRESS
))) {
1085 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Rejecting COMPRESSTYPE %d\n", cishort
));
1091 ho
->vj_protocol
= cishort
;
1092 if (cilen
== CILEN_VJ
) {
1093 GETCHAR(maxslotindex
, p
);
1094 if (maxslotindex
> ao
->maxslotindex
) {
1095 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Naking VJ max slot %d\n", maxslotindex
));
1097 if (!reject_if_disagree
) {
1099 PUTCHAR(ao
->maxslotindex
, p
);
1103 if (cflag
&& !ao
->cflag
) {
1104 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Naking VJ cflag %d\n", cflag
));
1106 if (!reject_if_disagree
) {
1108 PUTCHAR(wo
->cflag
, p
);
1111 ho
->maxslotindex
= maxslotindex
;
1115 ho
->maxslotindex
= MAX_SLOTS
- 1;
1118 IPCPDEBUG(LOG_INFO
, (
1119 "ipcp_reqci: received COMPRESSTYPE p=%d old=%d maxslot=%d cflag=%d\n",
1120 ho
->vj_protocol
, ho
->old_vj
, ho
->maxslotindex
, ho
->cflag
));
1124 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Rejecting unknown CI type %d\n", citype
));
1130 if (orc
== CONFACK
&& /* Good CI */
1131 rc
!= CONFACK
) { /* but prior CI wasnt? */
1132 continue; /* Don't send this one */
1135 if (orc
== CONFNAK
) { /* Nak this CI? */
1136 if (reject_if_disagree
) { /* Getting fed up with sending NAKs? */
1137 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Rejecting too many naks\n"));
1138 orc
= CONFREJ
; /* Get tough if so */
1140 if (rc
== CONFREJ
) { /* Rejecting prior CI? */
1141 continue; /* Don't send this one */
1143 if (rc
== CONFACK
) { /* Ack'd all prior CIs? */
1144 rc
= CONFNAK
; /* Not anymore... */
1145 ucp
= inp
; /* Backup */
1150 if (orc
== CONFREJ
&& /* Reject this CI */
1151 rc
!= CONFREJ
) { /* but no prior ones? */
1153 ucp
= inp
; /* Backup */
1156 /* Need to move CI? */
1158 BCOPY(cip
, ucp
, cilen
); /* Move it */
1161 /* Update output pointer */
1166 * If we aren't rejecting this packet, and we want to negotiate
1167 * their address, and they didn't send their address, then we
1168 * send a NAK with a CI_ADDR option appended. We assume the
1169 * input buffer is long enough that we can append the extra
1172 if (rc
!= CONFREJ
&& !ho
->neg_addr
&&
1173 wo
->req_addr
&& !reject_if_disagree
) {
1174 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: Requesting peer address\n"));
1175 if (rc
== CONFACK
) {
1177 ucp
= inp
; /* reset pointer */
1178 wo
->req_addr
= 0; /* don't ask again */
1180 PUTCHAR(CI_ADDR
, ucp
);
1181 PUTCHAR(CILEN_ADDR
, ucp
);
1182 tl
= ntohl(wo
->hisaddr
);
1186 *len
= (int)(ucp
- inp
); /* Compute output length */
1187 IPCPDEBUG(LOG_INFO
, ("ipcp_reqci: returning Configure-%s\n", CODENAME(rc
)));
1188 return (rc
); /* Return final code */
1194 * ip_check_options - check that any IP-related options are OK,
1195 * and assign appropriate defaults.
1198 ip_check_options(u_long localAddr
)
1200 ipcp_options
*wo
= &ipcp_wantoptions
[0];
1203 * Load our default IP address but allow the remote host to give us
1206 if (wo
->ouraddr
== 0 && !ppp_settings
.disable_defaultip
) {
1207 wo
->accept_local
= 1; /* don't insist on this default value */
1208 wo
->ouraddr
= htonl(localAddr
);
1215 * ipcp_up - IPCP has come UP.
1217 * Configure the IP network interface appropriately and bring it up.
1223 ipcp_options
*ho
= &ipcp_hisoptions
[f
->unit
];
1224 ipcp_options
*go
= &ipcp_gotoptions
[f
->unit
];
1225 ipcp_options
*wo
= &ipcp_wantoptions
[f
->unit
];
1227 np_up(f
->unit
, PPP_IP
);
1228 IPCPDEBUG(LOG_INFO
, ("ipcp: up\n"));
1231 * We must have a non-zero IP address for both ends of the link.
1233 if (!ho
->neg_addr
) {
1234 ho
->hisaddr
= wo
->hisaddr
;
1237 if (ho
->hisaddr
== 0) {
1238 IPCPDEBUG(LOG_ERR
, ("Could not determine remote IP address\n"));
1239 ipcp_close(f
->unit
, "Could not determine remote IP address");
1242 if (go
->ouraddr
== 0) {
1243 IPCPDEBUG(LOG_ERR
, ("Could not determine local IP address\n"));
1244 ipcp_close(f
->unit
, "Could not determine local IP address");
1248 if (ppp_settings
.usepeerdns
&& (go
->dnsaddr
[0] || go
->dnsaddr
[1])) {
1249 /*pppGotDNSAddrs(go->dnsaddr[0], go->dnsaddr[1]);*/
1253 * Check that the peer is allowed to use the IP address it wants.
1255 if (!auth_ip_addr(f
->unit
, ho
->hisaddr
)) {
1256 IPCPDEBUG(LOG_ERR
, ("Peer is not authorized to use remote address %s\n",
1257 inet_ntoa(ho
->hisaddr
)));
1258 ipcp_close(f
->unit
, "Unauthorized remote IP address");
1262 /* set tcp compression */
1263 sifvjcomp(f
->unit
, ho
->neg_vj
, ho
->cflag
, ho
->maxslotindex
);
1266 * Set IP addresses and (if specified) netmask.
1268 mask
= GetMask(go
->ouraddr
);
1270 if (!sifaddr(f
->unit
, go
->ouraddr
, ho
->hisaddr
, mask
, go
->dnsaddr
[0], go
->dnsaddr
[1])) {
1271 IPCPDEBUG(LOG_WARNING
, ("sifaddr failed\n"));
1272 ipcp_close(f
->unit
, "Interface configuration failed");
1276 /* bring the interface up for IP */
1277 if (!sifup(f
->unit
)) {
1278 IPCPDEBUG(LOG_WARNING
, ("sifup failed\n"));
1279 ipcp_close(f
->unit
, "Interface configuration failed");
1283 sifnpmode(f
->unit
, PPP_IP
, NPMODE_PASS
);
1285 /* assign a default route through the interface if required */
1286 if (ipcp_wantoptions
[f
->unit
].default_route
) {
1287 if (sifdefaultroute(f
->unit
, go
->ouraddr
, ho
->hisaddr
)) {
1288 default_route_set
[f
->unit
] = 1;
1292 IPCPDEBUG(LOG_NOTICE
, ("local IP address %s\n", inet_ntoa(go
->ouraddr
)));
1293 IPCPDEBUG(LOG_NOTICE
, ("remote IP address %s\n", inet_ntoa(ho
->hisaddr
)));
1294 if (go
->dnsaddr
[0]) {
1295 IPCPDEBUG(LOG_NOTICE
, ("primary DNS address %s\n", inet_ntoa(go
->dnsaddr
[0])));
1297 if (go
->dnsaddr
[1]) {
1298 IPCPDEBUG(LOG_NOTICE
, ("secondary DNS address %s\n", inet_ntoa(go
->dnsaddr
[1])));
1304 * ipcp_down - IPCP has gone DOWN.
1306 * Take the IP network interface down, clear its addresses
1307 * and delete routes through it.
1312 IPCPDEBUG(LOG_INFO
, ("ipcp: down\n"));
1313 np_down(f
->unit
, PPP_IP
);
1314 sifvjcomp(f
->unit
, 0, 0, 0);
1317 ipcp_clear_addrs(f
->unit
);
1322 * ipcp_clear_addrs() - clear the interface addresses, routes, etc.
1325 ipcp_clear_addrs(int unit
)
1327 u32_t ouraddr
, hisaddr
;
1329 ouraddr
= ipcp_gotoptions
[unit
].ouraddr
;
1330 hisaddr
= ipcp_hisoptions
[unit
].hisaddr
;
1331 if (default_route_set
[unit
]) {
1332 cifdefaultroute(unit
, ouraddr
, hisaddr
);
1333 default_route_set
[unit
] = 0;
1335 cifaddr(unit
, ouraddr
, hisaddr
);
1340 * ipcp_finished - possibly shut down the lower layers.
1343 ipcp_finished(fsm
*f
)
1345 np_finished(f
->unit
, PPP_IP
);
1348 #if PPP_ADDITIONAL_CALLBACKS
1350 ipcp_printpkt(u_char
*p
, int plen
, void (*printer
) (void *, char *, ...), void *arg
)
1353 LWIP_UNUSED_ARG(plen
);
1354 LWIP_UNUSED_ARG(printer
);
1355 LWIP_UNUSED_ARG(arg
);
1360 * ip_active_pkt - see if this IP packet is worth bringing the link up for.
1361 * We don't bring the link up for IP fragments or for TCP FIN packets
1364 #define IP_HDRLEN 20 /* bytes */
1365 #define IP_OFFMASK 0x1fff
1366 #define IPPROTO_TCP 6
1367 #define TCP_HDRLEN 20
1371 * We use these macros because the IP header may be at an odd address,
1372 * and some compilers might use word loads to get th_off or ip_hl.
1375 #define net_short(x) (((x)[0] << 8) + (x)[1])
1376 #define get_iphl(x) (((unsigned char *)(x))[0] & 0xF)
1377 #define get_ipoff(x) net_short((unsigned char *)(x) + 6)
1378 #define get_ipproto(x) (((unsigned char *)(x))[9])
1379 #define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
1380 #define get_tcpflags(x) (((unsigned char *)(x))[13])
1383 ip_active_pkt(u_char
*pkt
, int len
)
1390 if (len
< IP_HDRLEN
) {
1393 if ((get_ipoff(pkt
) & IP_OFFMASK
) != 0) {
1396 if (get_ipproto(pkt
) != IPPROTO_TCP
) {
1399 hlen
= get_iphl(pkt
) * 4;
1400 if (len
< hlen
+ TCP_HDRLEN
) {
1404 if ((get_tcpflags(tcp
) & TH_FIN
) != 0 && len
== hlen
+ get_tcpoff(tcp
) * 4) {
1409 #endif /* PPP_ADDITIONAL_CALLBACKS */
1411 #endif /* PPP_SUPPORT */