⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linux-kernel.diff

📁 一个可以实现MPLS实验的linux源代码.你不仅可以实现单层标签的转发,还可以实现2个标签的实验,很好的.
💻 DIFF
📖 第 1 页 / 共 5 页
字号:
+	return 255;+}++static void mplsbr_change_dsfield(struct sk_buff *skb, int ds)+{+	/* 802.1q? */+}++static int mplsbr_get_dsfield(struct sk_buff *skb)+{+	/* 802.1q? */+	return 0;+}++static int mplsbr_ttl_expired(struct sk_buff **skb)+{+	return NET_RX_DROP;+}++static int mplsbr_mtu_exceeded(struct sk_buff **skb, int mtu)+{+	return MPLS_RESULT_DROP;+}++static int mplsbr_local_deliver(struct sk_buff *skb)+{+	return NET_RX_DROP;+}++static int mplsbr_nexthop_resolve(struct neighbour **np,+	struct sockaddr *sock_addr, struct net_device *dev)+{+	struct neighbour *n;+	u32 index = dev->ifindex;++	n = __neigh_lookup_errno(&dumb_tbl, &index, dev);+	if (IS_ERR(n))+		return PTR_ERR(n);++	*np = n;+	return 0;+}++static struct mpls_prot_driver mplsbr_driver = {+	.name			=	"bridge",+	.family                 =       AF_PACKET,+	.ethertype              =       __constant_htons(ETH_P_ALL),+	.cache_flush            =       mplsbr_cache_flush,+	.set_ttl                =       mplsbr_set_ttl,+	.get_ttl                =       mplsbr_get_ttl,+	.change_dsfield         =       mplsbr_change_dsfield,+	.get_dsfield            =       mplsbr_get_dsfield,+	.ttl_expired            =       mplsbr_ttl_expired,+	.mtu_exceeded		=	mplsbr_mtu_exceeded,+	.local_deliver		=	mplsbr_local_deliver,+	.nexthop_resolve        =       mplsbr_nexthop_resolve,+	.owner                  =       THIS_MODULE,+};++static int __init mplsbr_init(void)+{+	printk("MPLS: Ethernet over MPLS support\n");+	neigh_table_init(&dumb_tbl);+	return mpls_proto_add(&mplsbr_driver);+}++static void __exit mplsbr_fini(void)+{+	mpls_proto_remove(&mplsbr_driver);+}++module_init(mplsbr_init);+module_exit(mplsbr_fini);diff -uNr linux-kernel/net/bridge/netfilter/ebt_mpls.c mpls-kernel-3/net/bridge/netfilter/ebt_mpls.c--- linux-kernel/net/bridge/netfilter/ebt_mpls.c	1969-12-31 18:00:00.000000000 -0600+++ mpls-kernel-3/net/bridge/netfilter/ebt_mpls.c	2005-10-21 01:18:57.000000000 -0500@@ -0,0 +1,109 @@+/* This is a module which is used for setting up a SKB to use a mpls. */+#include <linux/module.h>+#include <linux/skbuff.h>+#include <net/mpls.h>+#include <net/sock.h>++#include <linux/netfilter_bridge/ebtables.h>++MODULE_LICENSE("GPL");+MODULE_AUTHOR("James R. Leu <jle@mindspring.com>");+MODULE_DESCRIPTION("ebtables mpls module");++static int target(struct sk_buff **pskb, unsigned int hooknr,+   const struct net_device *in, const struct net_device *out,+   const void *targinfo, unsigned int datalen)+{+	const struct mpls_netfilter_target_info *mpls_info = targinfo;+	struct mpls_nhlfe *nhlfe = mpls_info->nhlfe;+	struct sk_buff *skb = NULL;++	skb = skb_copy(*pskb, GFP_ATOMIC);+	if (skb) {+		if ((*pskb)->sk)+			skb_set_owner_w(skb, (*pskb)->sk);+		/* until we can pass the proto driver via mpls_output_shim+		 * we'll let it look it up for us based on skb->protocol */+		skb->protocol = htons(ETH_P_ALL);++		/* skb->mac.raw is where the L2 header begins, push+		 * the SKB to make skb->data == skb->mac.raw, then+		 * set skb->nh.raw = skb->data, skb->nh.raw is where+		 * we put the MPLS shim+		 */+		skb_push(skb, skb->data - skb->mac.raw);+		skb->nh.raw = skb->data;+		mpls_output_shim(skb, nhlfe);+	}++	/* don't let anyone else use this frame */+	return EBT_DROP;+}++static int checkentry(const char *tablename, unsigned int hookmask,+   const struct ebt_entry *e, void *targinfo, unsigned int targinfosize)+{+	struct mpls_netfilter_target_info *mpls_info = targinfo;++	if (targinfosize+		!= EBT_ALIGN(sizeof(struct mpls_netfilter_target_info))) {+		printk(KERN_WARNING "mpls: targinfosize %u != %Zu\n",+		       targinfosize,+		       EBT_ALIGN(sizeof(struct mpls_netfilter_target_info)));+		return -EINVAL;+	}++	mpls_info->nhlfe = mpls_get_nhlfe(mpls_info->key);+	if (!mpls_info->nhlfe) {+		printk(KERN_WARNING "mpls: unable to find NHLFE with key %x\n",+			mpls_info->key);+		return -EINVAL;+	}++	mpls_info->proto = mpls_proto_find_by_ethertype(htons(ETH_P_ALL));+	if (!mpls_info->proto) {+		printk(KERN_WARNING "mpls: unable to find ETH_P_ALL driver\n");+		return -EINVAL;+	}++	return 0;+}++static void destroy(void *targinfo, unsigned int targinfosize)+{+	struct mpls_netfilter_target_info *mpls_info = targinfo;+	struct mpls_nhlfe *nhlfe = mpls_info->nhlfe;+	struct mpls_prot_driver *prot = mpls_info->proto;++	if (nhlfe) {+		mpls_nhlfe_release(nhlfe);+		mpls_info->nhlfe = NULL;+	}++	if (prot) {+		mpls_proto_release(prot);+		mpls_info->proto = NULL;+	}+}++static struct ebt_target mpls_target =+{+	.name		= "mpls",+	.target		= target,+	.destroy	= destroy,+	.check		= checkentry,+	.me		= THIS_MODULE,+};++static int __init init(void)+{+	return ebt_register_target(&mpls_target);+}++static void __exit fini(void)+{+	ebt_unregister_target(&mpls_target);+}++module_init(init);+module_exit(fini);diff -uNr linux-kernel/net/bridge/netfilter/Kconfig mpls-kernel-3/net/bridge/netfilter/Kconfig--- linux-kernel/net/bridge/netfilter/Kconfig	2005-09-19 22:47:52.000000000 -0500+++ mpls-kernel-3/net/bridge/netfilter/Kconfig	2005-12-06 22:26:57.000000000 -0600@@ -165,6 +165,15 @@  	  To compile it as a module, choose M here.  If unsure, say N. +config BRIDGE_EBT_MPLS+	tristate "ebt: MPLS target support"+	depends on BRIDGE_NF_EBTABLES && MPLS+	help+	  This option adds the ebtables MPLS target which allows for+	  bridging ethernets frame onto a MPLS LSP++	  To compile it as a module, choose M here.  If unsure, say N.+ config BRIDGE_EBT_REDIRECT 	tristate "ebt: redirect target support" 	depends on BRIDGE_NF_EBTABLESdiff -uNr linux-kernel/net/bridge/netfilter/Makefile mpls-kernel-3/net/bridge/netfilter/Makefile--- linux-kernel/net/bridge/netfilter/Makefile	2005-04-21 23:37:07.000000000 -0500+++ mpls-kernel-3/net/bridge/netfilter/Makefile	2005-10-08 23:16:34.000000000 -0500@@ -24,6 +24,7 @@ obj-$(CONFIG_BRIDGE_EBT_ARPREPLY) += ebt_arpreply.o obj-$(CONFIG_BRIDGE_EBT_MARK_T) += ebt_mark.o obj-$(CONFIG_BRIDGE_EBT_DNAT) += ebt_dnat.o+obj-$(CONFIG_BRIDGE_EBT_MPLS) += ebt_mpls.o obj-$(CONFIG_BRIDGE_EBT_REDIRECT) += ebt_redirect.o obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_snat.o diff -uNr linux-kernel/net/core/dev.c mpls-kernel-3/net/core/dev.c--- linux-kernel/net/core/dev.c	2006-01-04 23:44:43.000000000 -0600+++ mpls-kernel-3/net/core/dev.c	2006-01-05 00:14:01.000000000 -0600@@ -114,6 +114,7 @@ #include <net/iw_handler.h> #endif	/* CONFIG_NET_RADIO */ #include <asm/current.h>+#include <net/shim.h>  /*  *	The list of packet types we will receive (as opposed to discard)@@ -3259,6 +3260,8 @@ 	hotcpu_notifier(dev_cpu_callback, 0); 	dst_init(); 	dev_mcast_init();+	shim_init();+ 	rc = 0; out: 	return rc;diff -uNr linux-kernel/net/core/Makefile mpls-kernel-3/net/core/Makefile--- linux-kernel/net/core/Makefile	2005-11-15 21:43:53.000000000 -0600+++ mpls-kernel-3/net/core/Makefile	2005-11-15 23:18:03.000000000 -0600@@ -8,9 +8,11 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o  obj-y		     += dev.o ethtool.o dev_mcast.o dst.o \-			neighbour.o rtnetlink.o utils.o link_watch.o filter.o+			neighbour.o rtnetlink.o utils.o link_watch.o filter.o \+			shim.o  obj-$(CONFIG_XFRM) += flow.o+obj-$(CONFIG_PROC_FS) += shim_procfs.o obj-$(CONFIG_SYSFS) += net-sysfs.o obj-$(CONFIG_NET_DIVERT) += dv.o obj-$(CONFIG_NET_PKTGEN) += pktgen.odiff -uNr linux-kernel/net/core/shim.c mpls-kernel-3/net/core/shim.c--- linux-kernel/net/core/shim.c	1969-12-31 18:00:00.000000000 -0600+++ mpls-kernel-3/net/core/shim.c	2006-02-20 22:23:48.000000000 -0600@@ -0,0 +1,223 @@+/*+ *      Network shim interface for protocols that live below L3 and above L2+ *+ *		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.+ *+ *	Heavily borrowed from dev_remove_pack/dev_add_pack+ *+ *	Authors:	James R. Leu <jleu@mindspring.com>+ */++#include <linux/init.h>+#include <linux/kernel.h>+#include <linux/spinlock.h>+#include <asm/byteorder.h>+#include <linux/list.h>+#include <net/shim.h>+#include <linux/proc_fs.h>+#include <linux/seq_file.h>++spinlock_t shim_proto_lock = SPIN_LOCK_UNLOCKED;+struct list_head shim_proto_list;++/**+ *	shim_proto_add - add a shim protocol handler+ *	@shim: shim declaration+ *+ * 	Add a shim protocol handler to the networking stack.  The+ *	passed &shim is linked into the kernel list and may not be+ *	freed until it has been removed from the kernel list.+ *+ *	This call does not sleep therefore is can not guarantee all+ *	CPU's that are in middle of processing packets will see the+ *	new shim handler (until they process another packet)+ */++void shim_proto_add(struct shim *shim)+{+	spin_lock_bh(&shim_proto_lock);++	atomic_set(&shim->__ref, 1);+	list_add_rcu(&shim->list, &shim_proto_list);++	spin_unlock_bh(&shim_proto_lock);+}++/**+ *	shim_proto_remove - remove a shim protocol handler+ *	@shim: shim declaration+ *+ *	Remove a shim handler that was previously added to the+ *	kernels list of shim handlers by shim_proto_add().  The+ *	pass &shim is removed from the kernels list and can be freed+ *	or reused once this function returns.+ *+ *	This call sleeps to guarantee that no CPU is looking at the+ *	special nexthop handler after return.+ */++int shim_proto_remove(struct shim *shim)+{+	struct shim *shim1;+	int retval = -EPROTONOSUPPORT;++	spin_lock_bh(&shim_proto_lock);++	list_for_each_entry(shim1, &shim_proto_list, list) {+		if (shim == shim1) {+			if (atomic_read(&shim->__ref) != 1) {+				retval = -EADDRINUSE;+			} else {+				list_del_rcu(&shim->list);+				retval = 0;+			}+			break;+		}+	}+	spin_unlock_bh(&shim_proto_lock);++	synchronize_net();+	return retval;+}++/**+ *	shim_proto_find_by_name - find a shim handler by it's registered name+ *	@name: protocol name+ *+ *	Search the kernels list of shim handlers looking for+ *	a handler with this specific name+ */+struct shim *shim_proto_find_by_name(const char *name)+{+	struct shim *shim;++	spin_lock_bh(&shim_proto_lock);++	list_for_each_entry(shim, &shim_proto_list, list) {+		if (!strncmp(name, shim->name, SHIMNAMSIZ)) {+			shim_proto_hold(shim);+			goto out;+		}+	}+	shim = NULL;+out:+	spin_unlock_bh(&shim_proto_lock);++	return shim;+}++/*+ * Shim block utilities+ */++/**+ *	shim_build_blk - allocate memory for a shim blk and fill it with data+ *			 from rta+ *	@rta: data describing shim+ *+ *	Allocate a shim blk which links directly to the shim+ *	proto for use by the forwarding plane+ */+struct shim_blk *shim_build_blk(struct rtshim* rta)+{+	struct shim_blk *sblk;++	if (!rta)+		return NULL;++	sblk = kmalloc(sizeof(*sblk) + rta->datalen, GFP_ATOMIC);+	if (sblk) {+		sblk->shim = shim_proto_find_by_name(rta->name);+		if (sblk->shim) {+			sblk->datalen = rta->datalen;+			memcpy(sblk->data, rta->data, rta->datalen);+			return sblk;+		}+		kfree (sblk);+	}+	return NULL;+}++/**+ *	shim_destroy_blk - free memory a refcnts used bt a shim blk+ *	@sblk: shim blk+ *+ *	Release ref to shim proto and free memory+ */+void shim_destroy_blk(struct shim_blk *sblk)+{+	shim_proto_release(sblk->shim);+	kfree(sblk);+}++/**+ *	shim_unbuild_blk - copy data from various parts of a shim block+ *			   into a form which can be used by netlink+ *	@rta: contigous destination memory of size rtshim + datalen+ *	@sblk: active shim blk+ *+ *	Search the kernels list of shim handlers looking for+ *	a handler with this specific name+ */+void shim_unbuild_blk(struct rtshim* rta, struct shim_blk *sblk)+{+	rta->datalen = sblk->datalen;+	memcpy(rta->data, sblk->data, sblk->datalen);+	strncpy(rta->name, sblk->shim->name, SHIMNAMSIZ);+}++/**+ *	shim_rta_blk_cmp - compare config info with an active shim blk+ *	@rta: config data+ *	@sblk: shim blk+ *+ *	Used for comparing new config data with existing shim blks

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -