l2tp_ppp.c (37acd687269f8cb8366598e292f96eb5605d3e3a) | l2tp_ppp.c (90904ff5f958a215cc3d26f957a46e80fa178470) |
---|---|
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 * --- 414 unchanged lines hidden (view full) --- 423 ps = container_of(head, typeof(*ps), rcu); 424 sock_put(ps->__sk); 425} 426 427/* Called by l2tp_core when a session socket is being closed. 428 */ 429static void pppol2tp_session_close(struct l2tp_session *session) 430{ | 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 * --- 414 unchanged lines hidden (view full) --- 423 ps = container_of(head, typeof(*ps), rcu); 424 sock_put(ps->__sk); 425} 426 427/* Called by l2tp_core when a session socket is being closed. 428 */ 429static void pppol2tp_session_close(struct l2tp_session *session) 430{ |
431 struct pppol2tp_session *ps; 432 433 ps = l2tp_session_priv(session); 434 mutex_lock(&ps->sk_lock); 435 ps->__sk = rcu_dereference_protected(ps->sk, 436 lockdep_is_held(&ps->sk_lock)); 437 RCU_INIT_POINTER(ps->sk, NULL); 438 if (ps->__sk) 439 call_rcu(&ps->rcu, pppol2tp_put_sk); 440 mutex_unlock(&ps->sk_lock); | |
441} 442 443/* Really kill the session socket. (Called from sock_put() if 444 * refcnt == 0.) 445 */ 446static void pppol2tp_session_destruct(struct sock *sk) 447{ 448 struct l2tp_session *session = sk->sk_user_data; --- 26 unchanged lines hidden (view full) --- 475 476 pppox_unbind_sock(sk); 477 478 /* Signal the death of the socket. */ 479 sk->sk_state = PPPOX_DEAD; 480 sock_orphan(sk); 481 sock->sk = NULL; 482 | 431} 432 433/* Really kill the session socket. (Called from sock_put() if 434 * refcnt == 0.) 435 */ 436static void pppol2tp_session_destruct(struct sock *sk) 437{ 438 struct l2tp_session *session = sk->sk_user_data; --- 26 unchanged lines hidden (view full) --- 465 466 pppox_unbind_sock(sk); 467 468 /* Signal the death of the socket. */ 469 sk->sk_state = PPPOX_DEAD; 470 sock_orphan(sk); 471 sock->sk = NULL; 472 |
483 /* If the socket is associated with a session, 484 * l2tp_session_delete will call pppol2tp_session_close which 485 * will drop the session's ref on the socket. 486 */ | |
487 session = pppol2tp_sock_to_session(sk); 488 if (session) { | 473 session = pppol2tp_sock_to_session(sk); 474 if (session) { |
475 struct pppol2tp_session *ps; 476 |
|
489 l2tp_session_delete(session); | 477 l2tp_session_delete(session); |
490 /* drop the ref obtained by pppol2tp_sock_to_session */ 491 sock_put(sk); | 478 479 ps = l2tp_session_priv(session); 480 mutex_lock(&ps->sk_lock); 481 ps->__sk = rcu_dereference_protected(ps->sk, 482 lockdep_is_held(&ps->sk_lock)); 483 RCU_INIT_POINTER(ps->sk, NULL); 484 mutex_unlock(&ps->sk_lock); 485 call_rcu(&ps->rcu, pppol2tp_put_sk); 486 487 /* Rely on the sock_put() call at the end of the function for 488 * dropping the reference held by pppol2tp_sock_to_session(). 489 * The last reference will be dropped by pppol2tp_put_sk(). 490 */ |
492 } 493 494 release_sock(sk); 495 496 /* This will delete the session context via 497 * pppol2tp_session_destruct() if the socket's refcnt drops to 498 * zero. 499 */ --- 237 unchanged lines hidden (view full) --- 737 drop_refcnt = true; 738 ps = l2tp_session_priv(session); 739 740 /* Using a pre-existing session is fine as long as it hasn't 741 * been connected yet. 742 */ 743 mutex_lock(&ps->sk_lock); 744 if (rcu_dereference_protected(ps->sk, | 491 } 492 493 release_sock(sk); 494 495 /* This will delete the session context via 496 * pppol2tp_session_destruct() if the socket's refcnt drops to 497 * zero. 498 */ --- 237 unchanged lines hidden (view full) --- 736 drop_refcnt = true; 737 ps = l2tp_session_priv(session); 738 739 /* Using a pre-existing session is fine as long as it hasn't 740 * been connected yet. 741 */ 742 mutex_lock(&ps->sk_lock); 743 if (rcu_dereference_protected(ps->sk, |
745 lockdep_is_held(&ps->sk_lock))) { | 744 lockdep_is_held(&ps->sk_lock)) || 745 ps->__sk) { |
746 mutex_unlock(&ps->sk_lock); 747 error = -EEXIST; 748 goto end; 749 } 750 } else { 751 /* Default MTU must allow space for UDP/L2TP/PPP headers */ 752 cfg.mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD; 753 cfg.mru = cfg.mtu; | 746 mutex_unlock(&ps->sk_lock); 747 error = -EEXIST; 748 goto end; 749 } 750 } else { 751 /* Default MTU must allow space for UDP/L2TP/PPP headers */ 752 cfg.mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD; 753 cfg.mru = cfg.mtu; |
754 cfg.pw_type = L2TP_PWTYPE_PPP; |
|
754 755 session = l2tp_session_create(sizeof(struct pppol2tp_session), 756 tunnel, session_id, 757 peer_session_id, &cfg); 758 if (IS_ERR(session)) { 759 error = PTR_ERR(session); 760 goto end; 761 } --- 36 unchanged lines hidden (view full) --- 798 error = ppp_register_net_channel(sock_net(sk), &po->chan); 799 if (error) { 800 mutex_unlock(&ps->sk_lock); 801 goto end; 802 } 803 804out_no_ppp: 805 /* This is how we get the session context from the socket. */ | 755 756 session = l2tp_session_create(sizeof(struct pppol2tp_session), 757 tunnel, session_id, 758 peer_session_id, &cfg); 759 if (IS_ERR(session)) { 760 error = PTR_ERR(session); 761 goto end; 762 } --- 36 unchanged lines hidden (view full) --- 799 error = ppp_register_net_channel(sock_net(sk), &po->chan); 800 if (error) { 801 mutex_unlock(&ps->sk_lock); 802 goto end; 803 } 804 805out_no_ppp: 806 /* This is how we get the session context from the socket. */ |
806 sock_hold(sk); | |
807 sk->sk_user_data = session; 808 rcu_assign_pointer(ps->sk, sk); 809 mutex_unlock(&ps->sk_lock); 810 811 /* Keep the reference we've grabbed on the session: sk doesn't expect 812 * the session to disappear. pppol2tp_session_destruct() is responsible 813 * for dropping it. 814 */ --- 756 unchanged lines hidden (view full) --- 1571 return; 1572 1573 l2tp_tunnel_dec_refcount(pd->tunnel); 1574 } 1575} 1576 1577static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd) 1578{ | 807 sk->sk_user_data = session; 808 rcu_assign_pointer(ps->sk, sk); 809 mutex_unlock(&ps->sk_lock); 810 811 /* Keep the reference we've grabbed on the session: sk doesn't expect 812 * the session to disappear. pppol2tp_session_destruct() is responsible 813 * for dropping it. 814 */ --- 756 unchanged lines hidden (view full) --- 1571 return; 1572 1573 l2tp_tunnel_dec_refcount(pd->tunnel); 1574 } 1575} 1576 1577static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd) 1578{ |
1579 /* Drop reference taken during previous invocation */ 1580 if (pd->session) 1581 l2tp_session_dec_refcount(pd->session); 1582 |
|
1579 pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx); 1580 pd->session_idx++; 1581 1582 if (pd->session == NULL) { 1583 pd->session_idx = 0; 1584 pppol2tp_next_tunnel(net, pd); 1585 } 1586} --- 32 unchanged lines hidden (view full) --- 1619 1620static void pppol2tp_seq_stop(struct seq_file *p, void *v) 1621{ 1622 struct pppol2tp_seq_data *pd = v; 1623 1624 if (!pd || pd == SEQ_START_TOKEN) 1625 return; 1626 | 1583 pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx); 1584 pd->session_idx++; 1585 1586 if (pd->session == NULL) { 1587 pd->session_idx = 0; 1588 pppol2tp_next_tunnel(net, pd); 1589 } 1590} --- 32 unchanged lines hidden (view full) --- 1623 1624static void pppol2tp_seq_stop(struct seq_file *p, void *v) 1625{ 1626 struct pppol2tp_seq_data *pd = v; 1627 1628 if (!pd || pd == SEQ_START_TOKEN) 1629 return; 1630 |
1627 /* Drop reference taken by last invocation of pppol2tp_next_tunnel() */ | 1631 /* Drop reference taken by last invocation of pppol2tp_next_session() 1632 * or pppol2tp_next_tunnel(). 1633 */ 1634 if (pd->session) { 1635 l2tp_session_dec_refcount(pd->session); 1636 pd->session = NULL; 1637 } |
1628 if (pd->tunnel) { 1629 l2tp_tunnel_dec_refcount(pd->tunnel); 1630 pd->tunnel = NULL; | 1638 if (pd->tunnel) { 1639 l2tp_tunnel_dec_refcount(pd->tunnel); 1640 pd->tunnel = NULL; |
1631 pd->session = NULL; | |
1632 } 1633} 1634 1635static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v) 1636{ 1637 struct l2tp_tunnel *tunnel = v; 1638 1639 seq_printf(m, "\nTUNNEL '%s', %c %d\n", --- 78 unchanged lines hidden (view full) --- 1718 seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n"); 1719 seq_puts(m, " SESSION name, addr/port src-tid/sid " 1720 "dest-tid/sid state user-data-ok\n"); 1721 seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n"); 1722 seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n"); 1723 goto out; 1724 } 1725 | 1641 } 1642} 1643 1644static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v) 1645{ 1646 struct l2tp_tunnel *tunnel = v; 1647 1648 seq_printf(m, "\nTUNNEL '%s', %c %d\n", --- 78 unchanged lines hidden (view full) --- 1727 seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n"); 1728 seq_puts(m, " SESSION name, addr/port src-tid/sid " 1729 "dest-tid/sid state user-data-ok\n"); 1730 seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n"); 1731 seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n"); 1732 goto out; 1733 } 1734 |
1726 /* Show the tunnel or session context. 1727 */ 1728 if (!pd->session) { | 1735 if (!pd->session) |
1729 pppol2tp_seq_tunnel_show(m, pd->tunnel); | 1736 pppol2tp_seq_tunnel_show(m, pd->tunnel); |
1730 } else { | 1737 else |
1731 pppol2tp_seq_session_show(m, pd->session); | 1738 pppol2tp_seq_session_show(m, pd->session); |
1732 l2tp_session_dec_refcount(pd->session); 1733 } | |
1734 1735out: 1736 return 0; 1737} 1738 1739static const struct seq_operations pppol2tp_seq_ops = { 1740 .start = pppol2tp_seq_start, 1741 .next = pppol2tp_seq_next, 1742 .stop = pppol2tp_seq_stop, 1743 .show = pppol2tp_seq_show, 1744}; | 1739 1740out: 1741 return 0; 1742} 1743 1744static const struct seq_operations pppol2tp_seq_ops = { 1745 .start = pppol2tp_seq_start, 1746 .next = pppol2tp_seq_next, 1747 .stop = pppol2tp_seq_stop, 1748 .show = pppol2tp_seq_show, 1749}; |
1745 1746/* Called when our /proc file is opened. We allocate data for use when 1747 * iterating our tunnel / session contexts and store it in the private 1748 * data of the seq_file. 1749 */ 1750static int pppol2tp_proc_open(struct inode *inode, struct file *file) 1751{ 1752 return seq_open_net(inode, file, &pppol2tp_seq_ops, 1753 sizeof(struct pppol2tp_seq_data)); 1754} 1755 1756static const struct file_operations pppol2tp_proc_fops = { 1757 .open = pppol2tp_proc_open, 1758 .read = seq_read, 1759 .llseek = seq_lseek, 1760 .release = seq_release_net, 1761}; 1762 | |
1763#endif /* CONFIG_PROC_FS */ 1764 1765/***************************************************************************** 1766 * Network namespace 1767 *****************************************************************************/ 1768 1769static __net_init int pppol2tp_init_net(struct net *net) 1770{ 1771 struct proc_dir_entry *pde; 1772 int err = 0; 1773 | 1750#endif /* CONFIG_PROC_FS */ 1751 1752/***************************************************************************** 1753 * Network namespace 1754 *****************************************************************************/ 1755 1756static __net_init int pppol2tp_init_net(struct net *net) 1757{ 1758 struct proc_dir_entry *pde; 1759 int err = 0; 1760 |
1774 pde = proc_create("pppol2tp", 0444, net->proc_net, 1775 &pppol2tp_proc_fops); | 1761 pde = proc_create_net("pppol2tp", 0444, net->proc_net, 1762 &pppol2tp_seq_ops, sizeof(struct pppol2tp_seq_data)); |
1776 if (!pde) { 1777 err = -ENOMEM; 1778 goto out; 1779 } 1780 1781out: 1782 return err; 1783} --- 17 unchanged lines hidden (view full) --- 1801 .family = AF_PPPOX, 1802 .owner = THIS_MODULE, 1803 .release = pppol2tp_release, 1804 .bind = sock_no_bind, 1805 .connect = pppol2tp_connect, 1806 .socketpair = sock_no_socketpair, 1807 .accept = sock_no_accept, 1808 .getname = pppol2tp_getname, | 1763 if (!pde) { 1764 err = -ENOMEM; 1765 goto out; 1766 } 1767 1768out: 1769 return err; 1770} --- 17 unchanged lines hidden (view full) --- 1788 .family = AF_PPPOX, 1789 .owner = THIS_MODULE, 1790 .release = pppol2tp_release, 1791 .bind = sock_no_bind, 1792 .connect = pppol2tp_connect, 1793 .socketpair = sock_no_socketpair, 1794 .accept = sock_no_accept, 1795 .getname = pppol2tp_getname, |
1809 .poll = datagram_poll, | 1796 .poll_mask = datagram_poll_mask, |
1810 .listen = sock_no_listen, 1811 .shutdown = sock_no_shutdown, 1812 .setsockopt = pppol2tp_setsockopt, 1813 .getsockopt = pppol2tp_getsockopt, 1814 .sendmsg = pppol2tp_sendmsg, 1815 .recvmsg = pppol2tp_recvmsg, 1816 .mmap = sock_no_mmap, 1817 .ioctl = pppox_ioctl, --- 74 unchanged lines hidden --- | 1797 .listen = sock_no_listen, 1798 .shutdown = sock_no_shutdown, 1799 .setsockopt = pppol2tp_setsockopt, 1800 .getsockopt = pppol2tp_getsockopt, 1801 .sendmsg = pppol2tp_sendmsg, 1802 .recvmsg = pppol2tp_recvmsg, 1803 .mmap = sock_no_mmap, 1804 .ioctl = pppox_ioctl, --- 74 unchanged lines hidden --- |