2005-04-17 05:20:36 +07:00
|
|
|
/** -*- linux-c -*- ***********************************************************
|
|
|
|
* Linux PPP over Ethernet (PPPoX/PPPoE) Sockets
|
|
|
|
*
|
|
|
|
* PPPoX --- Generic PPP encapsulation socket family
|
|
|
|
* PPPoE --- PPP over Ethernet (RFC 2516)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Version: 0.7.0
|
|
|
|
*
|
2007-03-03 04:16:56 +07:00
|
|
|
* 070228 : Fix to allow multiple sessions with same remote MAC and same
|
|
|
|
* session id by including the local device ifindex in the
|
|
|
|
* tuple identifying a session. This also ensures packets can't
|
|
|
|
* be injected into a session from interfaces other than the one
|
|
|
|
* specified by userspace. Florian Zumbiehl <florz@florz.de>
|
|
|
|
* (Oh, BTW, this one is YYMMDD, in case you were wondering ...)
|
2005-04-17 05:20:36 +07:00
|
|
|
* 220102 : Fix module use count on failure in pppoe_create, pppox_sk -acme
|
|
|
|
* 030700 : Fixed connect logic to allow for disconnect.
|
|
|
|
* 270700 : Fixed potential SMP problems; we must protect against
|
|
|
|
* simultaneous invocation of ppp_input
|
|
|
|
* and ppp_unregister_channel.
|
|
|
|
* 040800 : Respect reference count mechanisms on net-devices.
|
|
|
|
* 200800 : fix kfree(skb) in pppoe_rcv (acme)
|
|
|
|
* Module reference count is decremented in the right spot now,
|
|
|
|
* guards against sock_put not actually freeing the sk
|
|
|
|
* in pppoe_release.
|
|
|
|
* 051000 : Initialization cleanup.
|
|
|
|
* 111100 : Fix recvmsg.
|
|
|
|
* 050101 : Fix PADT procesing.
|
|
|
|
* 140501 : Use pppoe_rcv_core to handle all backlog. (Alexey)
|
|
|
|
* 170701 : Do not lock_sock with rwlock held. (DaveM)
|
|
|
|
* Ignore discovery frames if user has socket
|
|
|
|
* locked. (DaveM)
|
|
|
|
* Ignore return value of dev_queue_xmit in __pppoe_xmit
|
|
|
|
* or else we may kfree an SKB twice. (DaveM)
|
|
|
|
* 190701 : When doing copies of skb's in __pppoe_xmit, always delete
|
|
|
|
* the original skb that was passed in on success, never on
|
|
|
|
* failure. Delete the copy of the skb on failure to avoid
|
|
|
|
* a memory leak.
|
|
|
|
* 081001 : Misc. cleanup (licence string, non-blocking, prevent
|
|
|
|
* reference of device on close).
|
|
|
|
* 121301 : New ppp channels interface; cannot unregister a channel
|
|
|
|
* from interrupts. Thus, we mark the socket as a ZOMBIE
|
|
|
|
* and do the unregistration later.
|
|
|
|
* 081002 : seq_file support for proc stuff -acme
|
|
|
|
* 111602 : Merge all 2.4 fixes into 2.5/2.6 tree. Label 2.5/2.6
|
|
|
|
* as version 0.7. Spacing cleanup.
|
|
|
|
* Author: Michal Ostrowski <mostrows@speakeasy.net>
|
|
|
|
* Contributors:
|
|
|
|
* Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
* David S. Miller (davem@redhat.com)
|
|
|
|
*
|
|
|
|
* License:
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/inetdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/if_pppox.h>
|
|
|
|
#include <linux/ppp_channel.h>
|
|
|
|
#include <linux/ppp_defs.h>
|
2012-03-04 19:56:55 +07:00
|
|
|
#include <linux/ppp-ioctl.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
#include <linux/nsproxy.h>
|
2007-09-12 17:01:34 +07:00
|
|
|
#include <net/net_namespace.h>
|
2009-01-22 06:54:54 +07:00
|
|
|
#include <net/netns/generic.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <net/sock.h>
|
|
|
|
|
2016-12-25 02:46:01 +07:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#define PPPOE_HASH_BITS 4
|
2009-01-22 06:54:15 +07:00
|
|
|
#define PPPOE_HASH_SIZE (1 << PPPOE_HASH_BITS)
|
|
|
|
#define PPPOE_HASH_MASK (PPPOE_HASH_SIZE - 1)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb);
|
|
|
|
|
2005-12-28 11:57:40 +07:00
|
|
|
static const struct proto_ops pppoe_ops;
|
2010-08-04 14:34:36 +07:00
|
|
|
static const struct ppp_channel_ops pppoe_chan_ops;
|
2009-01-22 06:54:54 +07:00
|
|
|
|
|
|
|
/* per-net private data for this module */
|
netns: make struct pernet_operations::id unsigned int
Make struct pernet_operations::id unsigned.
There are 2 reasons to do so:
1)
This field is really an index into an zero based array and
thus is unsigned entity. Using negative value is out-of-bound
access by definition.
2)
On x86_64 unsigned 32-bit data which are mixed with pointers
via array indexing or offsets added or subtracted to pointers
are preffered to signed 32-bit data.
"int" being used as an array index needs to be sign-extended
to 64-bit before being used.
void f(long *p, int i)
{
g(p[i]);
}
roughly translates to
movsx rsi, esi
mov rdi, [rsi+...]
call g
MOVSX is 3 byte instruction which isn't necessary if the variable is
unsigned because x86_64 is zero extending by default.
Now, there is net_generic() function which, you guessed it right, uses
"int" as an array index:
static inline void *net_generic(const struct net *net, int id)
{
...
ptr = ng->ptr[id - 1];
...
}
And this function is used a lot, so those sign extensions add up.
Patch snipes ~1730 bytes on allyesconfig kernel (without all junk
messing with code generation):
add/remove: 0/0 grow/shrink: 70/598 up/down: 396/-2126 (-1730)
Unfortunately some functions actually grow bigger.
This is a semmingly random artefact of code generation with register
allocator being used differently. gcc decides that some variable
needs to live in new r8+ registers and every access now requires REX
prefix. Or it is shifted into r12, so [r12+0] addressing mode has to be
used which is longer than [r8]
However, overall balance is in negative direction:
add/remove: 0/0 grow/shrink: 70/598 up/down: 396/-2126 (-1730)
function old new delta
nfsd4_lock 3886 3959 +73
tipc_link_build_proto_msg 1096 1140 +44
mac80211_hwsim_new_radio 2776 2808 +32
tipc_mon_rcv 1032 1058 +26
svcauth_gss_legacy_init 1413 1429 +16
tipc_bcbase_select_primary 379 392 +13
nfsd4_exchange_id 1247 1260 +13
nfsd4_setclientid_confirm 782 793 +11
...
put_client_renew_locked 494 480 -14
ip_set_sockfn_get 730 716 -14
geneve_sock_add 829 813 -16
nfsd4_sequence_done 721 703 -18
nlmclnt_lookup_host 708 686 -22
nfsd4_lockt 1085 1063 -22
nfs_get_client 1077 1050 -27
tcf_bpf_init 1106 1076 -30
nfsd4_encode_fattr 5997 5930 -67
Total: Before=154856051, After=154854321, chg -0.00%
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-11-17 08:58:21 +07:00
|
|
|
static unsigned int pppoe_net_id __read_mostly;
|
2009-01-22 06:54:54 +07:00
|
|
|
struct pppoe_net {
|
|
|
|
/*
|
|
|
|
* we could use _single_ hash table for all
|
|
|
|
* nets by injecting net id into the hash but
|
|
|
|
* it would increase hash chains and add
|
|
|
|
* a few additional math comparations messy
|
|
|
|
* as well, moreover in case of SMP less locking
|
|
|
|
* controversy here
|
|
|
|
*/
|
|
|
|
struct pppox_sock *hash_table[PPPOE_HASH_SIZE];
|
|
|
|
rwlock_t hash_lock;
|
|
|
|
};
|
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
/*
|
|
|
|
* PPPoE could be in the following stages:
|
|
|
|
* 1) Discovery stage (to obtain remote MAC and Session ID)
|
|
|
|
* 2) Session stage (MAC and SID are known)
|
|
|
|
*
|
|
|
|
* Ethernet frames have a special tag for this but
|
2011-03-31 08:57:33 +07:00
|
|
|
* we use simpler approach based on session id
|
2009-01-22 06:54:15 +07:00
|
|
|
*/
|
|
|
|
static inline bool stage_session(__be16 sid)
|
|
|
|
{
|
|
|
|
return sid != 0;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
static inline struct pppoe_net *pppoe_pernet(struct net *net)
|
|
|
|
{
|
|
|
|
BUG_ON(!net);
|
|
|
|
|
|
|
|
return net_generic(net, pppoe_net_id);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
static inline int cmp_2_addr(struct pppoe_addr *a, struct pppoe_addr *b)
|
|
|
|
{
|
2013-12-26 18:40:35 +07:00
|
|
|
return a->sid == b->sid && ether_addr_equal(a->remote, b->remote);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-08-23 13:55:33 +07:00
|
|
|
static inline int cmp_addr(struct pppoe_addr *a, __be16 sid, char *addr)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-12-26 18:40:35 +07:00
|
|
|
return a->sid == sid && ether_addr_equal(a->remote, addr);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
#if 8 % PPPOE_HASH_BITS
|
2007-08-01 03:47:57 +07:00
|
|
|
#error 8 must be a multiple of PPPOE_HASH_BITS
|
|
|
|
#endif
|
|
|
|
|
2007-08-23 13:55:33 +07:00
|
|
|
static int hash_item(__be16 sid, unsigned char *addr)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-08-01 03:47:57 +07:00
|
|
|
unsigned char hash = 0;
|
|
|
|
unsigned int i;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
for (i = 0; i < ETH_ALEN; i++)
|
2007-08-01 03:47:57 +07:00
|
|
|
hash ^= addr[i];
|
2009-01-22 06:54:15 +07:00
|
|
|
for (i = 0; i < sizeof(sid_t) * 8; i += 8)
|
|
|
|
hash ^= (__force __u32)sid >> i;
|
|
|
|
for (i = 8; (i >>= 1) >= PPPOE_HASH_BITS;)
|
|
|
|
hash ^= hash >> i;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
return hash & PPPOE_HASH_MASK;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* Set/get/delete/rehash items (internal versions)
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
2009-01-22 06:54:54 +07:00
|
|
|
static struct pppox_sock *__get_item(struct pppoe_net *pn, __be16 sid,
|
|
|
|
unsigned char *addr, int ifindex)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int hash = hash_item(sid, addr);
|
|
|
|
struct pppox_sock *ret;
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
ret = pn->hash_table[hash];
|
2009-01-22 06:54:15 +07:00
|
|
|
while (ret) {
|
|
|
|
if (cmp_addr(&ret->pppoe_pa, sid, addr) &&
|
|
|
|
ret->pppoe_ifindex == ifindex)
|
|
|
|
return ret;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
ret = ret->next;
|
2009-01-22 06:54:15 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
return NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
static int __set_item(struct pppoe_net *pn, struct pppox_sock *po)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int hash = hash_item(po->pppoe_pa.sid, po->pppoe_pa.remote);
|
|
|
|
struct pppox_sock *ret;
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
ret = pn->hash_table[hash];
|
2005-04-17 05:20:36 +07:00
|
|
|
while (ret) {
|
2009-01-22 06:54:15 +07:00
|
|
|
if (cmp_2_addr(&ret->pppoe_pa, &po->pppoe_pa) &&
|
|
|
|
ret->pppoe_ifindex == po->pppoe_ifindex)
|
2005-04-17 05:20:36 +07:00
|
|
|
return -EALREADY;
|
|
|
|
|
|
|
|
ret = ret->next;
|
|
|
|
}
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
po->next = pn->hash_table[hash];
|
|
|
|
pn->hash_table[hash] = po;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-17 12:04:50 +07:00
|
|
|
static void __delete_item(struct pppoe_net *pn, __be16 sid,
|
2009-01-22 06:54:54 +07:00
|
|
|
char *addr, int ifindex)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int hash = hash_item(sid, addr);
|
|
|
|
struct pppox_sock *ret, **src;
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
ret = pn->hash_table[hash];
|
|
|
|
src = &pn->hash_table[hash];
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
while (ret) {
|
2009-01-22 06:54:15 +07:00
|
|
|
if (cmp_addr(&ret->pppoe_pa, sid, addr) &&
|
|
|
|
ret->pppoe_ifindex == ifindex) {
|
2005-04-17 05:20:36 +07:00
|
|
|
*src = ret->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
src = &ret->next;
|
|
|
|
ret = ret->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* Set/get/delete/rehash items
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
2009-01-22 06:54:54 +07:00
|
|
|
static inline struct pppox_sock *get_item(struct pppoe_net *pn, __be16 sid,
|
|
|
|
unsigned char *addr, int ifindex)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct pppox_sock *po;
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
read_lock_bh(&pn->hash_lock);
|
|
|
|
po = __get_item(pn, sid, addr, ifindex);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (po)
|
|
|
|
sock_hold(sk_pppox(po));
|
2009-01-22 06:54:54 +07:00
|
|
|
read_unlock_bh(&pn->hash_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return po;
|
|
|
|
}
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
static inline struct pppox_sock *get_item_by_addr(struct net *net,
|
|
|
|
struct sockaddr_pppox *sp)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-04-21 06:56:31 +07:00
|
|
|
struct net_device *dev;
|
2009-01-22 06:54:54 +07:00
|
|
|
struct pppoe_net *pn;
|
2009-11-02 02:51:22 +07:00
|
|
|
struct pppox_sock *pppox_sock = NULL;
|
2009-01-22 06:54:54 +07:00
|
|
|
|
2007-03-03 04:16:56 +07:00
|
|
|
int ifindex;
|
|
|
|
|
2009-11-02 02:51:22 +07:00
|
|
|
rcu_read_lock();
|
|
|
|
dev = dev_get_by_name_rcu(net, sp->sa_addr.pppoe.dev);
|
|
|
|
if (dev) {
|
|
|
|
ifindex = dev->ifindex;
|
2010-04-26 08:46:12 +07:00
|
|
|
pn = pppoe_pernet(net);
|
2009-11-02 02:51:22 +07:00
|
|
|
pppox_sock = get_item(pn, sp->sa_addr.pppoe.sid,
|
2009-01-22 06:54:54 +07:00
|
|
|
sp->sa_addr.pppoe.remote, ifindex);
|
2009-11-02 02:51:22 +07:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
2009-01-22 06:54:54 +07:00
|
|
|
return pppox_sock;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2012-05-17 12:04:50 +07:00
|
|
|
static inline void delete_item(struct pppoe_net *pn, __be16 sid,
|
2009-01-22 06:54:54 +07:00
|
|
|
char *addr, int ifindex)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-01-22 06:54:54 +07:00
|
|
|
write_lock_bh(&pn->hash_lock);
|
2012-05-17 12:04:50 +07:00
|
|
|
__delete_item(pn, sid, addr, ifindex);
|
2009-01-22 06:54:54 +07:00
|
|
|
write_unlock_bh(&pn->hash_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Handler for device events.
|
|
|
|
* Certain device events require that sockets be unconnected.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
static void pppoe_flush_dev(struct net_device *dev)
|
|
|
|
{
|
2009-01-22 06:54:54 +07:00
|
|
|
struct pppoe_net *pn;
|
|
|
|
int i;
|
|
|
|
|
2010-05-22 17:27:48 +07:00
|
|
|
pn = pppoe_pernet(dev_net(dev));
|
2009-01-22 06:54:54 +07:00
|
|
|
write_lock_bh(&pn->hash_lock);
|
|
|
|
for (i = 0; i < PPPOE_HASH_SIZE; i++) {
|
|
|
|
struct pppox_sock *po = pn->hash_table[i];
|
2009-10-27 06:23:20 +07:00
|
|
|
struct sock *sk;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-10-27 06:23:20 +07:00
|
|
|
while (po) {
|
|
|
|
while (po && po->pppoe_dev != dev) {
|
2007-04-21 06:59:24 +07:00
|
|
|
po = po->next;
|
|
|
|
}
|
2009-10-27 06:23:20 +07:00
|
|
|
|
|
|
|
if (!po)
|
|
|
|
break;
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
sk = sk_pppox(po);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-04-21 06:59:24 +07:00
|
|
|
/* We always grab the socket lock, followed by the
|
2009-10-27 06:23:20 +07:00
|
|
|
* hash_lock, in that order. Since we should hold the
|
|
|
|
* sock lock while doing any unbinding, we need to
|
|
|
|
* release the lock we're holding. Hold a reference to
|
|
|
|
* the sock so it doesn't disappear as we're jumping
|
|
|
|
* between locks.
|
2007-04-21 06:59:24 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-04-21 06:59:24 +07:00
|
|
|
sock_hold(sk);
|
2009-01-22 06:54:54 +07:00
|
|
|
write_unlock_bh(&pn->hash_lock);
|
2007-04-21 06:59:24 +07:00
|
|
|
lock_sock(sk);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-12-03 14:58:21 +07:00
|
|
|
if (po->pppoe_dev == dev &&
|
2015-11-19 18:53:21 +07:00
|
|
|
sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) {
|
2007-04-21 06:59:24 +07:00
|
|
|
pppox_unbind_sock(sk);
|
|
|
|
sk->sk_state_change(sk);
|
2009-10-27 06:23:20 +07:00
|
|
|
po->pppoe_dev = NULL;
|
|
|
|
dev_put(dev);
|
2007-04-21 06:59:24 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-04-21 06:59:24 +07:00
|
|
|
release_sock(sk);
|
|
|
|
sock_put(sk);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-10-27 06:23:20 +07:00
|
|
|
/* Restart the process from the start of the current
|
|
|
|
* hash chain. We dropped locks so the world may have
|
|
|
|
* change from underneath us.
|
2007-04-21 06:59:24 +07:00
|
|
|
*/
|
2009-10-27 06:23:20 +07:00
|
|
|
|
|
|
|
BUG_ON(pppoe_pernet(dev_net(dev)) == NULL);
|
2009-01-22 06:54:54 +07:00
|
|
|
write_lock_bh(&pn->hash_lock);
|
|
|
|
po = pn->hash_table[i];
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
2009-01-22 06:54:54 +07:00
|
|
|
write_unlock_bh(&pn->hash_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pppoe_device_event(struct notifier_block *this,
|
|
|
|
unsigned long event, void *ptr)
|
|
|
|
{
|
2013-05-28 08:30:21 +07:00
|
|
|
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
2007-09-12 18:02:17 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Only look at sockets that are using this specific device. */
|
|
|
|
switch (event) {
|
2011-07-19 01:48:28 +07:00
|
|
|
case NETDEV_CHANGEADDR:
|
2005-04-17 05:20:36 +07:00
|
|
|
case NETDEV_CHANGEMTU:
|
2011-07-19 01:48:28 +07:00
|
|
|
/* A change in mtu or address is a bad thing, requiring
|
2005-04-17 05:20:36 +07:00
|
|
|
* LCP re-negotiation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case NETDEV_GOING_DOWN:
|
|
|
|
case NETDEV_DOWN:
|
|
|
|
/* Find every socket on this device and kill it. */
|
|
|
|
pppoe_flush_dev(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2010-05-18 12:47:34 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block pppoe_notifier = {
|
|
|
|
.notifier_call = pppoe_device_event,
|
|
|
|
};
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
*
|
|
|
|
* Do the real work of receiving a PPPoE Session frame.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
static int pppoe_rcv_core(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct pppox_sock *po = pppox_sk(sk);
|
2007-04-21 06:56:31 +07:00
|
|
|
struct pppox_sock *relay_po;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-10-27 06:23:20 +07:00
|
|
|
/* Backlog receive. Semantics of backlog rcv preclude any code from
|
|
|
|
* executing in lock_sock()/release_sock() bounds; meaning sk->sk_state
|
|
|
|
* can't change.
|
|
|
|
*/
|
|
|
|
|
2015-04-21 02:07:48 +07:00
|
|
|
if (skb->pkt_type == PACKET_OTHERHOST)
|
|
|
|
goto abort_kfree;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (sk->sk_state & PPPOX_BOUND) {
|
|
|
|
ppp_input(&po->chan, skb);
|
|
|
|
} else if (sk->sk_state & PPPOX_RELAY) {
|
2009-10-27 06:23:20 +07:00
|
|
|
relay_po = get_item_by_addr(sock_net(sk),
|
|
|
|
&po->pppoe_relay);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (relay_po == NULL)
|
|
|
|
goto abort_kfree;
|
|
|
|
|
|
|
|
if ((sk_pppox(relay_po)->sk_state & PPPOX_CONNECTED) == 0)
|
|
|
|
goto abort_put;
|
|
|
|
|
|
|
|
if (!__pppoe_xmit(sk_pppox(relay_po), skb))
|
|
|
|
goto abort_put;
|
2016-02-15 23:01:10 +07:00
|
|
|
|
|
|
|
sock_put(sk_pppox(relay_po));
|
2005-04-17 05:20:36 +07:00
|
|
|
} else {
|
|
|
|
if (sock_queue_rcv_skb(sk, skb))
|
|
|
|
goto abort_kfree;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NET_RX_SUCCESS;
|
|
|
|
|
|
|
|
abort_put:
|
|
|
|
sock_put(sk_pppox(relay_po));
|
|
|
|
|
|
|
|
abort_kfree:
|
|
|
|
kfree_skb(skb);
|
|
|
|
return NET_RX_DROP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
*
|
|
|
|
* Receive wrapper called in BH context.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
2009-01-22 06:54:54 +07:00
|
|
|
static int pppoe_rcv(struct sk_buff *skb, struct net_device *dev,
|
|
|
|
struct packet_type *pt, struct net_device *orig_dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct pppoe_hdr *ph;
|
|
|
|
struct pppox_sock *po;
|
2009-01-22 06:54:54 +07:00
|
|
|
struct pppoe_net *pn;
|
2008-06-11 04:07:25 +07:00
|
|
|
int len;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
skb = skb_share_check(skb, GFP_ATOMIC);
|
|
|
|
if (!skb)
|
2005-04-17 05:20:36 +07:00
|
|
|
goto out;
|
|
|
|
|
2007-09-17 06:19:20 +07:00
|
|
|
if (!pskb_may_pull(skb, sizeof(struct pppoe_hdr)))
|
|
|
|
goto drop;
|
|
|
|
|
2007-03-11 01:56:08 +07:00
|
|
|
ph = pppoe_hdr(skb);
|
2008-06-11 04:07:25 +07:00
|
|
|
len = ntohs(ph->length);
|
|
|
|
|
|
|
|
skb_pull_rcsum(skb, sizeof(*ph));
|
|
|
|
if (skb->len < len)
|
|
|
|
goto drop;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-10-31 13:11:44 +07:00
|
|
|
if (pskb_trim_rcsum(skb, len))
|
2008-06-11 04:07:25 +07:00
|
|
|
goto drop;
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
pn = pppoe_pernet(dev_net(dev));
|
2009-10-27 06:23:20 +07:00
|
|
|
|
|
|
|
/* Note that get_item does a sock_hold(), so sk_pppox(po)
|
|
|
|
* is known to be safe.
|
|
|
|
*/
|
2009-01-22 06:54:54 +07:00
|
|
|
po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
|
2008-10-31 13:11:44 +07:00
|
|
|
if (!po)
|
2008-06-11 04:07:25 +07:00
|
|
|
goto drop;
|
|
|
|
|
|
|
|
return sk_receive_skb(sk_pppox(po), skb, 0);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
drop:
|
|
|
|
kfree_skb(skb);
|
|
|
|
out:
|
|
|
|
return NET_RX_DROP;
|
|
|
|
}
|
|
|
|
|
2015-03-01 17:54:39 +07:00
|
|
|
static void pppoe_unbind_sock_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct pppox_sock *po = container_of(work, struct pppox_sock,
|
|
|
|
proto.pppoe.padt_work);
|
|
|
|
struct sock *sk = sk_pppox(po);
|
|
|
|
|
|
|
|
lock_sock(sk);
|
2015-05-10 04:08:38 +07:00
|
|
|
if (po->pppoe_dev) {
|
|
|
|
dev_put(po->pppoe_dev);
|
|
|
|
po->pppoe_dev = NULL;
|
|
|
|
}
|
2015-03-01 17:54:39 +07:00
|
|
|
pppox_unbind_sock(sk);
|
|
|
|
release_sock(sk);
|
|
|
|
sock_put(sk);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/************************************************************************
|
|
|
|
*
|
|
|
|
* Receive a PPPoE Discovery frame.
|
|
|
|
* This is solely for detection of PADT frames
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
2009-01-22 06:54:54 +07:00
|
|
|
static int pppoe_disc_rcv(struct sk_buff *skb, struct net_device *dev,
|
|
|
|
struct packet_type *pt, struct net_device *orig_dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
{
|
|
|
|
struct pppoe_hdr *ph;
|
|
|
|
struct pppox_sock *po;
|
2009-01-22 06:54:54 +07:00
|
|
|
struct pppoe_net *pn;
|
2007-09-18 01:53:39 +07:00
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
skb = skb_share_check(skb, GFP_ATOMIC);
|
|
|
|
if (!skb)
|
2005-04-17 05:20:36 +07:00
|
|
|
goto out;
|
|
|
|
|
2008-06-11 04:08:25 +07:00
|
|
|
if (!pskb_may_pull(skb, sizeof(struct pppoe_hdr)))
|
|
|
|
goto abort;
|
|
|
|
|
2007-03-11 01:56:08 +07:00
|
|
|
ph = pppoe_hdr(skb);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (ph->code != PADT_CODE)
|
|
|
|
goto abort;
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
pn = pppoe_pernet(dev_net(dev));
|
|
|
|
po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
|
2015-11-19 18:52:56 +07:00
|
|
|
if (po)
|
2015-03-01 17:54:39 +07:00
|
|
|
if (!schedule_work(&po->proto.pppoe.padt_work))
|
2015-11-19 18:52:56 +07:00
|
|
|
sock_put(sk_pppox(po));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
abort:
|
|
|
|
kfree_skb(skb);
|
|
|
|
out:
|
|
|
|
return NET_RX_SUCCESS; /* Lies... :-) */
|
|
|
|
}
|
|
|
|
|
2009-03-09 15:18:29 +07:00
|
|
|
static struct packet_type pppoes_ptype __read_mostly = {
|
2009-02-01 15:45:17 +07:00
|
|
|
.type = cpu_to_be16(ETH_P_PPP_SES),
|
2005-04-17 05:20:36 +07:00
|
|
|
.func = pppoe_rcv,
|
|
|
|
};
|
|
|
|
|
2009-03-09 15:18:29 +07:00
|
|
|
static struct packet_type pppoed_ptype __read_mostly = {
|
2009-02-01 15:45:17 +07:00
|
|
|
.type = cpu_to_be16(ETH_P_PPP_DISC),
|
2005-04-17 05:20:36 +07:00
|
|
|
.func = pppoe_disc_rcv,
|
|
|
|
};
|
|
|
|
|
2009-03-09 15:18:29 +07:00
|
|
|
static struct proto pppoe_sk_proto __read_mostly = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.name = "PPPOE",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.obj_size = sizeof(struct pppox_sock),
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Initialize a new struct sock.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
2015-05-09 09:09:13 +07:00
|
|
|
static int pppoe_create(struct net *net, struct socket *sock, int kern)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct sock *sk;
|
|
|
|
|
2015-05-09 09:09:13 +07:00
|
|
|
sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppoe_sk_proto, kern);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!sk)
|
2009-01-22 06:54:15 +07:00
|
|
|
return -ENOMEM;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
sock_init_data(sock, sk);
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
sock->state = SS_UNCONNECTED;
|
|
|
|
sock->ops = &pppoe_ops;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
sk->sk_backlog_rcv = pppoe_rcv_core;
|
|
|
|
sk->sk_state = PPPOX_NONE;
|
|
|
|
sk->sk_type = SOCK_STREAM;
|
|
|
|
sk->sk_family = PF_PPPOX;
|
|
|
|
sk->sk_protocol = PX_PROTO_OE;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-12-03 22:49:32 +07:00
|
|
|
INIT_WORK(&pppox_sk(sk)->proto.pppoe.padt_work,
|
|
|
|
pppoe_unbind_sock_work);
|
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pppoe_release(struct socket *sock)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct pppox_sock *po;
|
2009-01-22 06:54:54 +07:00
|
|
|
struct pppoe_net *pn;
|
2009-10-27 06:23:20 +07:00
|
|
|
struct net *net = NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (!sk)
|
|
|
|
return 0;
|
|
|
|
|
2007-04-21 06:59:24 +07:00
|
|
|
lock_sock(sk);
|
2009-01-22 06:54:15 +07:00
|
|
|
if (sock_flag(sk, SOCK_DEAD)) {
|
2007-04-21 06:59:24 +07:00
|
|
|
release_sock(sk);
|
2005-04-17 05:20:36 +07:00
|
|
|
return -EBADF;
|
2007-04-21 06:59:24 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-10-27 06:23:20 +07:00
|
|
|
po = pppox_sk(sk);
|
|
|
|
|
2015-10-22 21:57:10 +07:00
|
|
|
if (po->pppoe_dev) {
|
2009-10-27 06:23:20 +07:00
|
|
|
dev_put(po->pppoe_dev);
|
|
|
|
po->pppoe_dev = NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
pppox_unbind_sock(sk);
|
|
|
|
|
|
|
|
/* Signal the death of the socket. */
|
|
|
|
sk->sk_state = PPPOX_DEAD;
|
|
|
|
|
2009-10-27 06:23:20 +07:00
|
|
|
net = sock_net(sk);
|
|
|
|
pn = pppoe_pernet(net);
|
2007-04-21 06:59:24 +07:00
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
/*
|
|
|
|
* protect "po" from concurrent updates
|
|
|
|
* on pppoe_flush_dev
|
|
|
|
*/
|
2009-10-27 06:23:20 +07:00
|
|
|
delete_item(pn, po->pppoe_pa.sid, po->pppoe_pa.remote,
|
|
|
|
po->pppoe_ifindex);
|
2007-04-21 06:59:24 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
sock_orphan(sk);
|
|
|
|
sock->sk = NULL;
|
|
|
|
|
|
|
|
skb_queue_purge(&sk->sk_receive_queue);
|
2007-04-21 06:59:24 +07:00
|
|
|
release_sock(sk);
|
2005-04-17 05:20:36 +07:00
|
|
|
sock_put(sk);
|
|
|
|
|
2007-04-21 06:56:31 +07:00
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
|
|
|
|
int sockaddr_len, int flags)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
2009-01-22 06:54:54 +07:00
|
|
|
struct sockaddr_pppox *sp = (struct sockaddr_pppox *)uservaddr;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct pppox_sock *po = pppox_sk(sk);
|
2009-10-27 06:23:20 +07:00
|
|
|
struct net_device *dev = NULL;
|
2009-01-22 06:54:54 +07:00
|
|
|
struct pppoe_net *pn;
|
2009-10-27 06:23:20 +07:00
|
|
|
struct net *net = NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
int error;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
|
|
|
error = -EINVAL;
|
|
|
|
if (sp->sa_protocol != PX_PROTO_OE)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Check for already bound sockets */
|
|
|
|
error = -EBUSY;
|
2009-01-22 06:54:15 +07:00
|
|
|
if ((sk->sk_state & PPPOX_CONNECTED) &&
|
|
|
|
stage_session(sp->sa_addr.pppoe.sid))
|
2005-04-17 05:20:36 +07:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Check for already disconnected sockets, on attempts to disconnect */
|
|
|
|
error = -EALREADY;
|
2009-01-22 06:54:15 +07:00
|
|
|
if ((sk->sk_state & PPPOX_DEAD) &&
|
|
|
|
!stage_session(sp->sa_addr.pppoe.sid))
|
2005-04-17 05:20:36 +07:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
/* Delete the old binding */
|
|
|
|
if (stage_session(po->pppoe_pa.sid)) {
|
|
|
|
pppox_unbind_sock(sk);
|
2009-10-27 06:23:20 +07:00
|
|
|
pn = pppoe_pernet(sock_net(sk));
|
|
|
|
delete_item(pn, po->pppoe_pa.sid,
|
|
|
|
po->pppoe_pa.remote, po->pppoe_ifindex);
|
2009-01-22 06:54:54 +07:00
|
|
|
if (po->pppoe_dev) {
|
2005-04-17 05:20:36 +07:00
|
|
|
dev_put(po->pppoe_dev);
|
2009-10-27 06:23:20 +07:00
|
|
|
po->pppoe_dev = NULL;
|
2009-01-22 06:54:54 +07:00
|
|
|
}
|
2009-10-27 06:23:20 +07:00
|
|
|
|
2015-12-03 22:49:32 +07:00
|
|
|
po->pppoe_ifindex = 0;
|
|
|
|
memset(&po->pppoe_pa, 0, sizeof(po->pppoe_pa));
|
|
|
|
memset(&po->pppoe_relay, 0, sizeof(po->pppoe_relay));
|
|
|
|
memset(&po->chan, 0, sizeof(po->chan));
|
|
|
|
po->next = NULL;
|
|
|
|
po->num = 0;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
sk->sk_state = PPPOX_NONE;
|
|
|
|
}
|
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
/* Re-bind in session stage only */
|
|
|
|
if (stage_session(sp->sa_addr.pppoe.sid)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
error = -ENODEV;
|
2009-10-27 06:23:20 +07:00
|
|
|
net = sock_net(sk);
|
|
|
|
dev = dev_get_by_name(net, sp->sa_addr.pppoe.dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!dev)
|
2009-10-27 06:23:20 +07:00
|
|
|
goto err_put;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
po->pppoe_dev = dev;
|
2007-03-05 07:03:22 +07:00
|
|
|
po->pppoe_ifindex = dev->ifindex;
|
2009-10-27 06:23:20 +07:00
|
|
|
pn = pppoe_pernet(net);
|
2009-01-22 06:54:15 +07:00
|
|
|
if (!(dev->flags & IFF_UP)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
goto err_put;
|
2007-04-21 06:57:27 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
memcpy(&po->pppoe_pa,
|
|
|
|
&sp->sa_addr.pppoe,
|
|
|
|
sizeof(struct pppoe_addr));
|
|
|
|
|
2009-10-27 06:23:20 +07:00
|
|
|
write_lock_bh(&pn->hash_lock);
|
2009-01-22 06:54:54 +07:00
|
|
|
error = __set_item(pn, po);
|
|
|
|
write_unlock_bh(&pn->hash_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (error < 0)
|
|
|
|
goto err_put;
|
|
|
|
|
|
|
|
po->chan.hdrlen = (sizeof(struct pppoe_hdr) +
|
|
|
|
dev->hard_header_len);
|
|
|
|
|
net: pppoe: use correct channel MTU when using Multilink PPP
The PPP channel MTU is used with Multilink PPP when ppp_mp_explode() (see
ppp_generic module) tries to determine how big a fragment might be. According
to RFC 1661, the MTU excludes the 2-byte PPP protocol field, see the
corresponding comment and code in ppp_mp_explode():
/*
* hdrlen includes the 2-byte PPP protocol field, but the
* MTU counts only the payload excluding the protocol field.
* (RFC1661 Section 2)
*/
mtu = pch->chan->mtu - (hdrlen - 2);
However, the pppoe module *does* include the PPP protocol field in the channel
MTU, which is wrong as it causes the PPP payload to be 1-2 bytes too big under
certain circumstances (one byte if PPP protocol compression is used, two
otherwise), causing the generated Ethernet packets to be dropped. So the pppoe
module has to subtract two bytes from the channel MTU. This error only
manifests itself when using Multilink PPP, as otherwise the channel MTU is not
used anywhere.
In the following, I will describe how to reproduce this bug. We configure two
pppd instances for multilink PPP over two PPPoE links, say eth2 and eth3, with
a MTU of 1492 bytes for each link and a MRRU of 2976 bytes. (This MRRU is
computed by adding the two link MTUs and subtracting the MP header twice, which
is 4 bytes long.) The necessary pppd statements on both sides are "multilink
mtu 1492 mru 1492 mrru 2976". On the client side, we additionally need "plugin
rp-pppoe.so eth2" and "plugin rp-pppoe.so eth3", respectively; on the server
side, we additionally need to start two pppoe-server instances to be able to
establish two PPPoE sessions, one over eth2 and one over eth3. We set the MTU
of the PPP network interface to the MRRU (2976) on both sides of the connection
in order to make use of the higher bandwidth. (If we didn't do that, IP
fragmentation would kick in, which we want to avoid.)
Now we send a ICMPv4 echo request with a payload of 2948 bytes from client to
server over the PPP link. This results in the following network packet:
2948 (echo payload)
+ 8 (ICMPv4 header)
+ 20 (IPv4 header)
---------------------
2976 (PPP payload)
These 2976 bytes do not exceed the MTU of the PPP network interface, so the
IP packet is not fragmented. Now the multilink PPP code in ppp_mp_explode()
prepends one protocol byte (0x21 for IPv4), making the packet one byte bigger
than the negotiated MRRU. So this packet would have to be divided in three
fragments. But this does not happen as each link MTU is assumed to be two bytes
larger. So this packet is diveded into two fragments only, one of size 1489 and
one of size 1488. Now we have for that bigger fragment:
1489 (PPP payload)
+ 4 (MP header)
+ 2 (PPP protocol field for the MP payload (0x3d))
+ 6 (PPPoE header)
--------------------------
1501 (Ethernet payload)
This packet exceeds the link MTU and is discarded.
If one configures the link MTU on the client side to 1501, one can see the
discarded Ethernet frames with tcpdump running on the client. A
ping -s 2948 -c 1 192.168.15.254
leads to the smaller fragment that is correctly received on the server side:
(tcpdump -vvvne -i eth3 pppoes and ppp proto 0x3d)
52:54:00:ad:87:fd > 52:54:00:79:5c:d0, ethertype PPPoE S (0x8864),
length 1514: PPPoE [ses 0x3] MLPPP (0x003d), length 1494: seq 0x000,
Flags [end], length 1492
and to the bigger fragment that is not received on the server side:
(tcpdump -vvvne -i eth2 pppoes and ppp proto 0x3d)
52:54:00:70:9e:89 > 52:54:00:5d:6f:b0, ethertype PPPoE S (0x8864),
length 1515: PPPoE [ses 0x5] MLPPP (0x003d), length 1495: seq 0x000,
Flags [begin], length 1493
With the patch below, we correctly obtain three fragments:
52:54:00:ad:87:fd > 52:54:00:79:5c:d0, ethertype PPPoE S (0x8864),
length 1514: PPPoE [ses 0x1] MLPPP (0x003d), length 1494: seq 0x000,
Flags [begin], length 1492
52:54:00:70:9e:89 > 52:54:00:5d:6f:b0, ethertype PPPoE S (0x8864),
length 1514: PPPoE [ses 0x1] MLPPP (0x003d), length 1494: seq 0x000,
Flags [none], length 1492
52:54:00:ad:87:fd > 52:54:00:79:5c:d0, ethertype PPPoE S (0x8864),
length 27: PPPoE [ses 0x1] MLPPP (0x003d), length 7: seq 0x000,
Flags [end], length 5
And the ICMPv4 echo request is successfully received at the server side:
IP (tos 0x0, ttl 64, id 21925, offset 0, flags [DF], proto ICMP (1),
length 2976)
192.168.222.2 > 192.168.15.254: ICMP echo request, id 30530, seq 0,
length 2956
The bug was introduced in commit c9aa6895371b2a257401f59d3393c9f7ac5a8698
("[PPPOE]: Advertise PPPoE MTU") from the very beginning. This patch applies
to 3.10 upwards but the fix can be applied (with minor modifications) to
kernels as old as 2.6.32.
Signed-off-by: Christoph Schulz <develop@kristov.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-07-13 05:53:15 +07:00
|
|
|
po->chan.mtu = dev->mtu - sizeof(struct pppoe_hdr) - 2;
|
2005-04-17 05:20:36 +07:00
|
|
|
po->chan.private = sk;
|
|
|
|
po->chan.ops = &pppoe_chan_ops;
|
|
|
|
|
2009-01-22 06:55:40 +07:00
|
|
|
error = ppp_register_net_channel(dev_net(dev), &po->chan);
|
2009-10-27 06:23:20 +07:00
|
|
|
if (error) {
|
|
|
|
delete_item(pn, po->pppoe_pa.sid,
|
|
|
|
po->pppoe_pa.remote, po->pppoe_ifindex);
|
2005-04-17 05:20:36 +07:00
|
|
|
goto err_put;
|
2009-10-27 06:23:20 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
sk->sk_state = PPPOX_CONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
po->num = sp->sa_addr.pppoe.sid;
|
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
end:
|
2005-04-17 05:20:36 +07:00
|
|
|
release_sock(sk);
|
|
|
|
return error;
|
|
|
|
err_put:
|
|
|
|
if (po->pppoe_dev) {
|
|
|
|
dev_put(po->pppoe_dev);
|
|
|
|
po->pppoe_dev = NULL;
|
|
|
|
}
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pppoe_getname(struct socket *sock, struct sockaddr *uaddr,
|
|
|
|
int *usockaddr_len, int peer)
|
|
|
|
{
|
|
|
|
int len = sizeof(struct sockaddr_pppox);
|
|
|
|
struct sockaddr_pppox sp;
|
|
|
|
|
|
|
|
sp.sa_family = AF_PPPOX;
|
|
|
|
sp.sa_protocol = PX_PROTO_OE;
|
|
|
|
memcpy(&sp.sa_addr.pppoe, &pppox_sk(sock->sk)->pppoe_pa,
|
|
|
|
sizeof(struct pppoe_addr));
|
|
|
|
|
|
|
|
memcpy(uaddr, &sp, len);
|
|
|
|
|
|
|
|
*usockaddr_len = len;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pppoe_ioctl(struct socket *sock, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct pppox_sock *po = pppox_sk(sk);
|
2007-07-31 07:48:23 +07:00
|
|
|
int val;
|
|
|
|
int err;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case PPPIOCGMRU:
|
|
|
|
err = -ENXIO;
|
|
|
|
if (!(sk->sk_state & PPPOX_CONNECTED))
|
|
|
|
break;
|
|
|
|
|
|
|
|
err = -EFAULT;
|
|
|
|
if (put_user(po->pppoe_dev->mtu -
|
|
|
|
sizeof(struct pppoe_hdr) -
|
|
|
|
PPP_HDRLEN,
|
2009-01-22 06:54:54 +07:00
|
|
|
(int __user *)arg))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPIOCSMRU:
|
|
|
|
err = -ENXIO;
|
|
|
|
if (!(sk->sk_state & PPPOX_CONNECTED))
|
|
|
|
break;
|
|
|
|
|
|
|
|
err = -EFAULT;
|
2009-01-22 06:54:15 +07:00
|
|
|
if (get_user(val, (int __user *)arg))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (val < (po->pppoe_dev->mtu
|
|
|
|
- sizeof(struct pppoe_hdr)
|
|
|
|
- PPP_HDRLEN))
|
|
|
|
err = 0;
|
|
|
|
else
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPIOCSFLAGS:
|
|
|
|
err = -EFAULT;
|
2009-01-22 06:54:15 +07:00
|
|
|
if (get_user(val, (int __user *)arg))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPOEIOCSFWD:
|
|
|
|
{
|
|
|
|
struct pppox_sock *relay_po;
|
|
|
|
|
|
|
|
err = -EBUSY;
|
2015-11-19 18:53:21 +07:00
|
|
|
if (sk->sk_state & (PPPOX_BOUND | PPPOX_DEAD))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
err = -ENOTCONN;
|
|
|
|
if (!(sk->sk_state & PPPOX_CONNECTED))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* PPPoE address from the user specifies an outbound
|
2007-03-03 04:16:56 +07:00
|
|
|
PPPoE address which frames are forwarded to */
|
2005-04-17 05:20:36 +07:00
|
|
|
err = -EFAULT;
|
|
|
|
if (copy_from_user(&po->pppoe_relay,
|
|
|
|
(void __user *)arg,
|
|
|
|
sizeof(struct sockaddr_pppox)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
err = -EINVAL;
|
|
|
|
if (po->pppoe_relay.sa_family != AF_PPPOX ||
|
2009-01-22 06:54:15 +07:00
|
|
|
po->pppoe_relay.sa_protocol != PX_PROTO_OE)
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Check that the socket referenced by the address
|
|
|
|
actually exists. */
|
2009-01-22 06:54:54 +07:00
|
|
|
relay_po = get_item_by_addr(sock_net(sk), &po->pppoe_relay);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!relay_po)
|
|
|
|
break;
|
|
|
|
|
|
|
|
sock_put(sk_pppox(relay_po));
|
|
|
|
sk->sk_state |= PPPOX_RELAY;
|
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PPPOEIOCDFWD:
|
|
|
|
err = -EALREADY;
|
|
|
|
if (!(sk->sk_state & PPPOX_RELAY))
|
|
|
|
break;
|
|
|
|
|
|
|
|
sk->sk_state &= ~PPPOX_RELAY;
|
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
|
2007-07-31 07:48:23 +07:00
|
|
|
default:
|
|
|
|
err = -ENOTTY;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-03-02 14:37:48 +07:00
|
|
|
static int pppoe_sendmsg(struct socket *sock, struct msghdr *m,
|
|
|
|
size_t total_len)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-04-21 06:56:31 +07:00
|
|
|
struct sk_buff *skb;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct pppox_sock *po = pppox_sk(sk);
|
2007-04-21 06:56:31 +07:00
|
|
|
int error;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct pppoe_hdr hdr;
|
|
|
|
struct pppoe_hdr *ph;
|
|
|
|
struct net_device *dev;
|
|
|
|
char *start;
|
|
|
|
|
2007-07-31 07:49:13 +07:00
|
|
|
lock_sock(sk);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED)) {
|
|
|
|
error = -ENOTCONN;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hdr.ver = 1;
|
|
|
|
hdr.type = 1;
|
|
|
|
hdr.code = 0;
|
|
|
|
hdr.sid = po->num;
|
|
|
|
|
|
|
|
dev = po->pppoe_dev;
|
|
|
|
|
|
|
|
error = -EMSGSIZE;
|
2009-01-22 06:54:15 +07:00
|
|
|
if (total_len > (dev->mtu + dev->hard_header_len))
|
2005-04-17 05:20:36 +07:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
|
|
skb = sock_wmalloc(sk, total_len + dev->hard_header_len + 32,
|
|
|
|
0, GFP_KERNEL);
|
|
|
|
if (!skb) {
|
|
|
|
error = -ENOMEM;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reserve space for headers. */
|
|
|
|
skb_reserve(skb, dev->hard_header_len);
|
2007-04-11 10:45:18 +07:00
|
|
|
skb_reset_network_header(skb);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
skb->dev = dev;
|
|
|
|
|
|
|
|
skb->priority = sk->sk_priority;
|
2009-02-01 15:45:17 +07:00
|
|
|
skb->protocol = cpu_to_be16(ETH_P_PPP_SES);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
ph = (struct pppoe_hdr *)skb_put(skb, total_len + sizeof(struct pppoe_hdr));
|
|
|
|
start = (char *)&ph->tag[0];
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-04-07 08:25:44 +07:00
|
|
|
error = memcpy_from_msg(start, m, total_len);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (error < 0) {
|
|
|
|
kfree_skb(skb);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = total_len;
|
2007-10-09 15:36:32 +07:00
|
|
|
dev_hard_header(skb, dev, ETH_P_PPP_SES,
|
|
|
|
po->pppoe_pa.remote, NULL, total_len);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
memcpy(ph, &hdr, sizeof(struct pppoe_hdr));
|
|
|
|
|
|
|
|
ph->length = htons(total_len);
|
|
|
|
|
|
|
|
dev_queue_xmit(skb);
|
|
|
|
|
|
|
|
end:
|
|
|
|
release_sock(sk);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
*
|
|
|
|
* xmit function for internal use.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct pppox_sock *po = pppox_sk(sk);
|
|
|
|
struct net_device *dev = po->pppoe_dev;
|
|
|
|
struct pppoe_hdr *ph;
|
|
|
|
int data_len = skb->len;
|
|
|
|
|
2009-10-27 06:23:20 +07:00
|
|
|
/* The higher-level PPP code (ppp_unregister_channel()) ensures the PPP
|
|
|
|
* xmit operations conclude prior to an unregistration call. Thus
|
|
|
|
* sk->sk_state cannot change, so we don't need to do lock_sock().
|
|
|
|
* But, we also can't do a lock_sock since that introduces a potential
|
|
|
|
* deadlock as we'd reverse the lock ordering used when calling
|
|
|
|
* ppp_unregister_channel().
|
|
|
|
*/
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
|
|
|
|
goto abort;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
goto abort;
|
|
|
|
|
2007-09-17 06:19:50 +07:00
|
|
|
/* Copy the data if there is no space for the header or if it's
|
|
|
|
* read-only.
|
|
|
|
*/
|
2007-09-17 06:21:16 +07:00
|
|
|
if (skb_cow_head(skb, sizeof(*ph) + dev->hard_header_len))
|
2007-09-17 06:19:50 +07:00
|
|
|
goto abort;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-09-17 06:20:21 +07:00
|
|
|
__skb_push(skb, sizeof(*ph));
|
2007-09-17 06:19:50 +07:00
|
|
|
skb_reset_network_header(skb);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-09-17 06:20:21 +07:00
|
|
|
ph = pppoe_hdr(skb);
|
|
|
|
ph->ver = 1;
|
|
|
|
ph->type = 1;
|
|
|
|
ph->code = 0;
|
|
|
|
ph->sid = po->num;
|
|
|
|
ph->length = htons(data_len);
|
|
|
|
|
2009-02-01 15:45:17 +07:00
|
|
|
skb->protocol = cpu_to_be16(ETH_P_PPP_SES);
|
2007-09-17 06:19:50 +07:00
|
|
|
skb->dev = dev;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-10-09 15:36:32 +07:00
|
|
|
dev_hard_header(skb, dev, ETH_P_PPP_SES,
|
|
|
|
po->pppoe_pa.remote, NULL, data_len);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-09-20 00:45:02 +07:00
|
|
|
dev_queue_xmit(skb);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
abort:
|
2007-09-17 06:19:50 +07:00
|
|
|
kfree_skb(skb);
|
2010-12-13 06:06:16 +07:00
|
|
|
return 1;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
*
|
|
|
|
* xmit function called by generic PPP driver
|
|
|
|
* sends PPP frame over PPPoE socket
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
|
|
|
|
{
|
2009-01-22 06:54:54 +07:00
|
|
|
struct sock *sk = (struct sock *)chan->private;
|
2005-04-17 05:20:36 +07:00
|
|
|
return __pppoe_xmit(sk, skb);
|
|
|
|
}
|
|
|
|
|
2010-08-04 14:34:36 +07:00
|
|
|
static const struct ppp_channel_ops pppoe_chan_ops = {
|
2006-09-14 00:24:59 +07:00
|
|
|
.start_xmit = pppoe_xmit,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2015-03-02 14:37:48 +07:00
|
|
|
static int pppoe_recvmsg(struct socket *sock, struct msghdr *m,
|
|
|
|
size_t total_len, int flags)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
2007-04-21 06:56:31 +07:00
|
|
|
struct sk_buff *skb;
|
2005-04-17 05:20:36 +07:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if (sk->sk_state & PPPOX_BOUND) {
|
|
|
|
error = -EIO;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
|
|
|
|
flags & MSG_DONTWAIT, &error);
|
2007-04-21 06:56:31 +07:00
|
|
|
if (error < 0)
|
2005-04-17 05:20:36 +07:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (skb) {
|
2008-06-21 11:58:02 +07:00
|
|
|
total_len = min_t(size_t, total_len, skb->len);
|
2014-11-06 04:46:40 +07:00
|
|
|
error = skb_copy_datagram_msg(skb, 0, m, total_len);
|
2012-05-19 03:23:00 +07:00
|
|
|
if (error == 0) {
|
|
|
|
consume_skb(skb);
|
|
|
|
return total_len;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-03-11 01:56:08 +07:00
|
|
|
kfree_skb(skb);
|
2005-04-17 05:20:36 +07:00
|
|
|
end:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
static int pppoe_seq_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
struct pppox_sock *po;
|
|
|
|
char *dev_name;
|
|
|
|
|
|
|
|
if (v == SEQ_START_TOKEN) {
|
|
|
|
seq_puts(seq, "Id Address Device\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
po = v;
|
|
|
|
dev_name = po->pppoe_pa.dev;
|
|
|
|
|
2008-10-28 05:59:26 +07:00
|
|
|
seq_printf(seq, "%08X %pM %8s\n",
|
2009-01-22 06:54:54 +07:00
|
|
|
po->pppoe_pa.sid, po->pppoe_pa.remote, dev_name);
|
2005-04-17 05:20:36 +07:00
|
|
|
out:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
static inline struct pppox_sock *pppoe_get_idx(struct pppoe_net *pn, loff_t pos)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-04-21 06:56:31 +07:00
|
|
|
struct pppox_sock *po;
|
2009-01-22 06:54:15 +07:00
|
|
|
int i;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-01-22 06:54:15 +07:00
|
|
|
for (i = 0; i < PPPOE_HASH_SIZE; i++) {
|
2009-01-22 06:54:54 +07:00
|
|
|
po = pn->hash_table[i];
|
2005-04-17 05:20:36 +07:00
|
|
|
while (po) {
|
|
|
|
if (!pos--)
|
|
|
|
goto out;
|
|
|
|
po = po->next;
|
|
|
|
}
|
|
|
|
}
|
2009-01-22 06:54:54 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
out:
|
|
|
|
return po;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *pppoe_seq_start(struct seq_file *seq, loff_t *pos)
|
2009-01-22 06:54:54 +07:00
|
|
|
__acquires(pn->hash_lock)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-01-27 12:11:02 +07:00
|
|
|
struct pppoe_net *pn = pppoe_pernet(seq_file_net(seq));
|
2005-04-17 05:20:36 +07:00
|
|
|
loff_t l = *pos;
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
read_lock_bh(&pn->hash_lock);
|
|
|
|
return l ? pppoe_get_idx(pn, --l) : SEQ_START_TOKEN;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *pppoe_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
|
|
{
|
2009-01-27 12:11:02 +07:00
|
|
|
struct pppoe_net *pn = pppoe_pernet(seq_file_net(seq));
|
2005-04-17 05:20:36 +07:00
|
|
|
struct pppox_sock *po;
|
|
|
|
|
|
|
|
++*pos;
|
|
|
|
if (v == SEQ_START_TOKEN) {
|
2009-01-22 06:54:54 +07:00
|
|
|
po = pppoe_get_idx(pn, 0);
|
2005-04-17 05:20:36 +07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
po = v;
|
2006-09-14 00:24:59 +07:00
|
|
|
if (po->next)
|
2005-04-17 05:20:36 +07:00
|
|
|
po = po->next;
|
|
|
|
else {
|
|
|
|
int hash = hash_item(po->pppoe_pa.sid, po->pppoe_pa.remote);
|
|
|
|
|
2009-07-29 06:43:08 +07:00
|
|
|
po = NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
while (++hash < PPPOE_HASH_SIZE) {
|
2009-01-22 06:54:54 +07:00
|
|
|
po = pn->hash_table[hash];
|
2005-04-17 05:20:36 +07:00
|
|
|
if (po)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-22 06:54:54 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
out:
|
|
|
|
return po;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pppoe_seq_stop(struct seq_file *seq, void *v)
|
2009-01-22 06:54:54 +07:00
|
|
|
__releases(pn->hash_lock)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-01-27 12:11:02 +07:00
|
|
|
struct pppoe_net *pn = pppoe_pernet(seq_file_net(seq));
|
2009-01-22 06:54:54 +07:00
|
|
|
read_unlock_bh(&pn->hash_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2009-01-15 04:52:18 +07:00
|
|
|
static const struct seq_operations pppoe_seq_ops = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.start = pppoe_seq_start,
|
|
|
|
.next = pppoe_seq_next,
|
|
|
|
.stop = pppoe_seq_stop,
|
|
|
|
.show = pppoe_seq_show,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int pppoe_seq_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2009-01-27 12:11:02 +07:00
|
|
|
return seq_open_net(inode, file, &pppoe_seq_ops,
|
|
|
|
sizeof(struct seq_net_private));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-02-12 15:55:34 +07:00
|
|
|
static const struct file_operations pppoe_seq_fops = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = pppoe_seq_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
2009-01-27 12:11:02 +07:00
|
|
|
.release = seq_release_net,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
|
2005-12-28 11:57:40 +07:00
|
|
|
static const struct proto_ops pppoe_ops = {
|
2009-01-22 06:54:15 +07:00
|
|
|
.family = AF_PPPOX,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.release = pppoe_release,
|
|
|
|
.bind = sock_no_bind,
|
|
|
|
.connect = pppoe_connect,
|
|
|
|
.socketpair = sock_no_socketpair,
|
|
|
|
.accept = sock_no_accept,
|
|
|
|
.getname = pppoe_getname,
|
|
|
|
.poll = datagram_poll,
|
|
|
|
.listen = sock_no_listen,
|
|
|
|
.shutdown = sock_no_shutdown,
|
|
|
|
.setsockopt = sock_no_setsockopt,
|
|
|
|
.getsockopt = sock_no_getsockopt,
|
|
|
|
.sendmsg = pppoe_sendmsg,
|
|
|
|
.recvmsg = pppoe_recvmsg,
|
|
|
|
.mmap = sock_no_mmap,
|
|
|
|
.ioctl = pppox_ioctl,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2010-09-21 13:43:54 +07:00
|
|
|
static const struct pppox_proto pppoe_proto = {
|
2009-01-22 06:54:15 +07:00
|
|
|
.create = pppoe_create,
|
|
|
|
.ioctl = pppoe_ioctl,
|
|
|
|
.owner = THIS_MODULE,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2009-01-22 06:54:54 +07:00
|
|
|
static __net_init int pppoe_init_net(struct net *net)
|
|
|
|
{
|
2009-11-29 22:46:10 +07:00
|
|
|
struct pppoe_net *pn = pppoe_pernet(net);
|
2009-01-22 06:54:54 +07:00
|
|
|
struct proc_dir_entry *pde;
|
|
|
|
|
|
|
|
rwlock_init(&pn->hash_lock);
|
|
|
|
|
2013-02-18 08:34:54 +07:00
|
|
|
pde = proc_create("pppoe", S_IRUGO, net->proc_net, &pppoe_seq_fops);
|
2009-01-22 06:54:54 +07:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2009-11-29 22:46:10 +07:00
|
|
|
if (!pde)
|
|
|
|
return -ENOMEM;
|
2009-01-22 06:54:54 +07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __net_exit void pppoe_exit_net(struct net *net)
|
|
|
|
{
|
2013-02-18 08:34:56 +07:00
|
|
|
remove_proc_entry("pppoe", net->proc_net);
|
2009-01-22 06:54:54 +07:00
|
|
|
}
|
|
|
|
|
2009-02-10 09:05:16 +07:00
|
|
|
static struct pernet_operations pppoe_net_ops = {
|
2009-01-22 06:54:54 +07:00
|
|
|
.init = pppoe_init_net,
|
|
|
|
.exit = pppoe_exit_net,
|
2009-11-29 22:46:10 +07:00
|
|
|
.id = &pppoe_net_id,
|
|
|
|
.size = sizeof(struct pppoe_net),
|
2009-01-22 06:54:54 +07:00
|
|
|
};
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
static int __init pppoe_init(void)
|
|
|
|
{
|
2009-01-22 06:54:54 +07:00
|
|
|
int err;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-11-29 22:46:10 +07:00
|
|
|
err = register_pernet_device(&pppoe_net_ops);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2009-08-13 06:39:16 +07:00
|
|
|
err = proto_register(&pppoe_sk_proto, 0);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (err)
|
2009-08-13 06:39:16 +07:00
|
|
|
goto out_unregister_net_ops;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-08-13 06:39:16 +07:00
|
|
|
err = register_pppox_proto(PX_PROTO_OE, &pppoe_proto);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (err)
|
2009-08-13 06:39:16 +07:00
|
|
|
goto out_unregister_pppoe_proto;
|
2006-09-14 00:24:59 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
dev_add_pack(&pppoes_ptype);
|
|
|
|
dev_add_pack(&pppoed_ptype);
|
|
|
|
register_netdevice_notifier(&pppoe_notifier);
|
2009-01-22 06:54:54 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
out_unregister_pppoe_proto:
|
|
|
|
proto_unregister(&pppoe_sk_proto);
|
2009-08-13 06:39:16 +07:00
|
|
|
out_unregister_net_ops:
|
2009-11-29 22:46:10 +07:00
|
|
|
unregister_pernet_device(&pppoe_net_ops);
|
2009-01-22 06:54:54 +07:00
|
|
|
out:
|
|
|
|
return err;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit pppoe_exit(void)
|
|
|
|
{
|
|
|
|
unregister_netdevice_notifier(&pppoe_notifier);
|
2009-08-13 06:39:16 +07:00
|
|
|
dev_remove_pack(&pppoed_ptype);
|
|
|
|
dev_remove_pack(&pppoes_ptype);
|
|
|
|
unregister_pppox_proto(PX_PROTO_OE);
|
2005-04-17 05:20:36 +07:00
|
|
|
proto_unregister(&pppoe_sk_proto);
|
2009-11-29 22:46:10 +07:00
|
|
|
unregister_pernet_device(&pppoe_net_ops);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(pppoe_init);
|
|
|
|
module_exit(pppoe_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Michal Ostrowski <mostrows@speakeasy.net>");
|
|
|
|
MODULE_DESCRIPTION("PPP over Ethernet driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2015-12-02 22:27:39 +07:00
|
|
|
MODULE_ALIAS_NET_PF_PROTO(PF_PPPOX, PX_PROTO_OE);
|