📄 linux-kernel.diff
字号:
+ * Helper Functions+ *+ *+ *+ ****************************************************************************/++extern void mpls_skb_dump (struct sk_buff* sk);+extern char mpls_find_payload (struct sk_buff* skb);+extern unsigned int mpls_label2key (const int, const struct mpls_label*);++++/****************************************************************************+ * INCOMING (INPUT) LABELLED PACKET MANAGEMENT+ * net/mpls/mpls_input.c+ *+ *+ *+ ****************************************************************************/++extern int mpls_input_init (void);++extern void mpls_input_exit (void);++extern int mpls_skb_recv (struct sk_buff *skb, struct net_device *dev,+ struct packet_type* ptype);++extern int mpls_skb_recv_mc (struct sk_buff *skb, struct net_device *dev,+ struct packet_type* ptype);+++/****************************************************************************+ * OUTGOING (OUTPUT) LABELLED PACKET MANAGEMENT+ * net/mpls/mpls_output.c+ *+ *+ *+ ****************************************************************************/+++struct mpls_dst {+ union {+ struct dst_entry dst;+ struct mpls_dst *next;+ } u;++ struct sockaddr md_nh;+};++extern int mpls_output_init(void); +extern void mpls_output_exit(void);++extern int mpls_bogus_output(struct sk_buff *skb);+extern int mpls_set_nexthop(struct dst_entry *dst, u32 nh_data, struct spec_nh *spec);+extern int mpls_output(struct sk_buff **pskb); +extern int mpls_switch(struct sk_buff *skb); +extern int mpls_output_shim (struct sk_buff *skb, struct mpls_nhlfe *nhlfe);+extern int mpls_output2(struct sk_buff *skb,struct mpls_nhlfe *nhlfe);++/****************************************************************************+ * MPLS Destination (dst) Next hop (neighbour) cache management+ * net/mpls/mpls_dst.c+ ****************************************************************************/++extern int mpls_dst_init(void);+extern void mpls_dst_exit(void);++extern int +mpls_spec_nh(struct dst_entry *, u32, struct spec_nh *);++extern struct mpls_dst *+mpls_dst_alloc(struct net_device *dev, struct sockaddr *nh);++extern void+mpls_dst_release(struct mpls_dst *);++++/****************************************************************************+ * INPUT/OUTPUT INSTRUCTION OPCODES + * net/mpls/{mpls_opcode,mpls_opcode_in,mpls_opcode_out}.c+ *+ ****************************************************************************/+ +/*+ * skb: Socket buffer. May be modified [OUT] + * ilm: ILM entry object that owns this opcode. + * nhlfe: NHLF entry to apply. May be modified (e.g. MTU) [OUT] + * data: opcode dependant data. Cast to NHLFEs, DS marks, etc.+ */+#define MPLS_OPCODE_PROTOTYPE(NAME) \+int (NAME) (struct sk_buff** skb,struct mpls_ilm *ilm, \+ struct mpls_nhlfe **nhlfe, void *data) ++/*+ * instr: Instruction array. + * direction: MPLS_IN (ILM) or MPLS_OUT(NHLFE)+ * parent: ILM/NHLFE parent object for opcode.+ * data: opcode dependant data. [OUT]+ * last_able: Nonzero if this can be the last opcode. [OUT]+ * num_push: Number of pushes for this opcode. [OUT] (Incr. by OP_PUSH+ */+#define MPLS_BUILD_OPCODE_PROTOTYPE(NAME) \+int (NAME) (struct mpls_instr_elem *instr, \+ enum mpls_dir direction, void *parent,\+ void **data, int *last_able, int *num_push)++/*+ * instr: Instruction array. + * data: opcode dependant data. [OUT]+ */+#define MPLS_UNBUILD_OPCODE_PROTOTYPE(NAME) \+int (NAME) (struct mpls_instr_elem *instr, void *data)++/*+ * data: opcode dependant data.+ * parent: ILM/NHLFE parent object for opcode.+ * direction: MPLS_IN (ILM) or MPLS_OUT(NHLFE)+ */+#define MPLS_CLEAN_OPCODE_PROTOTYPE(NAME) \+void (NAME) (void *data, void *parent, enum mpls_dir direction)++/*+ * seq: seq_file output stream. + * data: opcode dependant data.+ * direction: MPLS_IN (ILM) or MPLS_OUT(NHLFE)+ */+#define MPLS_PRINT_OPCODE_PROTOTYPE(NAME) \+void (NAME) (struct seq_file *seq, void *data, enum mpls_dir direction)++#define MPLS_IN_OPCODE_PROTOTYPE(NAME) MPLS_OPCODE_PROTOTYPE(NAME) +#define MPLS_OUT_OPCODE_PROTOTYPE(NAME) MPLS_OPCODE_PROTOTYPE(NAME) ++struct mpls_ops {+ MPLS_IN_OPCODE_PROTOTYPE(*in);+ MPLS_OUT_OPCODE_PROTOTYPE(*out);+ MPLS_BUILD_OPCODE_PROTOTYPE(*build);+ MPLS_UNBUILD_OPCODE_PROTOTYPE(*unbuild);+ MPLS_CLEAN_OPCODE_PROTOTYPE(*cleanup);+ MPLS_PRINT_OPCODE_PROTOTYPE(*print);+ int extra;+ char *msg;+};++/* Array holding opcodes */+extern struct mpls_ops mpls_ops[MPLS_OP_MAX];++extern void mpls_finish(struct sk_buff *skb);+extern int mpls_opcode_peek(struct sk_buff *skb);+extern int mpls_push(struct sk_buff **skb, struct mpls_label *label);++/****************************************************************************+ * IOCTL/System Calls Management+ * net/mpls/mpls_ioctl.c+ *+ * (Cf. include/linux/mpls.h for IOCTLS)+ ****************************************************************************/+++/* Query/Update Incoming Labels */+extern int mpls_add_in_label (const struct mpls_in_label_req *in);+extern int mpls_get_in_label (struct mpls_in_label_req *in);+extern int mpls_del_in_label (struct mpls_in_label_req *in);+extern int mpls_set_in_label_proto (struct mpls_in_label_req *in);+extern int mpls_add_reserved_label (int label, struct mpls_ilm* ilm);+extern struct mpls_ilm* mpls_del_reserved_label (int label);++/* Query/Update Outgoing Labels */+extern int mpls_add_out_label (struct mpls_out_label_req *out, int seq,+ int pid);+extern int mpls_get_out_label (struct mpls_out_label_req *out);+extern int mpls_del_out_label (struct mpls_out_label_req *out);+extern int mpls_set_out_label_mtu (struct mpls_out_label_req *out);++/* Query/Update Crossconnects */+extern int mpls_attach_in2out (struct mpls_xconnect_req *req);+extern int mpls_detach_in2out (struct mpls_xconnect_req *req);+extern int mpls_get_in2out (struct mpls_xconnect_req *req);++/* Instruction Management */+extern int mpls_set_in_label_instrs (struct mpls_instr_req *mir);+extern int mpls_set_out_label_instrs (struct mpls_instr_req *mir);+extern int mpls_set_in_instrs (struct mpls_instr_elem *mie, + int length, struct mpls_ilm *ilm);+extern int mpls_set_out_instrs (struct mpls_instr_elem *mie, + int length, struct mpls_nhlfe *nhlfe);++extern void mpls_destroy_out_instrs (struct mpls_nhlfe *nhlfe);+extern void mpls_destroy_in_instrs (struct mpls_ilm *ilm);++/* Query/Update Labelspaces*/+extern int mpls_get_labelspace (struct mpls_labelspace_req *req);+extern int mpls_get_labelspace_by_name (const char *name);+extern int mpls_get_labelspace_by_index (int ifindex);+extern int mpls_set_labelspace (struct mpls_labelspace_req *req);+extern int mpls_set_labelspace_by_name (const char *name, int labelspace);+extern int mpls_set_labelspace_by_index (int ifindex, int labelspace);++/* Netlink event notification */+extern void mpls_ilm_event(int event, struct mpls_ilm *ilm);+extern void mpls_nhlfe_event(int event, struct mpls_nhlfe *nhlfe, int seq, int pid);+extern void mpls_labelspace_event(int event, struct net_device *dev);+extern void mpls_xc_event(int event, struct mpls_ilm *ilm,+ struct mpls_nhlfe *nhlfe);++++/****************************************************************************+ * REFERENCE COUNT MANAGEMENT + ****************************************************************************/++/* Hold */+static inline struct mpls_ilm* mpls_ilm_hold(struct mpls_ilm* ilm)+{+ BUG_ON(!ilm);+ dst_hold (&ilm->u.dst);+ return ilm;+}+++/* Release */+static inline void mpls_ilm_release(struct mpls_ilm* ilm)+{+ BUG_ON(!ilm);+ dst_release(&ilm->u.dst);+}+++/* Hold */+static inline struct mpls_nhlfe* mpls_nhlfe_hold(struct mpls_nhlfe* nhlfe)+{+ BUG_ON(!nhlfe);+ dst_hold (&nhlfe->u.dst);+ return nhlfe;+}++/* Release */+static inline void mpls_nhlfe_release(struct mpls_nhlfe* nhlfe)+{+ BUG_ON(!nhlfe);+ dst_release(&nhlfe->u.dst);+}++/****************************************************************************+ * SYSFS Implementation+ * net/mpls/mpls_sysfs.c+ ****************************************************************************/++extern int mpls_sysfs_init(void);+extern void mpls_sysfs_exit(void);++/****************************************************************************+ * NetLink Implementation + * net/mpls/mpls_netlink.c+ ****************************************************************************/++extern struct rtnetlink_link mpls_rtnetlink_table[];+extern int mpls_netlink_init (void);+extern void mpls_netlink_exit (void);++/****************************************************************************+ * Virtual Intefaces (Tunnel) Management + * (e.g. mpls0, mpls1, TXXethN, etc.)+ * net/mpls/mpls_tunnel.c+ ****************************************************************************/++struct mpls_tunnel_private {+ /* NHLFE Object to apply to this tunnel traffic */+ struct mpls_nhlfe *mtp_nhlfe;+ /* Netdevice for this tunnel */+ struct net_device *mtp_dev;+ /* Next tunnel in list */+ struct mpls_tunnel_private *next;+ /* Netdevice (this tunnel) traffic stats */+ struct net_device_stats stat;+};+++extern struct net_device* mpls_tunnel_get_by_name (const char* name);+extern struct net_device* mpls_tunnel_get (struct mpls_tunnel_req *mt);+extern void mpls_tunnel_put (struct net_device *dev); +extern struct net_device* mpls_tunnel_create (struct mpls_tunnel_req *mt);+extern void mpls_tunnel_destroy (struct mpls_tunnel_req *mt); ++/* Tunnel is a module now +extern void __exit mpls_tunnel_exit_module(void);+extern int __init mpls_tunnel_init_module(void);+*/++/* Casts */+#define _mpls_as_if(PTR) ((struct mpls_interface*)(PTR))+#define _mpls_as_label(PTR) ((struct mpls_label*)(PTR))+#define _mpls_as_ilm(PTR) ((struct mpls_ilm*)(PTR))+#define _mpls_as_nhlfe(PTR) ((struct mpls_nhlfe*)(PTR))+#define _mpls_as_dfi(PTR) ((struct mpls_dsmark_fwd_info*)(PTR))+#define _mpls_as_nfi(PTR) ((struct mpls_nfmark_fwd_info*)(PTR))+#define _mpls_as_efi(PTR) ((struct mpls_exp_fwd_info*)(PTR))+#define _mpls_as_netdev(PTR)((struct net_device*)(PTR))+#define _mpls_as_dst(PTR) ((struct mpls_dst*)(PTR))++#endifdiff -uNr linux-kernel/include/net/spec_nh.h mpls-kernel-1/include/net/spec_nh.h--- linux-kernel/include/net/spec_nh.h 1969-12-31 18:00:00.000000000 -0600+++ mpls-kernel-1/include/net/spec_nh.h 2005-01-05 01:09:39.000000000 -0600@@ -0,0 +1,32 @@+/*+ * SPEC NH Interface for special nexthop handling+ *+ * 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.+ *+ * Authors: James R. Leu <jleu@mindspring.com>+ */+#ifndef _LINUX_SPEC_NH_H+#define _LINUX_SPEC_NH_H++#include <linux/netdevice.h>+#include <linux/skbuff.h>+#include <net/dst.h>+#include <linux/list.h>++struct spec_nh+{+ char *name;+ int (*func)(struct dst_entry *, u32, struct spec_nh *);+ struct list_head list;+ unsigned short type;+};++extern void spec_nh_add(struct spec_nh *spec);+extern void spec_nh_remove(struct spec_nh *spec);+extern struct spec_nh *spec_nh_find(unsigned short proto);+extern void spec_nh_init(void);++#endifdiff -uNr linux-kernel/net/core/dev.c mpls-kernel-1/net/core/dev.c--- linux-kernel/net/core/dev.c 2004-10-22 13:40:44.000000000 -0500+++ mpls-kernel-1/net/core/dev.c 2005-01-05 01:12:17.000000000 -0600@@ -113,6 +113,7 @@ #include <net/iw_handler.h> #endif /* CONFIG_NET_RADIO */ #include <asm/current.h>+#include <net/spec_nh.h> /* This define, if set, will randomly drop a packet when congestion * is more than moderate. It helps fairness in the multi-interface@@ -2752,6 +2753,7 @@ return ret; } #endif /* WIRELESS_EXT */+ return -EINVAL; } }@@ -3289,6 +3291,8 @@ hotcpu_notifier(dev_cpu_callback, 0); dst_init(); dev_mcast_init();+ spec_nh_init();+ rc = 0; out: return rc;diff -uNr linux-kernel/net/core/Makefile mpls-kernel-1/net/core/Makefile--- linux-kernel/net/core/Makefile 2004-10-22 13:40:44.000000000 -0500+++ mpls-kernel-1/net/core/Makefile 2005-01-05 01:10:05.000000000 -0600@@ -7,7 +7,8 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o obj-y += flow.o 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 \+ spec_nh.o obj-$(CONFIG_SYSFS) += net-sysfs.o obj-$(CONFIG_NETFILTER) += netfilter.odiff -uNr linux-kernel/net/core/spec_nh.c mpls-kernel-1/net/core/spec_nh.c--- linux-kernel/net/core/spec_nh.c 1969-12-31 18:00:00.000000000 -0600+++ mpls-kernel-1/net/core/spec_nh.c 2005-01-05 01:10:07.000000000 -0600@@ -0,0 +1,286 @@+/*+ * SPEC NH Interface for special nexthops+ *+ * 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/spec_nh.h>+#include <linux/proc_fs.h>+#include <linux/seq_file.h>++static spinlock_t spec_nh_lock = SPIN_LOCK_UNLOCKED;+static struct list_head spec_nh_base[16]; /* 16 way hashed list */++/**+ * spec_nh_add - add a special nexthop handler+ * @spec: special nexthop declaration+ *+ * Add a special nexthop handler to the networking stack. The+ * passed &spec_nh 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 special nexthop handler (until they process another packet)+ */++void spec_nh_add(struct spec_nh *spec)+{+ int hash;++ spin_lock_bh(&spec_nh_lock);++ hash = ntohs(spec->type) & 15;+ list_add_rcu(&spec->list, &spec_nh_base[hash]);++ spin_unlock_bh(&spec_nh_lock);+}++/**+ * spec_nh_remove - remove a special nexthop handler+ * @spec: special nexthop declaration+ *+ * Remove a special nexthop handler that was previously added to the+ * kernels list of special nexthop handlers by spec_nh_add(). The+ * pass &spec_nh 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -