l2tp_ppp.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  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, PPPOL2TP_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, PPPOL2TP_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, PPPOL2TP_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. skb_queue_purge(&sk->sk_receive_queue);
  384. skb_queue_purge(&sk->sk_write_queue);
  385. if (session) {
  386. sk->sk_user_data = NULL;
  387. BUG_ON(session->magic != L2TP_SESSION_MAGIC);
  388. l2tp_session_dec_refcount(session);
  389. }
  390. }
  391. /* Called when the PPPoX socket (session) is closed.
  392. */
  393. static int pppol2tp_release(struct socket *sock)
  394. {
  395. struct sock *sk = sock->sk;
  396. struct l2tp_session *session;
  397. int error;
  398. if (!sk)
  399. return 0;
  400. error = -EBADF;
  401. lock_sock(sk);
  402. if (sock_flag(sk, SOCK_DEAD) != 0)
  403. goto error;
  404. pppox_unbind_sock(sk);
  405. /* Signal the death of the socket. */
  406. sk->sk_state = PPPOX_DEAD;
  407. sock_orphan(sk);
  408. sock->sk = NULL;
  409. session = pppol2tp_sock_to_session(sk);
  410. /* Purge any queued data */
  411. if (session != NULL) {
  412. __l2tp_session_unhash(session);
  413. l2tp_session_queue_purge(session);
  414. sock_put(sk);
  415. }
  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. bool drop_refcnt = false;
  491. int ver = 2;
  492. int fd;
  493. lock_sock(sk);
  494. error = -EINVAL;
  495. if (sockaddr_len != sizeof(struct sockaddr_pppol2tp) &&
  496. sockaddr_len != sizeof(struct sockaddr_pppol2tpv3) &&
  497. sockaddr_len != sizeof(struct sockaddr_pppol2tpin6) &&
  498. sockaddr_len != sizeof(struct sockaddr_pppol2tpv3in6))
  499. goto end;
  500. if (sp->sa_protocol != PX_PROTO_OL2TP)
  501. goto end;
  502. /* Check for already bound sockets */
  503. error = -EBUSY;
  504. if (sk->sk_state & PPPOX_CONNECTED)
  505. goto end;
  506. /* We don't supporting rebinding anyway */
  507. error = -EALREADY;
  508. if (sk->sk_user_data)
  509. goto end; /* socket is already attached */
  510. /* Get params from socket address. Handle L2TPv2 and L2TPv3.
  511. * This is nasty because there are different sockaddr_pppol2tp
  512. * structs for L2TPv2, L2TPv3, over IPv4 and IPv6. We use
  513. * the sockaddr size to determine which structure the caller
  514. * is using.
  515. */
  516. peer_tunnel_id = 0;
  517. if (sockaddr_len == sizeof(struct sockaddr_pppol2tp)) {
  518. fd = sp->pppol2tp.fd;
  519. tunnel_id = sp->pppol2tp.s_tunnel;
  520. peer_tunnel_id = sp->pppol2tp.d_tunnel;
  521. session_id = sp->pppol2tp.s_session;
  522. peer_session_id = sp->pppol2tp.d_session;
  523. } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpv3)) {
  524. struct sockaddr_pppol2tpv3 *sp3 =
  525. (struct sockaddr_pppol2tpv3 *) sp;
  526. ver = 3;
  527. fd = sp3->pppol2tp.fd;
  528. tunnel_id = sp3->pppol2tp.s_tunnel;
  529. peer_tunnel_id = sp3->pppol2tp.d_tunnel;
  530. session_id = sp3->pppol2tp.s_session;
  531. peer_session_id = sp3->pppol2tp.d_session;
  532. } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpin6)) {
  533. struct sockaddr_pppol2tpin6 *sp6 =
  534. (struct sockaddr_pppol2tpin6 *) sp;
  535. fd = sp6->pppol2tp.fd;
  536. tunnel_id = sp6->pppol2tp.s_tunnel;
  537. peer_tunnel_id = sp6->pppol2tp.d_tunnel;
  538. session_id = sp6->pppol2tp.s_session;
  539. peer_session_id = sp6->pppol2tp.d_session;
  540. } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpv3in6)) {
  541. struct sockaddr_pppol2tpv3in6 *sp6 =
  542. (struct sockaddr_pppol2tpv3in6 *) sp;
  543. ver = 3;
  544. fd = sp6->pppol2tp.fd;
  545. tunnel_id = sp6->pppol2tp.s_tunnel;
  546. peer_tunnel_id = sp6->pppol2tp.d_tunnel;
  547. session_id = sp6->pppol2tp.s_session;
  548. peer_session_id = sp6->pppol2tp.d_session;
  549. } else {
  550. error = -EINVAL;
  551. goto end; /* bad socket address */
  552. }
  553. /* Don't bind if tunnel_id is 0 */
  554. error = -EINVAL;
  555. if (tunnel_id == 0)
  556. goto end;
  557. tunnel = l2tp_tunnel_find(sock_net(sk), tunnel_id);
  558. /* Special case: create tunnel context if session_id and
  559. * peer_session_id is 0. Otherwise look up tunnel using supplied
  560. * tunnel id.
  561. */
  562. if ((session_id == 0) && (peer_session_id == 0)) {
  563. if (tunnel == NULL) {
  564. struct l2tp_tunnel_cfg tcfg = {
  565. .encap = L2TP_ENCAPTYPE_UDP,
  566. .debug = 0,
  567. };
  568. error = l2tp_tunnel_create(sock_net(sk), fd, ver, tunnel_id, peer_tunnel_id, &tcfg, &tunnel);
  569. if (error < 0)
  570. goto end;
  571. }
  572. } else {
  573. /* Error if we can't find the tunnel */
  574. error = -ENOENT;
  575. if (tunnel == NULL)
  576. goto end;
  577. /* Error if socket is not prepped */
  578. if (tunnel->sock == NULL)
  579. goto end;
  580. }
  581. if (tunnel->recv_payload_hook == NULL)
  582. tunnel->recv_payload_hook = pppol2tp_recv_payload_hook;
  583. if (tunnel->peer_tunnel_id == 0)
  584. tunnel->peer_tunnel_id = peer_tunnel_id;
  585. session = l2tp_session_get(sock_net(sk), tunnel, session_id, false);
  586. if (session) {
  587. drop_refcnt = true;
  588. ps = l2tp_session_priv(session);
  589. /* Using a pre-existing session is fine as long as it hasn't
  590. * been connected yet.
  591. */
  592. if (ps->sock) {
  593. error = -EEXIST;
  594. goto end;
  595. }
  596. /* consistency checks */
  597. if (ps->tunnel_sock != tunnel->sock) {
  598. error = -EEXIST;
  599. goto end;
  600. }
  601. } else {
  602. /* Default MTU must allow space for UDP/L2TP/PPP headers */
  603. cfg.mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD;
  604. cfg.mru = cfg.mtu;
  605. session = l2tp_session_create(sizeof(struct pppol2tp_session),
  606. tunnel, session_id,
  607. peer_session_id, &cfg);
  608. if (IS_ERR(session)) {
  609. error = PTR_ERR(session);
  610. goto end;
  611. }
  612. }
  613. /* Associate session with its PPPoL2TP socket */
  614. ps = l2tp_session_priv(session);
  615. ps->owner = current->pid;
  616. ps->sock = sk;
  617. ps->tunnel_sock = tunnel->sock;
  618. session->recv_skb = pppol2tp_recv;
  619. session->session_close = pppol2tp_session_close;
  620. #if IS_ENABLED(CONFIG_L2TP_DEBUGFS)
  621. session->show = pppol2tp_show;
  622. #endif
  623. /* We need to know each time a skb is dropped from the reorder
  624. * queue.
  625. */
  626. session->ref = pppol2tp_session_sock_hold;
  627. session->deref = pppol2tp_session_sock_put;
  628. /* If PMTU discovery was enabled, use the MTU that was discovered */
  629. dst = sk_dst_get(tunnel->sock);
  630. if (dst != NULL) {
  631. u32 pmtu = dst_mtu(dst);
  632. if (pmtu != 0)
  633. session->mtu = session->mru = pmtu -
  634. PPPOL2TP_HEADER_OVERHEAD;
  635. dst_release(dst);
  636. }
  637. /* Special case: if source & dest session_id == 0x0000, this
  638. * socket is being created to manage the tunnel. Just set up
  639. * the internal context for use by ioctl() and sockopt()
  640. * handlers.
  641. */
  642. if ((session->session_id == 0) &&
  643. (session->peer_session_id == 0)) {
  644. error = 0;
  645. goto out_no_ppp;
  646. }
  647. /* The only header we need to worry about is the L2TP
  648. * header. This size is different depending on whether
  649. * sequence numbers are enabled for the data channel.
  650. */
  651. po->chan.hdrlen = PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
  652. po->chan.private = sk;
  653. po->chan.ops = &pppol2tp_chan_ops;
  654. po->chan.mtu = session->mtu;
  655. error = ppp_register_net_channel(sock_net(sk), &po->chan);
  656. if (error)
  657. goto end;
  658. out_no_ppp:
  659. /* This is how we get the session context from the socket. */
  660. sk->sk_user_data = session;
  661. sk->sk_state = PPPOX_CONNECTED;
  662. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: created\n",
  663. session->name);
  664. end:
  665. if (drop_refcnt)
  666. l2tp_session_dec_refcount(session);
  667. release_sock(sk);
  668. return error;
  669. }
  670. #ifdef CONFIG_L2TP_V3
  671. /* Called when creating sessions via the netlink interface.
  672. */
  673. static int pppol2tp_session_create(struct net *net, u32 tunnel_id, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg)
  674. {
  675. int error;
  676. struct l2tp_tunnel *tunnel;
  677. struct l2tp_session *session;
  678. struct pppol2tp_session *ps;
  679. tunnel = l2tp_tunnel_find(net, tunnel_id);
  680. /* Error if we can't find the tunnel */
  681. error = -ENOENT;
  682. if (tunnel == NULL)
  683. goto out;
  684. /* Error if tunnel socket is not prepped */
  685. if (tunnel->sock == NULL)
  686. goto out;
  687. /* Default MTU values. */
  688. if (cfg->mtu == 0)
  689. cfg->mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD;
  690. if (cfg->mru == 0)
  691. cfg->mru = cfg->mtu;
  692. /* Allocate and initialize a new session context. */
  693. session = l2tp_session_create(sizeof(struct pppol2tp_session),
  694. tunnel, session_id,
  695. peer_session_id, cfg);
  696. if (IS_ERR(session)) {
  697. error = PTR_ERR(session);
  698. goto out;
  699. }
  700. ps = l2tp_session_priv(session);
  701. ps->tunnel_sock = tunnel->sock;
  702. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: created\n",
  703. session->name);
  704. error = 0;
  705. out:
  706. return error;
  707. }
  708. #endif /* CONFIG_L2TP_V3 */
  709. /* getname() support.
  710. */
  711. static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
  712. int *usockaddr_len, int peer)
  713. {
  714. int len = 0;
  715. int error = 0;
  716. struct l2tp_session *session;
  717. struct l2tp_tunnel *tunnel;
  718. struct sock *sk = sock->sk;
  719. struct inet_sock *inet;
  720. struct pppol2tp_session *pls;
  721. error = -ENOTCONN;
  722. if (sk == NULL)
  723. goto end;
  724. if (!(sk->sk_state & PPPOX_CONNECTED))
  725. goto end;
  726. error = -EBADF;
  727. session = pppol2tp_sock_to_session(sk);
  728. if (session == NULL)
  729. goto end;
  730. pls = l2tp_session_priv(session);
  731. tunnel = l2tp_sock_to_tunnel(pls->tunnel_sock);
  732. if (tunnel == NULL)
  733. goto end_put_sess;
  734. inet = inet_sk(tunnel->sock);
  735. if ((tunnel->version == 2) && (tunnel->sock->sk_family == AF_INET)) {
  736. struct sockaddr_pppol2tp sp;
  737. len = sizeof(sp);
  738. memset(&sp, 0, len);
  739. sp.sa_family = AF_PPPOX;
  740. sp.sa_protocol = PX_PROTO_OL2TP;
  741. sp.pppol2tp.fd = tunnel->fd;
  742. sp.pppol2tp.pid = pls->owner;
  743. sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
  744. sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
  745. sp.pppol2tp.s_session = session->session_id;
  746. sp.pppol2tp.d_session = session->peer_session_id;
  747. sp.pppol2tp.addr.sin_family = AF_INET;
  748. sp.pppol2tp.addr.sin_port = inet->inet_dport;
  749. sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
  750. memcpy(uaddr, &sp, len);
  751. #if IS_ENABLED(CONFIG_IPV6)
  752. } else if ((tunnel->version == 2) &&
  753. (tunnel->sock->sk_family == AF_INET6)) {
  754. struct sockaddr_pppol2tpin6 sp;
  755. len = sizeof(sp);
  756. memset(&sp, 0, len);
  757. sp.sa_family = AF_PPPOX;
  758. sp.sa_protocol = PX_PROTO_OL2TP;
  759. sp.pppol2tp.fd = tunnel->fd;
  760. sp.pppol2tp.pid = pls->owner;
  761. sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
  762. sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
  763. sp.pppol2tp.s_session = session->session_id;
  764. sp.pppol2tp.d_session = session->peer_session_id;
  765. sp.pppol2tp.addr.sin6_family = AF_INET6;
  766. sp.pppol2tp.addr.sin6_port = inet->inet_dport;
  767. memcpy(&sp.pppol2tp.addr.sin6_addr, &tunnel->sock->sk_v6_daddr,
  768. sizeof(tunnel->sock->sk_v6_daddr));
  769. memcpy(uaddr, &sp, len);
  770. } else if ((tunnel->version == 3) &&
  771. (tunnel->sock->sk_family == AF_INET6)) {
  772. struct sockaddr_pppol2tpv3in6 sp;
  773. len = sizeof(sp);
  774. memset(&sp, 0, len);
  775. sp.sa_family = AF_PPPOX;
  776. sp.sa_protocol = PX_PROTO_OL2TP;
  777. sp.pppol2tp.fd = tunnel->fd;
  778. sp.pppol2tp.pid = pls->owner;
  779. sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
  780. sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
  781. sp.pppol2tp.s_session = session->session_id;
  782. sp.pppol2tp.d_session = session->peer_session_id;
  783. sp.pppol2tp.addr.sin6_family = AF_INET6;
  784. sp.pppol2tp.addr.sin6_port = inet->inet_dport;
  785. memcpy(&sp.pppol2tp.addr.sin6_addr, &tunnel->sock->sk_v6_daddr,
  786. sizeof(tunnel->sock->sk_v6_daddr));
  787. memcpy(uaddr, &sp, len);
  788. #endif
  789. } else if (tunnel->version == 3) {
  790. struct sockaddr_pppol2tpv3 sp;
  791. len = sizeof(sp);
  792. memset(&sp, 0, len);
  793. sp.sa_family = AF_PPPOX;
  794. sp.sa_protocol = PX_PROTO_OL2TP;
  795. sp.pppol2tp.fd = tunnel->fd;
  796. sp.pppol2tp.pid = pls->owner;
  797. sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
  798. sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
  799. sp.pppol2tp.s_session = session->session_id;
  800. sp.pppol2tp.d_session = session->peer_session_id;
  801. sp.pppol2tp.addr.sin_family = AF_INET;
  802. sp.pppol2tp.addr.sin_port = inet->inet_dport;
  803. sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
  804. memcpy(uaddr, &sp, len);
  805. }
  806. *usockaddr_len = len;
  807. error = 0;
  808. sock_put(pls->tunnel_sock);
  809. end_put_sess:
  810. sock_put(sk);
  811. end:
  812. return error;
  813. }
  814. /****************************************************************************
  815. * ioctl() handlers.
  816. *
  817. * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
  818. * sockets. However, in order to control kernel tunnel features, we allow
  819. * userspace to create a special "tunnel" PPPoX socket which is used for
  820. * control only. Tunnel PPPoX sockets have session_id == 0 and simply allow
  821. * the user application to issue L2TP setsockopt(), getsockopt() and ioctl()
  822. * calls.
  823. ****************************************************************************/
  824. static void pppol2tp_copy_stats(struct pppol2tp_ioc_stats *dest,
  825. struct l2tp_stats *stats)
  826. {
  827. dest->tx_packets = atomic_long_read(&stats->tx_packets);
  828. dest->tx_bytes = atomic_long_read(&stats->tx_bytes);
  829. dest->tx_errors = atomic_long_read(&stats->tx_errors);
  830. dest->rx_packets = atomic_long_read(&stats->rx_packets);
  831. dest->rx_bytes = atomic_long_read(&stats->rx_bytes);
  832. dest->rx_seq_discards = atomic_long_read(&stats->rx_seq_discards);
  833. dest->rx_oos_packets = atomic_long_read(&stats->rx_oos_packets);
  834. dest->rx_errors = atomic_long_read(&stats->rx_errors);
  835. }
  836. /* Session ioctl helper.
  837. */
  838. static int pppol2tp_session_ioctl(struct l2tp_session *session,
  839. unsigned int cmd, unsigned long arg)
  840. {
  841. struct ifreq ifr;
  842. int err = 0;
  843. struct sock *sk;
  844. int val = (int) arg;
  845. struct pppol2tp_session *ps = l2tp_session_priv(session);
  846. struct l2tp_tunnel *tunnel = session->tunnel;
  847. struct pppol2tp_ioc_stats stats;
  848. l2tp_dbg(session, PPPOL2TP_MSG_CONTROL,
  849. "%s: pppol2tp_session_ioctl(cmd=%#x, arg=%#lx)\n",
  850. session->name, cmd, arg);
  851. sk = ps->sock;
  852. if (!sk)
  853. return -EBADR;
  854. sock_hold(sk);
  855. switch (cmd) {
  856. case SIOCGIFMTU:
  857. err = -ENXIO;
  858. if (!(sk->sk_state & PPPOX_CONNECTED))
  859. break;
  860. err = -EFAULT;
  861. if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
  862. break;
  863. ifr.ifr_mtu = session->mtu;
  864. if (copy_to_user((void __user *) arg, &ifr, sizeof(struct ifreq)))
  865. break;
  866. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: get mtu=%d\n",
  867. session->name, session->mtu);
  868. err = 0;
  869. break;
  870. case SIOCSIFMTU:
  871. err = -ENXIO;
  872. if (!(sk->sk_state & PPPOX_CONNECTED))
  873. break;
  874. err = -EFAULT;
  875. if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
  876. break;
  877. session->mtu = ifr.ifr_mtu;
  878. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: set mtu=%d\n",
  879. session->name, session->mtu);
  880. err = 0;
  881. break;
  882. case PPPIOCGMRU:
  883. err = -ENXIO;
  884. if (!(sk->sk_state & PPPOX_CONNECTED))
  885. break;
  886. err = -EFAULT;
  887. if (put_user(session->mru, (int __user *) arg))
  888. break;
  889. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: get mru=%d\n",
  890. session->name, session->mru);
  891. err = 0;
  892. break;
  893. case PPPIOCSMRU:
  894. err = -ENXIO;
  895. if (!(sk->sk_state & PPPOX_CONNECTED))
  896. break;
  897. err = -EFAULT;
  898. if (get_user(val, (int __user *) arg))
  899. break;
  900. session->mru = val;
  901. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: set mru=%d\n",
  902. session->name, session->mru);
  903. err = 0;
  904. break;
  905. case PPPIOCGFLAGS:
  906. err = -EFAULT;
  907. if (put_user(ps->flags, (int __user *) arg))
  908. break;
  909. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: get flags=%d\n",
  910. session->name, ps->flags);
  911. err = 0;
  912. break;
  913. case PPPIOCSFLAGS:
  914. err = -EFAULT;
  915. if (get_user(val, (int __user *) arg))
  916. break;
  917. ps->flags = val;
  918. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: set flags=%d\n",
  919. session->name, ps->flags);
  920. err = 0;
  921. break;
  922. case PPPIOCGL2TPSTATS:
  923. err = -ENXIO;
  924. if (!(sk->sk_state & PPPOX_CONNECTED))
  925. break;
  926. memset(&stats, 0, sizeof(stats));
  927. stats.tunnel_id = tunnel->tunnel_id;
  928. stats.session_id = session->session_id;
  929. pppol2tp_copy_stats(&stats, &session->stats);
  930. if (copy_to_user((void __user *) arg, &stats,
  931. sizeof(stats)))
  932. break;
  933. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: get L2TP stats\n",
  934. session->name);
  935. err = 0;
  936. break;
  937. default:
  938. err = -ENOSYS;
  939. break;
  940. }
  941. sock_put(sk);
  942. return err;
  943. }
  944. /* Tunnel ioctl helper.
  945. *
  946. * Note the special handling for PPPIOCGL2TPSTATS below. If the ioctl data
  947. * specifies a session_id, the session ioctl handler is called. This allows an
  948. * application to retrieve session stats via a tunnel socket.
  949. */
  950. static int pppol2tp_tunnel_ioctl(struct l2tp_tunnel *tunnel,
  951. unsigned int cmd, unsigned long arg)
  952. {
  953. int err = 0;
  954. struct sock *sk;
  955. struct pppol2tp_ioc_stats stats;
  956. l2tp_dbg(tunnel, PPPOL2TP_MSG_CONTROL,
  957. "%s: pppol2tp_tunnel_ioctl(cmd=%#x, arg=%#lx)\n",
  958. tunnel->name, cmd, arg);
  959. sk = tunnel->sock;
  960. sock_hold(sk);
  961. switch (cmd) {
  962. case PPPIOCGL2TPSTATS:
  963. err = -ENXIO;
  964. if (!(sk->sk_state & PPPOX_CONNECTED))
  965. break;
  966. if (copy_from_user(&stats, (void __user *) arg,
  967. sizeof(stats))) {
  968. err = -EFAULT;
  969. break;
  970. }
  971. if (stats.session_id != 0) {
  972. /* resend to session ioctl handler */
  973. struct l2tp_session *session =
  974. l2tp_session_get(sock_net(sk), tunnel,
  975. stats.session_id, true);
  976. if (session) {
  977. err = pppol2tp_session_ioctl(session, cmd,
  978. arg);
  979. if (session->deref)
  980. session->deref(session);
  981. l2tp_session_dec_refcount(session);
  982. } else {
  983. err = -EBADR;
  984. }
  985. break;
  986. }
  987. #ifdef CONFIG_XFRM
  988. stats.using_ipsec = (sk->sk_policy[0] || sk->sk_policy[1]) ? 1 : 0;
  989. #endif
  990. pppol2tp_copy_stats(&stats, &tunnel->stats);
  991. if (copy_to_user((void __user *) arg, &stats, sizeof(stats))) {
  992. err = -EFAULT;
  993. break;
  994. }
  995. l2tp_info(tunnel, PPPOL2TP_MSG_CONTROL, "%s: get L2TP stats\n",
  996. tunnel->name);
  997. err = 0;
  998. break;
  999. default:
  1000. err = -ENOSYS;
  1001. break;
  1002. }
  1003. sock_put(sk);
  1004. return err;
  1005. }
  1006. /* Main ioctl() handler.
  1007. * Dispatch to tunnel or session helpers depending on the socket.
  1008. */
  1009. static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
  1010. unsigned long arg)
  1011. {
  1012. struct sock *sk = sock->sk;
  1013. struct l2tp_session *session;
  1014. struct l2tp_tunnel *tunnel;
  1015. struct pppol2tp_session *ps;
  1016. int err;
  1017. if (!sk)
  1018. return 0;
  1019. err = -EBADF;
  1020. if (sock_flag(sk, SOCK_DEAD) != 0)
  1021. goto end;
  1022. err = -ENOTCONN;
  1023. if ((sk->sk_user_data == NULL) ||
  1024. (!(sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND))))
  1025. goto end;
  1026. /* Get session context from the socket */
  1027. err = -EBADF;
  1028. session = pppol2tp_sock_to_session(sk);
  1029. if (session == NULL)
  1030. goto end;
  1031. /* Special case: if session's session_id is zero, treat ioctl as a
  1032. * tunnel ioctl
  1033. */
  1034. ps = l2tp_session_priv(session);
  1035. if ((session->session_id == 0) &&
  1036. (session->peer_session_id == 0)) {
  1037. err = -EBADF;
  1038. tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
  1039. if (tunnel == NULL)
  1040. goto end_put_sess;
  1041. err = pppol2tp_tunnel_ioctl(tunnel, cmd, arg);
  1042. sock_put(ps->tunnel_sock);
  1043. goto end_put_sess;
  1044. }
  1045. err = pppol2tp_session_ioctl(session, cmd, arg);
  1046. end_put_sess:
  1047. sock_put(sk);
  1048. end:
  1049. return err;
  1050. }
  1051. /*****************************************************************************
  1052. * setsockopt() / getsockopt() support.
  1053. *
  1054. * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
  1055. * sockets. In order to control kernel tunnel features, we allow userspace to
  1056. * create a special "tunnel" PPPoX socket which is used for control only.
  1057. * Tunnel PPPoX sockets have session_id == 0 and simply allow the user
  1058. * application to issue L2TP setsockopt(), getsockopt() and ioctl() calls.
  1059. *****************************************************************************/
  1060. /* Tunnel setsockopt() helper.
  1061. */
  1062. static int pppol2tp_tunnel_setsockopt(struct sock *sk,
  1063. struct l2tp_tunnel *tunnel,
  1064. int optname, int val)
  1065. {
  1066. int err = 0;
  1067. switch (optname) {
  1068. case PPPOL2TP_SO_DEBUG:
  1069. tunnel->debug = val;
  1070. l2tp_info(tunnel, PPPOL2TP_MSG_CONTROL, "%s: set debug=%x\n",
  1071. tunnel->name, tunnel->debug);
  1072. break;
  1073. default:
  1074. err = -ENOPROTOOPT;
  1075. break;
  1076. }
  1077. return err;
  1078. }
  1079. /* Session setsockopt helper.
  1080. */
  1081. static int pppol2tp_session_setsockopt(struct sock *sk,
  1082. struct l2tp_session *session,
  1083. int optname, int val)
  1084. {
  1085. int err = 0;
  1086. struct pppol2tp_session *ps = l2tp_session_priv(session);
  1087. switch (optname) {
  1088. case PPPOL2TP_SO_RECVSEQ:
  1089. if ((val != 0) && (val != 1)) {
  1090. err = -EINVAL;
  1091. break;
  1092. }
  1093. session->recv_seq = val ? -1 : 0;
  1094. l2tp_info(session, PPPOL2TP_MSG_CONTROL,
  1095. "%s: set recv_seq=%d\n",
  1096. session->name, session->recv_seq);
  1097. break;
  1098. case PPPOL2TP_SO_SENDSEQ:
  1099. if ((val != 0) && (val != 1)) {
  1100. err = -EINVAL;
  1101. break;
  1102. }
  1103. session->send_seq = val ? -1 : 0;
  1104. {
  1105. struct sock *ssk = ps->sock;
  1106. struct pppox_sock *po = pppox_sk(ssk);
  1107. po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ :
  1108. PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
  1109. }
  1110. l2tp_session_set_header_len(session, session->tunnel->version);
  1111. l2tp_info(session, PPPOL2TP_MSG_CONTROL,
  1112. "%s: set send_seq=%d\n",
  1113. session->name, session->send_seq);
  1114. break;
  1115. case PPPOL2TP_SO_LNSMODE:
  1116. if ((val != 0) && (val != 1)) {
  1117. err = -EINVAL;
  1118. break;
  1119. }
  1120. session->lns_mode = val ? -1 : 0;
  1121. l2tp_info(session, PPPOL2TP_MSG_CONTROL,
  1122. "%s: set lns_mode=%d\n",
  1123. session->name, session->lns_mode);
  1124. break;
  1125. case PPPOL2TP_SO_DEBUG:
  1126. session->debug = val;
  1127. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: set debug=%x\n",
  1128. session->name, session->debug);
  1129. break;
  1130. case PPPOL2TP_SO_REORDERTO:
  1131. session->reorder_timeout = msecs_to_jiffies(val);
  1132. l2tp_info(session, PPPOL2TP_MSG_CONTROL,
  1133. "%s: set reorder_timeout=%d\n",
  1134. session->name, session->reorder_timeout);
  1135. break;
  1136. default:
  1137. err = -ENOPROTOOPT;
  1138. break;
  1139. }
  1140. return err;
  1141. }
  1142. /* Main setsockopt() entry point.
  1143. * Does API checks, then calls either the tunnel or session setsockopt
  1144. * handler, according to whether the PPPoL2TP socket is a for a regular
  1145. * session or the special tunnel type.
  1146. */
  1147. static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
  1148. char __user *optval, unsigned int optlen)
  1149. {
  1150. struct sock *sk = sock->sk;
  1151. struct l2tp_session *session;
  1152. struct l2tp_tunnel *tunnel;
  1153. struct pppol2tp_session *ps;
  1154. int val;
  1155. int err;
  1156. if (level != SOL_PPPOL2TP)
  1157. return -EINVAL;
  1158. if (optlen < sizeof(int))
  1159. return -EINVAL;
  1160. if (get_user(val, (int __user *)optval))
  1161. return -EFAULT;
  1162. err = -ENOTCONN;
  1163. if (sk->sk_user_data == NULL)
  1164. goto end;
  1165. /* Get session context from the socket */
  1166. err = -EBADF;
  1167. session = pppol2tp_sock_to_session(sk);
  1168. if (session == NULL)
  1169. goto end;
  1170. /* Special case: if session_id == 0x0000, treat as operation on tunnel
  1171. */
  1172. ps = l2tp_session_priv(session);
  1173. if ((session->session_id == 0) &&
  1174. (session->peer_session_id == 0)) {
  1175. err = -EBADF;
  1176. tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
  1177. if (tunnel == NULL)
  1178. goto end_put_sess;
  1179. err = pppol2tp_tunnel_setsockopt(sk, tunnel, optname, val);
  1180. sock_put(ps->tunnel_sock);
  1181. } else
  1182. err = pppol2tp_session_setsockopt(sk, session, optname, val);
  1183. err = 0;
  1184. end_put_sess:
  1185. sock_put(sk);
  1186. end:
  1187. return err;
  1188. }
  1189. /* Tunnel getsockopt helper. Called with sock locked.
  1190. */
  1191. static int pppol2tp_tunnel_getsockopt(struct sock *sk,
  1192. struct l2tp_tunnel *tunnel,
  1193. int optname, int *val)
  1194. {
  1195. int err = 0;
  1196. switch (optname) {
  1197. case PPPOL2TP_SO_DEBUG:
  1198. *val = tunnel->debug;
  1199. l2tp_info(tunnel, PPPOL2TP_MSG_CONTROL, "%s: get debug=%x\n",
  1200. tunnel->name, tunnel->debug);
  1201. break;
  1202. default:
  1203. err = -ENOPROTOOPT;
  1204. break;
  1205. }
  1206. return err;
  1207. }
  1208. /* Session getsockopt helper. Called with sock locked.
  1209. */
  1210. static int pppol2tp_session_getsockopt(struct sock *sk,
  1211. struct l2tp_session *session,
  1212. int optname, int *val)
  1213. {
  1214. int err = 0;
  1215. switch (optname) {
  1216. case PPPOL2TP_SO_RECVSEQ:
  1217. *val = session->recv_seq;
  1218. l2tp_info(session, PPPOL2TP_MSG_CONTROL,
  1219. "%s: get recv_seq=%d\n", session->name, *val);
  1220. break;
  1221. case PPPOL2TP_SO_SENDSEQ:
  1222. *val = session->send_seq;
  1223. l2tp_info(session, PPPOL2TP_MSG_CONTROL,
  1224. "%s: get send_seq=%d\n", session->name, *val);
  1225. break;
  1226. case PPPOL2TP_SO_LNSMODE:
  1227. *val = session->lns_mode;
  1228. l2tp_info(session, PPPOL2TP_MSG_CONTROL,
  1229. "%s: get lns_mode=%d\n", session->name, *val);
  1230. break;
  1231. case PPPOL2TP_SO_DEBUG:
  1232. *val = session->debug;
  1233. l2tp_info(session, PPPOL2TP_MSG_CONTROL, "%s: get debug=%d\n",
  1234. session->name, *val);
  1235. break;
  1236. case PPPOL2TP_SO_REORDERTO:
  1237. *val = (int) jiffies_to_msecs(session->reorder_timeout);
  1238. l2tp_info(session, PPPOL2TP_MSG_CONTROL,
  1239. "%s: get reorder_timeout=%d\n", session->name, *val);
  1240. break;
  1241. default:
  1242. err = -ENOPROTOOPT;
  1243. }
  1244. return err;
  1245. }
  1246. /* Main getsockopt() entry point.
  1247. * Does API checks, then calls either the tunnel or session getsockopt
  1248. * handler, according to whether the PPPoX socket is a for a regular session
  1249. * or the special tunnel type.
  1250. */
  1251. static int pppol2tp_getsockopt(struct socket *sock, int level, int optname,
  1252. char __user *optval, int __user *optlen)
  1253. {
  1254. struct sock *sk = sock->sk;
  1255. struct l2tp_session *session;
  1256. struct l2tp_tunnel *tunnel;
  1257. int val, len;
  1258. int err;
  1259. struct pppol2tp_session *ps;
  1260. if (level != SOL_PPPOL2TP)
  1261. return -EINVAL;
  1262. if (get_user(len, optlen))
  1263. return -EFAULT;
  1264. len = min_t(unsigned int, len, sizeof(int));
  1265. if (len < 0)
  1266. return -EINVAL;
  1267. err = -ENOTCONN;
  1268. if (sk->sk_user_data == NULL)
  1269. goto end;
  1270. /* Get the session context */
  1271. err = -EBADF;
  1272. session = pppol2tp_sock_to_session(sk);
  1273. if (session == NULL)
  1274. goto end;
  1275. /* Special case: if session_id == 0x0000, treat as operation on tunnel */
  1276. ps = l2tp_session_priv(session);
  1277. if ((session->session_id == 0) &&
  1278. (session->peer_session_id == 0)) {
  1279. err = -EBADF;
  1280. tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
  1281. if (tunnel == NULL)
  1282. goto end_put_sess;
  1283. err = pppol2tp_tunnel_getsockopt(sk, tunnel, optname, &val);
  1284. sock_put(ps->tunnel_sock);
  1285. } else
  1286. err = pppol2tp_session_getsockopt(sk, session, optname, &val);
  1287. err = -EFAULT;
  1288. if (put_user(len, optlen))
  1289. goto end_put_sess;
  1290. if (copy_to_user((void __user *) optval, &val, len))
  1291. goto end_put_sess;
  1292. err = 0;
  1293. end_put_sess:
  1294. sock_put(sk);
  1295. end:
  1296. return err;
  1297. }
  1298. /*****************************************************************************
  1299. * /proc filesystem for debug
  1300. * Since the original pppol2tp driver provided /proc/net/pppol2tp for
  1301. * L2TPv2, we dump only L2TPv2 tunnels and sessions here.
  1302. *****************************************************************************/
  1303. static unsigned int pppol2tp_net_id;
  1304. #ifdef CONFIG_PROC_FS
  1305. struct pppol2tp_seq_data {
  1306. struct seq_net_private p;
  1307. int tunnel_idx; /* current tunnel */
  1308. int session_idx; /* index of session within current tunnel */
  1309. struct l2tp_tunnel *tunnel;
  1310. struct l2tp_session *session; /* NULL means get next tunnel */
  1311. };
  1312. static void pppol2tp_next_tunnel(struct net *net, struct pppol2tp_seq_data *pd)
  1313. {
  1314. for (;;) {
  1315. pd->tunnel = l2tp_tunnel_find_nth(net, pd->tunnel_idx);
  1316. pd->tunnel_idx++;
  1317. if (pd->tunnel == NULL)
  1318. break;
  1319. /* Ignore L2TPv3 tunnels */
  1320. if (pd->tunnel->version < 3)
  1321. break;
  1322. }
  1323. }
  1324. static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd)
  1325. {
  1326. pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx, true);
  1327. pd->session_idx++;
  1328. if (pd->session == NULL) {
  1329. pd->session_idx = 0;
  1330. pppol2tp_next_tunnel(net, pd);
  1331. }
  1332. }
  1333. static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
  1334. {
  1335. struct pppol2tp_seq_data *pd = SEQ_START_TOKEN;
  1336. loff_t pos = *offs;
  1337. struct net *net;
  1338. if (!pos)
  1339. goto out;
  1340. BUG_ON(m->private == NULL);
  1341. pd = m->private;
  1342. net = seq_file_net(m);
  1343. if (pd->tunnel == NULL)
  1344. pppol2tp_next_tunnel(net, pd);
  1345. else
  1346. pppol2tp_next_session(net, pd);
  1347. /* NULL tunnel and session indicates end of list */
  1348. if ((pd->tunnel == NULL) && (pd->session == NULL))
  1349. pd = NULL;
  1350. out:
  1351. return pd;
  1352. }
  1353. static void *pppol2tp_seq_next(struct seq_file *m, void *v, loff_t *pos)
  1354. {
  1355. (*pos)++;
  1356. return NULL;
  1357. }
  1358. static void pppol2tp_seq_stop(struct seq_file *p, void *v)
  1359. {
  1360. /* nothing to do */
  1361. }
  1362. static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v)
  1363. {
  1364. struct l2tp_tunnel *tunnel = v;
  1365. seq_printf(m, "\nTUNNEL '%s', %c %d\n",
  1366. tunnel->name,
  1367. (tunnel == tunnel->sock->sk_user_data) ? 'Y' : 'N',
  1368. atomic_read(&tunnel->ref_count) - 1);
  1369. seq_printf(m, " %08x %ld/%ld/%ld %ld/%ld/%ld\n",
  1370. tunnel->debug,
  1371. atomic_long_read(&tunnel->stats.tx_packets),
  1372. atomic_long_read(&tunnel->stats.tx_bytes),
  1373. atomic_long_read(&tunnel->stats.tx_errors),
  1374. atomic_long_read(&tunnel->stats.rx_packets),
  1375. atomic_long_read(&tunnel->stats.rx_bytes),
  1376. atomic_long_read(&tunnel->stats.rx_errors));
  1377. }
  1378. static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
  1379. {
  1380. struct l2tp_session *session = v;
  1381. struct l2tp_tunnel *tunnel = session->tunnel;
  1382. struct pppol2tp_session *ps = l2tp_session_priv(session);
  1383. struct pppox_sock *po = pppox_sk(ps->sock);
  1384. u32 ip = 0;
  1385. u16 port = 0;
  1386. if (tunnel->sock) {
  1387. struct inet_sock *inet = inet_sk(tunnel->sock);
  1388. ip = ntohl(inet->inet_saddr);
  1389. port = ntohs(inet->inet_sport);
  1390. }
  1391. seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> "
  1392. "%04X/%04X %d %c\n",
  1393. session->name, ip, port,
  1394. tunnel->tunnel_id,
  1395. session->session_id,
  1396. tunnel->peer_tunnel_id,
  1397. session->peer_session_id,
  1398. ps->sock->sk_state,
  1399. (session == ps->sock->sk_user_data) ?
  1400. 'Y' : 'N');
  1401. seq_printf(m, " %d/%d/%c/%c/%s %08x %u\n",
  1402. session->mtu, session->mru,
  1403. session->recv_seq ? 'R' : '-',
  1404. session->send_seq ? 'S' : '-',
  1405. session->lns_mode ? "LNS" : "LAC",
  1406. session->debug,
  1407. jiffies_to_msecs(session->reorder_timeout));
  1408. seq_printf(m, " %hu/%hu %ld/%ld/%ld %ld/%ld/%ld\n",
  1409. session->nr, session->ns,
  1410. atomic_long_read(&session->stats.tx_packets),
  1411. atomic_long_read(&session->stats.tx_bytes),
  1412. atomic_long_read(&session->stats.tx_errors),
  1413. atomic_long_read(&session->stats.rx_packets),
  1414. atomic_long_read(&session->stats.rx_bytes),
  1415. atomic_long_read(&session->stats.rx_errors));
  1416. if (po)
  1417. seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
  1418. }
  1419. static int pppol2tp_seq_show(struct seq_file *m, void *v)
  1420. {
  1421. struct pppol2tp_seq_data *pd = v;
  1422. /* display header on line 1 */
  1423. if (v == SEQ_START_TOKEN) {
  1424. seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n");
  1425. seq_puts(m, "TUNNEL name, user-data-ok session-count\n");
  1426. seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
  1427. seq_puts(m, " SESSION name, addr/port src-tid/sid "
  1428. "dest-tid/sid state user-data-ok\n");
  1429. seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n");
  1430. seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
  1431. goto out;
  1432. }
  1433. /* Show the tunnel or session context.
  1434. */
  1435. if (!pd->session) {
  1436. pppol2tp_seq_tunnel_show(m, pd->tunnel);
  1437. } else {
  1438. pppol2tp_seq_session_show(m, pd->session);
  1439. if (pd->session->deref)
  1440. pd->session->deref(pd->session);
  1441. l2tp_session_dec_refcount(pd->session);
  1442. }
  1443. out:
  1444. return 0;
  1445. }
  1446. static const struct seq_operations pppol2tp_seq_ops = {
  1447. .start = pppol2tp_seq_start,
  1448. .next = pppol2tp_seq_next,
  1449. .stop = pppol2tp_seq_stop,
  1450. .show = pppol2tp_seq_show,
  1451. };
  1452. /* Called when our /proc file is opened. We allocate data for use when
  1453. * iterating our tunnel / session contexts and store it in the private
  1454. * data of the seq_file.
  1455. */
  1456. static int pppol2tp_proc_open(struct inode *inode, struct file *file)
  1457. {
  1458. return seq_open_net(inode, file, &pppol2tp_seq_ops,
  1459. sizeof(struct pppol2tp_seq_data));
  1460. }
  1461. static const struct file_operations pppol2tp_proc_fops = {
  1462. .owner = THIS_MODULE,
  1463. .open = pppol2tp_proc_open,
  1464. .read = seq_read,
  1465. .llseek = seq_lseek,
  1466. .release = seq_release_net,
  1467. };
  1468. #endif /* CONFIG_PROC_FS */
  1469. /*****************************************************************************
  1470. * Network namespace
  1471. *****************************************************************************/
  1472. static __net_init int pppol2tp_init_net(struct net *net)
  1473. {
  1474. struct proc_dir_entry *pde;
  1475. int err = 0;
  1476. pde = proc_create("pppol2tp", S_IRUGO, net->proc_net,
  1477. &pppol2tp_proc_fops);
  1478. if (!pde) {
  1479. err = -ENOMEM;
  1480. goto out;
  1481. }
  1482. out:
  1483. return err;
  1484. }
  1485. static __net_exit void pppol2tp_exit_net(struct net *net)
  1486. {
  1487. remove_proc_entry("pppol2tp", net->proc_net);
  1488. }
  1489. static struct pernet_operations pppol2tp_net_ops = {
  1490. .init = pppol2tp_init_net,
  1491. .exit = pppol2tp_exit_net,
  1492. .id = &pppol2tp_net_id,
  1493. };
  1494. /*****************************************************************************
  1495. * Init and cleanup
  1496. *****************************************************************************/
  1497. static const struct proto_ops pppol2tp_ops = {
  1498. .family = AF_PPPOX,
  1499. .owner = THIS_MODULE,
  1500. .release = pppol2tp_release,
  1501. .bind = sock_no_bind,
  1502. .connect = pppol2tp_connect,
  1503. .socketpair = sock_no_socketpair,
  1504. .accept = sock_no_accept,
  1505. .getname = pppol2tp_getname,
  1506. .poll = datagram_poll,
  1507. .listen = sock_no_listen,
  1508. .shutdown = sock_no_shutdown,
  1509. .setsockopt = pppol2tp_setsockopt,
  1510. .getsockopt = pppol2tp_getsockopt,
  1511. .sendmsg = pppol2tp_sendmsg,
  1512. .recvmsg = pppol2tp_recvmsg,
  1513. .mmap = sock_no_mmap,
  1514. .ioctl = pppox_ioctl,
  1515. };
  1516. static const struct pppox_proto pppol2tp_proto = {
  1517. .create = pppol2tp_create,
  1518. .ioctl = pppol2tp_ioctl,
  1519. .owner = THIS_MODULE,
  1520. };
  1521. #ifdef CONFIG_L2TP_V3
  1522. static const struct l2tp_nl_cmd_ops pppol2tp_nl_cmd_ops = {
  1523. .session_create = pppol2tp_session_create,
  1524. .session_delete = l2tp_session_delete,
  1525. };
  1526. #endif /* CONFIG_L2TP_V3 */
  1527. static int __init pppol2tp_init(void)
  1528. {
  1529. int err;
  1530. err = register_pernet_device(&pppol2tp_net_ops);
  1531. if (err)
  1532. goto out;
  1533. err = proto_register(&pppol2tp_sk_proto, 0);
  1534. if (err)
  1535. goto out_unregister_pppol2tp_pernet;
  1536. err = register_pppox_proto(PX_PROTO_OL2TP, &pppol2tp_proto);
  1537. if (err)
  1538. goto out_unregister_pppol2tp_proto;
  1539. #ifdef CONFIG_L2TP_V3
  1540. err = l2tp_nl_register_ops(L2TP_PWTYPE_PPP, &pppol2tp_nl_cmd_ops);
  1541. if (err)
  1542. goto out_unregister_pppox;
  1543. #endif
  1544. pr_info("PPPoL2TP kernel driver, %s\n", PPPOL2TP_DRV_VERSION);
  1545. out:
  1546. return err;
  1547. #ifdef CONFIG_L2TP_V3
  1548. out_unregister_pppox:
  1549. unregister_pppox_proto(PX_PROTO_OL2TP);
  1550. #endif
  1551. out_unregister_pppol2tp_proto:
  1552. proto_unregister(&pppol2tp_sk_proto);
  1553. out_unregister_pppol2tp_pernet:
  1554. unregister_pernet_device(&pppol2tp_net_ops);
  1555. goto out;
  1556. }
  1557. static void __exit pppol2tp_exit(void)
  1558. {
  1559. #ifdef CONFIG_L2TP_V3
  1560. l2tp_nl_unregister_ops(L2TP_PWTYPE_PPP);
  1561. #endif
  1562. unregister_pppox_proto(PX_PROTO_OL2TP);
  1563. proto_unregister(&pppol2tp_sk_proto);
  1564. unregister_pernet_device(&pppol2tp_net_ops);
  1565. }
  1566. module_init(pppol2tp_init);
  1567. module_exit(pppol2tp_exit);
  1568. MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
  1569. MODULE_DESCRIPTION("PPP over L2TP over UDP");
  1570. MODULE_LICENSE("GPL");
  1571. MODULE_VERSION(PPPOL2TP_DRV_VERSION);
  1572. MODULE_ALIAS_NET_PF_PROTO(PF_PPPOX, PX_PROTO_OL2TP);
  1573. MODULE_ALIAS_L2TP_PWTYPE(7);