X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/d547c00f76be21289a5ba403b3d94818d8696360..658f6aea7b968c7db3a1c2be58c62efb091c3984:/pppoe.c diff --git a/pppoe.c b/pppoe.c index 52b554e..61b881b 100644 --- a/pppoe.c +++ b/pppoe.c @@ -1,6 +1,7 @@ /* * Fernando ALVES 2013 * Add functionality "server pppoe" to l2tpns. + * inspiration pppoe.c of accel-ppp * GPL licenced */ @@ -20,6 +21,7 @@ #include #include #include +#include #include "l2tpns.h" #include "cluster.h" @@ -762,6 +764,72 @@ uint8_t *pppoe_makeppp(uint8_t *b, int size, uint8_t *p, int l, sessionidt s, tu return b; } +// fill in a PPPOE message with a PPP frame, +// returns start of PPP frame +//(note: THIS ROUTINE WRITES TO p[-28]). +uint8_t *opt_pppoe_makeppp(uint8_t *p, int l, sessionidt s, tunnelidt t, uint16_t mtype, uint8_t prio, bundleidt bid, uint8_t mp_bits) +{ + uint16_t type = mtype; + uint16_t hdrlen = l; + uint8_t *b = p; + struct pppoe_hdr *hdr; + + if (t != TUNNEL_ID_PPPOE) + return NULL; + + // Check whether this session is part of multilink + if (bid) + { + if (bundle[bid].num_of_links > 1) + type = PPPMP; // Change PPP message type to the PPPMP + else + bid = 0; + } + + if (bid) + { + // Add the message type if this fragment has the begin bit set + if (mp_bits & MP_BEGIN) + { + b -= 2; + *(uint16_t *) b = htons(mtype); // Message type + } + + // Set the sequence number and (B)egin (E)nd flags + if (session[s].mssf) + { + // Set the multilink bits + uint16_t bits_send = mp_bits; + b -= 2; + *(uint16_t *) b = htons((bundle[bid].seq_num_t & 0x0FFF)|bits_send); + } + else + { + b -= 4; + *(uint32_t *) b = htonl(bundle[bid].seq_num_t); + // Set the multilink bits + *b = mp_bits; + } + + bundle[bid].seq_num_t++; + } + + b -= 2; + *(uint16_t *) b = htons(type); + + // Size ppp packet + hdrlen += (p - b); + + // 14 bytes ethernet Header + 6 bytes header pppoe + b -= (ETH_HLEN + sizeof(*hdr)); + setup_header(b, config->pppoe_hwaddr, session[s].src_hwaddr, CODE_SESS, s, ETH_P_PPP_SES); + hdr = (struct pppoe_hdr *)(b + ETH_HLEN); + // Store length on header pppoe + hdr->length = hdrlen; + + return b; +} + // pppoe discovery recv data void process_pppoe_disc(uint8_t *pack, int size) { @@ -835,7 +903,6 @@ void process_pppoe_disc(uint8_t *pack, int size) } } -#ifdef LAC // Forward from pppoe to l2tp remote LNS static void pppoe_forwardto_session_rmlns(uint8_t *pack, int size, sessionidt sess, uint16_t proto) { @@ -969,7 +1036,6 @@ void pppoe_forwardto_session_pppoe(uint8_t *pack, int size, sessionidt sess, uin tunnelsend(p, lpppoe, t); // send it.... } -#endif void process_pppoe_sess(uint8_t *pack, int size) { @@ -1034,13 +1100,11 @@ void process_pppoe_sess(uint8_t *pack, int size) lppp -= 2; } -#ifdef LAC if (session[sid].forwardtosession) { // Must be forwaded to a remote lns tunnel l2tp pppoe_forwardto_session_rmlns(pack, size, sid, proto); return; } -#endif if (proto == PPPPAP) {