summaryrefslogtreecommitdiff
path: root/user/ppp/04_all_mpls.patch
blob: dd316974e1987c6c31e73ec651f8949d5abb63cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
--- ppp-2.4.5/pppd/main.c
+++ ppp-2.4.5/pppd/main.c
@@ -95,6 +95,9 @@
 #include "fsm.h"
 #include "lcp.h"
 #include "ipcp.h"
+
+#include "mplscp.h"
+
 #ifdef INET6
 #include "ipv6cp.h"
 #endif
@@ -283,6 +286,7 @@
     &cbcp_protent,
 #endif
     &ipcp_protent,
+    &mplscp_protent,
 #ifdef INET6
     &ipv6cp_protent,
 #endif
--- ppp-2.4.5/pppd/Makefile.linux
+++ ppp-2.4.5/pppd/Makefile.linux
@@ -13,16 +13,16 @@
 
 PPPDSRCS = main.c magic.c fsm.c lcp.c ipcp.c upap.c chap-new.c md5.c ccp.c \
 	   ecp.c ipxcp.c auth.c options.c sys-linux.c md4.c chap_ms.c \
-	   demand.c utils.c tty.c eap.c chap-md5.c session.c
+	   demand.c utils.c tty.c eap.c chap-md5.c session.c mplscp.c
 
 HEADERS = ccp.h session.h chap-new.h ecp.h fsm.h ipcp.h \
 	ipxcp.h lcp.h magic.h md5.h patchlevel.h pathnames.h pppd.h \
-	upap.h eap.h
+	upap.h eap.h mplscp.h
 
 MANPAGES = pppd.8
 PPPDOBJS = main.o magic.o fsm.o lcp.o ipcp.o upap.o chap-new.o md5.o ccp.o \
 	   ecp.o auth.o options.o demand.o utils.o sys-linux.o ipxcp.o tty.o \
-	   eap.o chap-md5.o session.o
+	   eap.o chap-md5.o session.o mplscp.o
 
 #
 # include dependencies if present
--- ppp-2.4.5/pppd/mplscp.c
+++ ppp-2.4.5/pppd/mplscp.c
@@ -0,0 +1,371 @@
+
+/* MPLSCP - Serge.Krier@advalvas.be (C) 2001 */
+
+#include <stdio.h>
+#include <string.h>
+#include <netdb.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "pppd.h"
+#include "fsm.h"
+#include "mplscp.h"
+
+
+/* local vars */
+/* static int mplscp_is_up; */                  /* have called np_up() */
+
+/*
+ * Callbacks for fsm code.  (CI = Configuration Information)
+ */
+static void mplscp_resetci __P((fsm *));	/* Reset our CI */
+static int  mplscp_cilen __P((fsm *));	        /* Return length of our CI */
+static void mplscp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
+static int  mplscp_ackci __P((fsm *, u_char *, int));	/* Peer ack'd our CI */
+static int  mplscp_nakci __P((fsm *, u_char *, int));	/* Peer nak'd our CI */
+static int  mplscp_rejci __P((fsm *, u_char *, int));	/* Peer rej'd our CI */
+static int  mplscp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
+static void mplscp_up __P((fsm *));		/* We're UP */
+static void mplscp_down __P((fsm *));		/* We're DOWN */
+static void mplscp_finished __P((fsm *));	/* Don't need lower layer */
+
+fsm mplscp_fsm[NUM_PPP];		/* MPLSCP fsm structure */
+
+static fsm_callbacks mplscp_callbacks = { /* MPLSCP callback routines */
+  mplscp_resetci,		/* Reset our Configuration Information */
+  mplscp_cilen,			/* Length of our Configuration Information */
+  mplscp_addci,			/* Add our Configuration Information */
+  mplscp_ackci,			/* ACK our Configuration Information */
+  mplscp_nakci,			/* NAK our Configuration Information */
+  mplscp_rejci,			/* Reject our Configuration Information */
+  mplscp_reqci,			/* Request peer's Configuration Information */
+  mplscp_up,			/* Called when fsm reaches OPENED state */
+  mplscp_down,			/* Called when fsm leaves OPENED state */
+  NULL,			        /* Called when we want the lower layer up */
+  mplscp_finished,		/* Called when we want the lower layer down */
+  NULL,			        /* Called when Protocol-Reject received */
+  NULL,			        /* Retransmission is necessary */
+  NULL,			        /* Called to handle protocol-specific codes */
+  "MPLSCP"			/* String name of protocol */
+};
+
+static option_t mplscp_option_list[] = {
+    { "mpls", o_bool, &mplscp_protent.enabled_flag,
+      "Enable MPLSCP (and MPLS)", 1 },
+    { NULL } };
+
+/*
+ * Protocol entry points from main code.
+ */
+
+static void mplscp_init __P((int));
+static void mplscp_open __P((int));
+static void mplscp_close __P((int, char *));
+static void mplscp_lowerup __P((int));
+static void mplscp_lowerdown __P((int));
+static void mplscp_input __P((int, u_char *, int));
+static void mplscp_protrej __P((int));
+static int  mplscp_printpkt __P((u_char *, int,
+				 void (*) __P((void *, char *, ...)), void *));
+
+struct protent mplscp_protent = {
+    PPP_MPLSCP,
+    mplscp_init,
+    mplscp_input,
+    mplscp_protrej,
+    mplscp_lowerup,
+    mplscp_lowerdown,
+    mplscp_open,
+    mplscp_close,
+    mplscp_printpkt,
+    NULL,
+    0,                            /* MPLS not enabled by default */
+    "MPLSCP",
+    "MPLS",
+    mplscp_option_list,
+    NULL,
+    NULL,
+    NULL
+};
+
+/*
+ * mplscp_init - Initialize MPLSCP.
+ */
+static void
+mplscp_init(int unit) {
+
+  fsm *f = &mplscp_fsm[unit];
+  
+  f->unit = unit;
+  f->protocol = PPP_MPLSCP;
+  f->callbacks = &mplscp_callbacks;  
+  fsm_init(&mplscp_fsm[unit]); 
+  
+}
+
+/*
+ * mplscp_open - MPLSCP is allowed to come up.
+ */
+static void
+mplscp_open(int unit) {
+  
+  fsm_open(&mplscp_fsm[unit]);
+
+}
+
+/*
+ * mplscp_close - Take MPLSCP down.
+ */
+static void
+mplscp_close(int unit, char *reason) {
+
+  fsm_close(&mplscp_fsm[unit], reason);
+
+}
+
+/*
+ * mplscp_lowerup - The lower layer is up.
+ */
+static void
+mplscp_lowerup(int unit) {
+
+  fsm_lowerup(&mplscp_fsm[unit]);
+}
+
+/*
+ * mplscp_lowerdown - The lower layer is down.
+ */
+static void
+mplscp_lowerdown(int unit) {
+  
+  fsm_lowerdown(&mplscp_fsm[unit]);
+}
+
+/*
+ * mplscp_input - Input MPLSCP packet.
+ */
+static void
+mplscp_input(int unit, u_char *p, int len) {
+
+  fsm_input(&mplscp_fsm[unit], p, len);
+}
+
+/*
+ * mplscp_protrej - A Protocol-Reject was received for MPLSCP.
+ * Pretend the lower layer went down, so we shut up.
+ */
+static void
+mplscp_protrej(int unit) {
+
+    fsm_lowerdown(&mplscp_fsm[unit]);
+}
+
+/*
+ * mplscp_resetci - Reset our CI.
+ * Called by fsm_sconfreq, Send Configure Request.
+ */
+static void
+mplscp_resetci(fsm *f) {
+
+  return;
+}
+
+/*
+ * mplscp_cilen - Return length of our CI.
+ * Called by fsm_sconfreq, Send Configure Request.
+ */
+static int
+mplscp_cilen(fsm *f) {
+
+  return 0;
+}
+
+/*
+ * mplscp_addci - Add our desired CIs to a packet.
+ * Called by fsm_sconfreq, Send Configure Request.
+ */
+static void
+mplscp_addci(fsm *f, u_char *ucp, int *lenp) {
+
+}
+
+/*
+ * ipcp_ackci - Ack our CIs.
+ * Called by fsm_rconfack, Receive Configure ACK.
+ *
+ * Returns:
+ *	0 - Ack was bad.
+ *	1 - Ack was good.
+ */
+static int
+mplscp_ackci(fsm *f, u_char *p, int  len) {
+  
+  return 1;
+
+}
+
+/*
+ * mplscp_nakci - Peer has sent a NAK for some of our CIs.
+ * This should not modify any state if the Nak is bad
+ * or if MPLSCP is in the OPENED state.
+ * Calback from fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
+ *
+ * Returns:
+ *	0 - Nak was bad.
+ *	1 - Nak was good.
+ */
+static int
+mplscp_nakci(fsm *f, u_char *p, int len) {
+
+  return 1;
+}
+
+/*
+ * MPLSVP_rejci - Reject some of our CIs.
+ * Callback from fsm_rconfnakrej.
+ */
+static int
+mplscp_rejci(fsm *f, u_char *p, int len) {
+
+  return 1;
+
+}
+
+/*
+ * mplscp_reqci - Check the peer's requested CIs and send appropriate response.
+ * Callback from fsm_rconfreq, Receive Configure Request
+ *
+ * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
+ * appropriately.  If reject_if_disagree is non-zero, doesn't return
+ * CONFNAK; returns CONFREJ if it can't return CONFACK.
+ */
+static int
+mplscp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) {
+  
+  
+  int rc = CONFACK;		/* Final packet return code */
+   
+  PUTCHAR(CONFACK,inp);
+
+  return rc;
+
+}
+
+static void
+mplscp_up(fsm *f) {
+
+  sifnpmode(f->unit, PPP_MPLS_UC, NPMODE_PASS);
+  /*  sifnpmode(f->unit, PPP_MPLS_MC, NPMODE_PASS);*/
+  
+  np_up(f->unit, PPP_MPLS_UC);
+  /*  np_up(f->unit, PPP_MPLS_MC);*/
+  /*  ipcp_is_up = 1;*/
+
+  
+#if 1
+  printf("MPLSCP is OPENED\n");
+#endif
+
+}
+
+static void
+mplscp_down(fsm *f) {
+  
+  sifnpmode(f->unit, PPP_MPLS_UC, NPMODE_DROP);
+  /*  sifnpmode(f->unit, PPP_MPLS_MC, NPMODE_DROP);*/
+
+  sifdown(f->unit); 
+  
+#if 1
+  printf("MPLSCP is CLOSED\n");
+#endif
+  
+
+}
+
+static void 
+mplscp_finished(fsm *f) {
+  
+  np_finished(f->unit, PPP_MPLS_UC);
+  /*  np_finished(f->unit, PPP_MPLS_MC);*/
+
+}
+
+/*
+ * mpls_printpkt - print the contents of an MPLSCP packet.
+ */
+static char *mplscp_codenames[] = {
+    "ConfReq", "ConfAck", "ConfNak", "ConfRej",
+    "TermReq", "TermAck", "CodeRej"
+};
+
+static int
+mplscp_printpkt(u_char *p, int plen, 
+		void (*printer) __P((void *, char *, ...)),
+		void *arg) {
+ 
+    int code, id, len, olen;
+    u_char *pstart, *optend;
+
+    if (plen < HEADERLEN)
+	return 0;
+    pstart = p;
+    GETCHAR(code, p);
+    GETCHAR(id, p);
+    GETSHORT(len, p);
+    if (len < HEADERLEN || len > plen)
+	return 0;
+
+    if (code >= 1 && code <= sizeof(mplscp_codenames) / sizeof(char *))
+	printer(arg, " %s", mplscp_codenames[code-1]);
+    else
+	printer(arg, " code=0x%x", code);
+    printer(arg, " id=0x%x", id);
+    len -= HEADERLEN;
+    switch (code) {
+    case CONFREQ:
+    case CONFACK:
+    case CONFNAK:
+    case CONFREJ:
+	/* print option list */
+	while (len >= 2) {
+	    GETCHAR(code, p);
+	    GETCHAR(olen, p);
+	    p -= 2;
+	    if (olen < 2 || olen > len) {
+		break;
+	    }
+	    printer(arg, " <");
+	    len -= olen;
+	    optend = p + olen;
+	    while (p < optend) {
+		GETCHAR(code, p);
+		printer(arg, " %.2x", code);
+	    }
+	    printer(arg, ">");
+	}
+	break;
+
+    case TERMACK:
+    case TERMREQ:
+	if (len > 0 && *p >= ' ' && *p < 0x7f) {
+	    printer(arg, " ");
+	    print_string((char *)p, len, printer, arg);
+	    p += len;
+	    len = 0;
+	}
+	break;
+    }
+
+    /* print the rest of the bytes in the packet */
+    for (; len > 0; --len) {
+	GETCHAR(code, p);
+	printer(arg, " %.2x", code);
+    }
+
+    return p - pstart;
+
+}
--- ppp-2.4.5/pppd/mplscp.h
+++ ppp-2.4.5/pppd/mplscp.h
@@ -0,0 +1,8 @@
+
+/* MPLSCP - Serge.Krier@advalvas.be (C) 2001 */
+
+#define PPP_MPLSCP  0x8281
+#define PPP_MPLS_UC 0x0281
+#define PPP_MPLS_MC 0x0283
+
+extern struct protent mplscp_protent;