2 ipv6cp.c - PPP IPV6 Control Protocol.
3 Copyright (C) 1999 Tommi Komulainen <Tommi.Komulainen@iki.fi>
5 Redistribution and use in source and binary forms are permitted
6 provided that the above copyright notice and this paragraph are
7 duplicated in all such forms. The name of the author may not be
8 used to endorse or promote products derived from this software
9 without specific prior written permission.
10 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
11 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 /* Original version, based on RFC2023 :
17 Copyright (c) 1995, 1996, 1997 Francis.Dupont@inria.fr, INRIA Rocquencourt,
18 Alain.Durand@imag.fr, IMAG,
19 Jean-Luc.Richier@imag.fr, IMAG-LSR.
21 Copyright (c) 1998, 1999 Francis.Dupont@inria.fr, GIE DYADE,
22 Alain.Durand@imag.fr, IMAG,
23 Jean-Luc.Richier@imag.fr, IMAG-LSR.
25 Ce travail a été fait au sein du GIE DYADE (Groupement d'Intérêt
26 Économique ayant pour membres BULL S.A. et l'INRIA).
28 Ce logiciel informatique est disponible aux conditions
29 usuelles dans la recherche, c'est-à-dire qu'il peut
30 être utilisé, copié, modifié, distribué à l'unique
31 condition que ce texte soit conservé afin que
32 l'origine de ce logiciel soit reconnue.
34 Le nom de l'Institut National de Recherche en Informatique
35 et en Automatique (INRIA), de l'IMAG, ou d'une personne morale
36 ou physique ayant participé à l'élaboration de ce logiciel ne peut
37 être utilisé sans son accord préalable explicite.
39 Ce logiciel est fourni tel quel sans aucune garantie,
40 support ou responsabilité d'aucune sorte.
41 Ce logiciel est dérivé de sources d'origine
42 "University of California at Berkeley" et
43 "Digital Equipment Corporation" couvertes par des copyrights.
45 L'Institut d'Informatique et de Mathématiques Appliquées de Grenoble (IMAG)
46 est une fédération d'unités mixtes de recherche du CNRS, de l'Institut National
47 Polytechnique de Grenoble et de l'Université Joseph Fourier regroupant
48 sept laboratoires dont le laboratoire Logiciels, Systèmes, Réseaux (LSR).
50 This work has been done in the context of GIE DYADE (joint R & D venture
51 between BULL S.A. and INRIA).
53 This software is available with usual "research" terms
54 with the aim of retain credits of the software.
55 Permission to use, copy, modify and distribute this software for any
56 purpose and without fee is hereby granted, provided that the above
57 copyright notice and this permission notice appear in all copies,
58 and the name of INRIA, IMAG, or any contributor not be used in advertising
59 or publicity pertaining to this material without the prior explicit
60 permission. The software is provided "as is" without any
61 warranties, support or liabilities of any kind.
62 This software is derived from source code from
63 "University of California at Berkeley" and
64 "Digital Equipment Corporation" protected by copyrights.
66 Grenoble's Institute of Computer Science and Applied Mathematics (IMAG)
67 is a federation of seven research units funded by the CNRS, National
68 Polytechnic Institute of Grenoble and University Joseph Fourier.
69 The research unit in Software, Systems, Networks (LSR) is member of IMAG.
76 * ipcp.c - PPP IP Control Protocol.
78 * Copyright (c) 1989 Carnegie Mellon University.
79 * All rights reserved.
81 * Redistribution and use in source and binary forms are permitted
82 * provided that the above copyright notice and this paragraph are
83 * duplicated in all such forms and that any documentation,
84 * advertising materials, and other materials related to such
85 * distribution and use acknowledge that the software was developed
86 * by Carnegie Mellon University. The name of the
87 * University may not be used to endorse or promote products derived
88 * from this software without specific prior written permission.
89 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
90 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
91 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
93 * $Id: ipv6cp.c,v 1.11 2000/08/05 06:46:47 paulus Exp $
96 #define RCSID "$Id: ipv6cp.c,v 1.11 2000/08/05 06:46:47 paulus Exp $"
101 * Proxy Neighbour Discovery.
103 * Better defines for selecting the ordering of
104 * interface up / set address. (currently checks for __linux__,
105 * since SVR4 && (SNI || __USLC__) didn't work properly)
112 #include <sys/param.h>
113 #include <sys/types.h>
114 #include <sys/socket.h>
115 #include <netinet/in.h>
116 #include <arpa/inet.h>
123 #include "pathnames.h"
125 static const char rcsid[] = RCSID;
128 ipv6cp_options ipv6cp_wantoptions[NUM_PPP]; /* Options that we want to request */
129 ipv6cp_options ipv6cp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
130 ipv6cp_options ipv6cp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
131 ipv6cp_options ipv6cp_hisoptions[NUM_PPP]; /* Options that we ack'd */
132 int no_ifaceid_neg = 0;
135 static int ipv6cp_is_up;
138 * Callbacks for fsm code. (CI = Configuration Information)
140 static void ipv6cp_resetci __P((fsm *)); /* Reset our CI */
141 static int ipv6cp_cilen __P((fsm *)); /* Return length of our CI */
142 static void ipv6cp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
143 static int ipv6cp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
144 static int ipv6cp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
145 static int ipv6cp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
146 static int ipv6cp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
147 static void ipv6cp_up __P((fsm *)); /* We're UP */
148 static void ipv6cp_down __P((fsm *)); /* We're DOWN */
149 static void ipv6cp_finished __P((fsm *)); /* Don't need lower layer */
151 fsm ipv6cp_fsm[NUM_PPP]; /* IPV6CP fsm structure */
153 static fsm_callbacks ipv6cp_callbacks = { /* IPV6CP callback routines */
154 ipv6cp_resetci, /* Reset our Configuration Information */
155 ipv6cp_cilen, /* Length of our Configuration Information */
156 ipv6cp_addci, /* Add our Configuration Information */
157 ipv6cp_ackci, /* ACK our Configuration Information */
158 ipv6cp_nakci, /* NAK our Configuration Information */
159 ipv6cp_rejci, /* Reject our Configuration Information */
160 ipv6cp_reqci, /* Request peer's Configuration Information */
161 ipv6cp_up, /* Called when fsm reaches OPENED state */
162 ipv6cp_down, /* Called when fsm leaves OPENED state */
163 NULL, /* Called when we want the lower layer up */
164 ipv6cp_finished, /* Called when we want the lower layer down */
165 NULL, /* Called when Protocol-Reject received */
166 NULL, /* Retransmission is necessary */
167 NULL, /* Called to handle protocol-specific codes */
168 "IPV6CP" /* String name of protocol */
172 * Command-line options.
174 static int setifaceid __P((char **arg));
176 static option_t ipv6cp_option_list[] = {
177 { "ipv6", o_special, (void *)setifaceid,
178 "Set interface identifiers for IPV6" },
179 { "noipv6", o_bool, &ipv6cp_protent.enabled_flag,
180 "Disable IPv6 and IPv6CP" },
181 { "-ipv6", o_bool, &ipv6cp_protent.enabled_flag,
182 "Disable IPv6 and IPv6CP" },
183 { "+ipv6", o_bool, &ipv6cp_protent.enabled_flag,
184 "Enable IPv6 and IPv6CP", 1 },
186 { "ipv6cp-accept-local", o_bool, &ipv6cp_allowoptions[0].accept_local,
187 "Accept peer's interface identifier for us", 1 },
188 { "ipv6cp-use-ipaddr", o_bool, &ipv6cp_allowoptions[0].use_ip,
189 "Use (default) IPv4 address as interface identifier", 0 },
191 { "ipv6cp-use-persistent", o_bool, &ipv6cp_wantoptions[0].use_persistent,
192 "Use uniquely-available persistent value for link local address", 1 },
193 #endif /* defined(SOL2) */
194 { "ipv6cp-restart", o_int, &ipv6cp_fsm[0].timeouttime,
195 "Set timeout for IPv6CP" },
196 { "ipv6cp-max-terminate", o_int, &ipv6cp_fsm[0].maxtermtransmits,
197 "Set max #xmits for term-reqs" },
198 { "ipv6cp-max-configure", o_int, &ipv6cp_fsm[0].maxconfreqtransmits,
199 "Set max #xmits for conf-reqs" },
200 { "ipv6cp-max-failure", o_int, &ipv6cp_fsm[0].maxnakloops,
201 "Set max #conf-naks for IPv6CP" },
208 * Protocol entry points from main code.
210 static void ipv6cp_init __P((int));
211 static void ipv6cp_open __P((int));
212 static void ipv6cp_close __P((int, char *));
213 static void ipv6cp_lowerup __P((int));
214 static void ipv6cp_lowerdown __P((int));
215 static void ipv6cp_input __P((int, u_char *, int));
216 static void ipv6cp_protrej __P((int));
217 static int ipv6cp_printpkt __P((u_char *, int,
218 void (*) __P((void *, char *, ...)), void *));
219 static void ipv6_check_options __P((void));
220 static int ipv6_demand_conf __P((int));
221 static int ipv6_active_pkt __P((u_char *, int));
223 struct protent ipv6cp_protent = {
243 static void ipv6cp_clear_addrs __P((int, eui64_t, eui64_t));
244 static void ipv6cp_script __P((char *));
245 static void ipv6cp_script_done __P((void *));
248 * Lengths of configuration options.
251 #define CILEN_COMPRESS 4 /* length for RFC2023 compress opt. */
252 #define CILEN_IFACEID 10 /* RFC2472, interface identifier */
254 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
255 (x) == CONFNAK ? "NAK" : "REJ")
258 * This state variable is used to ensure that we don't
259 * run an ipcp-up/down script while one is already running.
261 static enum script_state {
264 } ipv6cp_script_state;
265 static pid_t ipv6cp_script_pid;
268 * setifaceid - set the interface identifiers manually
275 ipv6cp_options *wo = &ipv6cp_wantoptions[0];
276 struct in6_addr addr;
278 #define VALIDID(a) ( (((a).s6_addr32[0] == 0) && ((a).s6_addr32[1] == 0)) && \
279 (((a).s6_addr32[2] != 0) || ((a).s6_addr32[3] != 0)) )
282 if ((comma = strchr(arg, ',')) == NULL)
283 comma = arg + strlen(arg);
286 * If comma first character, then no local identifier
291 if (inet_pton(AF_INET6, arg, &addr) == 0 || !VALIDID(addr)) {
292 option_error("Illegal interface identifier (local): %s", arg);
296 eui64_copy(addr.s6_addr32[2], wo->ourid);
302 * If comma last character, the no remote identifier
304 if (*comma != 0 && *++comma != '\0') {
305 if (inet_pton(AF_INET6, comma, &addr) == 0 || !VALIDID(addr)) {
306 option_error("Illegal interface identifier (remote): %s", comma);
309 eui64_copy(addr.s6_addr32[2], wo->hisid);
313 ipv6cp_protent.enabled_flag = 1;
318 * Make a string representation of a network address.
326 sprintf(b, "fe80::%s", eui64_ntoa(ifaceid));
332 * ipv6cp_init - Initialize IPV6CP.
338 fsm *f = &ipv6cp_fsm[unit];
339 ipv6cp_options *wo = &ipv6cp_wantoptions[unit];
340 ipv6cp_options *ao = &ipv6cp_allowoptions[unit];
343 f->protocol = PPP_IPV6CP;
344 f->callbacks = &ipv6cp_callbacks;
345 fsm_init(&ipv6cp_fsm[unit]);
347 memset(wo, 0, sizeof(*wo));
348 memset(ao, 0, sizeof(*ao));
350 wo->accept_local = 1;
357 wo->vj_protocol = IPV6CP_COMP;
364 * ipv6cp_open - IPV6CP is allowed to come up.
370 fsm_open(&ipv6cp_fsm[unit]);
375 * ipv6cp_close - Take IPV6CP down.
378 ipv6cp_close(unit, reason)
382 fsm_close(&ipv6cp_fsm[unit], reason);
387 * ipv6cp_lowerup - The lower layer is up.
393 fsm_lowerup(&ipv6cp_fsm[unit]);
398 * ipv6cp_lowerdown - The lower layer is down.
401 ipv6cp_lowerdown(unit)
404 fsm_lowerdown(&ipv6cp_fsm[unit]);
409 * ipv6cp_input - Input IPV6CP packet.
412 ipv6cp_input(unit, p, len)
417 fsm_input(&ipv6cp_fsm[unit], p, len);
422 * ipv6cp_protrej - A Protocol-Reject was received for IPV6CP.
424 * Pretend the lower layer went down, so we shut up.
430 fsm_lowerdown(&ipv6cp_fsm[unit]);
435 * ipv6cp_resetci - Reset our CI.
441 ipv6cp_options *wo = &ipv6cp_wantoptions[f->unit];
442 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
444 wo->req_ifaceid = wo->neg_ifaceid && ipv6cp_allowoptions[f->unit].neg_ifaceid;
446 if (!wo->opt_local) {
447 eui64_magic_nz(wo->ourid);
451 eui64_zero(go->hisid); /* last proposed interface identifier */
456 * ipv6cp_cilen - Return length of our CI.
462 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
464 #define LENCIVJ(neg) (neg ? CILEN_COMPRESS : 0)
465 #define LENCIIFACEID(neg) (neg ? CILEN_IFACEID : 0)
467 return (LENCIIFACEID(go->neg_ifaceid) +
468 LENCIVJ(go->neg_vj));
473 * ipv6cp_addci - Add our desired CIs to a packet.
476 ipv6cp_addci(f, ucp, lenp)
481 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
484 #define ADDCIVJ(opt, neg, val) \
486 int vjlen = CILEN_COMPRESS; \
487 if (len >= vjlen) { \
489 PUTCHAR(vjlen, ucp); \
490 PUTSHORT(val, ucp); \
496 #define ADDCIIFACEID(opt, neg, val1) \
498 int idlen = CILEN_IFACEID; \
499 if (len >= idlen) { \
501 PUTCHAR(idlen, ucp); \
502 eui64_put(val1, ucp); \
508 ADDCIIFACEID(CI_IFACEID, go->neg_ifaceid, go->ourid);
510 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol);
517 * ipv6cp_ackci - Ack our CIs.
524 ipv6cp_ackci(f, p, len)
529 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
530 u_short cilen, citype, cishort;
534 * CIs must be in exactly the same order that we sent...
535 * Check packet length and CI length at each step.
536 * If we find any deviations, then this packet is bad.
539 #define ACKCIVJ(opt, neg, val) \
541 int vjlen = CILEN_COMPRESS; \
542 if ((len -= vjlen) < 0) \
544 GETCHAR(citype, p); \
546 if (cilen != vjlen || \
549 GETSHORT(cishort, p); \
550 if (cishort != val) \
554 #define ACKCIIFACEID(opt, neg, val1) \
556 int idlen = CILEN_IFACEID; \
557 if ((len -= idlen) < 0) \
559 GETCHAR(citype, p); \
561 if (cilen != idlen || \
564 eui64_get(ifaceid, p); \
565 if (! eui64_equals(val1, ifaceid)) \
569 ACKCIIFACEID(CI_IFACEID, go->neg_ifaceid, go->ourid);
571 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol);
574 * If there are any remaining CIs, then this packet is bad.
581 IPV6CPDEBUG(("ipv6cp_ackci: received bad Ack!"));
586 * ipv6cp_nakci - Peer has sent a NAK for some of our CIs.
587 * This should not modify any state if the Nak is bad
588 * or if IPV6CP is in the OPENED state.
595 ipv6cp_nakci(f, p, len)
600 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
601 u_char citype, cilen, *next;
604 ipv6cp_options no; /* options we've seen Naks for */
605 ipv6cp_options try; /* options to request next time */
607 BZERO(&no, sizeof(no));
611 * Any Nak'd CIs must be in exactly the same order that we sent.
612 * Check packet length and CI length at each step.
613 * If we find any deviations, then this packet is bad.
615 #define NAKCIIFACEID(opt, neg, code) \
617 len >= (cilen = CILEN_IFACEID) && \
622 eui64_get(ifaceid, p); \
627 #define NAKCIVJ(opt, neg, code) \
629 ((cilen = p[1]) == CILEN_COMPRESS) && \
634 GETSHORT(cishort, p); \
640 * Accept the peer's idea of {our,his} interface identifier, if different
641 * from our idea, only if the accept_{local,remote} flag is set.
643 NAKCIIFACEID(CI_IFACEID, neg_ifaceid,
644 if (go->accept_local) {
645 while (eui64_iszero(ifaceid) ||
646 eui64_equals(ifaceid, go->hisid)) /* bad luck */
647 eui64_magic(ifaceid);
649 IPV6CPDEBUG(("local LL address %s", llv6_ntoa(ifaceid)));
654 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
656 if (cishort == IPV6CP_COMP) {
657 try.vj_protocol = cishort;
664 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
672 * There may be remaining CIs, if the peer is requesting negotiation
673 * on an option that we didn't include in our request packet.
674 * If they want to negotiate about interface identifier, we comply.
675 * If they want us to ask for compression, we refuse.
677 while (len > CILEN_VOID) {
680 if( (len -= cilen) < 0 )
682 next = p + cilen - 2;
685 case CI_COMPRESSTYPE:
686 if (go->neg_vj || no.neg_vj ||
687 (cilen != CILEN_COMPRESS))
692 if (go->neg_ifaceid || no.neg_ifaceid || cilen != CILEN_IFACEID)
695 eui64_get(ifaceid, p);
696 if (go->accept_local) {
697 while (eui64_iszero(ifaceid) ||
698 eui64_equals(ifaceid, go->hisid)) /* bad luck */
699 eui64_magic(ifaceid);
708 /* If there is still anything left, this packet is bad. */
713 * OK, the Nak is good. Now we can update state.
715 if (f->state != OPENED)
721 IPV6CPDEBUG(("ipv6cp_nakci: received bad Nak!"));
727 * ipv6cp_rejci - Reject some of our CIs.
730 ipv6cp_rejci(f, p, len)
735 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
739 ipv6cp_options try; /* options to request next time */
743 * Any Rejected CIs must be in exactly the same order that we sent.
744 * Check packet length and CI length at each step.
745 * If we find any deviations, then this packet is bad.
747 #define REJCIIFACEID(opt, neg, val1) \
749 len >= (cilen = CILEN_IFACEID) && \
754 eui64_get(ifaceid, p); \
755 /* Check rejected value. */ \
756 if (! eui64_equals(ifaceid, val1)) \
761 #define REJCIVJ(opt, neg, val) \
763 p[1] == CILEN_COMPRESS && \
768 GETSHORT(cishort, p); \
769 /* Check rejected value. */ \
770 if (cishort != val) \
775 REJCIIFACEID(CI_IFACEID, neg_ifaceid, go->ourid);
777 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol);
780 * If there are any remaining CIs, then this packet is bad.
785 * Now we can update state.
787 if (f->state != OPENED)
792 IPV6CPDEBUG(("ipv6cp_rejci: received bad Reject!"));
798 * ipv6cp_reqci - Check the peer's requested CIs and send appropriate response.
800 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
801 * appropriately. If reject_if_disagree is non-zero, doesn't return
802 * CONFNAK; returns CONFREJ if it can't return CONFACK.
805 ipv6cp_reqci(f, inp, len, reject_if_disagree)
807 u_char *inp; /* Requested CIs */
808 int *len; /* Length of requested CIs */
809 int reject_if_disagree;
811 ipv6cp_options *wo = &ipv6cp_wantoptions[f->unit];
812 ipv6cp_options *ho = &ipv6cp_hisoptions[f->unit];
813 ipv6cp_options *ao = &ipv6cp_allowoptions[f->unit];
814 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
815 u_char *cip, *next; /* Pointer to current and next CIs */
816 u_short cilen, citype; /* Parsed len, type */
817 u_short cishort; /* Parsed short value */
818 eui64_t ifaceid; /* Parsed interface identifier */
819 int rc = CONFACK; /* Final packet return code */
820 int orc; /* Individual option return code */
821 u_char *p; /* Pointer to next char to parse */
822 u_char *ucp = inp; /* Pointer to current output char */
823 int l = *len; /* Length left */
826 * Reset all his options.
828 BZERO(ho, sizeof(*ho));
831 * Process all his options.
835 orc = CONFACK; /* Assume success */
836 cip = p = next; /* Remember begining of CI */
837 if (l < 2 || /* Not enough data for CI header or */
838 p[1] < 2 || /* CI length too small or */
839 p[1] > l) { /* CI length too big? */
840 IPV6CPDEBUG(("ipv6cp_reqci: bad CI length!"));
841 orc = CONFREJ; /* Reject bad CI */
842 cilen = l; /* Reject till end of packet */
843 l = 0; /* Don't loop again */
846 GETCHAR(citype, p); /* Parse CI type */
847 GETCHAR(cilen, p); /* Parse CI length */
848 l -= cilen; /* Adjust remaining length */
849 next += cilen; /* Step to next CI */
851 switch (citype) { /* Check CI type */
853 IPV6CPDEBUG(("ipv6cp: received interface identifier "));
855 if (!ao->neg_ifaceid ||
856 cilen != CILEN_IFACEID) { /* Check CI length */
857 orc = CONFREJ; /* Reject CI */
862 * If he has no interface identifier, or if we both have same
863 * identifier then NAK it with new idea.
864 * In particular, if we don't know his identifier, but he does,
867 eui64_get(ifaceid, p);
868 IPV6CPDEBUG(("(%s)", llv6_ntoa(ifaceid)));
869 if (eui64_iszero(ifaceid) && eui64_iszero(go->ourid)) {
870 orc = CONFREJ; /* Reject CI */
873 if (!eui64_iszero(wo->hisid) &&
874 !eui64_equals(ifaceid, wo->hisid) &&
875 eui64_iszero(go->hisid)) {
880 DECPTR(sizeof(ifaceid), p);
881 eui64_put(ifaceid, p);
883 if (eui64_iszero(ifaceid) || eui64_equals(ifaceid, go->ourid)) {
885 if (eui64_iszero(go->hisid)) /* first time, try option */
887 while (eui64_iszero(ifaceid) ||
888 eui64_equals(ifaceid, go->ourid)) /* bad luck */
889 eui64_magic(ifaceid);
891 DECPTR(sizeof(ifaceid), p);
892 eui64_put(ifaceid, p);
899 case CI_COMPRESSTYPE:
900 IPV6CPDEBUG(("ipv6cp: received COMPRESSTYPE "));
902 (cilen != CILEN_COMPRESS)) {
906 GETSHORT(cishort, p);
907 IPV6CPDEBUG(("(%d)", cishort));
910 if (!(cishort == IPV6CP_COMP)) {
916 ho->vj_protocol = cishort;
929 IPV6CPDEBUG((" (%s)\n", CODENAME(orc)));
931 if (orc == CONFACK && /* Good CI */
932 rc != CONFACK) /* but prior CI wasnt? */
933 continue; /* Don't send this one */
935 if (orc == CONFNAK) { /* Nak this CI? */
936 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
937 orc = CONFREJ; /* Get tough if so */
939 if (rc == CONFREJ) /* Rejecting prior CI? */
940 continue; /* Don't send this one */
941 if (rc == CONFACK) { /* Ack'd all prior CIs? */
942 rc = CONFNAK; /* Not anymore... */
943 ucp = inp; /* Backup */
948 if (orc == CONFREJ && /* Reject this CI */
949 rc != CONFREJ) { /* but no prior ones? */
951 ucp = inp; /* Backup */
954 /* Need to move CI? */
956 BCOPY(cip, ucp, cilen); /* Move it */
958 /* Update output pointer */
963 * If we aren't rejecting this packet, and we want to negotiate
964 * their identifier and they didn't send their identifier, then we
965 * send a NAK with a CI_IFACEID option appended. We assume the
966 * input buffer is long enough that we can append the extra
969 if (rc != CONFREJ && !ho->neg_ifaceid &&
970 wo->req_ifaceid && !reject_if_disagree) {
973 ucp = inp; /* reset pointer */
974 wo->req_ifaceid = 0; /* don't ask again */
976 PUTCHAR(CI_IFACEID, ucp);
977 PUTCHAR(CILEN_IFACEID, ucp);
978 eui64_put(wo->hisid, ucp);
981 *len = ucp - inp; /* Compute output length */
982 IPV6CPDEBUG(("ipv6cp: returning Configure-%s", CODENAME(rc)));
983 return (rc); /* Return final code */
988 * ipv6_check_options - check that any IP-related options are OK,
989 * and assign appropriate defaults.
994 ipv6cp_options *wo = &ipv6cp_wantoptions[0];
998 * Persistent link-local id is only used when user has not explicitly
999 * configure/hard-code the id
1001 if ((wo->use_persistent) && (!wo->opt_local) && (!wo->opt_remote)) {
1004 * On systems where there are no Ethernet interfaces used, there
1005 * may be other ways to obtain a persistent id. Right now, it
1006 * will fall back to using magic [see eui64_magic] below when
1007 * an EUI-48 from MAC address can't be obtained. Other possibilities
1008 * include obtaining EEPROM serial numbers, or some other unique
1009 * yet persistent number. On Sparc platforms, this is possible,
1010 * but too bad there's no standards yet for x86 machines.
1012 if (ether_to_eui64(&wo->ourid)) {
1018 if (!wo->opt_local) { /* init interface identifier */
1019 if (wo->use_ip && eui64_iszero(wo->ourid)) {
1020 eui64_setlo32(wo->ourid, ntohl(ipcp_wantoptions[0].ouraddr));
1021 if (!eui64_iszero(wo->ourid))
1025 while (eui64_iszero(wo->ourid))
1026 eui64_magic(wo->ourid);
1029 if (!wo->opt_remote) {
1030 if (wo->use_ip && eui64_iszero(wo->hisid)) {
1031 eui64_setlo32(wo->hisid, ntohl(ipcp_wantoptions[0].hisaddr));
1032 if (!eui64_iszero(wo->hisid))
1037 if (demand && (eui64_iszero(wo->ourid) || eui64_iszero(wo->hisid))) {
1038 option_error("local/remote LL address required for demand-dialling\n");
1045 * ipv6_demand_conf - configure the interface as though
1046 * IPV6CP were up, for use with dial-on-demand.
1052 ipv6cp_options *wo = &ipv6cp_wantoptions[u];
1054 #if defined(__linux__) || defined(SOL2) || (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1061 #endif /* defined(SOL2) */
1063 if (!sif6addr(u, wo->ourid, wo->hisid))
1065 #if !defined(__linux__) && !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1069 if (!sifnpmode(u, PPP_IPV6, NPMODE_QUEUE))
1072 notice("ipv6_demand_conf");
1073 notice("local LL address %s", llv6_ntoa(wo->ourid));
1074 notice("remote LL address %s", llv6_ntoa(wo->hisid));
1081 * ipv6cp_up - IPV6CP has come UP.
1083 * Configure the IPv6 network interface appropriately and bring it up.
1089 ipv6cp_options *ho = &ipv6cp_hisoptions[f->unit];
1090 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
1091 ipv6cp_options *wo = &ipv6cp_wantoptions[f->unit];
1093 IPV6CPDEBUG(("ipv6cp: up"));
1096 * We must have a non-zero LL address for both ends of the link.
1098 if (!ho->neg_ifaceid)
1099 ho->hisid = wo->hisid;
1101 if(!no_ifaceid_neg) {
1102 if (eui64_iszero(ho->hisid)) {
1103 error("Could not determine remote LL address");
1104 ipv6cp_close(f->unit, "Could not determine remote LL address");
1107 if (eui64_iszero(go->ourid)) {
1108 error("Could not determine local LL address");
1109 ipv6cp_close(f->unit, "Could not determine local LL address");
1112 if (eui64_equals(go->ourid, ho->hisid)) {
1113 error("local and remote LL addresses are equal");
1114 ipv6cp_close(f->unit, "local and remote LL addresses are equal");
1118 script_setenv("LLLOCAL", llv6_ntoa(go->ourid), 0);
1119 script_setenv("LLREMOTE", llv6_ntoa(ho->hisid), 0);
1122 /* set tcp compression */
1123 sif6comp(f->unit, ho->neg_vj);
1127 * If we are doing dial-on-demand, the interface is already
1128 * configured, so we put out any saved-up packets, then set the
1129 * interface to pass IPv6 packets.
1132 if (! eui64_equals(go->ourid, wo->ourid) ||
1133 ! eui64_equals(ho->hisid, wo->hisid)) {
1134 if (! eui64_equals(go->ourid, wo->ourid))
1135 warn("Local LL address changed to %s",
1136 llv6_ntoa(go->ourid));
1137 if (! eui64_equals(ho->hisid, wo->hisid))
1138 warn("Remote LL address changed to %s",
1139 llv6_ntoa(ho->hisid));
1140 ipv6cp_clear_addrs(f->unit, go->ourid, ho->hisid);
1142 /* Set the interface to the new addresses */
1143 if (!sif6addr(f->unit, go->ourid, ho->hisid)) {
1145 warn("sif6addr failed");
1146 ipv6cp_close(f->unit, "Interface configuration failed");
1151 demand_rexmit(PPP_IPV6);
1152 sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
1158 #if !defined(__linux__) && !defined(SOL2) && !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1159 if (!sif6addr(f->unit, go->ourid, ho->hisid)) {
1161 warn("sif6addr failed");
1162 ipv6cp_close(f->unit, "Interface configuration failed");
1167 /* bring the interface up for IPv6 */
1169 if (!sif6up(f->unit)) {
1171 warn("sifup failed (IPV6)");
1172 ipv6cp_close(f->unit, "Interface configuration failed");
1176 if (!sifup(f->unit)) {
1178 warn("sifup failed (IPV6)");
1179 ipv6cp_close(f->unit, "Interface configuration failed");
1182 #endif /* defined(SOL2) */
1184 #if defined(__linux__) || defined(SOL2) || (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1185 if (!sif6addr(f->unit, go->ourid, ho->hisid)) {
1187 warn("sif6addr failed");
1188 ipv6cp_close(f->unit, "Interface configuration failed");
1192 sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
1194 notice("local LL address %s", llv6_ntoa(go->ourid));
1195 notice("remote LL address %s", llv6_ntoa(ho->hisid));
1198 np_up(f->unit, PPP_IPV6);
1202 * Execute the ipv6-up script, like this:
1203 * /etc/ppp/ipv6-up interface tty speed local-LL remote-LL
1205 if (ipv6cp_script_state == s_down && ipv6cp_script_pid == 0) {
1206 ipv6cp_script_state = s_up;
1207 ipv6cp_script(_PATH_IPV6UP);
1213 * ipv6cp_down - IPV6CP has gone DOWN.
1215 * Take the IPv6 network interface down, clear its addresses
1216 * and delete routes through it.
1222 IPV6CPDEBUG(("ipv6cp: down"));
1223 update_link_stats(f->unit);
1226 np_down(f->unit, PPP_IPV6);
1229 sif6comp(f->unit, 0);
1233 * If we are doing dial-on-demand, set the interface
1234 * to queue up outgoing packets (for now).
1237 sifnpmode(f->unit, PPP_IPV6, NPMODE_QUEUE);
1239 sifnpmode(f->unit, PPP_IPV6, NPMODE_DROP);
1240 #if !defined(__linux__) && !(defined(SVR4) && (defined(SNI) || defined(__USLC)))
1245 #endif /* defined(SOL2) */
1247 ipv6cp_clear_addrs(f->unit,
1248 ipv6cp_gotoptions[f->unit].ourid,
1249 ipv6cp_hisoptions[f->unit].hisid);
1250 #if defined(__linux__) || (defined(SVR4) && (defined(SNI) || defined(__USLC)))
1255 /* Execute the ipv6-down script */
1256 if (ipv6cp_script_state == s_up && ipv6cp_script_pid == 0) {
1257 ipv6cp_script_state = s_down;
1258 ipv6cp_script(_PATH_IPV6DOWN);
1264 * ipv6cp_clear_addrs() - clear the interface addresses, routes,
1265 * proxy neighbour discovery entries, etc.
1268 ipv6cp_clear_addrs(unit, ourid, hisid)
1273 cif6addr(unit, ourid, hisid);
1278 * ipv6cp_finished - possibly shut down the lower layers.
1284 np_finished(f->unit, PPP_IPV6);
1289 * ipv6cp_script_done - called when the ipv6-up or ipv6-down script
1293 ipv6cp_script_done(arg)
1296 ipv6cp_script_pid = 0;
1297 switch (ipv6cp_script_state) {
1299 if (ipv6cp_fsm[0].state != OPENED) {
1300 ipv6cp_script_state = s_down;
1301 ipv6cp_script(_PATH_IPV6DOWN);
1305 if (ipv6cp_fsm[0].state == OPENED) {
1306 ipv6cp_script_state = s_up;
1307 ipv6cp_script(_PATH_IPV6UP);
1315 * ipv6cp_script - Execute a script with arguments
1316 * interface-name tty-name speed local-LL remote-LL.
1319 ipv6cp_script(script)
1322 char strspeed[32], strlocal[32], strremote[32];
1325 sprintf(strspeed, "%d", baud_rate);
1326 strcpy(strlocal, llv6_ntoa(ipv6cp_gotoptions[0].ourid));
1327 strcpy(strremote, llv6_ntoa(ipv6cp_hisoptions[0].hisid));
1334 argv[5] = strremote;
1338 ipv6cp_script_pid = run_program(script, argv, 0, ipv6cp_script_done, NULL);
1342 * ipv6cp_printpkt - print the contents of an IPV6CP packet.
1344 static char *ipv6cp_codenames[] = {
1345 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1346 "TermReq", "TermAck", "CodeRej"
1350 ipv6cp_printpkt(p, plen, printer, arg)
1353 void (*printer) __P((void *, char *, ...));
1356 int code, id, len, olen;
1357 u_char *pstart, *optend;
1361 if (plen < HEADERLEN)
1367 if (len < HEADERLEN || len > plen)
1370 if (code >= 1 && code <= sizeof(ipv6cp_codenames) / sizeof(char *))
1371 printer(arg, " %s", ipv6cp_codenames[code-1]);
1373 printer(arg, " code=0x%x", code);
1374 printer(arg, " id=0x%x", id);
1381 /* print option list */
1386 if (olen < 2 || olen > len) {
1393 case CI_COMPRESSTYPE:
1394 if (olen >= CILEN_COMPRESS) {
1396 GETSHORT(cishort, p);
1397 printer(arg, "compress ");
1398 printer(arg, "0x%x", cishort);
1402 if (olen == CILEN_IFACEID) {
1404 eui64_get(ifaceid, p);
1405 printer(arg, "addr %s", llv6_ntoa(ifaceid));
1409 while (p < optend) {
1411 printer(arg, " %.2x", code);
1419 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1421 print_string((char *)p, len, printer, arg);
1428 /* print the rest of the bytes in the packet */
1429 for (; len > 0; --len) {
1431 printer(arg, " %.2x", code);
1438 * ipv6_active_pkt - see if this IP packet is worth bringing the link up for.
1439 * We don't bring the link up for IP fragments or for TCP FIN packets
1442 #define IP6_HDRLEN 40 /* bytes */
1443 #define IP6_NHDR_FRAG 44 /* fragment IPv6 header */
1444 #define IPPROTO_TCP 6
1445 #define TCP_HDRLEN 20
1449 * We use these macros because the IP header may be at an odd address,
1450 * and some compilers might use word loads to get th_off or ip_hl.
1453 #define get_ip6nh(x) (((unsigned char *)(x))[6])
1454 #define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
1455 #define get_tcpflags(x) (((unsigned char *)(x))[13])
1458 ipv6_active_pkt(pkt, len)
1466 if (len < IP6_HDRLEN)
1468 if (get_ip6nh(pkt) == IP6_NHDR_FRAG)
1470 if (get_ip6nh(pkt) != IPPROTO_TCP)
1472 if (len < IP6_HDRLEN + TCP_HDRLEN)
1474 tcp = pkt + IP6_HDRLEN;
1475 if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == IP6_HDRLEN + get_tcpoff(tcp) * 4)