// SPDX-License-Identifier: GPL-2.0-or-later /** -*- 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 * * 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 ...) * 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 processing. * 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:
*/
/* per-net private data for this module */ staticunsignedint pppoe_net_id __read_mostly; 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 comparisons messy * as well, moreover in case of SMP less locking * controversy here
*/ struct pppox_sock *hash_table[PPPOE_HASH_SIZE];
rwlock_t hash_lock;
};
/* * 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 * we use simpler approach based on session id
*/ staticinlinebool stage_session(__be16 sid)
{ return sid != 0;
}
staticinlinestruct pppoe_net *pppoe_pernet(struct net *net)
{ return net_generic(net, pppoe_net_id);
}
for (i = 0; i < ETH_ALEN; i++)
hash ^= addr[i]; 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;
/*************************************************************************** * * Handler for device events. * Certain device events require that sockets be unconnected. *
**************************************************************************/
staticvoid pppoe_flush_dev(struct net_device *dev)
{ struct pppoe_net *pn; int i;
pn = pppoe_pernet(dev_net(dev));
write_lock_bh(&pn->hash_lock); for (i = 0; i < PPPOE_HASH_SIZE; i++) { struct pppox_sock *po = pn->hash_table[i]; struct sock *sk;
while (po) { while (po && po->pppoe_dev != dev) {
po = po->next;
}
if (!po) break;
sk = sk_pppox(po);
/* We always grab the socket lock, followed by the * 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.
*/
/* Only look at sockets that are using this specific device. */ switch (event) { case NETDEV_CHANGEADDR: case NETDEV_CHANGEMTU: /* A change in mtu or address is a bad thing, requiring * LCP re-negotiation.
*/
case NETDEV_GOING_DOWN: case NETDEV_DOWN: /* Find every socket on this device and kill it. */
pppoe_flush_dev(dev); break;
/************************************************************************ * * Do the real work of receiving a PPPoE Session frame. *
***********************************************************************/ staticint pppoe_rcv_core(struct sock *sk, struct sk_buff *skb)
{ struct pppox_sock *po = pppox_sk(sk); struct pppox_sock *relay_po;
/* Backlog receive. Semantics of backlog rcv preclude any code from * executing in lock_sock()/release_sock() bounds; meaning sk->sk_state * can't change.
*/
/* Note that get_item does a sock_hold(), so sk_pppox(po) * is known to be safe.
*/
po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex); if (!po) goto drop;
skb = skb_share_check(skb, GFP_ATOMIC); if (!skb) goto out;
if (skb->pkt_type != PACKET_HOST) goto abort;
if (!pskb_may_pull(skb, sizeof(struct pppoe_hdr))) goto abort;
ph = pppoe_hdr(skb); if (ph->code != PADT_CODE) goto abort;
pn = pppoe_pernet(dev_net(dev));
po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex); if (po) if (!schedule_work(&po->proto.pppoe.padt_work))
sock_put(sk_pppox(po));
/* Re-bind in session stage only */ if (stage_session(sp->sa_addr.pppoe.sid)) {
error = -ENODEV;
net = sock_net(sk);
dev = dev_get_by_name(net, sp->sa_addr.pppoe.dev); if (!dev) goto err_put;
case PPPIOCSFLAGS:
err = -EFAULT; if (get_user(val, (int __user *)arg)) break;
err = 0; break;
case PPPOEIOCSFWD:
{ struct pppox_sock *relay_po;
err = -EBUSY; if (sk->sk_state & (PPPOX_BOUND | PPPOX_DEAD)) break;
err = -ENOTCONN; if (!(sk->sk_state & PPPOX_CONNECTED)) break;
/* PPPoE address from the user specifies an outbound
PPPoE address which frames are forwarded to */
err = -EFAULT; if (copy_from_user(&po->pppoe_relay,
(void __user *)arg, sizeof(struct sockaddr_pppox))) break;
/* Check that the socket referenced by the address
actually exists. */
relay_po = get_item_by_addr(sock_net(sk), &po->pppoe_relay); if (!relay_po) break;
/* 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().
*/
if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED)) goto abort;
if (!dev) goto abort;
/* Copy the data if there is no space for the header or if it's * read-only.
*/ if (skb_cow_head(skb, LL_RESERVED_SPACE(dev) + sizeof(*ph))) goto abort;
++*pos; if (v == SEQ_START_TOKEN) {
po = pppoe_get_idx(pn, 0); goto out;
}
po = v; if (po->next)
po = po->next; else { int hash = hash_item(po->pppoe_pa.sid, po->pppoe_pa.remote);
po = NULL; while (++hash < PPPOE_HASH_SIZE) {
po = pn->hash_table[hash]; if (po) break;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.