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