2 * ipxcp.c - PPP IPX Control Protocol.
4 * Copyright (c) 1989 Carnegie Mellon University.
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.
22 #define RCSID "$Id: ipxcp.c,v 1.20 2001/03/08 05:11:13 paulus Exp $"
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
39 #include "pathnames.h"
42 static const char rcsid[] = RCSID;
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 */
50 #define wo (&ipxcp_wantoptions[0])
51 #define ao (&ipxcp_allowoptions[0])
52 #define go (&ipxcp_gotoptions[0])
53 #define ho (&ipxcp_hisoptions[0])
56 * Callbacks for fsm code. (CI = Configuration Information)
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 */
70 fsm ipxcp_fsm[NUM_PPP]; /* IPXCP fsm structure */
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 */
91 * Command-line options.
93 static int setipxnode __P((char **));
94 static void printipxnode __P((option_t *,
95 void (*)(void *, char *, ...), void *));
96 static int setipxname __P((char **));
98 static option_t ipxcp_option_list[] = {
99 { "ipx", o_bool, &ipxcp_protent.enabled_flag,
100 "Enable IPXCP (and IPX)", OPT_PRIO | 1 },
101 { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
102 "Enable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS | 1 },
103 { "noipx", o_bool, &ipxcp_protent.enabled_flag,
104 "Disable IPXCP (and IPX)", OPT_PRIOSUB },
105 { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
106 "Disable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS },
108 { "ipx-network", o_uint32, &ipxcp_wantoptions[0].our_network,
109 "Set our IPX network number", OPT_PRIO, &ipxcp_wantoptions[0].neg_nn },
111 { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
112 "Accept peer IPX network number", 1,
113 &ipxcp_allowoptions[0].accept_network },
115 { "ipx-node", o_special, (void *)setipxnode,
116 "Set IPX node number", OPT_A2PRINTER, (void *)printipxnode },
118 { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
119 "Accept our IPX address", 1,
120 &ipxcp_allowoptions[0].accept_local },
122 { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
123 "Accept peer's IPX address", 1,
124 &ipxcp_allowoptions[0].accept_remote },
126 { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
127 "Set IPX routing proto number", OPT_PRIO,
128 &ipxcp_wantoptions[0].neg_router },
130 { "ipx-router-name", o_special, setipxname,
131 "Set IPX router name", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC,
132 &ipxcp_wantoptions[0].name },
134 { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
135 "Set timeout for IPXCP", OPT_PRIO },
136 { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
137 "Set max #xmits for IPXCP term-reqs", OPT_PRIO },
138 { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
139 "Set max #xmits for IPXCP conf-reqs", OPT_PRIO },
140 { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
141 "Set max #conf-naks for IPXCP", OPT_PRIO },
147 * Protocol entry points.
150 static void ipxcp_init __P((int));
151 static void ipxcp_open __P((int));
152 static void ipxcp_close __P((int, char *));
153 static void ipxcp_lowerup __P((int));
154 static void ipxcp_lowerdown __P((int));
155 static void ipxcp_input __P((int, u_char *, int));
156 static void ipxcp_protrej __P((int));
157 static int ipxcp_printpkt __P((u_char *, int,
158 void (*) __P((void *, char *, ...)), void *));
160 struct protent ipxcp_protent = {
181 * Lengths of configuration options.
185 #define CILEN_COMPLETE 2 /* length of complete option */
186 #define CILEN_NETN 6 /* network number length option */
187 #define CILEN_NODEN 8 /* node number length option */
188 #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
189 #define CILEN_NAME 3 /* Minimum length of router name */
190 #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
192 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
193 (x) == CONFNAK ? "NAK" : "REJ")
195 static int ipxcp_is_up;
197 static char *ipx_ntoa __P((u_int32_t));
199 /* Used in printing the node number */
200 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
202 /* Used to generate the proper bit mask */
203 #define BIT(num) (1 << (num))
206 * Convert from internal to external notation
210 to_external(internal)
215 if (internal & BIT(IPX_NONE) )
224 * Make a string representation of a network IP address.
232 slprintf(b, sizeof(b), "%x", ipxaddr);
238 setipxnodevalue(src,dst)
245 if (!isxdigit (*src))
248 for (indx = 0; indx < 5; ++indx) {
250 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
253 item = toupper (*src) - '0';
257 dst[5] = (dst[5] << 4) | item;
263 static int ipx_prio_our, ipx_prio_his;
274 memset (our_node, 0, 6);
275 memset (his_node, 0, 6);
277 end = setipxnodevalue (*argv, our_node);
280 end = setipxnodevalue (++end, his_node);
284 ipxcp_wantoptions[0].neg_node = 1;
285 if (option_priority >= ipx_prio_our) {
286 memcpy(&ipxcp_wantoptions[0].our_node[0], our_node, 6);
287 ipx_prio_our = option_priority;
289 if (have_his && option_priority >= ipx_prio_his) {
290 memcpy(&ipxcp_wantoptions[0].his_node[0], his_node, 6);
291 ipx_prio_his = option_priority;
296 option_error("invalid parameter '%s' for ipx-node option", *argv);
301 printipxnode(opt, printer, arg)
303 void (*printer) __P((void *, char *, ...));
308 p = ipxcp_wantoptions[0].our_node;
310 printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
311 p[0], p[1], p[2], p[3], p[4], p[5]);
313 p = ipxcp_wantoptions[0].his_node;
315 printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
316 p[0], p[1], p[2], p[3], p[4], p[5]);
323 char *dest = ipxcp_wantoptions[0].name;
328 ipxcp_wantoptions[0].neg_name = 1;
329 ipxcp_allowoptions[0].neg_name = 1;
330 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
335 if (! isalnum (ch) && ch != '_') {
336 option_error("IPX router name must be alphanumeric or _");
340 if (count >= sizeof (ipxcp_wantoptions[0].name) - 1) {
341 option_error("IPX router name is limited to %d characters",
342 sizeof (ipxcp_wantoptions[0].name) - 1);
346 dest[count++] = toupper (ch);
354 * ipxcp_init - Initialize IPXCP.
360 fsm *f = &ipxcp_fsm[unit];
363 f->protocol = PPP_IPXCP;
364 f->callbacks = &ipxcp_callbacks;
365 fsm_init(&ipxcp_fsm[unit]);
367 memset (wo->name, 0, sizeof (wo->name));
368 memset (wo->our_node, 0, sizeof (wo->our_node));
369 memset (wo->his_node, 0, sizeof (wo->his_node));
372 wo->neg_complete = 1;
378 ao->neg_complete = 1;
381 ao->accept_local = 0;
382 ao->accept_remote = 0;
383 ao->accept_network = 0;
390 * Copy the node number
397 memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
401 * Compare node numbers
405 compare_node (src, dst)
408 return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
412 * Is the node number zero?
420 for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
421 if (node [indx] != 0)
427 * Increment the node number
441 PUTLONG (magic_num, outp);
445 * ipxcp_open - IPXCP is allowed to come up.
451 fsm_open(&ipxcp_fsm[unit]);
455 * ipxcp_close - Take IPXCP down.
458 ipxcp_close(unit, reason)
462 fsm_close(&ipxcp_fsm[unit], reason);
467 * ipxcp_lowerup - The lower layer is up.
473 fsm_lowerup(&ipxcp_fsm[unit]);
478 * ipxcp_lowerdown - The lower layer is down.
481 ipxcp_lowerdown(unit)
484 fsm_lowerdown(&ipxcp_fsm[unit]);
489 * ipxcp_input - Input IPXCP packet.
492 ipxcp_input(unit, p, len)
497 fsm_input(&ipxcp_fsm[unit], p, len);
502 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
504 * Pretend the lower layer went down, so we shut up.
510 fsm_lowerdown(&ipxcp_fsm[unit]);
515 * ipxcp_resetci - Reset our CI.
521 wo->req_node = wo->neg_node && ao->neg_node;
522 wo->req_nn = wo->neg_nn && ao->neg_nn;
524 if (wo->our_network == 0) {
526 ao->accept_network = 1;
529 * If our node number is zero then change it.
531 if (zero_node (wo->our_node)) {
532 inc_node (wo->our_node);
533 ao->accept_local = 1;
537 * If his node number is zero then change it.
539 if (zero_node (wo->his_node)) {
540 inc_node (wo->his_node);
541 ao->accept_remote = 1;
544 * If no routing agent was specified then we do RIP/SAP according to the
545 * RFC documents. If you have specified something then OK. Otherwise, we
548 if (ao->router == 0) {
549 ao->router |= BIT(RIP_SAP);
550 wo->router |= BIT(RIP_SAP);
553 /* Always specify a routing protocol unless it was REJected. */
556 * Start with these default values
562 * ipxcp_cilen - Return length of our CI.
571 len = go->neg_nn ? CILEN_NETN : 0;
572 len += go->neg_node ? CILEN_NODEN : 0;
573 len += go->neg_name ? CILEN_NAME + strlen (go->name) - 1 : 0;
575 /* RFC says that defaults should not be included. */
576 if (go->neg_router && to_external(go->router) != RIP_SAP)
577 len += CILEN_PROTOCOL;
584 * ipxcp_addci - Add our desired CIs to a packet.
587 ipxcp_addci(f, ucp, lenp)
593 * Add the options to the record.
596 PUTCHAR (IPX_NETWORK_NUMBER, ucp);
597 PUTCHAR (CILEN_NETN, ucp);
598 PUTLONG (go->our_network, ucp);
603 PUTCHAR (IPX_NODE_NUMBER, ucp);
604 PUTCHAR (CILEN_NODEN, ucp);
605 for (indx = 0; indx < sizeof (go->our_node); ++indx)
606 PUTCHAR (go->our_node[indx], ucp);
610 int cilen = strlen (go->name);
612 PUTCHAR (IPX_ROUTER_NAME, ucp);
613 PUTCHAR (CILEN_NAME + cilen - 1, ucp);
614 for (indx = 0; indx < cilen; ++indx)
615 PUTCHAR (go->name [indx], ucp);
618 if (go->neg_router) {
619 short external = to_external (go->router);
620 if (external != RIP_SAP) {
621 PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
622 PUTCHAR (CILEN_PROTOCOL, ucp);
623 PUTSHORT (external, ucp);
629 * ipxcp_ackci - Ack our CIs.
636 ipxcp_ackci(f, p, len)
641 u_short cilen, citype, cishort;
645 #define ACKCIVOID(opt, neg) \
647 if ((len -= CILEN_VOID) < 0) \
649 GETCHAR(citype, p); \
651 if (cilen != CILEN_VOID || \
656 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
658 #define ACKCICHARS(opt, neg, val, cnt) \
660 int indx, count = cnt; \
661 len -= (count + 2); \
664 GETCHAR(citype, p); \
666 if (cilen != (count + 2) || \
669 for (indx = 0; indx < count; ++indx) {\
670 GETCHAR(cichar, p); \
671 if (cichar != ((u_char *) &val)[indx]) \
678 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
679 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen(val))
681 #define ACKCINETWORK(opt, neg, val) \
683 if ((len -= CILEN_NETN) < 0) \
685 GETCHAR(citype, p); \
687 if (cilen != CILEN_NETN || \
690 GETLONG(cilong, p); \
695 #define ACKCIPROTO(opt, neg, val) \
699 GETCHAR(citype, p); \
701 if (cilen != CILEN_PROTOCOL || citype != opt) \
706 GETSHORT(cishort, p); \
707 if (cishort != to_external (val) || cishort == RIP_SAP) \
711 * Process the ACK frame in the order in which the frame was assembled
714 ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
715 ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
716 ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
718 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
720 * This is the end of the record.
726 * The frame is invalid
728 IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
733 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
734 * This should not modify any state if the Nak is bad
735 * or if IPXCP is in the OPENED state.
743 ipxcp_nakci(f, p, len)
748 u_char citype, cilen, *next;
751 ipxcp_options no; /* options we've seen Naks for */
752 ipxcp_options try; /* options to request next time */
754 BZERO(&no, sizeof(no));
757 while (len > CILEN_VOID) {
763 next = &p [cilen - CILEN_VOID];
766 case IPX_NETWORK_NUMBER:
767 if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
772 if (l && ao->accept_network)
776 case IPX_NODE_NUMBER:
777 if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
781 if (!zero_node (p) && ao->accept_local &&
782 ! compare_node (p, ho->his_node))
783 copy_node (p, try.our_node);
786 /* This has never been sent. Ignore the NAK frame */
787 case IPX_COMPRESSION_PROTOCOL:
790 case IPX_ROUTER_PROTOCOL:
791 if (!go->neg_router || (cilen < CILEN_PROTOCOL))
795 if (s > 15) /* This is just bad, but ignore for now. */
799 if (no.router & s) /* duplicate NAKs are always bad */
802 if (no.router == 0) /* Reset on first NAK only */
810 /* These, according to the RFC, must never be NAKed. */
811 case IPX_ROUTER_NAME:
815 /* These are for options which we have not seen. */
823 * Do not permit the peer to force a router protocol which we do not
824 * support. However, default to the condition that will accept "NONE".
826 try.router &= (ao->router | BIT(IPX_NONE));
827 if (try.router == 0 && ao->router != 0)
828 try.router = BIT(IPX_NONE);
834 * OK, the Nak is good. Now we can update state.
835 * If there are any options left, we ignore them.
837 if (f->state != OPENED)
843 IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
848 * ipxcp_rejci - Reject some of our CIs.
851 ipxcp_rejci(f, p, len)
856 u_short cilen, citype, cishort;
859 ipxcp_options try; /* options to request next time */
861 #define REJCINETWORK(opt, neg, val) \
862 if (neg && p[0] == opt) { \
863 if ((len -= CILEN_NETN) < 0) \
865 GETCHAR(citype, p); \
867 if (cilen != CILEN_NETN || \
870 GETLONG(cilong, p); \
876 #define REJCICHARS(opt, neg, val, cnt) \
877 if (neg && p[0] == opt) { \
878 int indx, count = cnt; \
879 len -= (count + 2); \
882 GETCHAR(citype, p); \
884 if (cilen != (count + 2) || \
887 for (indx = 0; indx < count; ++indx) {\
888 GETCHAR(cichar, p); \
889 if (cichar != ((u_char *) &val)[indx]) \
897 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
898 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen(val))
900 #define REJCIVOID(opt, neg) \
901 if (neg && p[0] == opt) { \
902 if ((len -= CILEN_VOID) < 0) \
904 GETCHAR(citype, p); \
906 if (cilen != CILEN_VOID || citype != opt) \
911 /* a reject for RIP/SAP is invalid since we don't send it and you can't
912 reject something which is not sent. (You can NAK, but you can't REJ.) */
913 #define REJCIPROTO(opt, neg, val, bit) \
914 if (neg && p[0] == opt) { \
915 if ((len -= CILEN_PROTOCOL) < 0) \
917 GETCHAR(citype, p); \
919 if (cilen != CILEN_PROTOCOL) \
921 GETSHORT(cishort, p); \
922 if (cishort != to_external (val) || cishort == RIP_SAP) \
927 * Any Rejected CIs must be in exactly the same order that we sent.
928 * Check packet length and CI length at each step.
929 * If we find any deviations, then this packet is bad.
934 REJCINETWORK (IPX_NETWORK_NUMBER, try.neg_nn, try.our_network);
935 REJCINODE (IPX_NODE_NUMBER, try.neg_node, try.our_node);
936 REJCINAME (IPX_ROUTER_NAME, try.neg_name, try.name);
937 REJCIPROTO (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
939 * This is the end of the record.
942 if (f->state != OPENED)
948 * The frame is invalid at this point.
950 IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
955 * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
957 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
958 * appropriately. If reject_if_disagree is non-zero, doesn't return
959 * CONFNAK; returns CONFREJ if it can't return CONFACK.
962 ipxcp_reqci(f, inp, len, reject_if_disagree)
964 u_char *inp; /* Requested CIs */
965 int *len; /* Length of requested CIs */
966 int reject_if_disagree;
968 u_char *cip, *next; /* Pointer to current and next CIs */
969 u_short cilen, citype; /* Parsed len, type */
970 u_short cishort; /* Parsed short value */
971 u_int32_t cinetwork; /* Parsed address values */
972 int rc = CONFACK; /* Final packet return code */
973 int orc; /* Individual option return code */
974 u_char *p; /* Pointer to next char to parse */
975 u_char *ucp = inp; /* Pointer to current output char */
976 int l = *len; /* Length left */
979 * Reset all his options.
981 BZERO(ho, sizeof(*ho));
984 * Process all his options.
988 orc = CONFACK; /* Assume success */
989 cip = p = next; /* Remember begining of CI */
990 if (l < 2 || /* Not enough data for CI header or */
991 p[1] < 2 || /* CI length too small or */
992 p[1] > l) { /* CI length too big? */
993 IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
994 orc = CONFREJ; /* Reject bad CI */
995 cilen = l; /* Reject till end of packet */
996 l = 0; /* Don't loop again */
999 GETCHAR(citype, p); /* Parse CI type */
1000 GETCHAR(cilen, p); /* Parse CI length */
1001 l -= cilen; /* Adjust remaining length */
1002 next += cilen; /* Step to next CI */
1004 switch (citype) { /* Check CI type */
1006 * The network number must match. Choose the larger of the two.
1008 case IPX_NETWORK_NUMBER:
1009 /* if we wont negotiate the network number or the length is wrong
1010 then reject the option */
1011 if ( !ao->neg_nn || cilen != CILEN_NETN ) {
1015 GETLONG(cinetwork, p);
1017 /* If the network numbers match then acknowledge them. */
1018 if (cinetwork != 0) {
1019 ho->his_network = cinetwork;
1021 if (wo->our_network == cinetwork)
1024 * If the network number is not given or we don't accept their change or
1025 * the network number is too small then NAK it.
1027 if (! ao->accept_network || cinetwork < wo->our_network) {
1028 DECPTR (sizeof (u_int32_t), p);
1029 PUTLONG (wo->our_network, p);
1035 * The peer sent '0' for the network. Give it ours if we have one.
1037 if (go->our_network != 0) {
1038 DECPTR (sizeof (u_int32_t), p);
1039 PUTLONG (wo->our_network, p);
1042 * We don't have one. Reject the value.
1049 * The node number is required
1051 case IPX_NODE_NUMBER:
1052 /* if we wont negotiate the node number or the length is wrong
1053 then reject the option */
1054 if ( cilen != CILEN_NODEN ) {
1059 copy_node (p, ho->his_node);
1062 * If the remote does not have a number and we do then NAK it with the value
1063 * which we have for it. (We never have a default value of zero.)
1065 if (zero_node (ho->his_node)) {
1067 copy_node (wo->his_node, p);
1068 INCPTR (sizeof (wo->his_node), p);
1072 * If you have given me the expected network node number then I'll accept
1075 if (compare_node (wo->his_node, ho->his_node)) {
1078 INCPTR (sizeof (wo->his_node), p);
1082 * If his node number is the same as ours then ask him to try the next
1085 if (compare_node (ho->his_node, go->our_node)) {
1086 inc_node (ho->his_node);
1088 copy_node (ho->his_node, p);
1089 INCPTR (sizeof (wo->his_node), p);
1093 * If we don't accept a new value then NAK it.
1095 if (! ao->accept_remote) {
1096 copy_node (wo->his_node, p);
1097 INCPTR (sizeof (wo->his_node), p);
1103 INCPTR (sizeof (wo->his_node), p);
1106 * Compression is not desired at this time. It is always rejected.
1108 case IPX_COMPRESSION_PROTOCOL:
1112 * The routing protocol is a bitmask of various types. Any combination
1113 * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1114 * routing protocol must be specified only once.
1116 case IPX_ROUTER_PROTOCOL:
1117 if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
1122 GETSHORT (cishort, p);
1124 if (wo->neg_router == 0) {
1126 wo->router = BIT(IPX_NONE);
1129 if ((cishort == IPX_NONE && ho->router != 0) ||
1130 (ho->router & BIT(IPX_NONE))) {
1135 cishort = BIT(cishort);
1136 if (ho->router & cishort) {
1141 ho->router |= cishort;
1144 /* Finally do not allow a router protocol which we do not
1147 if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1150 if (cishort == BIT(NLSP) &&
1151 (ao->router & BIT(RIP_SAP)) &&
1156 protocol = IPX_NONE;
1158 DECPTR (sizeof (u_int16_t), p);
1159 PUTSHORT (protocol, p);
1164 * The router name is advisorary. Just accept it if it is not too large.
1166 case IPX_ROUTER_NAME:
1167 if (cilen >= CILEN_NAME) {
1168 int name_size = cilen - CILEN_NAME;
1169 if (name_size > sizeof (ho->name))
1170 name_size = sizeof (ho->name) - 1;
1171 memset (ho->name, 0, sizeof (ho->name));
1172 memcpy (ho->name, p, name_size);
1173 ho->name [name_size] = '\0';
1181 * This is advisorary.
1184 if (cilen != CILEN_COMPLETE)
1187 ho->neg_complete = 1;
1192 * All other entries are not known at this time.
1199 if (orc == CONFACK && /* Good CI */
1200 rc != CONFACK) /* but prior CI wasnt? */
1201 continue; /* Don't send this one */
1203 if (orc == CONFNAK) { /* Nak this CI? */
1204 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1205 orc = CONFREJ; /* Get tough if so */
1206 if (rc == CONFREJ) /* Rejecting prior CI? */
1207 continue; /* Don't send this one */
1208 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1209 rc = CONFNAK; /* Not anymore... */
1210 ucp = inp; /* Backup */
1214 if (orc == CONFREJ && /* Reject this CI */
1215 rc != CONFREJ) { /* but no prior ones? */
1217 ucp = inp; /* Backup */
1220 /* Need to move CI? */
1222 BCOPY(cip, ucp, cilen); /* Move it */
1224 /* Update output pointer */
1229 * If we aren't rejecting this packet, and we want to negotiate
1230 * their address, and they didn't send their address, then we
1231 * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1232 * input buffer is long enough that we can append the extra
1236 if (rc != CONFREJ && !ho->neg_node &&
1237 wo->req_nn && !reject_if_disagree) {
1238 if (rc == CONFACK) {
1240 wo->req_nn = 0; /* don't ask again */
1241 ucp = inp; /* reset pointer */
1244 if (zero_node (wo->his_node))
1245 inc_node (wo->his_node);
1247 PUTCHAR (IPX_NODE_NUMBER, ucp);
1248 PUTCHAR (CILEN_NODEN, ucp);
1249 copy_node (wo->his_node, ucp);
1250 INCPTR (sizeof (wo->his_node), ucp);
1253 *len = ucp - inp; /* Compute output length */
1254 IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));
1255 return (rc); /* Return final code */
1259 * ipxcp_up - IPXCP has come UP.
1261 * Configure the IP network interface appropriately and bring it up.
1270 IPXCPDEBUG(("ipxcp: up"));
1272 /* The default router protocol is RIP/SAP. */
1273 if (ho->router == 0)
1274 ho->router = BIT(RIP_SAP);
1276 if (go->router == 0)
1277 go->router = BIT(RIP_SAP);
1279 /* Fetch the network number */
1281 ho->his_network = wo->his_network;
1284 copy_node (wo->his_node, ho->his_node);
1286 if (!wo->neg_node && !go->neg_node)
1287 copy_node (wo->our_node, go->our_node);
1289 if (zero_node (go->our_node)) {
1290 static char errmsg[] = "Could not determine local IPX node address";
1293 ipxcp_close(f->unit, errmsg);
1297 go->network = go->our_network;
1298 if (ho->his_network != 0 && ho->his_network > go->network)
1299 go->network = ho->his_network;
1301 if (go->network == 0) {
1302 static char errmsg[] = "Can not determine network number";
1305 ipxcp_close (unit, errmsg);
1309 /* bring the interface up */
1312 warn("sifup failed (IPX)");
1313 ipxcp_close(unit, "Interface configuration failed");
1318 /* set the network number for IPX */
1319 if (!sipxfaddr(unit, go->network, go->our_node)) {
1321 warn("sipxfaddr failed");
1322 ipxcp_close(unit, "Interface configuration failed");
1326 np_up(f->unit, PPP_IPX);
1329 * Execute the ipx-up script, like this:
1330 * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1333 ipxcp_script (f, _PATH_IPXUP);
1337 * ipxcp_down - IPXCP has gone DOWN.
1339 * Take the IP network interface down, clear its addresses
1340 * and delete routes through it.
1347 IPXCPDEBUG(("ipxcp: down"));
1352 np_down(f->unit, PPP_IPX);
1354 sifnpmode(f->unit, PPP_IPX, NPMODE_DROP);
1356 ipxcp_script (f, _PATH_IPXDOWN);
1361 * ipxcp_finished - possibly shut down the lower layers.
1367 np_finished(f->unit, PPP_IPX);
1372 * ipxcp_script - Execute a script with arguments
1373 * interface-name tty-name speed local-IPX remote-IPX networks.
1376 ipxcp_script(f, script)
1380 char strspeed[32], strlocal[32], strremote[32];
1381 char strnetwork[32], strpid[32];
1382 char *argv[14], strproto_lcl[32], strproto_rmt[32];
1384 slprintf(strpid, sizeof(strpid), "%d", getpid());
1385 slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);
1387 strproto_lcl[0] = '\0';
1388 if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1389 if (go->router & BIT(RIP_SAP))
1390 strlcpy (strproto_lcl, "RIP ", sizeof(strproto_lcl));
1391 if (go->router & BIT(NLSP))
1392 strlcat (strproto_lcl, "NLSP ", sizeof(strproto_lcl));
1395 if (strproto_lcl[0] == '\0')
1396 strlcpy (strproto_lcl, "NONE ", sizeof(strproto_lcl));
1398 strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1400 strproto_rmt[0] = '\0';
1401 if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1402 if (ho->router & BIT(RIP_SAP))
1403 strlcpy (strproto_rmt, "RIP ", sizeof(strproto_rmt));
1404 if (ho->router & BIT(NLSP))
1405 strlcat (strproto_rmt, "NLSP ", sizeof(strproto_rmt));
1408 if (strproto_rmt[0] == '\0')
1409 strlcpy (strproto_rmt, "NONE ", sizeof(strproto_rmt));
1411 strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1413 strlcpy (strnetwork, ipx_ntoa (go->network), sizeof(strnetwork));
1415 slprintf (strlocal, sizeof(strlocal), "%0.6B", go->our_node);
1417 slprintf (strremote, sizeof(strremote), "%0.6B", ho->his_node);
1423 argv[4] = strnetwork;
1425 argv[6] = strremote;
1426 argv[7] = strproto_lcl;
1427 argv[8] = strproto_rmt;
1429 argv[10] = ho->name;
1433 run_program(script, argv, 0, NULL, NULL);
1437 * ipxcp_printpkt - print the contents of an IPXCP packet.
1439 static char *ipxcp_codenames[] = {
1440 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1441 "TermReq", "TermAck", "CodeRej"
1445 ipxcp_printpkt(p, plen, printer, arg)
1448 void (*printer) __P((void *, char *, ...));
1451 int code, id, len, olen;
1452 u_char *pstart, *optend;
1456 if (plen < HEADERLEN)
1462 if (len < HEADERLEN || len > plen)
1465 if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1466 printer(arg, " %s", ipxcp_codenames[code-1]);
1468 printer(arg, " code=0x%x", code);
1469 printer(arg, " id=0x%x", id);
1476 /* print option list */
1481 if (olen < CILEN_VOID || olen > len) {
1488 case IPX_NETWORK_NUMBER:
1489 if (olen == CILEN_NETN) {
1492 printer (arg, "network %s", ipx_ntoa (cilong));
1495 case IPX_NODE_NUMBER:
1496 if (olen == CILEN_NODEN) {
1498 printer (arg, "node ");
1499 while (p < optend) {
1501 printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1505 case IPX_COMPRESSION_PROTOCOL:
1506 if (olen == CILEN_COMPRESS) {
1508 GETSHORT (cishort, p);
1509 printer (arg, "compression %d", (int) cishort);
1512 case IPX_ROUTER_PROTOCOL:
1513 if (olen == CILEN_PROTOCOL) {
1515 GETSHORT (cishort, p);
1516 printer (arg, "router proto %d", (int) cishort);
1519 case IPX_ROUTER_NAME:
1520 if (olen >= CILEN_NAME) {
1522 printer (arg, "router name \"");
1523 while (p < optend) {
1525 if (code >= 0x20 && code <= 0x7E)
1526 printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1528 printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1530 printer (arg, "\"");
1534 if (olen == CILEN_COMPLETE) {
1536 printer (arg, "complete");
1543 while (p < optend) {
1545 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1553 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1555 print_string(p, len, printer, arg);
1562 /* print the rest of the bytes in the packet */
1563 for (; len > 0; --len) {
1565 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1570 #endif /* ifdef IPX_CHANGE */