Renamed patches to keep their original numbering from codelinaro.org Fixed minor bugs and added support for the qca-nss-drv-l2tpv2 module
1376 lines
38 KiB
Diff
1376 lines
38 KiB
Diff
--- a/drivers/net/ppp/ppp_generic.c
|
|
+++ b/drivers/net/ppp/ppp_generic.c
|
|
@@ -1,5 +1,21 @@
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
+ **************************************************************************
|
|
+ * Copyright (c) 2016, The Linux Foundation. All rights reserved.
|
|
+ * Permission to use, copy, modify, and/or distribute this software for
|
|
+ * any purpose with or without fee is hereby granted, provided that the
|
|
+ * above copyright notice and this permission notice appear in all copies.
|
|
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
|
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
+ **************************************************************************
|
|
+ */
|
|
+
|
|
+/*
|
|
* Generic PPP layer for Linux.
|
|
*
|
|
* Copyright 1999-2002 Paul Mackerras.
|
|
@@ -48,11 +64,17 @@
|
|
#include <net/slhc_vj.h>
|
|
#include <linux/atomic.h>
|
|
#include <linux/refcount.h>
|
|
+#include <linux/if_pppox.h>
|
|
|
|
#include <linux/nsproxy.h>
|
|
#include <net/net_namespace.h>
|
|
#include <net/netns/generic.h>
|
|
|
|
+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
|
|
+#include <linux/netfilter.h>
|
|
+#include <net/netfilter/nf_flow_table.h>
|
|
+#endif
|
|
+
|
|
#define PPP_VERSION "2.4.2"
|
|
|
|
/*
|
|
@@ -255,6 +277,24 @@ struct ppp_net {
|
|
#define seq_before(a, b) ((s32)((a) - (b)) < 0)
|
|
#define seq_after(a, b) ((s32)((a) - (b)) > 0)
|
|
|
|
+/*
|
|
+ * Registration/Unregistration methods
|
|
+ * for PPP channel connect and disconnect event notifications.
|
|
+ */
|
|
+RAW_NOTIFIER_HEAD(ppp_channel_connection_notifier_list);
|
|
+
|
|
+void ppp_channel_connection_register_notify(struct notifier_block *nb)
|
|
+{
|
|
+ raw_notifier_chain_register(&ppp_channel_connection_notifier_list, nb);
|
|
+}
|
|
+EXPORT_SYMBOL_GPL(ppp_channel_connection_register_notify);
|
|
+
|
|
+void ppp_channel_connection_unregister_notify(struct notifier_block *nb)
|
|
+{
|
|
+ raw_notifier_chain_unregister(&ppp_channel_connection_notifier_list, nb);
|
|
+}
|
|
+EXPORT_SYMBOL_GPL(ppp_channel_connection_unregister_notify);
|
|
+
|
|
/* Prototypes. */
|
|
static int ppp_unattached_ioctl(struct net *net, struct ppp_file *pf,
|
|
struct file *file, unsigned int cmd, unsigned long arg);
|
|
@@ -1592,10 +1632,10 @@ static void ppp_dev_priv_destructor(stru
|
|
ppp_destroy_interface(ppp);
|
|
}
|
|
|
|
-static int ppp_fill_forward_path(struct net_device_path_ctx *ctx,
|
|
- struct net_device_path *path)
|
|
+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
|
|
+static int ppp_flow_offload_check(struct flow_offload_hw_path *path)
|
|
{
|
|
- struct ppp *ppp = netdev_priv(ctx->dev);
|
|
+ struct ppp *ppp = netdev_priv(path->dev);
|
|
struct ppp_channel *chan;
|
|
struct channel *pch;
|
|
|
|
@@ -1607,11 +1647,12 @@ static int ppp_fill_forward_path(struct
|
|
|
|
pch = list_first_entry(&ppp->channels, struct channel, clist);
|
|
chan = pch->chan;
|
|
- if (!chan->ops->fill_forward_path)
|
|
+ if (!chan->ops->flow_offload_check)
|
|
return -EOPNOTSUPP;
|
|
|
|
- return chan->ops->fill_forward_path(ctx, path, chan);
|
|
+ return chan->ops->flow_offload_check(chan, path);
|
|
}
|
|
+#endif /* CONFIG_NF_FLOW_TABLE */
|
|
|
|
static const struct net_device_ops ppp_netdev_ops = {
|
|
.ndo_init = ppp_dev_init,
|
|
@@ -1619,7 +1660,9 @@ static const struct net_device_ops ppp_n
|
|
.ndo_start_xmit = ppp_start_xmit,
|
|
.ndo_siocdevprivate = ppp_net_siocdevprivate,
|
|
.ndo_get_stats64 = ppp_get_stats64,
|
|
- .ndo_fill_forward_path = ppp_fill_forward_path,
|
|
+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
|
|
+ .ndo_flow_offload_check = ppp_flow_offload_check,
|
|
+#endif
|
|
};
|
|
|
|
static struct device_type ppp_type = {
|
|
@@ -2968,6 +3011,20 @@ char *ppp_dev_name(struct ppp_channel *c
|
|
return name;
|
|
}
|
|
|
|
+/* Return the PPP net device index */
|
|
+int ppp_dev_index(struct ppp_channel *chan)
|
|
+{
|
|
+ struct channel *pch = chan->ppp;
|
|
+ int ifindex = 0;
|
|
+
|
|
+ if (pch) {
|
|
+ read_lock_bh(&pch->upl);
|
|
+ if (pch->ppp && pch->ppp->dev)
|
|
+ ifindex = pch->ppp->dev->ifindex;
|
|
+ read_unlock_bh(&pch->upl);
|
|
+ }
|
|
+ return ifindex;
|
|
+}
|
|
|
|
/*
|
|
* Disconnect a channel from the generic layer.
|
|
@@ -3468,6 +3525,9 @@ ppp_connect_channel(struct channel *pch,
|
|
struct ppp_net *pn;
|
|
int ret = -ENXIO;
|
|
int hdrlen;
|
|
+ int ppp_proto;
|
|
+ int version;
|
|
+ int notify = 0;
|
|
|
|
pn = ppp_pernet(pch->chan_net);
|
|
|
|
@@ -3500,6 +3560,32 @@ ppp_connect_channel(struct channel *pch,
|
|
++ppp->n_channels;
|
|
pch->ppp = ppp;
|
|
refcount_inc(&ppp->file.refcnt);
|
|
+
|
|
+ ppp_proto = ppp_channel_get_protocol(pch->chan);
|
|
+ switch (ppp_proto) {
|
|
+ case PX_PROTO_OL2TP:
|
|
+ version = ppp_channel_get_proto_version(pch->chan);
|
|
+ switch (version) {
|
|
+ case 2:
|
|
+ ppp->dev->priv_flags_ext |= IFF_EXT_PPP_L2TPV2;
|
|
+ break;
|
|
+ case 3:
|
|
+ ppp->dev->priv_flags_ext |= IFF_EXT_PPP_L2TPV3;
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ break;
|
|
+
|
|
+ case PX_PROTO_PPTP:
|
|
+ ppp->dev->priv_flags_ext |= IFF_EXT_PPP_PPTP;
|
|
+ break;
|
|
+
|
|
+ default:
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ notify = 1;
|
|
+
|
|
ppp_unlock(ppp);
|
|
ret = 0;
|
|
|
|
@@ -3507,6 +3593,14 @@ ppp_connect_channel(struct channel *pch,
|
|
write_unlock_bh(&pch->upl);
|
|
out:
|
|
mutex_unlock(&pn->all_ppp_mutex);
|
|
+
|
|
+ if (notify && ppp && ppp->dev) {
|
|
+ dev_hold(ppp->dev);
|
|
+ raw_notifier_call_chain(&ppp_channel_connection_notifier_list,
|
|
+ PPP_CHANNEL_CONNECT, ppp->dev);
|
|
+ dev_put(ppp->dev);
|
|
+ }
|
|
+
|
|
return ret;
|
|
}
|
|
|
|
@@ -3524,6 +3618,13 @@ ppp_disconnect_channel(struct channel *p
|
|
pch->ppp = NULL;
|
|
write_unlock_bh(&pch->upl);
|
|
if (ppp) {
|
|
+ if (ppp->dev) {
|
|
+ dev_hold(ppp->dev);
|
|
+ raw_notifier_call_chain(&ppp_channel_connection_notifier_list,
|
|
+ PPP_CHANNEL_DISCONNECT, ppp->dev);
|
|
+ dev_put(ppp->dev);
|
|
+ }
|
|
+
|
|
/* remove it from the ppp unit's list */
|
|
ppp_lock(ppp);
|
|
list_del(&pch->clist);
|
|
@@ -3603,6 +3704,323 @@ static void *unit_find(struct idr *p, in
|
|
return idr_find(p, n);
|
|
}
|
|
|
|
+/* Updates the PPP interface statistics. */
|
|
+void ppp_update_stats(struct net_device *dev, unsigned long rx_packets,
|
|
+ unsigned long rx_bytes, unsigned long tx_packets,
|
|
+ unsigned long tx_bytes, unsigned long rx_errors,
|
|
+ unsigned long tx_errors, unsigned long rx_dropped,
|
|
+ unsigned long tx_dropped)
|
|
+{
|
|
+ struct ppp *ppp;
|
|
+
|
|
+ if (!dev)
|
|
+ return;
|
|
+
|
|
+ if (dev->type != ARPHRD_PPP)
|
|
+ return;
|
|
+
|
|
+ ppp = netdev_priv(dev);
|
|
+
|
|
+ ppp_xmit_lock(ppp);
|
|
+ ppp->stats64.tx_packets += tx_packets;
|
|
+ ppp->stats64.tx_bytes += tx_bytes;
|
|
+ ppp->dev->stats.tx_errors += tx_errors;
|
|
+ ppp->dev->stats.tx_dropped += tx_dropped;
|
|
+ if (tx_packets)
|
|
+ ppp->last_xmit = jiffies;
|
|
+ ppp_xmit_unlock(ppp);
|
|
+
|
|
+ ppp_recv_lock(ppp);
|
|
+ ppp->stats64.rx_packets += rx_packets;
|
|
+ ppp->stats64.rx_bytes += rx_bytes;
|
|
+ ppp->dev->stats.rx_errors += rx_errors;
|
|
+ ppp->dev->stats.rx_dropped += rx_dropped;
|
|
+ if (rx_packets)
|
|
+ ppp->last_recv = jiffies;
|
|
+ ppp_recv_unlock(ppp);
|
|
+}
|
|
+
|
|
+/* Returns true if Compression is enabled on PPP device
|
|
+ */
|
|
+bool ppp_is_cp_enabled(struct net_device *dev)
|
|
+{
|
|
+ struct ppp *ppp;
|
|
+ bool flag = false;
|
|
+
|
|
+ if (!dev)
|
|
+ return false;
|
|
+
|
|
+ if (dev->type != ARPHRD_PPP)
|
|
+ return false;
|
|
+
|
|
+ ppp = netdev_priv(dev);
|
|
+ ppp_lock(ppp);
|
|
+ flag = !!(ppp->xstate & SC_COMP_RUN) || !!(ppp->rstate & SC_DECOMP_RUN);
|
|
+ ppp_unlock(ppp);
|
|
+
|
|
+ return flag;
|
|
+}
|
|
+EXPORT_SYMBOL(ppp_is_cp_enabled);
|
|
+
|
|
+/* Returns >0 if the device is a multilink PPP netdevice, 0 if not or < 0 if
|
|
+ * the device is not PPP.
|
|
+ */
|
|
+int ppp_is_multilink(struct net_device *dev)
|
|
+{
|
|
+ struct ppp *ppp;
|
|
+ unsigned int flags;
|
|
+
|
|
+ if (!dev)
|
|
+ return -1;
|
|
+
|
|
+ if (dev->type != ARPHRD_PPP)
|
|
+ return -1;
|
|
+
|
|
+ ppp = netdev_priv(dev);
|
|
+ ppp_lock(ppp);
|
|
+ flags = ppp->flags;
|
|
+ ppp_unlock(ppp);
|
|
+
|
|
+ if (flags & SC_MULTILINK)
|
|
+ return 1;
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+EXPORT_SYMBOL(ppp_is_multilink);
|
|
+
|
|
+/* __ppp_is_multilink()
|
|
+ * Returns >0 if the device is a multilink PPP netdevice, 0 if not or < 0
|
|
+ * if the device is not PPP. Caller should acquire ppp_lock before calling
|
|
+ * this function
|
|
+ */
|
|
+int __ppp_is_multilink(struct net_device *dev)
|
|
+{
|
|
+ struct ppp *ppp;
|
|
+ unsigned int flags;
|
|
+
|
|
+ if (!dev)
|
|
+ return -1;
|
|
+
|
|
+ if (dev->type != ARPHRD_PPP)
|
|
+ return -1;
|
|
+
|
|
+ ppp = netdev_priv(dev);
|
|
+ flags = ppp->flags;
|
|
+
|
|
+ if (flags & SC_MULTILINK)
|
|
+ return 1;
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+EXPORT_SYMBOL(__ppp_is_multilink);
|
|
+
|
|
+/* ppp_channel_get_protocol()
|
|
+ * Call this to obtain the underlying protocol of the PPP channel,
|
|
+ * e.g. PX_PROTO_OE
|
|
+ *
|
|
+ * NOTE: Some channels do not use PX sockets so the protocol value may be very
|
|
+ * different for them.
|
|
+ * NOTE: -1 indicates failure.
|
|
+ * NOTE: Once you know the channel protocol you may then either cast 'chan' to
|
|
+ * its sub-class or use the channel protocol specific API's as provided by that
|
|
+ * channel sub type.
|
|
+ */
|
|
+int ppp_channel_get_protocol(struct ppp_channel *chan)
|
|
+{
|
|
+ if (!chan->ops->get_channel_protocol)
|
|
+ return -1;
|
|
+
|
|
+ return chan->ops->get_channel_protocol(chan);
|
|
+}
|
|
+EXPORT_SYMBOL(ppp_channel_get_protocol);
|
|
+
|
|
+/* ppp_channel_get_proto_version()
|
|
+ * Call this to get channel protocol version
|
|
+ */
|
|
+int ppp_channel_get_proto_version(struct ppp_channel *chan)
|
|
+{
|
|
+ if (!chan->ops->get_channel_protocol_ver)
|
|
+ return -1;
|
|
+
|
|
+ return chan->ops->get_channel_protocol_ver(chan);
|
|
+}
|
|
+EXPORT_SYMBOL(ppp_channel_get_proto_version);
|
|
+
|
|
+/* ppp_channel_hold()
|
|
+ * Call this to hold a channel.
|
|
+ *
|
|
+ * Returns true on success or false if the hold could not happen.
|
|
+ *
|
|
+ * NOTE: chan must be protected against destruction during this call -
|
|
+ * either by correct locking etc. or because you already have an implicit
|
|
+ * or explicit hold to the channel already and this is an additional hold.
|
|
+ */
|
|
+bool ppp_channel_hold(struct ppp_channel *chan)
|
|
+{
|
|
+ if (!chan->ops->hold)
|
|
+ return false;
|
|
+
|
|
+ chan->ops->hold(chan);
|
|
+ return true;
|
|
+}
|
|
+EXPORT_SYMBOL(ppp_channel_hold);
|
|
+
|
|
+/* ppp_channel_release()
|
|
+ * Call this to release a hold you have upon a channel
|
|
+ */
|
|
+void ppp_channel_release(struct ppp_channel *chan)
|
|
+{
|
|
+ chan->ops->release(chan);
|
|
+}
|
|
+EXPORT_SYMBOL(ppp_channel_release);
|
|
+
|
|
+/* ppp_hold_channels()
|
|
+ * Returns the PPP channels of the PPP device, storing each one into
|
|
+ * channels[].
|
|
+ *
|
|
+ * channels[] has chan_sz elements.
|
|
+ * This function returns the number of channels stored, up to chan_sz.
|
|
+ * It will return < 0 if the device is not PPP.
|
|
+ *
|
|
+ * You MUST release the channels using ppp_release_channels().
|
|
+ */
|
|
+int ppp_hold_channels(struct net_device *dev, struct ppp_channel *channels[],
|
|
+ unsigned int chan_sz)
|
|
+{
|
|
+ struct ppp *ppp;
|
|
+ int c;
|
|
+ struct channel *pch;
|
|
+
|
|
+ if (!dev)
|
|
+ return -1;
|
|
+
|
|
+ if (dev->type != ARPHRD_PPP)
|
|
+ return -1;
|
|
+
|
|
+ ppp = netdev_priv(dev);
|
|
+
|
|
+ c = 0;
|
|
+ ppp_lock(ppp);
|
|
+ list_for_each_entry(pch, &ppp->channels, clist) {
|
|
+ struct ppp_channel *chan;
|
|
+
|
|
+ if (!pch->chan) {
|
|
+ /* Channel is going / gone away */
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ if (c == chan_sz) {
|
|
+ /* No space to record channel */
|
|
+ ppp_unlock(ppp);
|
|
+ return c;
|
|
+ }
|
|
+
|
|
+ /* Hold the channel, if supported */
|
|
+ chan = pch->chan;
|
|
+ if (!chan->ops->hold)
|
|
+ continue;
|
|
+
|
|
+ chan->ops->hold(chan);
|
|
+
|
|
+ /* Record the channel */
|
|
+ channels[c++] = chan;
|
|
+ }
|
|
+ ppp_unlock(ppp);
|
|
+ return c;
|
|
+}
|
|
+EXPORT_SYMBOL(ppp_hold_channels);
|
|
+
|
|
+/* __ppp_hold_channels()
|
|
+ * Returns the PPP channels of the PPP device, storing each one
|
|
+ * into channels[].
|
|
+ *
|
|
+ * channels[] has chan_sz elements.
|
|
+ * This function returns the number of channels stored, up to chan_sz.
|
|
+ * It will return < 0 if the device is not PPP.
|
|
+ *
|
|
+ * You MUST acquire ppp_lock and release the channels using
|
|
+ * ppp_release_channels().
|
|
+ */
|
|
+int __ppp_hold_channels(struct net_device *dev, struct ppp_channel *channels[],
|
|
+ unsigned int chan_sz)
|
|
+{
|
|
+ struct ppp *ppp;
|
|
+ int c;
|
|
+ struct channel *pch;
|
|
+
|
|
+ if (!dev)
|
|
+ return -1;
|
|
+
|
|
+ if (dev->type != ARPHRD_PPP)
|
|
+ return -1;
|
|
+
|
|
+ ppp = netdev_priv(dev);
|
|
+
|
|
+ c = 0;
|
|
+ list_for_each_entry(pch, &ppp->channels, clist) {
|
|
+ struct ppp_channel *chan;
|
|
+
|
|
+ if (!pch->chan) {
|
|
+ /* Channel is going / gone away*/
|
|
+ continue;
|
|
+ }
|
|
+ if (c == chan_sz) {
|
|
+ /* No space to record channel */
|
|
+ return c;
|
|
+ }
|
|
+
|
|
+ /* Hold the channel, if supported */
|
|
+ chan = pch->chan;
|
|
+ if (!chan->ops->hold)
|
|
+ continue;
|
|
+
|
|
+ chan->ops->hold(chan);
|
|
+
|
|
+ /* Record the channel */
|
|
+ channels[c++] = chan;
|
|
+ }
|
|
+ return c;
|
|
+}
|
|
+EXPORT_SYMBOL(__ppp_hold_channels);
|
|
+
|
|
+/* ppp_release_channels()
|
|
+ * Releases channels
|
|
+ */
|
|
+void ppp_release_channels(struct ppp_channel *channels[], unsigned int chan_sz)
|
|
+{
|
|
+ unsigned int c;
|
|
+
|
|
+ for (c = 0; c < chan_sz; ++c) {
|
|
+ struct ppp_channel *chan;
|
|
+
|
|
+ chan = channels[c];
|
|
+ chan->ops->release(chan);
|
|
+ }
|
|
+}
|
|
+EXPORT_SYMBOL(ppp_release_channels);
|
|
+
|
|
+/* Check if ppp xmit lock is on hold */
|
|
+bool ppp_is_xmit_locked(struct net_device *dev)
|
|
+{
|
|
+ struct ppp *ppp;
|
|
+
|
|
+ if (!dev)
|
|
+ return false;
|
|
+
|
|
+ if (dev->type != ARPHRD_PPP)
|
|
+ return false;
|
|
+
|
|
+ ppp = netdev_priv(dev);
|
|
+ if (!ppp)
|
|
+ return false;
|
|
+
|
|
+ if (spin_is_locked(&(ppp)->wlock))
|
|
+ return true;
|
|
+
|
|
+ return false;
|
|
+}
|
|
+EXPORT_SYMBOL(ppp_is_xmit_locked);
|
|
+
|
|
/* Module/initialization stuff */
|
|
|
|
module_init(ppp_init);
|
|
@@ -3614,11 +4032,14 @@ EXPORT_SYMBOL(ppp_unregister_channel);
|
|
EXPORT_SYMBOL(ppp_channel_index);
|
|
EXPORT_SYMBOL(ppp_unit_number);
|
|
EXPORT_SYMBOL(ppp_dev_name);
|
|
+EXPORT_SYMBOL(ppp_dev_index);
|
|
EXPORT_SYMBOL(ppp_input);
|
|
EXPORT_SYMBOL(ppp_input_error);
|
|
EXPORT_SYMBOL(ppp_output_wakeup);
|
|
EXPORT_SYMBOL(ppp_register_compressor);
|
|
EXPORT_SYMBOL(ppp_unregister_compressor);
|
|
+EXPORT_SYMBOL(ppp_update_stats);
|
|
+
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS_CHARDEV(PPP_MAJOR, 0);
|
|
MODULE_ALIAS_RTNL_LINK("ppp");
|
|
--- a/drivers/net/ppp/pppoe.c
|
|
+++ b/drivers/net/ppp/pppoe.c
|
|
@@ -62,6 +62,7 @@
|
|
#include <linux/inetdevice.h>
|
|
#include <linux/etherdevice.h>
|
|
#include <linux/skbuff.h>
|
|
+#include <linux/if_arp.h>
|
|
#include <linux/init.h>
|
|
#include <linux/if_ether.h>
|
|
#include <linux/if_pppox.h>
|
|
@@ -73,6 +74,12 @@
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
|
|
+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
|
|
+#include <linux/netfilter.h>
|
|
+#include <net/netfilter/nf_flow_table.h>
|
|
+#endif
|
|
+
|
|
+
|
|
#include <linux/nsproxy.h>
|
|
#include <net/net_namespace.h>
|
|
#include <net/netns/generic.h>
|
|
@@ -87,7 +94,7 @@
|
|
static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb);
|
|
|
|
static const struct proto_ops pppoe_ops;
|
|
-static const struct ppp_channel_ops pppoe_chan_ops;
|
|
+static const struct pppoe_channel_ops pppoe_chan_ops;
|
|
|
|
/* per-net private data for this module */
|
|
static unsigned int pppoe_net_id __read_mostly;
|
|
@@ -692,7 +699,7 @@ static int pppoe_connect(struct socket *
|
|
|
|
po->chan.mtu = dev->mtu - sizeof(struct pppoe_hdr) - 2;
|
|
po->chan.private = sk;
|
|
- po->chan.ops = &pppoe_chan_ops;
|
|
+ po->chan.ops = (struct ppp_channel_ops *)&pppoe_chan_ops;
|
|
|
|
error = ppp_register_net_channel(dev_net(dev), &po->chan);
|
|
if (error) {
|
|
@@ -972,9 +979,9 @@ static int pppoe_xmit(struct ppp_channel
|
|
return __pppoe_xmit(sk, skb);
|
|
}
|
|
|
|
-static int pppoe_fill_forward_path(struct net_device_path_ctx *ctx,
|
|
- struct net_device_path *path,
|
|
- const struct ppp_channel *chan)
|
|
+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
|
|
+static int pppoe_flow_offload_check(struct ppp_channel *chan,
|
|
+ struct flow_offload_hw_path *path)
|
|
{
|
|
struct sock *sk = chan->private;
|
|
struct pppox_sock *po = pppox_sk(sk);
|
|
@@ -982,22 +989,97 @@ static int pppoe_fill_forward_path(struc
|
|
|
|
if (sock_flag(sk, SOCK_DEAD) ||
|
|
!(sk->sk_state & PPPOX_CONNECTED) || !dev)
|
|
- return -1;
|
|
+ return -ENODEV;
|
|
|
|
- path->type = DEV_PATH_PPPOE;
|
|
- path->encap.proto = htons(ETH_P_PPP_SES);
|
|
- path->encap.id = be16_to_cpu(po->num);
|
|
- memcpy(path->encap.h_dest, po->pppoe_pa.remote, ETH_ALEN);
|
|
- memcpy(ctx->daddr, po->pppoe_pa.remote, ETH_ALEN);
|
|
- path->dev = ctx->dev;
|
|
- ctx->dev = dev;
|
|
+ path->dev = po->pppoe_dev;
|
|
+ path->flags |= FLOW_OFFLOAD_PATH_PPPOE;
|
|
+ memcpy(path->eth_src, po->pppoe_dev->dev_addr, ETH_ALEN);
|
|
+ memcpy(path->eth_dest, po->pppoe_pa.remote, ETH_ALEN);
|
|
+ path->pppoe_sid = be16_to_cpu(po->num);
|
|
+
|
|
+ if (path->dev->netdev_ops->ndo_flow_offload_check)
|
|
+ return path->dev->netdev_ops->ndo_flow_offload_check(path);
|
|
|
|
return 0;
|
|
}
|
|
+#endif /* CONFIG_NF_FLOW_TABLE */
|
|
+
|
|
+/************************************************************************
|
|
+ *
|
|
+ * function called by generic PPP driver to hold channel
|
|
+ *
|
|
+ ***********************************************************************/
|
|
+static void pppoe_hold_chan(struct ppp_channel *chan)
|
|
+{
|
|
+ struct sock *sk = (struct sock *)chan->private;
|
|
+
|
|
+ sock_hold(sk);
|
|
+}
|
|
+
|
|
+/************************************************************************
|
|
+ *
|
|
+ * function called by generic PPP driver to release channel
|
|
+ *
|
|
+ ***********************************************************************/
|
|
+static void pppoe_release_chan(struct ppp_channel *chan)
|
|
+{
|
|
+ struct sock *sk = (struct sock *)chan->private;
|
|
+
|
|
+ sock_put(sk);
|
|
+}
|
|
+
|
|
+/************************************************************************
|
|
+ *
|
|
+ * function called to get the channel protocol type
|
|
+ *
|
|
+ ***********************************************************************/
|
|
+static int pppoe_get_channel_protocol(struct ppp_channel *chan)
|
|
+{
|
|
+ return PX_PROTO_OE;
|
|
+}
|
|
+
|
|
+/************************************************************************
|
|
+ *
|
|
+ * function called to get the PPPoE channel addressing
|
|
+ * NOTE: This function returns a HOLD to the netdevice
|
|
+ *
|
|
+ ***********************************************************************/
|
|
+static int pppoe_get_addressing(struct ppp_channel *chan,
|
|
+ struct pppoe_opt *addressing)
|
|
+{
|
|
+ struct sock *sk = (struct sock *)chan->private;
|
|
+ struct pppox_sock *po = pppox_sk(sk);
|
|
+ int err = 0;
|
|
+
|
|
+ *addressing = po->proto.pppoe;
|
|
+ if (!addressing->dev)
|
|
+ return -ENODEV;
|
|
+
|
|
+ dev_hold(addressing->dev);
|
|
+ return err;
|
|
+}
|
|
|
|
-static const struct ppp_channel_ops pppoe_chan_ops = {
|
|
- .start_xmit = pppoe_xmit,
|
|
- .fill_forward_path = pppoe_fill_forward_path,
|
|
+/* pppoe_channel_addressing_get()
|
|
+ * Return PPPoE channel specific addressing information.
|
|
+ */
|
|
+int pppoe_channel_addressing_get(struct ppp_channel *chan,
|
|
+ struct pppoe_opt *addressing)
|
|
+{
|
|
+ return pppoe_get_addressing(chan, addressing);
|
|
+}
|
|
+EXPORT_SYMBOL(pppoe_channel_addressing_get);
|
|
+
|
|
+static const struct pppoe_channel_ops pppoe_chan_ops = {
|
|
+ /* PPPoE specific channel ops */
|
|
+ .get_addressing = pppoe_get_addressing,
|
|
+ /* General ppp channel ops */
|
|
+ .ops.start_xmit = pppoe_xmit,
|
|
+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
|
|
+ .ops.flow_offload_check = pppoe_flow_offload_check,
|
|
+#endif
|
|
+ .ops.get_channel_protocol = pppoe_get_channel_protocol,
|
|
+ .ops.hold = pppoe_hold_chan,
|
|
+ .ops.release = pppoe_release_chan,
|
|
};
|
|
|
|
static int pppoe_recvmsg(struct socket *sock, struct msghdr *m,
|
|
--- a/drivers/net/ppp/pptp.c
|
|
+++ b/drivers/net/ppp/pptp.c
|
|
@@ -50,6 +50,8 @@ static struct proto pptp_sk_proto __read
|
|
static const struct ppp_channel_ops pptp_chan_ops;
|
|
static const struct proto_ops pptp_ops;
|
|
|
|
+static pptp_gre_seq_offload_callback_t __rcu pptp_gre_offload_xmit_cb;
|
|
+
|
|
static struct pppox_sock *lookup_chan(u16 call_id, __be32 s_addr)
|
|
{
|
|
struct pppox_sock *sock;
|
|
@@ -91,6 +93,79 @@ static int lookup_chan_dst(u16 call_id,
|
|
return i < MAX_CALLID;
|
|
}
|
|
|
|
+/* Search a pptp session based on local call id, local and remote ip address */
|
|
+static int lookup_session_src(struct pptp_opt *opt, u16 call_id, __be32 daddr, __be32 saddr)
|
|
+{
|
|
+ struct pppox_sock *sock;
|
|
+ int i = 1;
|
|
+
|
|
+ rcu_read_lock();
|
|
+ for_each_set_bit_from(i, callid_bitmap, MAX_CALLID) {
|
|
+ sock = rcu_dereference(callid_sock[i]);
|
|
+ if (!sock)
|
|
+ continue;
|
|
+
|
|
+ if (sock->proto.pptp.src_addr.call_id == call_id &&
|
|
+ sock->proto.pptp.dst_addr.sin_addr.s_addr == daddr &&
|
|
+ sock->proto.pptp.src_addr.sin_addr.s_addr == saddr) {
|
|
+ sock_hold(sk_pppox(sock));
|
|
+ memcpy(opt, &sock->proto.pptp, sizeof(struct pptp_opt));
|
|
+ sock_put(sk_pppox(sock));
|
|
+ rcu_read_unlock();
|
|
+ return 0;
|
|
+ }
|
|
+ }
|
|
+ rcu_read_unlock();
|
|
+ return -EINVAL;
|
|
+}
|
|
+
|
|
+/* Search a pptp session based on peer call id and peer ip address */
|
|
+static int lookup_session_dst(struct pptp_opt *opt, u16 call_id, __be32 d_addr)
|
|
+{
|
|
+ struct pppox_sock *sock;
|
|
+ int i = 1;
|
|
+
|
|
+ rcu_read_lock();
|
|
+ for_each_set_bit_from(i, callid_bitmap, MAX_CALLID) {
|
|
+ sock = rcu_dereference(callid_sock[i]);
|
|
+ if (!sock)
|
|
+ continue;
|
|
+
|
|
+ if (sock->proto.pptp.dst_addr.call_id == call_id &&
|
|
+ sock->proto.pptp.dst_addr.sin_addr.s_addr == d_addr) {
|
|
+ sock_hold(sk_pppox(sock));
|
|
+ memcpy(opt, &sock->proto.pptp, sizeof(struct pptp_opt));
|
|
+ sock_put(sk_pppox(sock));
|
|
+ rcu_read_unlock();
|
|
+ return 0;
|
|
+ }
|
|
+ }
|
|
+ rcu_read_unlock();
|
|
+ return -EINVAL;
|
|
+}
|
|
+
|
|
+/* If offload mode set then this function sends all packets to
|
|
+ * offload module instead of network stack
|
|
+ */
|
|
+static int pptp_client_skb_xmit(struct sk_buff *skb,
|
|
+ struct net_device *pptp_dev)
|
|
+{
|
|
+ pptp_gre_seq_offload_callback_t pptp_gre_offload_cb_f;
|
|
+ int ret;
|
|
+
|
|
+ rcu_read_lock();
|
|
+ pptp_gre_offload_cb_f = rcu_dereference(pptp_gre_offload_xmit_cb);
|
|
+
|
|
+ if (!pptp_gre_offload_cb_f) {
|
|
+ rcu_read_unlock();
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ ret = pptp_gre_offload_cb_f(skb, pptp_dev);
|
|
+ rcu_read_unlock();
|
|
+ return ret;
|
|
+}
|
|
+
|
|
static int add_chan(struct pppox_sock *sock,
|
|
struct pptp_addr *sa)
|
|
{
|
|
@@ -163,8 +238,11 @@ static int pptp_xmit(struct ppp_channel
|
|
|
|
struct rtable *rt;
|
|
struct net_device *tdev;
|
|
+ struct net_device *pptp_dev;
|
|
struct iphdr *iph;
|
|
int max_headroom;
|
|
+ int pptp_ifindex;
|
|
+ int ret;
|
|
|
|
if (sk_pppox(po)->sk_state & PPPOX_DEAD)
|
|
goto tx_error;
|
|
@@ -258,9 +336,33 @@ static int pptp_xmit(struct ppp_channel
|
|
ip_select_ident(net, skb, NULL);
|
|
ip_send_check(iph);
|
|
|
|
- ip_local_out(net, skb->sk, skb);
|
|
- return 1;
|
|
+ pptp_ifindex = ppp_dev_index(chan);
|
|
+
|
|
+ /* set incoming interface as the ppp interface */
|
|
+ if (skb->skb_iif)
|
|
+ skb->skb_iif = pptp_ifindex;
|
|
+
|
|
+ /* If the PPTP GRE seq number offload module is not enabled yet
|
|
+ * then sends all PPTP GRE packets through linux network stack
|
|
+ */
|
|
+ if (!opt->pptp_offload_mode) {
|
|
+ ip_local_out(net, skb->sk, skb);
|
|
+ return 1;
|
|
+ }
|
|
+
|
|
+ pptp_dev = dev_get_by_index(&init_net, pptp_ifindex);
|
|
+ if (!pptp_dev)
|
|
+ goto tx_error;
|
|
+
|
|
+ /* If PPTP offload module is enabled then forward all PPTP GRE
|
|
+ * packets to PPTP GRE offload module
|
|
+ */
|
|
+ ret = pptp_client_skb_xmit(skb, pptp_dev);
|
|
+ dev_put(pptp_dev);
|
|
+ if (ret < 0)
|
|
+ goto tx_error;
|
|
|
|
+ return 1;
|
|
tx_error:
|
|
kfree_skb(skb);
|
|
return 1;
|
|
@@ -314,6 +416,13 @@ static int pptp_rcv_core(struct sock *sk
|
|
goto drop;
|
|
|
|
payload = skb->data + headersize;
|
|
+
|
|
+ /* If offload is enabled, we expect the offload module
|
|
+ * to handle PPTP GRE sequence number checks
|
|
+ */
|
|
+ if (opt->pptp_offload_mode)
|
|
+ goto allow_packet;
|
|
+
|
|
/* check for expected sequence number */
|
|
if (seq < opt->seq_recv + 1 || WRAPPED(opt->seq_recv, seq)) {
|
|
if ((payload[0] == PPP_ALLSTATIONS) && (payload[1] == PPP_UI) &&
|
|
@@ -371,6 +480,7 @@ static int pptp_rcv(struct sk_buff *skb)
|
|
if (po) {
|
|
skb_dst_drop(skb);
|
|
nf_reset_ct(skb);
|
|
+ skb->skb_iif = ppp_dev_index(&po->chan);
|
|
return sk_receive_skb(sk_pppox(po), skb, 0);
|
|
}
|
|
drop:
|
|
@@ -473,7 +583,7 @@ static int pptp_connect(struct socket *s
|
|
|
|
opt->dst_addr = sp->sa_addr.pptp;
|
|
sk->sk_state |= PPPOX_CONNECTED;
|
|
-
|
|
+ opt->pptp_offload_mode = false;
|
|
end:
|
|
release_sock(sk);
|
|
return error;
|
|
@@ -603,9 +713,169 @@ static int pptp_ppp_ioctl(struct ppp_cha
|
|
return err;
|
|
}
|
|
|
|
+/* pptp_channel_addressing_get()
|
|
+ * Return PPTP channel specific addressing information.
|
|
+ */
|
|
+void pptp_channel_addressing_get(struct pptp_opt *opt, struct ppp_channel *chan)
|
|
+{
|
|
+ struct sock *sk;
|
|
+ struct pppox_sock *po;
|
|
+
|
|
+ if (!opt)
|
|
+ return;
|
|
+
|
|
+ sk = (struct sock *)chan->private;
|
|
+ if (!sk)
|
|
+ return;
|
|
+
|
|
+ sock_hold(sk);
|
|
+
|
|
+ /* This is very unlikely, but check the socket is connected state */
|
|
+ if (unlikely(sock_flag(sk, SOCK_DEAD) ||
|
|
+ !(sk->sk_state & PPPOX_CONNECTED))) {
|
|
+ sock_put(sk);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ po = pppox_sk(sk);
|
|
+ memcpy(opt, &po->proto.pptp, sizeof(struct pptp_opt));
|
|
+ sock_put(sk);
|
|
+}
|
|
+EXPORT_SYMBOL(pptp_channel_addressing_get);
|
|
+
|
|
+/* pptp_session_find()
|
|
+ * Search and return a PPTP session info based on peer callid and IP
|
|
+ * address. The function accepts the parameters in network byte order.
|
|
+ */
|
|
+int pptp_session_find(struct pptp_opt *opt, __be16 peer_call_id,
|
|
+ __be32 peer_ip_addr)
|
|
+{
|
|
+ if (!opt)
|
|
+ return -EINVAL;
|
|
+
|
|
+ return lookup_session_dst(opt, ntohs(peer_call_id), peer_ip_addr);
|
|
+}
|
|
+EXPORT_SYMBOL(pptp_session_find);
|
|
+
|
|
+/* pptp_session_find_by_src_callid()
|
|
+ * Search and return a PPTP session info based on src callid and IP
|
|
+ * address. The function accepts the parameters in network byte order.
|
|
+ */
|
|
+int pptp_session_find_by_src_callid(struct pptp_opt *opt, __be16 src_call_id,
|
|
+ __be32 daddr, __be32 saddr)
|
|
+{
|
|
+ if (!opt)
|
|
+ return -EINVAL;
|
|
+
|
|
+ return lookup_session_src(opt, ntohs(src_call_id), daddr, saddr);
|
|
+}
|
|
+EXPORT_SYMBOL(pptp_session_find_by_src_callid);
|
|
+
|
|
+ /* Function to change the offload mode true/false for a PPTP session */
|
|
+static int pptp_set_offload_mode(bool accel_mode,
|
|
+ __be16 peer_call_id, __be32 peer_ip_addr)
|
|
+{
|
|
+ struct pppox_sock *sock;
|
|
+ int i = 1;
|
|
+
|
|
+ rcu_read_lock();
|
|
+ for_each_set_bit_from(i, callid_bitmap, MAX_CALLID) {
|
|
+ sock = rcu_dereference(callid_sock[i]);
|
|
+ if (!sock)
|
|
+ continue;
|
|
+
|
|
+ if (sock->proto.pptp.dst_addr.call_id == peer_call_id &&
|
|
+ sock->proto.pptp.dst_addr.sin_addr.s_addr == peer_ip_addr) {
|
|
+ sock_hold(sk_pppox(sock));
|
|
+ sock->proto.pptp.pptp_offload_mode = accel_mode;
|
|
+ sock_put(sk_pppox(sock));
|
|
+ rcu_read_unlock();
|
|
+ return 0;
|
|
+ }
|
|
+ }
|
|
+ rcu_read_unlock();
|
|
+ return -EINVAL;
|
|
+}
|
|
+
|
|
+/* Enable the PPTP session offload flag */
|
|
+int pptp_session_enable_offload_mode(__be16 peer_call_id, __be32 peer_ip_addr)
|
|
+{
|
|
+ return pptp_set_offload_mode(true, peer_call_id, peer_ip_addr);
|
|
+}
|
|
+EXPORT_SYMBOL(pptp_session_enable_offload_mode);
|
|
+
|
|
+/* Disable the PPTP session offload flag */
|
|
+int pptp_session_disable_offload_mode(__be16 peer_call_id, __be32 peer_ip_addr)
|
|
+{
|
|
+ return pptp_set_offload_mode(false, peer_call_id, peer_ip_addr);
|
|
+}
|
|
+EXPORT_SYMBOL(pptp_session_disable_offload_mode);
|
|
+
|
|
+/* Register the offload callback function on behalf of the module which
|
|
+ * will own the sequence and acknowledgment number updates for all
|
|
+ * PPTP GRE packets. All PPTP GRE packets are then transmitted to this
|
|
+ * module after encapsulation in order to ensure the correct seq/ack
|
|
+ * fields are set in the packets before transmission. This is required
|
|
+ * when PPTP flows are offloaded to acceleration engines, in-order to
|
|
+ * ensure consistency in sequence and ack numbers between PPTP control
|
|
+ * (PPP LCP) and data packets
|
|
+ */
|
|
+int pptp_register_gre_seq_offload_callback(pptp_gre_seq_offload_callback_t
|
|
+ pptp_gre_offload_cb)
|
|
+{
|
|
+ pptp_gre_seq_offload_callback_t pptp_gre_offload_cb_f;
|
|
+
|
|
+ rcu_read_lock();
|
|
+ pptp_gre_offload_cb_f = rcu_dereference(pptp_gre_offload_xmit_cb);
|
|
+
|
|
+ if (pptp_gre_offload_cb_f) {
|
|
+ rcu_read_unlock();
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ rcu_assign_pointer(pptp_gre_offload_xmit_cb, pptp_gre_offload_cb);
|
|
+ rcu_read_unlock();
|
|
+ return 0;
|
|
+}
|
|
+EXPORT_SYMBOL(pptp_register_gre_seq_offload_callback);
|
|
+
|
|
+/* Unregister the PPTP GRE packets sequence number offload callback */
|
|
+void pptp_unregister_gre_seq_offload_callback(void)
|
|
+{
|
|
+ rcu_assign_pointer(pptp_gre_offload_xmit_cb, NULL);
|
|
+}
|
|
+EXPORT_SYMBOL(pptp_unregister_gre_seq_offload_callback);
|
|
+
|
|
+/* pptp_hold_chan() */
|
|
+static void pptp_hold_chan(struct ppp_channel *chan)
|
|
+{
|
|
+ struct sock *sk = (struct sock *)chan->private;
|
|
+
|
|
+ sock_hold(sk);
|
|
+}
|
|
+
|
|
+/* pptp_release_chan() */
|
|
+static void pptp_release_chan(struct ppp_channel *chan)
|
|
+{
|
|
+ struct sock *sk = (struct sock *)chan->private;
|
|
+
|
|
+ sock_put(sk);
|
|
+}
|
|
+
|
|
+/* pptp_get_channel_protocol()
|
|
+ * Return the protocol type of the PPTP over PPP protocol
|
|
+ */
|
|
+static int pptp_get_channel_protocol(struct ppp_channel *chan)
|
|
+{
|
|
+ return PX_PROTO_PPTP;
|
|
+}
|
|
+
|
|
static const struct ppp_channel_ops pptp_chan_ops = {
|
|
.start_xmit = pptp_xmit,
|
|
.ioctl = pptp_ppp_ioctl,
|
|
+ .get_channel_protocol = pptp_get_channel_protocol,
|
|
+ .hold = pptp_hold_chan,
|
|
+ .release = pptp_release_chan,
|
|
};
|
|
|
|
static struct proto pptp_sk_proto __read_mostly = {
|
|
--- a/include/linux/if_pppol2tp.h
|
|
+++ b/include/linux/if_pppol2tp.h
|
|
@@ -12,4 +12,27 @@
|
|
#include <linux/in6.h>
|
|
#include <uapi/linux/if_pppol2tp.h>
|
|
|
|
+/*
|
|
+ * Holds L2TP channel info
|
|
+ */
|
|
+struct pppol2tp_common_addr {
|
|
+ int tunnel_version; /* v2 or v3 */
|
|
+ __u32 local_tunnel_id, remote_tunnel_id; /* tunnel id */
|
|
+ __u32 local_session_id, remote_session_id; /* session id */
|
|
+ struct sockaddr_in local_addr, remote_addr; /* ip address and port */
|
|
+};
|
|
+
|
|
+/*
|
|
+ * L2TP channel operations
|
|
+ */
|
|
+struct pppol2tp_channel_ops {
|
|
+ struct ppp_channel_ops ops; /* ppp channel ops */
|
|
+};
|
|
+
|
|
+/*
|
|
+ * exported function which calls pppol2tp channel's get addressing
|
|
+ * function
|
|
+ */
|
|
+extern int pppol2tp_channel_addressing_get(struct ppp_channel *,
|
|
+ struct pppol2tp_common_addr *);
|
|
#endif
|
|
--- a/include/linux/if_pppox.h
|
|
+++ b/include/linux/if_pppox.h
|
|
@@ -36,6 +36,7 @@ struct pptp_opt {
|
|
u32 ack_sent, ack_recv;
|
|
u32 seq_sent, seq_recv;
|
|
int ppp_flags;
|
|
+ bool pptp_offload_mode;
|
|
};
|
|
#include <net/sock.h>
|
|
|
|
@@ -91,4 +92,49 @@ enum {
|
|
PPPOX_DEAD = 16 /* dead, useless, please clean me up!*/
|
|
};
|
|
|
|
+/*
|
|
+ * PPPoE Channel specific operations
|
|
+ */
|
|
+struct pppoe_channel_ops {
|
|
+ /* Must be first - general to all PPP channels */
|
|
+ struct ppp_channel_ops ops;
|
|
+ int (*get_addressing)(struct ppp_channel *, struct pppoe_opt *);
|
|
+};
|
|
+
|
|
+/* PPTP client callback */
|
|
+typedef int (*pptp_gre_seq_offload_callback_t)(struct sk_buff *skb,
|
|
+ struct net_device *pptp_dev);
|
|
+
|
|
+/* Return PPPoE channel specific addressing information */
|
|
+extern int pppoe_channel_addressing_get(struct ppp_channel *chan,
|
|
+ struct pppoe_opt *addressing);
|
|
+
|
|
+/* Lookup PPTP session info and return PPTP session using sip, dip and local call id */
|
|
+extern int pptp_session_find_by_src_callid(struct pptp_opt *opt, __be16 src_call_id,
|
|
+ __be32 daddr, __be32 saddr);
|
|
+
|
|
+/* Lookup PPTP session info and return PPTP session using dip and peer call id */
|
|
+extern int pptp_session_find(struct pptp_opt *opt, __be16 peer_call_id,
|
|
+ __be32 peer_ip_addr);
|
|
+
|
|
+/* Return PPTP session information given the channel */
|
|
+extern void pptp_channel_addressing_get(struct pptp_opt *opt,
|
|
+ struct ppp_channel *chan);
|
|
+
|
|
+/* Enable the PPTP session offload flag */
|
|
+extern int pptp_session_enable_offload_mode(__be16 peer_call_id,
|
|
+ __be32 peer_ip_addr);
|
|
+
|
|
+/* Disable the PPTP session offload flag */
|
|
+extern int pptp_session_disable_offload_mode(__be16 peer_call_id,
|
|
+ __be32 peer_ip_addr);
|
|
+
|
|
+/* Register the PPTP GRE packets sequence number offload callback */
|
|
+extern int
|
|
+pptp_register_gre_seq_offload_callback(pptp_gre_seq_offload_callback_t
|
|
+ pptp_client_cb);
|
|
+
|
|
+/* Unregister the PPTP GRE packets sequence number offload callback */
|
|
+extern void pptp_unregister_gre_seq_offload_callback(void);
|
|
+
|
|
#endif /* !(__LINUX_IF_PPPOX_H) */
|
|
--- a/include/linux/ppp_channel.h
|
|
+++ b/include/linux/ppp_channel.h
|
|
@@ -19,6 +19,12 @@
|
|
#include <linux/skbuff.h>
|
|
#include <linux/poll.h>
|
|
#include <net/net_namespace.h>
|
|
+#include <linux/ppp_defs.h>
|
|
+#include <linux/notifier.h>
|
|
+
|
|
+/* PPP channel connection event types */
|
|
+#define PPP_CHANNEL_DISCONNECT 0
|
|
+#define PPP_CHANNEL_CONNECT 1
|
|
|
|
struct net_device_path;
|
|
struct net_device_path_ctx;
|
|
@@ -30,9 +36,20 @@ struct ppp_channel_ops {
|
|
int (*start_xmit)(struct ppp_channel *, struct sk_buff *);
|
|
/* Handle an ioctl call that has come in via /dev/ppp. */
|
|
int (*ioctl)(struct ppp_channel *, unsigned int, unsigned long);
|
|
- int (*fill_forward_path)(struct net_device_path_ctx *,
|
|
- struct net_device_path *,
|
|
- const struct ppp_channel *);
|
|
+
|
|
+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
|
|
+ int (*flow_offload_check)(struct ppp_channel *, struct flow_offload_hw_path *);
|
|
+#endif
|
|
+ /* Get channel protocol type, one of PX_PROTO_XYZ or specific to
|
|
+ * the channel subtype
|
|
+ */
|
|
+ int (*get_channel_protocol)(struct ppp_channel *);
|
|
+ /* Get channel protocol version */
|
|
+ int (*get_channel_protocol_ver)(struct ppp_channel *);
|
|
+ /* Hold the channel from being destroyed */
|
|
+ void (*hold)(struct ppp_channel *);
|
|
+ /* Release hold on the channel */
|
|
+ void (*release)(struct ppp_channel *);
|
|
};
|
|
|
|
struct ppp_channel {
|
|
@@ -47,6 +64,54 @@ struct ppp_channel {
|
|
};
|
|
|
|
#ifdef __KERNEL__
|
|
+/* Call this to obtain the underlying protocol of the PPP channel,
|
|
+ * e.g. PX_PROTO_OE
|
|
+ */
|
|
+extern int ppp_channel_get_protocol(struct ppp_channel *);
|
|
+
|
|
+/* Call this get protocol version */
|
|
+extern int ppp_channel_get_proto_version(struct ppp_channel *);
|
|
+
|
|
+/* Call this to hold a channel */
|
|
+extern bool ppp_channel_hold(struct ppp_channel *);
|
|
+
|
|
+/* Call this to release a hold you have upon a channel */
|
|
+extern void ppp_channel_release(struct ppp_channel *);
|
|
+
|
|
+/* Release hold on PPP channels */
|
|
+extern void ppp_release_channels(struct ppp_channel *channels[],
|
|
+ unsigned int chan_sz);
|
|
+
|
|
+/* Hold PPP channels for the PPP device */
|
|
+extern int ppp_hold_channels(struct net_device *dev,
|
|
+ struct ppp_channel *channels[],
|
|
+ unsigned int chan_sz);
|
|
+
|
|
+/* Test if ppp xmit lock is locked */
|
|
+extern bool ppp_is_xmit_locked(struct net_device *dev);
|
|
+
|
|
+/* Hold PPP channels for the PPP device */
|
|
+extern int __ppp_hold_channels(struct net_device *dev,
|
|
+ struct ppp_channel *channels[],
|
|
+ unsigned int chan_sz);
|
|
+
|
|
+bool ppp_is_cp_enabled(struct net_device *dev);
|
|
+
|
|
+/* Test if the ppp device is a multi-link ppp device */
|
|
+extern int ppp_is_multilink(struct net_device *dev);
|
|
+
|
|
+/* Test if the ppp device is a multi-link ppp device */
|
|
+extern int __ppp_is_multilink(struct net_device *dev);
|
|
+
|
|
+/* Update statistics of the PPP net_device by incrementing related
|
|
+ * statistics field value with corresponding parameter
|
|
+ */
|
|
+extern void ppp_update_stats(struct net_device *dev, unsigned long rx_packets,
|
|
+ unsigned long rx_bytes, unsigned long tx_packets,
|
|
+ unsigned long tx_bytes, unsigned long rx_errors,
|
|
+ unsigned long tx_errors, unsigned long rx_dropped,
|
|
+ unsigned long tx_dropped);
|
|
+
|
|
/* Called by the channel when it can send some more data. */
|
|
extern void ppp_output_wakeup(struct ppp_channel *);
|
|
|
|
@@ -70,12 +135,21 @@ extern void ppp_unregister_channel(struc
|
|
/* Get the channel number for a channel */
|
|
extern int ppp_channel_index(struct ppp_channel *);
|
|
|
|
+/* Get the device index associated with a channel, or 0, if none */
|
|
+extern int ppp_dev_index(struct ppp_channel *);
|
|
+
|
|
/* Get the unit number associated with a channel, or -1 if none */
|
|
extern int ppp_unit_number(struct ppp_channel *);
|
|
|
|
/* Get the device name associated with a channel, or NULL if none */
|
|
extern char *ppp_dev_name(struct ppp_channel *);
|
|
|
|
+/* Register the PPP channel connect notifier */
|
|
+extern void ppp_channel_connection_register_notify(struct notifier_block *nb);
|
|
+
|
|
+/* Unregister the PPP channel connect notifier */
|
|
+extern void ppp_channel_connection_unregister_notify(struct notifier_block *nb);
|
|
+
|
|
/*
|
|
* SMP locking notes:
|
|
* The channel code must ensure that when it calls ppp_unregister_channel,
|
|
--- a/include/linux/netdevice.h
|
|
+++ b/include/linux/netdevice.h
|
|
@@ -1073,6 +1073,20 @@ struct dev_ifalias {
|
|
struct devlink;
|
|
struct tlsdev_ops;
|
|
|
|
+struct flow_offload;
|
|
+struct flow_offload_hw_path;
|
|
+
|
|
+enum flow_offload_type {
|
|
+ FLOW_OFFLOAD_ADD = 0,
|
|
+ FLOW_OFFLOAD_DEL,
|
|
+};
|
|
+
|
|
+enum nss_flow_offload_type {
|
|
+ NF_FLOW_OFFLOAD_UNSPEC = 0,
|
|
+ NF_FLOW_OFFLOAD_ROUTE,
|
|
+};
|
|
+
|
|
+
|
|
struct netdev_net_notifier {
|
|
struct list_head list;
|
|
struct notifier_block *nb;
|
|
@@ -1626,6 +1640,12 @@ struct net_device_ops {
|
|
int (*ndo_bridge_dellink)(struct net_device *dev,
|
|
struct nlmsghdr *nlh,
|
|
u16 flags);
|
|
+ int (*ndo_flow_offload_check)(struct flow_offload_hw_path *path);
|
|
+ int (*ndo_flow_offload)(enum nss_flow_offload_type type,
|
|
+ struct flow_offload *flow,
|
|
+ struct flow_offload_hw_path *src,
|
|
+ struct flow_offload_hw_path *dest);
|
|
+
|
|
int (*ndo_change_carrier)(struct net_device *dev,
|
|
bool new_carrier);
|
|
int (*ndo_get_phys_port_id)(struct net_device *dev,
|
|
--- a/include/net/netfilter/nf_flow_table.h
|
|
+++ b/include/net/netfilter/nf_flow_table.h
|
|
@@ -171,10 +171,14 @@ enum nf_flow_flags {
|
|
NF_FLOW_HW_ESTABLISHED,
|
|
};
|
|
|
|
-enum flow_offload_type {
|
|
- NF_FLOW_OFFLOAD_UNSPEC = 0,
|
|
- NF_FLOW_OFFLOAD_ROUTE,
|
|
-};
|
|
+
|
|
+#define FLOW_OFFLOAD_SNAT 0x1
|
|
+#define FLOW_OFFLOAD_DNAT 0x2
|
|
+#define FLOW_OFFLOAD_DYING 0x4
|
|
+#define FLOW_OFFLOAD_TEARDOWN 0x8
|
|
+#define FLOW_OFFLOAD_HW 0x10
|
|
+#define FLOW_OFFLOAD_KEEP 0x20
|
|
+
|
|
|
|
struct flow_offload {
|
|
struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX];
|
|
@@ -185,6 +189,25 @@ struct flow_offload {
|
|
struct rcu_head rcu_head;
|
|
};
|
|
|
|
+
|
|
+#define FLOW_OFFLOAD_PATH_ETHERNET BIT(0)
|
|
+#define FLOW_OFFLOAD_PATH_VLAN BIT(1)
|
|
+#define FLOW_OFFLOAD_PATH_PPPOE BIT(2)
|
|
+#define FLOW_OFFLOAD_PATH_DSA BIT(3)
|
|
+
|
|
+struct flow_offload_hw_path {
|
|
+ struct net_device *dev;
|
|
+ u32 flags;
|
|
+
|
|
+ u8 eth_src[ETH_ALEN];
|
|
+ u8 eth_dest[ETH_ALEN];
|
|
+ u16 vlan_proto;
|
|
+ u16 vlan_id;
|
|
+ u16 pppoe_sid;
|
|
+ u16 dsa_port;
|
|
+};
|
|
+
|
|
+
|
|
#define NF_FLOW_TIMEOUT (30 * HZ)
|
|
#define nf_flowtable_time_stamp (u32)jiffies
|
|
|
|
--- a/net/l2tp/l2tp_core.c
|
|
+++ b/net/l2tp/l2tp_core.c
|
|
@@ -403,6 +403,30 @@ err_tlock:
|
|
}
|
|
EXPORT_SYMBOL_GPL(l2tp_session_register);
|
|
|
|
+void l2tp_stats_update(struct l2tp_tunnel *tunnel,
|
|
+ struct l2tp_session *session,
|
|
+ struct l2tp_stats *stats)
|
|
+{
|
|
+ atomic_long_add(atomic_long_read(&stats->rx_packets),
|
|
+ &tunnel->stats.rx_packets);
|
|
+ atomic_long_add(atomic_long_read(&stats->rx_bytes),
|
|
+ &tunnel->stats.rx_bytes);
|
|
+ atomic_long_add(atomic_long_read(&stats->tx_packets),
|
|
+ &tunnel->stats.tx_packets);
|
|
+ atomic_long_add(atomic_long_read(&stats->tx_bytes),
|
|
+ &tunnel->stats.tx_bytes);
|
|
+
|
|
+ atomic_long_add(atomic_long_read(&stats->rx_packets),
|
|
+ &session->stats.rx_packets);
|
|
+ atomic_long_add(atomic_long_read(&stats->rx_bytes),
|
|
+ &session->stats.rx_bytes);
|
|
+ atomic_long_add(atomic_long_read(&stats->tx_packets),
|
|
+ &session->stats.tx_packets);
|
|
+ atomic_long_add(atomic_long_read(&stats->tx_bytes),
|
|
+ &session->stats.tx_bytes);
|
|
+}
|
|
+EXPORT_SYMBOL_GPL(l2tp_stats_update);
|
|
+
|
|
/*****************************************************************************
|
|
* Receive data handling
|
|
*****************************************************************************/
|
|
--- a/net/l2tp/l2tp_core.h
|
|
+++ b/net/l2tp/l2tp_core.h
|
|
@@ -231,6 +231,8 @@ struct l2tp_session *l2tp_session_get(co
|
|
struct l2tp_session *l2tp_session_get_nth(struct l2tp_tunnel *tunnel, int nth);
|
|
struct l2tp_session *l2tp_session_get_by_ifname(const struct net *net,
|
|
const char *ifname);
|
|
+void l2tp_stats_update(struct l2tp_tunnel *tunnel, struct l2tp_session *session,
|
|
+ struct l2tp_stats *stats);
|
|
|
|
/* Tunnel and session lifetime management.
|
|
* Creation of a new instance is a two-step process: create, then register.
|