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

📄 ebtables.diff

📁 一个可以实现MPLS实验的linux源代码.你不仅可以实现单层标签的转发,还可以实现2个标签的实验,很好的.
💻 DIFF
字号:
diff -uNr ebtables/extensions/ebt_mpls.c ebtables-mpls/extensions/ebt_mpls.c--- ebtables/extensions/ebt_mpls.c	1969-12-31 18:00:00.000000000 -0600+++ ebtables-mpls/extensions/ebt_mpls.c	2005-10-25 21:57:56.000000000 -0500@@ -0,0 +1,102 @@+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <getopt.h>+#include "../include/ebtables_u.h"+#define __KERNEL__+#include <linux/mpls.h>+#undef __KERNEL__++#define MPLS_TARGET '1'+static struct option opts[] =+{+	{ "nhlfe", required_argument, 0, MPLS_TARGET },+	{ 0 }+};++static void print_help()+{+	printf(+	"mpls option:\n"+	" --nhlfe value   : Index of MPLS NHLFE to map traffic to\n");+}++static void init(struct ebt_entry_target *target)+{+}++static int parse(int c, char **argv, int argc,+   const struct ebt_u_entry *entry, unsigned int *flags,+   struct ebt_entry_target **target)+{+	unsigned int temp;+	struct mpls_netfilter_target_info *mplsinfo =+	   (struct mpls_netfilter_target_info *)(*target)->data;+	char *end;++	switch (c) {+	case MPLS_TARGET:+		if (*flags) {+			print_error("mpls target: Can't specify --nhlfe twice");+		}++		mplsinfo->key = strtoul(optarg, &end, 0);+		if (*end != '\0' || end == optarg)+			print_error("Bad MPLS key `%s'", optarg);+		*flags = 1;+		break;+	default:+		return 0;+	}+	return 1;+}++static void final_check(const struct ebt_u_entry *entry,+   const struct ebt_entry_target *target, const char *name,+   unsigned int hookmask, unsigned int time)+{+	struct mpls_netfilter_target_info *mplsinfo =+	   (struct mpls_netfilter_target_info *)target->data;++	if (!mplsinfo->key)+		print_error("mpls target: Parameter --nhlfe is required");+}++static void print(const struct ebt_u_entry *entry,+   const struct ebt_entry_target *target)+{+	struct mpls_netfilter_target_info *mplsinfo =+	   (struct mpls_netfilter_target_info *)target->data;++	printf(" --nhlfe 0x%x", mplsinfo->key);+}++static int compare(const struct ebt_entry_target *t1,+   const struct ebt_entry_target *t2)+{+	struct mpls_netfilter_target_info *mplsinfo1 =+	   (struct mpls_netfilter_target_info *)t1->data;+	struct mpls_netfilter_target_info *mplsinfo2 =+	   (struct mpls_netfilter_target_info *)t2->data;++	return mplsinfo1->key == mplsinfo2->key;+}++static struct ebt_u_target mpls_target =+{+	.name		= "mpls",+	.size		= sizeof(struct mpls_netfilter_target_info),+	.help		= print_help,+	.init		= init,+	.parse		= parse,+	.final_check	= final_check,+	.print		= print,+	.compare	= compare,+	.extra_ops	= opts,+};++static void _init(void) __attribute__ ((constructor));+static void _init(void)+{+	register_target(&mpls_target);+}diff -uNr ebtables/extensions/Makefile ebtables-mpls/extensions/Makefile--- ebtables/extensions/Makefile	2005-10-14 23:05:56.000000000 -0500+++ ebtables-mpls/extensions/Makefile	2005-10-15 01:25:55.000000000 -0500@@ -1,7 +1,7 @@ #! /usr/bin/make  EXT_FUNC+=802_3 nat arp arpreply ip standard log redirect vlan mark_m mark \-          pkttype stp among limit+          pkttype stp among limit mpls EXT_TABLES+=filter nat broute EXT_OBJS+=$(foreach T,$(EXT_FUNC), extensions/ebt_$(T).o) EXT_OBJS+=$(foreach T,$(EXT_TABLES), extensions/ebtable_$(T).o)diff -uNr ebtables/include/linux/mpls.h ebtables-mpls/include/linux/mpls.h--- ebtables/include/linux/mpls.h	1969-12-31 18:00:00.000000000 -0600+++ ebtables-mpls/include/linux/mpls.h	2005-11-01 22:40:21.000000000 -0600@@ -0,0 +1,255 @@+/*****************************************************************************+ * MPLS+ *      An implementation of the MPLS (MultiProtocol Label+ *      Switching Architecture) for Linux.+ *+ * Authors:+ *          James Leu        <jleu@mindspring.com>+ *          Ramon Casellas   <casellas@infres.enst.fr>+ *+ *   (c) 1999-2004   James Leu        <jleu@mindspring.com>+ *   (c) 2003-2004   Ramon Casellas   <casellas@infres.enst.fr>+ *+ * include/linux/mpls.h+ *      Data types and structs used by userspace programs to access MPLS+ *      forwarding. Most interface with the MPLS subsystem is IOCTL based+ *+ *      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.+ ****************************************************************************/++#ifndef _LINUX_MPLS_H_+#define _LINUX_MPLS_H_++#ifdef __KERNEL__+#include <linux/socket.h>+#include <linux/if.h>+#else+#include <sys/socket.h>+#include <net/if.h>+#endif++#define MPLS_NUM_OPS		8++#define MPLS_LINUX_VERSION	0x01090500++#define	MPLS_GRP_ILM	1+#define	MPLS_GRP_NHLFE	2+#define	MPLS_GRP_XC	4+#define	MPLS_GRP_LABELSPACE 8++#define MPLS_IPV4_EXPLICIT_NULL	0       /* only valid as sole label stack entry+					   Pop label and send to IPv4 stack */+#define MPLS_ROUTER_ALERT	1       /* anywhere except bottom, packet it is+					   forwared to a software module+					   determined by the next label,+					   if the packet is forwarded, push this+					   label back on */+#define MPLS_IPV6_EXPLICIT_NULL	2       /* only valid as sole label stack entry+					   Pop label and send to IPv6 stack */+#define MPLS_IMPLICIT_NULL	3       /* a LIB with this, signifies to pop+					   the next label and use that */++#define MPLS_CHANGE_MTU		0x01+#define MPLS_CHANGE_PROP_TTL	0x02+#define MPLS_CHANGE_INSTR	0x04+#define MPLS_CHANGE_PROTO	0x10++enum mpls_dir {+	MPLS_IN = 0x10,+	MPLS_OUT = 0x20+};++enum mpls_opcode_enum {+	MPLS_OP_NOP = 0x00,+	MPLS_OP_POP,+	MPLS_OP_PEEK,+	MPLS_OP_PUSH,+	MPLS_OP_DLV,+	MPLS_OP_FWD,+	MPLS_OP_NF_FWD,+	MPLS_OP_DS_FWD,+	MPLS_OP_EXP_FWD,+	MPLS_OP_SET,+	MPLS_OP_SET_RX,+	MPLS_OP_SET_TC,+	MPLS_OP_SET_DS,+	MPLS_OP_SET_EXP,+	MPLS_OP_EXP2TC,+	MPLS_OP_EXP2DS,+	MPLS_OP_TC2EXP,+	MPLS_OP_DS2EXP,+	MPLS_OP_NF2EXP,+	MPLS_OP_SET_NF,+	MPLS_OP_MAX+};++enum mpls_label_type_enum {+	MPLS_LABEL_GEN = 1,+	MPLS_LABEL_ATM,+	MPLS_LABEL_FR,+	MPLS_LABEL_KEY+};++struct mpls_label_atm {+	u_int16_t  mla_vpi;+	u_int16_t  mla_vci;+};++struct mpls_label {+	enum mpls_label_type_enum ml_type;+	union {+		u_int32_t ml_key;+		u_int32_t ml_gen;+		u_int32_t ml_fr;+		struct mpls_label_atm ml_atm;+	} u;+	int ml_index;+};++struct mpls_in_label_req {+	unsigned int      mil_proto;+	struct mpls_label mil_label;+	unsigned char     mil_change_flag;+};++#define MPLS_LABELSPACE_MAX	255++struct mpls_labelspace_req {+	int mls_ifindex;                  /* Index to the MPLS-enab. interface*/+	int mls_labelspace;               /* Labelspace IN/SET -- OUT/GET     */+};++struct mpls_nexthop_info {+	unsigned int    mni_if;+	struct sockaddr mni_addr;+};++struct mpls_out_label_req {+	struct mpls_label mol_label;+	u_int32_t         mol_mtu;+	int8_t            mol_propagate_ttl;+	unsigned char     mol_change_flag;+};++struct mpls_netfilter_target_info {+        u_int32_t key;++	/* only used by the netfilter kernel modules */+        void *nhlfe;+        void *proto;+};++struct mpls_xconnect_req {+	struct mpls_label mx_in;+	struct mpls_label mx_out;+};++struct mpls_tunnel_req {+	char mt_ifname[IFNAMSIZ];+	unsigned int mt_nhlfe_key;+};++#define MPLS_NFMARK_NUM 64++struct mpls_nfmark_fwd {+	unsigned int nf_key[MPLS_NFMARK_NUM];+	unsigned short nf_mask;+};++#define MPLS_DSMARK_NUM 64++struct mpls_dsmark_fwd {+	unsigned int df_key[MPLS_DSMARK_NUM];+	unsigned char df_mask;+};++#define MPLS_TCINDEX_NUM 64++struct mpls_tcindex_fwd {+	unsigned int tc_key[MPLS_TCINDEX_NUM];+	unsigned short tc_mask;+};++#define MPLS_EXP_NUM 8++struct mpls_exp_fwd {+	unsigned int ef_key[MPLS_EXP_NUM];+};++struct mpls_exp2tcindex {+	unsigned short e2t[MPLS_EXP_NUM];+};++struct mpls_exp2dsmark {+	unsigned char e2d[MPLS_EXP_NUM];+};++struct mpls_tcindex2exp {+	unsigned char t2e_mask;+	unsigned char t2e[MPLS_TCINDEX_NUM];+};++struct mpls_dsmark2exp {+	unsigned char d2e_mask;+	unsigned char d2e[MPLS_DSMARK_NUM];+};++struct mpls_nfmark2exp {+	unsigned char n2e_mask;+	unsigned char n2e[MPLS_NFMARK_NUM];+};++struct mpls_instr_elem {+	unsigned short mir_opcode;+	unsigned char mir_direction;+	union {+		struct mpls_label        push;+		struct mpls_label        fwd;+		struct mpls_nfmark_fwd   nf_fwd;+		struct mpls_dsmark_fwd   ds_fwd;+		struct mpls_exp_fwd      exp_fwd;+		struct mpls_nexthop_info set;+		unsigned int             set_rx;+		unsigned short           set_tc;+		unsigned short           set_ds;+		unsigned char            set_exp;+		struct mpls_exp2tcindex  exp2tc;+		struct mpls_exp2dsmark   exp2ds;+		struct mpls_tcindex2exp  tc2exp;+		struct mpls_dsmark2exp   ds2exp;+		struct mpls_nfmark2exp   nf2exp;+		unsigned long            set_nf;+	} mir_data;+};++/* Standard shortcuts */+#define mir_push       mir_data.push+#define mir_fwd        mir_data.fwd+#define mir_nf_fwd     mir_data.nf_fwd+#define mir_ds_fwd     mir_data.ds_fwd+#define mir_exp_fwd    mir_data.exp_fwd+#define mir_set        mir_data.set+#define mir_set_rx     mir_data.set_rx+#define mir_set_tc     mir_data.set_tc+#define mir_set_tx     mir_data.set_tx+#define mir_set_ds     mir_data.set_ds+#define mir_set_exp    mir_data.set_exp+#define mir_set_nf     mir_data.set_nf+#define mir_exp2tc     mir_data.exp2tc+#define mir_exp2ds     mir_data.exp2ds+#define mir_tc2exp     mir_data.tc2exp+#define mir_ds2exp     mir_data.ds2exp+#define mir_nf2exp     mir_data.nf2exp++struct mpls_instr_req {+	struct mpls_instr_elem       mir_instr[MPLS_NUM_OPS];+	unsigned char                mir_instr_length;+	unsigned char                mir_direction;+	int                          mir_index;+	struct mpls_label            mir_label;+};++#endifdiff -uNr ebtables/redhat/ebtables.spec ebtables-mpls/redhat/ebtables.spec--- ebtables/redhat/ebtables.spec	2005-10-14 23:09:03.000000000 -0500+++ ebtables-mpls/redhat/ebtables.spec	2005-11-01 23:30:15.000000000 -0600@@ -1,8 +1,8 @@-%define		epoch	%(date '+%s')+%define subver %([ ${MPLSVER}"x" != "x" ] && echo ${MPLSVER} || echo 0.`date '+%s'`)  Name:		ebtables Version:	2.0.6-Release:        7%{?dist}_%{epoch}+Release:        7%{?dist}_mpls_%{subver} Summary:	Ethernet Bridge frame table administration tool License:	GPL Group:		System Environment/Base@@ -53,7 +53,7 @@ fi  %postun-if [ $1 -ge 1 ]+if [ $1 -ge 1 ]; then 	/sbin/service ebtables condrestart &> /dev/null || : fi 

⌨️ 快捷键说明

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