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 static char rcsid[] = "$Id: ipxcp.c,v 1.15 1999/04/01 07:08:47 paulus Exp $";
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
40 #include "pathnames.h"
44 ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */
45 ipxcp_options ipxcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
46 ipxcp_options ipxcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
47 ipxcp_options ipxcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
49 #define wo (&ipxcp_wantoptions[0])
50 #define ao (&ipxcp_allowoptions[0])
51 #define go (&ipxcp_gotoptions[0])
52 #define ho (&ipxcp_hisoptions[0])
55 * Callbacks for fsm code. (CI = Configuration Information)
57 static void ipxcp_resetci __P((fsm *)); /* Reset our CI */
58 static int ipxcp_cilen __P((fsm *)); /* Return length of our CI */
59 static void ipxcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
60 static int ipxcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
61 static int ipxcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
62 static int ipxcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
63 static int ipxcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
64 static void ipxcp_up __P((fsm *)); /* We're UP */
65 static void ipxcp_down __P((fsm *)); /* We're DOWN */
66 static void ipxcp_finished __P((fsm *)); /* Don't need lower layer */
67 static void ipxcp_script __P((fsm *, char *)); /* Run an up/down script */
69 fsm ipxcp_fsm[NUM_PPP]; /* IPXCP fsm structure */
71 static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */
72 ipxcp_resetci, /* Reset our Configuration Information */
73 ipxcp_cilen, /* Length of our Configuration Information */
74 ipxcp_addci, /* Add our Configuration Information */
75 ipxcp_ackci, /* ACK our Configuration Information */
76 ipxcp_nakci, /* NAK our Configuration Information */
77 ipxcp_rejci, /* Reject our Configuration Information */
78 ipxcp_reqci, /* Request peer's Configuration Information */
79 ipxcp_up, /* Called when fsm reaches OPENED state */
80 ipxcp_down, /* Called when fsm leaves OPENED state */
81 NULL, /* Called when we want the lower layer up */
82 ipxcp_finished, /* Called when we want the lower layer down */
83 NULL, /* Called when Protocol-Reject received */
84 NULL, /* Retransmission is necessary */
85 NULL, /* Called to handle protocol-specific codes */
86 "IPXCP" /* String name of protocol */
90 * Command-line options.
92 static int setipxnode __P((char **));
93 static int setipxname __P((char **));
95 static option_t ipxcp_option_list[] = {
96 { "ipx", o_bool, &ipxcp_protent.enabled_flag,
97 "Enable IPXCP (and IPX)", 1 },
98 { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
99 "Enable IPXCP (and IPX)", 1 },
100 { "noipx", o_bool, &ipxcp_protent.enabled_flag,
101 "Disable IPXCP (and IPX)" },
102 { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
103 "Disable IPXCP (and IPX)" } ,
104 { "ipx-network", o_uint32, &ipxcp_wantoptions[0].our_network,
105 "Set our IPX network number", 0, &ipxcp_wantoptions[0].neg_nn },
106 { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
107 "Accept peer IPX network number", 1,
108 &ipxcp_allowoptions[0].accept_network },
109 { "ipx-node", o_special, setipxnode,
110 "Set IPX node number" },
111 { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
112 "Accept our IPX address", 1,
113 &ipxcp_allowoptions[0].accept_local },
114 { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
115 "Accept peer's IPX address", 1,
116 &ipxcp_allowoptions[0].accept_remote },
117 { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
118 "Set IPX routing proto number", 0,
119 &ipxcp_wantoptions[0].neg_router },
120 { "ipx-router-name", o_special, setipxname,
121 "Set IPX router name" },
122 { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
123 "Set timeout for IPXCP" },
124 { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
125 "Set max #xmits for IPXCP term-reqs" },
126 { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
127 "Set max #xmits for IPXCP conf-reqs" },
128 { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
129 "Set max #conf-naks for IPXCP" },
134 * Protocol entry points.
137 static void ipxcp_init __P((int));
138 static void ipxcp_open __P((int));
139 static void ipxcp_close __P((int, char *));
140 static void ipxcp_lowerup __P((int));
141 static void ipxcp_lowerdown __P((int));
142 static void ipxcp_input __P((int, u_char *, int));
143 static void ipxcp_protrej __P((int));
144 static int ipxcp_printpkt __P((u_char *, int,
145 void (*) __P((void *, char *, ...)), void *));
147 struct protent ipxcp_protent = {
168 * Lengths of configuration options.
172 #define CILEN_COMPLETE 2 /* length of complete option */
173 #define CILEN_NETN 6 /* network number length option */
174 #define CILEN_NODEN 8 /* node number length option */
175 #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
176 #define CILEN_NAME 3 /* Minimum length of router name */
177 #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
179 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
180 (x) == CONFNAK ? "NAK" : "REJ")
182 static int ipxcp_is_up;
184 static char *ipx_ntoa __P((u_int32_t));
186 /* Used in printing the node number */
187 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
189 /* Used to generate the proper bit mask */
190 #define BIT(num) (1 << (num))
193 * Convert from internal to external notation
197 to_external(internal)
202 if (internal & BIT(IPX_NONE) )
211 * Make a string representation of a network IP address.
219 slprintf(b, sizeof(b), "%x", ipxaddr);
225 setipxnodevalue(src,dst)
232 if (!isxdigit (*src))
235 for (indx = 0; indx < 5; ++indx) {
237 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
240 item = toupper (*src) - '0';
244 dst[5] = (dst[5] << 4) | item;
256 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
257 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
259 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
261 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
264 ipxcp_wantoptions[0].neg_node = 1;
268 option_error("invalid parameter '%s' for ipx-node option", *argv);
276 char *dest = ipxcp_wantoptions[0].name;
281 ipxcp_wantoptions[0].neg_name = 1;
282 ipxcp_allowoptions[0].neg_name = 1;
283 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
288 if (! isalnum (ch) && ch != '_') {
289 option_error("IPX router name must be alphanumeric or _");
293 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
294 option_error("IPX router name is limited to %d characters",
295 sizeof (ipxcp_wantoptions[0].name) - 1);
299 dest[count++] = toupper (ch);
306 * ipxcp_init - Initialize IPXCP.
312 fsm *f = &ipxcp_fsm[unit];
315 f->protocol = PPP_IPXCP;
316 f->callbacks = &ipxcp_callbacks;
317 fsm_init(&ipxcp_fsm[unit]);
319 memset (wo->name, 0, sizeof (wo->name));
320 memset (wo->our_node, 0, sizeof (wo->our_node));
321 memset (wo->his_node, 0, sizeof (wo->his_node));
324 wo->neg_complete = 1;
330 ao->neg_complete = 1;
333 ao->accept_local = 0;
334 ao->accept_remote = 0;
335 ao->accept_network = 0;
342 * Copy the node number
349 memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
353 * Compare node numbers
357 compare_node (src, dst)
360 return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
364 * Is the node number zero?
372 for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
373 if (node [indx] != 0)
379 * Increment the node number
393 PUTLONG (magic_num, outp);
397 * ipxcp_open - IPXCP is allowed to come up.
403 fsm_open(&ipxcp_fsm[unit]);
407 * ipxcp_close - Take IPXCP down.
410 ipxcp_close(unit, reason)
414 fsm_close(&ipxcp_fsm[unit], reason);
419 * ipxcp_lowerup - The lower layer is up.
425 fsm_lowerup(&ipxcp_fsm[unit]);
430 * ipxcp_lowerdown - The lower layer is down.
433 ipxcp_lowerdown(unit)
436 fsm_lowerdown(&ipxcp_fsm[unit]);
441 * ipxcp_input - Input IPXCP packet.
444 ipxcp_input(unit, p, len)
449 fsm_input(&ipxcp_fsm[unit], p, len);
454 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
456 * Pretend the lower layer went down, so we shut up.
462 fsm_lowerdown(&ipxcp_fsm[unit]);
467 * ipxcp_resetci - Reset our CI.
473 wo->req_node = wo->neg_node && ao->neg_node;
474 wo->req_nn = wo->neg_nn && ao->neg_nn;
476 if (wo->our_network == 0) {
478 ao->accept_network = 1;
481 * If our node number is zero then change it.
483 if (zero_node (wo->our_node)) {
484 inc_node (wo->our_node);
485 ao->accept_local = 1;
489 * If his node number is zero then change it.
491 if (zero_node (wo->his_node)) {
492 inc_node (wo->his_node);
493 ao->accept_remote = 1;
496 * If no routing agent was specified then we do RIP/SAP according to the
497 * RFC documents. If you have specified something then OK. Otherwise, we
500 if (ao->router == 0) {
501 ao->router |= BIT(RIP_SAP);
502 wo->router |= BIT(RIP_SAP);
505 /* Always specify a routing protocol unless it was REJected. */
508 * Start with these default values
514 * ipxcp_cilen - Return length of our CI.
523 len = go->neg_nn ? CILEN_NETN : 0;
524 len += go->neg_node ? CILEN_NODEN : 0;
525 len += go->neg_name ? CILEN_NAME + strlen (go->name) - 1 : 0;
527 /* RFC says that defaults should not be included. */
528 if (go->neg_router && to_external(go->router) != RIP_SAP)
529 len += CILEN_PROTOCOL;
536 * ipxcp_addci - Add our desired CIs to a packet.
539 ipxcp_addci(f, ucp, lenp)
545 * Add the options to the record.
548 PUTCHAR (IPX_NETWORK_NUMBER, ucp);
549 PUTCHAR (CILEN_NETN, ucp);
550 PUTLONG (go->our_network, ucp);
555 PUTCHAR (IPX_NODE_NUMBER, ucp);
556 PUTCHAR (CILEN_NODEN, ucp);
557 for (indx = 0; indx < sizeof (go->our_node); ++indx)
558 PUTCHAR (go->our_node[indx], ucp);
562 int cilen = strlen (go->name);
564 PUTCHAR (IPX_ROUTER_NAME, ucp);
565 PUTCHAR (CILEN_NAME + cilen - 1, ucp);
566 for (indx = 0; indx < cilen; ++indx)
567 PUTCHAR (go->name [indx], ucp);
570 if (go->neg_router) {
571 short external = to_external (go->router);
572 if (external != RIP_SAP) {
573 PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
574 PUTCHAR (CILEN_PROTOCOL, ucp);
575 PUTSHORT (external, ucp);
581 * ipxcp_ackci - Ack our CIs.
588 ipxcp_ackci(f, p, len)
593 u_short cilen, citype, cishort;
597 #define ACKCIVOID(opt, neg) \
599 if ((len -= CILEN_VOID) < 0) \
601 GETCHAR(citype, p); \
603 if (cilen != CILEN_VOID || \
608 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
610 #define ACKCICHARS(opt, neg, val, cnt) \
612 int indx, count = cnt; \
613 len -= (count + 2); \
616 GETCHAR(citype, p); \
618 if (cilen != (count + 2) || \
621 for (indx = 0; indx < count; ++indx) {\
622 GETCHAR(cichar, p); \
623 if (cichar != ((u_char *) &val)[indx]) \
630 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
631 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen(val))
633 #define ACKCINETWORK(opt, neg, val) \
635 if ((len -= CILEN_NETN) < 0) \
637 GETCHAR(citype, p); \
639 if (cilen != CILEN_NETN || \
642 GETLONG(cilong, p); \
647 #define ACKCIPROTO(opt, neg, val) \
651 GETCHAR(citype, p); \
653 if (cilen != CILEN_PROTOCOL || citype != opt) \
658 GETSHORT(cishort, p); \
659 if (cishort != to_external (val) || cishort == RIP_SAP) \
663 * Process the ACK frame in the order in which the frame was assembled
666 ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
667 ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
668 ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
670 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
672 * This is the end of the record.
678 * The frame is invalid
680 IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
685 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
686 * This should not modify any state if the Nak is bad
687 * or if IPXCP is in the OPENED state.
695 ipxcp_nakci(f, p, len)
700 u_char citype, cilen, *next;
703 ipxcp_options no; /* options we've seen Naks for */
704 ipxcp_options try; /* options to request next time */
706 BZERO(&no, sizeof(no));
709 while (len > CILEN_VOID) {
715 next = &p [cilen - CILEN_VOID];
718 case IPX_NETWORK_NUMBER:
719 if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
724 if (l && ao->accept_network)
728 case IPX_NODE_NUMBER:
729 if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
733 if (!zero_node (p) && ao->accept_local &&
734 ! compare_node (p, ho->his_node))
735 copy_node (p, try.our_node);
738 /* This has never been sent. Ignore the NAK frame */
739 case IPX_COMPRESSION_PROTOCOL:
742 case IPX_ROUTER_PROTOCOL:
743 if (!go->neg_router || (cilen < CILEN_PROTOCOL))
747 if (s > 15) /* This is just bad, but ignore for now. */
751 if (no.router & s) /* duplicate NAKs are always bad */
754 if (no.router == 0) /* Reset on first NAK only */
762 /* These, according to the RFC, must never be NAKed. */
763 case IPX_ROUTER_NAME:
767 /* These are for options which we have not seen. */
775 * Do not permit the peer to force a router protocol which we do not
776 * support. However, default to the condition that will accept "NONE".
778 try.router &= (ao->router | BIT(IPX_NONE));
779 if (try.router == 0 && ao->router != 0)
780 try.router = BIT(IPX_NONE);
786 * OK, the Nak is good. Now we can update state.
787 * If there are any options left, we ignore them.
789 if (f->state != OPENED)
795 IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
800 * ipxcp_rejci - Reject some of our CIs.
803 ipxcp_rejci(f, p, len)
808 u_short cilen, citype, cishort;
811 ipxcp_options try; /* options to request next time */
813 #define REJCINETWORK(opt, neg, val) \
814 if (neg && p[0] == opt) { \
815 if ((len -= CILEN_NETN) < 0) \
817 GETCHAR(citype, p); \
819 if (cilen != CILEN_NETN || \
822 GETLONG(cilong, p); \
828 #define REJCICHARS(opt, neg, val, cnt) \
829 if (neg && p[0] == opt) { \
830 int indx, count = cnt; \
831 len -= (count + 2); \
834 GETCHAR(citype, p); \
836 if (cilen != (count + 2) || \
839 for (indx = 0; indx < count; ++indx) {\
840 GETCHAR(cichar, p); \
841 if (cichar != ((u_char *) &val)[indx]) \
849 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
850 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen(val))
852 #define REJCIVOID(opt, neg) \
853 if (neg && p[0] == opt) { \
854 if ((len -= CILEN_VOID) < 0) \
856 GETCHAR(citype, p); \
858 if (cilen != CILEN_VOID || citype != opt) \
863 /* a reject for RIP/SAP is invalid since we don't send it and you can't
864 reject something which is not sent. (You can NAK, but you can't REJ.) */
865 #define REJCIPROTO(opt, neg, val, bit) \
866 if (neg && p[0] == opt) { \
867 if ((len -= CILEN_PROTOCOL) < 0) \
869 GETCHAR(citype, p); \
871 if (cilen != CILEN_PROTOCOL) \
873 GETSHORT(cishort, p); \
874 if (cishort != to_external (val) || cishort == RIP_SAP) \
879 * Any Rejected CIs must be in exactly the same order that we sent.
880 * Check packet length and CI length at each step.
881 * If we find any deviations, then this packet is bad.
886 REJCINETWORK (IPX_NETWORK_NUMBER, try.neg_nn, try.our_network);
887 REJCINODE (IPX_NODE_NUMBER, try.neg_node, try.our_node);
888 REJCINAME (IPX_ROUTER_NAME, try.neg_name, try.name);
889 REJCIPROTO (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
891 * This is the end of the record.
894 if (f->state != OPENED)
900 * The frame is invalid at this point.
902 IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
907 * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
909 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
910 * appropriately. If reject_if_disagree is non-zero, doesn't return
911 * CONFNAK; returns CONFREJ if it can't return CONFACK.
914 ipxcp_reqci(f, inp, len, reject_if_disagree)
916 u_char *inp; /* Requested CIs */
917 int *len; /* Length of requested CIs */
918 int reject_if_disagree;
920 u_char *cip, *next; /* Pointer to current and next CIs */
921 u_short cilen, citype; /* Parsed len, type */
922 u_short cishort; /* Parsed short value */
923 u_int32_t cinetwork; /* Parsed address values */
924 int rc = CONFACK; /* Final packet return code */
925 int orc; /* Individual option return code */
926 u_char *p; /* Pointer to next char to parse */
927 u_char *ucp = inp; /* Pointer to current output char */
928 int l = *len; /* Length left */
931 * Reset all his options.
933 BZERO(ho, sizeof(*ho));
936 * Process all his options.
940 orc = CONFACK; /* Assume success */
941 cip = p = next; /* Remember begining of CI */
942 if (l < 2 || /* Not enough data for CI header or */
943 p[1] < 2 || /* CI length too small or */
944 p[1] > l) { /* CI length too big? */
945 IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
946 orc = CONFREJ; /* Reject bad CI */
947 cilen = l; /* Reject till end of packet */
948 l = 0; /* Don't loop again */
951 GETCHAR(citype, p); /* Parse CI type */
952 GETCHAR(cilen, p); /* Parse CI length */
953 l -= cilen; /* Adjust remaining length */
954 next += cilen; /* Step to next CI */
956 switch (citype) { /* Check CI type */
958 * The network number must match. Choose the larger of the two.
960 case IPX_NETWORK_NUMBER:
961 /* if we wont negotiate the network number or the length is wrong
962 then reject the option */
963 if ( !ao->neg_nn || cilen != CILEN_NETN ) {
967 GETLONG(cinetwork, p);
969 /* If the network numbers match then acknowledge them. */
970 if (cinetwork != 0) {
971 ho->his_network = cinetwork;
973 if (wo->our_network == cinetwork)
976 * If the network number is not given or we don't accept their change or
977 * the network number is too small then NAK it.
979 if (! ao->accept_network || cinetwork < wo->our_network) {
980 DECPTR (sizeof (u_int32_t), p);
981 PUTLONG (wo->our_network, p);
987 * The peer sent '0' for the network. Give it ours if we have one.
989 if (go->our_network != 0) {
990 DECPTR (sizeof (u_int32_t), p);
991 PUTLONG (wo->our_network, p);
994 * We don't have one. Reject the value.
1001 * The node number is required
1003 case IPX_NODE_NUMBER:
1004 /* if we wont negotiate the node number or the length is wrong
1005 then reject the option */
1006 if ( cilen != CILEN_NODEN ) {
1011 copy_node (p, ho->his_node);
1014 * If the remote does not have a number and we do then NAK it with the value
1015 * which we have for it. (We never have a default value of zero.)
1017 if (zero_node (ho->his_node)) {
1019 copy_node (wo->his_node, p);
1020 INCPTR (sizeof (wo->his_node), p);
1024 * If you have given me the expected network node number then I'll accept
1027 if (compare_node (wo->his_node, ho->his_node)) {
1030 INCPTR (sizeof (wo->his_node), p);
1034 * If his node number is the same as ours then ask him to try the next
1037 if (compare_node (ho->his_node, go->our_node)) {
1038 inc_node (ho->his_node);
1040 copy_node (ho->his_node, p);
1041 INCPTR (sizeof (wo->his_node), p);
1045 * If we don't accept a new value then NAK it.
1047 if (! ao->accept_remote) {
1048 copy_node (wo->his_node, p);
1049 INCPTR (sizeof (wo->his_node), p);
1055 INCPTR (sizeof (wo->his_node), p);
1058 * Compression is not desired at this time. It is always rejected.
1060 case IPX_COMPRESSION_PROTOCOL:
1064 * The routing protocol is a bitmask of various types. Any combination
1065 * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1066 * routing protocol must be specified only once.
1068 case IPX_ROUTER_PROTOCOL:
1069 if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
1074 GETSHORT (cishort, p);
1076 if (wo->neg_router == 0) {
1078 wo->router = BIT(IPX_NONE);
1081 if ((cishort == IPX_NONE && ho->router != 0) ||
1082 (ho->router & BIT(IPX_NONE))) {
1087 cishort = BIT(cishort);
1088 if (ho->router & cishort) {
1093 ho->router |= cishort;
1096 /* Finally do not allow a router protocol which we do not
1099 if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1102 if (cishort == BIT(NLSP) &&
1103 (ao->router & BIT(RIP_SAP)) &&
1108 protocol = IPX_NONE;
1110 DECPTR (sizeof (u_int16_t), p);
1111 PUTSHORT (protocol, p);
1116 * The router name is advisorary. Just accept it if it is not too large.
1118 case IPX_ROUTER_NAME:
1119 if (cilen >= CILEN_NAME) {
1120 int name_size = cilen - CILEN_NAME;
1121 if (name_size > sizeof (ho->name))
1122 name_size = sizeof (ho->name) - 1;
1123 memset (ho->name, 0, sizeof (ho->name));
1124 memcpy (ho->name, p, name_size);
1125 ho->name [name_size] = '\0';
1133 * This is advisorary.
1136 if (cilen != CILEN_COMPLETE)
1139 ho->neg_complete = 1;
1144 * All other entries are not known at this time.
1151 if (orc == CONFACK && /* Good CI */
1152 rc != CONFACK) /* but prior CI wasnt? */
1153 continue; /* Don't send this one */
1155 if (orc == CONFNAK) { /* Nak this CI? */
1156 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1157 orc = CONFREJ; /* Get tough if so */
1158 if (rc == CONFREJ) /* Rejecting prior CI? */
1159 continue; /* Don't send this one */
1160 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1161 rc = CONFNAK; /* Not anymore... */
1162 ucp = inp; /* Backup */
1166 if (orc == CONFREJ && /* Reject this CI */
1167 rc != CONFREJ) { /* but no prior ones? */
1169 ucp = inp; /* Backup */
1172 /* Need to move CI? */
1174 BCOPY(cip, ucp, cilen); /* Move it */
1176 /* Update output pointer */
1181 * If we aren't rejecting this packet, and we want to negotiate
1182 * their address, and they didn't send their address, then we
1183 * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1184 * input buffer is long enough that we can append the extra
1188 if (rc != CONFREJ && !ho->neg_node &&
1189 wo->req_nn && !reject_if_disagree) {
1190 if (rc == CONFACK) {
1192 wo->req_nn = 0; /* don't ask again */
1193 ucp = inp; /* reset pointer */
1196 if (zero_node (wo->his_node))
1197 inc_node (wo->his_node);
1199 PUTCHAR (IPX_NODE_NUMBER, ucp);
1200 PUTCHAR (CILEN_NODEN, ucp);
1201 copy_node (wo->his_node, ucp);
1202 INCPTR (sizeof (wo->his_node), ucp);
1205 *len = ucp - inp; /* Compute output length */
1206 IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));
1207 return (rc); /* Return final code */
1211 * ipxcp_up - IPXCP has come UP.
1213 * Configure the IP network interface appropriately and bring it up.
1222 IPXCPDEBUG(("ipxcp: up"));
1224 /* The default router protocol is RIP/SAP. */
1225 if (ho->router == 0)
1226 ho->router = BIT(RIP_SAP);
1228 if (go->router == 0)
1229 go->router = BIT(RIP_SAP);
1231 /* Fetch the network number */
1233 ho->his_network = wo->his_network;
1236 copy_node (wo->his_node, ho->his_node);
1238 if (!wo->neg_node && !go->neg_node)
1239 copy_node (wo->our_node, go->our_node);
1241 if (zero_node (go->our_node)) {
1242 static char errmsg[] = "Could not determine local IPX node address";
1245 ipxcp_close(f->unit, errmsg);
1249 go->network = go->our_network;
1250 if (ho->his_network != 0 && ho->his_network > go->network)
1251 go->network = ho->his_network;
1253 if (go->network == 0) {
1254 static char errmsg[] = "Can not determine network number";
1257 ipxcp_close (unit, errmsg);
1261 /* bring the interface up */
1264 warn("sifup failed (IPX)");
1265 ipxcp_close(unit, "Interface configuration failed");
1269 /* set the network number for IPX */
1270 if (!sipxfaddr(unit, go->network, go->our_node)) {
1272 warn("sipxfaddr failed");
1273 ipxcp_close(unit, "Interface configuration failed");
1278 np_up(f->unit, PPP_IPX);
1281 * Execute the ipx-up script, like this:
1282 * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1285 ipxcp_script (f, _PATH_IPXUP);
1289 * ipxcp_down - IPXCP has gone DOWN.
1291 * Take the IP network interface down, clear its addresses
1292 * and delete routes through it.
1299 IPXCPDEBUG(("ipxcp: down"));
1303 np_down(f->unit, PPP_IPX);
1305 cipxfaddr (f->unit);
1307 ipxcp_script (f, _PATH_IPXDOWN);
1312 * ipxcp_finished - possibly shut down the lower layers.
1318 np_finished(f->unit, PPP_IPX);
1323 * ipxcp_script - Execute a script with arguments
1324 * interface-name tty-name speed local-IPX remote-IPX networks.
1327 ipxcp_script(f, script)
1331 char strspeed[32], strlocal[32], strremote[32];
1332 char strnetwork[32], strpid[32];
1333 char *argv[14], strproto_lcl[32], strproto_rmt[32];
1335 slprintf(strpid, sizeof(strpid), "%d", getpid());
1336 slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);
1338 strproto_lcl[0] = '\0';
1339 if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1340 if (go->router & BIT(RIP_SAP))
1341 strlcpy (strproto_lcl, "RIP ", sizeof(strproto_lcl));
1342 if (go->router & BIT(NLSP))
1343 strlcat (strproto_lcl, "NLSP ", sizeof(strproto_lcl));
1346 if (strproto_lcl[0] == '\0')
1347 strlcpy (strproto_lcl, "NONE ", sizeof(strproto_lcl));
1349 strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1351 strproto_rmt[0] = '\0';
1352 if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1353 if (ho->router & BIT(RIP_SAP))
1354 strlcpy (strproto_rmt, "RIP ", sizeof(strproto_rmt));
1355 if (ho->router & BIT(NLSP))
1356 strlcat (strproto_rmt, "NLSP ", sizeof(strproto_rmt));
1359 if (strproto_rmt[0] == '\0')
1360 strlcpy (strproto_rmt, "NONE ", sizeof(strproto_rmt));
1362 strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1364 strlcpy (strnetwork, ipx_ntoa (go->network), sizeof(strnetwork));
1366 slprintf (strlocal, sizeof(strlocal), "%0.6B", go->our_node);
1368 slprintf (strremote, sizeof(strremote), "%0.6B", ho->his_node);
1374 argv[4] = strnetwork;
1376 argv[6] = strremote;
1377 argv[7] = strproto_lcl;
1378 argv[8] = strproto_rmt;
1380 argv[10] = ho->name;
1384 run_program(script, argv, 0, NULL, NULL);
1388 * ipxcp_printpkt - print the contents of an IPXCP packet.
1390 static char *ipxcp_codenames[] = {
1391 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1392 "TermReq", "TermAck", "CodeRej"
1396 ipxcp_printpkt(p, plen, printer, arg)
1399 void (*printer) __P((void *, char *, ...));
1402 int code, id, len, olen;
1403 u_char *pstart, *optend;
1407 if (plen < HEADERLEN)
1413 if (len < HEADERLEN || len > plen)
1416 if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1417 printer(arg, " %s", ipxcp_codenames[code-1]);
1419 printer(arg, " code=0x%x", code);
1420 printer(arg, " id=0x%x", id);
1427 /* print option list */
1432 if (olen < CILEN_VOID || olen > len) {
1439 case IPX_NETWORK_NUMBER:
1440 if (olen == CILEN_NETN) {
1443 printer (arg, "network %s", ipx_ntoa (cilong));
1446 case IPX_NODE_NUMBER:
1447 if (olen == CILEN_NODEN) {
1449 printer (arg, "node ");
1450 while (p < optend) {
1452 printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1456 case IPX_COMPRESSION_PROTOCOL:
1457 if (olen == CILEN_COMPRESS) {
1459 GETSHORT (cishort, p);
1460 printer (arg, "compression %d", (int) cishort);
1463 case IPX_ROUTER_PROTOCOL:
1464 if (olen == CILEN_PROTOCOL) {
1466 GETSHORT (cishort, p);
1467 printer (arg, "router proto %d", (int) cishort);
1470 case IPX_ROUTER_NAME:
1471 if (olen >= CILEN_NAME) {
1473 printer (arg, "router name \"");
1474 while (p < optend) {
1476 if (code >= 0x20 && code <= 0x7E)
1477 printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1479 printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1481 printer (arg, "\"");
1485 if (olen == CILEN_COMPLETE) {
1487 printer (arg, "complete");
1494 while (p < optend) {
1496 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1504 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1506 print_string(p, len, printer, arg);
1513 /* print the rest of the bytes in the packet */
1514 for (; len > 0; --len) {
1516 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1521 #endif /* ifdef IPX_CHANGE */