2 ipv6cp.c - PPP IPV6 Control Protocol.
3 Copyright (C) 1999 Tommi Komulainen <Tommi.Komulainen@iki.fi>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 /* Original version, based on RFC2023 :
22 Copyright (c) 1995, 1996, 1997 Francis.Dupont@inria.fr, INRIA Rocquencourt,
23 Alain.Durand@imag.fr, IMAG,
24 Jean-Luc.Richier@imag.fr, IMAG-LSR.
26 Copyright (c) 1998, 1999 Francis.Dupont@inria.fr, GIE DYADE,
27 Alain.Durand@imag.fr, IMAG,
28 Jean-Luc.Richier@imag.fr, IMAG-LSR.
30 Ce travail a été fait au sein du GIE DYADE (Groupement d'Intérêt
31 Économique ayant pour membres BULL S.A. et l'INRIA).
33 Ce logiciel informatique est disponible aux conditions
34 usuelles dans la recherche, c'est-à-dire qu'il peut
35 être utilisé, copié, modifié, distribué à l'unique
36 condition que ce texte soit conservé afin que
37 l'origine de ce logiciel soit reconnue.
39 Le nom de l'Institut National de Recherche en Informatique
40 et en Automatique (INRIA), de l'IMAG, ou d'une personne morale
41 ou physique ayant participé à l'élaboration de ce logiciel ne peut
42 être utilisé sans son accord préalable explicite.
44 Ce logiciel est fourni tel quel sans aucune garantie,
45 support ou responsabilité d'aucune sorte.
46 Ce logiciel est dérivé de sources d'origine
47 "University of California at Berkeley" et
48 "Digital Equipment Corporation" couvertes par des copyrights.
50 L'Institut d'Informatique et de Mathématiques Appliquées de Grenoble (IMAG)
51 est une fédération d'unités mixtes de recherche du CNRS, de l'Institut National
52 Polytechnique de Grenoble et de l'Université Joseph Fourier regroupant
53 sept laboratoires dont le laboratoire Logiciels, Systèmes, Réseaux (LSR).
55 This work has been done in the context of GIE DYADE (joint R & D venture
56 between BULL S.A. and INRIA).
58 This software is available with usual "research" terms
59 with the aim of retain credits of the software.
60 Permission to use, copy, modify and distribute this software for any
61 purpose and without fee is hereby granted, provided that the above
62 copyright notice and this permission notice appear in all copies,
63 and the name of INRIA, IMAG, or any contributor not be used in advertising
64 or publicity pertaining to this material without the prior explicit
65 permission. The software is provided "as is" without any
66 warranties, support or liabilities of any kind.
67 This software is derived from source code from
68 "University of California at Berkeley" and
69 "Digital Equipment Corporation" protected by copyrights.
71 Grenoble's Institute of Computer Science and Applied Mathematics (IMAG)
72 is a federation of seven research units funded by the CNRS, National
73 Polytechnic Institute of Grenoble and University Joseph Fourier.
74 The research unit in Software, Systems, Networks (LSR) is member of IMAG.
81 * ipcp.c - PPP IP Control Protocol.
83 * Copyright (c) 1989 Carnegie Mellon University.
84 * All rights reserved.
86 * Redistribution and use in source and binary forms are permitted
87 * provided that the above copyright notice and this paragraph are
88 * duplicated in all such forms and that any documentation,
89 * advertising materials, and other materials related to such
90 * distribution and use acknowledge that the software was developed
91 * by Carnegie Mellon University. The name of the
92 * University may not be used to endorse or promote products derived
93 * from this software without specific prior written permission.
94 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
95 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
96 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
98 * $Id: ipv6cp.c,v 1.4 1999/08/25 04:15:51 paulus Exp $
101 #define RCSID "$Id: ipv6cp.c,v 1.4 1999/08/25 04:15:51 paulus Exp $"
106 * Proxy Neighbour Discovery.
108 * Better defines for selecting the ordering of
109 * interface up / set address. (currently checks for __linux__,
110 * since SVR4 && (SNI || __USLC__) didn't work properly)
117 #include <sys/param.h>
118 #include <sys/types.h>
119 #include <sys/socket.h>
120 #include <netinet/in.h>
121 #include <arpa/inet.h>
128 #include "pathnames.h"
130 static const char rcsid[] = RCSID;
133 ipv6cp_options ipv6cp_wantoptions[NUM_PPP]; /* Options that we want to request */
134 ipv6cp_options ipv6cp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
135 ipv6cp_options ipv6cp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
136 ipv6cp_options ipv6cp_hisoptions[NUM_PPP]; /* Options that we ack'd */
137 int no_ifaceid_neg = 0;
140 static int ipv6cp_is_up;
143 * Callbacks for fsm code. (CI = Configuration Information)
145 static void ipv6cp_resetci __P((fsm *)); /* Reset our CI */
146 static int ipv6cp_cilen __P((fsm *)); /* Return length of our CI */
147 static void ipv6cp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
148 static int ipv6cp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
149 static int ipv6cp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
150 static int ipv6cp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
151 static int ipv6cp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
152 static void ipv6cp_up __P((fsm *)); /* We're UP */
153 static void ipv6cp_down __P((fsm *)); /* We're DOWN */
154 static void ipv6cp_finished __P((fsm *)); /* Don't need lower layer */
156 fsm ipv6cp_fsm[NUM_PPP]; /* IPV6CP fsm structure */
158 static fsm_callbacks ipv6cp_callbacks = { /* IPV6CP callback routines */
159 ipv6cp_resetci, /* Reset our Configuration Information */
160 ipv6cp_cilen, /* Length of our Configuration Information */
161 ipv6cp_addci, /* Add our Configuration Information */
162 ipv6cp_ackci, /* ACK our Configuration Information */
163 ipv6cp_nakci, /* NAK our Configuration Information */
164 ipv6cp_rejci, /* Reject our Configuration Information */
165 ipv6cp_reqci, /* Request peer's Configuration Information */
166 ipv6cp_up, /* Called when fsm reaches OPENED state */
167 ipv6cp_down, /* Called when fsm leaves OPENED state */
168 NULL, /* Called when we want the lower layer up */
169 ipv6cp_finished, /* Called when we want the lower layer down */
170 NULL, /* Called when Protocol-Reject received */
171 NULL, /* Retransmission is necessary */
172 NULL, /* Called to handle protocol-specific codes */
173 "IPV6CP" /* String name of protocol */
177 * Command-line options.
179 static int setifaceid __P((char **arg));
181 static option_t ipv6cp_option_list[] = {
182 { "ipv6", o_special, setifaceid,
183 "Set interface identifiers for IPV6" },
184 { "noipv6", o_bool, &ipv6cp_protent.enabled_flag,
185 "Disable IPv6 and IPv6CP" },
186 { "-ipv6", o_bool, &ipv6cp_protent.enabled_flag,
187 "Disable IPv6 and IPv6CP" },
188 { "+ipv6", o_bool, &ipv6cp_protent.enabled_flag,
189 "Enable IPv6 and IPv6CP", 1 },
191 { "ipv6cp-accept-local", o_bool, &ipv6cp_allowoptions[0].accept_local,
192 "Accept peer's interface identifier for us", 1 },
193 { "ipv6cp-use-ipaddr", o_bool, &ipv6cp_allowoptions[0].use_ip,
194 "Use (default) IPv4 address as interface identifier", 0 },
196 { "ipv6cp-restart", o_int, &ipv6cp_fsm[0].timeouttime,
197 "Set timeout for IPv6CP" },
198 { "ipv6cp-max-terminate", o_int, &ipv6cp_fsm[0].maxtermtransmits,
199 "Set max #xmits for term-reqs" },
200 { "ipv6cp-max-configure", o_int, &ipv6cp_fsm[0].maxconfreqtransmits,
201 "Set max #xmits for conf-reqs" },
202 { "ipv6cp-max-failure", o_int, &ipv6cp_fsm[0].maxnakloops,
203 "Set max #conf-naks for IPv6CP" },
210 * Protocol entry points from main code.
212 static void ipv6cp_init __P((int));
213 static void ipv6cp_open __P((int));
214 static void ipv6cp_close __P((int, char *));
215 static void ipv6cp_lowerup __P((int));
216 static void ipv6cp_lowerdown __P((int));
217 static void ipv6cp_input __P((int, u_char *, int));
218 static void ipv6cp_protrej __P((int));
219 static int ipv6cp_printpkt __P((u_char *, int,
220 void (*) __P((void *, char *, ...)), void *));
221 static void ipv6_check_options __P((void));
222 static int ipv6_demand_conf __P((int));
223 static int ipv6_active_pkt __P((u_char *, int));
225 struct protent ipv6cp_protent = {
245 static void ipv6cp_clear_addrs __P((int, eui64_t, eui64_t));
246 static void ipv6cp_script __P((char *));
247 static void ipv6cp_script_done __P((void *));
250 * Lengths of configuration options.
253 #define CILEN_COMPRESS 4 /* length for RFC2023 compress opt. */
254 #define CILEN_IFACEID 10 /* RFC2472, interface identifier */
256 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
257 (x) == CONFNAK ? "NAK" : "REJ")
260 * This state variable is used to ensure that we don't
261 * run an ipcp-up/down script while one is already running.
263 static enum script_state {
266 } ipv6cp_script_state;
267 static pid_t ipv6cp_script_pid;
270 * setifaceid - set the interface identifiers manually
277 ipv6cp_options *wo = &ipv6cp_wantoptions[0];
278 struct in6_addr addr;
280 #define VALIDID(a) ( (((a).s6_addr32[0] == 0) && ((a).s6_addr32[1] == 0)) && \
281 (((a).s6_addr32[2] != 0) || ((a).s6_addr32[3] != 0)) )
284 if ((comma = strchr(arg, ',')) == NULL)
285 comma = arg + strlen(arg);
288 * If comma first character, then no local identifier
293 if (inet_pton(AF_INET6, arg, &addr) == 0 || !VALIDID(addr)) {
294 option_error("Illegal interface identifier (local): %s", arg);
298 eui64_copy(addr.s6_addr32[2], wo->ourid);
304 * If comma last character, the no remote identifier
306 if (*comma != 0 && *++comma != '\0') {
307 if (inet_pton(AF_INET6, comma, &addr) == 0 || !VALIDID(addr)) {
308 option_error("Illegal interface identifier (remote): %s", comma);
311 eui64_copy(addr.s6_addr32[2], wo->hisid);
319 * Make a string representation of a network address.
327 sprintf(b, "fe80::%s", eui64_ntoa(ifaceid));
333 * ipv6cp_init - Initialize IPV6CP.
339 fsm *f = &ipv6cp_fsm[unit];
340 ipv6cp_options *wo = &ipv6cp_wantoptions[unit];
341 ipv6cp_options *ao = &ipv6cp_allowoptions[unit];
344 f->protocol = PPP_IPV6CP;
345 f->callbacks = &ipv6cp_callbacks;
346 fsm_init(&ipv6cp_fsm[unit]);
348 memset(wo, 0, sizeof(*wo));
349 memset(ao, 0, sizeof(*ao));
351 wo->accept_local = 1;
358 wo->vj_protocol = IPV6CP_COMP;
365 * ipv6cp_open - IPV6CP is allowed to come up.
371 fsm_open(&ipv6cp_fsm[unit]);
376 * ipv6cp_close - Take IPV6CP down.
379 ipv6cp_close(unit, reason)
383 fsm_close(&ipv6cp_fsm[unit], reason);
388 * ipv6cp_lowerup - The lower layer is up.
394 fsm_lowerup(&ipv6cp_fsm[unit]);
399 * ipv6cp_lowerdown - The lower layer is down.
402 ipv6cp_lowerdown(unit)
405 fsm_lowerdown(&ipv6cp_fsm[unit]);
410 * ipv6cp_input - Input IPV6CP packet.
413 ipv6cp_input(unit, p, len)
418 fsm_input(&ipv6cp_fsm[unit], p, len);
423 * ipv6cp_protrej - A Protocol-Reject was received for IPV6CP.
425 * Pretend the lower layer went down, so we shut up.
431 fsm_lowerdown(&ipv6cp_fsm[unit]);
436 * ipv6cp_resetci - Reset our CI.
442 ipv6cp_options *wo = &ipv6cp_wantoptions[f->unit];
443 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
445 wo->req_ifaceid = wo->neg_ifaceid && ipv6cp_allowoptions[f->unit].neg_ifaceid;
447 if (!wo->opt_local) {
448 eui64_magic_nz(wo->ourid);
452 eui64_zero(go->hisid); /* last proposed interface identifier */
457 * ipv6cp_cilen - Return length of our CI.
463 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
465 #define LENCIVJ(neg) (neg ? CILEN_COMPRESS : 0)
466 #define LENCIIFACEID(neg) (neg ? CILEN_IFACEID : 0)
468 return (LENCIIFACEID(go->neg_ifaceid) +
469 LENCIVJ(go->neg_vj));
474 * ipv6cp_addci - Add our desired CIs to a packet.
477 ipv6cp_addci(f, ucp, lenp)
482 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
485 #define ADDCIVJ(opt, neg, val) \
487 int vjlen = CILEN_COMPRESS; \
488 if (len >= vjlen) { \
490 PUTCHAR(vjlen, ucp); \
491 PUTSHORT(val, ucp); \
497 #define ADDCIIFACEID(opt, neg, val1) \
499 int idlen = CILEN_IFACEID; \
500 if (len >= idlen) { \
502 PUTCHAR(idlen, ucp); \
503 eui64_put(val1, ucp); \
509 ADDCIIFACEID(CI_IFACEID, go->neg_ifaceid, go->ourid);
511 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol);
518 * ipv6cp_ackci - Ack our CIs.
525 ipv6cp_ackci(f, p, len)
530 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
531 u_short cilen, citype, cishort;
535 * CIs must be in exactly the same order that we sent...
536 * Check packet length and CI length at each step.
537 * If we find any deviations, then this packet is bad.
540 #define ACKCIVJ(opt, neg, val) \
542 int vjlen = CILEN_COMPRESS; \
543 if ((len -= vjlen) < 0) \
545 GETCHAR(citype, p); \
547 if (cilen != vjlen || \
550 GETSHORT(cishort, p); \
551 if (cishort != val) \
555 #define ACKCIIFACEID(opt, neg, val1) \
557 int idlen = CILEN_IFACEID; \
558 if ((len -= idlen) < 0) \
560 GETCHAR(citype, p); \
562 if (cilen != idlen || \
565 eui64_get(ifaceid, p); \
566 if (! eui64_equals(val1, ifaceid)) \
570 ACKCIIFACEID(CI_IFACEID, go->neg_ifaceid, go->ourid);
572 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol);
575 * If there are any remaining CIs, then this packet is bad.
582 IPV6CPDEBUG(("ipv6cp_ackci: received bad Ack!"));
587 * ipv6cp_nakci - Peer has sent a NAK for some of our CIs.
588 * This should not modify any state if the Nak is bad
589 * or if IPV6CP is in the OPENED state.
596 ipv6cp_nakci(f, p, len)
601 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
602 u_char citype, cilen, *next;
605 ipv6cp_options no; /* options we've seen Naks for */
606 ipv6cp_options try; /* options to request next time */
608 BZERO(&no, sizeof(no));
612 * Any Nak'd CIs must be in exactly the same order that we sent.
613 * Check packet length and CI length at each step.
614 * If we find any deviations, then this packet is bad.
616 #define NAKCIIFACEID(opt, neg, code) \
618 len >= (cilen = CILEN_IFACEID) && \
623 eui64_get(ifaceid, p); \
628 #define NAKCIVJ(opt, neg, code) \
630 ((cilen = p[1]) == CILEN_COMPRESS) && \
635 GETSHORT(cishort, p); \
641 * Accept the peer's idea of {our,his} interface identifier, if different
642 * from our idea, only if the accept_{local,remote} flag is set.
644 NAKCIIFACEID(CI_IFACEID, neg_ifaceid,
645 if (go->accept_local) {
646 while (eui64_iszero(ifaceid) ||
647 eui64_equals(ifaceid, go->hisid)) /* bad luck */
648 eui64_magic(ifaceid);
650 IPV6CPDEBUG(("local LL address %s", llv6_ntoa(ifaceid)));
655 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
657 if (cishort == IPV6CP_COMP) {
658 try.vj_protocol = cishort;
665 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
673 * There may be remaining CIs, if the peer is requesting negotiation
674 * on an option that we didn't include in our request packet.
675 * If they want to negotiate about interface identifier, we comply.
676 * If they want us to ask for compression, we refuse.
678 while (len > CILEN_VOID) {
681 if( (len -= cilen) < 0 )
683 next = p + cilen - 2;
686 case CI_COMPRESSTYPE:
687 if (go->neg_vj || no.neg_vj ||
688 (cilen != CILEN_COMPRESS))
693 if (go->neg_ifaceid || no.neg_ifaceid || cilen != CILEN_IFACEID)
696 eui64_get(ifaceid, p);
697 if (go->accept_local) {
698 while (eui64_iszero(ifaceid) ||
699 eui64_equals(ifaceid, go->hisid)) /* bad luck */
700 eui64_magic(ifaceid);
709 /* If there is still anything left, this packet is bad. */
714 * OK, the Nak is good. Now we can update state.
716 if (f->state != OPENED)
722 IPV6CPDEBUG(("ipv6cp_nakci: received bad Nak!"));
728 * ipv6cp_rejci - Reject some of our CIs.
731 ipv6cp_rejci(f, p, len)
736 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
740 ipv6cp_options try; /* options to request next time */
744 * Any Rejected CIs must be in exactly the same order that we sent.
745 * Check packet length and CI length at each step.
746 * If we find any deviations, then this packet is bad.
748 #define REJCIIFACEID(opt, neg, val1) \
750 len >= (cilen = CILEN_IFACEID) && \
755 eui64_get(ifaceid, p); \
756 /* Check rejected value. */ \
757 if (! eui64_equals(ifaceid, val1)) \
762 #define REJCIVJ(opt, neg, val) \
764 p[1] == CILEN_COMPRESS && \
769 GETSHORT(cishort, p); \
770 /* Check rejected value. */ \
771 if (cishort != val) \
776 REJCIIFACEID(CI_IFACEID, neg_ifaceid, go->ourid);
778 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol);
781 * If there are any remaining CIs, then this packet is bad.
786 * Now we can update state.
788 if (f->state != OPENED)
793 IPV6CPDEBUG(("ipv6cp_rejci: received bad Reject!"));
799 * ipv6cp_reqci - Check the peer's requested CIs and send appropriate response.
801 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
802 * appropriately. If reject_if_disagree is non-zero, doesn't return
803 * CONFNAK; returns CONFREJ if it can't return CONFACK.
806 ipv6cp_reqci(f, inp, len, reject_if_disagree)
808 u_char *inp; /* Requested CIs */
809 int *len; /* Length of requested CIs */
810 int reject_if_disagree;
812 ipv6cp_options *wo = &ipv6cp_wantoptions[f->unit];
813 ipv6cp_options *ho = &ipv6cp_hisoptions[f->unit];
814 ipv6cp_options *ao = &ipv6cp_allowoptions[f->unit];
815 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
816 u_char *cip, *next; /* Pointer to current and next CIs */
817 u_short cilen, citype; /* Parsed len, type */
818 u_short cishort; /* Parsed short value */
819 eui64_t ifaceid; /* Parsed interface identifier */
820 int rc = CONFACK; /* Final packet return code */
821 int orc; /* Individual option return code */
822 u_char *p; /* Pointer to next char to parse */
823 u_char *ucp = inp; /* Pointer to current output char */
824 int l = *len; /* Length left */
827 * Reset all his options.
829 BZERO(ho, sizeof(*ho));
832 * Process all his options.
836 orc = CONFACK; /* Assume success */
837 cip = p = next; /* Remember begining of CI */
838 if (l < 2 || /* Not enough data for CI header or */
839 p[1] < 2 || /* CI length too small or */
840 p[1] > l) { /* CI length too big? */
841 IPV6CPDEBUG(("ipv6cp_reqci: bad CI length!"));
842 orc = CONFREJ; /* Reject bad CI */
843 cilen = l; /* Reject till end of packet */
844 l = 0; /* Don't loop again */
847 GETCHAR(citype, p); /* Parse CI type */
848 GETCHAR(cilen, p); /* Parse CI length */
849 l -= cilen; /* Adjust remaining length */
850 next += cilen; /* Step to next CI */
852 switch (citype) { /* Check CI type */
854 IPV6CPDEBUG(("ipv6cp: received interface identifier "));
856 if (!ao->neg_ifaceid ||
857 cilen != CILEN_IFACEID) { /* Check CI length */
858 orc = CONFREJ; /* Reject CI */
863 * If he has no interface identifier, or if we both have same
864 * identifier then NAK it with new idea.
865 * In particular, if we don't know his identifier, but he does,
868 eui64_get(ifaceid, p);
869 IPV6CPDEBUG(("(%s)", llv6_ntoa(ifaceid)));
870 if (eui64_iszero(ifaceid) && eui64_iszero(go->ourid)) {
871 orc = CONFREJ; /* Reject CI */
874 if (!eui64_iszero(wo->hisid) &&
875 !eui64_equals(ifaceid, wo->hisid) &&
876 eui64_iszero(go->hisid)) {
881 DECPTR(sizeof(ifaceid), p);
882 eui64_put(ifaceid, p);
884 if (eui64_iszero(ifaceid) || eui64_equals(ifaceid, go->ourid)) {
886 if (eui64_iszero(go->hisid)) /* first time, try option */
888 while (eui64_iszero(ifaceid) ||
889 eui64_equals(ifaceid, go->ourid)) /* bad luck */
890 eui64_magic(ifaceid);
892 DECPTR(sizeof(ifaceid), p);
893 eui64_put(ifaceid, p);
900 case CI_COMPRESSTYPE:
901 IPV6CPDEBUG(("ipv6cp: received COMPRESSTYPE "));
903 (cilen != CILEN_COMPRESS)) {
907 GETSHORT(cishort, p);
908 IPV6CPDEBUG(("(%d)", cishort));
911 if (!(cishort == IPV6CP_COMP)) {
921 ho->vj_protocol = cishort;
930 IPV6CPDEBUG((" (%s)\n", CODENAME(orc)));
932 if (orc == CONFACK && /* Good CI */
933 rc != CONFACK) /* but prior CI wasnt? */
934 continue; /* Don't send this one */
936 if (orc == CONFNAK) { /* Nak this CI? */
937 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
938 orc = CONFREJ; /* Get tough if so */
940 if (rc == CONFREJ) /* Rejecting prior CI? */
941 continue; /* Don't send this one */
942 if (rc == CONFACK) { /* Ack'd all prior CIs? */
943 rc = CONFNAK; /* Not anymore... */
944 ucp = inp; /* Backup */
949 if (orc == CONFREJ && /* Reject this CI */
950 rc != CONFREJ) { /* but no prior ones? */
952 ucp = inp; /* Backup */
955 /* Need to move CI? */
957 BCOPY(cip, ucp, cilen); /* Move it */
959 /* Update output pointer */
964 * If we aren't rejecting this packet, and we want to negotiate
965 * their identifier and they didn't send their identifier, then we
966 * send a NAK with a CI_IFACEID option appended. We assume the
967 * input buffer is long enough that we can append the extra
970 if (rc != CONFREJ && !ho->neg_ifaceid &&
971 wo->req_ifaceid && !reject_if_disagree) {
974 ucp = inp; /* reset pointer */
975 wo->req_ifaceid = 0; /* don't ask again */
977 PUTCHAR(CI_IFACEID, ucp);
978 PUTCHAR(CILEN_IFACEID, ucp);
979 eui64_put(wo->hisid, ucp);
982 *len = ucp - inp; /* Compute output length */
983 IPV6CPDEBUG(("ipv6cp: returning Configure-%s", CODENAME(rc)));
984 return (rc); /* Return final code */
989 * ipv6_check_options - check that any IP-related options are OK,
990 * and assign appropriate defaults.
995 ipv6cp_options *wo = &ipv6cp_wantoptions[0];
997 if (!wo->opt_local) { /* init interface identifier */
998 if (wo->use_ip && eui64_iszero(wo->ourid)) {
999 eui64_setlo32(wo->ourid, ntohl(ipcp_wantoptions[0].ouraddr));
1000 if (!eui64_iszero(wo->ourid))
1004 while (eui64_iszero(wo->ourid))
1005 eui64_magic(wo->ourid);
1008 if (!wo->opt_remote) {
1009 if (wo->use_ip && eui64_iszero(wo->hisid)) {
1010 eui64_setlo32(wo->hisid, ntohl(ipcp_wantoptions[0].hisaddr));
1011 if (!eui64_iszero(wo->hisid))
1016 if (demand && (eui64_iszero(wo->ourid) || eui64_iszero(wo->hisid))) {
1017 option_error("local/remote LL address required for demand-dialling\n");
1024 * ipv6_demand_conf - configure the interface as though
1025 * IPV6CP were up, for use with dial-on-demand.
1031 ipv6cp_options *wo = &ipv6cp_wantoptions[u];
1033 #if defined(__linux__) || (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1037 if (!sif6addr(u, wo->ourid, wo->hisid))
1039 #if !defined(__linux__) && !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1043 if (!sifnpmode(u, PPP_IPV6, NPMODE_QUEUE))
1046 notice("ipv6_demand_conf");
1047 notice("local LL address %s", llv6_ntoa(wo->ourid));
1048 notice("remote LL address %s", llv6_ntoa(wo->hisid));
1055 * ipv6cp_up - IPV6CP has come UP.
1057 * Configure the IPv6 network interface appropriately and bring it up.
1063 ipv6cp_options *ho = &ipv6cp_hisoptions[f->unit];
1064 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
1065 ipv6cp_options *wo = &ipv6cp_wantoptions[f->unit];
1067 IPV6CPDEBUG(("ipv6cp: up"));
1070 * We must have a non-zero LL address for both ends of the link.
1072 if (!ho->neg_ifaceid)
1073 ho->hisid = wo->hisid;
1075 if(!no_ifaceid_neg) {
1076 if (eui64_iszero(ho->hisid)) {
1077 error("Could not determine remote LL address");
1078 ipv6cp_close(f->unit, "Could not determine remote LL address");
1081 if (eui64_iszero(go->ourid)) {
1082 error("Could not determine local LL address");
1083 ipv6cp_close(f->unit, "Could not determine local LL address");
1086 if (eui64_equals(go->ourid, ho->hisid)) {
1087 error("local and remote LL addresses are equal");
1088 ipv6cp_close(f->unit, "local and remote LL addresses are equal");
1092 script_setenv("LLLOCAL", llv6_ntoa(go->ourid));
1093 script_setenv("LLREMOTE", llv6_ntoa(ho->hisid));
1096 /* set tcp compression */
1097 sif6comp(f->unit, ho->neg_vj);
1101 * If we are doing dial-on-demand, the interface is already
1102 * configured, so we put out any saved-up packets, then set the
1103 * interface to pass IPv6 packets.
1106 if (! eui64_equals(go->ourid, wo->ourid) ||
1107 ! eui64_equals(ho->hisid, wo->hisid)) {
1108 if (! eui64_equals(go->ourid, wo->ourid))
1109 warn("Local LL address changed to %s",
1110 llv6_ntoa(go->ourid));
1111 if (! eui64_equals(ho->hisid, wo->hisid))
1112 warn("Remote LL address changed to %s",
1113 llv6_ntoa(ho->hisid));
1114 ipv6cp_clear_addrs(f->unit, go->ourid, ho->hisid);
1116 /* Set the interface to the new addresses */
1117 if (!sif6addr(f->unit, go->ourid, ho->hisid)) {
1119 warn("sif6addr failed");
1120 ipv6cp_close(f->unit, "Interface configuration failed");
1125 demand_rexmit(PPP_IPV6);
1126 sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
1132 #if !defined(__linux__) && !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1133 if (!sif6addr(f->unit, go->ourid, ho->hisid)) {
1135 warn("sif6addr failed");
1136 ipv6cp_close(f->unit, "Interface configuration failed");
1141 /* bring the interface up for IPv6 */
1142 if (!sifup(f->unit)) {
1144 warn("sifup failed (IPV6)");
1145 ipv6cp_close(f->unit, "Interface configuration failed");
1149 #if defined(__linux__) || (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1150 if (!sif6addr(f->unit, go->ourid, ho->hisid)) {
1152 warn("sif6addr failed");
1153 ipv6cp_close(f->unit, "Interface configuration failed");
1157 sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
1159 notice("local LL address %s", llv6_ntoa(go->ourid));
1160 notice("remote LL address %s", llv6_ntoa(ho->hisid));
1163 np_up(f->unit, PPP_IPV6);
1167 * Execute the ipv6-up script, like this:
1168 * /etc/ppp/ipv6-up interface tty speed local-LL remote-LL
1170 if (ipv6cp_script_state == s_down && ipv6cp_script_pid == 0) {
1171 ipv6cp_script_state = s_up;
1172 ipv6cp_script(_PATH_IPV6UP);
1178 * ipv6cp_down - IPV6CP has gone DOWN.
1180 * Take the IPv6 network interface down, clear its addresses
1181 * and delete routes through it.
1187 IPV6CPDEBUG(("ipv6cp: down"));
1188 update_link_stats(f->unit);
1191 np_down(f->unit, PPP_IPV6);
1194 sif6comp(f->unit, 0);
1198 * If we are doing dial-on-demand, set the interface
1199 * to queue up outgoing packets (for now).
1202 sifnpmode(f->unit, PPP_IPV6, NPMODE_QUEUE);
1204 sifnpmode(f->unit, PPP_IPV6, NPMODE_DROP);
1205 #if !defined(__linux__) && !(defined(SVR4) && (defined(SNI) || defined(__USLC)))
1208 ipv6cp_clear_addrs(f->unit,
1209 ipv6cp_gotoptions[f->unit].ourid,
1210 ipv6cp_hisoptions[f->unit].hisid);
1211 #if defined(__linux__) || (defined(SVR4) && (defined(SNI) || defined(__USLC)))
1216 /* Execute the ipv6-down script */
1217 if (ipv6cp_script_state == s_up && ipv6cp_script_pid == 0) {
1218 ipv6cp_script_state = s_down;
1219 ipv6cp_script(_PATH_IPV6DOWN);
1225 * ipv6cp_clear_addrs() - clear the interface addresses, routes,
1226 * proxy neighbour discovery entries, etc.
1229 ipv6cp_clear_addrs(unit, ourid, hisid)
1234 cif6addr(unit, ourid, hisid);
1239 * ipv6cp_finished - possibly shut down the lower layers.
1245 np_finished(f->unit, PPP_IPV6);
1250 * ipv6cp_script_done - called when the ipv6-up or ipv6-down script
1254 ipv6cp_script_done(arg)
1257 ipv6cp_script_pid = 0;
1258 switch (ipv6cp_script_state) {
1260 if (ipv6cp_fsm[0].state != OPENED) {
1261 ipv6cp_script_state = s_down;
1262 ipv6cp_script(_PATH_IPV6DOWN);
1266 if (ipv6cp_fsm[0].state == OPENED) {
1267 ipv6cp_script_state = s_up;
1268 ipv6cp_script(_PATH_IPV6UP);
1276 * ipv6cp_script - Execute a script with arguments
1277 * interface-name tty-name speed local-LL remote-LL.
1280 ipv6cp_script(script)
1283 char strspeed[32], strlocal[32], strremote[32];
1286 sprintf(strspeed, "%d", baud_rate);
1287 strcpy(strlocal, llv6_ntoa(ipv6cp_gotoptions[0].ourid));
1288 strcpy(strremote, llv6_ntoa(ipv6cp_hisoptions[0].hisid));
1295 argv[5] = strremote;
1299 ipv6cp_script_pid = run_program(script, argv, 0, ipv6cp_script_done, NULL);
1303 * ipv6cp_printpkt - print the contents of an IPV6CP packet.
1305 static char *ipv6cp_codenames[] = {
1306 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1307 "TermReq", "TermAck", "CodeRej"
1311 ipv6cp_printpkt(p, plen, printer, arg)
1314 void (*printer) __P((void *, char *, ...));
1317 int code, id, len, olen;
1318 u_char *pstart, *optend;
1322 if (plen < HEADERLEN)
1328 if (len < HEADERLEN || len > plen)
1331 if (code >= 1 && code <= sizeof(ipv6cp_codenames) / sizeof(char *))
1332 printer(arg, " %s", ipv6cp_codenames[code-1]);
1334 printer(arg, " code=0x%x", code);
1335 printer(arg, " id=0x%x", id);
1342 /* print option list */
1347 if (olen < 2 || olen > len) {
1354 case CI_COMPRESSTYPE:
1355 if (olen >= CILEN_COMPRESS) {
1357 GETSHORT(cishort, p);
1358 printer(arg, "compress ");
1359 printer(arg, "0x%x", cishort);
1363 if (olen == CILEN_IFACEID) {
1365 eui64_get(ifaceid, p);
1366 printer(arg, "addr %s", llv6_ntoa(ifaceid));
1370 while (p < optend) {
1372 printer(arg, " %.2x", code);
1380 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1382 print_string(p, len, printer, arg);
1389 /* print the rest of the bytes in the packet */
1390 for (; len > 0; --len) {
1392 printer(arg, " %.2x", code);
1399 * ipv6_active_pkt - see if this IP packet is worth bringing the link up for.
1400 * We don't bring the link up for IP fragments or for TCP FIN packets
1403 #define IP6_HDRLEN 40 /* bytes */
1404 #define IP6_NHDR_FRAG 44 /* fragment IPv6 header */
1405 #define IPPROTO_TCP 6
1406 #define TCP_HDRLEN 20
1410 * We use these macros because the IP header may be at an odd address,
1411 * and some compilers might use word loads to get th_off or ip_hl.
1414 #define get_ip6nh(x) (((unsigned char *)(x))[6])
1415 #define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
1416 #define get_tcpflags(x) (((unsigned char *)(x))[13])
1419 ipv6_active_pkt(pkt, len)
1427 if (len < IP6_HDRLEN)
1429 if (get_ip6nh(pkt) == IP6_NHDR_FRAG)
1431 if (get_ip6nh(pkt) != IPPROTO_TCP)
1433 if (len < IP6_HDRLEN + TCP_HDRLEN)
1435 tcp = pkt + IP6_HDRLEN;
1436 if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == IP6_HDRLEN + get_tcpoff(tcp) * 4)