04_all_mpls.patch 10 KB

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