📄 linux-kernel.diff
字号:
+ * (c) 2003-2004 Ramon Casellas <casellas@infres.enst.fr>+ *+ * 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.+ *+ * Changes:+ * 20031126 RCAS:+ * - Rewrite the debugging macros.+ * 20040319 JLEU:+ * - switch to gen_stats+ * 20041018 JLEU+ * - added cache_flush to the prot driver+ *****************************************************************************+ */+#ifndef __LINUX_NET_MPLS__H_+#define __LINUX_NET_MPLS__H_++#include <net/shim.h>+#include <net/dst.h>+#include <asm/atomic.h>+#include <linux/init.h>+#include <linux/mpls.h>+#include <linux/netdevice.h>+#include <linux/skbuff.h>+#include <linux/rtnetlink.h>+#include <linux/gen_stats.h>++/* + * Forward declarations+ */++struct fib_result;+struct rtable;++extern int mpls_debug;+extern struct dst_ops mpls_dst_ops;++#define MPLS_ERR KERN_ERR+#define MPLS_INF KERN_ALERT+#define MPLS_DBG KERN_DEBUG++/* Comment this to suppress MPLS_DEBUG calls */+#define MPLS_ENABLE_DEBUG 1++/* Comment this to suppress TRACING enter/exit functions */+#define MPLS_ENABLE_DEBUG_FUNC 1++#ifdef MPLS_ENABLE_DEBUG+#define MPLS_DEBUG(f, a...) \+{ \+ if (mpls_debug) {\+ printk (MPLS_DBG "MPLS DEBUG %s:%d:%s: ", \+ __FILE__, __LINE__, __FUNCTION__); \+ printk (f, ##a); \+ }\+}++#define MPLS_DEBUG_CALL(f) \+{ \+ if (mpls_debug) {\+ f; \+ } \+}+#else+#define MPLS_DEBUG(f, a...) /**/+#define MPLS_DEBUG_CALL(f) /**/+#endif /* MPLS_ENABLE_DEBUG */++#ifdef MPLS_ENABLE_DEBUG_FUNC+#define MPLS_ENTER MPLS_DEBUG("enter\n")+#define MPLS_EXIT MPLS_DEBUG("exit\n")+#else+#define MPLS_ENTER /**/+#define MPLS_EXIT /**/+#endif++#define MPLS_INFO(f, a...) printk (KERN_INFO "MPLS INFO " f, ##a);++#ifdef MPLS_ENABLE_DEBUG +#define MPLS_ASSERT(expr) \+if(unlikely(!(expr))) { \+ printk(KERN_ERR "MPLS Assertion failed! %s,%s,%s,line=%d\n",#expr,\+ __FILE__,__FUNCTION__,__LINE__); \+}+#else+#define MPLS_ASSERT(expr) /**/+#endif /* MPLS_ENABLE_DEBUG */++/****************************************************************************+ * MPLS Interface "Extension" + * In the current implementation the "all loved" net_device struct is + * extended with one field struct mpls_interface (cast'd to void) called+ * mpls_ptr; This holds basically the "per interface" labelspace.+ ****************************************************************************/++struct mpls_interface {+ /* + * (any mif object)->list_out is a circular d-linked list. Each node+ * of this list is a NHLFE. NHLFE's are added to this list when adding a + * OP_SET opcode to a nhlfe instruction array.+ * + * list_add(&nhlfe->dev_entry, &mpls_if->list_out) : adds nhlfe to this + * list.+ *+ * "List of all NHLFEs that use this device (e.g. eth0) as output"+ * cf. mpls_init.c+ */+ struct list_head list_out;+ ++ /* + * (any mif object)->list_in is a circular d-linked list. Each node+ * of this list is a ILM. ILM's are added to this list when + */+ struct list_head list_in; ++ /* + * Label Space for this interface + */+ int labelspace; +};++++extern struct mpls_interface* mpls_create_if_info(void);+extern void mpls_delete_if_info(struct mpls_interface *mpls_if);++/****************************************************************************+ * Socket Buffer Mangement+ ****************************************************************************/++struct mpls_skb_parm {+ struct mpls_prot_driver *prot;+ unsigned int gap;+ unsigned int label:20;+ unsigned int ttl:8;+ unsigned int exp:3;+ unsigned int bos:1;+ unsigned char flag;+ unsigned char popped_bos;+ unsigned char *top_of_stack;+};++#define MPLSCB(skb) ((struct mpls_skb_parm*)((skb)->cb))+++/****************************************************************************+ * Result codes for Input/Output Opcodes. + * net/mpls/{mpls_opcode,mpls_opcode_all}.c+ ****************************************************************************/++#define MPLS_RESULT_SUCCESS 0+#define MPLS_RESULT_RECURSE 1+#define MPLS_RESULT_DROP 2+#define MPLS_RESULT_DLV 3+#define MPLS_RESULT_FWD 4+++/**+ * mpls_instr - Struct to hold one instruction+ * @mi_opcode: Opcode. MPLS_OP_POP,etc... + * @mi_data: Opcode data.+ * @mi_next: Next Instruction to execute. + **/+struct mpls_instr {+ struct mpls_instr *mi_next;+ unsigned short mi_opcode;+ enum mpls_dir mi_dir;+ void *mi_data; + void * mi_parent;+};+++struct mpls_nfmark_fwd_info {+ struct mpls_nhlfe *nfi_nhlfe[MPLS_NFMARK_NUM];+ unsigned short nfi_mask;+};++struct mpls_dsmark_fwd_info {+ struct mpls_nhlfe *dfi_nhlfe[MPLS_DSMARK_NUM];+ unsigned char dfi_mask;+};++struct mpls_tcindex_fwd_info {+ struct mpls_nhlfe *tfi_nhlfe[MPLS_TCINDEX_NUM];+ unsigned short tfi_mask;+};++struct mpls_exp_fwd_info {+ struct mpls_nhlfe *efi_nhlfe[MPLS_EXP_NUM];+};++struct mpls_exp2dsmark_info {+ unsigned char e2d[MPLS_EXP_NUM];+};++struct mpls_exp2tcindex_info {+ unsigned short e2t[MPLS_EXP_NUM];+};++struct mpls_tcindex2exp_info {+ unsigned char t2e_mask;+ unsigned char t2e[MPLS_TCINDEX_NUM];+};++struct mpls_dsmark2exp_info {+ unsigned char d2e_mask;+ unsigned char d2e[MPLS_DSMARK_NUM];+};++struct mpls_nfmark2exp_info {+ unsigned char n2e_mask;+ unsigned char n2e[MPLS_NFMARK_NUM];+};++/****************************************************************************+ * Instruction (OPCODEs) Management + * net/mpls/mpls_instr.c+ ****************************************************************************/++void mpls_instr_release(struct mpls_instr *mi);+struct mpls_instr* mpls_instr_alloc(unsigned short opcode);+void mpls_instrs_free(struct mpls_instr *list);+int mpls_instrs_build(struct mpls_instr_elem *mie, + struct mpls_instr **instr, int length, + enum mpls_dir dir,void *parent);+void mpls_instrs_unbuild(struct mpls_instr *instr,+ struct mpls_instr_req *req);++/****************************************************************************+ * Layer 3 protocol driver+ *+ * most of this code is taken from DaveM&JHadi implementation+ ****************************************************************************/+#define MPLSPROTONAMSIZ 16+struct mpls_prot_driver {+ atomic_t __refcnt;+ struct list_head list;++ unsigned short family;+ unsigned short ethertype;+ char name[MPLSPROTONAMSIZ + 1];++ void (*cache_flush)(void);+ void (*set_ttl)(struct sk_buff *skb, int ttl);+ int (*get_ttl)(struct sk_buff *skb);+ void (*change_dsfield)(struct sk_buff *skb, int ds);+ int (*get_dsfield)(struct sk_buff *skb);+ int (*ttl_expired)(struct sk_buff **skb);+ int (*mtu_exceeded)(struct sk_buff **skb, int mtu);+ int (*local_deliver)(struct sk_buff *skb);++ int (*nexthop_resolve)(struct neighbour **,+ struct sockaddr *, struct net_device *);++ struct module *owner;+};++/****************************************************************************+ * Protocol driver Management + * net/mpls/mpls_proto.c+ ****************************************************************************/++void mpls_proto_init(void);+void mpls_proto_exit(void);+int mpls_proto_add(struct mpls_prot_driver *);+int mpls_proto_remove(struct mpls_prot_driver *);+struct mpls_prot_driver *mpls_proto_find_by_family(unsigned short);+struct mpls_prot_driver *mpls_proto_find_by_ethertype(unsigned short);+struct mpls_prot_driver *mpls_proto_find_by_name(char *);+void mpls_proto_cache_flush_all (void);++#define mpls_proto_release(V) atomic_dec((&V->__refcnt));+#define mpls_proto_hold(V) atomic_inc((&V->__refcnt));++/****************************************************************************+ * MPLS INPUT INFO (ILM) OBJECT MANAGEMENT+ * net/mpls/mpls_ilm.c+ ****************************************************************************/++struct mpls_ilm {++ union {+ struct dst_entry dst;+ struct mpls_ilm *next;+ } u;++ struct list_head global;++ /* To appear as an entry in the device ILM list */ + struct list_head dev_entry;+ /* Generic stats */+ struct gnet_stats_basic ilm_stats;+ unsigned int ilm_drops;+ /* List of NHLFE */ + struct list_head nhlfe_entry;+ /* Instructions to execute for this ILM */ + struct mpls_instr *ilm_instr;+ /* Incoming Label for this ILM */+ struct mpls_label ilm_label;+ /* Key used to lookup this object in a data structure */+ unsigned int ilm_key;+ /* Jiffies */+ unsigned int ilm_age;+ /* L3 protocol driver for packets that use this ILM */+ struct mpls_prot_driver *ilm_proto;+ /* Incoming Labelspace (see doc) */+ unsigned short ilm_labelspace;+};+++/****************************************************************************+ * Input Radix Tree Management+ ****************************************************************************/++extern spinlock_t mpls_ilm_lock;+extern struct radix_tree_root mpls_ilm_tree;++int mpls_ilm_init(void);+void mpls_ilm_exit(void);+int mpls_insert_ilm(unsigned int, struct mpls_ilm* ilm);+struct mpls_ilm* mpls_delete_ilm(unsigned int key);+struct mpls_ilm* mpls_get_ilm(unsigned int key);+struct mpls_ilm* mpls_get_ilm_by_label(struct mpls_label *label,+ int labelspace, char bos);+extern struct mpls_ilm* mpls_ilm_dst_alloc(unsigned int key,+ struct mpls_label *ml, unsigned short family,+ struct mpls_instr_elem *instr, int instr_len);++++/****************************************************************************+ * MPLS OUTPUT INFO (NHLFE) OBJECT MANAGEMENT+ * net/mpls/mpls_ilm.c+ ****************************************************************************/++struct mpls_nhlfe {+ /* since most higher lay protocol operate on dst_entries, representing+ * a NHLFE as a dst_enttry make sense. Higher layer protocols+ * may hold references to the dst_entry. The result is that+ * a NHLFE may exist after the user deletes it from the RADIX tree.+ */+ union {+ struct dst_entry dst;+ struct mpls_nhlfe *next;+ } u;+#define nhlfe_mtu u.dst.metrics[RTAX_MTU-1]++ /* user configured references as opposed to the references+ * created by protocol drivers (ie IPv4 route cache)+ */+ atomic_t __refcnt;++ struct list_head global;++ /* Generic stats */+ struct gnet_stats_basic nhlfe_stats;+ unsigned int nhlfe_drops;+ /* List of notif */+ struct notifier_block* nhlfe_notifier_list;+ /* List of NHLFE that are linked to this NHLFE */+ struct list_head list_out;+ /* List of ILM that are linked to this NHLFE */+ struct list_head list_in;+ /* To be added into a device list_out if the NHLFE uses (SET) the dev */+ struct list_head dev_entry;+ /* To be added into list_out if this nhlfe uses (FWD) another NHLFE */+ struct list_head nhlfe_entry;+ /* Array of instructions for this NHLFE */ + struct mpls_instr *nhlfe_instr;+ /* Key to used to store/lookup a given NHLFE in the tree */+ unsigned int nhlfe_key;+ /* Age in jiffies */+ unsigned int nhlfe_age;+ /* MTU Limit (e.g. from device MTU + number of pushes */+ unsigned short nhlfe_mtu_limit;+ unsigned char nhlfe_propagate_ttl;+};+++struct mpls_fwd_block {+ struct notifier_block notifier_block;+ struct mpls_nhlfe *owner;+ struct mpls_nhlfe *fwd;+};++/****************************************************************************+ * Output Radix Tree Management+ ****************************************************************************/++extern struct radix_tree_root mpls_nhlfe_tree;+extern spinlock_t mpls_nhlfe_lock;++int mpls_nhlfe_init(void);+void mpls_nhlfe_exit(void);+int mpls_insert_nhlfe(unsigned int, struct mpls_nhlfe*);+struct mpls_nhlfe* mpls_delete_nhlfe(unsigned int);+struct mpls_nhlfe* mpls_get_nhlfe(unsigned int);+++/****************************************************************************+ * Helper Functions+ ****************************************************************************/++void mpls_skb_dump(struct sk_buff* sk);+char mpls_find_payload(struct sk_buff* skb);+unsigned int mpls_label2key(const int, const struct mpls_label*);+++/****************************************************************************+ * INCOMING (INPUT) LABELLED PACKET MANAGEMENT+ * net/mpls/mpls_input.c+ ****************************************************************************/++int mpls_skb_recv (struct sk_buff *skb, struct net_device *dev,+ struct packet_type* ptype, struct net_device *orig);+int mpls_skb_recv_mc (struct sk_buff *skb, struct net_device *dev,+ struct packet_type* ptype, struct net_device *orig);+++/****************************************************************************+ * OUTGOING (OUTPUT) LABELLED PACKET MANAGEMENT+ * net/mpls/mpls_output.c+ ****************************************************************************/++struct mpls_dst {+ union {+ struct dst_entry dst;+ struct mpls_dst *next;+ } u;+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -