📄 linux-kernel.diff
字号:
+ */+int shim_rta_blk_cmp(struct rtshim *a, struct shim_blk *b)+{+ int n = 0;+ if (a && b) {+ if (!(n = strncmp(a->name, b->shim->name, SHIMNAMSIZ)))+ n = memcmp(a->data, b->data, a->datalen);+ } else {+ if (a) n = 1;+ if (b) n = -1;+ }+ return n;+}++/**+ * shim_blk_cmp - compare two active shim blks+ * @a: shim blk+ * @b: shim blk+ *+ * Used for comparing two existing shim blks+ */+int shim_blk_cmp(struct shim_blk *a, struct shim_blk *b)+{+ int n = 0;+ if (a && b) {+ if (!(n = strncmp(a->shim->name, b->shim->name, SHIMNAMSIZ)))+ n = memcmp(a->data, b->data, a->datalen);+ } else {+ if (a) n = 1;+ if (b) n = -1;+ }+ return n;+}++void __init shim_init(void)+{+ printk("NET: shim interface - <jleu@mindspring.com>\n");+ INIT_LIST_HEAD(&shim_proto_list);+}++EXPORT_SYMBOL(shim_proto_add);+EXPORT_SYMBOL(shim_proto_remove);+EXPORT_SYMBOL(shim_build_blk);+EXPORT_SYMBOL(shim_destroy_blk);+EXPORT_SYMBOL(shim_proto_lock);+EXPORT_SYMBOL(shim_proto_list);diff -uNr linux-kernel/net/core/shim_procfs.c mpls-kernel-3/net/core/shim_procfs.c--- linux-kernel/net/core/shim_procfs.c 1969-12-31 18:00:00.000000000 -0600+++ mpls-kernel-3/net/core/shim_procfs.c 2005-11-11 12:19:10.000000000 -0600@@ -0,0 +1,170 @@+/*+ * 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>++extern spinlock_t shim_proto_lock;+extern struct list_head shim_proto_list;++/*+ * MODULE Information and attributes+ */++MODULE_AUTHOR("James R. Leu <jleu@mindspring.com>");+MODULE_DESCRIPTION("net-shim procfs module");+MODULE_LICENSE("GPL");++/*+ * Proc filesystem directory entries.+ */++/*+ * /proc/net/shim+ */+ +static struct proc_dir_entry *proc_net_shim;++/*+ * Names of the proc directory entry+ */+ +static const char name_shim[] = "shim";++/*+ * The following few functions build the content of /proc/net/shim+ */++/* starting at shim, find the next registered protocol */+static struct shim *shim_skip(struct shim *shim)+{+ struct shim *shim1;+ int next = 0;++ if (!shim)+ next = 1;+ + list_for_each_entry(shim1, &shim_proto_list, list) {+ if (next)+ return shim1;++ if (shim1 == shim)+ next = 1;+ }++ return NULL;+}++ +/* start read of /proc/net/shim */+static void *shim_seq_start(struct seq_file *seq, loff_t *pos)+{+ struct shim *shim;+ loff_t i = 1;++ spin_lock_bh(&shim_proto_lock);++ if (*pos == 0)+ return SEQ_START_TOKEN;++ for (shim = shim_skip(NULL); shim && i < *pos;+ shim = shim_skip(shim), ++i);+ + return (i == *pos) ? shim : NULL;+}++static void *shim_seq_next(struct seq_file *seq, void *v, loff_t *pos)+{+ ++*pos;+ + return shim_skip((v == SEQ_START_TOKEN)+ ? NULL+ : (struct shim *)v);+}+ +static void shim_seq_stop(struct seq_file *seq, void *v)+{+ spin_unlock_bh(&shim_proto_lock);+}++static int shim_seq_show(struct seq_file *seq, void *v)+{+ struct shim* shim = (struct shim*)v;+ if (v != SEQ_START_TOKEN)+ seq_printf(seq, "%s\t%d\n",+ shim->name ? shim->name : "(none)",+ atomic_read(&shim->__ref));+ return 0;+}++/*+ * Generic /proc/net/shim file and inode operations+ */+ +static struct seq_operations shim_seq_ops = {+ .start = shim_seq_start,+ .next = shim_seq_next,+ .stop = shim_seq_stop,+ .show = shim_seq_show,+};+ +static int shim_seq_open(struct inode *inode, struct file *file)+{+ return seq_open(file, &shim_seq_ops);+}+ +static struct file_operations shim_fops = {+ .owner = THIS_MODULE,+ .open = shim_seq_open,+ .read = seq_read,+ .llseek = seq_lseek,+ .release = seq_release,+};++/*+ * Clean up /proc/net/shim+ */+ +static void __exit shim_proc_cleanup(void)+{+ if (proc_net)+ remove_proc_entry(name_shim, proc_net);+}++/*+ * Create /proc/net/shim+ */++static int __init shim_proc_init(void)+{+ if (proc_net) {+ proc_net_shim = create_proc_entry(name_shim,+ S_IFREG|S_IRUSR|S_IWUSR,+ proc_net);+ if (proc_net_shim) {+ proc_net_shim->proc_fops = &shim_fops;+ return 0;+ }+ return -ENOBUFS;+ }+ return -EINVAL;+}++module_init(shim_proc_init);+module_exit(shim_proc_cleanup);diff -uNr linux-kernel/net/ipv4/fib_semantics.c mpls-kernel-3/net/ipv4/fib_semantics.c--- linux-kernel/net/ipv4/fib_semantics.c 2005-12-05 22:01:03.000000000 -0600+++ mpls-kernel-3/net/ipv4/fib_semantics.c 2005-12-12 21:30:26.000000000 -0600@@ -43,6 +43,7 @@ #include <net/sock.h> #include <net/ip_fib.h> #include <net/ip_mp_alg.h>+#include <net/shim.h> #include "fib_lookup.h" @@ -148,9 +149,12 @@ return; } change_nexthops(fi) {+ if (nh->nh_shim)+ shim_destroy_blk(nh->nh_shim); if (nh->nh_dev) dev_put(nh->nh_dev); nh->nh_dev = NULL;+ nh->nh_shim = NULL; } endfor_nexthops(fi); fib_info_cnt--; kfree(fi);@@ -188,6 +192,7 @@ #ifdef CONFIG_NET_CLS_ROUTE nh->nh_tclassid != onh->nh_tclassid || #endif+ shim_blk_cmp(nh->nh_shim, onh->nh_shim) || ((nh->nh_flags^onh->nh_flags)&~RTNH_F_DEAD)) return -1; onh++;@@ -341,14 +346,20 @@ #ifdef CONFIG_IP_ROUTE_MULTIPATH -static u32 fib_get_attr32(struct rtattr *attr, int attrlen, int type)+static void* fib_get_attr(struct rtattr *attr, int attrlen, int type) { while (RTA_OK(attr,attrlen)) { if (attr->rta_type == type)- return *(u32*)RTA_DATA(attr);+ return RTA_DATA(attr); attr = RTA_NEXT(attr, attrlen); }- return 0;+ return NULL;+}++static u32 fib_get_attr32(struct rtattr *attr, int attrlen, int type)+{+ void *data = fib_get_attr(attr, attrlen, type);+ return data ? *(u32*)data : 0; } static int@@ -385,6 +396,9 @@ #ifdef CONFIG_NET_CLS_ROUTE nh->nh_tclassid = fib_get_attr32(RTNH_DATA(nhp), attrlen, RTA_FLOW); #endif+ nh->nh_shim =+ shim_build_blk(fib_get_attr(RTNH_DATA(nhp),+ attrlen, RTA_SHIM)); } nhp = RTNH_NEXT(nhp); } endfor_nexthops(fi);@@ -407,6 +421,7 @@ if (rta->rta_oif || rta->rta_gw) { if ((!rta->rta_oif || *rta->rta_oif == fi->fib_nh->nh_oif) &&+ (!rta->rta_shim || shim_rta_blk_cmp(rta->rta_shim, fi->fib_nh->nh_shim) == 0) && (!rta->rta_gw || memcmp(rta->rta_gw, &fi->fib_nh->nh_gw, 4) == 0)) return 0; return 1;@@ -435,6 +450,9 @@ if (gw && gw != nh->nh_tclassid) return 1; #endif+ if (shim_rta_blk_cmp(fib_get_attr(RTNH_DATA(nhp),+ attrlen, RTA_SHIM), nh->nh_shim))+ return 1; } nhp = RTNH_NEXT(nhp); } endfor_nexthops(fi);@@ -749,6 +767,8 @@ goto err_inval; if (rta->rta_gw && memcmp(&fi->fib_nh->nh_gw, rta->rta_gw, 4)) goto err_inval;+ if (shim_rta_blk_cmp(rta->rta_shim, fi->fib_nh->nh_shim))+ goto err_inval; #ifdef CONFIG_NET_CLS_ROUTE if (rta->rta_flow && memcmp(&fi->fib_nh->nh_tclassid, rta->rta_flow, 4)) goto err_inval;@@ -770,6 +790,11 @@ #ifdef CONFIG_IP_ROUTE_MULTIPATH nh->nh_weight = 1; #endif+ if (rta->rta_shim) {+ nh->nh_shim = shim_build_blk(rta->rta_shim);+ if (!nh->nh_shim)+ goto err_inval;+ } } #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED@@ -777,7 +802,7 @@ #endif if (fib_props[r->rtm_type].error) {- if (rta->rta_gw || rta->rta_oif || rta->rta_mp)+ if (rta->rta_gw || rta->rta_oif || rta->rta_mp || rta->rta_shim) goto err_inval; goto link_it; }@@ -974,6 +999,12 @@ RTA_PUT(skb, RTA_GATEWAY, 4, &fi->fib_nh->nh_gw); if (fi->fib_nh->nh_oif) RTA_PUT(skb, RTA_OIF, sizeof(int), &fi->fib_nh->nh_oif);+ if (fi->fib_nh->nh_shim) {+ struct rtshim *shim = RTA_DATA(__RTA_PUT(skb, RTA_SHIM,+ sizeof(struct rtshim) ++ fi->fib_nh->nh_shim->datalen));+ shim_unbuild_blk(shim, fi->fib_nh->nh_shim);+ } } #ifdef CONFIG_IP_ROUTE_MULTIPATH if (fi->fib_nhs > 1) {@@ -992,6 +1023,13 @@ nhp->rtnh_ifindex = nh->nh_oif; if (nh->nh_gw) RTA_PUT(skb, RTA_GATEWAY, 4, &nh->nh_gw);+ if (nh->nh_shim) {+ struct rtattr *rta;+ rta = __RTA_PUT(skb, RTA_SHIM,+ sizeof(struct rtshim) ++ nh->nh_shim->datalen);+ shim_unbuild_blk(RTA_DATA(rta), nh->nh_shim);+ } nhp->rtnh_len = skb->tail - (unsigned char*)nhp; } endfor_nexthops(fi); mp_head->rta_type = RTA_MULTIPATH;diff -uNr linux-kernel/net/ipv4/ip_input.c mpls-kernel-3/net/ipv4/ip_input.c--- linux-kernel/net/ipv4/ip_input.c 2005-11-15 21:43:54.000000000 -0600+++ mpls-kernel-3/net/ipv4/ip_input.c 2005-12-06 22:36:05.000000000 -0600@@ -443,3 +443,4 @@ } EXPORT_SYMBOL(ip_statistics);+EXPORT_SYMBOL(ip_rcv);diff -uNr linux-kernel/net/ipv4/ip_output.c mpls-kernel-3/net/ipv4/ip_output.c--- linux-kernel/net/ipv4/ip_output.c 2005-12-05 22:01:03.000000000 -0600+++ mpls-kernel-3/net/ipv4/ip_output.c 2005-12-12 21:30:43.000000000 -0600@@ -167,6 +167,11 @@ struct net_device *dev = dst->dev; int hh_len = LL_RESERVED_SPACE(dev); + if (dst->child) {+ skb->dst = dst_pop(skb->dst);+ return dst_output(skb);+ }+ /* Be paranoid, rather than too clever. */ if (unlikely(skb_headroom(skb) < hh_len && dev->hard_header)) { struct sk_buff *skb2;diff -uNr linux-kernel/net/ipv4/Kconfig mpls-kernel-3/net/ipv4/Kconfig--- linux-kernel/net/ipv4/Kconfig 2005-11-15 21:43:55.000000000 -0600+++ mpls-kernel-3/net/ipv4/Kconfig 2005-11-15 23:18:10.000000000 -0600@@ -231,6 +231,15 @@ operating on your network. Read <file:Documentation/nfsroot.txt> for details. +config IP_MPLS+ tristate "IP: MPLS support"+ depends on INET && MPLS+ ---help---+ If you say Y here, the kernel will support being an ingress and+ egress LER for IPv4 packets++ If unsure, say N.+ # not yet ready.. # bool ' IP: ARP support' CONFIG_IP_PNP_ARP config NET_IPIPdiff -uNr linux-kernel/net/ipv4/Makefile mpls-kernel-3/net/ipv4/Makefile--- linux-kernel/net/ipv4/Makefile 2005-11-15 21:43:55.000000000 -0600+++ mpls-kernel-3/net/ipv4/Makefile 2005-11-15 23:18:10.000000000 -0600@@ -28,6 +28,7 @@ obj-$(CONFIG_IP_ROUTE_MULTIPATH_RANDOM) += multipath_random.o obj-$(CONFIG_IP_ROUTE_MULTIPATH_WRANDOM) += multipath_wrandom.o obj-$(CONFIG_IP_ROUTE_MULTIPATH_DRR) += multipath_drr.o+obj-$(CONFIG_IP_MPLS) += mpls4.o obj-$(CONFIG_NETFILTER) += netfilter/ obj-$(CONFIG_IP_VS) += ipvs/ obj-$(CONFIG_INET_DIAG) += inet_diag.o diff -uNr linux-kernel/net/ipv4/mpls4.c mpls-kernel-3/net/ipv4/mpls4.c--- linux-kernel/net/ipv4/mpls4.c 1969-12-31 18:00:00.000000000 -0600+++ mpls-kernel-3/net/ipv4/mpls4.c 2005-12-18 09:51:01.000000000 -0600@@ -0,0 +1,394 @@+/* mpls4.c: IPv4 MPLS protocol driver.+ *+ * Copyright (C) 2003 David S. Miller (davem@redhat.com)+ *+ * Changes:+ * JLEU: Add ICMP handling+ * Add nexthop printing+ * Change nexthop resolve signature+ * JLEU: Added mpls4_cache_flush()+ * JLEU: un/register reserved labels in fini/init+ * JLEU: removed sysfs print routin+ */++#include <linux/mo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -