]> git.ozlabs.org Git - ppp.git/blob - pppd/ipxcp.c
840daf5ae3ae95d79c1894a9da1f2ecfd2069c57
[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.13 1999/03/19 01:22:09 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     "IPX",
161     ipxcp_option_list,
162     NULL,
163     NULL,
164     NULL
165 };
166
167 /*
168  * Lengths of configuration options.
169  */
170
171 #define CILEN_VOID      2
172 #define CILEN_COMPLETE  2       /* length of complete option */
173 #define CILEN_NETN      6       /* network number length option */
174 #define CILEN_NODEN     8       /* node number length option */
175 #define CILEN_PROTOCOL  4       /* Minimum length of routing protocol */
176 #define CILEN_NAME      3       /* Minimum length of router name */
177 #define CILEN_COMPRESS  4       /* Minimum length of compression protocol */
178
179 #define CODENAME(x)     ((x) == CONFACK ? "ACK" : \
180                          (x) == CONFNAK ? "NAK" : "REJ")
181
182 static int ipxcp_is_up;
183
184 static char *ipx_ntoa __P((u_int32_t));
185
186 /* Used in printing the node number */
187 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
188
189 /* Used to generate the proper bit mask */
190 #define BIT(num)   (1 << (num))
191
192 /*
193  * Convert from internal to external notation
194  */
195
196 static short int
197 to_external(internal)
198 short int internal;
199 {
200     short int  external;
201
202     if (internal & IPX_NONE)
203         external = IPX_NONE;
204     else
205         external = RIP_SAP;
206
207     return external;
208 }
209
210 /*
211  * Make a string representation of a network IP address.
212  */
213
214 static char *
215 ipx_ntoa(ipxaddr)
216 u_int32_t ipxaddr;
217 {
218     static char b[64];
219     slprintf(b, sizeof(b), "%x", ipxaddr);
220     return b;
221 }
222
223
224 static u_char *
225 setipxnodevalue(src,dst)
226 u_char *src, *dst;
227 {
228     int indx;
229     int item;
230
231     for (;;) {
232         if (!isxdigit (*src))
233             break;
234         
235         for (indx = 0; indx < 5; ++indx) {
236             dst[indx] <<= 4;
237             dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
238         }
239
240         item = toupper (*src) - '0';
241         if (item > 9)
242             item -= 7;
243
244         dst[5] = (dst[5] << 4) | item;
245         ++src;
246     }
247     return src;
248 }
249
250 static int
251 setipxnode(argv)
252     char **argv;
253 {
254     char *end;
255
256     memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
257     memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
258
259     end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
260     if (*end == ':')
261         end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
262
263     if (*end == '\0') {
264         ipxcp_wantoptions[0].neg_node = 1;
265         return 1;
266     }
267
268     option_error("invalid parameter '%s' for ipx-node option", *argv);
269     return 0;
270 }
271
272 static int
273 setipxname (argv)
274     char **argv;
275 {
276     char *dest = ipxcp_wantoptions[0].name;
277     char *src  = *argv;
278     int  count;
279     char ch;
280
281     ipxcp_wantoptions[0].neg_name  = 1;
282     ipxcp_allowoptions[0].neg_name = 1;
283     memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
284
285     count = 0;
286     while (*src) {
287         ch = *src++;
288         if (! isalnum (ch) && ch != '_') {
289             option_error("IPX router name must be alphanumeric or _");
290             return 0;
291         }
292
293         if (count >= sizeof (ipxcp_wantoptions[0].name)) {
294             option_error("IPX router name is limited to %d characters",
295                          sizeof (ipxcp_wantoptions[0].name) - 1);
296             return 0;
297         }
298
299         dest[count++] = toupper (ch);
300     }
301
302     return 1;
303 }
304
305 /*
306  * ipxcp_init - Initialize IPXCP.
307  */
308 static void
309 ipxcp_init(unit)
310     int unit;
311 {
312     fsm *f = &ipxcp_fsm[unit];
313
314     f->unit      = unit;
315     f->protocol  = PPP_IPXCP;
316     f->callbacks = &ipxcp_callbacks;
317     fsm_init(&ipxcp_fsm[unit]);
318
319     memset (wo->name,     0, sizeof (wo->name));
320     memset (wo->our_node, 0, sizeof (wo->our_node));
321     memset (wo->his_node, 0, sizeof (wo->his_node));
322
323     wo->neg_nn         = 1;
324     wo->neg_complete   = 1;
325     wo->network        = 0;
326
327     ao->neg_node       = 1;
328     ao->neg_nn         = 1;
329     ao->neg_name       = 1;
330     ao->neg_complete   = 1;
331     ao->neg_router     = 1;
332
333     ao->accept_local   = 0;
334     ao->accept_remote  = 0;
335     ao->accept_network = 0;
336
337     wo->tried_rip      = 0;
338     wo->tried_nlsp     = 0;
339 }
340
341 /*
342  * Copy the node number
343  */
344
345 static void
346 copy_node (src, dst)
347 u_char *src, *dst;
348 {
349     memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
350 }
351
352 /*
353  * Compare node numbers
354  */
355
356 static int
357 compare_node (src, dst)
358 u_char *src, *dst;
359 {
360     return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
361 }
362
363 /*
364  * Is the node number zero?
365  */
366
367 static int
368 zero_node (node)
369 u_char *node;
370 {
371     int indx;
372     for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
373         if (node [indx] != 0)
374             return 0;
375     return 1;
376 }
377
378 /*
379  * Increment the node number
380  */
381
382 static void
383 inc_node (node)
384 u_char *node;
385 {
386     u_char   *outp;
387     u_int32_t magic_num;
388
389     outp      = node;
390     magic_num = magic();
391     *outp++   = '\0';
392     *outp++   = '\0';
393     PUTLONG (magic_num, outp);
394 }
395
396 /*
397  * ipxcp_open - IPXCP is allowed to come up.
398  */
399 static void
400 ipxcp_open(unit)
401     int unit;
402 {
403     fsm_open(&ipxcp_fsm[unit]);
404 }
405
406 /*
407  * ipxcp_close - Take IPXCP down.
408  */
409 static void
410 ipxcp_close(unit, reason)
411     int unit;
412     char *reason;
413 {
414     fsm_close(&ipxcp_fsm[unit], reason);
415 }
416
417
418 /*
419  * ipxcp_lowerup - The lower layer is up.
420  */
421 static void
422 ipxcp_lowerup(unit)
423     int unit;
424 {
425     fsm_lowerup(&ipxcp_fsm[unit]);
426 }
427
428
429 /*
430  * ipxcp_lowerdown - The lower layer is down.
431  */
432 static void
433 ipxcp_lowerdown(unit)
434     int unit;
435 {
436     fsm_lowerdown(&ipxcp_fsm[unit]);
437 }
438
439
440 /*
441  * ipxcp_input - Input IPXCP packet.
442  */
443 static void
444 ipxcp_input(unit, p, len)
445     int unit;
446     u_char *p;
447     int len;
448 {
449     fsm_input(&ipxcp_fsm[unit], p, len);
450 }
451
452
453 /*
454  * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
455  *
456  * Pretend the lower layer went down, so we shut up.
457  */
458 static void
459 ipxcp_protrej(unit)
460     int unit;
461 {
462     fsm_lowerdown(&ipxcp_fsm[unit]);
463 }
464
465
466 /*
467  * ipxcp_resetci - Reset our CI.
468  */
469 static void
470 ipxcp_resetci(f)
471     fsm *f;
472 {
473     wo->req_node = wo->neg_node && ao->neg_node;
474     wo->req_nn   = wo->neg_nn   && ao->neg_nn;
475
476     if (wo->our_network == 0) {
477         wo->neg_node       = 1;
478         ao->accept_network = 1;
479     }
480 /*
481  * If our node number is zero then change it.
482  */
483     if (zero_node (wo->our_node)) {
484         inc_node (wo->our_node);
485         ao->accept_local = 1;
486         wo->neg_node     = 1;
487     }
488 /*
489  * If his node number is zero then change it.
490  */
491     if (zero_node (wo->his_node)) {
492         inc_node (wo->his_node);
493         ao->accept_remote = 1;
494     }
495 /*
496  * If no routing agent was specified then we do RIP/SAP according to the
497  * RFC documents. If you have specified something then OK. Otherwise, we
498  * do RIP/SAP.
499  */
500     if (ao->router == 0) {
501         ao->router |= BIT(RIP_SAP);
502         wo->router |= BIT(RIP_SAP);
503     }
504
505     /* Always specify a routing protocol unless it was REJected. */
506     wo->neg_router = 1;
507 /*
508  * Start with these default values
509  */
510     *go = *wo;
511 }
512
513 /*
514  * ipxcp_cilen - Return length of our CI.
515  */
516
517 static int
518 ipxcp_cilen(f)
519     fsm *f;
520 {
521     int len;
522
523     len  = go->neg_nn       ? CILEN_NETN     : 0;
524     len += go->neg_node     ? CILEN_NODEN    : 0;
525     len += go->neg_name     ? CILEN_NAME + strlen (go->name) - 1 : 0;
526
527     /* RFC says that defaults should not be included. */
528     if (go->neg_router && to_external(go->router) != RIP_SAP)
529         len += CILEN_PROTOCOL;
530
531     return (len);
532 }
533
534
535 /*
536  * ipxcp_addci - Add our desired CIs to a packet.
537  */
538 static void
539 ipxcp_addci(f, ucp, lenp)
540     fsm *f;
541     u_char *ucp;
542     int *lenp;
543 {
544 /*
545  * Add the options to the record.
546  */
547     if (go->neg_nn) {
548         PUTCHAR (IPX_NETWORK_NUMBER, ucp);
549         PUTCHAR (CILEN_NETN, ucp);
550         PUTLONG (go->our_network, ucp);
551     }
552
553     if (go->neg_node) {
554         int indx;
555         PUTCHAR (IPX_NODE_NUMBER, ucp);
556         PUTCHAR (CILEN_NODEN, ucp);
557         for (indx = 0; indx < sizeof (go->our_node); ++indx)
558             PUTCHAR (go->our_node[indx], ucp);
559     }
560
561     if (go->neg_name) {
562         int cilen = strlen (go->name);
563         int indx;
564         PUTCHAR (IPX_ROUTER_NAME, ucp);
565         PUTCHAR (CILEN_NAME + cilen - 1, ucp);
566         for (indx = 0; indx < cilen; ++indx)
567             PUTCHAR (go->name [indx], ucp);
568     }
569
570     if (go->neg_router) {
571         short external = to_external (go->router);
572         if (external != RIP_SAP) {
573             PUTCHAR  (IPX_ROUTER_PROTOCOL, ucp);
574             PUTCHAR  (CILEN_PROTOCOL,      ucp);
575             PUTSHORT (external,            ucp);
576         }
577     }
578 }
579
580 /*
581  * ipxcp_ackci - Ack our CIs.
582  *
583  * Returns:
584  *      0 - Ack was bad.
585  *      1 - Ack was good.
586  */
587 static int
588 ipxcp_ackci(f, p, len)
589     fsm *f;
590     u_char *p;
591     int len;
592 {
593     u_short cilen, citype, cishort;
594     u_char cichar;
595     u_int32_t cilong;
596
597 #define ACKCIVOID(opt, neg) \
598     if (neg) { \
599         if ((len -= CILEN_VOID) < 0) \
600             break; \
601         GETCHAR(citype, p); \
602         GETCHAR(cilen, p); \
603         if (cilen != CILEN_VOID || \
604             citype != opt) \
605             break; \
606     }
607
608 #define ACKCICOMPLETE(opt,neg)  ACKCIVOID(opt, neg)
609
610 #define ACKCICHARS(opt, neg, val, cnt) \
611     if (neg) { \
612         int indx, count = cnt; \
613         len -= (count + 2); \
614         if (len < 0) \
615             break; \
616         GETCHAR(citype, p); \
617         GETCHAR(cilen, p); \
618         if (cilen != (count + 2) || \
619             citype != opt) \
620             break; \
621         for (indx = 0; indx < count; ++indx) {\
622             GETCHAR(cichar, p); \
623             if (cichar != ((u_char *) &val)[indx]) \
624                break; \
625         }\
626         if (indx != count) \
627             break; \
628     }
629
630 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
631 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen(val))
632
633 #define ACKCINETWORK(opt, neg, val) \
634     if (neg) { \
635         if ((len -= CILEN_NETN) < 0) \
636             break; \
637         GETCHAR(citype, p); \
638         GETCHAR(cilen, p); \
639         if (cilen != CILEN_NETN || \
640             citype != opt) \
641             break; \
642         GETLONG(cilong, p); \
643         if (cilong != val) \
644             break; \
645     }
646
647 #define ACKCIPROTO(opt, neg, val) \
648     if (neg) { \
649         if (len < 2) \
650             break; \
651         GETCHAR(citype, p); \
652         GETCHAR(cilen, p); \
653         if (cilen != CILEN_PROTOCOL || citype != opt) \
654             break; \
655         len -= cilen; \
656         if (len < 0) \
657             break; \
658         GETSHORT(cishort, p); \
659         if (cishort != to_external (val) || cishort == RIP_SAP) \
660             break; \
661       }
662 /*
663  * Process the ACK frame in the order in which the frame was assembled
664  */
665     do {
666         ACKCINETWORK  (IPX_NETWORK_NUMBER,  go->neg_nn,     go->our_network);
667         ACKCINODE     (IPX_NODE_NUMBER,     go->neg_node,   go->our_node);
668         ACKCINAME     (IPX_ROUTER_NAME,     go->neg_name,   go->name);
669         ACKCIPROTO    (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
670         ACKCIPROTO    (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
671         ACKCIPROTO    (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
672 /*
673  * This is the end of the record.
674  */
675         if (len == 0)
676             return (1);
677     } while (0);
678 /*
679  * The frame is invalid
680  */
681     IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
682     return (0);
683 }
684
685 /*
686  * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
687  * This should not modify any state if the Nak is bad
688  * or if IPXCP is in the OPENED state.
689  *
690  * Returns:
691  *      0 - Nak was bad.
692  *      1 - Nak was good.
693  */
694
695 static int
696 ipxcp_nakci(f, p, len)
697     fsm *f;
698     u_char *p;
699     int len;
700 {
701     u_char citype, cilen, *next;
702     u_short s;
703     u_int32_t l;
704     ipxcp_options no;           /* options we've seen Naks for */
705     ipxcp_options try;          /* options to request next time */
706
707     BZERO(&no, sizeof(no));
708     try = *go;
709
710     while (len > CILEN_VOID) {
711         GETCHAR (citype, p);
712         GETCHAR (cilen,  p);
713         len -= cilen;
714         if (len < 0)
715             goto bad;
716         next = &p [cilen - CILEN_VOID];
717
718         switch (citype) {
719         case IPX_NETWORK_NUMBER:
720             if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
721                 goto bad;
722             no.neg_nn = 1;
723
724             GETLONG(l, p);
725             if (l && ao->accept_network)
726                 try.our_network = l;
727             break;
728
729         case IPX_NODE_NUMBER:
730             if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
731                 goto bad;
732             no.neg_node = 1;
733
734             if (!zero_node (p) && ao->accept_local &&
735                 ! compare_node (p, ho->his_node))
736                 copy_node (p, try.our_node);
737             break;
738
739             /* This has never been sent. Ignore the NAK frame */
740         case IPX_COMPRESSION_PROTOCOL:
741             goto bad;
742
743         case IPX_ROUTER_PROTOCOL:
744             if (!go->neg_router || (cilen < CILEN_PROTOCOL))
745                 goto bad;
746
747             GETSHORT (s, p);
748             if (s > 15)         /* This is just bad, but ignore for now. */
749                 break;
750
751             s = BIT(s);
752             if (no.router & s)  /* duplicate NAKs are always bad */
753                 goto bad;
754
755             if (no.router == 0) /* Reset on first NAK only */
756                 try.router = 0;
757
758             no.router      |= s;
759             try.router     |= s;
760             try.neg_router  = 1;
761             break;
762
763             /* These, according to the RFC, must never be NAKed. */
764         case IPX_ROUTER_NAME:
765         case IPX_COMPLETE:
766             goto bad;
767
768             /* These are for options which we have not seen. */
769         default:
770             break;
771         }
772         p = next;
773     }
774
775     /*
776      * Do not permit the peer to force a router protocol which we do not
777      * support. However, default to the condition that will accept "NONE".
778      */
779     try.router &= (ao->router | BIT(IPX_NONE));
780     if (try.router == 0 && ao->router != 0)
781         try.router = BIT(IPX_NONE);
782
783     if (try.router != 0)
784         try.neg_router = 1;
785     
786     /*
787      * OK, the Nak is good.  Now we can update state.
788      * If there are any options left, we ignore them.
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, "RIP ", sizeof(strproto_lcl));
1343         if (go->router & BIT(NLSP))
1344             strlcat (strproto_lcl, "NLSP ", sizeof(strproto_lcl));
1345     }
1346
1347     if (strproto_lcl[0] == '\0')
1348         strlcpy (strproto_lcl, "NONE ", sizeof(strproto_lcl));
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, "RIP ", sizeof(strproto_rmt));
1356         if (ho->router & BIT(NLSP))
1357             strlcat (strproto_rmt, "NLSP ", sizeof(strproto_rmt));
1358     }
1359
1360     if (strproto_rmt[0] == '\0')
1361         strlcpy (strproto_rmt, "NONE ", sizeof(strproto_rmt));
1362
1363     strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1364
1365     strlcpy (strnetwork, ipx_ntoa (go->network), sizeof(strnetwork));
1366
1367     slprintf (strlocal, sizeof(strlocal), "%0.6B", go->our_node);
1368
1369     slprintf (strremote, sizeof(strremote), "%0.6B", ho->his_node);
1370
1371     argv[0]  = script;
1372     argv[1]  = ifname;
1373     argv[2]  = devnam;
1374     argv[3]  = strspeed;
1375     argv[4]  = strnetwork;
1376     argv[5]  = strlocal;
1377     argv[6]  = strremote;
1378     argv[7]  = strproto_lcl;
1379     argv[8]  = strproto_rmt;
1380     argv[9]  = go->name;
1381     argv[10] = ho->name;
1382     argv[11] = ipparam;
1383     argv[12] = strpid;
1384     argv[13] = NULL;
1385     run_program(script, argv, 0, NULL, NULL);
1386 }
1387
1388 /*
1389  * ipxcp_printpkt - print the contents of an IPXCP packet.
1390  */
1391 static char *ipxcp_codenames[] = {
1392     "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1393     "TermReq", "TermAck", "CodeRej"
1394 };
1395
1396 static int
1397 ipxcp_printpkt(p, plen, printer, arg)
1398     u_char *p;
1399     int plen;
1400     void (*printer) __P((void *, char *, ...));
1401     void *arg;
1402 {
1403     int code, id, len, olen;
1404     u_char *pstart, *optend;
1405     u_short cishort;
1406     u_int32_t cilong;
1407
1408     if (plen < HEADERLEN)
1409         return 0;
1410     pstart = p;
1411     GETCHAR(code, p);
1412     GETCHAR(id, p);
1413     GETSHORT(len, p);
1414     if (len < HEADERLEN || len > plen)
1415         return 0;
1416
1417     if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1418         printer(arg, " %s", ipxcp_codenames[code-1]);
1419     else
1420         printer(arg, " code=0x%x", code);
1421     printer(arg, " id=0x%x", id);
1422     len -= HEADERLEN;
1423     switch (code) {
1424     case CONFREQ:
1425     case CONFACK:
1426     case CONFNAK:
1427     case CONFREJ:
1428         /* print option list */
1429         while (len >= 2) {
1430             GETCHAR(code, p);
1431             GETCHAR(olen, p);
1432             p -= 2;
1433             if (olen < CILEN_VOID || olen > len) {
1434                 break;
1435             }
1436             printer(arg, " <");
1437             len -= olen;
1438             optend = p + olen;
1439             switch (code) {
1440             case IPX_NETWORK_NUMBER:
1441                 if (olen == CILEN_NETN) {
1442                     p += 2;
1443                     GETLONG(cilong, p);
1444                     printer (arg, "network %s", ipx_ntoa (cilong));
1445                 }
1446                 break;
1447             case IPX_NODE_NUMBER:
1448                 if (olen == CILEN_NODEN) {
1449                     p += 2;
1450                     printer (arg, "node ");
1451                     while (p < optend) {
1452                         GETCHAR(code, p);
1453                         printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1454                     }
1455                 }
1456                 break;
1457             case IPX_COMPRESSION_PROTOCOL:
1458                 if (olen == CILEN_COMPRESS) {
1459                     p += 2;
1460                     GETSHORT (cishort, p);
1461                     printer (arg, "compression %d", (int) cishort);
1462                 }
1463                 break;
1464             case IPX_ROUTER_PROTOCOL:
1465                 if (olen == CILEN_PROTOCOL) {
1466                     p += 2;
1467                     GETSHORT (cishort, p);
1468                     printer (arg, "router proto %d", (int) cishort);
1469                 }
1470                 break;
1471             case IPX_ROUTER_NAME:
1472                 if (olen >= CILEN_NAME) {
1473                     p += 2;
1474                     printer (arg, "router name \"");
1475                     while (p < optend) {
1476                         GETCHAR(code, p);
1477                         if (code >= 0x20 && code <= 0x7E)
1478                             printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1479                         else
1480                             printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1481                     }
1482                     printer (arg, "\"");
1483                 }
1484                 break;
1485             case IPX_COMPLETE:
1486                 if (olen == CILEN_COMPLETE) {
1487                     p += 2;
1488                     printer (arg, "complete");
1489                 }
1490                 break;
1491             default:
1492                 break;
1493             }
1494
1495             while (p < optend) {
1496                 GETCHAR(code, p);
1497                 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1498             }
1499             printer(arg, ">");
1500         }
1501         break;
1502
1503     case TERMACK:
1504     case TERMREQ:
1505         if (len > 0 && *p >= ' ' && *p < 0x7f) {
1506             printer(arg, " ");
1507             print_string(p, len, printer, arg);
1508             p += len;
1509             len = 0;
1510         }
1511         break;
1512     }
1513
1514     /* print the rest of the bytes in the packet */
1515     for (; len > 0; --len) {
1516         GETCHAR(code, p);
1517         printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1518     }
1519
1520     return p - pstart;
1521 }
1522 #endif /* ifdef IPX_CHANGE */