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

📄 iproute2.diff

📁 基于linux内核2.6.9的mpls补丁
💻 DIFF
📖 第 1 页 / 共 3 页
字号:
+			int exp;+			int mask;+			NEXT_ARG();+			if (!get_unsigned(&mask, *argv, 0)) {+				instr->mir_instr[c].mir_tc2exp.t2e_mask = mask;+				do {+					NEXT_ARG();+					if (get_unsigned(&tcindex, *argv, 0)) {+						done = 1;+						break;+					}+					NEXT_ARG();+					if (get_unsigned(&exp, *argv, 0)) {+						done = 1;+						break;+					}+					instr->mir_instr[c].mir_tc2exp.t2e[tcindex] = exp;+				} while (!done);+			}+			PREV_ARG();+			instr->mir_instr[c].mir_opcode = MPLS_OP_TC2EXP;+		} else if (strcmp(*argv, "ds2exp") == 0) {+			int done = 0;+			int dscp;+			int exp;+			int mask;+			if (direction == MPLS_IN)+				invarg(*argv, "invalid ILM instruction");+			NEXT_ARG();+			if (!get_unsigned(&mask, *argv, 0)) {+				instr->mir_instr[c].mir_ds2exp.d2e_mask = mask;+				do {+					NEXT_ARG();+					if (get_unsigned(&dscp, *argv, 0)) {+						done = 1;+						break;+					}+					NEXT_ARG();+					if (get_unsigned(&exp, *argv, 0)) {+						done = 1;+						break;+					}+					instr->mir_instr[c].mir_ds2exp.d2e[dscp] = exp;+				} while (!done);+			}+			PREV_ARG();+			instr->mir_instr[c].mir_opcode = MPLS_OP_DS2EXP;+		} else if (strcmp(*argv, "dsfwd") == 0) {+			int done = 0;+			int dscp;+			int key;+			int mask;+			NEXT_ARG();+			if (!get_unsigned(&mask, *argv, 0)) {+				instr->mir_instr[c].mir_ds_fwd.df_mask = mask;+				do {+					NEXT_ARG();+					if (get_unsigned(&dscp, *argv, 0)) {+						done = 1;+						break;+					}+					NEXT_ARG();+					if (get_unsigned(&key, *argv, 0)) {+						done = 1;+						break;+					}+					instr->mir_instr[c].mir_ds_fwd.df_key[dscp] = key;+				} while (!done);+			}+			PREV_ARG();+			instr->mir_instr[c].mir_opcode = MPLS_OP_DS_FWD;+		} else {+			invarg(*argv, "invalid mpls instruction");+		}+		argc--; argv++; c++;+	}+	instr->mir_instr_length = c;+	instr->mir_direction = direction;++	*pargc = argc;+	*pargv = argv;+}++int+mpls_ilm_modify(int cmd, unsigned flags, int argc, char **argv)+{+	struct {+		struct nlmsghdr			n;+		struct mpls_in_label_req	t;+		struct mpls_instr_req		i;+	} req;++	memset(&req, 0, sizeof(req));++	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct mpls_in_label_req) ++		sizeof(struct mpls_instr_req));+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;+	req.n.nlmsg_type = cmd;+	req.t.mil_family = AF_MPLS;+	req.t.mil_proto = ETH_P_IP;++	while (argc > 0) {+		if (strcmp(*argv, "labelspace") == 0) {+			__u32 ls;+			NEXT_ARG();+			if (get_unsigned(&ls, *argv, 0) || ls > 255)+				invarg(*argv, "invalid labelspace");+			req.t.mil_label.ml_index = ls;+		} else if (strcmp(*argv, "label") == 0) {+			NEXT_ARG();+			mpls_parse_label(&req.t.mil_label, &argc, &argv);+		} else if (strcmp(*argv, "proto") == 0) {+			NEXT_ARG();+			if (strncmp(*argv, "ipv4", 4) == 0) {+				req.t.mil_proto = ETH_P_IP;+			} else if (strncmp(*argv, "ipv6", 4) == 0) {+				req.t.mil_proto = ETH_P_IPV6;+			} else {+				invarg(*argv, "invalid ilm proto");+			}+		} else if (strcmp(*argv, "instructions") == 0) {+			NEXT_ARG();+			mpls_parse_instr(&req.i, &argc, &argv, MPLS_IN);+		} else {+			invarg(*argv, "invalid ilm argument");+		}+		argc--; argv++;+	}++	if (!req.t.mil_label.ml_type) {+		fprintf(stderr, "you must specify a label value\n");+		exit(1);+	}++	if (rtnl_talk(&rth1, &req.n, 0, 0, NULL, NULL, NULL) < 0)+		exit(2);++	return 0;+}++int+mpls_nhlfe_modify(int cmd, unsigned flags, int argc, char **argv)+{+	struct nlmsghdr *answer = NULL;+	struct {+		struct nlmsghdr			n;+		struct mpls_out_label_req 	t;+		struct mpls_instr_req 		i;+	} req;++	memset(&req, 0, sizeof(req));++	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct mpls_out_label_req) ++		sizeof(struct mpls_instr_req));+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;+	req.n.nlmsg_type = cmd;+	req.t.mol_family = AF_MPLS;++	while (argc > 0) {+		if (strcmp(*argv, "key") == 0) {+			__u32 key;+			NEXT_ARG();+			if (get_unsigned(&key, *argv, 0))+				invarg(*argv, "invalid key");+			req.t.mol_label.u.ml_key = key;+			req.t.mol_label.ml_type = MPLS_LABEL_KEY;+		} else if (strcmp(*argv, "mtu") == 0) {+			__u32 mtu;+			NEXT_ARG();+			if (get_unsigned(&mtu, *argv, 0))+				invarg(*argv, "invalid mtu");+			req.t.mol_mtu = mtu;+		} else if (strcmp(*argv, "propagate_ttl") == 0) {+			req.t.mol_propagate_ttl = 1;+		} else if (strcmp(*argv, "instructions") == 0) {+			NEXT_ARG();+			mpls_parse_instr(&req.i, &argc, &argv, MPLS_OUT);+		} else {+			usage();+		}+		argc--; argv++;+	}++	if (flags & NLM_F_CREATE)+	    answer = &req.n;++	if (rtnl_talk(&rth1, &req.n, 0, 0, answer, NULL, NULL) < 0)+		exit(2);++	if (flags & NLM_F_CREATE)+		fprintf(stderr, "Key: 0x%08x\n", req.t.mol_label.u.ml_key);++	return 0;+}++int+mpls_xc_modify(int cmd, unsigned flags, int argc, char **argv)+{+	struct {+		struct nlmsghdr 		n;+		struct mpls_xconnect_req	t;+	} req;++	memset(&req, 0, sizeof(req));++	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct mpls_xconnect_req));+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;+	req.n.nlmsg_type = cmd;+	req.t.mx_family = AF_MPLS;++	while (argc > 0) {++		if (strcmp(*argv, "ilm_labelspace") == 0) {+			__u32 ls;+			NEXT_ARG();+			if (get_unsigned(&ls, *argv, 0) || ls > 255)+				invarg(*argv, "invalid labelspace");+			req.t.mx_in.ml_index = ls;+		} else if (strcmp(*argv, "ilm_label") == 0) {+			NEXT_ARG();+			mpls_parse_label(&req.t.mx_in, &argc, &argv);+		} else if (strcmp(*argv, "nhlfe_key") == 0) {+			__u32 key;+			NEXT_ARG();+			if (get_unsigned(&key, *argv, 0))+				invarg(*argv, "invalid key");+			req.t.mx_out.u.ml_key = key;+			req.t.mx_out.ml_type = MPLS_LABEL_KEY;+		} else {+			usage();+		}+		argc--; argv++;+	}++	if (!req.t.mx_in.ml_type) {+		fprintf(stderr, "you must specify a ILM label value\n");+		exit(1);+	}++	if (!req.t.mx_out.u.ml_key) {+		fprintf(stderr, "you must specify a NHLFE key\n");+		exit(1);+	}++	if (rtnl_talk(&rth1, &req.n, 0, 0, NULL, NULL, NULL) < 0)+		exit(2);++	return 0;+}++int+mpls_labelspace_modify(int cmd, unsigned flags, int argc, char **argv)+{+	__u32 labelspace = -2;+	struct {+		struct nlmsghdr 	n;+		struct mpls_labelspace_req 	t;+		char   			buf[4096];+	} req;++	memset(&req, 0, sizeof(req));++	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct mpls_labelspace_req));+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;+	req.n.nlmsg_type = cmd;+	req.t.mls_family = AF_MPLS;++	while (argc > 0) {+		if (strcmp(*argv, "dev") == 0) {+			NEXT_ARG();+			req.t.mls_ifindex = ll_name_to_index(*argv);+		} else if (strcmp(*argv, "labelspace") == 0) {+			NEXT_ARG();+			if (get_unsigned(&labelspace, *argv, 0))+				invarg(*argv, "invalid labelspace");+			req.t.mls_labelspace = labelspace;+		} else {+			usage();+		}+		argc--; argv++;+	}++	if (req.t.mls_ifindex == 0 || req.t.mls_labelspace == -2) {+		fprintf(stderr, "Invalid arguments\n");+		exit(1);+	}++	if (rtnl_talk(&rth1, &req.n, 0, 0, NULL, NULL, NULL) < 0)+		exit(2);++	return 0;+}++int+mpls_tunnel_modify(int cmd, unsigned flags, int argc, char **argv)+{+	unsigned int key = -2;+	struct {+		struct nlmsghdr 	n;+		struct mpls_tunnel_req 	t;+		char   			buf[4096];+	} req;++	memset(&req, 0, sizeof(req));++	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct mpls_tunnel_req));+	req.n.nlmsg_flags = NLM_F_REQUEST|flags;+	req.n.nlmsg_type = cmd;+	req.t.mt_family = AF_MPLS;++	while (argc > 0) {+		if (strcmp(*argv, "dev") == 0) {+			NEXT_ARG();+			strncpy(req.t.mt_ifname, *argv, IFNAMSIZ);+		} else if (strcmp(*argv, "key") == 0) {+			NEXT_ARG();+			if (get_unsigned(&key, *argv, 0))+				invarg(*argv, "invalid NHLFE key");+			req.t.mt_nhlfe_key = key;+		} else {+			usage();+		}+		argc--; argv++;+	}++	if (!strlen(req.t.mt_ifname)) {+		fprintf(stderr, "You must specify a interface name\n");+		exit(1);+	}++	if (rtnl_talk(&rth1, &req.n, 0, 0, NULL, NULL, NULL) < 0)+		exit(2);++	return 0;+}++void print_mpls_stats(FILE *fp, struct gnet_stats_basic *st, unsigned int drops)+{+	fprintf(fp, " (%llu bytes, %u pkts, %u dropped)",+		(unsigned long long)st->bytes, st->packets, drops);+}++void print_address(FILE *fp, struct sockaddr *addr) {+	char buf[256];+	switch (addr->sa_family) {+		case AF_INET:+		{+			struct sockaddr_in *sin = (struct sockaddr_in*)addr;+			inet_ntop(addr->sa_family, &sin->sin_addr,+				buf, sizeof(buf));+			fprintf(fp, "ipv4 %s ", buf);+			break;+		}+		case AF_INET6:+		{+			struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)addr;+			inet_ntop(addr->sa_family, &sin6->sin6_addr,+				buf, sizeof(buf));+			fprintf(fp, "ipv6 %s ", buf);+			break;+		}+		default:+			fprintf(fp, "<unknown address family %d> ",+				addr->sa_family);+	}+}++void print_label(FILE *fp, struct mpls_label *label) {+	switch (label->ml_type) {+		case MPLS_LABEL_GEN:+			fprintf(fp, "gen %d ", label->u.ml_gen);+			break;+		case MPLS_LABEL_ATM:+			fprintf(fp, "atm %d/%d ", label->u.ml_atm.mla_vpi,+				label->u.ml_atm.mla_vci);+			break;+		case MPLS_LABEL_FR:+			fprintf(fp, "fr %d ", label->u.ml_fr);+			break;+		case MPLS_LABEL_KEY:+			fprintf(fp, "key 0x%08x ", label->u.ml_key);+			break;+		default:+			fprintf(fp, "<unknown label type %d> ", label->ml_type);+	}+}++void print_instructions(FILE *fp, struct mpls_instr_req *instr) +{+	struct mpls_instr_elem *ci;   /* current instruction */+	unsigned int key;+	int i,j;++	for(i = 0;i < instr->mir_instr_length;i++) {+		ci = &instr->mir_instr[i];++		switch (ci->mir_opcode) {+			case MPLS_OP_NOP:+				fprintf(fp, "noop ");+				break;+			case MPLS_OP_POP:+				fprintf(fp, "pop ");+				break;+			case MPLS_OP_PEEK:+				fprintf(fp, "peek ");+				break;+			case MPLS_OP_PUSH:+				fprintf(fp, "push ");+				print_label(fp, &ci->mir_push);+				break;+			case MPLS_OP_FWD:+				fprintf(fp, "forward ");+				print_label(fp, &ci->mir_fwd);+				break;+			case MPLS_OP_DLV:+				fprintf(fp, "deliver ");+				break;+			case MPLS_OP_SET:+				fprintf(fp, "set %s ",+					ll_index_to_name(ci->mir_set.mni_if));+				print_address(fp, &ci->mir_set.mni_addr);+				break;				+		        case MPLS_OP_SET_RX:+				fprintf(fp, "set-rx-if %s ",+					ll_index_to_name(ci->mir_set_rx));+				break;+		        case MPLS_OP_SET_TC:+				fprintf(fp, "set-tcindex %hu ",ci->mir_set_tc);+				break;+			case MPLS_OP_SET_DS:+				fprintf(fp, "set-dscp %hu ",ci->mir_set_ds);+				break;+			case MPLS_OP_SET_EXP:+				fprintf(fp, "set-exp %hhu ",ci->mir_set_exp);+				break;	+		        case MPLS_OP_NF_FWD:+				fprintf(fp, "nffwd 0x%2.2hhx ",+					ci->mir_nf_fwd.nf_mask);++				for(j=0;j<MPLS_NFMARK_NUM;j++) {+					key = ci->mir_nf_fwd.nf_key[j];+					if (key) fprintf(fp,"%d %8.8x ",j,key);+				}+				break;+		        case MPLS_OP_DS_FWD:+				fprintf(fp, "dsfwd 0x%2.2hhx ",+					ci->mir_ds_fwd.df_mask);++				for(j=0;j<MPLS_DSMARK_NUM;j++) {+					key = ci->mir_ds_fwd.df_key[j];+					if (key) fprintf(fp,"%d %8.8x ",j,key);+				}+				break;+		        case MPLS_OP_EXP_FWD:+				fprintf(fp, "exp-fwd ");++				for(j=0;j<MPLS_EXP_NUM;j++) {+					key = ci->mir_exp_fwd.ef_key[j];+					if (key) fprintf(fp,"%d %8.8x ",j,key);+				}+				break;+		        case MPLS_OP_EXP2TC:+				fprintf(fp, "exp2tc ");++				for(j=0;j<MPLS_EXP_NUM;j++) {+					fprintf(fp,"%d %hu ",+						j,ci->mir_exp2tc.e2t[j]);++				}+				break;+		        case MPLS_OP_EXP2DS:+				fprintf(fp, "exp2ds ");++				for(j=0;j<MPLS_EXP_NUM;j++) {+					fprintf(fp,"%d %hhu ",+						j,ci->mir_exp2ds.e2d[j]);+				}+				break;+		        case MPLS_OP_TC2EXP:+				fprintf(fp, "tc2exp 0x%2.2hhx ",+					ci->mir_tc2exp.t2e_mask);++				for(j=0;j<MPLS_TCINDEX_NUM;j++) {+					fprintf(fp,"%d %hhu ",+						j,ci->mir_tc2exp.t2e[j]);++				}+				break;+			case MPLS_OP_DS2EXP:+				fprintf(fp, "ds2exp 0x%2.2hhx ",+					ci->mir_ds2exp.d2e_mask);++				for(j=0;j<MPLS_DSMARK_NUM;j++) {+					fprintf(fp,"%d %hhu ",+						j,ci->mir_ds2exp.d2e[j]);++				}+				break;+			case MPLS_OP_NF2EXP:+				fprintf(fp, "nf2exp 0x%2.2hhx ",+					ci->mir_nf2exp.n2e_mask);++				for(j=0;j<MPLS_NFMARK_NUM;j++) {+					fprintf(fp,"%d %hhu ",+						j,ci->mir_nf2exp.n2e[j]);++				}+				break;	+			default:+				fprintf(fp, "<unknown opcode %d> ", +					ci->mir_opcode);+		}+	}+}++int print_ilm(const struct sockaddr_nl *who, const struct nlmsghdr *n, void *arg)+{+	FILE *fp = (FILE*)arg;+	struct mpls_in_label_req *t = NLMSG_DATA(n);+	struct mpls_instr_req *i = (void*)&t[1];+	struct gnet_stats_basic *s = (void*)&i[1];+	unsigned int *d = (void*)&s[1];+	int len = n->nlmsg_len;++	if (n->nlmsg_type != MPLS_RTM_ADDILM &&+		n->nlmsg_type != MPLS_RTM_DELILM) {+		fprintf(stderr, "Not a ILN\n");+		return 0;+	}+	len -= NLMSG_LENGTH(sizeof(*t));+	if (len < 0) {+		fprintf(stderr, "Wrong len %d\n", len);+		return -1;+	}++	if (n->nlmsg_type == MPLS_RTM_DELILM)+		fprintf(fp, "deleted ILM entry ");++	if (n->nlmsg_type == MPLS_RTM_ADDILM)+		fprintf(fp, "ILM entry ");++	fprintf(fp, "label ");+	print_label(fp, &t->mil_label);++	fprintf(fp, "labelspace %d ", t->mil_label.ml_index);++	switch(t->mil_proto) {+		case AF_INET:+			fprintf(fp, "proto ipv4 ");+			break;+		case AF_INET6:+			fprintf(fp, "proto ipv6 ");+			break;+		default:+			fprintf(fp, "<unknown proto %d> ", t->mil_proto);+	}++	fprintf(fp, "\n\t");+	if (i->mir_instr_length) {+		print_instructions(fp, i);

⌨️ 快捷键说明

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