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