📄 iproute2.diff
字号:
diff -uNr iproute2/include/linux/rtnetlink.h iproute2-mpls-1.1/include/linux/rtnetlink.h--- iproute2/include/linux/rtnetlink.h 2004-12-22 16:11:55.000000000 -0600+++ iproute2-mpls-1.1/include/linux/rtnetlink.h 2004-12-22 23:31:16.000000000 -0600@@ -214,6 +214,8 @@ RTA_FLOW, RTA_CACHEINFO, RTA_SESSION,+ RTA_SPEC_PROTO,+ RTA_SPEC_DATA, __RTA_MAX }; @@ -237,6 +239,8 @@ unsigned char rtnh_flags; unsigned char rtnh_hops; int rtnh_ifindex;+ unsigned int rtnh_spec_proto;+ unsigned int rtnh_spec_data; }; /* rtnh_flags */diff -uNr iproute2/include/utils.h iproute2-mpls-1.1/include/utils.h--- iproute2/include/utils.h 2004-12-22 16:11:56.000000000 -0600+++ iproute2-mpls-1.1/include/utils.h 2004-12-30 15:29:00.000000000 -0600@@ -61,6 +61,11 @@ u_int8_t ipx_node[IPX_NODE_LEN]; }; +#ifndef AF_MPLS+#define AF_MPLS 30+#define PF_MPLS AF_MPLS+#endif+ extern __u32 get_addr32(const char *name); extern int get_addr_1(inet_prefix *dst, const char *arg, int family); extern int get_prefix_1(inet_prefix *dst, const char *arg, int family);diff -uNr iproute2/ip/iproute.c iproute2-mpls-1.1/ip/iproute.c--- iproute2/ip/iproute.c 2004-12-22 16:11:56.000000000 -0600+++ iproute2-mpls-1.1/ip/iproute.c 2004-12-22 16:35:09.000000000 -0600@@ -54,7 +54,7 @@ fprintf(stderr, " [ table TABLE_ID ] [ proto RTPROTO ]\n"); fprintf(stderr, " [ scope SCOPE ] [ metric METRIC ]\n"); fprintf(stderr, "INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ]...\n");- fprintf(stderr, "NH := [ via ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS\n");+ fprintf(stderr, "NH := [ via ADDRESS ] [ dev STRING ] [ weight NUMBER ] [ spec_nh PROTO DATA ] NHFLAGS\n"); fprintf(stderr, "OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ]\n"); fprintf(stderr, " [ rtt NUMBER ] [ rttvar NUMBER ]\n"); fprintf(stderr, " [ window NUMBER] [ cwnd NUMBER ] [ ssthresh REALM ]\n");@@ -91,6 +91,7 @@ inet_prefix mdst; inet_prefix rsrc; inet_prefix msrc;+ unsigned short spec_nh; } filter; static int flush_update(void)@@ -254,6 +255,13 @@ if ((oif^filter.oif)&filter.oifmask) return 0; }+ if (filter.spec_nh) {+ unsigned short spec_nh = 0;+ if (tb[RTA_SPEC_PROTO])+ spec_nh = ntohs(*(unsigned short*)RTA_DATA(tb[RTA_SPEC_PROTO]));+ if (filter.spec_nh && spec_nh != filter.spec_nh)+ return 0;+ } if (filter.flushb && r->rtm_family == AF_INET6 && r->rtm_dst_len == 0 &&@@ -261,7 +269,6 @@ tb[RTA_PRIORITY] && *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1) return 0;- if (filter.flushb) { struct nlmsghdr *fn; if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {@@ -335,6 +342,8 @@ } if (tb[RTA_OIF] && filter.oifmask != -1) fprintf(fp, "dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])));+ if (tb[RTA_SPEC_PROTO])+ fprintf(fp, "spec_nh 0x%04x 0x%08x ", ntohs(*(unsigned short*)RTA_DATA(tb[RTA_SPEC_PROTO])), *(__u32*)RTA_DATA(tb[RTA_SPEC_DATA])); if (!(r->rtm_flags&RTM_F_CLONED)) { if (r->rtm_table != RT_TABLE_MAIN && !filter.tb)@@ -592,6 +601,20 @@ rtnh->rtnh_hops = w - 1; } else if (strcmp(*argv, "onlink") == 0) { rtnh->rtnh_flags |= RTNH_F_ONLINK;+ } else if (strcmp(*argv, "spec_nh") == 0) {+ unsigned short proto;+ __u32 data;+ NEXT_ARG();+ if (get_u16(&proto, *argv, 0))+ invarg("\"spec_nh proto\" value is invalid\n",+ *argv);+ NEXT_ARG();+ if (get_u32(&data, *argv, 0))+ invarg("\"spec_nh data\" value is invalid\n",+ *argv);++ rtnh->rtnh_spec_proto = htons(proto);+ rtnh->rtnh_spec_data = data; } else break; }@@ -689,6 +712,22 @@ if (req.r.rtm_family == AF_UNSPEC) req.r.rtm_family = addr.family; addattr_l(&req.n, sizeof(req), RTA_GATEWAY, &addr.data, addr.bytelen);+ } else if (strcmp(*argv, "spec_nh") == 0) {+ unsigned short proto;+ __u32 data;+ NEXT_ARG();+ if (get_u16(&proto, *argv, 0))+ invarg("\"spec_nh proto\" value is invalid\n",+ *argv);+ NEXT_ARG();+ if (get_u32(&data, *argv, 0))+ invarg("\"spec_nh data\" value is invalid\n",+ *argv);++ proto = htons(proto);+ addattr_l(&req.n, sizeof(req), RTA_SPEC_PROTO, &proto, 4);+ addattr32(&req.n, sizeof(req), RTA_SPEC_DATA, data);+ } else if (strcmp(*argv, "from") == 0) { inet_prefix addr; NEXT_ARG();@@ -1055,6 +1094,10 @@ } else if (strcmp(*argv, "src") == 0) { NEXT_ARG(); get_prefix(&filter.rprefsrc, *argv, do_ipv6);+ } else if (matches(*argv, "spec_nh") == 0) {+ NEXT_ARG();+ get_u16(&filter.spec_nh, *argv, 0);+ filter.spec_nh = htons(filter.spec_nh); } else if (matches(*argv, "realms") == 0) { __u32 realm; NEXT_ARG();@@ -1267,6 +1310,22 @@ strcmp(*argv, "dev") == 0) { NEXT_ARG(); odev = *argv;+ } else if (matches(*argv, "spec_nh") == 0) {+ unsigned short proto;+ __u32 data;+ NEXT_ARG();+ if (get_u16(&proto, *argv, 0))+ invarg("\"spec_nh proto\" value is invalid\n",+ *argv);+ NEXT_ARG();+ if (get_u32(&data, *argv, 0))+ invarg("\"spec_nh data\" value is invalid\n",+ *argv);++ proto = htons(proto);+ addattr_l(&req.n, sizeof(req), RTA_SPEC_PROTO, &proto, 4);+ addattr32(&req.n, sizeof(req), RTA_SPEC_DATA, data);+ } else if (matches(*argv, "notify") == 0) { req.r.rtm_flags |= RTM_F_NOTIFY; } else if (matches(*argv, "connected") == 0) {@@ -1355,6 +1414,10 @@ } if (!odev && tb[RTA_OIF]) tb[RTA_OIF]->rta_type = 0;+ if (tb[RTA_SPEC_PROTO]) {+ tb[RTA_SPEC_PROTO]->rta_type = 0;+ tb[RTA_SPEC_DATA]->rta_type = 0;+ } if (tb[RTA_GATEWAY]) tb[RTA_GATEWAY]->rta_type = 0; if (!idev && tb[RTA_IIF])diff -uNr iproute2/Makefile iproute2-mpls-1.1/Makefile--- iproute2/Makefile 2004-12-22 16:11:56.000000000 -0600+++ iproute2-mpls-1.1/Makefile 2004-12-22 16:37:51.000000000 -0600@@ -26,7 +26,7 @@ LDLIBS += -L../lib -lnetlink -lutil -SUBDIRS=lib ip tc misc+SUBDIRS=lib ip mpls tc misc LIBNETLINK=../lib/libnetlink.a ../lib/libutil.a diff -uNr iproute2/mpls/Makefile iproute2-mpls-1.1/mpls/Makefile--- iproute2/mpls/Makefile 1969-12-31 18:00:00.000000000 -0600+++ iproute2-mpls-1.1/mpls/Makefile 2005-01-05 22:53:24.000000000 -0600@@ -0,0 +1,19 @@+MPLSOBJ=mpls.o mpls_monitor.o++include ../Config++MPLSMODULES :=++MPLSLIB := ++LDFLAGS += -Wl,-export-dynamic -lm++all: mpls ++mpls: $(MPLSOBJ) $(LIBNETLINK) $(LIBUTIL) $(MPLSLIB) ++install: all+ install -m 0755 -s mpls $(DESTDIR)$(SBINDIR)++clean:+ rm -f $(MPLSOBJ) $(MPLSLIB) mplsdiff -uNr iproute2/mpls/mpls.c iproute2-mpls-1.1/mpls/mpls.c--- iproute2/mpls/mpls.c 1969-12-31 18:00:00.000000000 -0600+++ iproute2-mpls-1.1/mpls/mpls.c 2005-01-22 00:29:25.000000000 -0600@@ -0,0 +1,1302 @@+/*+ * mpls.c "mpls" utility frontend.+ *+ * 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.+ *+ * Heavly based on 'l2c' code from Jamal Hadi Salim+ *+ *+ */++#include <stdio.h>+#include <stdlib.h>+#include <unistd.h>+#include <syslog.h>+#include <fcntl.h>+#include <dlfcn.h>+#include <sys/socket.h>+#include <netinet/in.h>+#include <arpa/inet.h>+#include <string.h>+#include <errno.h>+#include <math.h>+#include <asm/types.h>+#include <linux/if_ether.h>+#include <linux/gen_stats.h>+#include <linux/mpls.h>+#include <linux/socket.h>++#include "SNAPSHOT.h"+#include "utils.h"++int show_stats = 0;+int show_details = 0;+int show_raw = 0;+int resolve_hosts = 0;+struct rtnl_handle rth1;++extern int do_mplsmonitor(int argc, char **argv);++static void usage(void)+{+ fprintf(stderr, "Usage: mpls ilm CMD label LABEL labelspace NUMBER [proto PROTO | instructions INSTR]\n");+ fprintf(stderr, " mpls nhlfe CMD key KEY [mtu MTU propagate_ttl | instructions INSTR]\n");+ fprintf(stderr, " mpls xc CMD ilm_label LABEL ilm_labelspace NUMBER nhlfe_key KEY\n");+ fprintf(stderr, " mpls labelspace CMD dev NAME labelspace NUMBER\n");+ fprintf(stderr, " mpls tunnel CMD dev NAME key KEY\n");+ fprintf(stderr, "\n");+ fprintf(stderr, " mpls ilm show [label LABEL labelspace NUMBER]\n");+ fprintf(stderr, " mpls nhlfe show [key KEY]\n");+ fprintf(stderr, " mpls xc show [ilm_label LABEL ilm_labelspace NUMBER]\n");+ fprintf(stderr, " mpls labelspace show [dev NAME]\n");+ fprintf(stderr, " mpls monitor ...\n");+ fprintf(stderr, "\n");+ fprintf(stderr, "Where:\n");+ fprintf(stderr, "CMD := add | del | change\n");+ fprintf(stderr, "NUMBER := 0 .. 255\n");+ fprintf(stderr, "TYPE := gen | atm | fr\n");+ fprintf(stderr, "VALUE := 16 .. 1048575 | <VPI>/<VCI> | 16 .. 1023\n");+ fprintf(stderr, "LABEL := TYPE VALUE\n");+ fprintf(stderr, "KEY := 0 for add | previously returned key\n");+ fprintf(stderr, "NAME := network device name (i.e. eth0)\n");+ fprintf(stderr, "PROTO := ipv4 | ipv6\n");+ fprintf(stderr, "ADDR := ipv6 or ipv4 address\n");+ fprintf(stderr, "NH := nexthop NAME [none | PROTO ADDR]\n");+ fprintf(stderr, "FWD := forward KEY\n");+ fprintf(stderr, "PUSH := push LABEL\n");+ fprintf(stderr, "INSTR := NH | PUSH | pop | deliver | peek | FWD |\n");+ fprintf(stderr, " set-dscp <DSCP> | set-exp <EXP> |\n");+ fprintf(stderr, " set-tcindex <TCINDEX> | set-rx-if <NAME>\n");+ fprintf(stderr, " forward <KEY> | expfwd <EXP> <KEY> ... |\n");+ fprintf(stderr, " exp2tc <EXP> <TCINDEX> ... | exp2ds <EXP> <DSCP> ... |\n");+ fprintf(stderr, " nffwd <MASK> [ <NFMARK> <KEY> ... ] |\n");+ fprintf(stderr, " nf2exp <MASK> [ <NFMARK> <EXP> ... ] |\n");+ fprintf(stderr, " tc2exp <MASK> [ <TCINDEX> <EXP> ... ] |\n");+ fprintf(stderr, " ds2exp <MASK> [ <DSCP> <EXP> ... ] |\n");+ fprintf(stderr, " dsfwd <MASK> [ <DSCP> <KEY> ... ]\n");+ fprintf(stderr, "\n");+ exit(-1);+}++int mpls_list(int cmd,int argc, char **argv);++int mpls_table_list(int argc, char **argv)+{+ if (argc <= 0) {+ mpls_list(MPLS_RTM_GETNHLFE,0,NULL);+ mpls_list(MPLS_RTM_GETILM ,0,NULL);+ mpls_list(MPLS_RTM_GETXC ,0,NULL);+ mpls_list(MPLS_RTM_GETLABELSPACE ,0,NULL);+ }+ return 0;+}++void+mpls_parse_label (struct mpls_label *label, int *pargc, char ***pargv) {+ unsigned int l1, l2;+ char *value;+ int argc = *pargc;+ char **argv = *pargv;++ if (strncmp(*argv, "fr", 2) == 0) {+ label->ml_type = MPLS_LABEL_FR;+ } else if (strncmp(*argv, "atm", 3) == 0) {+ label->ml_type = MPLS_LABEL_ATM;+ } else if (strncmp(*argv, "gen", 3) == 0) {+ label->ml_type = MPLS_LABEL_GEN;+ } else {+ invarg(*argv, "invalid mpls label type");+ }++ NEXT_ARG();+ value = *argv;++ switch (label->ml_type) {+ case MPLS_LABEL_GEN:+ if (get_unsigned(&l1, value, 0) || l1 > 1048575)+ invarg(value, "invalid label value");+ label->u.ml_gen = l1;+ break;+ case MPLS_LABEL_ATM:+ if (sscanf(value, "%u/%d", &l1, &l2) != 2)+ invarg(value, "invalid label value");+ label->u.ml_atm.mla_vpi = l1;+ label->u.ml_atm.mla_vci = l2;+ case MPLS_LABEL_FR:+ if (get_unsigned(&l1, value, 0) || l1 > 1023)+ invarg(value, "invalid label value");+ label->u.ml_fr = l1;+ default:+ fprintf(stderr, "Invalid label type!\n");+ exit(-1);+ }+ *pargc = argc;+ *pargv = argv;+}++void+mpls_parse_instr(struct mpls_instr_req *instr, int *pargc, char ***pargv,+ int direction) {+ int argc = *pargc;+ char **argv = *pargv;+ int c = 0;++ while (argc > 0) {+ if (strcmp(*argv, "nexthop") == 0) {+ NEXT_ARG();+ inet_prefix addr;+ instr->mir_instr[c].mir_opcode = MPLS_OP_SET;+ instr->mir_instr[c].mir_set.mni_if =+ ll_name_to_index(*argv);+ NEXT_ARG();+ if (strcmp(*argv, "ipv4") == 0) {+ struct sockaddr_in *sin = (struct sockaddr_in*)+ &instr->mir_instr[c].mir_set.mni_addr;+ NEXT_ARG();+ get_addr(&addr, *argv, AF_INET);+ sin->sin_family = AF_INET;+ memcpy(&sin->sin_addr, &addr.data,+ addr.bytelen);+ } else if (strcmp(*argv, "ipv6") == 0) {+ struct sockaddr_in6 *sin6=(struct sockaddr_in6*)+ &instr->mir_instr[c].mir_set.mni_addr;+ NEXT_ARG();+ get_addr(&addr, *argv, AF_INET6);+ sin6->sin6_family = AF_INET6;+ memcpy(&sin6->sin6_addr, &addr.data,+ addr.bytelen);+ } else if (strcmp(*argv, "none") == 0) {+ struct sockaddr *s =+ &instr->mir_instr[c].mir_set.mni_addr;+ NEXT_ARG();+ memset(s, 0, sizeof(struct sockaddr));+ continue;+ } else {+ invarg(*argv, "invalid nexthop type");+ }+ } else if (strcmp(*argv, "push") == 0) {+ NEXT_ARG();+ instr->mir_instr[c].mir_opcode = MPLS_OP_PUSH;+ *pargc = argc; *pargv = argv;+ mpls_parse_label(&instr->mir_instr[c].mir_push,+ pargc, pargv);+ argc = *pargc; argv = *pargv;+ } else if (strcmp(*argv, "forward") == 0) {+ __u32 key;+ NEXT_ARG();+ if (get_unsigned(&key, *argv, 0))+ invarg(*argv, "invalid key");+ instr->mir_instr[c].mir_fwd.ml_type = MPLS_LABEL_KEY;+ instr->mir_instr[c].mir_fwd.u.ml_key = key;+ instr->mir_instr[c].mir_opcode = MPLS_OP_FWD;+ } else if (strcmp(*argv, "pop") == 0) {+ if (direction == MPLS_OUT)+ invarg(*argv, "invalid NHLFE instruction");+ instr->mir_instr[c].mir_opcode = MPLS_OP_POP;+ } else if (strcmp(*argv, "peek") == 0) {+ if (direction == MPLS_OUT)+ invarg(*argv, "invalid NHLFE instruction");+ instr->mir_instr[c].mir_opcode = MPLS_OP_PEEK;+ } else if (strcmp(*argv, "deliver") == 0) {+ if (direction == MPLS_OUT)+ invarg(*argv, "invalid NHLFE instruction");+ instr->mir_instr[c].mir_opcode = MPLS_OP_DLV;+ } else if (strcmp(*argv, "set-dscp") == 0) {+ __u32 dscp;+ if (direction == MPLS_OUT)+ invarg(*argv, "invalid NHLFE instruction");+ NEXT_ARG();+ if (get_unsigned(&dscp, *argv, 0))+ invarg(*argv, "invalid DSCP");+ instr->mir_instr[c].mir_opcode = MPLS_OP_SET_DS;+ instr->mir_instr[c].mir_set_ds = dscp;+ } else if (strcmp(*argv, "set-tcindex") == 0) {+ __u32 tcindex;+ NEXT_ARG();+ if (get_unsigned(&tcindex, *argv, 0))+ invarg(*argv, "invalid TCINDEX");+ instr->mir_instr[c].mir_opcode = MPLS_OP_SET_TC;+ instr->mir_instr[c].mir_set_tc = tcindex;+ } else if (strcmp(*argv, "set-exp") == 0) {+ __u32 exp;+ NEXT_ARG();+ if (get_unsigned(&exp, *argv, 0))+ invarg(*argv, "invalid EXP");+ instr->mir_instr[c].mir_opcode = MPLS_OP_SET_EXP;+ instr->mir_instr[c].mir_set_exp = exp;+ } else if (strcmp(*argv, "set-rx-if") == 0) {+ if (direction == MPLS_OUT)+ invarg(*argv, "invalid NHLFE instruction");+ NEXT_ARG();+ instr->mir_instr[c].mir_opcode = MPLS_OP_SET_RX;+ instr->mir_instr[c].mir_set_rx =ll_name_to_index(*argv);+ } else if (strcmp(*argv, "expfwd") == 0) {+ int done = 0;+ int exp;+ int key;+ do {+ NEXT_ARG();+ if (get_unsigned(&exp, *argv, 0)) {+ done = 1;+ break;+ }+ NEXT_ARG();+ if (get_unsigned(&key, *argv, 0)) {+ done = 1;+ break;+ }+ instr->mir_instr[c].mir_exp_fwd.ef_key[exp] = key;+ } while (!done);+ PREV_ARG();+ instr->mir_instr[c].mir_opcode = MPLS_OP_EXP_FWD;+ } else if (strcmp(*argv, "exp2tc") == 0) {+ int done = 0;+ int exp;+ int tcindex;+ do {+ NEXT_ARG();+ if (get_unsigned(&exp, *argv, 0)) {+ done = 1;+ break;+ }+ NEXT_ARG();+ if (get_unsigned(&tcindex, *argv, 0)) {+ done = 1;+ break;+ }+ instr->mir_instr[c].mir_exp2tc.e2t[exp] = tcindex;+ } while (!done);+ PREV_ARG();+ instr->mir_instr[c].mir_opcode = MPLS_OP_EXP2TC;+ } else if (strcmp(*argv, "exp2ds") == 0) {+ int done = 0;+ int exp;+ int dscp;+ if (direction == MPLS_OUT)+ invarg(*argv, "invalid NHLFE instruction");+ do {+ NEXT_ARG();+ if (get_unsigned(&exp, *argv, 0)) {+ done = 1;+ break;+ }+ NEXT_ARG();+ if (get_unsigned(&dscp, *argv, 0)) {+ done = 1;+ break;+ }+ instr->mir_instr[c].mir_exp2ds.e2d[exp] = dscp;+ } while (!done);+ PREV_ARG();+ instr->mir_instr[c].mir_opcode = MPLS_OP_EXP2DS;+ } else if (strcmp(*argv, "nffwd") == 0) {+ int done = 0;+ int nfmark;+ int key;+ int mask;+ NEXT_ARG();+ if (!get_unsigned(&mask, *argv, 0)) {+ instr->mir_instr[c].mir_nf_fwd.nf_mask = mask;+ do {+ NEXT_ARG();+ if (get_unsigned(&nfmark, *argv, 0)) {+ done = 1;+ break;+ }+ NEXT_ARG();+ if (get_unsigned(&key, *argv, 0)) {+ done = 1;+ break;+ }+ instr->mir_instr[c].mir_nf_fwd.nf_key[nfmark] = key;+ } while (!done);+ }+ PREV_ARG();+ instr->mir_instr[c].mir_opcode = MPLS_OP_NF_FWD;+ } else if (strcmp(*argv, "nf2exp") == 0) {+ int done = 0;+ int nfmark;+ int exp;+ int mask;+ NEXT_ARG();+ if (!get_unsigned(&mask, *argv, 0)) {+ instr->mir_instr[c].mir_nf2exp.n2e_mask = mask;+ do {+ NEXT_ARG();+ if (get_unsigned(&nfmark, *argv, 0)) {+ done = 1;+ break;+ }+ NEXT_ARG();+ if (get_unsigned(&exp, *argv, 0)) {+ done = 1;+ break;+ }+ instr->mir_instr[c].mir_nf2exp.n2e[nfmark] = exp;+ } while (!done);+ }+ PREV_ARG();+ instr->mir_instr[c].mir_opcode = MPLS_OP_NF2EXP;+ } else if (strcmp(*argv, "tc2exp") == 0) {+ int done = 0;+ int tcindex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -