From 216cebcf491dc62b799a72a78c6a3b4252141213 Mon Sep 17 00:00:00 2001 From: Markus Amend Date: Wed, 16 May 2012 17:05:58 +0200 Subject: [PATCH] MPLS --- src/dissector_eth.c | 1 + src/examples/pcap/mpls-basic.pcap | Bin 0 -> 5644 bytes src/netsniff-ng/CMakeLists.txt | 1 + src/proto_mpls_unicast.c | 71 ++++++++++++++++++++++++++++++++++++++ src/protos.h | 1 + 5 files changed, 74 insertions(+) create mode 100755 src/examples/pcap/mpls-basic.pcap create mode 100644 src/proto_mpls_unicast.c diff --git a/src/dissector_eth.c b/src/dissector_eth.c index a3a246c3..543226c5 100644 --- a/src/dissector_eth.c +++ b/src/dissector_eth.c @@ -85,6 +85,7 @@ static void dissector_init_layer_2(int type) INSERT_HASH_PROTOS(ipv4_ops, eth_lay2); INSERT_HASH_PROTOS(ipv6_ops, eth_lay2); INSERT_HASH_PROTOS(QinQ_ops, eth_lay2); + INSERT_HASH_PROTOS(mpls_uc_ops, eth_lay2); for_each_hash_int(ð_lay2, dissector_set_print_type, type); } diff --git a/src/examples/pcap/mpls-basic.pcap b/src/examples/pcap/mpls-basic.pcap new file mode 100755 index 0000000000000000000000000000000000000000..75275d148df28b5e9f29abd88d7b00dbf2618291 GIT binary patch literal 5644 zcwV)be{54#6vxkd?d!U?cI{-aqSHQpsNL8`+mX2qFvuJR6J#=i7)0r|vK3f6+m5kl z{1F8GLk%&8fDR3WK>{So;-U!=i7udFs1O*+4>J{EPQnkB=;*e3&h1|J=(^TI_m}2Q`EbBLIhA8L5Yg|6B_2Foez^JHWbGuoP>d{18~FGncWi zU*vd>+V~^<5y<{#5QiH@jv$=QpaL~rXCkc~R3m8@`%7-21(3!M)4mQcn#5?|Gny2l zZBPsFIF6x{gJ%Im1#K45_@zg;5v?2Bc;U)!xb?`vVLB!gz<>s5bsWdYtG^Q%fI%2D z^tlN_&ivnlSQFaQMyiw@lvRE}4t6J?ay*h7-bqb7HUo;-=;hd$kaotQO*}SzirAcx zV?(s|p42gj%|s;src=RMd`M?FHn{3H9s}-pupFQU=Yk;Dx{6jVP6kd3rA=aqW*Xy~ z3oG^>yR$!10Y(*g5$6r5!1=@L8&WX9?OsK*lL~;jNmo#m5!Z(_=7US&!&ih@S#zhnOqfzvts(7V?NX=d`P;27E@dw^vs7^g%5sl zR&rIWyCgo3 zrKdEB?+*Qn-637x9f(%FC}j+GvAdCc@H3TiuMIhcpNa0Z*~oIdr-4cwL?=$y+1VLl zapimVr~q^l@Shwd5k|kG*4Olq-CC4iXagQH5P*6*X~7r{6&T9>bxyC_>9yrD`TNq{^3vs;djI zdwqjzjk88tT-S(z{CUo*eC%zrm(D1pF`+3y0~w*ww3c&#AY&*Uu(OK*xXda#wf>zXlJj9V-Oo6zyGv8tTS>eIUhuN9yJ6t zJ1@ywNp2rxZLu2y^n3+xly=O)+10#>Xy#}1BVTl~pNur1*>x$rC1mCHy>;sCok;6n zahFlr&>kZ3YGO@Yt{<5-N@W&W4l3)7P}Yyk)(WFh+S)}!iPeIvGQ2JujYTg=Vs%Gl znT%5NK5QRQ1q0?_U=ks_#)i1HVpQT8ZBW@@(40bL8mL|g{9l-XRW~cyD@ERfQReD&4v}MukTR@RT`#K`* z+fR!{T-JKT=|#O*;qduzv#XK3&gUClUT007RMqI0+#a`6@;Uu_aSBfLcMdmtg0qO@ zR6P+>b>UQ*7;){^R(UF7oz3IoWl&1g7-bT(!f3d<^&kzMiY!kD50vd)QCPZZi}loJ9QM(wL+^MFgUV4K?a(`4WZ%L$?5N#9*ZdXO z$eyV`etqcvjiGyCXq6qGC#Q}g*7%F*vE9$5iU{5RIjZ|6!__zUP&A44(WUfQS)q>l z+6!gHM9hj7fMM2CJ#lndAeHI*B|_H(WS(YOaX?<K2)D>oBUXICnk+G)7XWdVw z+Tq*yedsSmaq)v(Ts(lZrVn*vP+UBS + * Subject to the GPL, version 2. + * + * http://tools.ietf.org/html/rfc3032 + */ + +#include +#include +#include /* for ntohs() */ + +#include "proto.h" +#include "protos.h" +#include "dissector_eth.h" +#include "pkt_buff.h" + +struct mpls_uchdr { + uint32_t mpls_uc_hdr; +} __attribute__((packed)); + +static void mpls_uc_full(struct pkt_buff *pkt) +{ + uint8_t s = 0; + uint16_t mpls_uc_data; + + do { + struct mpls_uchdr *mpls_uc = (struct mpls_uchdr *) pkt_pull(pkt, + sizeof(*mpls_uc)); + + if (mpls_uc == NULL) + return; +tprintf("%x\n",mpls_uc->mpls_uc_hdr); + mpls_uc_data = ntohl(mpls_uc->mpls_uc_hdr); + s = (mpls_uc_data >> 8) & 0x1; +tprintf("%x\n",mpls_uc_data); +tprintf("%x",mpls_uc->mpls_uc_hdr); + tprintf(" [ MPLS "); + tprintf("Label (%u), ", mpls_uc_data >> 12); + tprintf("Exp (%u), ", (mpls_uc_data >> 9) & 0x3); + tprintf("S (%u), ", s); + tprintf("TTL (%u), ", (mpls_uc_data & 0xFF)); + tprintf(" ]\n"); + }while(!s); + +// pkt_set_proto(pkt, ð_lay2, ntohs(mpls_uc->TPID)); +} + +static void mpls_uc_less(struct pkt_buff *pkt) +{ +// uint16_t mpls_uc_data; +// struct mpls_uchdr *mpls_uc = (struct mpls_uchdr *) pkt_pull(pkt, +// sizeof(*mpls_uc)); +// +// if (mpls_uc == NULL) +// return; +// +// mpls_uc_data = ntohs(mpls_uc->TCI); +// +// tprintf(" VLAN%d", (mpls_uc_data & 0x0FFF)); +// +// pkt_set_proto(pkt, ð_lay2, ntohs(mpls_uc->TPID)); +} + +struct protocol mpls_uc_ops = { + .key = 0x8847, + .print_full = mpls_uc_full, + .print_less = mpls_uc_less, +}; + +EXPORT_SYMBOL(mpls_uc_ops); diff --git a/src/protos.h b/src/protos.h index 0319047e..11550e69 100644 --- a/src/protos.h +++ b/src/protos.h @@ -32,5 +32,6 @@ extern struct protocol udp_ops; extern struct protocol vlan_ops; extern struct protocol ieee80211_ops; extern struct protocol QinQ_ops; +extern struct protocol mpls_uc_ops; #endif /* PROTOS_H */ -- 2.11.4.GIT