2 * ipxcp.c - PPP IPX Control Protocol.
4 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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
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
25 * Pittsburgh, PA 15213-3890
26 * (412) 268-4387, fax: (412) 268-7395
27 * tech-transfer@andrew.cmu.edu
29 * 4. Redistributions of any form whatsoever must retain the following
31 * "This product includes software developed by Computing Services
32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
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.
45 #define RCSID "$Id: ipxcp.c,v 1.24 2005/08/25 23:59:34 paulus Exp $"
55 #include <sys/types.h>
56 #include <sys/socket.h>
57 #include <netinet/in.h>
62 #include "pathnames.h"
65 static const char rcsid
[] = RCSID
;
68 ipxcp_options ipxcp_wantoptions
[NUM_PPP
]; /* Options that we want to request */
69 ipxcp_options ipxcp_gotoptions
[NUM_PPP
]; /* Options that peer ack'd */
70 ipxcp_options ipxcp_allowoptions
[NUM_PPP
]; /* Options we allow peer to request */
71 ipxcp_options ipxcp_hisoptions
[NUM_PPP
]; /* Options that we ack'd */
73 #define wo (&ipxcp_wantoptions[0])
74 #define ao (&ipxcp_allowoptions[0])
75 #define go (&ipxcp_gotoptions[0])
76 #define ho (&ipxcp_hisoptions[0])
79 * Callbacks for fsm code. (CI = Configuration Information)
81 static void ipxcp_resetci
__P((fsm
*)); /* Reset our CI */
82 static int ipxcp_cilen
__P((fsm
*)); /* Return length of our CI */
83 static void ipxcp_addci
__P((fsm
*, u_char
*, int *)); /* Add our CI */
84 static int ipxcp_ackci
__P((fsm
*, u_char
*, int)); /* Peer ack'd our CI */
85 static int ipxcp_nakci
__P((fsm
*, u_char
*, int, int));/* Peer nak'd our CI */
86 static int ipxcp_rejci
__P((fsm
*, u_char
*, int)); /* Peer rej'd our CI */
87 static int ipxcp_reqci
__P((fsm
*, u_char
*, int *, int)); /* Rcv CI */
88 static void ipxcp_up
__P((fsm
*)); /* We're UP */
89 static void ipxcp_down
__P((fsm
*)); /* We're DOWN */
90 static void ipxcp_finished
__P((fsm
*)); /* Don't need lower layer */
91 static void ipxcp_script
__P((fsm
*, char *)); /* Run an up/down script */
93 fsm ipxcp_fsm
[NUM_PPP
]; /* IPXCP fsm structure */
95 static fsm_callbacks ipxcp_callbacks
= { /* IPXCP callback routines */
96 ipxcp_resetci
, /* Reset our Configuration Information */
97 ipxcp_cilen
, /* Length of our Configuration Information */
98 ipxcp_addci
, /* Add our Configuration Information */
99 ipxcp_ackci
, /* ACK our Configuration Information */
100 ipxcp_nakci
, /* NAK our Configuration Information */
101 ipxcp_rejci
, /* Reject our Configuration Information */
102 ipxcp_reqci
, /* Request peer's Configuration Information */
103 ipxcp_up
, /* Called when fsm reaches OPENED state */
104 ipxcp_down
, /* Called when fsm leaves OPENED state */
105 NULL
, /* Called when we want the lower layer up */
106 ipxcp_finished
, /* Called when we want the lower layer down */
107 NULL
, /* Called when Protocol-Reject received */
108 NULL
, /* Retransmission is necessary */
109 NULL
, /* Called to handle protocol-specific codes */
110 "IPXCP" /* String name of protocol */
114 * Command-line options.
116 static int setipxnode
__P((char **));
117 static void printipxnode
__P((option_t
*,
118 void (*)(void *, char *, ...), void *));
119 static int setipxname
__P((char **));
121 static option_t ipxcp_option_list
[] = {
122 { "ipx", o_bool
, &ipxcp_protent
.enabled_flag
,
123 "Enable IPXCP (and IPX)", OPT_PRIO
| 1 },
124 { "+ipx", o_bool
, &ipxcp_protent
.enabled_flag
,
125 "Enable IPXCP (and IPX)", OPT_PRIOSUB
| OPT_ALIAS
| 1 },
126 { "noipx", o_bool
, &ipxcp_protent
.enabled_flag
,
127 "Disable IPXCP (and IPX)", OPT_PRIOSUB
},
128 { "-ipx", o_bool
, &ipxcp_protent
.enabled_flag
,
129 "Disable IPXCP (and IPX)", OPT_PRIOSUB
| OPT_ALIAS
},
131 { "ipx-network", o_uint32
, &ipxcp_wantoptions
[0].our_network
,
132 "Set our IPX network number", OPT_PRIO
, &ipxcp_wantoptions
[0].neg_nn
},
134 { "ipxcp-accept-network", o_bool
, &ipxcp_wantoptions
[0].accept_network
,
135 "Accept peer IPX network number", 1,
136 &ipxcp_allowoptions
[0].accept_network
},
138 { "ipx-node", o_special
, (void *)setipxnode
,
139 "Set IPX node number", OPT_A2PRINTER
, (void *)printipxnode
},
141 { "ipxcp-accept-local", o_bool
, &ipxcp_wantoptions
[0].accept_local
,
142 "Accept our IPX address", 1,
143 &ipxcp_allowoptions
[0].accept_local
},
145 { "ipxcp-accept-remote", o_bool
, &ipxcp_wantoptions
[0].accept_remote
,
146 "Accept peer's IPX address", 1,
147 &ipxcp_allowoptions
[0].accept_remote
},
149 { "ipx-routing", o_int
, &ipxcp_wantoptions
[0].router
,
150 "Set IPX routing proto number", OPT_PRIO
,
151 &ipxcp_wantoptions
[0].neg_router
},
153 { "ipx-router-name", o_special
, setipxname
,
154 "Set IPX router name", OPT_PRIO
| OPT_A2STRVAL
| OPT_STATIC
,
155 &ipxcp_wantoptions
[0].name
},
157 { "ipxcp-restart", o_int
, &ipxcp_fsm
[0].timeouttime
,
158 "Set timeout for IPXCP", OPT_PRIO
},
159 { "ipxcp-max-terminate", o_int
, &ipxcp_fsm
[0].maxtermtransmits
,
160 "Set max #xmits for IPXCP term-reqs", OPT_PRIO
},
161 { "ipxcp-max-configure", o_int
, &ipxcp_fsm
[0].maxconfreqtransmits
,
162 "Set max #xmits for IPXCP conf-reqs", OPT_PRIO
},
163 { "ipxcp-max-failure", o_int
, &ipxcp_fsm
[0].maxnakloops
,
164 "Set max #conf-naks for IPXCP", OPT_PRIO
},
170 * Protocol entry points.
173 static void ipxcp_init
__P((int));
174 static void ipxcp_open
__P((int));
175 static void ipxcp_close
__P((int, char *));
176 static void ipxcp_lowerup
__P((int));
177 static void ipxcp_lowerdown
__P((int));
178 static void ipxcp_input
__P((int, u_char
*, int));
179 static void ipxcp_protrej
__P((int));
180 static int ipxcp_printpkt
__P((u_char
*, int,
181 void (*) __P((void *, char *, ...)), void *));
183 struct protent ipxcp_protent
= {
204 * Lengths of configuration options.
208 #define CILEN_COMPLETE 2 /* length of complete option */
209 #define CILEN_NETN 6 /* network number length option */
210 #define CILEN_NODEN 8 /* node number length option */
211 #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
212 #define CILEN_NAME 3 /* Minimum length of router name */
213 #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
215 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
216 (x) == CONFNAK ? "NAK" : "REJ")
218 static int ipxcp_is_up
;
220 static char *ipx_ntoa
__P((u_int32_t
));
222 /* Used in printing the node number */
223 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
225 /* Used to generate the proper bit mask */
226 #define BIT(num) (1 << (num))
229 * Convert from internal to external notation
233 to_external(internal
)
238 if (internal
& BIT(IPX_NONE
) )
247 * Make a string representation of a network IP address.
255 slprintf(b
, sizeof(b
), "%x", ipxaddr
);
261 setipxnodevalue(src
,dst
)
268 if (!isxdigit (*src
))
271 for (indx
= 0; indx
< 5; ++indx
) {
273 dst
[indx
] |= (dst
[indx
+ 1] >> 4) & 0x0F;
276 item
= toupper (*src
) - '0';
280 dst
[5] = (dst
[5] << 4) | item
;
286 static int ipx_prio_our
, ipx_prio_his
;
297 memset (our_node
, 0, 6);
298 memset (his_node
, 0, 6);
300 end
= setipxnodevalue (*argv
, our_node
);
303 end
= setipxnodevalue (++end
, his_node
);
307 ipxcp_wantoptions
[0].neg_node
= 1;
308 if (option_priority
>= ipx_prio_our
) {
309 memcpy(&ipxcp_wantoptions
[0].our_node
[0], our_node
, 6);
310 ipx_prio_our
= option_priority
;
312 if (have_his
&& option_priority
>= ipx_prio_his
) {
313 memcpy(&ipxcp_wantoptions
[0].his_node
[0], his_node
, 6);
314 ipx_prio_his
= option_priority
;
319 option_error("invalid parameter '%s' for ipx-node option", *argv
);
324 printipxnode(opt
, printer
, arg
)
326 void (*printer
) __P((void *, char *, ...));
331 p
= ipxcp_wantoptions
[0].our_node
;
333 printer(arg
, "%.2x%.2x%.2x%.2x%.2x%.2x",
334 p
[0], p
[1], p
[2], p
[3], p
[4], p
[5]);
336 p
= ipxcp_wantoptions
[0].his_node
;
338 printer(arg
, "%.2x%.2x%.2x%.2x%.2x%.2x",
339 p
[0], p
[1], p
[2], p
[3], p
[4], p
[5]);
346 u_char
*dest
= ipxcp_wantoptions
[0].name
;
351 ipxcp_wantoptions
[0].neg_name
= 1;
352 ipxcp_allowoptions
[0].neg_name
= 1;
353 memset (dest
, '\0', sizeof (ipxcp_wantoptions
[0].name
));
358 if (! isalnum (ch
) && ch
!= '_') {
359 option_error("IPX router name must be alphanumeric or _");
363 if (count
>= sizeof (ipxcp_wantoptions
[0].name
) - 1) {
364 option_error("IPX router name is limited to %d characters",
365 sizeof (ipxcp_wantoptions
[0].name
) - 1);
369 dest
[count
++] = toupper (ch
);
377 * ipxcp_init - Initialize IPXCP.
383 fsm
*f
= &ipxcp_fsm
[unit
];
386 f
->protocol
= PPP_IPXCP
;
387 f
->callbacks
= &ipxcp_callbacks
;
388 fsm_init(&ipxcp_fsm
[unit
]);
390 memset (wo
->name
, 0, sizeof (wo
->name
));
391 memset (wo
->our_node
, 0, sizeof (wo
->our_node
));
392 memset (wo
->his_node
, 0, sizeof (wo
->his_node
));
395 wo
->neg_complete
= 1;
401 ao
->neg_complete
= 1;
404 ao
->accept_local
= 0;
405 ao
->accept_remote
= 0;
406 ao
->accept_network
= 0;
413 * Copy the node number
420 memcpy (dst
, src
, sizeof (ipxcp_wantoptions
[0].our_node
));
424 * Compare node numbers
428 compare_node (src
, dst
)
431 return memcmp (dst
, src
, sizeof (ipxcp_wantoptions
[0].our_node
)) == 0;
435 * Is the node number zero?
443 for (indx
= 0; indx
< sizeof (ipxcp_wantoptions
[0].our_node
); ++indx
)
444 if (node
[indx
] != 0)
450 * Increment the node number
464 PUTLONG (magic_num
, outp
);
468 * ipxcp_open - IPXCP is allowed to come up.
474 fsm_open(&ipxcp_fsm
[unit
]);
478 * ipxcp_close - Take IPXCP down.
481 ipxcp_close(unit
, reason
)
485 fsm_close(&ipxcp_fsm
[unit
], reason
);
490 * ipxcp_lowerup - The lower layer is up.
496 fsm_lowerup(&ipxcp_fsm
[unit
]);
501 * ipxcp_lowerdown - The lower layer is down.
504 ipxcp_lowerdown(unit
)
507 fsm_lowerdown(&ipxcp_fsm
[unit
]);
512 * ipxcp_input - Input IPXCP packet.
515 ipxcp_input(unit
, p
, len
)
520 fsm_input(&ipxcp_fsm
[unit
], p
, len
);
525 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
527 * Pretend the lower layer went down, so we shut up.
533 fsm_lowerdown(&ipxcp_fsm
[unit
]);
538 * ipxcp_resetci - Reset our CI.
544 wo
->req_node
= wo
->neg_node
&& ao
->neg_node
;
545 wo
->req_nn
= wo
->neg_nn
&& ao
->neg_nn
;
547 if (wo
->our_network
== 0) {
549 ao
->accept_network
= 1;
552 * If our node number is zero then change it.
554 if (zero_node (wo
->our_node
)) {
555 inc_node (wo
->our_node
);
556 ao
->accept_local
= 1;
560 * If his node number is zero then change it.
562 if (zero_node (wo
->his_node
)) {
563 inc_node (wo
->his_node
);
564 ao
->accept_remote
= 1;
567 * If no routing agent was specified then we do RIP/SAP according to the
568 * RFC documents. If you have specified something then OK. Otherwise, we
571 if (ao
->router
== 0) {
572 ao
->router
|= BIT(RIP_SAP
);
573 wo
->router
|= BIT(RIP_SAP
);
576 /* Always specify a routing protocol unless it was REJected. */
579 * Start with these default values
585 * ipxcp_cilen - Return length of our CI.
594 len
= go
->neg_nn
? CILEN_NETN
: 0;
595 len
+= go
->neg_node
? CILEN_NODEN
: 0;
596 len
+= go
->neg_name
? CILEN_NAME
+ strlen ((char *)go
->name
) - 1 : 0;
598 /* RFC says that defaults should not be included. */
599 if (go
->neg_router
&& to_external(go
->router
) != RIP_SAP
)
600 len
+= CILEN_PROTOCOL
;
607 * ipxcp_addci - Add our desired CIs to a packet.
610 ipxcp_addci(f
, ucp
, lenp
)
616 * Add the options to the record.
619 PUTCHAR (IPX_NETWORK_NUMBER
, ucp
);
620 PUTCHAR (CILEN_NETN
, ucp
);
621 PUTLONG (go
->our_network
, ucp
);
626 PUTCHAR (IPX_NODE_NUMBER
, ucp
);
627 PUTCHAR (CILEN_NODEN
, ucp
);
628 for (indx
= 0; indx
< sizeof (go
->our_node
); ++indx
)
629 PUTCHAR (go
->our_node
[indx
], ucp
);
633 int cilen
= strlen ((char *)go
->name
);
635 PUTCHAR (IPX_ROUTER_NAME
, ucp
);
636 PUTCHAR (CILEN_NAME
+ cilen
- 1, ucp
);
637 for (indx
= 0; indx
< cilen
; ++indx
)
638 PUTCHAR (go
->name
[indx
], ucp
);
641 if (go
->neg_router
) {
642 short external
= to_external (go
->router
);
643 if (external
!= RIP_SAP
) {
644 PUTCHAR (IPX_ROUTER_PROTOCOL
, ucp
);
645 PUTCHAR (CILEN_PROTOCOL
, ucp
);
646 PUTSHORT (external
, ucp
);
652 * ipxcp_ackci - Ack our CIs.
659 ipxcp_ackci(f
, p
, len
)
664 u_short cilen
, citype
, cishort
;
668 #define ACKCIVOID(opt, neg) \
670 if ((len -= CILEN_VOID) < 0) \
672 GETCHAR(citype, p); \
674 if (cilen != CILEN_VOID || \
679 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
681 #define ACKCICHARS(opt, neg, val, cnt) \
683 int indx, count = cnt; \
684 len -= (count + 2); \
687 GETCHAR(citype, p); \
689 if (cilen != (count + 2) || \
692 for (indx = 0; indx < count; ++indx) {\
693 GETCHAR(cichar, p); \
694 if (cichar != ((u_char *) &val)[indx]) \
701 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
702 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen((char *)val))
704 #define ACKCINETWORK(opt, neg, val) \
706 if ((len -= CILEN_NETN) < 0) \
708 GETCHAR(citype, p); \
710 if (cilen != CILEN_NETN || \
713 GETLONG(cilong, p); \
718 #define ACKCIPROTO(opt, neg, val) \
722 GETCHAR(citype, p); \
724 if (cilen != CILEN_PROTOCOL || citype != opt) \
729 GETSHORT(cishort, p); \
730 if (cishort != to_external (val) || cishort == RIP_SAP) \
734 * Process the ACK frame in the order in which the frame was assembled
737 ACKCINETWORK (IPX_NETWORK_NUMBER
, go
->neg_nn
, go
->our_network
);
738 ACKCINODE (IPX_NODE_NUMBER
, go
->neg_node
, go
->our_node
);
739 ACKCINAME (IPX_ROUTER_NAME
, go
->neg_name
, go
->name
);
741 ACKCIPROTO (IPX_ROUTER_PROTOCOL
, go
->neg_router
, go
->router
);
743 * This is the end of the record.
749 * The frame is invalid
751 IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
756 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
757 * This should not modify any state if the Nak is bad
758 * or if IPXCP is in the OPENED state.
766 ipxcp_nakci(f
, p
, len
, treat_as_reject
)
772 u_char citype
, cilen
, *next
;
775 ipxcp_options no
; /* options we've seen Naks for */
776 ipxcp_options
try; /* options to request next time */
778 BZERO(&no
, sizeof(no
));
781 while (len
>= CILEN_VOID
) {
785 if (cilen
< CILEN_VOID
|| len
< 0)
787 next
= &p
[cilen
- CILEN_VOID
];
790 case IPX_NETWORK_NUMBER
:
791 if (!go
->neg_nn
|| no
.neg_nn
|| (cilen
!= CILEN_NETN
))
798 else if (l
&& ao
->accept_network
)
802 case IPX_NODE_NUMBER
:
803 if (!go
->neg_node
|| no
.neg_node
|| (cilen
!= CILEN_NODEN
))
809 else if (!zero_node (p
) && ao
->accept_local
&&
810 ! compare_node (p
, ho
->his_node
))
811 copy_node (p
, try.our_node
);
814 /* This has never been sent. Ignore the NAK frame */
815 case IPX_COMPRESSION_PROTOCOL
:
818 case IPX_ROUTER_PROTOCOL
:
819 if (!go
->neg_router
|| (cilen
< CILEN_PROTOCOL
))
823 if (s
> 15) /* This is just bad, but ignore for now. */
827 if (no
.router
& s
) /* duplicate NAKs are always bad */
830 if (no
.router
== 0) /* Reset on first NAK only */
838 /* These, according to the RFC, must never be NAKed. */
839 case IPX_ROUTER_NAME
:
843 /* These are for options which we have not seen. */
851 * Do not permit the peer to force a router protocol which we do not
852 * support. However, default to the condition that will accept "NONE".
854 try.router
&= (ao
->router
| BIT(IPX_NONE
));
855 if (try.router
== 0 && ao
->router
!= 0)
856 try.router
= BIT(IPX_NONE
);
862 * OK, the Nak is good. Now we can update state.
863 * If there are any options left, we ignore them.
865 if (f
->state
!= OPENED
)
871 IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
876 * ipxcp_rejci - Reject some of our CIs.
879 ipxcp_rejci(f
, p
, len
)
884 u_short cilen
, citype
, cishort
;
887 ipxcp_options
try; /* options to request next time */
889 #define REJCINETWORK(opt, neg, val) \
890 if (neg && p[0] == opt) { \
891 if ((len -= CILEN_NETN) < 0) \
893 GETCHAR(citype, p); \
895 if (cilen != CILEN_NETN || \
898 GETLONG(cilong, p); \
904 #define REJCICHARS(opt, neg, val, cnt) \
905 if (neg && p[0] == opt) { \
906 int indx, count = cnt; \
907 len -= (count + 2); \
910 GETCHAR(citype, p); \
912 if (cilen != (count + 2) || \
915 for (indx = 0; indx < count; ++indx) {\
916 GETCHAR(cichar, p); \
917 if (cichar != ((u_char *) &val)[indx]) \
925 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
926 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen((char *)val))
928 #define REJCIVOID(opt, neg) \
929 if (neg && p[0] == opt) { \
930 if ((len -= CILEN_VOID) < 0) \
932 GETCHAR(citype, p); \
934 if (cilen != CILEN_VOID || citype != opt) \
939 /* a reject for RIP/SAP is invalid since we don't send it and you can't
940 reject something which is not sent. (You can NAK, but you can't REJ.) */
941 #define REJCIPROTO(opt, neg, val, bit) \
942 if (neg && p[0] == opt) { \
943 if ((len -= CILEN_PROTOCOL) < 0) \
945 GETCHAR(citype, p); \
947 if (cilen != CILEN_PROTOCOL) \
949 GETSHORT(cishort, p); \
950 if (cishort != to_external (val) || cishort == RIP_SAP) \
955 * Any Rejected CIs must be in exactly the same order that we sent.
956 * Check packet length and CI length at each step.
957 * If we find any deviations, then this packet is bad.
962 REJCINETWORK (IPX_NETWORK_NUMBER
, try.neg_nn
, try.our_network
);
963 REJCINODE (IPX_NODE_NUMBER
, try.neg_node
, try.our_node
);
964 REJCINAME (IPX_ROUTER_NAME
, try.neg_name
, try.name
);
965 REJCIPROTO (IPX_ROUTER_PROTOCOL
, try.neg_router
, try.router
, 0);
967 * This is the end of the record.
970 if (f
->state
!= OPENED
)
976 * The frame is invalid at this point.
978 IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
983 * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
985 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
986 * appropriately. If reject_if_disagree is non-zero, doesn't return
987 * CONFNAK; returns CONFREJ if it can't return CONFACK.
990 ipxcp_reqci(f
, inp
, len
, reject_if_disagree
)
992 u_char
*inp
; /* Requested CIs */
993 int *len
; /* Length of requested CIs */
994 int reject_if_disagree
;
996 u_char
*cip
, *next
; /* Pointer to current and next CIs */
997 u_short cilen
, citype
; /* Parsed len, type */
998 u_short cishort
; /* Parsed short value */
999 u_int32_t cinetwork
; /* Parsed address values */
1000 int rc
= CONFACK
; /* Final packet return code */
1001 int orc
; /* Individual option return code */
1002 u_char
*p
; /* Pointer to next char to parse */
1003 u_char
*ucp
= inp
; /* Pointer to current output char */
1004 int l
= *len
; /* Length left */
1007 * Reset all his options.
1009 BZERO(ho
, sizeof(*ho
));
1012 * Process all his options.
1016 orc
= CONFACK
; /* Assume success */
1017 cip
= p
= next
; /* Remember begining of CI */
1018 if (l
< 2 || /* Not enough data for CI header or */
1019 p
[1] < 2 || /* CI length too small or */
1020 p
[1] > l
) { /* CI length too big? */
1021 IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
1022 orc
= CONFREJ
; /* Reject bad CI */
1023 cilen
= l
; /* Reject till end of packet */
1024 l
= 0; /* Don't loop again */
1027 GETCHAR(citype
, p
); /* Parse CI type */
1028 GETCHAR(cilen
, p
); /* Parse CI length */
1029 l
-= cilen
; /* Adjust remaining length */
1030 next
+= cilen
; /* Step to next CI */
1032 switch (citype
) { /* Check CI type */
1034 * The network number must match. Choose the larger of the two.
1036 case IPX_NETWORK_NUMBER
:
1037 /* if we wont negotiate the network number or the length is wrong
1038 then reject the option */
1039 if ( !ao
->neg_nn
|| cilen
!= CILEN_NETN
) {
1043 GETLONG(cinetwork
, p
);
1045 /* If the network numbers match then acknowledge them. */
1046 if (cinetwork
!= 0) {
1047 ho
->his_network
= cinetwork
;
1049 if (wo
->our_network
== cinetwork
)
1052 * If the network number is not given or we don't accept their change or
1053 * the network number is too small then NAK it.
1055 if (! ao
->accept_network
|| cinetwork
< wo
->our_network
) {
1056 DECPTR (sizeof (u_int32_t
), p
);
1057 PUTLONG (wo
->our_network
, p
);
1063 * The peer sent '0' for the network. Give it ours if we have one.
1065 if (go
->our_network
!= 0) {
1066 DECPTR (sizeof (u_int32_t
), p
);
1067 PUTLONG (wo
->our_network
, p
);
1070 * We don't have one. Reject the value.
1077 * The node number is required
1079 case IPX_NODE_NUMBER
:
1080 /* if we wont negotiate the node number or the length is wrong
1081 then reject the option */
1082 if ( cilen
!= CILEN_NODEN
) {
1087 copy_node (p
, ho
->his_node
);
1090 * If the remote does not have a number and we do then NAK it with the value
1091 * which we have for it. (We never have a default value of zero.)
1093 if (zero_node (ho
->his_node
)) {
1095 copy_node (wo
->his_node
, p
);
1096 INCPTR (sizeof (wo
->his_node
), p
);
1100 * If you have given me the expected network node number then I'll accept
1103 if (compare_node (wo
->his_node
, ho
->his_node
)) {
1106 INCPTR (sizeof (wo
->his_node
), p
);
1110 * If his node number is the same as ours then ask him to try the next
1113 if (compare_node (ho
->his_node
, go
->our_node
)) {
1114 inc_node (ho
->his_node
);
1116 copy_node (ho
->his_node
, p
);
1117 INCPTR (sizeof (wo
->his_node
), p
);
1121 * If we don't accept a new value then NAK it.
1123 if (! ao
->accept_remote
) {
1124 copy_node (wo
->his_node
, p
);
1125 INCPTR (sizeof (wo
->his_node
), p
);
1131 INCPTR (sizeof (wo
->his_node
), p
);
1134 * Compression is not desired at this time. It is always rejected.
1136 case IPX_COMPRESSION_PROTOCOL
:
1140 * The routing protocol is a bitmask of various types. Any combination
1141 * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1142 * routing protocol must be specified only once.
1144 case IPX_ROUTER_PROTOCOL
:
1145 if ( !ao
->neg_router
|| cilen
< CILEN_PROTOCOL
) {
1150 GETSHORT (cishort
, p
);
1152 if (wo
->neg_router
== 0) {
1154 wo
->router
= BIT(IPX_NONE
);
1157 if ((cishort
== IPX_NONE
&& ho
->router
!= 0) ||
1158 (ho
->router
& BIT(IPX_NONE
))) {
1163 cishort
= BIT(cishort
);
1164 if (ho
->router
& cishort
) {
1169 ho
->router
|= cishort
;
1172 /* Finally do not allow a router protocol which we do not
1175 if ((cishort
& (ao
->router
| BIT(IPX_NONE
))) == 0) {
1178 if (cishort
== BIT(NLSP
) &&
1179 (ao
->router
& BIT(RIP_SAP
)) &&
1184 protocol
= IPX_NONE
;
1186 DECPTR (sizeof (u_int16_t
), p
);
1187 PUTSHORT (protocol
, p
);
1192 * The router name is advisorary. Just accept it if it is not too large.
1194 case IPX_ROUTER_NAME
:
1195 if (cilen
>= CILEN_NAME
) {
1196 int name_size
= cilen
- CILEN_NAME
;
1197 if (name_size
> sizeof (ho
->name
))
1198 name_size
= sizeof (ho
->name
) - 1;
1199 memset (ho
->name
, 0, sizeof (ho
->name
));
1200 memcpy (ho
->name
, p
, name_size
);
1201 ho
->name
[name_size
] = '\0';
1209 * This is advisorary.
1212 if (cilen
!= CILEN_COMPLETE
)
1215 ho
->neg_complete
= 1;
1220 * All other entries are not known at this time.
1227 if (orc
== CONFACK
&& /* Good CI */
1228 rc
!= CONFACK
) /* but prior CI wasnt? */
1229 continue; /* Don't send this one */
1231 if (orc
== CONFNAK
) { /* Nak this CI? */
1232 if (reject_if_disagree
) /* Getting fed up with sending NAKs? */
1233 orc
= CONFREJ
; /* Get tough if so */
1234 if (rc
== CONFREJ
) /* Rejecting prior CI? */
1235 continue; /* Don't send this one */
1236 if (rc
== CONFACK
) { /* Ack'd all prior CIs? */
1237 rc
= CONFNAK
; /* Not anymore... */
1238 ucp
= inp
; /* Backup */
1242 if (orc
== CONFREJ
&& /* Reject this CI */
1243 rc
!= CONFREJ
) { /* but no prior ones? */
1245 ucp
= inp
; /* Backup */
1248 /* Need to move CI? */
1250 BCOPY(cip
, ucp
, cilen
); /* Move it */
1252 /* Update output pointer */
1257 * If we aren't rejecting this packet, and we want to negotiate
1258 * their address, and they didn't send their address, then we
1259 * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1260 * input buffer is long enough that we can append the extra
1264 if (rc
!= CONFREJ
&& !ho
->neg_node
&&
1265 wo
->req_nn
&& !reject_if_disagree
) {
1266 if (rc
== CONFACK
) {
1268 wo
->req_nn
= 0; /* don't ask again */
1269 ucp
= inp
; /* reset pointer */
1272 if (zero_node (wo
->his_node
))
1273 inc_node (wo
->his_node
);
1275 PUTCHAR (IPX_NODE_NUMBER
, ucp
);
1276 PUTCHAR (CILEN_NODEN
, ucp
);
1277 copy_node (wo
->his_node
, ucp
);
1278 INCPTR (sizeof (wo
->his_node
), ucp
);
1281 *len
= ucp
- inp
; /* Compute output length */
1282 IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc
)));
1283 return (rc
); /* Return final code */
1287 * ipxcp_up - IPXCP has come UP.
1289 * Configure the IP network interface appropriately and bring it up.
1298 IPXCPDEBUG(("ipxcp: up"));
1300 /* The default router protocol is RIP/SAP. */
1301 if (ho
->router
== 0)
1302 ho
->router
= BIT(RIP_SAP
);
1304 if (go
->router
== 0)
1305 go
->router
= BIT(RIP_SAP
);
1307 /* Fetch the network number */
1309 ho
->his_network
= wo
->his_network
;
1312 copy_node (wo
->his_node
, ho
->his_node
);
1314 if (!wo
->neg_node
&& !go
->neg_node
)
1315 copy_node (wo
->our_node
, go
->our_node
);
1317 if (zero_node (go
->our_node
)) {
1318 static char errmsg
[] = "Could not determine local IPX node address";
1321 ipxcp_close(f
->unit
, errmsg
);
1325 go
->network
= go
->our_network
;
1326 if (ho
->his_network
!= 0 && ho
->his_network
> go
->network
)
1327 go
->network
= ho
->his_network
;
1329 if (go
->network
== 0) {
1330 static char errmsg
[] = "Can not determine network number";
1333 ipxcp_close (unit
, errmsg
);
1337 /* bring the interface up */
1340 warn("sifup failed (IPX)");
1341 ipxcp_close(unit
, "Interface configuration failed");
1346 /* set the network number for IPX */
1347 if (!sipxfaddr(unit
, go
->network
, go
->our_node
)) {
1349 warn("sipxfaddr failed");
1350 ipxcp_close(unit
, "Interface configuration failed");
1354 np_up(f
->unit
, PPP_IPX
);
1357 * Execute the ipx-up script, like this:
1358 * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1361 ipxcp_script (f
, _PATH_IPXUP
);
1365 * ipxcp_down - IPXCP has gone DOWN.
1367 * Take the IP network interface down, clear its addresses
1368 * and delete routes through it.
1375 IPXCPDEBUG(("ipxcp: down"));
1380 np_down(f
->unit
, PPP_IPX
);
1382 sifnpmode(f
->unit
, PPP_IPX
, NPMODE_DROP
);
1384 ipxcp_script (f
, _PATH_IPXDOWN
);
1389 * ipxcp_finished - possibly shut down the lower layers.
1395 np_finished(f
->unit
, PPP_IPX
);
1400 * ipxcp_script - Execute a script with arguments
1401 * interface-name tty-name speed local-IPX remote-IPX networks.
1404 ipxcp_script(f
, script
)
1408 char strspeed
[32], strlocal
[32], strremote
[32];
1409 char strnetwork
[32], strpid
[32];
1410 char *argv
[14], strproto_lcl
[32], strproto_rmt
[32];
1412 slprintf(strpid
, sizeof(strpid
), "%d", getpid());
1413 slprintf(strspeed
, sizeof(strspeed
),"%d", baud_rate
);
1415 strproto_lcl
[0] = '\0';
1416 if (go
->neg_router
&& ((go
->router
& BIT(IPX_NONE
)) == 0)) {
1417 if (go
->router
& BIT(RIP_SAP
))
1418 strlcpy (strproto_lcl
, "RIP ", sizeof(strproto_lcl
));
1419 if (go
->router
& BIT(NLSP
))
1420 strlcat (strproto_lcl
, "NLSP ", sizeof(strproto_lcl
));
1423 if (strproto_lcl
[0] == '\0')
1424 strlcpy (strproto_lcl
, "NONE ", sizeof(strproto_lcl
));
1426 strproto_lcl
[strlen (strproto_lcl
)-1] = '\0';
1428 strproto_rmt
[0] = '\0';
1429 if (ho
->neg_router
&& ((ho
->router
& BIT(IPX_NONE
)) == 0)) {
1430 if (ho
->router
& BIT(RIP_SAP
))
1431 strlcpy (strproto_rmt
, "RIP ", sizeof(strproto_rmt
));
1432 if (ho
->router
& BIT(NLSP
))
1433 strlcat (strproto_rmt
, "NLSP ", sizeof(strproto_rmt
));
1436 if (strproto_rmt
[0] == '\0')
1437 strlcpy (strproto_rmt
, "NONE ", sizeof(strproto_rmt
));
1439 strproto_rmt
[strlen (strproto_rmt
)-1] = '\0';
1441 strlcpy (strnetwork
, ipx_ntoa (go
->network
), sizeof(strnetwork
));
1443 slprintf (strlocal
, sizeof(strlocal
), "%0.6B", go
->our_node
);
1445 slprintf (strremote
, sizeof(strremote
), "%0.6B", ho
->his_node
);
1451 argv
[4] = strnetwork
;
1453 argv
[6] = strremote
;
1454 argv
[7] = strproto_lcl
;
1455 argv
[8] = strproto_rmt
;
1456 argv
[9] = (char *)go
->name
;
1457 argv
[10] = (char *)ho
->name
;
1461 run_program(script
, argv
, 0, NULL
, NULL
, 0);
1465 * ipxcp_printpkt - print the contents of an IPXCP packet.
1467 static char *ipxcp_codenames
[] = {
1468 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1469 "TermReq", "TermAck", "CodeRej"
1473 ipxcp_printpkt(p
, plen
, printer
, arg
)
1476 void (*printer
) __P((void *, char *, ...));
1479 int code
, id
, len
, olen
;
1480 u_char
*pstart
, *optend
;
1484 if (plen
< HEADERLEN
)
1490 if (len
< HEADERLEN
|| len
> plen
)
1493 if (code
>= 1 && code
<= sizeof(ipxcp_codenames
) / sizeof(char *))
1494 printer(arg
, " %s", ipxcp_codenames
[code
-1]);
1496 printer(arg
, " code=0x%x", code
);
1497 printer(arg
, " id=0x%x", id
);
1504 /* print option list */
1509 if (olen
< CILEN_VOID
|| olen
> len
) {
1516 case IPX_NETWORK_NUMBER
:
1517 if (olen
== CILEN_NETN
) {
1520 printer (arg
, "network %s", ipx_ntoa (cilong
));
1523 case IPX_NODE_NUMBER
:
1524 if (olen
== CILEN_NODEN
) {
1526 printer (arg
, "node ");
1527 while (p
< optend
) {
1529 printer(arg
, "%.2x", (int) (unsigned int) (unsigned char) code
);
1533 case IPX_COMPRESSION_PROTOCOL
:
1534 if (olen
== CILEN_COMPRESS
) {
1536 GETSHORT (cishort
, p
);
1537 printer (arg
, "compression %d", (int) cishort
);
1540 case IPX_ROUTER_PROTOCOL
:
1541 if (olen
== CILEN_PROTOCOL
) {
1543 GETSHORT (cishort
, p
);
1544 printer (arg
, "router proto %d", (int) cishort
);
1547 case IPX_ROUTER_NAME
:
1548 if (olen
>= CILEN_NAME
) {
1550 printer (arg
, "router name \"");
1551 while (p
< optend
) {
1553 if (code
>= 0x20 && code
<= 0x7E)
1554 printer (arg
, "%c", (int) (unsigned int) (unsigned char) code
);
1556 printer (arg
, " \\%.2x", (int) (unsigned int) (unsigned char) code
);
1558 printer (arg
, "\"");
1562 if (olen
== CILEN_COMPLETE
) {
1564 printer (arg
, "complete");
1571 while (p
< optend
) {
1573 printer(arg
, " %.2x", (int) (unsigned int) (unsigned char) code
);
1581 if (len
> 0 && *p
>= ' ' && *p
< 0x7f) {
1583 print_string((char *)p
, len
, printer
, arg
);
1590 /* print the rest of the bytes in the packet */
1591 for (; len
> 0; --len
) {
1593 printer(arg
, " %.2x", (int) (unsigned int) (unsigned char) code
);
1598 #endif /* ifdef IPX_CHANGE */