Change NHLFE MTU calculation
[mpls-linux.git] / patches / ppp.diff
blobba9e4cfb4f90aafa1bc2871731603fca7c51f52f
1 diff -uNr --exclude=.p4config --exclude=redhat ppp/pppd/main.c ppp-mpls/pppd/main.c
2 --- ppp/pppd/main.c 2006-06-03 22:52:50.000000000 -0500
3 +++ ppp-mpls/pppd/main.c 2007-08-10 00:05:21.000000000 -0500
4 @@ -96,6 +96,9 @@
5 #include "fsm.h"
6 #include "lcp.h"
7 #include "ipcp.h"
9 +#include "mplscp.h"
11 #ifdef INET6
12 #include "ipv6cp.h"
13 #endif
14 @@ -282,6 +285,7 @@
15 &cbcp_protent,
16 #endif
17 &ipcp_protent,
18 + &mplscp_protent,
19 #ifdef INET6
20 &ipv6cp_protent,
21 #endif
22 diff -uNr --exclude=.p4config --exclude=redhat ppp/pppd/Makefile.linux ppp-mpls/pppd/Makefile.linux
23 --- ppp/pppd/Makefile.linux 2007-08-28 00:35:23.000000000 -0500
24 +++ ppp-mpls/pppd/Makefile.linux 2007-08-10 00:05:19.000000000 -0500
25 @@ -14,16 +14,16 @@
27 PPPDSRCS = main.c magic.c fsm.c lcp.c ipcp.c upap.c chap-new.c md5.c ccp.c \
28 ecp.c ipxcp.c auth.c options.c sys-linux.c md4.c chap_ms.c \
29 - demand.c utils.c tty.c eap.c chap-md5.c
30 + demand.c utils.c tty.c eap.c chap-md5.c mplscp.c
32 HEADERS = ccp.h chap-new.h ecp.h fsm.h ipcp.h \
33 ipxcp.h lcp.h magic.h md5.h patchlevel.h pathnames.h pppd.h \
34 - upap.h eap.h
35 + upap.h eap.h mplscp.h
37 MANPAGES = pppd.8
38 PPPDOBJS = main.o magic.o fsm.o lcp.o ipcp.o upap.o chap-new.o md5.o ccp.o \
39 ecp.o auth.o options.o demand.o utils.o sys-linux.o ipxcp.o tty.o \
40 - eap.o chap-md5.o
41 + eap.o chap-md5.o mplscp.o
44 # include dependencies if present
45 diff -uNr --exclude=.p4config --exclude=redhat ppp/pppd/mplscp.c ppp-mpls/pppd/mplscp.c
46 --- ppp/pppd/mplscp.c 1969-12-31 18:00:00.000000000 -0600
47 +++ ppp-mpls/pppd/mplscp.c 2006-08-09 22:05:35.000000000 -0500
48 @@ -0,0 +1,371 @@
50 +/* MPLSCP - Serge.Krier@advalvas.be (C) 2001 */
52 +#include <stdio.h>
53 +#include <string.h>
54 +#include <netdb.h>
55 +#include <sys/param.h>
56 +#include <sys/types.h>
57 +#include <sys/socket.h>
58 +#include <netinet/in.h>
59 +#include <arpa/inet.h>
61 +#include "pppd.h"
62 +#include "fsm.h"
63 +#include "mplscp.h"
66 +/* local vars */
67 +/* static int mplscp_is_up; */ /* have called np_up() */
69 +/*
70 + * Callbacks for fsm code. (CI = Configuration Information)
71 + */
72 +static void mplscp_resetci __P((fsm *)); /* Reset our CI */
73 +static int mplscp_cilen __P((fsm *)); /* Return length of our CI */
74 +static void mplscp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
75 +static int mplscp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
76 +static int mplscp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
77 +static int mplscp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
78 +static int mplscp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
79 +static void mplscp_up __P((fsm *)); /* We're UP */
80 +static void mplscp_down __P((fsm *)); /* We're DOWN */
81 +static void mplscp_finished __P((fsm *)); /* Don't need lower layer */
83 +fsm mplscp_fsm[NUM_PPP]; /* MPLSCP fsm structure */
85 +static fsm_callbacks mplscp_callbacks = { /* MPLSCP callback routines */
86 + mplscp_resetci, /* Reset our Configuration Information */
87 + mplscp_cilen, /* Length of our Configuration Information */
88 + mplscp_addci, /* Add our Configuration Information */
89 + mplscp_ackci, /* ACK our Configuration Information */
90 + mplscp_nakci, /* NAK our Configuration Information */
91 + mplscp_rejci, /* Reject our Configuration Information */
92 + mplscp_reqci, /* Request peer's Configuration Information */
93 + mplscp_up, /* Called when fsm reaches OPENED state */
94 + mplscp_down, /* Called when fsm leaves OPENED state */
95 + NULL, /* Called when we want the lower layer up */
96 + mplscp_finished, /* Called when we want the lower layer down */
97 + NULL, /* Called when Protocol-Reject received */
98 + NULL, /* Retransmission is necessary */
99 + NULL, /* Called to handle protocol-specific codes */
100 + "MPLSCP" /* String name of protocol */
103 +static option_t mplscp_option_list[] = {
104 + { "mpls", o_bool, &mplscp_protent.enabled_flag,
105 + "Enable MPLSCP (and MPLS)", 1 },
106 + { NULL } };
109 + * Protocol entry points from main code.
110 + */
112 +static void mplscp_init __P((int));
113 +static void mplscp_open __P((int));
114 +static void mplscp_close __P((int, char *));
115 +static void mplscp_lowerup __P((int));
116 +static void mplscp_lowerdown __P((int));
117 +static void mplscp_input __P((int, u_char *, int));
118 +static void mplscp_protrej __P((int));
119 +static int mplscp_printpkt __P((u_char *, int,
120 + void (*) __P((void *, char *, ...)), void *));
122 +struct protent mplscp_protent = {
123 + PPP_MPLSCP,
124 + mplscp_init,
125 + mplscp_input,
126 + mplscp_protrej,
127 + mplscp_lowerup,
128 + mplscp_lowerdown,
129 + mplscp_open,
130 + mplscp_close,
131 + mplscp_printpkt,
132 + NULL,
133 + 0, /* MPLS not enabled by default */
134 + "MPLSCP",
135 + "MPLS",
136 + mplscp_option_list,
137 + NULL,
138 + NULL,
139 + NULL
143 + * mplscp_init - Initialize MPLSCP.
144 + */
145 +static void
146 +mplscp_init(int unit) {
148 + fsm *f = &mplscp_fsm[unit];
150 + f->unit = unit;
151 + f->protocol = PPP_MPLSCP;
152 + f->callbacks = &mplscp_callbacks;
153 + fsm_init(&mplscp_fsm[unit]);
158 + * mplscp_open - MPLSCP is allowed to come up.
159 + */
160 +static void
161 +mplscp_open(int unit) {
163 + fsm_open(&mplscp_fsm[unit]);
168 + * mplscp_close - Take MPLSCP down.
169 + */
170 +static void
171 +mplscp_close(int unit, char *reason) {
173 + fsm_close(&mplscp_fsm[unit], reason);
178 + * mplscp_lowerup - The lower layer is up.
179 + */
180 +static void
181 +mplscp_lowerup(int unit) {
183 + fsm_lowerup(&mplscp_fsm[unit]);
187 + * mplscp_lowerdown - The lower layer is down.
188 + */
189 +static void
190 +mplscp_lowerdown(int unit) {
192 + fsm_lowerdown(&mplscp_fsm[unit]);
196 + * mplscp_input - Input MPLSCP packet.
197 + */
198 +static void
199 +mplscp_input(int unit, u_char *p, int len) {
201 + fsm_input(&mplscp_fsm[unit], p, len);
205 + * mplscp_protrej - A Protocol-Reject was received for MPLSCP.
206 + * Pretend the lower layer went down, so we shut up.
207 + */
208 +static void
209 +mplscp_protrej(int unit) {
211 + fsm_lowerdown(&mplscp_fsm[unit]);
215 + * mplscp_resetci - Reset our CI.
216 + * Called by fsm_sconfreq, Send Configure Request.
217 + */
218 +static void
219 +mplscp_resetci(fsm *f) {
221 + return;
225 + * mplscp_cilen - Return length of our CI.
226 + * Called by fsm_sconfreq, Send Configure Request.
227 + */
228 +static int
229 +mplscp_cilen(fsm *f) {
231 + return 0;
235 + * mplscp_addci - Add our desired CIs to a packet.
236 + * Called by fsm_sconfreq, Send Configure Request.
237 + */
238 +static void
239 +mplscp_addci(fsm *f, u_char *ucp, int *lenp) {
244 + * ipcp_ackci - Ack our CIs.
245 + * Called by fsm_rconfack, Receive Configure ACK.
247 + * Returns:
248 + * 0 - Ack was bad.
249 + * 1 - Ack was good.
250 + */
251 +static int
252 +mplscp_ackci(fsm *f, u_char *p, int len) {
254 + return 1;
259 + * mplscp_nakci - Peer has sent a NAK for some of our CIs.
260 + * This should not modify any state if the Nak is bad
261 + * or if MPLSCP is in the OPENED state.
262 + * Calback from fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
264 + * Returns:
265 + * 0 - Nak was bad.
266 + * 1 - Nak was good.
267 + */
268 +static int
269 +mplscp_nakci(fsm *f, u_char *p, int len) {
271 + return 1;
275 + * MPLSVP_rejci - Reject some of our CIs.
276 + * Callback from fsm_rconfnakrej.
277 + */
278 +static int
279 +mplscp_rejci(fsm *f, u_char *p, int len) {
281 + return 1;
286 + * mplscp_reqci - Check the peer's requested CIs and send appropriate response.
287 + * Callback from fsm_rconfreq, Receive Configure Request
289 + * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
290 + * appropriately. If reject_if_disagree is non-zero, doesn't return
291 + * CONFNAK; returns CONFREJ if it can't return CONFACK.
292 + */
293 +static int
294 +mplscp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) {
297 + int rc = CONFACK; /* Final packet return code */
299 + PUTCHAR(CONFACK,inp);
301 + return rc;
305 +static void
306 +mplscp_up(fsm *f) {
308 + sifnpmode(f->unit, PPP_MPLS_UC, NPMODE_PASS);
309 + /* sifnpmode(f->unit, PPP_MPLS_MC, NPMODE_PASS);*/
311 + np_up(f->unit, PPP_MPLS_UC);
312 + /* np_up(f->unit, PPP_MPLS_MC);*/
313 + /* ipcp_is_up = 1;*/
316 +#if 1
317 + printf("MPLSCP is OPENED\n");
318 +#endif
322 +static void
323 +mplscp_down(fsm *f) {
325 + sifnpmode(f->unit, PPP_MPLS_UC, NPMODE_DROP);
326 + /* sifnpmode(f->unit, PPP_MPLS_MC, NPMODE_DROP);*/
328 + sifdown(f->unit);
330 +#if 1
331 + printf("MPLSCP is CLOSED\n");
332 +#endif
337 +static void
338 +mplscp_finished(fsm *f) {
340 + np_finished(f->unit, PPP_MPLS_UC);
341 + /* np_finished(f->unit, PPP_MPLS_MC);*/
346 + * mpls_printpkt - print the contents of an MPLSCP packet.
347 + */
348 +static char *mplscp_codenames[] = {
349 + "ConfReq", "ConfAck", "ConfNak", "ConfRej",
350 + "TermReq", "TermAck", "CodeRej"
353 +static int
354 +mplscp_printpkt(u_char *p, int plen,
355 + void (*printer) __P((void *, char *, ...)),
356 + void *arg) {
358 + int code, id, len, olen;
359 + u_char *pstart, *optend;
361 + if (plen < HEADERLEN)
362 + return 0;
363 + pstart = p;
364 + GETCHAR(code, p);
365 + GETCHAR(id, p);
366 + GETSHORT(len, p);
367 + if (len < HEADERLEN || len > plen)
368 + return 0;
370 + if (code >= 1 && code <= sizeof(mplscp_codenames) / sizeof(char *))
371 + printer(arg, " %s", mplscp_codenames[code-1]);
372 + else
373 + printer(arg, " code=0x%x", code);
374 + printer(arg, " id=0x%x", id);
375 + len -= HEADERLEN;
376 + switch (code) {
377 + case CONFREQ:
378 + case CONFACK:
379 + case CONFNAK:
380 + case CONFREJ:
381 + /* print option list */
382 + while (len >= 2) {
383 + GETCHAR(code, p);
384 + GETCHAR(olen, p);
385 + p -= 2;
386 + if (olen < 2 || olen > len) {
387 + break;
389 + printer(arg, " <");
390 + len -= olen;
391 + optend = p + olen;
392 + while (p < optend) {
393 + GETCHAR(code, p);
394 + printer(arg, " %.2x", code);
396 + printer(arg, ">");
398 + break;
400 + case TERMACK:
401 + case TERMREQ:
402 + if (len > 0 && *p >= ' ' && *p < 0x7f) {
403 + printer(arg, " ");
404 + print_string((char *)p, len, printer, arg);
405 + p += len;
406 + len = 0;
408 + break;
411 + /* print the rest of the bytes in the packet */
412 + for (; len > 0; --len) {
413 + GETCHAR(code, p);
414 + printer(arg, " %.2x", code);
417 + return p - pstart;
420 diff -uNr --exclude=.p4config --exclude=redhat ppp/pppd/mplscp.h ppp-mpls/pppd/mplscp.h
421 --- ppp/pppd/mplscp.h 1969-12-31 18:00:00.000000000 -0600
422 +++ ppp-mpls/pppd/mplscp.h 2006-08-09 22:05:20.000000000 -0500
423 @@ -0,0 +1,8 @@
425 +/* MPLSCP - Serge.Krier@advalvas.be (C) 2001 */
427 +#define PPP_MPLSCP 0x8281
428 +#define PPP_MPLS_UC 0x0281
429 +#define PPP_MPLS_MC 0x0283
431 +extern struct protent mplscp_protent;