l2tp_ppp.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846
  1. /*****************************************************************************
  2. * Linux PPP over L2TP (PPPoX/PPPoL2TP) Sockets
  3. *
  4. * PPPoX --- Generic PPP encapsulation socket family
  5. * PPPoL2TP --- PPP over L2TP (RFC 2661)
  6. *
  7. * Version: 2.0.0
  8. *
  9. * Authors: James Chapman (jchapman@katalix.com)
  10. *
  11. * Based on original work by Martijn van Oosterhout <kleptog@svana.org>
  12. *
  13. * License:
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. *
  19. */
  20. /* This driver handles only L2TP data frames; control frames are handled by a
  21. * userspace application.
  22. *
  23. * To send data in an L2TP session, userspace opens a PPPoL2TP socket and
  24. * attaches it to a bound UDP socket with local tunnel_id / session_id and
  25. * peer tunnel_id / session_id set. Data can then be sent or received using
  26. * regular socket sendmsg() / recvmsg() calls. Kernel parameters of the socket
  27. * can be read or modified using ioctl() or [gs]etsockopt() calls.
  28. *
  29. * When a PPPoL2TP socket is connected with local and peer session_id values
  30. * zero, the socket is treated as a special tunnel management socket.
  31. *
  32. * Here's example userspace code to create a socket for sending/receiving data
  33. * over an L2TP session:-
  34. *
  35. * struct sockaddr_pppol2tp sax;
  36. * int fd;
  37. * int session_fd;
  38. *
  39. * fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
  40. *
  41. * sax.sa_family = AF_PPPOX;
  42. * sax.sa_protocol = PX_PROTO_OL2TP;
  43. * sax.pppol2tp.fd = tunnel_fd; // bound UDP socket
  44. * sax.pppol2tp.addr.sin_addr.s_addr = addr->sin_addr.s_addr;
  45. * sax.pppol2tp.addr.sin_port = addr->sin_port;
  46. * sax.pppol2tp.addr.sin_family = AF_INET;
  47. * sax.pppol2tp.s_tunnel = tunnel_id;
  48. * sax.pppol2tp.s_session = session_id;
  49. * sax.pppol2tp.d_tunnel = peer_tunnel_id;
  50. * sax.pppol2tp.d_session = peer_session_id;
  51. *
  52. * session_fd = connect(fd, (struct sockaddr *)&sax, sizeof(sax));
  53. *
  54. * A pppd plugin that allows PPP traffic to be carried over L2TP using
  55. * this driver is available from the OpenL2TP project at
  56. * http://openl2tp.sourceforge.net.
  57. */
  58. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  59. #include <linux/module.h>
  60. #include <linux/string.h>
  61. #include <linux/list.h>
  62. #include <linux/uaccess.h>
  63. #include <linux/kernel.h>
  64. #include <linux/spinlock.h>
  65. #include <linux/kthread.h>
  66. #include <linux/sched.h>
  67. #include <linux/slab.h>
  68. #include <linux/errno.h>
  69. #include <linux/jiffies.h>
  70. #include <linux/netdevice.h>
  71. #include <linux/net.h>
  72. #include <linux/inetdevice.h>
  73. #include <linux/skbuff.h>
  74. #include <linux/init.h>
  75. #include <linux/ip.h>
  76. #include <linux/udp.h>
  77. #include <linux/if_pppox.h>
  78. #include <linux/if_pppol2tp.h>
  79. #include <net/sock.h>
  80. #include <linux/ppp_channel.h>
  81. #include <linux/ppp_defs.h>
  82. #include <linux/ppp-ioctl.h>
  83. #include <linux/file.h>
  84. #include <linux/hash.h>
  85. #include <linux/sort.h>
  86. #include <linux/proc_fs.h>
  87. #include <linux/l2tp.h>
  88. #include <linux/nsproxy.h>
  89. #include <net/net_namespace.h>
  90. #include <net/netns/generic.h>
  91. #include <net/dst.h>
  92. #include <net/ip.h>
  93. #include <net/udp.h>
  94. #include <net/xfrm.h>
  95. #include <net/inet_common.h>
  96. #include <asm/byteorder.h>
  97. #include <linux/atomic.h>
  98. #include "l2tp_core.h"
  99. #define PPPOL2TP_DRV_VERSION "V2.0"
  100. /* Space for UDP, L2TP and PPP headers */
  101. #define PPPOL2TP_HEADER_OVERHEAD 40
  102. /* Number of bytes to build transmit L2TP headers.
  103. * Unfortunately the size is different depending on whether sequence numbers
  104. * are enabled.
  105. */
  106. #define PPPOL2TP_L2TP_HDR_SIZE_SEQ 10
  107. #define PPPOL2TP_L2TP_HDR_SIZE_NOSEQ 6
  108. /* Private data of each session. This data lives at the end of struct
  109. * l2tp_session, referenced via session->priv[].
  110. */
  111. struct pppol2tp_session {
  112. int owner; /* pid that opened the socket */
  113. struct sock *sock; /* Pointer to the session
  114. * PPPoX socket */
  115. struct sock *tunnel_sock; /* Pointer to the tunnel UDP
  116. * socket */
  117. int flags; /* accessed by PPPIOCGFLAGS.
  118. * Unused. */
  119. };
  120. static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb);
  121. static const struct ppp_channel_ops pppol2tp_chan_ops = {
  122. .start_xmit = pppol2tp_xmit,
  123. };
  124. static const struct proto_ops pppol2tp_ops;
  125. /* Helpers to obtain tunnel/session contexts from sockets.
  126. */
  127. static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
  128. {
  129. struct l2tp_session *session;
  130. if (sk == NULL)
  131. return NULL;
  132. sock_hold(sk);
  133. session = (struct l2tp_session *)(sk->sk_user_data);
  134. if (session == NULL) {
  135. sock_put(sk);
  136. goto out;
  137. }
  138. BUG_ON(session->magic != L2TP_SESSION_MAGIC);
  139. out:
  140. return session;
  141. }
  142. /*****************************************************************************
  143. * Receive data handling
  144. *****************************************************************************/
  145. static int pppol2tp_recv_payload_hook(struct sk_buff *skb)
  146. {
  147. /* Skip PPP header, if present. In testing, Microsoft L2TP clients
  148. * don't send the PPP header (PPP header compression enabled), but
  149. * other clients can include the header. So we cope with both cases
  150. * here. The PPP header is always FF03 when using L2TP.
  151. *
  152. * Note that skb->data[] isn't dereferenced from a u16 ptr here since
  153. * the field may be unaligned.
  154. */
  155. if (!pskb_may_pull(skb, 2))
  156. return 1;
  157. if ((skb->data[0] == PPP_ALLSTATIONS) && (skb->data[1] == PPP_UI))
  158. skb_pull(skb, 2);
  159. return 0;
  160. }
  161. /* Receive message. This is the recvmsg for the PPPoL2TP socket.
  162. */
  163. static int pppol2tp_recvmsg(struct socket *sock, struct msghdr *msg,
  164. size_t len, int flags)
  165. {
  166. int err;
  167. struct sk_buff *skb;
  168. struct sock *sk = sock->sk;
  169. err = -EIO;
  170. if (sk->sk_state & PPPOX_BOUND)
  171. goto end;
  172. err = 0;
  173. skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
  174. flags & MSG_DONTWAIT, &err);
  175. if (!skb)
  176. goto end;
  177. if (len > skb->len)
  178. len = skb->len;
  179. else if (len < skb->len)
  180. msg->msg_flags |= MSG_TRUNC;
  181. err = skb_copy_datagram_msg(skb, 0, msg, len);
  182. if (likely(err == 0))
  183. err = len;
  184. kfree_skb(skb);
  185. end:
  186. return err;
  187. }
  188. static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int data_len)
  189. {
  190. struct pppol2tp_session *ps = l2tp_session_priv(session);
  191. struct sock *sk = NULL;
  192. /* If the socket is bound, send it in to PPP's input queue. Otherwise
  193. * queue it on the session socket.
  194. */
  195. sk = ps->sock;
  196. if (sk == NULL)
  197. goto no_sock;
  198. if (sk->sk_state & PPPOX_BOUND) {
  199. struct pppox_sock *po;
  200. l2tp_dbg(session, L2TP_MSG_DATA,
  201. "%s: recv %d byte data frame, passing to ppp\n",
  202. session->name, data_len);
  203. po = pppox_sk(sk);
  204. ppp_input(&po->chan, skb);
  205. } else {
  206. l2tp_dbg(session, L2TP_MSG_DATA,
  207. "%s: recv %d byte data frame, passing to L2TP socket\n",
  208. session->name, data_len);
  209. if (sock_queue_rcv_skb(sk, skb) < 0) {
  210. atomic_long_inc(&session->stats.rx_errors);
  211. kfree_skb(skb);
  212. }
  213. }
  214. return;
  215. no_sock:
  216. l2tp_info(session, L2TP_MSG_DATA, "%s: no socket\n", session->name);
  217. kfree_skb(skb);
  218. }
  219. static void pppol2tp_session_sock_hold(struct l2tp_session *session)
  220. {
  221. struct pppol2tp_session *ps = l2tp_session_priv(session);
  222. if (ps->sock)
  223. sock_hold(ps->sock);
  224. }
  225. static void pppol2tp_session_sock_put(struct l2tp_session *session)
  226. {
  227. struct pppol2tp_session *ps = l2tp_session_priv(session);
  228. if (ps->sock)
  229. sock_put(ps->sock);
  230. }
  231. /************************************************************************
  232. * Transmit handling
  233. ***********************************************************************/
  234. /* This is the sendmsg for the PPPoL2TP pppol2tp_session socket. We come here
  235. * when a user application does a sendmsg() on the session socket. L2TP and
  236. * PPP headers must be inserted into the user's data.
  237. */
  238. static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m,
  239. size_t total_len)
  240. {
  241. struct sock *sk = sock->sk;
  242. struct sk_buff *skb;
  243. int error;
  244. struct l2tp_session *session;
  245. struct l2tp_tunnel *tunnel;
  246. struct pppol2tp_session *ps;
  247. int uhlen;
  248. error = -ENOTCONN;
  249. if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
  250. goto error;
  251. /* Get session and tunnel contexts */
  252. error = -EBADF;
  253. session = pppol2tp_sock_to_session(sk);
  254. if (session == NULL)
  255. goto error;
  256. ps = l2tp_session_priv(session);
  257. tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
  258. if (tunnel == NULL)
  259. goto error_put_sess;
  260. uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
  261. /* Allocate a socket buffer */
  262. error = -ENOMEM;
  263. skb = sock_wmalloc(sk, NET_SKB_PAD + sizeof(struct iphdr) +
  264. uhlen + session->hdr_len +
  265. 2 + total_len, /* 2 bytes for PPP_ALLSTATIONS & PPP_UI */
  266. 0, GFP_KERNEL);
  267. if (!skb)
  268. goto error_put_sess_tun;
  269. /* Reserve space for headers. */
  270. skb_reserve(skb, NET_SKB_PAD);
  271. skb_reset_network_header(skb);
  272. skb_reserve(skb, sizeof(struct iphdr));
  273. skb_reset_transport_header(skb);
  274. skb_reserve(skb, uhlen);
  275. /* Add PPP header */
  276. skb->data[0] = PPP_ALLSTATIONS;
  277. skb->data[1] = PPP_UI;
  278. skb_put(skb, 2);
  279. /* Copy user data into skb */
  280. error = memcpy_from_msg(skb_put(skb, total_len), m, total_len);
  281. if (error < 0) {
  282. kfree_skb(skb);
  283. goto error_put_sess_tun;
  284. }
  285. local_bh_disable();
  286. l2tp_xmit_skb(session, skb, session->hdr_len);
  287. local_bh_enable();
  288. sock_put(ps->tunnel_sock);
  289. sock_put(sk);
  290. return total_len;
  291. error_put_sess_tun:
  292. sock_put(ps->tunnel_sock);
  293. error_put_sess:
  294. sock_put(sk);
  295. error:
  296. return error;
  297. }
  298. /* Transmit function called by generic PPP driver. Sends PPP frame
  299. * over PPPoL2TP socket.
  300. *
  301. * This is almost the same as pppol2tp_sendmsg(), but rather than
  302. * being called with a msghdr from userspace, it is called with a skb
  303. * from the kernel.
  304. *
  305. * The supplied skb from ppp doesn't have enough headroom for the
  306. * insertion of L2TP, UDP and IP headers so we need to allocate more
  307. * headroom in the skb. This will create a cloned skb. But we must be
  308. * careful in the error case because the caller will expect to free
  309. * the skb it supplied, not our cloned skb. So we take care to always
  310. * leave the original skb unfreed if we return an error.
  311. */
  312. static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
  313. {
  314. struct sock *sk = (struct sock *) chan->private;
  315. struct sock *sk_tun;
  316. struct l2tp_session *session;
  317. struct l2tp_tunnel *tunnel;
  318. struct pppol2tp_session *ps;
  319. int uhlen, headroom;
  320. if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
  321. goto abort;
  322. /* Get session and tunnel contexts from the socket */
  323. session = pppol2tp_sock_to_session(sk);
  324. if (session == NULL)
  325. goto abort;
  326. ps = l2tp_session_priv(session);
  327. sk_tun = ps->tunnel_sock;
  328. if (sk_tun == NULL)
  329. goto abort_put_sess;
  330. tunnel = l2tp_sock_to_tunnel(sk_tun);
  331. if (tunnel == NULL)
  332. goto abort_put_sess;
  333. uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
  334. headroom = NET_SKB_PAD +
  335. sizeof(struct iphdr) + /* IP header */
  336. uhlen + /* UDP header (if L2TP_ENCAPTYPE_UDP) */
  337. session->hdr_len + /* L2TP header */
  338. 2; /* 2 bytes for PPP_ALLSTATIONS & PPP_UI */
  339. if (skb_cow_head(skb, headroom))
  340. goto abort_put_sess_tun;
  341. /* Setup PPP header */
  342. __skb_push(skb, 2);
  343. skb->data[0] = PPP_ALLSTATIONS;
  344. skb->data[1] = PPP_UI;
  345. local_bh_disable();
  346. l2tp_xmit_skb(session, skb, session->hdr_len);
  347. local_bh_enable();
  348. sock_put(sk_tun);
  349. sock_put(sk);
  350. return 1;
  351. abort_put_sess_tun:
  352. sock_put(sk_tun);
  353. abort_put_sess:
  354. sock_put(sk);
  355. abort:
  356. /* Free the original skb */
  357. kfree_skb(skb);
  358. return 1;
  359. }
  360. /*****************************************************************************
  361. * Session (and tunnel control) socket create/destroy.
  362. *****************************************************************************/
  363. /* Called by l2tp_core when a session socket is being closed.
  364. */
  365. static void pppol2tp_session_close(struct l2tp_session *session)
  366. {
  367. struct pppol2tp_session *ps = l2tp_session_priv(session);
  368. struct sock *sk = ps->sock;
  369. struct socket *sock = sk->sk_socket;
  370. BUG_ON(session->magic != L2TP_SESSION_MAGIC);
  371. if (sock) {
  372. inet_shutdown(sock, SEND_SHUTDOWN);
  373. /* Don't let the session go away before our socket does */
  374. l2tp_session_inc_refcount(session);
  375. }
  376. }
  377. /* Really kill the session socket. (Called from sock_put() if
  378. * refcnt == 0.)
  379. */
  380. static void pppol2tp_session_destruct(struct sock *sk)
  381. {
  382. struct l2tp_session *session = sk->sk_user_data;
  383. if (session) {
  384. sk->sk_user_data = NULL;
  385. BUG_ON(session->magic != L2TP_SESSION_MAGIC);
  386. l2tp_session_dec_refcount(session);
  387. }
  388. }
  389. /* Called when the PPPoX socket (session) is closed.
  390. */
  391. static int pppol2tp_release(struct socket *sock)
  392. {
  393. struct sock *sk = sock->sk;
  394. struct l2tp_session *session;
  395. int error;
  396. if (!sk)
  397. return 0;
  398. error = -EBADF;
  399. lock_sock(sk);
  400. if (sock_flag(sk, SOCK_DEAD) != 0)
  401. goto error;
  402. pppox_unbind_sock(sk);
  403. /* Signal the death of the socket. */
  404. sk->sk_state = PPPOX_DEAD;
  405. sock_orphan(sk);
  406. sock->sk = NULL;
  407. session = pppol2tp_sock_to_session(sk);
  408. /* Purge any queued data */
  409. if (session != NULL) {
  410. __l2tp_session_unhash(session);
  411. l2tp_session_queue_purge(session);
  412. sock_put(sk);
  413. }
  414. skb_queue_purge(&sk->sk_receive_queue);
  415. skb_queue_purge(&sk->sk_write_queue);
  416. release_sock(sk);
  417. /* This will delete the session context via
  418. * pppol2tp_session_destruct() if the socket's refcnt drops to
  419. * zero.
  420. */
  421. sock_put(sk);
  422. return 0;
  423. error:
  424. release_sock(sk);
  425. return error;
  426. }
  427. static struct proto pppol2tp_sk_proto = {
  428. .name = "PPPOL2TP",
  429. .owner = THIS_MODULE,
  430. .obj_size = sizeof(struct pppox_sock),
  431. };
  432. static int pppol2tp_backlog_recv(struct sock *sk, struct sk_buff *skb)
  433. {
  434. int rc;
  435. rc = l2tp_udp_encap_recv(sk, skb);
  436. if (rc)
  437. kfree_skb(skb);
  438. return NET_RX_SUCCESS;
  439. }
  440. /* socket() handler. Initialize a new struct sock.
  441. */
  442. static int pppol2tp_create(struct net *net, struct socket *sock, int kern)
  443. {
  444. int error = -ENOMEM;
  445. struct sock *sk;
  446. sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppol2tp_sk_proto, kern);
  447. if (!sk)
  448. goto out;
  449. sock_init_data(sock, sk);
  450. sock->state = SS_UNCONNECTED;
  451. sock->ops = &pppol2tp_ops;
  452. sk->sk_backlog_rcv = pppol2tp_backlog_recv;
  453. sk->sk_protocol = PX_PROTO_OL2TP;
  454. sk->sk_family = PF_PPPOX;
  455. sk->sk_state = PPPOX_NONE;
  456. sk->sk_type = SOCK_STREAM;
  457. sk->sk_destruct = pppol2tp_session_destruct;
  458. error = 0;
  459. out:
  460. return error;
  461. }
  462. #if IS_ENABLED(CONFIG_L2TP_DEBUGFS)
  463. static void pppol2tp_show(struct seq_file *m, void *arg)
  464. {
  465. struct l2tp_session *session = arg;
  466. struct pppol2tp_session *ps = l2tp_session_priv(session);
  467. if (ps) {
  468. struct pppox_sock *po = pppox_sk(ps->sock);
  469. if (po)
  470. seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
  471. }
  472. }
  473. #endif
  474. /* connect() handler. Attach a PPPoX socket to a tunnel UDP socket
  475. */
  476. static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
  477. int sockaddr_len, int flags)
  478. {
  479. struct sock *sk = sock->sk;
  480. struct sockaddr_pppol2tp *sp = (struct sockaddr_pppol2tp *) uservaddr;
  481. struct pppox_sock *po = pppox_sk(sk);
  482. struct l2tp_session *session = NULL;
  483. struct l2tp_tunnel *tunnel;
  484. struct pppol2tp_session *ps;
  485. struct dst_entry *dst;
  486. struct l2tp_session_cfg cfg = { 0, };
  487. int error = 0;
  488. u32 tunnel_id, peer_tunnel_id;
  489. u32 session_id, peer_session_id;
  490. int ver = 2;
  491. int fd;
  492. lock_sock(sk);
  493. error = -EINVAL;
  494. if (sp->sa_protocol != PX_PROTO_OL2TP)
  495. goto end;
  496. /* Check for already bound sockets */
  497. error = -EBUSY;
  498. if (sk->sk_state & PPPOX_CONNECTED)
  499. goto end;
  500. /* We don't supporting rebinding anyway */
  501. error = -EALREADY;
  502. if (sk->sk_user_data)
  503. goto end; /* socket is already attached */
  504. /* Get params from socket address. Handle L2TPv2 and L2TPv3.
  505. * This is nasty because there are different sockaddr_pppol2tp
  506. * structs for L2TPv2, L2TPv3, over IPv4 and IPv6. We use
  507. * the sockaddr size to determine which structure the caller
  508. * is using.
  509. */
  510. peer_tunnel_id = 0;
  511. if (sockaddr_len == sizeof(struct sockaddr_pppol2tp)) {
  512. fd = sp->pppol2tp.fd;
  513. tunnel_id = sp->pppol2tp.s_tunnel;
  514. peer_tunnel_id = sp->pppol2tp.d_tunnel;
  515. session_id = sp->pppol2tp.s_session;
  516. peer_session_id = sp->pppol2tp.d_session;
  517. } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpv3)) {
  518. struct sockaddr_pppol2tpv3 *sp3 =
  519. (struct sockaddr_pppol2tpv3 *) sp;
  520. ver = 3;
  521. fd = sp3->pppol2tp.fd;
  522. tunnel_id = sp3->pppol2tp.s_tunnel;
  523. peer_tunnel_id = sp3->pppol2tp.d_tunnel;
  524. session_id = sp3->pppol2tp.s_session;
  525. peer_session_id = sp3->pppol2tp.d_session;
  526. } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpin6)) {
  527. struct sockaddr_pppol2tpin6 *sp6 =
  528. (struct sockaddr_pppol2tpin6 *) sp;
  529. fd = sp6->pppol2tp.fd;
  530. tunnel_id = sp6->pppol2tp.s_tunnel;
  531. peer_tunnel_id = sp6->pppol2tp.d_tunnel;
  532. session_id = sp6->pppol2tp.s_session;
  533. peer_session_id = sp6->pppol2tp.d_session;
  534. } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpv3in6)) {
  535. struct sockaddr_pppol2tpv3in6 *sp6 =
  536. (struct sockaddr_pppol2tpv3in6 *) sp;
  537. ver = 3;
  538. fd = sp6->pppol2tp.fd;
  539. tunnel_id = sp6->pppol2tp.s_tunnel;
  540. peer_tunnel_id = sp6->pppol2tp.d_tunnel;
  541. session_id = sp6->pppol2tp.s_session;
  542. peer_session_id = sp6->pppol2tp.d_session;
  543. } else {
  544. error = -EINVAL;
  545. goto end; /* bad socket address */
  546. }
  547. /* Don't bind if tunnel_id is 0 */
  548. error = -EINVAL;
  549. if (tunnel_id == 0)
  550. goto end;
  551. tunnel = l2tp_tunnel_find(sock_net(sk), tunnel_id);
  552. /* Special case: create tunnel context if session_id and
  553. * peer_session_id is 0. Otherwise look up tunnel using supplied
  554. * tunnel id.
  555. */
  556. if ((session_id == 0) && (peer_session_id == 0)) {
  557. if (tunnel == NULL) {
  558. struct l2tp_tunnel_cfg tcfg = {
  559. .encap = L2TP_ENCAPTYPE_UDP,
  560. .debug = 0,
  561. };
  562. error = l2tp_tunnel_create(sock_net(sk), fd, ver, tunnel_id, peer_tunnel_id, &tcfg, &tunnel);
  563. if (error < 0)
  564. goto end;
  565. }
  566. } else {
  567. /* Error if we can't find the tunnel */
  568. error = -ENOENT;
  569. if (tunnel == NULL)
  570. goto end;
  571. /* Error if socket is not prepped */
  572. if (tunnel->sock == NULL)
  573. goto end;
  574. }
  575. if (tunnel->recv_payload_hook == NULL)
  576. tunnel->recv_payload_hook = pppol2tp_recv_payload_hook;
  577. if (tunnel->peer_tunnel_id == 0)
  578. tunnel->peer_tunnel_id = peer_tunnel_id;
  579. /* Create session if it doesn't already exist. We handle the
  580. * case where a session was previously created by the netlink
  581. * interface by checking that the session doesn't already have
  582. * a socket and its tunnel socket are what we expect. If any
  583. * of those checks fail, return EEXIST to the caller.
  584. */
  585. session = l2tp_session_find(sock_net(sk), tunnel, session_id);
  586. if (session == NULL) {
  587. /* Default MTU must allow space for UDP/L2TP/PPP
  588. * headers.
  589. */
  590. cfg.mtu = cfg.mru = 1500 - PPPOL2TP_HEADER_OVERHEAD;
  591. /* Allocate and initialize a new session context. */
  592. session = l2tp_session_create(sizeof(struct pppol2tp_session),
  593. tunnel, session_id,
  594. peer_session_id, &cfg);
  595. if (session == NULL) {
  596. error = -ENOMEM;
  597. goto end;
  598. }
  599. } else {
  600. ps = l2tp_session_priv(session);
  601. error = -EEXIST;
  602. if (ps->sock != NULL)
  603. goto end;
  604. /* consistency checks */
  605. if (ps->tunnel_sock != tunnel->sock)
  606. goto end;
  607. }
  608. /* Associate session with its PPPoL2TP socket */
  609. ps = l2tp_session_priv(session);
  610. ps->owner = current->pid;
  611. ps->sock = sk;
  612. ps->tunnel_sock = tunnel->sock;
  613. session->recv_skb = pppol2tp_recv;
  614. session->session_close = pppol2tp_session_close;
  615. #if IS_ENABLED(CONFIG_L2TP_DEBUGFS)
  616. session->show = pppol2tp_show;
  617. #endif
  618. /* We need to know each time a skb is dropped from the reorder
  619. * queue.
  620. */
  621. session->ref = pppol2tp_session_sock_hold;
  622. session->deref = pppol2tp_session_sock_put;
  623. /* If PMTU discovery was enabled, use the MTU that was discovered */
  624. dst = sk_dst_get(tunnel->sock);
  625. if (dst != NULL) {
  626. u32 pmtu = dst_mtu(dst);
  627. if (pmtu != 0)
  628. session->mtu = session->mru = pmtu -
  629. PPPOL2TP_HEADER_OVERHEAD;
  630. dst_release(dst);
  631. }
  632. /* Special case: if source & dest session_id == 0x0000, this
  633. * socket is being created to manage the tunnel. Just set up
  634. * the internal context for use by ioctl() and sockopt()
  635. * handlers.
  636. */
  637. if ((session->session_id == 0) &&
  638. (session->peer_session_id == 0)) {
  639. error = 0;
  640. goto out_no_ppp;
  641. }
  642. /* The only header we need to worry about is the L2TP
  643. * header. This size is different depending on whether
  644. * sequence numbers are enabled for the data channel.
  645. */
  646. po->chan.hdrlen = PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
  647. po->chan.private = sk;
  648. po->chan.ops = &pppol2tp_chan_ops;
  649. po->chan.mtu = session->mtu;
  650. error = ppp_register_net_channel(sock_net(sk), &po->chan);
  651. if (error)
  652. goto end;
  653. out_no_ppp:
  654. /* This is how we get the session context from the socket. */
  655. sk->sk_user_data = session;
  656. sk->sk_state = PPPOX_CONNECTED;
  657. l2tp_info(session, L2TP_MSG_CONTROL, "%s: created\n",
  658. session->name);
  659. end:
  660. release_sock(sk);
  661. return error;
  662. }
  663. #ifdef CONFIG_L2TP_V3
  664. /* Called when creating sessions via the netlink interface.
  665. */
  666. static int pppol2tp_session_create(struct net *net, u32 tunnel_id, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg)
  667. {
  668. int error;
  669. struct l2tp_tunnel *tunnel;
  670. struct l2tp_session *session;
  671. struct pppol2tp_session *ps;
  672. tunnel = l2tp_tunnel_find(net, tunnel_id);
  673. /* Error if we can't find the tunnel */
  674. error = -ENOENT;
  675. if (tunnel == NULL)
  676. goto out;
  677. /* Error if tunnel socket is not prepped */
  678. if (tunnel->sock == NULL)
  679. goto out;
  680. /* Check that this session doesn't already exist */
  681. error = -EEXIST;
  682. session = l2tp_session_find(net, tunnel, session_id);
  683. if (session != NULL)
  684. goto out;
  685. /* Default MTU values. */
  686. if (cfg->mtu == 0)
  687. cfg->mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD;
  688. if (cfg->mru == 0)
  689. cfg->mru = cfg->mtu;
  690. /* Allocate and initialize a new session context. */
  691. error = -ENOMEM;
  692. session = l2tp_session_create(sizeof(struct pppol2tp_session),
  693. tunnel, session_id,
  694. peer_session_id, cfg);
  695. if (session == NULL)
  696. goto out;
  697. ps = l2tp_session_priv(session);
  698. ps->tunnel_sock = tunnel->sock;
  699. l2tp_info(session, L2TP_MSG_CONTROL, "%s: created\n",
  700. session->name);
  701. error = 0;
  702. out:
  703. return error;
  704. }
  705. #endif /* CONFIG_L2TP_V3 */
  706. /* getname() support.
  707. */
  708. static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
  709. int *usockaddr_len, int peer)
  710. {
  711. int len = 0;
  712. int error = 0;
  713. struct l2tp_session *session;
  714. struct l2tp_tunnel *tunnel;
  715. struct sock *sk = sock->sk;
  716. struct inet_sock *inet;
  717. struct pppol2tp_session *pls;
  718. error = -ENOTCONN;
  719. if (sk == NULL)
  720. goto end;
  721. if (!(sk->sk_state & PPPOX_CONNECTED))
  722. goto end;
  723. error = -EBADF;
  724. session = pppol2tp_sock_to_session(sk);
  725. if (session == NULL)
  726. goto end;
  727. pls = l2tp_session_priv(session);
  728. tunnel = l2tp_sock_to_tunnel(pls->tunnel_sock);
  729. if (tunnel == NULL)
  730. goto end_put_sess;
  731. inet = inet_sk(tunnel->sock);
  732. if ((tunnel->version == 2) && (tunnel->sock->sk_family == AF_INET)) {
  733. struct sockaddr_pppol2tp sp;
  734. len = sizeof(sp);
  735. memset(&sp, 0, len);
  736. sp.sa_family = AF_PPPOX;
  737. sp.sa_protocol = PX_PROTO_OL2TP;
  738. sp.pppol2tp.fd = tunnel->fd;
  739. sp.pppol2tp.pid = pls->owner;
  740. sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
  741. sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
  742. sp.pppol2tp.s_session = session->session_id;
  743. sp.pppol2tp.d_session = session->peer_session_id;
  744. sp.pppol2tp.addr.sin_family = AF_INET;
  745. sp.pppol2tp.addr.sin_port = inet->inet_dport;
  746. sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
  747. memcpy(uaddr, &sp, len);
  748. #if IS_ENABLED(CONFIG_IPV6)
  749. } else if ((tunnel->version == 2) &&
  750. (tunnel->sock->sk_family == AF_INET6)) {
  751. struct sockaddr_pppol2tpin6 sp;
  752. len = sizeof(sp);
  753. memset(&sp, 0, len);
  754. sp.sa_family = AF_PPPOX;
  755. sp.sa_protocol = PX_PROTO_OL2TP;
  756. sp.pppol2tp.fd = tunnel->fd;
  757. sp.pppol2tp.pid = pls->owner;
  758. sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
  759. sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
  760. sp.pppol2tp.s_session = session->session_id;
  761. sp.pppol2tp.d_session = session->peer_session_id;
  762. sp.pppol2tp.addr.sin6_family = AF_INET6;
  763. sp.pppol2tp.addr.sin6_port = inet->inet_dport;
  764. memcpy(&sp.pppol2tp.addr.sin6_addr, &tunnel->sock->sk_v6_daddr,
  765. sizeof(tunnel->sock->sk_v6_daddr));
  766. memcpy(uaddr, &sp, len);
  767. } else if ((tunnel->version == 3) &&
  768. (tunnel->sock->sk_family == AF_INET6)) {
  769. struct sockaddr_pppol2tpv3in6 sp;
  770. len = sizeof(sp);
  771. memset(&sp, 0, len);
  772. sp.sa_family = AF_PPPOX;
  773. sp.sa_protocol = PX_PROTO_OL2TP;
  774. sp.pppol2tp.fd = tunnel->fd;
  775. sp.pppol2tp.pid = pls->owner;
  776. sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
  777. sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
  778. sp.pppol2tp.s_session = session->session_id;
  779. sp.pppol2tp.d_session = session->peer_session_id;
  780. sp.pppol2tp.addr.sin6_family = AF_INET6;
  781. sp.pppol2tp.addr.sin6_port = inet->inet_dport;
  782. memcpy(&sp.pppol2tp.addr.sin6_addr, &tunnel->sock->sk_v6_daddr,
  783. sizeof(tunnel->sock->sk_v6_daddr));
  784. memcpy(uaddr, &sp, len);
  785. #endif
  786. } else if (tunnel->version == 3) {
  787. struct sockaddr_pppol2tpv3 sp;
  788. len = sizeof(sp);
  789. memset(&sp, 0, len);
  790. sp.sa_family = AF_PPPOX;
  791. sp.sa_protocol = PX_PROTO_OL2TP;
  792. sp.pppol2tp.fd = tunnel->fd;
  793. sp.pppol2tp.pid = pls->owner;
  794. sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
  795. sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
  796. sp.pppol2tp.s_session = session->session_id;
  797. sp.pppol2tp.d_session = session->peer_session_id;
  798. sp.pppol2tp.addr.sin_family = AF_INET;
  799. sp.pppol2tp.addr.sin_port = inet->inet_dport;
  800. sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
  801. memcpy(uaddr, &sp, len);
  802. }
  803. *usockaddr_len = len;
  804. error = 0;
  805. sock_put(pls->tunnel_sock);
  806. end_put_sess:
  807. sock_put(sk);
  808. end:
  809. return error;
  810. }
  811. /****************************************************************************
  812. * ioctl() handlers.
  813. *
  814. * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
  815. * sockets. However, in order to control kernel tunnel features, we allow
  816. * userspace to create a special "tunnel" PPPoX socket which is used for
  817. * control only. Tunnel PPPoX sockets have session_id == 0 and simply allow
  818. * the user application to issue L2TP setsockopt(), getsockopt() and ioctl()
  819. * calls.
  820. ****************************************************************************/
  821. static void pppol2tp_copy_stats(struct pppol2tp_ioc_stats *dest,
  822. struct l2tp_stats *stats)
  823. {
  824. dest->tx_packets = atomic_long_read(&stats->tx_packets);
  825. dest->tx_bytes = atomic_long_read(&stats->tx_bytes);
  826. dest->tx_errors = atomic_long_read(&stats->tx_errors);
  827. dest->rx_packets = atomic_long_read(&stats->rx_packets);
  828. dest->rx_bytes = atomic_long_read(&stats->rx_bytes);
  829. dest->rx_seq_discards = atomic_long_read(&stats->rx_seq_discards);
  830. dest->rx_oos_packets = atomic_long_read(&stats->rx_oos_packets);
  831. dest->rx_errors = atomic_long_read(&stats->rx_errors);
  832. }
  833. /* Session ioctl helper.
  834. */
  835. static int pppol2tp_session_ioctl(struct l2tp_session *session,
  836. unsigned int cmd, unsigned long arg)
  837. {
  838. struct ifreq ifr;
  839. int err = 0;
  840. struct sock *sk;
  841. int val = (int) arg;
  842. struct pppol2tp_session *ps = l2tp_session_priv(session);
  843. struct l2tp_tunnel *tunnel = session->tunnel;
  844. struct pppol2tp_ioc_stats stats;
  845. l2tp_dbg(session, L2TP_MSG_CONTROL,
  846. "%s: pppol2tp_session_ioctl(cmd=%#x, arg=%#lx)\n",
  847. session->name, cmd, arg);
  848. sk = ps->sock;
  849. sock_hold(sk);
  850. switch (cmd) {
  851. case SIOCGIFMTU:
  852. err = -ENXIO;
  853. if (!(sk->sk_state & PPPOX_CONNECTED))
  854. break;
  855. err = -EFAULT;
  856. if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
  857. break;
  858. ifr.ifr_mtu = session->mtu;
  859. if (copy_to_user((void __user *) arg, &ifr, sizeof(struct ifreq)))
  860. break;
  861. l2tp_info(session, L2TP_MSG_CONTROL, "%s: get mtu=%d\n",
  862. session->name, session->mtu);
  863. err = 0;
  864. break;
  865. case SIOCSIFMTU:
  866. err = -ENXIO;
  867. if (!(sk->sk_state & PPPOX_CONNECTED))
  868. break;
  869. err = -EFAULT;
  870. if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
  871. break;
  872. session->mtu = ifr.ifr_mtu;
  873. l2tp_info(session, L2TP_MSG_CONTROL, "%s: set mtu=%d\n",
  874. session->name, session->mtu);
  875. err = 0;
  876. break;
  877. case PPPIOCGMRU:
  878. err = -ENXIO;
  879. if (!(sk->sk_state & PPPOX_CONNECTED))
  880. break;
  881. err = -EFAULT;
  882. if (put_user(session->mru, (int __user *) arg))
  883. break;
  884. l2tp_info(session, L2TP_MSG_CONTROL, "%s: get mru=%d\n",
  885. session->name, session->mru);
  886. err = 0;
  887. break;
  888. case PPPIOCSMRU:
  889. err = -ENXIO;
  890. if (!(sk->sk_state & PPPOX_CONNECTED))
  891. break;
  892. err = -EFAULT;
  893. if (get_user(val, (int __user *) arg))
  894. break;
  895. session->mru = val;
  896. l2tp_info(session, L2TP_MSG_CONTROL, "%s: set mru=%d\n",
  897. session->name, session->mru);
  898. err = 0;
  899. break;
  900. case PPPIOCGFLAGS:
  901. err = -EFAULT;
  902. if (put_user(ps->flags, (int __user *) arg))
  903. break;
  904. l2tp_info(session, L2TP_MSG_CONTROL, "%s: get flags=%d\n",
  905. session->name, ps->flags);
  906. err = 0;
  907. break;
  908. case PPPIOCSFLAGS:
  909. err = -EFAULT;
  910. if (get_user(val, (int __user *) arg))
  911. break;
  912. ps->flags = val;
  913. l2tp_info(session, L2TP_MSG_CONTROL, "%s: set flags=%d\n",
  914. session->name, ps->flags);
  915. err = 0;
  916. break;
  917. case PPPIOCGL2TPSTATS:
  918. err = -ENXIO;
  919. if (!(sk->sk_state & PPPOX_CONNECTED))
  920. break;
  921. memset(&stats, 0, sizeof(stats));
  922. stats.tunnel_id = tunnel->tunnel_id;
  923. stats.session_id = session->session_id;
  924. pppol2tp_copy_stats(&stats, &session->stats);
  925. if (copy_to_user((void __user *) arg, &stats,
  926. sizeof(stats)))
  927. break;
  928. l2tp_info(session, L2TP_MSG_CONTROL, "%s: get L2TP stats\n",
  929. session->name);
  930. err = 0;
  931. break;
  932. default:
  933. err = -ENOSYS;
  934. break;
  935. }
  936. sock_put(sk);
  937. return err;
  938. }
  939. /* Tunnel ioctl helper.
  940. *
  941. * Note the special handling for PPPIOCGL2TPSTATS below. If the ioctl data
  942. * specifies a session_id, the session ioctl handler is called. This allows an
  943. * application to retrieve session stats via a tunnel socket.
  944. */
  945. static int pppol2tp_tunnel_ioctl(struct l2tp_tunnel *tunnel,
  946. unsigned int cmd, unsigned long arg)
  947. {
  948. int err = 0;
  949. struct sock *sk;
  950. struct pppol2tp_ioc_stats stats;
  951. l2tp_dbg(tunnel, L2TP_MSG_CONTROL,
  952. "%s: pppol2tp_tunnel_ioctl(cmd=%#x, arg=%#lx)\n",
  953. tunnel->name, cmd, arg);
  954. sk = tunnel->sock;
  955. sock_hold(sk);
  956. switch (cmd) {
  957. case PPPIOCGL2TPSTATS:
  958. err = -ENXIO;
  959. if (!(sk->sk_state & PPPOX_CONNECTED))
  960. break;
  961. if (copy_from_user(&stats, (void __user *) arg,
  962. sizeof(stats))) {
  963. err = -EFAULT;
  964. break;
  965. }
  966. if (stats.session_id != 0) {
  967. /* resend to session ioctl handler */
  968. struct l2tp_session *session =
  969. l2tp_session_find(sock_net(sk), tunnel, stats.session_id);
  970. if (session != NULL)
  971. err = pppol2tp_session_ioctl(session, cmd, arg);
  972. else
  973. err = -EBADR;
  974. break;
  975. }
  976. #ifdef CONFIG_XFRM
  977. stats.using_ipsec = (sk->sk_policy[0] || sk->sk_policy[1]) ? 1 : 0;
  978. #endif
  979. pppol2tp_copy_stats(&stats, &tunnel->stats);
  980. if (copy_to_user((void __user *) arg, &stats, sizeof(stats))) {
  981. err = -EFAULT;
  982. break;
  983. }
  984. l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: get L2TP stats\n",
  985. tunnel->name);
  986. err = 0;
  987. break;
  988. default:
  989. err = -ENOSYS;
  990. break;
  991. }
  992. sock_put(sk);
  993. return err;
  994. }
  995. /* Main ioctl() handler.
  996. * Dispatch to tunnel or session helpers depending on the socket.
  997. */
  998. static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
  999. unsigned long arg)
  1000. {
  1001. struct sock *sk = sock->sk;
  1002. struct l2tp_session *session;
  1003. struct l2tp_tunnel *tunnel;
  1004. struct pppol2tp_session *ps;
  1005. int err;
  1006. if (!sk)
  1007. return 0;
  1008. err = -EBADF;
  1009. if (sock_flag(sk, SOCK_DEAD) != 0)
  1010. goto end;
  1011. err = -ENOTCONN;
  1012. if ((sk->sk_user_data == NULL) ||
  1013. (!(sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND))))
  1014. goto end;
  1015. /* Get session context from the socket */
  1016. err = -EBADF;
  1017. session = pppol2tp_sock_to_session(sk);
  1018. if (session == NULL)
  1019. goto end;
  1020. /* Special case: if session's session_id is zero, treat ioctl as a
  1021. * tunnel ioctl
  1022. */
  1023. ps = l2tp_session_priv(session);
  1024. if ((session->session_id == 0) &&
  1025. (session->peer_session_id == 0)) {
  1026. err = -EBADF;
  1027. tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
  1028. if (tunnel == NULL)
  1029. goto end_put_sess;
  1030. err = pppol2tp_tunnel_ioctl(tunnel, cmd, arg);
  1031. sock_put(ps->tunnel_sock);
  1032. goto end_put_sess;
  1033. }
  1034. err = pppol2tp_session_ioctl(session, cmd, arg);
  1035. end_put_sess:
  1036. sock_put(sk);
  1037. end:
  1038. return err;
  1039. }
  1040. /*****************************************************************************
  1041. * setsockopt() / getsockopt() support.
  1042. *
  1043. * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
  1044. * sockets. In order to control kernel tunnel features, we allow userspace to
  1045. * create a special "tunnel" PPPoX socket which is used for control only.
  1046. * Tunnel PPPoX sockets have session_id == 0 and simply allow the user
  1047. * application to issue L2TP setsockopt(), getsockopt() and ioctl() calls.
  1048. *****************************************************************************/
  1049. /* Tunnel setsockopt() helper.
  1050. */
  1051. static int pppol2tp_tunnel_setsockopt(struct sock *sk,
  1052. struct l2tp_tunnel *tunnel,
  1053. int optname, int val)
  1054. {
  1055. int err = 0;
  1056. switch (optname) {
  1057. case PPPOL2TP_SO_DEBUG:
  1058. tunnel->debug = val;
  1059. l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: set debug=%x\n",
  1060. tunnel->name, tunnel->debug);
  1061. break;
  1062. default:
  1063. err = -ENOPROTOOPT;
  1064. break;
  1065. }
  1066. return err;
  1067. }
  1068. /* Session setsockopt helper.
  1069. */
  1070. static int pppol2tp_session_setsockopt(struct sock *sk,
  1071. struct l2tp_session *session,
  1072. int optname, int val)
  1073. {
  1074. int err = 0;
  1075. struct pppol2tp_session *ps = l2tp_session_priv(session);
  1076. switch (optname) {
  1077. case PPPOL2TP_SO_RECVSEQ:
  1078. if ((val != 0) && (val != 1)) {
  1079. err = -EINVAL;
  1080. break;
  1081. }
  1082. session->recv_seq = !!val;
  1083. l2tp_info(session, L2TP_MSG_CONTROL,
  1084. "%s: set recv_seq=%d\n",
  1085. session->name, session->recv_seq);
  1086. break;
  1087. case PPPOL2TP_SO_SENDSEQ:
  1088. if ((val != 0) && (val != 1)) {
  1089. err = -EINVAL;
  1090. break;
  1091. }
  1092. session->send_seq = !!val;
  1093. {
  1094. struct sock *ssk = ps->sock;
  1095. struct pppox_sock *po = pppox_sk(ssk);
  1096. po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ :
  1097. PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
  1098. }
  1099. l2tp_session_set_header_len(session, session->tunnel->version);
  1100. l2tp_info(session, L2TP_MSG_CONTROL,
  1101. "%s: set send_seq=%d\n",
  1102. session->name, session->send_seq);
  1103. break;
  1104. case PPPOL2TP_SO_LNSMODE:
  1105. if ((val != 0) && (val != 1)) {
  1106. err = -EINVAL;
  1107. break;
  1108. }
  1109. session->lns_mode = !!val;
  1110. l2tp_info(session, L2TP_MSG_CONTROL,
  1111. "%s: set lns_mode=%d\n",
  1112. session->name, session->lns_mode);
  1113. break;
  1114. case PPPOL2TP_SO_DEBUG:
  1115. session->debug = val;
  1116. l2tp_info(session, L2TP_MSG_CONTROL, "%s: set debug=%x\n",
  1117. session->name, session->debug);
  1118. break;
  1119. case PPPOL2TP_SO_REORDERTO:
  1120. session->reorder_timeout = msecs_to_jiffies(val);
  1121. l2tp_info(session, L2TP_MSG_CONTROL,
  1122. "%s: set reorder_timeout=%d\n",
  1123. session->name, session->reorder_timeout);
  1124. break;
  1125. default:
  1126. err = -ENOPROTOOPT;
  1127. break;
  1128. }
  1129. return err;
  1130. }
  1131. /* Main setsockopt() entry point.
  1132. * Does API checks, then calls either the tunnel or session setsockopt
  1133. * handler, according to whether the PPPoL2TP socket is a for a regular
  1134. * session or the special tunnel type.
  1135. */
  1136. static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
  1137. char __user *optval, unsigned int optlen)
  1138. {
  1139. struct sock *sk = sock->sk;
  1140. struct l2tp_session *session;
  1141. struct l2tp_tunnel *tunnel;
  1142. struct pppol2tp_session *ps;
  1143. int val;
  1144. int err;
  1145. if (level != SOL_PPPOL2TP)
  1146. return -EINVAL;
  1147. if (optlen < sizeof(int))
  1148. return -EINVAL;
  1149. if (get_user(val, (int __user *)optval))
  1150. return -EFAULT;
  1151. err = -ENOTCONN;
  1152. if (sk->sk_user_data == NULL)
  1153. goto end;
  1154. /* Get session context from the socket */
  1155. err = -EBADF;
  1156. session = pppol2tp_sock_to_session(sk);
  1157. if (session == NULL)
  1158. goto end;
  1159. /* Special case: if session_id == 0x0000, treat as operation on tunnel
  1160. */
  1161. ps = l2tp_session_priv(session);
  1162. if ((session->session_id == 0) &&
  1163. (session->peer_session_id == 0)) {
  1164. err = -EBADF;
  1165. tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
  1166. if (tunnel == NULL)
  1167. goto end_put_sess;
  1168. err = pppol2tp_tunnel_setsockopt(sk, tunnel, optname, val);
  1169. sock_put(ps->tunnel_sock);
  1170. } else
  1171. err = pppol2tp_session_setsockopt(sk, session, optname, val);
  1172. err = 0;
  1173. end_put_sess:
  1174. sock_put(sk);
  1175. end:
  1176. return err;
  1177. }
  1178. /* Tunnel getsockopt helper. Called with sock locked.
  1179. */
  1180. static int pppol2tp_tunnel_getsockopt(struct sock *sk,
  1181. struct l2tp_tunnel *tunnel,
  1182. int optname, int *val)
  1183. {
  1184. int err = 0;
  1185. switch (optname) {
  1186. case PPPOL2TP_SO_DEBUG:
  1187. *val = tunnel->debug;
  1188. l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: get debug=%x\n",
  1189. tunnel->name, tunnel->debug);
  1190. break;
  1191. default:
  1192. err = -ENOPROTOOPT;
  1193. break;
  1194. }
  1195. return err;
  1196. }
  1197. /* Session getsockopt helper. Called with sock locked.
  1198. */
  1199. static int pppol2tp_session_getsockopt(struct sock *sk,
  1200. struct l2tp_session *session,
  1201. int optname, int *val)
  1202. {
  1203. int err = 0;
  1204. switch (optname) {
  1205. case PPPOL2TP_SO_RECVSEQ:
  1206. *val = session->recv_seq;
  1207. l2tp_info(session, L2TP_MSG_CONTROL,
  1208. "%s: get recv_seq=%d\n", session->name, *val);
  1209. break;
  1210. case PPPOL2TP_SO_SENDSEQ:
  1211. *val = session->send_seq;
  1212. l2tp_info(session, L2TP_MSG_CONTROL,
  1213. "%s: get send_seq=%d\n", session->name, *val);
  1214. break;
  1215. case PPPOL2TP_SO_LNSMODE:
  1216. *val = session->lns_mode;
  1217. l2tp_info(session, L2TP_MSG_CONTROL,
  1218. "%s: get lns_mode=%d\n", session->name, *val);
  1219. break;
  1220. case PPPOL2TP_SO_DEBUG:
  1221. *val = session->debug;
  1222. l2tp_info(session, L2TP_MSG_CONTROL, "%s: get debug=%d\n",
  1223. session->name, *val);
  1224. break;
  1225. case PPPOL2TP_SO_REORDERTO:
  1226. *val = (int) jiffies_to_msecs(session->reorder_timeout);
  1227. l2tp_info(session, L2TP_MSG_CONTROL,
  1228. "%s: get reorder_timeout=%d\n", session->name, *val);
  1229. break;
  1230. default:
  1231. err = -ENOPROTOOPT;
  1232. }
  1233. return err;
  1234. }
  1235. /* Main getsockopt() entry point.
  1236. * Does API checks, then calls either the tunnel or session getsockopt
  1237. * handler, according to whether the PPPoX socket is a for a regular session
  1238. * or the special tunnel type.
  1239. */
  1240. static int pppol2tp_getsockopt(struct socket *sock, int level, int optname,
  1241. char __user *optval, int __user *optlen)
  1242. {
  1243. struct sock *sk = sock->sk;
  1244. struct l2tp_session *session;
  1245. struct l2tp_tunnel *tunnel;
  1246. int val, len;
  1247. int err;
  1248. struct pppol2tp_session *ps;
  1249. if (level != SOL_PPPOL2TP)
  1250. return -EINVAL;
  1251. if (get_user(len, optlen))
  1252. return -EFAULT;
  1253. len = min_t(unsigned int, len, sizeof(int));
  1254. if (len < 0)
  1255. return -EINVAL;
  1256. err = -ENOTCONN;
  1257. if (sk->sk_user_data == NULL)
  1258. goto end;
  1259. /* Get the session context */
  1260. err = -EBADF;
  1261. session = pppol2tp_sock_to_session(sk);
  1262. if (session == NULL)
  1263. goto end;
  1264. /* Special case: if session_id == 0x0000, treat as operation on tunnel */
  1265. ps = l2tp_session_priv(session);
  1266. if ((session->session_id == 0) &&
  1267. (session->peer_session_id == 0)) {
  1268. err = -EBADF;
  1269. tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
  1270. if (tunnel == NULL)
  1271. goto end_put_sess;
  1272. err = pppol2tp_tunnel_getsockopt(sk, tunnel, optname, &val);
  1273. sock_put(ps->tunnel_sock);
  1274. } else
  1275. err = pppol2tp_session_getsockopt(sk, session, optname, &val);
  1276. err = -EFAULT;
  1277. if (put_user(len, optlen))
  1278. goto end_put_sess;
  1279. if (copy_to_user((void __user *) optval, &val, len))
  1280. goto end_put_sess;
  1281. err = 0;
  1282. end_put_sess:
  1283. sock_put(sk);
  1284. end:
  1285. return err;
  1286. }
  1287. /*****************************************************************************
  1288. * /proc filesystem for debug
  1289. * Since the original pppol2tp driver provided /proc/net/pppol2tp for
  1290. * L2TPv2, we dump only L2TPv2 tunnels and sessions here.
  1291. *****************************************************************************/
  1292. static unsigned int pppol2tp_net_id;
  1293. #ifdef CONFIG_PROC_FS
  1294. struct pppol2tp_seq_data {
  1295. struct seq_net_private p;
  1296. int tunnel_idx; /* current tunnel */
  1297. int session_idx; /* index of session within current tunnel */
  1298. struct l2tp_tunnel *tunnel;
  1299. struct l2tp_session *session; /* NULL means get next tunnel */
  1300. };
  1301. static void pppol2tp_next_tunnel(struct net *net, struct pppol2tp_seq_data *pd)
  1302. {
  1303. for (;;) {
  1304. pd->tunnel = l2tp_tunnel_find_nth(net, pd->tunnel_idx);
  1305. pd->tunnel_idx++;
  1306. if (pd->tunnel == NULL)
  1307. break;
  1308. /* Ignore L2TPv3 tunnels */
  1309. if (pd->tunnel->version < 3)
  1310. break;
  1311. }
  1312. }
  1313. static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd)
  1314. {
  1315. pd->session = l2tp_session_find_nth(pd->tunnel, pd->session_idx);
  1316. pd->session_idx++;
  1317. if (pd->session == NULL) {
  1318. pd->session_idx = 0;
  1319. pppol2tp_next_tunnel(net, pd);
  1320. }
  1321. }
  1322. static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
  1323. {
  1324. struct pppol2tp_seq_data *pd = SEQ_START_TOKEN;
  1325. loff_t pos = *offs;
  1326. struct net *net;
  1327. if (!pos)
  1328. goto out;
  1329. BUG_ON(m->private == NULL);
  1330. pd = m->private;
  1331. net = seq_file_net(m);
  1332. if (pd->tunnel == NULL)
  1333. pppol2tp_next_tunnel(net, pd);
  1334. else
  1335. pppol2tp_next_session(net, pd);
  1336. /* NULL tunnel and session indicates end of list */
  1337. if ((pd->tunnel == NULL) && (pd->session == NULL))
  1338. pd = NULL;
  1339. out:
  1340. return pd;
  1341. }
  1342. static void *pppol2tp_seq_next(struct seq_file *m, void *v, loff_t *pos)
  1343. {
  1344. (*pos)++;
  1345. return NULL;
  1346. }
  1347. static void pppol2tp_seq_stop(struct seq_file *p, void *v)
  1348. {
  1349. /* nothing to do */
  1350. }
  1351. static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v)
  1352. {
  1353. struct l2tp_tunnel *tunnel = v;
  1354. seq_printf(m, "\nTUNNEL '%s', %c %d\n",
  1355. tunnel->name,
  1356. (tunnel == tunnel->sock->sk_user_data) ? 'Y' : 'N',
  1357. atomic_read(&tunnel->ref_count) - 1);
  1358. seq_printf(m, " %08x %ld/%ld/%ld %ld/%ld/%ld\n",
  1359. tunnel->debug,
  1360. atomic_long_read(&tunnel->stats.tx_packets),
  1361. atomic_long_read(&tunnel->stats.tx_bytes),
  1362. atomic_long_read(&tunnel->stats.tx_errors),
  1363. atomic_long_read(&tunnel->stats.rx_packets),
  1364. atomic_long_read(&tunnel->stats.rx_bytes),
  1365. atomic_long_read(&tunnel->stats.rx_errors));
  1366. }
  1367. static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
  1368. {
  1369. struct l2tp_session *session = v;
  1370. struct l2tp_tunnel *tunnel = session->tunnel;
  1371. struct pppol2tp_session *ps = l2tp_session_priv(session);
  1372. struct pppox_sock *po = pppox_sk(ps->sock);
  1373. u32 ip = 0;
  1374. u16 port = 0;
  1375. if (tunnel->sock) {
  1376. struct inet_sock *inet = inet_sk(tunnel->sock);
  1377. ip = ntohl(inet->inet_saddr);
  1378. port = ntohs(inet->inet_sport);
  1379. }
  1380. seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> "
  1381. "%04X/%04X %d %c\n",
  1382. session->name, ip, port,
  1383. tunnel->tunnel_id,
  1384. session->session_id,
  1385. tunnel->peer_tunnel_id,
  1386. session->peer_session_id,
  1387. ps->sock->sk_state,
  1388. (session == ps->sock->sk_user_data) ?
  1389. 'Y' : 'N');
  1390. seq_printf(m, " %d/%d/%c/%c/%s %08x %u\n",
  1391. session->mtu, session->mru,
  1392. session->recv_seq ? 'R' : '-',
  1393. session->send_seq ? 'S' : '-',
  1394. session->lns_mode ? "LNS" : "LAC",
  1395. session->debug,
  1396. jiffies_to_msecs(session->reorder_timeout));
  1397. seq_printf(m, " %hu/%hu %ld/%ld/%ld %ld/%ld/%ld\n",
  1398. session->nr, session->ns,
  1399. atomic_long_read(&session->stats.tx_packets),
  1400. atomic_long_read(&session->stats.tx_bytes),
  1401. atomic_long_read(&session->stats.tx_errors),
  1402. atomic_long_read(&session->stats.rx_packets),
  1403. atomic_long_read(&session->stats.rx_bytes),
  1404. atomic_long_read(&session->stats.rx_errors));
  1405. if (po)
  1406. seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
  1407. }
  1408. static int pppol2tp_seq_show(struct seq_file *m, void *v)
  1409. {
  1410. struct pppol2tp_seq_data *pd = v;
  1411. /* display header on line 1 */
  1412. if (v == SEQ_START_TOKEN) {
  1413. seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n");
  1414. seq_puts(m, "TUNNEL name, user-data-ok session-count\n");
  1415. seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
  1416. seq_puts(m, " SESSION name, addr/port src-tid/sid "
  1417. "dest-tid/sid state user-data-ok\n");
  1418. seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n");
  1419. seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
  1420. goto out;
  1421. }
  1422. /* Show the tunnel or session context.
  1423. */
  1424. if (pd->session == NULL)
  1425. pppol2tp_seq_tunnel_show(m, pd->tunnel);
  1426. else
  1427. pppol2tp_seq_session_show(m, pd->session);
  1428. out:
  1429. return 0;
  1430. }
  1431. static const struct seq_operations pppol2tp_seq_ops = {
  1432. .start = pppol2tp_seq_start,
  1433. .next = pppol2tp_seq_next,
  1434. .stop = pppol2tp_seq_stop,
  1435. .show = pppol2tp_seq_show,
  1436. };
  1437. /* Called when our /proc file is opened. We allocate data for use when
  1438. * iterating our tunnel / session contexts and store it in the private
  1439. * data of the seq_file.
  1440. */
  1441. static int pppol2tp_proc_open(struct inode *inode, struct file *file)
  1442. {
  1443. return seq_open_net(inode, file, &pppol2tp_seq_ops,
  1444. sizeof(struct pppol2tp_seq_data));
  1445. }
  1446. static const struct file_operations pppol2tp_proc_fops = {
  1447. .owner = THIS_MODULE,
  1448. .open = pppol2tp_proc_open,
  1449. .read = seq_read,
  1450. .llseek = seq_lseek,
  1451. .release = seq_release_net,
  1452. };
  1453. #endif /* CONFIG_PROC_FS */
  1454. /*****************************************************************************
  1455. * Network namespace
  1456. *****************************************************************************/
  1457. static __net_init int pppol2tp_init_net(struct net *net)
  1458. {
  1459. struct proc_dir_entry *pde;
  1460. int err = 0;
  1461. pde = proc_create("pppol2tp", S_IRUGO, net->proc_net,
  1462. &pppol2tp_proc_fops);
  1463. if (!pde) {
  1464. err = -ENOMEM;
  1465. goto out;
  1466. }
  1467. out:
  1468. return err;
  1469. }
  1470. static __net_exit void pppol2tp_exit_net(struct net *net)
  1471. {
  1472. remove_proc_entry("pppol2tp", net->proc_net);
  1473. }
  1474. static struct pernet_operations pppol2tp_net_ops = {
  1475. .init = pppol2tp_init_net,
  1476. .exit = pppol2tp_exit_net,
  1477. .id = &pppol2tp_net_id,
  1478. };
  1479. /*****************************************************************************
  1480. * Init and cleanup
  1481. *****************************************************************************/
  1482. static const struct proto_ops pppol2tp_ops = {
  1483. .family = AF_PPPOX,
  1484. .owner = THIS_MODULE,
  1485. .release = pppol2tp_release,
  1486. .bind = sock_no_bind,
  1487. .connect = pppol2tp_connect,
  1488. .socketpair = sock_no_socketpair,
  1489. .accept = sock_no_accept,
  1490. .getname = pppol2tp_getname,
  1491. .poll = datagram_poll,
  1492. .listen = sock_no_listen,
  1493. .shutdown = sock_no_shutdown,
  1494. .setsockopt = pppol2tp_setsockopt,
  1495. .getsockopt = pppol2tp_getsockopt,
  1496. .sendmsg = pppol2tp_sendmsg,
  1497. .recvmsg = pppol2tp_recvmsg,
  1498. .mmap = sock_no_mmap,
  1499. .ioctl = pppox_ioctl,
  1500. };
  1501. static const struct pppox_proto pppol2tp_proto = {
  1502. .create = pppol2tp_create,
  1503. .ioctl = pppol2tp_ioctl,
  1504. .owner = THIS_MODULE,
  1505. };
  1506. #ifdef CONFIG_L2TP_V3
  1507. static const struct l2tp_nl_cmd_ops pppol2tp_nl_cmd_ops = {
  1508. .session_create = pppol2tp_session_create,
  1509. .session_delete = l2tp_session_delete,
  1510. };
  1511. #endif /* CONFIG_L2TP_V3 */
  1512. static int __init pppol2tp_init(void)
  1513. {
  1514. int err;
  1515. err = register_pernet_device(&pppol2tp_net_ops);
  1516. if (err)
  1517. goto out;
  1518. err = proto_register(&pppol2tp_sk_proto, 0);
  1519. if (err)
  1520. goto out_unregister_pppol2tp_pernet;
  1521. err = register_pppox_proto(PX_PROTO_OL2TP, &pppol2tp_proto);
  1522. if (err)
  1523. goto out_unregister_pppol2tp_proto;
  1524. #ifdef CONFIG_L2TP_V3
  1525. err = l2tp_nl_register_ops(L2TP_PWTYPE_PPP, &pppol2tp_nl_cmd_ops);
  1526. if (err)
  1527. goto out_unregister_pppox;
  1528. #endif
  1529. pr_info("PPPoL2TP kernel driver, %s\n", PPPOL2TP_DRV_VERSION);
  1530. out:
  1531. return err;
  1532. #ifdef CONFIG_L2TP_V3
  1533. out_unregister_pppox:
  1534. unregister_pppox_proto(PX_PROTO_OL2TP);
  1535. #endif
  1536. out_unregister_pppol2tp_proto:
  1537. proto_unregister(&pppol2tp_sk_proto);
  1538. out_unregister_pppol2tp_pernet:
  1539. unregister_pernet_device(&pppol2tp_net_ops);
  1540. goto out;
  1541. }
  1542. static void __exit pppol2tp_exit(void)
  1543. {
  1544. #ifdef CONFIG_L2TP_V3
  1545. l2tp_nl_unregister_ops(L2TP_PWTYPE_PPP);
  1546. #endif
  1547. unregister_pppox_proto(PX_PROTO_OL2TP);
  1548. proto_unregister(&pppol2tp_sk_proto);
  1549. unregister_pernet_device(&pppol2tp_net_ops);
  1550. }
  1551. module_init(pppol2tp_init);
  1552. module_exit(pppol2tp_exit);
  1553. MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
  1554. MODULE_DESCRIPTION("PPP over L2TP over UDP");
  1555. MODULE_LICENSE("GPL");
  1556. MODULE_VERSION(PPPOL2TP_DRV_VERSION);
  1557. MODULE_ALIAS_NET_PF_PROTO(PF_PPPOX, PX_PROTO_OL2TP);
  1558. MODULE_ALIAS_L2TP_PWTYPE(11);