]> git.ozlabs.org Git - ppp.git/blob - pppd/ipxcp.c
don't call np_down unless np_up has been called
[ppp.git] / pppd / ipxcp.c
1 /*
2  * ipxcp.c - PPP IPX Control Protocol.
3  *
4  * Copyright (c) 1989 Carnegie Mellon University.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted
8  * provided that the above copyright notice and this paragraph are
9  * duplicated in all such forms and that any documentation,
10  * advertising materials, and other materials related to such
11  * distribution and use acknowledge that the software was developed
12  * by Carnegie Mellon University.  The name of the
13  * University may not be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  */
19
20 #ifdef IPX_CHANGE
21 #ifndef lint
22 static char rcsid[] = "$Id: ipxcp.c,v 1.11 1999/03/16 04:00:53 paulus Exp $";
23 #endif
24
25 /*
26  * TODO:
27  */
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <unistd.h>
32 #include <ctype.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36
37 #include "pppd.h"
38 #include "fsm.h"
39 #include "ipxcp.h"
40 #include "pathnames.h"
41 #include "magic.h"
42
43 /* global vars */
44 ipxcp_options ipxcp_wantoptions[NUM_PPP];       /* Options that we want to request */
45 ipxcp_options ipxcp_gotoptions[NUM_PPP];        /* Options that peer ack'd */
46 ipxcp_options ipxcp_allowoptions[NUM_PPP];      /* Options we allow peer to request */
47 ipxcp_options ipxcp_hisoptions[NUM_PPP];        /* Options that we ack'd */
48
49 #define wo (&ipxcp_wantoptions[0])
50 #define ao (&ipxcp_allowoptions[0])
51 #define go (&ipxcp_gotoptions[0])
52 #define ho (&ipxcp_hisoptions[0])
53
54 /*
55  * Callbacks for fsm code.  (CI = Configuration Information)
56  */
57 static void ipxcp_resetci __P((fsm *)); /* Reset our CI */
58 static int  ipxcp_cilen __P((fsm *));           /* Return length of our CI */
59 static void ipxcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
60 static int  ipxcp_ackci __P((fsm *, u_char *, int));    /* Peer ack'd our CI */
61 static int  ipxcp_nakci __P((fsm *, u_char *, int));    /* Peer nak'd our CI */
62 static int  ipxcp_rejci __P((fsm *, u_char *, int));    /* Peer rej'd our CI */
63 static int  ipxcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
64 static void ipxcp_up __P((fsm *));              /* We're UP */
65 static void ipxcp_down __P((fsm *));            /* We're DOWN */
66 static void ipxcp_finished __P((fsm *));        /* Don't need lower layer */
67 static void ipxcp_script __P((fsm *, char *)); /* Run an up/down script */
68
69 fsm ipxcp_fsm[NUM_PPP];         /* IPXCP fsm structure */
70
71 static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */
72     ipxcp_resetci,              /* Reset our Configuration Information */
73     ipxcp_cilen,                /* Length of our Configuration Information */
74     ipxcp_addci,                /* Add our Configuration Information */
75     ipxcp_ackci,                /* ACK our Configuration Information */
76     ipxcp_nakci,                /* NAK our Configuration Information */
77     ipxcp_rejci,                /* Reject our Configuration Information */
78     ipxcp_reqci,                /* Request peer's Configuration Information */
79     ipxcp_up,                   /* Called when fsm reaches OPENED state */
80     ipxcp_down,                 /* Called when fsm leaves OPENED state */
81     NULL,                       /* Called when we want the lower layer up */
82     ipxcp_finished,             /* Called when we want the lower layer down */
83     NULL,                       /* Called when Protocol-Reject received */
84     NULL,                       /* Retransmission is necessary */
85     NULL,                       /* Called to handle protocol-specific codes */
86     "IPXCP"                     /* String name of protocol */
87 };
88
89 /*
90  * Command-line options.
91  */
92 static int setipxnode __P((char **));
93 static int setipxname __P((char **));
94
95 static option_t ipxcp_option_list[] = {
96     { "ipx", o_bool, &ipxcp_protent.enabled_flag,
97       "Enable IPXCP (and IPX)", 1 },
98     { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
99       "Enable IPXCP (and IPX)", 1 },
100     { "noipx", o_bool, &ipxcp_protent.enabled_flag,
101       "Disable IPXCP (and IPX)" },
102     { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
103       "Disable IPXCP (and IPX)" } ,
104     { "ipx-network", o_int, &ipxcp_wantoptions[0].our_network,
105       "Set our IPX network number", 0, &ipxcp_wantoptions[0].neg_nn },
106     { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
107       "Accept peer IPX network number", 1,
108       &ipxcp_allowoptions[0].accept_network },
109     { "ipx-node", o_special, setipxnode,
110       "Set IPX node number" },
111     { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
112       "Accept our IPX address", 1,
113       &ipxcp_allowoptions[0].accept_local },
114     { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
115       "Accept peer's IPX address", 1,
116       &ipxcp_allowoptions[0].accept_remote },
117     { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
118       "Set IPX routing proto number", 0,
119       &ipxcp_wantoptions[0].neg_router },
120     { "ipx-router-name", o_special, setipxname,
121       "Set IPX router name" },
122     { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
123       "Set timeout for IPXCP" },
124     { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
125       "Set max #xmits for IPXCP term-reqs" },
126     { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
127       "Set max #xmits for IPXCP conf-reqs" },
128     { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
129       "Set max #conf-naks for IPXCP" },
130     { NULL }
131 };
132
133 /*
134  * Protocol entry points.
135  */
136
137 static void ipxcp_init __P((int));
138 static void ipxcp_open __P((int));
139 static void ipxcp_close __P((int, char *));
140 static void ipxcp_lowerup __P((int));
141 static void ipxcp_lowerdown __P((int));
142 static void ipxcp_input __P((int, u_char *, int));
143 static void ipxcp_protrej __P((int));
144 static int  ipxcp_printpkt __P((u_char *, int,
145                                 void (*) __P((void *, char *, ...)), void *));
146
147 struct protent ipxcp_protent = {
148     PPP_IPXCP,
149     ipxcp_init,
150     ipxcp_input,
151     ipxcp_protrej,
152     ipxcp_lowerup,
153     ipxcp_lowerdown,
154     ipxcp_open,
155     ipxcp_close,
156     ipxcp_printpkt,
157     NULL,
158     0,
159     "IPXCP",
160     ipxcp_option_list,
161     NULL,
162     NULL,
163     NULL
164 };
165
166 /*
167  * Lengths of configuration options.
168  */
169
170 #define CILEN_VOID      2
171 #define CILEN_COMPLETE  2       /* length of complete option */
172 #define CILEN_NETN      6       /* network number length option */
173 #define CILEN_NODEN     8       /* node number length option */
174 #define CILEN_PROTOCOL  4       /* Minimum length of routing protocol */
175 #define CILEN_NAME      3       /* Minimum length of router name */
176 #define CILEN_COMPRESS  4       /* Minimum length of compression protocol */
177
178 #define CODENAME(x)     ((x) == CONFACK ? "ACK" : \
179                          (x) == CONFNAK ? "NAK" : "REJ")
180
181 static int ipxcp_is_up;
182
183 /* Used in printing the node number */
184 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
185
186 /* Used to generate the proper bit mask */
187 #define BIT(num)   (1 << (num))
188
189 /*
190  * Convert from internal to external notation
191  */
192
193 static short int
194 to_external(internal)
195 short int internal;
196 {
197     short int  external;
198
199     if (internal & IPX_NONE)
200         external = IPX_NONE;
201     else
202         external = RIP_SAP;
203
204     return external;
205 }
206
207 /*
208  * Make a string representation of a network IP address.
209  */
210
211 char *
212 ipx_ntoa(ipxaddr)
213 u_int32_t ipxaddr;
214 {
215     static char b[64];
216     slprintf(b, sizeof(b), "%x", ipxaddr);
217     return b;
218 }
219
220
221 static u_char *
222 setipxnodevalue(src,dst)
223 u_char *src, *dst;
224 {
225     int indx;
226     int item;
227
228     for (;;) {
229         if (!isxdigit (*src))
230             break;
231         
232         for (indx = 0; indx < 5; ++indx) {
233             dst[indx] <<= 4;
234             dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
235         }
236
237         item = toupper (*src) - '0';
238         if (item > 9)
239             item -= 7;
240
241         dst[5] = (dst[5] << 4) | item;
242         ++src;
243     }
244     return src;
245 }
246
247 static int
248 setipxnode(argv)
249     char **argv;
250 {
251     char *end;
252
253     memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
254     memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
255
256     end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
257     if (*end == ':')
258         end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
259
260     if (*end == '\0') {
261         ipxcp_wantoptions[0].neg_node = 1;
262         return 1;
263     }
264
265     option_error("invalid parameter '%s' for ipx-node option", *argv);
266     return 0;
267 }
268
269 static int
270 setipxname (argv)
271     char **argv;
272 {
273     char *dest = ipxcp_wantoptions[0].name;
274     char *src  = *argv;
275     int  count;
276     char ch;
277
278     ipxcp_wantoptions[0].neg_name  = 1;
279     ipxcp_allowoptions[0].neg_name = 1;
280     memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
281
282     count = 0;
283     while (*src) {
284         ch = *src++;
285         if (! isalnum (ch) && ch != '_') {
286             option_error("IPX router name must be alphanumeric or _");
287             return 0;
288         }
289
290         if (count >= sizeof (ipxcp_wantoptions[0].name)) {
291             option_error("IPX router name is limited to %d characters",
292                          sizeof (ipxcp_wantoptions[0].name) - 1);
293             return 0;
294         }
295
296         dest[count++] = toupper (ch);
297     }
298
299     return 1;
300 }
301
302 /*
303  * ipxcp_init - Initialize IPXCP.
304  */
305 static void
306 ipxcp_init(unit)
307     int unit;
308 {
309     fsm *f = &ipxcp_fsm[unit];
310
311     f->unit      = unit;
312     f->protocol  = PPP_IPXCP;
313     f->callbacks = &ipxcp_callbacks;
314     fsm_init(&ipxcp_fsm[unit]);
315
316     memset (wo->name,     0, sizeof (wo->name));
317     memset (wo->our_node, 0, sizeof (wo->our_node));
318     memset (wo->his_node, 0, sizeof (wo->his_node));
319
320     wo->neg_nn         = 1;
321     wo->neg_complete   = 1;
322     wo->network        = 0;
323
324     ao->neg_node       = 1;
325     ao->neg_nn         = 1;
326     ao->neg_name       = 1;
327     ao->neg_complete   = 1;
328     ao->neg_router     = 1;
329
330     ao->accept_local   = 0;
331     ao->accept_remote  = 0;
332     ao->accept_network = 0;
333
334     wo->tried_rip      = 0;
335     wo->tried_nlsp     = 0;
336 }
337
338 /*
339  * Copy the node number
340  */
341
342 static void
343 copy_node (src, dst)
344 u_char *src, *dst;
345 {
346     memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
347 }
348
349 /*
350  * Compare node numbers
351  */
352
353 static int
354 compare_node (src, dst)
355 u_char *src, *dst;
356 {
357     return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
358 }
359
360 /*
361  * Is the node number zero?
362  */
363
364 static int
365 zero_node (node)
366 u_char *node;
367 {
368     int indx;
369     for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
370         if (node [indx] != 0)
371             return 0;
372     return 1;
373 }
374
375 /*
376  * Increment the node number
377  */
378
379 static void
380 inc_node (node)
381 u_char *node;
382 {
383     u_char   *outp;
384     u_int32_t magic_num;
385
386     outp      = node;
387     magic_num = magic();
388     *outp++   = '\0';
389     *outp++   = '\0';
390     PUTLONG (magic_num, outp);
391 }
392
393 /*
394  * ipxcp_open - IPXCP is allowed to come up.
395  */
396 static void
397 ipxcp_open(unit)
398     int unit;
399 {
400     fsm_open(&ipxcp_fsm[unit]);
401 }
402
403 /*
404  * ipxcp_close - Take IPXCP down.
405  */
406 static void
407 ipxcp_close(unit, reason)
408     int unit;
409     char *reason;
410 {
411     fsm_close(&ipxcp_fsm[unit], reason);
412 }
413
414
415 /*
416  * ipxcp_lowerup - The lower layer is up.
417  */
418 static void
419 ipxcp_lowerup(unit)
420     int unit;
421 {
422     fsm_lowerup(&ipxcp_fsm[unit]);
423 }
424
425
426 /*
427  * ipxcp_lowerdown - The lower layer is down.
428  */
429 static void
430 ipxcp_lowerdown(unit)
431     int unit;
432 {
433     fsm_lowerdown(&ipxcp_fsm[unit]);
434 }
435
436
437 /*
438  * ipxcp_input - Input IPXCP packet.
439  */
440 static void
441 ipxcp_input(unit, p, len)
442     int unit;
443     u_char *p;
444     int len;
445 {
446     fsm_input(&ipxcp_fsm[unit], p, len);
447 }
448
449
450 /*
451  * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
452  *
453  * Pretend the lower layer went down, so we shut up.
454  */
455 static void
456 ipxcp_protrej(unit)
457     int unit;
458 {
459     fsm_lowerdown(&ipxcp_fsm[unit]);
460 }
461
462
463 /*
464  * ipxcp_resetci - Reset our CI.
465  */
466 static void
467 ipxcp_resetci(f)
468     fsm *f;
469 {
470     wo->req_node = wo->neg_node && ao->neg_node;
471     wo->req_nn   = wo->neg_nn   && ao->neg_nn;
472
473     if (wo->our_network == 0) {
474         wo->neg_node       = 1;
475         ao->accept_network = 1;
476     }
477 /*
478  * If our node number is zero then change it.
479  */
480     if (zero_node (wo->our_node)) {
481         inc_node (wo->our_node);
482         ao->accept_local = 1;
483         wo->neg_node     = 1;
484     }
485 /*
486  * If his node number is zero then change it.
487  */
488     if (zero_node (wo->his_node)) {
489         inc_node (wo->his_node);
490         ao->accept_remote = 1;
491     }
492 /*
493  * If no routing agent was specified then we do RIP/SAP according to the
494  * RFC documents. If you have specified something then OK. Otherwise, we
495  * do RIP/SAP.
496  */
497     if (ao->router == 0) {
498         ao->router |= BIT(RIP_SAP);
499         wo->router |= BIT(RIP_SAP);
500     }
501
502     /* Always specify a routing protocol unless it was REJected. */
503     wo->neg_router = 1;
504 /*
505  * Start with these default values
506  */
507     *go = *wo;
508 }
509
510 /*
511  * ipxcp_cilen - Return length of our CI.
512  */
513
514 static int
515 ipxcp_cilen(f)
516     fsm *f;
517 {
518     int len;
519
520     len  = go->neg_nn       ? CILEN_NETN     : 0;
521     len += go->neg_node     ? CILEN_NODEN    : 0;
522     len += go->neg_name     ? CILEN_NAME + strlen (go->name) - 1 : 0;
523
524     /* RFC says that defaults should not be included. */
525     if (go->neg_router && to_external(go->router) != RIP_SAP)
526         len += CILEN_PROTOCOL;
527
528     return (len);
529 }
530
531
532 /*
533  * ipxcp_addci - Add our desired CIs to a packet.
534  */
535 static void
536 ipxcp_addci(f, ucp, lenp)
537     fsm *f;
538     u_char *ucp;
539     int *lenp;
540 {
541 /*
542  * Add the options to the record.
543  */
544     if (go->neg_nn) {
545         PUTCHAR (IPX_NETWORK_NUMBER, ucp);
546         PUTCHAR (CILEN_NETN, ucp);
547         PUTLONG (go->our_network, ucp);
548     }
549
550     if (go->neg_node) {
551         int indx;
552         PUTCHAR (IPX_NODE_NUMBER, ucp);
553         PUTCHAR (CILEN_NODEN, ucp);
554         for (indx = 0; indx < sizeof (go->our_node); ++indx)
555             PUTCHAR (go->our_node[indx], ucp);
556     }
557
558     if (go->neg_name) {
559         int cilen = strlen (go->name);
560         int indx;
561         PUTCHAR (IPX_ROUTER_NAME, ucp);
562         PUTCHAR (CILEN_NAME + cilen - 1, ucp);
563         for (indx = 0; indx < cilen; ++indx)
564             PUTCHAR (go->name [indx], ucp);
565     }
566
567     if (go->neg_router) {
568         short external = to_external (go->router);
569         if (external != RIP_SAP) {
570             PUTCHAR  (IPX_ROUTER_PROTOCOL, ucp);
571             PUTCHAR  (CILEN_PROTOCOL,      ucp);
572             PUTSHORT (external,            ucp);
573         }
574     }
575 }
576
577 /*
578  * ipxcp_ackci - Ack our CIs.
579  *
580  * Returns:
581  *      0 - Ack was bad.
582  *      1 - Ack was good.
583  */
584 static int
585 ipxcp_ackci(f, p, len)
586     fsm *f;
587     u_char *p;
588     int len;
589 {
590     u_short cilen, citype, cishort;
591     u_char cichar;
592     u_int32_t cilong;
593
594 #define ACKCIVOID(opt, neg) \
595     if (neg) { \
596         if ((len -= CILEN_VOID) < 0) \
597             break; \
598         GETCHAR(citype, p); \
599         GETCHAR(cilen, p); \
600         if (cilen != CILEN_VOID || \
601             citype != opt) \
602             break; \
603     }
604
605 #define ACKCICOMPLETE(opt,neg)  ACKCIVOID(opt, neg)
606
607 #define ACKCICHARS(opt, neg, val, cnt) \
608     if (neg) { \
609         int indx, count = cnt; \
610         len -= (count + 2); \
611         if (len < 0) \
612             break; \
613         GETCHAR(citype, p); \
614         GETCHAR(cilen, p); \
615         if (cilen != (count + 2) || \
616             citype != opt) \
617             break; \
618         for (indx = 0; indx < count; ++indx) {\
619             GETCHAR(cichar, p); \
620             if (cichar != ((u_char *) &val)[indx]) \
621                break; \
622         }\
623         if (indx != count) \
624             break; \
625     }
626
627 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
628 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen(val))
629
630 #define ACKCINETWORK(opt, neg, val) \
631     if (neg) { \
632         if ((len -= CILEN_NETN) < 0) \
633             break; \
634         GETCHAR(citype, p); \
635         GETCHAR(cilen, p); \
636         if (cilen != CILEN_NETN || \
637             citype != opt) \
638             break; \
639         GETLONG(cilong, p); \
640         if (cilong != val) \
641             break; \
642     }
643
644 #define ACKCIPROTO(opt, neg, val) \
645     if (neg) { \
646         if (len < 2) \
647             break; \
648         GETCHAR(citype, p); \
649         GETCHAR(cilen, p); \
650         if (cilen != CILEN_PROTOCOL || citype != opt) \
651             break; \
652         len -= cilen; \
653         if (len < 0) \
654             break; \
655         GETSHORT(cishort, p); \
656         if (cishort != to_external (val) || cishort == RIP_SAP) \
657             break; \
658       }
659 /*
660  * Process the ACK frame in the order in which the frame was assembled
661  */
662     do {
663         ACKCINETWORK  (IPX_NETWORK_NUMBER,  go->neg_nn,     go->our_network);
664         ACKCINODE     (IPX_NODE_NUMBER,     go->neg_node,   go->our_node);
665         ACKCINAME     (IPX_ROUTER_NAME,     go->neg_name,   go->name);
666         ACKCIPROTO    (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
667         ACKCIPROTO    (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
668         ACKCIPROTO    (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
669 /*
670  * This is the end of the record.
671  */
672         if (len == 0)
673             return (1);
674     } while (0);
675 /*
676  * The frame is invalid
677  */
678     IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
679     return (0);
680 }
681
682 /*
683  * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
684  * This should not modify any state if the Nak is bad
685  * or if IPXCP is in the OPENED state.
686  *
687  * Returns:
688  *      0 - Nak was bad.
689  *      1 - Nak was good.
690  */
691
692 static int
693 ipxcp_nakci(f, p, len)
694     fsm *f;
695     u_char *p;
696     int len;
697 {
698     u_char citype, cilen, *next;
699     u_short s;
700     u_int32_t l;
701     ipxcp_options no;           /* options we've seen Naks for */
702     ipxcp_options try;          /* options to request next time */
703
704     BZERO(&no, sizeof(no));
705     try = *go;
706
707     while (len > CILEN_VOID) {
708         GETCHAR (citype, p);
709         GETCHAR (cilen,  p);
710         len -= cilen;
711         if (len < 0)
712             goto bad;
713         next = &p [cilen - CILEN_VOID];
714
715         switch (citype) {
716         case IPX_NETWORK_NUMBER:
717             if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
718                 goto bad;
719             no.neg_nn = 1;
720
721             GETLONG(l, p);
722             if (l && ao->accept_network)
723                 try.our_network = l;
724             break;
725
726         case IPX_NODE_NUMBER:
727             if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
728                 goto bad;
729             no.neg_node = 1;
730
731             if (!zero_node (p) && ao->accept_local &&
732                 ! compare_node (p, ho->his_node))
733                 copy_node (p, try.our_node);
734             break;
735
736             /* This has never been sent. Ignore the NAK frame */
737         case IPX_COMPRESSION_PROTOCOL:
738             goto bad;
739
740         case IPX_ROUTER_PROTOCOL:
741             if (!go->neg_router || (cilen < CILEN_PROTOCOL))
742                 goto bad;
743
744             GETSHORT (s, p);
745             if (s > 15)         /* This is just bad, but ignore for now. */
746                 break;
747
748             s = BIT(s);
749             if (no.router & s)  /* duplicate NAKs are always bad */
750                 goto bad;
751
752             if (no.router == 0) /* Reset on first NAK only */
753                 try.router = 0;
754
755             no.router      |= s;
756             try.router     |= s;
757             try.neg_router  = 1;
758             break;
759
760             /* These, according to the RFC, must never be NAKed. */
761         case IPX_ROUTER_NAME:
762         case IPX_COMPLETE:
763             goto bad;
764
765             /* These are for options which we have not seen. */
766         default:
767             break;
768         }
769         p = next;
770     }
771
772     /* If there is still anything left, this packet is bad. */
773     if (len != 0)
774         goto bad;
775
776     /*
777      * Do not permit the peer to force a router protocol which we do not
778      * support. However, default to the condition that will accept "NONE".
779      */
780     try.router &= (ao->router | BIT(IPX_NONE));
781     if (try.router == 0 && ao->router != 0)
782         try.router = BIT(IPX_NONE);
783
784     if (try.router != 0)
785         try.neg_router = 1;
786     
787     /*
788      * OK, the Nak is good.  Now we can update state.
789      */
790     if (f->state != OPENED)
791         *go = try;
792
793     return 1;
794
795 bad:
796     IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
797     return 0;
798 }
799
800 /*
801  * ipxcp_rejci - Reject some of our CIs.
802  */
803 static int
804 ipxcp_rejci(f, p, len)
805     fsm *f;
806     u_char *p;
807     int len;
808 {
809     u_short cilen, citype, cishort;
810     u_char cichar;
811     u_int32_t cilong;
812     ipxcp_options try;          /* options to request next time */
813
814 #define REJCINETWORK(opt, neg, val) \
815     if (neg && p[0] == opt) { \
816         if ((len -= CILEN_NETN) < 0) \
817             break; \
818         GETCHAR(citype, p); \
819         GETCHAR(cilen, p); \
820         if (cilen != CILEN_NETN || \
821             citype != opt) \
822             break; \
823         GETLONG(cilong, p); \
824         if (cilong != val) \
825             break; \
826         neg = 0; \
827     }
828
829 #define REJCICHARS(opt, neg, val, cnt) \
830     if (neg && p[0] == opt) { \
831         int indx, count = cnt; \
832         len -= (count + 2); \
833         if (len < 0) \
834             break; \
835         GETCHAR(citype, p); \
836         GETCHAR(cilen, p); \
837         if (cilen != (count + 2) || \
838             citype != opt) \
839             break; \
840         for (indx = 0; indx < count; ++indx) {\
841             GETCHAR(cichar, p); \
842             if (cichar != ((u_char *) &val)[indx]) \
843                break; \
844         }\
845         if (indx != count) \
846             break; \
847         neg = 0; \
848     }
849
850 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
851 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen(val))
852
853 #define REJCIVOID(opt, neg) \
854     if (neg && p[0] == opt) { \
855         if ((len -= CILEN_VOID) < 0) \
856             break; \
857         GETCHAR(citype, p); \
858         GETCHAR(cilen, p); \
859         if (cilen != CILEN_VOID || citype != opt) \
860             break; \
861         neg = 0; \
862     }
863
864 /* a reject for RIP/SAP is invalid since we don't send it and you can't
865    reject something which is not sent. (You can NAK, but you can't REJ.) */
866 #define REJCIPROTO(opt, neg, val, bit) \
867     if (neg && p[0] == opt) { \
868         if ((len -= CILEN_PROTOCOL) < 0) \
869             break; \
870         GETCHAR(citype, p); \
871         GETCHAR(cilen, p); \
872         if (cilen != CILEN_PROTOCOL) \
873             break; \
874         GETSHORT(cishort, p); \
875         if (cishort != to_external (val) || cishort == RIP_SAP) \
876             break; \
877         neg = 0; \
878     }
879 /*
880  * Any Rejected CIs must be in exactly the same order that we sent.
881  * Check packet length and CI length at each step.
882  * If we find any deviations, then this packet is bad.
883  */
884     try = *go;
885
886     do {
887         REJCINETWORK (IPX_NETWORK_NUMBER,  try.neg_nn,     try.our_network);
888         REJCINODE    (IPX_NODE_NUMBER,     try.neg_node,   try.our_node);
889         REJCINAME    (IPX_ROUTER_NAME,     try.neg_name,   try.name);
890         REJCIPROTO   (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
891 /*
892  * This is the end of the record.
893  */
894         if (len == 0) {
895             if (f->state != OPENED)
896                 *go = try;
897             return (1);
898         }
899     } while (0);
900 /*
901  * The frame is invalid at this point.
902  */
903     IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
904     return 0;
905 }
906
907 /*
908  * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
909  *
910  * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
911  * appropriately.  If reject_if_disagree is non-zero, doesn't return
912  * CONFNAK; returns CONFREJ if it can't return CONFACK.
913  */
914 static int
915 ipxcp_reqci(f, inp, len, reject_if_disagree)
916     fsm *f;
917     u_char *inp;                /* Requested CIs */
918     int *len;                   /* Length of requested CIs */
919     int reject_if_disagree;
920 {
921     u_char *cip, *next;         /* Pointer to current and next CIs */
922     u_short cilen, citype;      /* Parsed len, type */
923     u_short cishort;            /* Parsed short value */
924     u_int32_t cinetwork;        /* Parsed address values */
925     int rc = CONFACK;           /* Final packet return code */
926     int orc;                    /* Individual option return code */
927     u_char *p;                  /* Pointer to next char to parse */
928     u_char *ucp = inp;          /* Pointer to current output char */
929     int l = *len;               /* Length left */
930
931     /*
932      * Reset all his options.
933      */
934     BZERO(ho, sizeof(*ho));
935     
936     /*
937      * Process all his options.
938      */
939     next = inp;
940     while (l) {
941         orc = CONFACK;                  /* Assume success */
942         cip = p = next;                 /* Remember begining of CI */
943         if (l < 2 ||                    /* Not enough data for CI header or */
944             p[1] < 2 ||                 /*  CI length too small or */
945             p[1] > l) {                 /*  CI length too big? */
946             IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
947             orc = CONFREJ;              /* Reject bad CI */
948             cilen = l;                  /* Reject till end of packet */
949             l = 0;                      /* Don't loop again */
950             goto endswitch;
951         }
952         GETCHAR(citype, p);             /* Parse CI type */
953         GETCHAR(cilen, p);              /* Parse CI length */
954         l -= cilen;                     /* Adjust remaining length */
955         next += cilen;                  /* Step to next CI */
956
957         switch (citype) {               /* Check CI type */
958 /*
959  * The network number must match. Choose the larger of the two.
960  */
961         case IPX_NETWORK_NUMBER:
962             /* if we wont negotiate the network number or the length is wrong
963                then reject the option */
964             if ( !ao->neg_nn || cilen != CILEN_NETN ) {
965                 orc = CONFREJ;
966                 break;          
967             }
968             GETLONG(cinetwork, p);
969
970             /* If the network numbers match then acknowledge them. */
971             if (cinetwork != 0) {
972                 ho->his_network = cinetwork;
973                 ho->neg_nn      = 1;
974                 if (wo->our_network == cinetwork)
975                     break;
976 /*
977  * If the network number is not given or we don't accept their change or
978  * the network number is too small then NAK it.
979  */
980                 if (! ao->accept_network || cinetwork < wo->our_network) {
981                     DECPTR (sizeof (u_int32_t), p);
982                     PUTLONG (wo->our_network, p);
983                     orc = CONFNAK;
984                 }
985                 break;
986             }
987 /*
988  * The peer sent '0' for the network. Give it ours if we have one.
989  */
990             if (go->our_network != 0) {
991                 DECPTR (sizeof (u_int32_t), p);
992                 PUTLONG (wo->our_network, p);
993                 orc = CONFNAK;
994 /*
995  * We don't have one. Reject the value.
996  */
997             } else
998                 orc = CONFREJ;
999
1000             break;
1001 /*
1002  * The node number is required
1003  */
1004         case IPX_NODE_NUMBER:
1005             /* if we wont negotiate the node number or the length is wrong
1006                then reject the option */
1007             if ( cilen != CILEN_NODEN ) {
1008                 orc = CONFREJ;
1009                 break;
1010             }
1011
1012             copy_node (p, ho->his_node);
1013             ho->neg_node = 1;
1014 /*
1015  * If the remote does not have a number and we do then NAK it with the value
1016  * which we have for it. (We never have a default value of zero.)
1017  */
1018             if (zero_node (ho->his_node)) {
1019                 orc = CONFNAK;
1020                 copy_node (wo->his_node, p);
1021                 INCPTR (sizeof (wo->his_node), p);
1022                 break;
1023             }
1024 /*
1025  * If you have given me the expected network node number then I'll accept
1026  * it now.
1027  */
1028             if (compare_node (wo->his_node, ho->his_node)) {
1029                 orc = CONFACK;
1030                 ho->neg_node = 1;
1031                 INCPTR (sizeof (wo->his_node), p);
1032                 break;
1033             }
1034 /*
1035  * If his node number is the same as ours then ask him to try the next
1036  * value.
1037  */
1038             if (compare_node (ho->his_node, go->our_node)) {
1039                 inc_node (ho->his_node);
1040                 orc = CONFNAK;
1041                 copy_node (ho->his_node, p);
1042                 INCPTR (sizeof (wo->his_node), p);
1043                 break;
1044             }
1045 /*
1046  * If we don't accept a new value then NAK it.
1047  */
1048             if (! ao->accept_remote) {
1049                 copy_node (wo->his_node, p);
1050                 INCPTR (sizeof (wo->his_node), p);
1051                 orc = CONFNAK;
1052                 break;
1053             }
1054             orc = CONFACK;
1055             ho->neg_node = 1;
1056             INCPTR (sizeof (wo->his_node), p);
1057             break;
1058 /*
1059  * Compression is not desired at this time. It is always rejected.
1060  */
1061         case IPX_COMPRESSION_PROTOCOL:
1062             orc = CONFREJ;
1063             break;
1064 /*
1065  * The routing protocol is a bitmask of various types. Any combination
1066  * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1067  * routing protocol must be specified only once.
1068  */
1069         case IPX_ROUTER_PROTOCOL:
1070             if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
1071                 orc = CONFREJ;
1072                 break;          
1073             }
1074
1075             GETSHORT (cishort, p);
1076
1077             if (wo->neg_router == 0) {
1078                 wo->neg_router = 1;
1079                 wo->router     = BIT(IPX_NONE);
1080             }
1081
1082             if ((cishort == IPX_NONE && ho->router != 0) ||
1083                 (ho->router & BIT(IPX_NONE))) {
1084                 orc = CONFREJ;
1085                 break;
1086             }
1087
1088             cishort = BIT(cishort);
1089             if (ho->router & cishort) {
1090                 orc = CONFREJ;
1091                 break;
1092             }
1093
1094             ho->router    |= cishort;
1095             ho->neg_router = 1;
1096
1097             /* Finally do not allow a router protocol which we do not
1098                support. */
1099
1100             if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1101                 int protocol;
1102
1103                 if (cishort == BIT(NLSP) &&
1104                     (ao->router & BIT(RIP_SAP)) &&
1105                     !wo->tried_rip) {
1106                     protocol      = RIP_SAP;
1107                     wo->tried_rip = 1;
1108                 } else
1109                     protocol = IPX_NONE;
1110
1111                 DECPTR (sizeof (u_int16_t), p);
1112                 PUTSHORT (protocol, p);
1113                 orc = CONFNAK;
1114             }
1115             break;
1116 /*
1117  * The router name is advisorary. Just accept it if it is not too large.
1118  */
1119         case IPX_ROUTER_NAME:
1120             if (cilen >= CILEN_NAME) {
1121                 int name_size = cilen - CILEN_NAME;
1122                 if (name_size > sizeof (ho->name))
1123                     name_size = sizeof (ho->name) - 1;
1124                 memset (ho->name, 0, sizeof (ho->name));
1125                 memcpy (ho->name, p, name_size);
1126                 ho->name [name_size] = '\0';
1127                 ho->neg_name = 1;
1128                 orc = CONFACK;
1129                 break;
1130             }
1131             orc = CONFREJ;
1132             break;
1133 /*
1134  * This is advisorary.
1135  */
1136         case IPX_COMPLETE:
1137             if (cilen != CILEN_COMPLETE)
1138                 orc = CONFREJ;
1139             else {
1140                 ho->neg_complete = 1;
1141                 orc = CONFACK;
1142             }
1143             break;
1144 /*
1145  * All other entries are not known at this time.
1146  */
1147         default:
1148             orc = CONFREJ;
1149             break;
1150         }
1151 endswitch:
1152         if (orc == CONFACK &&           /* Good CI */
1153             rc != CONFACK)              /*  but prior CI wasnt? */
1154             continue;                   /* Don't send this one */
1155
1156         if (orc == CONFNAK) {           /* Nak this CI? */
1157             if (reject_if_disagree)     /* Getting fed up with sending NAKs? */
1158                 orc = CONFREJ;          /* Get tough if so */
1159             if (rc == CONFREJ)          /* Rejecting prior CI? */
1160                 continue;               /* Don't send this one */
1161             if (rc == CONFACK) {        /* Ack'd all prior CIs? */
1162                 rc  = CONFNAK;          /* Not anymore... */
1163                 ucp = inp;              /* Backup */
1164             }
1165         }
1166
1167         if (orc == CONFREJ &&           /* Reject this CI */
1168             rc != CONFREJ) {            /*  but no prior ones? */
1169             rc = CONFREJ;
1170             ucp = inp;                  /* Backup */
1171         }
1172
1173         /* Need to move CI? */
1174         if (ucp != cip)
1175             BCOPY(cip, ucp, cilen);     /* Move it */
1176
1177         /* Update output pointer */
1178         INCPTR(cilen, ucp);
1179     }
1180
1181     /*
1182      * If we aren't rejecting this packet, and we want to negotiate
1183      * their address, and they didn't send their address, then we
1184      * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1185      * input buffer is long enough that we can append the extra
1186      * option safely.
1187      */
1188
1189     if (rc != CONFREJ && !ho->neg_node &&
1190         wo->req_nn && !reject_if_disagree) {
1191         if (rc == CONFACK) {
1192             rc = CONFNAK;
1193             wo->req_nn = 0;             /* don't ask again */
1194             ucp = inp;                  /* reset pointer */
1195         }
1196
1197         if (zero_node (wo->his_node))
1198             inc_node (wo->his_node);
1199
1200         PUTCHAR (IPX_NODE_NUMBER, ucp);
1201         PUTCHAR (CILEN_NODEN, ucp);
1202         copy_node (wo->his_node, ucp);
1203         INCPTR (sizeof (wo->his_node), ucp);
1204     }
1205
1206     *len = ucp - inp;                   /* Compute output length */
1207     IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));
1208     return (rc);                        /* Return final code */
1209 }
1210
1211 /*
1212  * ipxcp_up - IPXCP has come UP.
1213  *
1214  * Configure the IP network interface appropriately and bring it up.
1215  */
1216
1217 static void
1218 ipxcp_up(f)
1219     fsm *f;
1220 {
1221     int unit = f->unit;
1222
1223     IPXCPDEBUG(("ipxcp: up"));
1224
1225     /* The default router protocol is RIP/SAP. */
1226     if (ho->router == 0)
1227         ho->router = BIT(RIP_SAP);
1228
1229     if (go->router == 0)
1230         go->router = BIT(RIP_SAP);
1231
1232     /* Fetch the network number */
1233     if (!ho->neg_nn)
1234         ho->his_network = wo->his_network;
1235
1236     if (!ho->neg_node)
1237         copy_node (wo->his_node, ho->his_node);
1238
1239     if (!wo->neg_node && !go->neg_node)
1240         copy_node (wo->our_node, go->our_node);
1241
1242     if (zero_node (go->our_node)) {
1243         static char errmsg[] = "Could not determine local IPX node address";
1244         if (debug)
1245             error(errmsg);
1246         ipxcp_close(f->unit, errmsg);
1247         return;
1248     }
1249
1250     go->network = go->our_network;
1251     if (ho->his_network != 0 && ho->his_network > go->network)
1252         go->network = ho->his_network;
1253
1254     if (go->network == 0) {
1255         static char errmsg[] = "Can not determine network number";
1256         if (debug)
1257             error(errmsg);
1258         ipxcp_close (unit, errmsg);
1259         return;
1260     }
1261
1262     /* bring the interface up */
1263     if (!sifup(unit)) {
1264         if (debug)
1265             warn("sifup failed (IPX)");
1266         ipxcp_close(unit, "Interface configuration failed");
1267         return;
1268     }
1269
1270     /* set the network number for IPX */
1271     if (!sipxfaddr(unit, go->network, go->our_node)) {
1272         if (debug)
1273             warn("sipxfaddr failed");
1274         ipxcp_close(unit, "Interface configuration failed");
1275         return;
1276     }
1277
1278     ipxcp_is_up = 1;
1279     np_up(f->unit, PPP_IPX);
1280
1281     /*
1282      * Execute the ipx-up script, like this:
1283      *  /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1284      */
1285
1286     ipxcp_script (f, _PATH_IPXUP);
1287 }
1288
1289 /*
1290  * ipxcp_down - IPXCP has gone DOWN.
1291  *
1292  * Take the IP network interface down, clear its addresses
1293  * and delete routes through it.
1294  */
1295
1296 static void
1297 ipxcp_down(f)
1298     fsm *f;
1299 {
1300     IPXCPDEBUG(("ipxcp: down"));
1301
1302     if (ipxcp_is_up) {
1303         ipxcp_is_up = 0;
1304         np_down(f->unit, PPP_IPX);
1305     }
1306     cipxfaddr (f->unit);
1307     sifdown(f->unit);
1308     ipxcp_script (f, _PATH_IPXDOWN);
1309 }
1310
1311
1312 /*
1313  * ipxcp_finished - possibly shut down the lower layers.
1314  */
1315 static void
1316 ipxcp_finished(f)
1317     fsm *f;
1318 {
1319     np_finished(f->unit, PPP_IPX);
1320 }
1321
1322
1323 /*
1324  * ipxcp_script - Execute a script with arguments
1325  * interface-name tty-name speed local-IPX remote-IPX networks.
1326  */
1327 static void
1328 ipxcp_script(f, script)
1329     fsm *f;
1330     char *script;
1331 {
1332     char strspeed[32],   strlocal[32],     strremote[32];
1333     char strnetwork[32], strpid[32];
1334     char *argv[14],      strproto_lcl[32], strproto_rmt[32];
1335
1336     slprintf(strpid, sizeof(strpid), "%d", getpid());
1337     slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);
1338
1339     strproto_lcl[0] = '\0';
1340     if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1341         if (go->router & BIT(RIP_SAP))
1342             strlcpy (strproto_lcl, sizeof(strproto_lcl), "RIP ");
1343         if (go->router & BIT(NLSP))
1344             strlcat (strproto_lcl, sizeof(strproto_lcl), "NLSP ");
1345     }
1346
1347     if (strproto_lcl[0] == '\0')
1348         strlcpy (strproto_lcl, sizeof(strproto_lcl), "NONE ");
1349
1350     strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1351
1352     strproto_rmt[0] = '\0';
1353     if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1354         if (ho->router & BIT(RIP_SAP))
1355             strlcpy (strproto_rmt, sizeof(strproto_rmt), "RIP ");
1356         if (ho->router & BIT(NLSP))
1357             strlcat (strproto_rmt, sizeof(strproto_rmt), "NLSP ");
1358     }
1359
1360     if (strproto_rmt[0] == '\0')
1361         strlcpy (strproto_rmt, sizeof(strproto_rmt), "NONE ");
1362
1363     strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1364
1365     strlcpy (strnetwork, sizeof(strnetwork), ipx_ntoa (go->network));
1366
1367     slprintf (strlocal, sizeof(strlocal),
1368               "%02X%02X%02X%02X%02X%02X",
1369               NODE(go->our_node));
1370
1371     slprintf (strremote, sizeof(strremote),
1372               "%02X%02X%02X%02X%02X%02X",
1373               NODE(ho->his_node));
1374
1375     argv[0]  = script;
1376     argv[1]  = ifname;
1377     argv[2]  = devnam;
1378     argv[3]  = strspeed;
1379     argv[4]  = strnetwork;
1380     argv[5]  = strlocal;
1381     argv[6]  = strremote;
1382     argv[7]  = strproto_lcl;
1383     argv[8]  = strproto_rmt;
1384     argv[9]  = go->name;
1385     argv[10] = ho->name;
1386     argv[11] = ipparam;
1387     argv[12] = strpid;
1388     argv[13] = NULL;
1389     run_program(script, argv, 0, NULL, NULL);
1390 }
1391
1392 /*
1393  * ipxcp_printpkt - print the contents of an IPXCP packet.
1394  */
1395 static char *ipxcp_codenames[] = {
1396     "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1397     "TermReq", "TermAck", "CodeRej"
1398 };
1399
1400 static int
1401 ipxcp_printpkt(p, plen, printer, arg)
1402     u_char *p;
1403     int plen;
1404     void (*printer) __P((void *, char *, ...));
1405     void *arg;
1406 {
1407     int code, id, len, olen;
1408     u_char *pstart, *optend;
1409     u_short cishort;
1410     u_int32_t cilong;
1411
1412     if (plen < HEADERLEN)
1413         return 0;
1414     pstart = p;
1415     GETCHAR(code, p);
1416     GETCHAR(id, p);
1417     GETSHORT(len, p);
1418     if (len < HEADERLEN || len > plen)
1419         return 0;
1420
1421     if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1422         printer(arg, " %s", ipxcp_codenames[code-1]);
1423     else
1424         printer(arg, " code=0x%x", code);
1425     printer(arg, " id=0x%x", id);
1426     len -= HEADERLEN;
1427     switch (code) {
1428     case CONFREQ:
1429     case CONFACK:
1430     case CONFNAK:
1431     case CONFREJ:
1432         /* print option list */
1433         while (len >= 2) {
1434             GETCHAR(code, p);
1435             GETCHAR(olen, p);
1436             p -= 2;
1437             if (olen < CILEN_VOID || olen > len) {
1438                 break;
1439             }
1440             printer(arg, " <");
1441             len -= olen;
1442             optend = p + olen;
1443             switch (code) {
1444             case IPX_NETWORK_NUMBER:
1445                 if (olen == CILEN_NETN) {
1446                     p += 2;
1447                     GETLONG(cilong, p);
1448                     printer (arg, "network %s", ipx_ntoa (cilong));
1449                 }
1450                 break;
1451             case IPX_NODE_NUMBER:
1452                 if (olen == CILEN_NODEN) {
1453                     p += 2;
1454                     printer (arg, "node ");
1455                     while (p < optend) {
1456                         GETCHAR(code, p);
1457                         printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1458                     }
1459                 }
1460                 break;
1461             case IPX_COMPRESSION_PROTOCOL:
1462                 if (olen == CILEN_COMPRESS) {
1463                     p += 2;
1464                     GETSHORT (cishort, p);
1465                     printer (arg, "compression %d", (int) cishort);
1466                 }
1467                 break;
1468             case IPX_ROUTER_PROTOCOL:
1469                 if (olen == CILEN_PROTOCOL) {
1470                     p += 2;
1471                     GETSHORT (cishort, p);
1472                     printer (arg, "router proto %d", (int) cishort);
1473                 }
1474                 break;
1475             case IPX_ROUTER_NAME:
1476                 if (olen >= CILEN_NAME) {
1477                     p += 2;
1478                     printer (arg, "router name \"");
1479                     while (p < optend) {
1480                         GETCHAR(code, p);
1481                         if (code >= 0x20 && code <= 0x7E)
1482                             printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1483                         else
1484                             printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1485                     }
1486                     printer (arg, "\"");
1487                 }
1488                 break;
1489             case IPX_COMPLETE:
1490                 if (olen == CILEN_COMPLETE) {
1491                     p += 2;
1492                     printer (arg, "complete");
1493                 }
1494                 break;
1495             default:
1496                 break;
1497             }
1498
1499             while (p < optend) {
1500                 GETCHAR(code, p);
1501                 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1502             }
1503             printer(arg, ">");
1504         }
1505         break;
1506
1507     case TERMACK:
1508     case TERMREQ:
1509         if (len > 0 && *p >= ' ' && *p < 0x7f) {
1510             printer(arg, " ");
1511             print_string(p, len, printer, arg);
1512             p += len;
1513             len = 0;
1514         }
1515         break;
1516     }
1517
1518     /* print the rest of the bytes in the packet */
1519     for (; len > 0; --len) {
1520         GETCHAR(code, p);
1521         printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1522     }
1523
1524     return p - pstart;
1525 }
1526 #endif /* ifdef IPX_CHANGE */