Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /** -*- linux-c -*- ***********************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Linux PPP over Ethernet (PPPoX/PPPoE) Sockets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * PPPoX --- Generic PPP encapsulation socket family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * PPPoE --- PPP over Ethernet (RFC 2516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Version:	0.7.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * 070228 :	Fix to allow multiple sessions with same remote MAC and same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *		session id by including the local device ifindex in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *		tuple identifying a session. This also ensures packets can't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *		be injected into a session from interfaces other than the one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *		specified by userspace. Florian Zumbiehl <florz@florz.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *		(Oh, BTW, this one is YYMMDD, in case you were wondering ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * 220102 :	Fix module use count on failure in pppoe_create, pppox_sk -acme
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  * 030700 :	Fixed connect logic to allow for disconnect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * 270700 :	Fixed potential SMP problems; we must protect against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *		simultaneous invocation of ppp_input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *		and ppp_unregister_channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  * 040800 :	Respect reference count mechanisms on net-devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * 200800 :	fix kfree(skb) in pppoe_rcv (acme)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *		Module reference count is decremented in the right spot now,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *		guards against sock_put not actually freeing the sk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *		in pppoe_release.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * 051000 :	Initialization cleanup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * 111100 :	Fix recvmsg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * 050101 :	Fix PADT procesing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * 140501 :	Use pppoe_rcv_core to handle all backlog. (Alexey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  * 170701 :	Do not lock_sock with rwlock held. (DaveM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *		Ignore discovery frames if user has socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *		locked. (DaveM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *		Ignore return value of dev_queue_xmit in __pppoe_xmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *		or else we may kfree an SKB twice. (DaveM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  * 190701 :	When doing copies of skb's in __pppoe_xmit, always delete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  *		the original skb that was passed in on success, never on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  *		failure.  Delete the copy of the skb on failure to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  *		a memory leak.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  * 081001 :	Misc. cleanup (licence string, non-blocking, prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  *		reference of device on close).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  * 121301 :	New ppp channels interface; cannot unregister a channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  *		from interrupts.  Thus, we mark the socket as a ZOMBIE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  *		and do the unregistration later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  * 081002 :	seq_file support for proc stuff -acme
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)  * 111602 :	Merge all 2.4 fixes into 2.5/2.6 tree.  Label 2.5/2.6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  *		as version 0.7.  Spacing cleanup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)  * Author:	Michal Ostrowski <mostrows@speakeasy.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  * Contributors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  * 		Arnaldo Carvalho de Melo <acme@conectiva.com.br>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)  *		David S. Miller (davem@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)  * License:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include <linux/inetdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #include <linux/if_pppox.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #include <linux/ppp_channel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #include <linux/ppp_defs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #include <linux/ppp-ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #include <linux/nsproxy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #include <net/netns/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #define PPPOE_HASH_BITS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #define PPPOE_HASH_SIZE (1 << PPPOE_HASH_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define PPPOE_HASH_MASK	(PPPOE_HASH_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) static const struct proto_ops pppoe_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) static const struct ppp_channel_ops pppoe_chan_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) /* per-net private data for this module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) static unsigned int pppoe_net_id __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) struct pppoe_net {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	 * we could use _single_ hash table for all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	 * nets by injecting net id into the hash but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	 * it would increase hash chains and add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	 * a few additional math comparations messy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	 * as well, moreover in case of SMP less locking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	 * controversy here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	struct pppox_sock *hash_table[PPPOE_HASH_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	rwlock_t hash_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  * PPPoE could be in the following stages:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)  * 1) Discovery stage (to obtain remote MAC and Session ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  * 2) Session stage (MAC and SID are known)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  * Ethernet frames have a special tag for this but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  * we use simpler approach based on session id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static inline bool stage_session(__be16 sid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	return sid != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) static inline struct pppoe_net *pppoe_pernet(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	return net_generic(net, pppoe_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) static inline int cmp_2_addr(struct pppoe_addr *a, struct pppoe_addr *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	return a->sid == b->sid && ether_addr_equal(a->remote, b->remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) static inline int cmp_addr(struct pppoe_addr *a, __be16 sid, char *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	return a->sid == sid && ether_addr_equal(a->remote, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) #if 8 % PPPOE_HASH_BITS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) #error 8 must be a multiple of PPPOE_HASH_BITS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) static int hash_item(__be16 sid, unsigned char *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	unsigned char hash = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	for (i = 0; i < ETH_ALEN; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		hash ^= addr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	for (i = 0; i < sizeof(sid_t) * 8; i += 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		hash ^= (__force __u32)sid >> i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	for (i = 8; (i >>= 1) >= PPPOE_HASH_BITS;)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		hash ^= hash >> i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	return hash & PPPOE_HASH_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) /**********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156)  *  Set/get/delete/rehash items  (internal versions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158)  **********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) static struct pppox_sock *__get_item(struct pppoe_net *pn, __be16 sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 				unsigned char *addr, int ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	int hash = hash_item(sid, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	struct pppox_sock *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	ret = pn->hash_table[hash];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	while (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		if (cmp_addr(&ret->pppoe_pa, sid, addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 		    ret->pppoe_ifindex == ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		ret = ret->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) static int __set_item(struct pppoe_net *pn, struct pppox_sock *po)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	int hash = hash_item(po->pppoe_pa.sid, po->pppoe_pa.remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	struct pppox_sock *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	ret = pn->hash_table[hash];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	while (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		if (cmp_2_addr(&ret->pppoe_pa, &po->pppoe_pa) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		    ret->pppoe_ifindex == po->pppoe_ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 			return -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		ret = ret->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	po->next = pn->hash_table[hash];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	pn->hash_table[hash] = po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) static void __delete_item(struct pppoe_net *pn, __be16 sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 					char *addr, int ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	int hash = hash_item(sid, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	struct pppox_sock *ret, **src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	ret = pn->hash_table[hash];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	src = &pn->hash_table[hash];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	while (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		if (cmp_addr(&ret->pppoe_pa, sid, addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		    ret->pppoe_ifindex == ifindex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 			*src = ret->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		src = &ret->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		ret = ret->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) /**********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)  *  Set/get/delete/rehash items
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  **********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) static inline struct pppox_sock *get_item(struct pppoe_net *pn, __be16 sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 					unsigned char *addr, int ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	struct pppox_sock *po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	read_lock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	po = __get_item(pn, sid, addr, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	if (po)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		sock_hold(sk_pppox(po));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	read_unlock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	return po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) static inline struct pppox_sock *get_item_by_addr(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 						struct sockaddr_pppox *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	struct pppoe_net *pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	struct pppox_sock *pppox_sock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	int ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	dev = dev_get_by_name_rcu(net, sp->sa_addr.pppoe.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		ifindex = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		pn = pppoe_pernet(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		pppox_sock = get_item(pn, sp->sa_addr.pppoe.sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 				sp->sa_addr.pppoe.remote, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	return pppox_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) static inline void delete_item(struct pppoe_net *pn, __be16 sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 					char *addr, int ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	write_lock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	__delete_item(pn, sid, addr, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	write_unlock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268)  *  Handler for device events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269)  *  Certain device events require that sockets be unconnected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271)  **************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) static void pppoe_flush_dev(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	struct pppoe_net *pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	pn = pppoe_pernet(dev_net(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	write_lock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	for (i = 0; i < PPPOE_HASH_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 		struct pppox_sock *po = pn->hash_table[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 		struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		while (po) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 			while (po && po->pppoe_dev != dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 				po = po->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 			if (!po)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 			sk = sk_pppox(po);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 			/* We always grab the socket lock, followed by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			 * hash_lock, in that order.  Since we should hold the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 			 * sock lock while doing any unbinding, we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 			 * release the lock we're holding.  Hold a reference to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 			 * the sock so it doesn't disappear as we're jumping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			 * between locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 			sock_hold(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 			write_unlock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 			if (po->pppoe_dev == dev &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 			    sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 				pppox_unbind_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 				sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 				po->pppoe_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 				dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 			release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 			sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 			/* Restart the process from the start of the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 			 * hash chain. We dropped locks so the world may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 			 * change from underneath us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 			BUG_ON(pppoe_pernet(dev_net(dev)) == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 			write_lock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 			po = pn->hash_table[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	write_unlock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) static int pppoe_device_event(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 			      unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	/* Only look at sockets that are using this specific device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	case NETDEV_CHANGEADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	case NETDEV_CHANGEMTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		/* A change in mtu or address is a bad thing, requiring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		 * LCP re-negotiation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	case NETDEV_GOING_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	case NETDEV_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		/* Find every socket on this device and kill it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		pppoe_flush_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) static struct notifier_block pppoe_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	.notifier_call = pppoe_device_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362)  * Do the real work of receiving a PPPoE Session frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364)  ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) static int pppoe_rcv_core(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	struct pppox_sock *po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	struct pppox_sock *relay_po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	/* Backlog receive. Semantics of backlog rcv preclude any code from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	 * executing in lock_sock()/release_sock() bounds; meaning sk->sk_state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	 * can't change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	if (skb->pkt_type == PACKET_OTHERHOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		goto abort_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	if (sk->sk_state & PPPOX_BOUND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		ppp_input(&po->chan, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	} else if (sk->sk_state & PPPOX_RELAY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		relay_po = get_item_by_addr(sock_net(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 					    &po->pppoe_relay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		if (relay_po == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 			goto abort_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		if ((sk_pppox(relay_po)->sk_state & PPPOX_CONNECTED) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			goto abort_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		if (!__pppoe_xmit(sk_pppox(relay_po), skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 			goto abort_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		sock_put(sk_pppox(relay_po));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		if (sock_queue_rcv_skb(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			goto abort_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) abort_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	sock_put(sk_pppox(relay_po));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) abort_kfree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  * Receive wrapper called in BH context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)  ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) static int pppoe_rcv(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		     struct packet_type *pt, struct net_device *orig_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	struct pppoe_hdr *ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	struct pppox_sock *po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	struct pppoe_net *pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	skb = skb_share_check(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	if (skb_mac_header_len(skb) < ETH_HLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	if (!pskb_may_pull(skb, sizeof(struct pppoe_hdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	ph = pppoe_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	len = ntohs(ph->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	skb_pull_rcsum(skb, sizeof(*ph));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	if (skb->len < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	if (pskb_trim_rcsum(skb, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	ph = pppoe_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	pn = pppoe_pernet(dev_net(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	/* Note that get_item does a sock_hold(), so sk_pppox(po)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	 * is known to be safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	if (!po)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	return sk_receive_skb(sk_pppox(po), skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) static void pppoe_unbind_sock_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	struct pppox_sock *po = container_of(work, struct pppox_sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 					     proto.pppoe.padt_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	struct sock *sk = sk_pppox(po);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	if (po->pppoe_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		dev_put(po->pppoe_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		po->pppoe_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	pppox_unbind_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477)  * Receive a PPPoE Discovery frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478)  * This is solely for detection of PADT frames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480)  ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) static int pppoe_disc_rcv(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 			  struct packet_type *pt, struct net_device *orig_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	struct pppoe_hdr *ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	struct pppox_sock *po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	struct pppoe_net *pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	skb = skb_share_check(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	if (skb->pkt_type != PACKET_HOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	if (!pskb_may_pull(skb, sizeof(struct pppoe_hdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	ph = pppoe_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	if (ph->code != PADT_CODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	pn = pppoe_pernet(dev_net(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	if (po)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		if (!schedule_work(&po->proto.pppoe.padt_work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 			sock_put(sk_pppox(po));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) abort:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	return NET_RX_SUCCESS; /* Lies... :-) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) static struct packet_type pppoes_ptype __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	.type	= cpu_to_be16(ETH_P_PPP_SES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	.func	= pppoe_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) static struct packet_type pppoed_ptype __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	.type	= cpu_to_be16(ETH_P_PPP_DISC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	.func	= pppoe_disc_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) static struct proto pppoe_sk_proto __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	.name	  = "PPPOE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	.owner	  = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	.obj_size = sizeof(struct pppox_sock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) /***********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533)  * Initialize a new struct sock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535)  **********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) static int pppoe_create(struct net *net, struct socket *sock, int kern)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppoe_sk_proto, kern);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	sock_init_data(sock, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	sock->state	= SS_UNCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	sock->ops	= &pppoe_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	sk->sk_backlog_rcv	= pppoe_rcv_core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	sk->sk_state		= PPPOX_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	sk->sk_type		= SOCK_STREAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	sk->sk_family		= PF_PPPOX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	sk->sk_protocol		= PX_PROTO_OE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	INIT_WORK(&pppox_sk(sk)->proto.pppoe.padt_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		  pppoe_unbind_sock_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) static int pppoe_release(struct socket *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	struct pppox_sock *po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	struct pppoe_net *pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	struct net *net = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	if (sock_flag(sk, SOCK_DEAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	if (po->pppoe_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		dev_put(po->pppoe_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		po->pppoe_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	pppox_unbind_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	/* Signal the death of the socket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	sk->sk_state = PPPOX_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	pn = pppoe_pernet(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	 * protect "po" from concurrent updates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	 * on pppoe_flush_dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	delete_item(pn, po->pppoe_pa.sid, po->pppoe_pa.remote,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		    po->pppoe_ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	sock_orphan(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	sock->sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	skb_queue_purge(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		  int sockaddr_len, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	struct sockaddr_pppox *sp = (struct sockaddr_pppox *)uservaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	struct pppox_sock *po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	struct net_device *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	struct pppoe_net *pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	struct net *net = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	if (sockaddr_len != sizeof(struct sockaddr_pppox))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	if (sp->sa_protocol != PX_PROTO_OE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	/* Check for already bound sockets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	error = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	if ((sk->sk_state & PPPOX_CONNECTED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	     stage_session(sp->sa_addr.pppoe.sid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	/* Check for already disconnected sockets, on attempts to disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	error = -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	if ((sk->sk_state & PPPOX_DEAD) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	     !stage_session(sp->sa_addr.pppoe.sid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	/* Delete the old binding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	if (stage_session(po->pppoe_pa.sid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		pppox_unbind_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		pn = pppoe_pernet(sock_net(sk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		delete_item(pn, po->pppoe_pa.sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 			    po->pppoe_pa.remote, po->pppoe_ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		if (po->pppoe_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 			dev_put(po->pppoe_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 			po->pppoe_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		po->pppoe_ifindex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		memset(&po->pppoe_pa, 0, sizeof(po->pppoe_pa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		memset(&po->pppoe_relay, 0, sizeof(po->pppoe_relay));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		memset(&po->chan, 0, sizeof(po->chan));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		po->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		po->num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		sk->sk_state = PPPOX_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	/* Re-bind in session stage only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	if (stage_session(sp->sa_addr.pppoe.sid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		dev = dev_get_by_name(net, sp->sa_addr.pppoe.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			goto err_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		po->pppoe_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		po->pppoe_ifindex = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		pn = pppoe_pernet(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		if (!(dev->flags & IFF_UP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 			goto err_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		memcpy(&po->pppoe_pa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		       &sp->sa_addr.pppoe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		       sizeof(struct pppoe_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		write_lock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		error = __set_item(pn, po);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		write_unlock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 			goto err_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		po->chan.hdrlen = (sizeof(struct pppoe_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 				   dev->hard_header_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		po->chan.mtu = dev->mtu - sizeof(struct pppoe_hdr) - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		po->chan.private = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		po->chan.ops = &pppoe_chan_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		error = ppp_register_net_channel(dev_net(dev), &po->chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 			delete_item(pn, po->pppoe_pa.sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 				    po->pppoe_pa.remote, po->pppoe_ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			goto err_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		sk->sk_state = PPPOX_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	po->num = sp->sa_addr.pppoe.sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) err_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	if (po->pppoe_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		dev_put(po->pppoe_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		po->pppoe_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) static int pppoe_getname(struct socket *sock, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		  int peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	int len = sizeof(struct sockaddr_pppox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	struct sockaddr_pppox sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	sp.sa_family	= AF_PPPOX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	sp.sa_protocol	= PX_PROTO_OE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	memcpy(&sp.sa_addr.pppoe, &pppox_sk(sock->sk)->pppoe_pa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	       sizeof(struct pppoe_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	memcpy(uaddr, &sp, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) static int pppoe_ioctl(struct socket *sock, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	struct pppox_sock *po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	case PPPIOCGMRU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		err = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		if (!(sk->sk_state & PPPOX_CONNECTED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		if (put_user(po->pppoe_dev->mtu -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 			     sizeof(struct pppoe_hdr) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 			     PPP_HDRLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 			     (int __user *)arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	case PPPIOCSMRU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		err = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		if (!(sk->sk_state & PPPOX_CONNECTED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		if (get_user(val, (int __user *)arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		if (val < (po->pppoe_dev->mtu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 			   - sizeof(struct pppoe_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 			   - PPP_HDRLEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 			err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 			err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	case PPPIOCSFLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		if (get_user(val, (int __user *)arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	case PPPOEIOCSFWD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		struct pppox_sock *relay_po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		if (sk->sk_state & (PPPOX_BOUND | PPPOX_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		err = -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		if (!(sk->sk_state & PPPOX_CONNECTED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		/* PPPoE address from the user specifies an outbound
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		   PPPoE address which frames are forwarded to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		if (copy_from_user(&po->pppoe_relay,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 				   (void __user *)arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 				   sizeof(struct sockaddr_pppox)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		if (po->pppoe_relay.sa_family != AF_PPPOX ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		    po->pppoe_relay.sa_protocol != PX_PROTO_OE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		/* Check that the socket referenced by the address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		   actually exists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		relay_po = get_item_by_addr(sock_net(sk), &po->pppoe_relay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		if (!relay_po)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		sock_put(sk_pppox(relay_po));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		sk->sk_state |= PPPOX_RELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	case PPPOEIOCDFWD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		err = -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		if (!(sk->sk_state & PPPOX_RELAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		sk->sk_state &= ~PPPOX_RELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		err = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) static int pppoe_sendmsg(struct socket *sock, struct msghdr *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 			 size_t total_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	struct pppox_sock *po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	struct pppoe_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	struct pppoe_hdr *ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	char *start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	int hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		error = -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	hdr.ver = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	hdr.type = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	hdr.code = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	hdr.sid = po->num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	dev = po->pppoe_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	error = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	if (total_len > (dev->mtu + dev->hard_header_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	hlen = LL_RESERVED_SPACE(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	skb = sock_wmalloc(sk, hlen + sizeof(*ph) + total_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 			   dev->needed_tailroom, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	/* Reserve space for headers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	skb_reserve(skb, hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	skb->priority = sk->sk_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	skb->protocol = cpu_to_be16(ETH_P_PPP_SES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	ph = skb_put(skb, total_len + sizeof(struct pppoe_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	start = (char *)&ph->tag[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	error = memcpy_from_msg(start, m, total_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	error = total_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	dev_hard_header(skb, dev, ETH_P_PPP_SES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 			po->pppoe_pa.remote, NULL, total_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	memcpy(ph, &hdr, sizeof(struct pppoe_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	ph->length = htons(total_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909)  * xmit function for internal use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911)  ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	struct pppox_sock *po = pppox_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	struct net_device *dev = po->pppoe_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	struct pppoe_hdr *ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	int data_len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	/* The higher-level PPP code (ppp_unregister_channel()) ensures the PPP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	 * xmit operations conclude prior to an unregistration call.  Thus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	 * sk->sk_state cannot change, so we don't need to do lock_sock().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	 * But, we also can't do a lock_sock since that introduces a potential
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	 * deadlock as we'd reverse the lock ordering used when calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	 * ppp_unregister_channel().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	/* Copy the data if there is no space for the header or if it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	 * read-only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	if (skb_cow_head(skb, LL_RESERVED_SPACE(dev) + sizeof(*ph)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	__skb_push(skb, sizeof(*ph));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	ph = pppoe_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	ph->ver	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	ph->type = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	ph->code = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	ph->sid	= po->num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	ph->length = htons(data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	skb->protocol = cpu_to_be16(ETH_P_PPP_SES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	dev_hard_header(skb, dev, ETH_P_PPP_SES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 			po->pppoe_pa.remote, NULL, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) abort:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965)  * xmit function called by generic PPP driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966)  * sends PPP frame over PPPoE socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968)  ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	struct sock *sk = (struct sock *)chan->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	return __pppoe_xmit(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) static const struct ppp_channel_ops pppoe_chan_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	.start_xmit = pppoe_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) static int pppoe_recvmsg(struct socket *sock, struct msghdr *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			 size_t total_len, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	if (sk->sk_state & PPPOX_BOUND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 				flags & MSG_DONTWAIT, &error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	if (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		total_len = min_t(size_t, total_len, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		error = skb_copy_datagram_msg(skb, 0, m, total_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		if (error == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 			consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 			return total_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) static int pppoe_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	struct pppox_sock *po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	char *dev_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	if (v == SEQ_START_TOKEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		seq_puts(seq, "Id       Address              Device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	po = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	dev_name = po->pppoe_pa.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	seq_printf(seq, "%08X %pM %8s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		po->pppoe_pa.sid, po->pppoe_pa.remote, dev_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) static inline struct pppox_sock *pppoe_get_idx(struct pppoe_net *pn, loff_t pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	struct pppox_sock *po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	for (i = 0; i < PPPOE_HASH_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		po = pn->hash_table[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		while (po) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 			if (!pos--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 			po = po->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	return po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) static void *pppoe_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	__acquires(pn->hash_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	struct pppoe_net *pn = pppoe_pernet(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	loff_t l = *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	read_lock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	return l ? pppoe_get_idx(pn, --l) : SEQ_START_TOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) static void *pppoe_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	struct pppoe_net *pn = pppoe_pernet(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	struct pppox_sock *po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	if (v == SEQ_START_TOKEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		po = pppoe_get_idx(pn, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	po = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	if (po->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		po = po->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		int hash = hash_item(po->pppoe_pa.sid, po->pppoe_pa.remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		po = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 		while (++hash < PPPOE_HASH_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 			po = pn->hash_table[hash];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 			if (po)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	return po;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) static void pppoe_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	__releases(pn->hash_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	struct pppoe_net *pn = pppoe_pernet(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	read_unlock_bh(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) static const struct seq_operations pppoe_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	.start		= pppoe_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	.next		= pppoe_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	.stop		= pppoe_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	.show		= pppoe_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) #endif /* CONFIG_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) static const struct proto_ops pppoe_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	.family		= AF_PPPOX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	.release	= pppoe_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	.bind		= sock_no_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	.connect	= pppoe_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	.socketpair	= sock_no_socketpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	.accept		= sock_no_accept,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	.getname	= pppoe_getname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	.poll		= datagram_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	.listen		= sock_no_listen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	.shutdown	= sock_no_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	.sendmsg	= pppoe_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	.recvmsg	= pppoe_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	.mmap		= sock_no_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	.ioctl		= pppox_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	.compat_ioctl	= pppox_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) static const struct pppox_proto pppoe_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	.create	= pppoe_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	.ioctl	= pppoe_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	.owner	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) static __net_init int pppoe_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	struct pppoe_net *pn = pppoe_pernet(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	struct proc_dir_entry *pde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	rwlock_init(&pn->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	pde = proc_create_net("pppoe", 0444, net->proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 			&pppoe_seq_ops, sizeof(struct seq_net_private));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	if (!pde)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) static __net_exit void pppoe_exit_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	remove_proc_entry("pppoe", net->proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) static struct pernet_operations pppoe_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	.init = pppoe_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	.exit = pppoe_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	.id   = &pppoe_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	.size = sizeof(struct pppoe_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) static int __init pppoe_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	err = register_pernet_device(&pppoe_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	err = proto_register(&pppoe_sk_proto, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		goto out_unregister_net_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	err = register_pppox_proto(PX_PROTO_OE, &pppoe_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		goto out_unregister_pppoe_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	dev_add_pack(&pppoes_ptype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	dev_add_pack(&pppoed_ptype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	register_netdevice_notifier(&pppoe_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) out_unregister_pppoe_proto:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	proto_unregister(&pppoe_sk_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) out_unregister_net_ops:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	unregister_pernet_device(&pppoe_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) static void __exit pppoe_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	unregister_netdevice_notifier(&pppoe_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	dev_remove_pack(&pppoed_ptype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	dev_remove_pack(&pppoes_ptype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	unregister_pppox_proto(PX_PROTO_OE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	proto_unregister(&pppoe_sk_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	unregister_pernet_device(&pppoe_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) module_init(pppoe_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) module_exit(pppoe_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) MODULE_AUTHOR("Michal Ostrowski <mostrows@speakeasy.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) MODULE_DESCRIPTION("PPP over Ethernet driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) MODULE_ALIAS_NET_PF_PROTO(PF_PPPOX, PX_PROTO_OE);