0003-Add-MPLSCP-support.patch 10 KB

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