]> git.ozlabs.org Git - ppp.git/blob - pppd/ipxcp.c
937dea1095cc55dac734b8173b0cf0e3546b78dd
[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.17 1999/08/13 06:46:14 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" },
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
257     memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
258     memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
259
260     end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
261     if (*end == ':')
262         end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
263
264     if (*end == '\0') {
265         ipxcp_wantoptions[0].neg_node = 1;
266         return 1;
267     }
268
269     option_error("invalid parameter '%s' for ipx-node option", *argv);
270     return 0;
271 }
272
273 static int
274 setipxname (argv)
275     char **argv;
276 {
277     char *dest = ipxcp_wantoptions[0].name;
278     char *src  = *argv;
279     int  count;
280     char ch;
281
282     ipxcp_wantoptions[0].neg_name  = 1;
283     ipxcp_allowoptions[0].neg_name = 1;
284     memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
285
286     count = 0;
287     while (*src) {
288         ch = *src++;
289         if (! isalnum (ch) && ch != '_') {
290             option_error("IPX router name must be alphanumeric or _");
291             return 0;
292         }
293
294         if (count >= sizeof (ipxcp_wantoptions[0].name)) {
295             option_error("IPX router name is limited to %d characters",
296                          sizeof (ipxcp_wantoptions[0].name) - 1);
297             return 0;
298         }
299
300         dest[count++] = toupper (ch);
301     }
302
303     return 1;
304 }
305
306 /*
307  * ipxcp_init - Initialize IPXCP.
308  */
309 static void
310 ipxcp_init(unit)
311     int unit;
312 {
313     fsm *f = &ipxcp_fsm[unit];
314
315     f->unit      = unit;
316     f->protocol  = PPP_IPXCP;
317     f->callbacks = &ipxcp_callbacks;
318     fsm_init(&ipxcp_fsm[unit]);
319
320     memset (wo->name,     0, sizeof (wo->name));
321     memset (wo->our_node, 0, sizeof (wo->our_node));
322     memset (wo->his_node, 0, sizeof (wo->his_node));
323
324     wo->neg_nn         = 1;
325     wo->neg_complete   = 1;
326     wo->network        = 0;
327
328     ao->neg_node       = 1;
329     ao->neg_nn         = 1;
330     ao->neg_name       = 1;
331     ao->neg_complete   = 1;
332     ao->neg_router     = 1;
333
334     ao->accept_local   = 0;
335     ao->accept_remote  = 0;
336     ao->accept_network = 0;
337
338     wo->tried_rip      = 0;
339     wo->tried_nlsp     = 0;
340 }
341
342 /*
343  * Copy the node number
344  */
345
346 static void
347 copy_node (src, dst)
348 u_char *src, *dst;
349 {
350     memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
351 }
352
353 /*
354  * Compare node numbers
355  */
356
357 static int
358 compare_node (src, dst)
359 u_char *src, *dst;
360 {
361     return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
362 }
363
364 /*
365  * Is the node number zero?
366  */
367
368 static int
369 zero_node (node)
370 u_char *node;
371 {
372     int indx;
373     for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
374         if (node [indx] != 0)
375             return 0;
376     return 1;
377 }
378
379 /*
380  * Increment the node number
381  */
382
383 static void
384 inc_node (node)
385 u_char *node;
386 {
387     u_char   *outp;
388     u_int32_t magic_num;
389
390     outp      = node;
391     magic_num = magic();
392     *outp++   = '\0';
393     *outp++   = '\0';
394     PUTLONG (magic_num, outp);
395 }
396
397 /*
398  * ipxcp_open - IPXCP is allowed to come up.
399  */
400 static void
401 ipxcp_open(unit)
402     int unit;
403 {
404     fsm_open(&ipxcp_fsm[unit]);
405 }
406
407 /*
408  * ipxcp_close - Take IPXCP down.
409  */
410 static void
411 ipxcp_close(unit, reason)
412     int unit;
413     char *reason;
414 {
415     fsm_close(&ipxcp_fsm[unit], reason);
416 }
417
418
419 /*
420  * ipxcp_lowerup - The lower layer is up.
421  */
422 static void
423 ipxcp_lowerup(unit)
424     int unit;
425 {
426     fsm_lowerup(&ipxcp_fsm[unit]);
427 }
428
429
430 /*
431  * ipxcp_lowerdown - The lower layer is down.
432  */
433 static void
434 ipxcp_lowerdown(unit)
435     int unit;
436 {
437     fsm_lowerdown(&ipxcp_fsm[unit]);
438 }
439
440
441 /*
442  * ipxcp_input - Input IPXCP packet.
443  */
444 static void
445 ipxcp_input(unit, p, len)
446     int unit;
447     u_char *p;
448     int len;
449 {
450     fsm_input(&ipxcp_fsm[unit], p, len);
451 }
452
453
454 /*
455  * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
456  *
457  * Pretend the lower layer went down, so we shut up.
458  */
459 static void
460 ipxcp_protrej(unit)
461     int unit;
462 {
463     fsm_lowerdown(&ipxcp_fsm[unit]);
464 }
465
466
467 /*
468  * ipxcp_resetci - Reset our CI.
469  */
470 static void
471 ipxcp_resetci(f)
472     fsm *f;
473 {
474     wo->req_node = wo->neg_node && ao->neg_node;
475     wo->req_nn   = wo->neg_nn   && ao->neg_nn;
476
477     if (wo->our_network == 0) {
478         wo->neg_node       = 1;
479         ao->accept_network = 1;
480     }
481 /*
482  * If our node number is zero then change it.
483  */
484     if (zero_node (wo->our_node)) {
485         inc_node (wo->our_node);
486         ao->accept_local = 1;
487         wo->neg_node     = 1;
488     }
489 /*
490  * If his node number is zero then change it.
491  */
492     if (zero_node (wo->his_node)) {
493         inc_node (wo->his_node);
494         ao->accept_remote = 1;
495     }
496 /*
497  * If no routing agent was specified then we do RIP/SAP according to the
498  * RFC documents. If you have specified something then OK. Otherwise, we
499  * do RIP/SAP.
500  */
501     if (ao->router == 0) {
502         ao->router |= BIT(RIP_SAP);
503         wo->router |= BIT(RIP_SAP);
504     }
505
506     /* Always specify a routing protocol unless it was REJected. */
507     wo->neg_router = 1;
508 /*
509  * Start with these default values
510  */
511     *go = *wo;
512 }
513
514 /*
515  * ipxcp_cilen - Return length of our CI.
516  */
517
518 static int
519 ipxcp_cilen(f)
520     fsm *f;
521 {
522     int len;
523
524     len  = go->neg_nn       ? CILEN_NETN     : 0;
525     len += go->neg_node     ? CILEN_NODEN    : 0;
526     len += go->neg_name     ? CILEN_NAME + strlen (go->name) - 1 : 0;
527
528     /* RFC says that defaults should not be included. */
529     if (go->neg_router && to_external(go->router) != RIP_SAP)
530         len += CILEN_PROTOCOL;
531
532     return (len);
533 }
534
535
536 /*
537  * ipxcp_addci - Add our desired CIs to a packet.
538  */
539 static void
540 ipxcp_addci(f, ucp, lenp)
541     fsm *f;
542     u_char *ucp;
543     int *lenp;
544 {
545 /*
546  * Add the options to the record.
547  */
548     if (go->neg_nn) {
549         PUTCHAR (IPX_NETWORK_NUMBER, ucp);
550         PUTCHAR (CILEN_NETN, ucp);
551         PUTLONG (go->our_network, ucp);
552     }
553
554     if (go->neg_node) {
555         int indx;
556         PUTCHAR (IPX_NODE_NUMBER, ucp);
557         PUTCHAR (CILEN_NODEN, ucp);
558         for (indx = 0; indx < sizeof (go->our_node); ++indx)
559             PUTCHAR (go->our_node[indx], ucp);
560     }
561
562     if (go->neg_name) {
563         int cilen = strlen (go->name);
564         int indx;
565         PUTCHAR (IPX_ROUTER_NAME, ucp);
566         PUTCHAR (CILEN_NAME + cilen - 1, ucp);
567         for (indx = 0; indx < cilen; ++indx)
568             PUTCHAR (go->name [indx], ucp);
569     }
570
571     if (go->neg_router) {
572         short external = to_external (go->router);
573         if (external != RIP_SAP) {
574             PUTCHAR  (IPX_ROUTER_PROTOCOL, ucp);
575             PUTCHAR  (CILEN_PROTOCOL,      ucp);
576             PUTSHORT (external,            ucp);
577         }
578     }
579 }
580
581 /*
582  * ipxcp_ackci - Ack our CIs.
583  *
584  * Returns:
585  *      0 - Ack was bad.
586  *      1 - Ack was good.
587  */
588 static int
589 ipxcp_ackci(f, p, len)
590     fsm *f;
591     u_char *p;
592     int len;
593 {
594     u_short cilen, citype, cishort;
595     u_char cichar;
596     u_int32_t cilong;
597
598 #define ACKCIVOID(opt, neg) \
599     if (neg) { \
600         if ((len -= CILEN_VOID) < 0) \
601             break; \
602         GETCHAR(citype, p); \
603         GETCHAR(cilen, p); \
604         if (cilen != CILEN_VOID || \
605             citype != opt) \
606             break; \
607     }
608
609 #define ACKCICOMPLETE(opt,neg)  ACKCIVOID(opt, neg)
610
611 #define ACKCICHARS(opt, neg, val, cnt) \
612     if (neg) { \
613         int indx, count = cnt; \
614         len -= (count + 2); \
615         if (len < 0) \
616             break; \
617         GETCHAR(citype, p); \
618         GETCHAR(cilen, p); \
619         if (cilen != (count + 2) || \
620             citype != opt) \
621             break; \
622         for (indx = 0; indx < count; ++indx) {\
623             GETCHAR(cichar, p); \
624             if (cichar != ((u_char *) &val)[indx]) \
625                break; \
626         }\
627         if (indx != count) \
628             break; \
629     }
630
631 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
632 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen(val))
633
634 #define ACKCINETWORK(opt, neg, val) \
635     if (neg) { \
636         if ((len -= CILEN_NETN) < 0) \
637             break; \
638         GETCHAR(citype, p); \
639         GETCHAR(cilen, p); \
640         if (cilen != CILEN_NETN || \
641             citype != opt) \
642             break; \
643         GETLONG(cilong, p); \
644         if (cilong != val) \
645             break; \
646     }
647
648 #define ACKCIPROTO(opt, neg, val) \
649     if (neg) { \
650         if (len < 2) \
651             break; \
652         GETCHAR(citype, p); \
653         GETCHAR(cilen, p); \
654         if (cilen != CILEN_PROTOCOL || citype != opt) \
655             break; \
656         len -= cilen; \
657         if (len < 0) \
658             break; \
659         GETSHORT(cishort, p); \
660         if (cishort != to_external (val) || cishort == RIP_SAP) \
661             break; \
662       }
663 /*
664  * Process the ACK frame in the order in which the frame was assembled
665  */
666     do {
667         ACKCINETWORK  (IPX_NETWORK_NUMBER,  go->neg_nn,     go->our_network);
668         ACKCINODE     (IPX_NODE_NUMBER,     go->neg_node,   go->our_node);
669         ACKCINAME     (IPX_ROUTER_NAME,     go->neg_name,   go->name);
670         if (len > 0)
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 */