CPU: Wrong CPU Load %.
[tomato.git] / release / src / router / ppp / pppd / ipv6cp.c
blob205e8de44a60b14e6387a21e82e99c0584c94b35
1 /*
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.
73 * Derived from :
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.1.1.4 2003/10/14 08:09:53 sparq Exp $
96 #define RCSID "$Id: ipv6cp.c,v 1.1.1.4 2003/10/14 08:09:53 sparq Exp $"
99 * TODO:
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)
108 #include <stdio.h>
109 #include <string.h>
110 #include <stdlib.h>
111 #include <netdb.h>
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>
118 #include "../pppoecd/pppd.h"
119 #include "fsm.h"
120 #include "ipcp.h"
121 #include "ipv6cp.h"
122 #include "magic.h"
123 #include "pathnames.h"
125 static const char rcsid[] = RCSID;
127 /* global vars */
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;
134 /* local vars */
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));
175 static void printifaceid __P((option_t *,
176 void (*)(void *, char *, ...), void *));
178 static option_t ipv6cp_option_list[] = {
179 { "ipv6", o_special, (void *)setifaceid,
180 "Set interface identifiers for IPV6",
181 OPT_A2PRINTER, (void *)printifaceid },
183 { "+ipv6", o_bool, &ipv6cp_protent.enabled_flag,
184 "Enable IPv6 and IPv6CP", OPT_PRIO | 1 },
185 { "noipv6", o_bool, &ipv6cp_protent.enabled_flag,
186 "Disable IPv6 and IPv6CP", OPT_PRIOSUB },
187 { "-ipv6", o_bool, &ipv6cp_protent.enabled_flag,
188 "Disable IPv6 and IPv6CP", OPT_PRIOSUB | OPT_ALIAS },
190 { "ipv6cp-accept-local", o_bool, &ipv6cp_allowoptions[0].accept_local,
191 "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", 1 },
196 #if defined(SOL2)
197 { "ipv6cp-use-persistent", o_bool, &ipv6cp_wantoptions[0].use_persistent,
198 "Use uniquely-available persistent value for link local address", 1 },
199 #endif /* defined(SOL2) */
201 { "ipv6cp-restart", o_int, &ipv6cp_fsm[0].timeouttime,
202 "Set timeout for IPv6CP", OPT_PRIO },
203 { "ipv6cp-max-terminate", o_int, &ipv6cp_fsm[0].maxtermtransmits,
204 "Set max #xmits for term-reqs", OPT_PRIO },
205 { "ipv6cp-max-configure", o_int, &ipv6cp_fsm[0].maxconfreqtransmits,
206 "Set max #xmits for conf-reqs", OPT_PRIO },
207 { "ipv6cp-max-failure", o_int, &ipv6cp_fsm[0].maxnakloops,
208 "Set max #conf-naks for IPv6CP", OPT_PRIO },
210 { NULL }
215 * Protocol entry points from main code.
217 static void ipv6cp_init __P((int));
218 static void ipv6cp_open __P((int));
219 static void ipv6cp_close __P((int, char *));
220 static void ipv6cp_lowerup __P((int));
221 static void ipv6cp_lowerdown __P((int));
222 static void ipv6cp_input __P((int, u_char *, int));
223 static void ipv6cp_protrej __P((int));
224 static int ipv6cp_printpkt __P((u_char *, int,
225 void (*) __P((void *, char *, ...)), void *));
226 static void ipv6_check_options __P((void));
227 static int ipv6_demand_conf __P((int));
228 static int ipv6_active_pkt __P((u_char *, int));
230 struct protent ipv6cp_protent = {
231 PPP_IPV6CP,
232 ipv6cp_init,
233 ipv6cp_input,
234 ipv6cp_protrej,
235 ipv6cp_lowerup,
236 ipv6cp_lowerdown,
237 ipv6cp_open,
238 ipv6cp_close,
239 ipv6cp_printpkt,
240 NULL,
242 "IPV6CP",
243 "IPV6",
244 ipv6cp_option_list,
245 ipv6_check_options,
246 ipv6_demand_conf,
247 ipv6_active_pkt
250 static void ipv6cp_clear_addrs __P((int, eui64_t, eui64_t));
251 static void ipv6cp_script __P((char *));
252 static void ipv6cp_script_done __P((void *));
255 * Lengths of configuration options.
257 #define CILEN_VOID 2
258 #define CILEN_COMPRESS 4 /* length for RFC2023 compress opt. */
259 #define CILEN_IFACEID 10 /* RFC2472, interface identifier */
261 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
262 (x) == CONFNAK ? "NAK" : "REJ")
265 * This state variable is used to ensure that we don't
266 * run an ipcp-up/down script while one is already running.
268 static enum script_state {
269 s_down,
270 s_up,
271 } ipv6cp_script_state;
272 static pid_t ipv6cp_script_pid;
275 * setifaceid - set the interface identifiers manually
277 static int
278 setifaceid(argv)
279 char **argv;
281 char *comma, *arg, c;
282 ipv6cp_options *wo = &ipv6cp_wantoptions[0];
283 struct in6_addr addr;
284 static int prio_local, prio_remote;
286 #define VALIDID(a) ( (((a).s6_addr32[0] == 0) && ((a).s6_addr32[1] == 0)) && \
287 (((a).s6_addr32[2] != 0) || ((a).s6_addr32[3] != 0)) )
289 arg = *argv;
290 if ((comma = strchr(arg, ',')) == NULL)
291 comma = arg + strlen(arg);
294 * If comma first character, then no local identifier
296 if (comma != arg) {
297 c = *comma;
298 *comma = '\0';
300 if (inet_pton(AF_INET6, arg, &addr) == 0 || !VALIDID(addr)) {
301 option_error("Illegal interface identifier (local): %s", arg);
302 return 0;
305 if (option_priority >= prio_local) {
306 eui64_copy(addr.s6_addr32[2], wo->ourid);
307 wo->opt_local = 1;
308 prio_local = option_priority;
310 *comma = c;
314 * If comma last character, the no remote identifier
316 if (*comma != 0 && *++comma != '\0') {
317 if (inet_pton(AF_INET6, comma, &addr) == 0 || !VALIDID(addr)) {
318 option_error("Illegal interface identifier (remote): %s", comma);
319 return 0;
321 if (option_priority >= prio_remote) {
322 eui64_copy(addr.s6_addr32[2], wo->hisid);
323 wo->opt_remote = 1;
324 prio_remote = option_priority;
328 if (override_value("+ipv6", option_priority, option_source))
329 ipv6cp_protent.enabled_flag = 1;
330 return 1;
333 static void
334 printifaceid(opt, printer, arg)
335 option_t *opt;
336 void (*printer) __P((void *, char *, ...));
337 void *arg;
339 ipv6cp_options *wo = &ipv6cp_wantoptions[0];
340 char *llv6_ntoa(ifaceid);
342 if (wo->opt_local)
343 printer(arg, "%s", llv6_ntoa(wo->ourid));
344 printer(arg, ",");
345 if (wo->opt_remote)
346 printer(arg, "%s", llv6_ntoa(wo->hisid));
350 * Make a string representation of a network address.
352 char *
353 llv6_ntoa(ifaceid)
354 eui64_t ifaceid;
356 static char b[64];
358 sprintf(b, "fe80::%s", eui64_ntoa(ifaceid));
359 return b;
364 * ipv6cp_init - Initialize IPV6CP.
366 static void
367 ipv6cp_init(unit)
368 int unit;
370 fsm *f = &ipv6cp_fsm[unit];
371 ipv6cp_options *wo = &ipv6cp_wantoptions[unit];
372 ipv6cp_options *ao = &ipv6cp_allowoptions[unit];
374 f->unit = unit;
375 f->protocol = PPP_IPV6CP;
376 f->callbacks = &ipv6cp_callbacks;
377 fsm_init(&ipv6cp_fsm[unit]);
379 memset(wo, 0, sizeof(*wo));
380 memset(ao, 0, sizeof(*ao));
382 wo->accept_local = 1;
383 wo->neg_ifaceid = 1;
384 ao->neg_ifaceid = 1;
386 #ifdef IPV6CP_COMP
387 wo->neg_vj = 1;
388 ao->neg_vj = 1;
389 wo->vj_protocol = IPV6CP_COMP;
390 #endif
396 * ipv6cp_open - IPV6CP is allowed to come up.
398 static void
399 ipv6cp_open(unit)
400 int unit;
402 fsm_open(&ipv6cp_fsm[unit]);
407 * ipv6cp_close - Take IPV6CP down.
409 static void
410 ipv6cp_close(unit, reason)
411 int unit;
412 char *reason;
414 fsm_close(&ipv6cp_fsm[unit], reason);
419 * ipv6cp_lowerup - The lower layer is up.
421 static void
422 ipv6cp_lowerup(unit)
423 int unit;
425 fsm_lowerup(&ipv6cp_fsm[unit]);
430 * ipv6cp_lowerdown - The lower layer is down.
432 static void
433 ipv6cp_lowerdown(unit)
434 int unit;
436 fsm_lowerdown(&ipv6cp_fsm[unit]);
441 * ipv6cp_input - Input IPV6CP packet.
443 static void
444 ipv6cp_input(unit, p, len)
445 int unit;
446 u_char *p;
447 int len;
449 fsm_input(&ipv6cp_fsm[unit], p, len);
454 * ipv6cp_protrej - A Protocol-Reject was received for IPV6CP.
456 * Pretend the lower layer went down, so we shut up.
458 static void
459 ipv6cp_protrej(unit)
460 int unit;
462 fsm_lowerdown(&ipv6cp_fsm[unit]);
467 * ipv6cp_resetci - Reset our CI.
469 static void
470 ipv6cp_resetci(f)
471 fsm *f;
473 ipv6cp_options *wo = &ipv6cp_wantoptions[f->unit];
474 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
476 wo->req_ifaceid = wo->neg_ifaceid && ipv6cp_allowoptions[f->unit].neg_ifaceid;
478 if (!wo->opt_local) {
479 eui64_magic_nz(wo->ourid);
482 *go = *wo;
483 eui64_zero(go->hisid); /* last proposed interface identifier */
488 * ipv6cp_cilen - Return length of our CI.
490 static int
491 ipv6cp_cilen(f)
492 fsm *f;
494 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
496 #define LENCIVJ(neg) (neg ? CILEN_COMPRESS : 0)
497 #define LENCIIFACEID(neg) (neg ? CILEN_IFACEID : 0)
499 return (LENCIIFACEID(go->neg_ifaceid) +
500 LENCIVJ(go->neg_vj));
505 * ipv6cp_addci - Add our desired CIs to a packet.
507 static void
508 ipv6cp_addci(f, ucp, lenp)
509 fsm *f;
510 u_char *ucp;
511 int *lenp;
513 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
514 int len = *lenp;
516 #define ADDCIVJ(opt, neg, val) \
517 if (neg) { \
518 int vjlen = CILEN_COMPRESS; \
519 if (len >= vjlen) { \
520 PUTCHAR(opt, ucp); \
521 PUTCHAR(vjlen, ucp); \
522 PUTSHORT(val, ucp); \
523 len -= vjlen; \
524 } else \
525 neg = 0; \
528 #define ADDCIIFACEID(opt, neg, val1) \
529 if (neg) { \
530 int idlen = CILEN_IFACEID; \
531 if (len >= idlen) { \
532 PUTCHAR(opt, ucp); \
533 PUTCHAR(idlen, ucp); \
534 eui64_put(val1, ucp); \
535 len -= idlen; \
536 } else \
537 neg = 0; \
540 ADDCIIFACEID(CI_IFACEID, go->neg_ifaceid, go->ourid);
542 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol);
544 *lenp -= len;
549 * ipv6cp_ackci - Ack our CIs.
551 * Returns:
552 * 0 - Ack was bad.
553 * 1 - Ack was good.
555 static int
556 ipv6cp_ackci(f, p, len)
557 fsm *f;
558 u_char *p;
559 int len;
561 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
562 u_short cilen, citype, cishort;
563 eui64_t ifaceid;
566 * CIs must be in exactly the same order that we sent...
567 * Check packet length and CI length at each step.
568 * If we find any deviations, then this packet is bad.
571 #define ACKCIVJ(opt, neg, val) \
572 if (neg) { \
573 int vjlen = CILEN_COMPRESS; \
574 if ((len -= vjlen) < 0) \
575 goto bad; \
576 GETCHAR(citype, p); \
577 GETCHAR(cilen, p); \
578 if (cilen != vjlen || \
579 citype != opt) \
580 goto bad; \
581 GETSHORT(cishort, p); \
582 if (cishort != val) \
583 goto bad; \
586 #define ACKCIIFACEID(opt, neg, val1) \
587 if (neg) { \
588 int idlen = CILEN_IFACEID; \
589 if ((len -= idlen) < 0) \
590 goto bad; \
591 GETCHAR(citype, p); \
592 GETCHAR(cilen, p); \
593 if (cilen != idlen || \
594 citype != opt) \
595 goto bad; \
596 eui64_get(ifaceid, p); \
597 if (! eui64_equals(val1, ifaceid)) \
598 goto bad; \
601 ACKCIIFACEID(CI_IFACEID, go->neg_ifaceid, go->ourid);
603 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol);
606 * If there are any remaining CIs, then this packet is bad.
608 if (len != 0)
609 goto bad;
610 return (1);
612 bad:
613 IPV6CPDEBUG(("ipv6cp_ackci: received bad Ack!"));
614 return (0);
618 * ipv6cp_nakci - Peer has sent a NAK for some of our CIs.
619 * This should not modify any state if the Nak is bad
620 * or if IPV6CP is in the OPENED state.
622 * Returns:
623 * 0 - Nak was bad.
624 * 1 - Nak was good.
626 static int
627 ipv6cp_nakci(f, p, len)
628 fsm *f;
629 u_char *p;
630 int len;
632 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
633 u_char citype, cilen, *next;
634 u_short cishort;
635 eui64_t ifaceid;
636 ipv6cp_options no; /* options we've seen Naks for */
637 ipv6cp_options try; /* options to request next time */
639 BZERO(&no, sizeof(no));
640 try = *go;
643 * Any Nak'd CIs must be in exactly the same order that we sent.
644 * Check packet length and CI length at each step.
645 * If we find any deviations, then this packet is bad.
647 #define NAKCIIFACEID(opt, neg, code) \
648 if (go->neg && \
649 len >= (cilen = CILEN_IFACEID) && \
650 p[1] == cilen && \
651 p[0] == opt) { \
652 len -= cilen; \
653 INCPTR(2, p); \
654 eui64_get(ifaceid, p); \
655 no.neg = 1; \
656 code \
659 #define NAKCIVJ(opt, neg, code) \
660 if (go->neg && \
661 ((cilen = p[1]) == CILEN_COMPRESS) && \
662 len >= cilen && \
663 p[0] == opt) { \
664 len -= cilen; \
665 INCPTR(2, p); \
666 GETSHORT(cishort, p); \
667 no.neg = 1; \
668 code \
672 * Accept the peer's idea of {our,his} interface identifier, if different
673 * from our idea, only if the accept_{local,remote} flag is set.
675 NAKCIIFACEID(CI_IFACEID, neg_ifaceid,
676 if (go->accept_local) {
677 while (eui64_iszero(ifaceid) ||
678 eui64_equals(ifaceid, go->hisid)) /* bad luck */
679 eui64_magic(ifaceid);
680 try.ourid = ifaceid;
681 IPV6CPDEBUG(("local LL address %s", llv6_ntoa(ifaceid)));
685 #ifdef IPV6CP_COMP
686 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
688 if (cishort == IPV6CP_COMP) {
689 try.vj_protocol = cishort;
690 } else {
691 try.neg_vj = 0;
695 #else
696 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
698 try.neg_vj = 0;
701 #endif
704 * There may be remaining CIs, if the peer is requesting negotiation
705 * on an option that we didn't include in our request packet.
706 * If they want to negotiate about interface identifier, we comply.
707 * If they want us to ask for compression, we refuse.
709 while (len > CILEN_VOID) {
710 GETCHAR(citype, p);
711 GETCHAR(cilen, p);
712 if( (len -= cilen) < 0 )
713 goto bad;
714 next = p + cilen - 2;
716 switch (citype) {
717 case CI_COMPRESSTYPE:
718 if (go->neg_vj || no.neg_vj ||
719 (cilen != CILEN_COMPRESS))
720 goto bad;
721 no.neg_vj = 1;
722 break;
723 case CI_IFACEID:
724 if (go->neg_ifaceid || no.neg_ifaceid || cilen != CILEN_IFACEID)
725 goto bad;
726 try.neg_ifaceid = 1;
727 eui64_get(ifaceid, p);
728 if (go->accept_local) {
729 while (eui64_iszero(ifaceid) ||
730 eui64_equals(ifaceid, go->hisid)) /* bad luck */
731 eui64_magic(ifaceid);
732 try.ourid = ifaceid;
734 no.neg_ifaceid = 1;
735 break;
737 p = next;
740 /* If there is still anything left, this packet is bad. */
741 if (len != 0)
742 goto bad;
745 * OK, the Nak is good. Now we can update state.
747 if (f->state != OPENED)
748 *go = try;
750 return 1;
752 bad:
753 IPV6CPDEBUG(("ipv6cp_nakci: received bad Nak!"));
754 return 0;
759 * ipv6cp_rejci - Reject some of our CIs.
761 static int
762 ipv6cp_rejci(f, p, len)
763 fsm *f;
764 u_char *p;
765 int len;
767 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
768 u_char cilen;
769 u_short cishort;
770 eui64_t ifaceid;
771 ipv6cp_options try; /* options to request next time */
773 try = *go;
775 * Any Rejected CIs must be in exactly the same order that we sent.
776 * Check packet length and CI length at each step.
777 * If we find any deviations, then this packet is bad.
779 #define REJCIIFACEID(opt, neg, val1) \
780 if (go->neg && \
781 len >= (cilen = CILEN_IFACEID) && \
782 p[1] == cilen && \
783 p[0] == opt) { \
784 len -= cilen; \
785 INCPTR(2, p); \
786 eui64_get(ifaceid, p); \
787 /* Check rejected value. */ \
788 if (! eui64_equals(ifaceid, val1)) \
789 goto bad; \
790 try.neg = 0; \
793 #define REJCIVJ(opt, neg, val) \
794 if (go->neg && \
795 p[1] == CILEN_COMPRESS && \
796 len >= p[1] && \
797 p[0] == opt) { \
798 len -= p[1]; \
799 INCPTR(2, p); \
800 GETSHORT(cishort, p); \
801 /* Check rejected value. */ \
802 if (cishort != val) \
803 goto bad; \
804 try.neg = 0; \
807 REJCIIFACEID(CI_IFACEID, neg_ifaceid, go->ourid);
809 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol);
812 * If there are any remaining CIs, then this packet is bad.
814 if (len != 0)
815 goto bad;
817 * Now we can update state.
819 if (f->state != OPENED)
820 *go = try;
821 return 1;
823 bad:
824 IPV6CPDEBUG(("ipv6cp_rejci: received bad Reject!"));
825 return 0;
830 * ipv6cp_reqci - Check the peer's requested CIs and send appropriate response.
832 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
833 * appropriately. If reject_if_disagree is non-zero, doesn't return
834 * CONFNAK; returns CONFREJ if it can't return CONFACK.
836 static int
837 ipv6cp_reqci(f, inp, len, reject_if_disagree)
838 fsm *f;
839 u_char *inp; /* Requested CIs */
840 int *len; /* Length of requested CIs */
841 int reject_if_disagree;
843 ipv6cp_options *wo = &ipv6cp_wantoptions[f->unit];
844 ipv6cp_options *ho = &ipv6cp_hisoptions[f->unit];
845 ipv6cp_options *ao = &ipv6cp_allowoptions[f->unit];
846 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
847 u_char *cip, *next; /* Pointer to current and next CIs */
848 u_short cilen, citype; /* Parsed len, type */
849 u_short cishort; /* Parsed short value */
850 eui64_t ifaceid; /* Parsed interface identifier */
851 int rc = CONFACK; /* Final packet return code */
852 int orc; /* Individual option return code */
853 u_char *p; /* Pointer to next char to parse */
854 u_char *ucp = inp; /* Pointer to current output char */
855 int l = *len; /* Length left */
858 * Reset all his options.
860 BZERO(ho, sizeof(*ho));
863 * Process all his options.
865 next = inp;
866 while (l) {
867 orc = CONFACK; /* Assume success */
868 cip = p = next; /* Remember begining of CI */
869 if (l < 2 || /* Not enough data for CI header or */
870 p[1] < 2 || /* CI length too small or */
871 p[1] > l) { /* CI length too big? */
872 IPV6CPDEBUG(("ipv6cp_reqci: bad CI length!"));
873 orc = CONFREJ; /* Reject bad CI */
874 cilen = l; /* Reject till end of packet */
875 l = 0; /* Don't loop again */
876 goto endswitch;
878 GETCHAR(citype, p); /* Parse CI type */
879 GETCHAR(cilen, p); /* Parse CI length */
880 l -= cilen; /* Adjust remaining length */
881 next += cilen; /* Step to next CI */
883 switch (citype) { /* Check CI type */
884 case CI_IFACEID:
885 IPV6CPDEBUG(("ipv6cp: received interface identifier "));
887 if (!ao->neg_ifaceid ||
888 cilen != CILEN_IFACEID) { /* Check CI length */
889 orc = CONFREJ; /* Reject CI */
890 break;
894 * If he has no interface identifier, or if we both have same
895 * identifier then NAK it with new idea.
896 * In particular, if we don't know his identifier, but he does,
897 * then accept it.
899 eui64_get(ifaceid, p);
900 IPV6CPDEBUG(("(%s)", llv6_ntoa(ifaceid)));
901 if (eui64_iszero(ifaceid) && eui64_iszero(go->ourid)) {
902 orc = CONFREJ; /* Reject CI */
903 break;
905 if (!eui64_iszero(wo->hisid) &&
906 !eui64_equals(ifaceid, wo->hisid) &&
907 eui64_iszero(go->hisid)) {
909 orc = CONFNAK;
910 ifaceid = wo->hisid;
911 go->hisid = ifaceid;
912 DECPTR(sizeof(ifaceid), p);
913 eui64_put(ifaceid, p);
914 } else
915 if (eui64_iszero(ifaceid) || eui64_equals(ifaceid, go->ourid)) {
916 orc = CONFNAK;
917 if (eui64_iszero(go->hisid)) /* first time, try option */
918 ifaceid = wo->hisid;
919 while (eui64_iszero(ifaceid) ||
920 eui64_equals(ifaceid, go->ourid)) /* bad luck */
921 eui64_magic(ifaceid);
922 go->hisid = ifaceid;
923 DECPTR(sizeof(ifaceid), p);
924 eui64_put(ifaceid, p);
927 ho->neg_ifaceid = 1;
928 ho->hisid = ifaceid;
929 break;
931 case CI_COMPRESSTYPE:
932 IPV6CPDEBUG(("ipv6cp: received COMPRESSTYPE "));
933 if (!ao->neg_vj ||
934 (cilen != CILEN_COMPRESS)) {
935 orc = CONFREJ;
936 break;
938 GETSHORT(cishort, p);
939 IPV6CPDEBUG(("(%d)", cishort));
941 #ifdef IPV6CP_COMP
942 if (!(cishort == IPV6CP_COMP)) {
943 orc = CONFREJ;
944 break;
947 ho->neg_vj = 1;
948 ho->vj_protocol = cishort;
949 break;
950 #else
951 orc = CONFREJ;
952 break;
953 #endif
955 default:
956 orc = CONFREJ;
957 break;
960 endswitch:
961 IPV6CPDEBUG((" (%s)\n", CODENAME(orc)));
963 if (orc == CONFACK && /* Good CI */
964 rc != CONFACK) /* but prior CI wasnt? */
965 continue; /* Don't send this one */
967 if (orc == CONFNAK) { /* Nak this CI? */
968 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
969 orc = CONFREJ; /* Get tough if so */
970 else {
971 if (rc == CONFREJ) /* Rejecting prior CI? */
972 continue; /* Don't send this one */
973 if (rc == CONFACK) { /* Ack'd all prior CIs? */
974 rc = CONFNAK; /* Not anymore... */
975 ucp = inp; /* Backup */
980 if (orc == CONFREJ && /* Reject this CI */
981 rc != CONFREJ) { /* but no prior ones? */
982 rc = CONFREJ;
983 ucp = inp; /* Backup */
986 /* Need to move CI? */
987 if (ucp != cip)
988 BCOPY(cip, ucp, cilen); /* Move it */
990 /* Update output pointer */
991 INCPTR(cilen, ucp);
995 * If we aren't rejecting this packet, and we want to negotiate
996 * their identifier and they didn't send their identifier, then we
997 * send a NAK with a CI_IFACEID option appended. We assume the
998 * input buffer is long enough that we can append the extra
999 * option safely.
1001 if (rc != CONFREJ && !ho->neg_ifaceid &&
1002 wo->req_ifaceid && !reject_if_disagree) {
1003 if (rc == CONFACK) {
1004 rc = CONFNAK;
1005 ucp = inp; /* reset pointer */
1006 wo->req_ifaceid = 0; /* don't ask again */
1008 PUTCHAR(CI_IFACEID, ucp);
1009 PUTCHAR(CILEN_IFACEID, ucp);
1010 eui64_put(wo->hisid, ucp);
1013 *len = ucp - inp; /* Compute output length */
1014 IPV6CPDEBUG(("ipv6cp: returning Configure-%s", CODENAME(rc)));
1015 return (rc); /* Return final code */
1020 * ipv6_check_options - check that any IP-related options are OK,
1021 * and assign appropriate defaults.
1023 static void
1024 ipv6_check_options()
1026 ipv6cp_options *wo = &ipv6cp_wantoptions[0];
1028 if (!ipv6cp_protent.enabled_flag)
1029 return;
1031 #if defined(SOL2)
1033 * Persistent link-local id is only used when user has not explicitly
1034 * configure/hard-code the id
1036 if ((wo->use_persistent) && (!wo->opt_local) && (!wo->opt_remote)) {
1039 * On systems where there are no Ethernet interfaces used, there
1040 * may be other ways to obtain a persistent id. Right now, it
1041 * will fall back to using magic [see eui64_magic] below when
1042 * an EUI-48 from MAC address can't be obtained. Other possibilities
1043 * include obtaining EEPROM serial numbers, or some other unique
1044 * yet persistent number. On Sparc platforms, this is possible,
1045 * but too bad there's no standards yet for x86 machines.
1047 if (ether_to_eui64(&wo->ourid)) {
1048 wo->opt_local = 1;
1051 #endif
1053 if (!wo->opt_local) { /* init interface identifier */
1054 if (wo->use_ip && eui64_iszero(wo->ourid)) {
1055 eui64_setlo32(wo->ourid, ntohl(ipcp_wantoptions[0].ouraddr));
1056 if (!eui64_iszero(wo->ourid))
1057 wo->opt_local = 1;
1060 while (eui64_iszero(wo->ourid))
1061 eui64_magic(wo->ourid);
1064 if (!wo->opt_remote) {
1065 if (wo->use_ip && eui64_iszero(wo->hisid)) {
1066 eui64_setlo32(wo->hisid, ntohl(ipcp_wantoptions[0].hisaddr));
1067 if (!eui64_iszero(wo->hisid))
1068 wo->opt_remote = 1;
1072 if (demand && (eui64_iszero(wo->ourid) || eui64_iszero(wo->hisid))) {
1073 option_error("local/remote LL address required for demand-dialling\n");
1074 exit(1);
1080 * ipv6_demand_conf - configure the interface as though
1081 * IPV6CP were up, for use with dial-on-demand.
1083 static int
1084 ipv6_demand_conf(u)
1085 int u;
1087 ipv6cp_options *wo = &ipv6cp_wantoptions[u];
1089 #if defined(__linux__) || defined(SOL2) || (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1090 #if defined(SOL2)
1091 if (!sif6up(u))
1092 return 0;
1093 #else
1094 if (!sifup(u))
1095 return 0;
1096 #endif /* defined(SOL2) */
1097 #endif
1098 if (!sif6addr(u, wo->ourid, wo->hisid))
1099 return 0;
1100 #if !defined(__linux__) && !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1101 if (!sifup(u))
1102 return 0;
1103 #endif
1104 if (!sifnpmode(u, PPP_IPV6, NPMODE_QUEUE))
1105 return 0;
1107 notice("ipv6_demand_conf");
1108 notice("local LL address %s", llv6_ntoa(wo->ourid));
1109 notice("remote LL address %s", llv6_ntoa(wo->hisid));
1111 return 1;
1116 * ipv6cp_up - IPV6CP has come UP.
1118 * Configure the IPv6 network interface appropriately and bring it up.
1120 static void
1121 ipv6cp_up(f)
1122 fsm *f;
1124 ipv6cp_options *ho = &ipv6cp_hisoptions[f->unit];
1125 ipv6cp_options *go = &ipv6cp_gotoptions[f->unit];
1126 ipv6cp_options *wo = &ipv6cp_wantoptions[f->unit];
1128 IPV6CPDEBUG(("ipv6cp: up"));
1131 * We must have a non-zero LL address for both ends of the link.
1133 if (!ho->neg_ifaceid)
1134 ho->hisid = wo->hisid;
1136 if(!no_ifaceid_neg) {
1137 if (eui64_iszero(ho->hisid)) {
1138 error("Could not determine remote LL address");
1139 ipv6cp_close(f->unit, "Could not determine remote LL address");
1140 return;
1142 if (eui64_iszero(go->ourid)) {
1143 error("Could not determine local LL address");
1144 ipv6cp_close(f->unit, "Could not determine local LL address");
1145 return;
1147 if (eui64_equals(go->ourid, ho->hisid)) {
1148 error("local and remote LL addresses are equal");
1149 ipv6cp_close(f->unit, "local and remote LL addresses are equal");
1150 return;
1153 script_setenv("LLLOCAL", llv6_ntoa(go->ourid), 0);
1154 script_setenv("LLREMOTE", llv6_ntoa(ho->hisid), 0);
1156 #ifdef IPV6CP_COMP
1157 /* set tcp compression */
1158 sif6comp(f->unit, ho->neg_vj);
1159 #endif
1162 * If we are doing dial-on-demand, the interface is already
1163 * configured, so we put out any saved-up packets, then set the
1164 * interface to pass IPv6 packets.
1166 if (demand) {
1167 if (! eui64_equals(go->ourid, wo->ourid) ||
1168 ! eui64_equals(ho->hisid, wo->hisid)) {
1169 if (! eui64_equals(go->ourid, wo->ourid))
1170 warn("Local LL address changed to %s",
1171 llv6_ntoa(go->ourid));
1172 if (! eui64_equals(ho->hisid, wo->hisid))
1173 warn("Remote LL address changed to %s",
1174 llv6_ntoa(ho->hisid));
1175 ipv6cp_clear_addrs(f->unit, go->ourid, ho->hisid);
1177 /* Set the interface to the new addresses */
1178 if (!sif6addr(f->unit, go->ourid, ho->hisid)) {
1179 if (debug)
1180 warn("sif6addr failed");
1181 ipv6cp_close(f->unit, "Interface configuration failed");
1182 return;
1186 demand_rexmit(PPP_IPV6);
1187 sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
1189 } else {
1191 * Set LL addresses
1193 #if !defined(__linux__) && !defined(SOL2) && !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1194 if (!sif6addr(f->unit, go->ourid, ho->hisid)) {
1195 if (debug)
1196 warn("sif6addr failed");
1197 ipv6cp_close(f->unit, "Interface configuration failed");
1198 return;
1200 #endif
1202 /* bring the interface up for IPv6 */
1203 #if defined(SOL2)
1204 if (!sif6up(f->unit)) {
1205 if (debug)
1206 warn("sifup failed (IPV6)");
1207 ipv6cp_close(f->unit, "Interface configuration failed");
1208 return;
1210 #else
1211 if (!sifup(f->unit)) {
1212 if (debug)
1213 warn("sifup failed (IPV6)");
1214 ipv6cp_close(f->unit, "Interface configuration failed");
1215 return;
1217 #endif /* defined(SOL2) */
1219 #if defined(__linux__) || defined(SOL2) || (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
1220 if (!sif6addr(f->unit, go->ourid, ho->hisid)) {
1221 if (debug)
1222 warn("sif6addr failed");
1223 ipv6cp_close(f->unit, "Interface configuration failed");
1224 return;
1226 #endif
1227 sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
1229 notice("local LL address %s", llv6_ntoa(go->ourid));
1230 notice("remote LL address %s", llv6_ntoa(ho->hisid));
1233 np_up(f->unit, PPP_IPV6);
1234 ipv6cp_is_up = 1;
1237 * Execute the ipv6-up script, like this:
1238 * /etc/ppp/ipv6-up interface tty speed local-LL remote-LL
1240 if (ipv6cp_script_state == s_down && ipv6cp_script_pid == 0) {
1241 ipv6cp_script_state = s_up;
1242 ipv6cp_script(_PATH_IPV6UP);
1248 * ipv6cp_down - IPV6CP has gone DOWN.
1250 * Take the IPv6 network interface down, clear its addresses
1251 * and delete routes through it.
1253 static void
1254 ipv6cp_down(f)
1255 fsm *f;
1257 IPV6CPDEBUG(("ipv6cp: down"));
1258 update_link_stats(f->unit);
1259 if (ipv6cp_is_up) {
1260 ipv6cp_is_up = 0;
1261 np_down(f->unit, PPP_IPV6);
1263 #ifdef IPV6CP_COMP
1264 sif6comp(f->unit, 0);
1265 #endif
1268 * If we are doing dial-on-demand, set the interface
1269 * to queue up outgoing packets (for now).
1271 if (demand) {
1272 sifnpmode(f->unit, PPP_IPV6, NPMODE_QUEUE);
1273 } else {
1274 sifnpmode(f->unit, PPP_IPV6, NPMODE_DROP);
1275 #if !defined(__linux__) && !(defined(SVR4) && (defined(SNI) || defined(__USLC)))
1276 #if defined(SOL2)
1277 sif6down(f->unit);
1278 #else
1279 sifdown(f->unit);
1280 #endif /* defined(SOL2) */
1281 #endif
1282 ipv6cp_clear_addrs(f->unit,
1283 ipv6cp_gotoptions[f->unit].ourid,
1284 ipv6cp_hisoptions[f->unit].hisid);
1285 #if defined(__linux__) || (defined(SVR4) && (defined(SNI) || defined(__USLC)))
1286 sifdown(f->unit);
1287 #endif
1290 /* Execute the ipv6-down script */
1291 if (ipv6cp_script_state == s_up && ipv6cp_script_pid == 0) {
1292 ipv6cp_script_state = s_down;
1293 ipv6cp_script(_PATH_IPV6DOWN);
1299 * ipv6cp_clear_addrs() - clear the interface addresses, routes,
1300 * proxy neighbour discovery entries, etc.
1302 static void
1303 ipv6cp_clear_addrs(unit, ourid, hisid)
1304 int unit;
1305 eui64_t ourid;
1306 eui64_t hisid;
1308 cif6addr(unit, ourid, hisid);
1313 * ipv6cp_finished - possibly shut down the lower layers.
1315 static void
1316 ipv6cp_finished(f)
1317 fsm *f;
1319 np_finished(f->unit, PPP_IPV6);
1324 * ipv6cp_script_done - called when the ipv6-up or ipv6-down script
1325 * has finished.
1327 static void
1328 ipv6cp_script_done(arg)
1329 void *arg;
1331 ipv6cp_script_pid = 0;
1332 switch (ipv6cp_script_state) {
1333 case s_up:
1334 if (ipv6cp_fsm[0].state != OPENED) {
1335 ipv6cp_script_state = s_down;
1336 ipv6cp_script(_PATH_IPV6DOWN);
1338 break;
1339 case s_down:
1340 if (ipv6cp_fsm[0].state == OPENED) {
1341 ipv6cp_script_state = s_up;
1342 ipv6cp_script(_PATH_IPV6UP);
1344 break;
1350 * ipv6cp_script - Execute a script with arguments
1351 * interface-name tty-name speed local-LL remote-LL.
1353 static void
1354 ipv6cp_script(script)
1355 char *script;
1357 char strspeed[32], strlocal[32], strremote[32];
1358 char *argv[8];
1360 sprintf(strspeed, "%d", baud_rate);
1361 strcpy(strlocal, llv6_ntoa(ipv6cp_gotoptions[0].ourid));
1362 strcpy(strremote, llv6_ntoa(ipv6cp_hisoptions[0].hisid));
1364 argv[0] = script;
1365 argv[1] = ifname;
1366 argv[2] = devnam;
1367 argv[3] = strspeed;
1368 argv[4] = strlocal;
1369 argv[5] = strremote;
1370 argv[6] = ipparam;
1371 argv[7] = NULL;
1373 ipv6cp_script_pid = run_program(script, argv, 0, ipv6cp_script_done, NULL);
1377 * ipv6cp_printpkt - print the contents of an IPV6CP packet.
1379 static char *ipv6cp_codenames[] = {
1380 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1381 "TermReq", "TermAck", "CodeRej"
1384 static int
1385 ipv6cp_printpkt(p, plen, printer, arg)
1386 u_char *p;
1387 int plen;
1388 void (*printer) __P((void *, char *, ...));
1389 void *arg;
1391 int code, id, len, olen;
1392 u_char *pstart, *optend;
1393 u_short cishort;
1394 eui64_t ifaceid;
1396 if (plen < HEADERLEN)
1397 return 0;
1398 pstart = p;
1399 GETCHAR(code, p);
1400 GETCHAR(id, p);
1401 GETSHORT(len, p);
1402 if (len < HEADERLEN || len > plen)
1403 return 0;
1405 if (code >= 1 && code <= sizeof(ipv6cp_codenames) / sizeof(char *))
1406 printer(arg, " %s", ipv6cp_codenames[code-1]);
1407 else
1408 printer(arg, " code=0x%x", code);
1409 printer(arg, " id=0x%x", id);
1410 len -= HEADERLEN;
1411 switch (code) {
1412 case CONFREQ:
1413 case CONFACK:
1414 case CONFNAK:
1415 case CONFREJ:
1416 /* print option list */
1417 while (len >= 2) {
1418 GETCHAR(code, p);
1419 GETCHAR(olen, p);
1420 p -= 2;
1421 if (olen < 2 || olen > len) {
1422 break;
1424 printer(arg, " <");
1425 len -= olen;
1426 optend = p + olen;
1427 switch (code) {
1428 case CI_COMPRESSTYPE:
1429 if (olen >= CILEN_COMPRESS) {
1430 p += 2;
1431 GETSHORT(cishort, p);
1432 printer(arg, "compress ");
1433 printer(arg, "0x%x", cishort);
1435 break;
1436 case CI_IFACEID:
1437 if (olen == CILEN_IFACEID) {
1438 p += 2;
1439 eui64_get(ifaceid, p);
1440 printer(arg, "addr %s", llv6_ntoa(ifaceid));
1442 break;
1444 while (p < optend) {
1445 GETCHAR(code, p);
1446 printer(arg, " %.2x", code);
1448 printer(arg, ">");
1450 break;
1452 case TERMACK:
1453 case TERMREQ:
1454 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1455 printer(arg, " ");
1456 print_string((char *)p, len, printer, arg);
1457 p += len;
1458 len = 0;
1460 break;
1463 /* print the rest of the bytes in the packet */
1464 for (; len > 0; --len) {
1465 GETCHAR(code, p);
1466 printer(arg, " %.2x", code);
1469 return p - pstart;
1473 * ipv6_active_pkt - see if this IP packet is worth bringing the link up for.
1474 * We don't bring the link up for IP fragments or for TCP FIN packets
1475 * with no data.
1477 #define IP6_HDRLEN 40 /* bytes */
1478 #define IP6_NHDR_FRAG 44 /* fragment IPv6 header */
1479 #define TCP_HDRLEN 20
1480 #define TH_FIN 0x01
1483 * We use these macros because the IP header may be at an odd address,
1484 * and some compilers might use word loads to get th_off or ip_hl.
1487 #define get_ip6nh(x) (((unsigned char *)(x))[6])
1488 #define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
1489 #define get_tcpflags(x) (((unsigned char *)(x))[13])
1491 static int
1492 ipv6_active_pkt(pkt, len)
1493 u_char *pkt;
1494 int len;
1496 u_char *tcp;
1498 len -= PPP_HDRLEN;
1499 pkt += PPP_HDRLEN;
1500 if (len < IP6_HDRLEN)
1501 return 0;
1502 if (get_ip6nh(pkt) == IP6_NHDR_FRAG)
1503 return 0;
1504 if (get_ip6nh(pkt) != IPPROTO_TCP)
1505 return 1;
1506 if (len < IP6_HDRLEN + TCP_HDRLEN)
1507 return 0;
1508 tcp = pkt + IP6_HDRLEN;
1509 if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == IP6_HDRLEN + get_tcpoff(tcp) * 4)
1510 return 0;
1511 return 1;