Ethereal-dev: [Ethereal-dev] Patch for packet-ospf.c
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Kan Sasaki <sasaki@xxxxxxxxx>
Date: Wed, 07 Dec 2005 17:26:17 +0900 (JST)
Hello, A patch for packet-ospf.c is attached: - fix the handling of the DN-bit of options field - dissect the flags bitfield (only tested v2) Please find this patch. Regards, -- Fusion Communications Corp. Kan Sasaki sasaki@xxxxxxxxx
Index: packet-ospf.c =================================================================== --- packet-ospf.c (revision 16716) +++ packet-ospf.c (working copy) @@ -81,13 +81,13 @@ {0, NULL } }; -#define OSPF_V2_OPTIONS_DN 0x01 #define OSPF_V2_OPTIONS_E 0x02 #define OSPF_V2_OPTIONS_MC 0x04 #define OSPF_V2_OPTIONS_NP 0x08 #define OSPF_V2_OPTIONS_EA 0x10 #define OSPF_V2_OPTIONS_DC 0x20 #define OSPF_V2_OPTIONS_O 0x40 +#define OSPF_V2_OPTIONS_DN 0x80 #define OSPF_V3_OPTIONS_V6 0x01 #define OSPF_V3_OPTIONS_E 0x02 #define OSPF_V3_OPTIONS_MC 0x04 @@ -183,6 +183,9 @@ {0, NULL}, }; +#define OSPF_V2_ROUTER_LSA_FLAG_B 0x01 +#define OSPF_V2_ROUTER_LSA_FLAG_E 0x02 +#define OSPF_V2_ROUTER_LSA_FLAG_V 0x04 #define OSPF_V3_ROUTER_LSA_FLAG_B 0x01 #define OSPF_V3_ROUTER_LSA_FLAG_E 0x02 #define OSPF_V3_ROUTER_LSA_FLAG_V 0x04 @@ -218,6 +221,19 @@ static int hf_ospf_dbd_i = -1; static int hf_ospf_dbd_m = -1; static int hf_ospf_dbd_ms = -1; +static int hf_ospf_flags_v2 = -1; +static int hf_ospf_flags_v2_b = -1; +static int hf_ospf_flags_v2_e = -1; +static int hf_ospf_flags_v2_v = -1; +static int hf_ospf_flags_v3 = -1; +static int hf_ospf_flags_v3_b = -1; +static int hf_ospf_flags_v3_e = -1; +static int hf_ospf_flags_v3_v = -1; +static int hf_ospf_flags_v3_w = -1; +static int hf_ospf_flags_v3_asext = -1; +static int hf_ospf_flags_v3_asext_t = -1; +static int hf_ospf_flags_v3_asext_f = -1; +static int hf_ospf_flags_v3_asext_e = -1; static gint ett_ospf = -1; static gint ett_ospf_hdr = -1; @@ -230,6 +246,9 @@ static gint ett_ospf_options_v2 = -1; static gint ett_ospf_options_v3 = -1; static gint ett_ospf_dbd = -1; +static gint ett_ospf_flags_v2 = -1; +static gint ett_ospf_flags_v3 = -1; +static gint ett_ospf_flags_v3_asext = -1; /* Trees for opaque LSAs */ static gint ett_ospf_lsa_mpls = -1; @@ -259,7 +278,7 @@ "NOT multicast capable" }; static const true_false_string tfs_options_v2_e = { - "ExternalRoputingCapability", + "ExternalRoutingCapability", "NO ExternalRoutingCapability" }; static const true_false_string tfs_options_v2_o = { @@ -307,6 +326,46 @@ "MS is SET", "MS is NOT set" }; +static const true_false_string tfs_flags_v2_b = { + "Area border router", + "NO Area border router" +}; +static const true_false_string tfs_flags_v2_e = { + "AS boundary router", + "NO AS boundary router" +}; +static const true_false_string tfs_flags_v2_v = { + "Virtual link endpoint", + "NO Virtual link endpoint" +}; +static const true_false_string tfs_flags_v3_b = { + "Area border router", + "NO Area border router" +}; +static const true_false_string tfs_flags_v3_e = { + "AS boundary router", + "NO AS boundary router" +}; +static const true_false_string tfs_flags_v3_v = { + "Virtual link endpoint", + "NO Virtual link endpoint" +}; +static const true_false_string tfs_flags_v3_w = { + "Wild-card multicast receiver", + "NO Wild-card multicast receiver" +}; +static const true_false_string tfs_flags_v3_asext_t = { + "External Route Tag is included", + "External Route Tag is NOT included" +}; +static const true_false_string tfs_flags_v3_asext_f = { + "Forwarding Address is included", + "Forwarding Address is NOT included" +}; +static const true_false_string tfs_flags_v3_asext_e = { + "Type 2 external metric", + "Type 1 external metric" +}; /*----------------------------------------------------------------------- * OSPF Filtering @@ -520,6 +579,45 @@ {&hf_ospf_dbd_ms, { "MS", "ospf.dbd.ms", FT_BOOLEAN, 8, TFS(&tfs_dbd_ms), OSPF_DBD_FLAG_MS, "", HFILL }}, + {&hf_ospf_flags_v2, + { "Flags", "ospf.flags.v2", FT_UINT8, BASE_HEX, + NULL, 0x0, "", HFILL }}, + {&hf_ospf_flags_v2_b, + { "B", "ospf.flags.v2.b", FT_BOOLEAN, 8, + TFS(&tfs_flags_v2_b), OSPF_V2_ROUTER_LSA_FLAG_B, "", HFILL }}, + {&hf_ospf_flags_v2_e, + { "E", "ospf.flags.v2.e", FT_BOOLEAN, 8, + TFS(&tfs_flags_v2_e), OSPF_V2_ROUTER_LSA_FLAG_E, "", HFILL }}, + {&hf_ospf_flags_v2_v, + { "V", "ospf.flags.v2.v", FT_BOOLEAN, 8, + TFS(&tfs_flags_v2_v), OSPF_V2_ROUTER_LSA_FLAG_V, "", HFILL }}, + {&hf_ospf_flags_v3, + { "Flags", "ospf.flags.v3", FT_UINT8, BASE_HEX, + NULL, 0x0, "", HFILL }}, + {&hf_ospf_flags_v3_b, + { "B", "ospf.flags.v3.b", FT_BOOLEAN, 8, + TFS(&tfs_flags_v3_b), OSPF_V3_ROUTER_LSA_FLAG_B, "", HFILL }}, + {&hf_ospf_flags_v3_e, + { "E", "ospf.flags.v3.e", FT_BOOLEAN, 8, + TFS(&tfs_flags_v3_e), OSPF_V3_ROUTER_LSA_FLAG_E, "", HFILL }}, + {&hf_ospf_flags_v3_v, + { "V", "ospf.flags.v3.v", FT_BOOLEAN, 8, + TFS(&tfs_flags_v3_v), OSPF_V3_ROUTER_LSA_FLAG_V, "", HFILL }}, + {&hf_ospf_flags_v3_w, + { "W", "ospf.flags.v3.w", FT_BOOLEAN, 8, + TFS(&tfs_flags_v3_w), OSPF_V3_ROUTER_LSA_FLAG_W, "", HFILL }}, + {&hf_ospf_flags_v3_asext, + { "Flags", "ospf.flags.v3.asext", FT_UINT8, BASE_HEX, + NULL, 0x0, "", HFILL }}, + {&hf_ospf_flags_v3_asext_t, + { "T", "ospf.flags.v3.asext_t", FT_BOOLEAN, 8, + TFS(&tfs_flags_v3_asext_t), OSPF_V3_AS_EXTERNAL_FLAG_T, "", HFILL }}, + {&hf_ospf_flags_v3_asext_f, + { "F", "ospf.flags.v3.asext_f", FT_BOOLEAN, 8, + TFS(&tfs_flags_v3_asext_f), OSPF_V3_AS_EXTERNAL_FLAG_F, "", HFILL }}, + {&hf_ospf_flags_v3_asext_e, + { "E", "ospf.flags.v3.asext_e", FT_BOOLEAN, 8, + TFS(&tfs_flags_v3_asext_e), OSPF_V3_AS_EXTERNAL_FLAG_E, "", HFILL }}, }; @@ -560,6 +658,9 @@ static int dissect_ospf_v2_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body); static int dissect_ospf_v3_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body); +static void dissect_ospf_flags(tvbuff_t*, int, proto_tree*, guint8); +static void dissect_ospf_v3_flags_asext (proto_tree*, tvbuff_t*, int); + static void dissect_ospf_options(tvbuff_t *, int, proto_tree *, guint8); static void dissect_ospf_v3_prefix_options(tvbuff_t *, int, proto_tree *); @@ -1688,9 +1789,9 @@ switch (ls_type){ case OSPF_LSTYPE_ROUTER: - /* again: flags should be secified in detail */ - proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x", - tvb_get_guint8(tvb, offset)); + /* flags field in an router-lsa */ + dissect_ospf_flags(tvb, offset, ospf_lsa_tree, OSPF_VERSION_2); + nr_links = tvb_get_ntohs(tvb, offset + 2); proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "Number of Links: %u", nr_links); @@ -1903,9 +2004,6 @@ const char *link_type_str; guint32 metric; - guint8 router_lsa_flags; - char router_lsa_flags_string[5]; - guint8 router_priority; guint32 number_prefixes; guint8 prefix_length; @@ -1914,7 +2012,6 @@ guint16 referenced_ls_type; guint8 flags; - guint8 flags_string[4]; guint32 external_route_tag; @@ -1961,31 +2058,9 @@ case OSPF_V3_LSTYPE_ROUTER: + /* flags field in an router-lsa */ + dissect_ospf_flags(tvb, offset, ospf_lsa_tree, OSPF_VERSION_3); - /* flags field in an router-lsa */ - router_lsa_flags=tvb_get_guint8(tvb,offset); - if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_B) - router_lsa_flags_string[3] = 'B'; - else - router_lsa_flags_string[3] = '.'; - if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_E) - router_lsa_flags_string[2] = 'E'; - else - router_lsa_flags_string[2] = '.'; - if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_V) - router_lsa_flags_string[1] = 'V'; - else - router_lsa_flags_string[1] = '.'; - if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_W) - router_lsa_flags_string[0] = 'W'; - else - router_lsa_flags_string[0] = '.'; - - router_lsa_flags_string[4]=0; - - proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x (%s)", - router_lsa_flags, router_lsa_flags_string); - /* options field in an router-lsa */ dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3); @@ -2142,25 +2217,9 @@ case OSPF_V3_LSTYPE_AS_EXTERNAL: /* flags */ + dissect_ospf_v3_flags_asext(ospf_lsa_tree, tvb, offset); flags=tvb_get_guint8(tvb, offset); - if (flags & OSPF_V3_AS_EXTERNAL_FLAG_E) - flags_string[0] = 'E'; - else - flags_string[0] = '.'; - if (flags & OSPF_V3_AS_EXTERNAL_FLAG_F) - flags_string[1] = 'F'; - else - flags_string[1] = '.'; - if (flags & OSPF_V3_AS_EXTERNAL_FLAG_T) - flags_string[2] = 'T'; - else - flags_string[2] = '.'; - flags_string[3]=0; - - proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x (%s)", - flags, flags_string); - /* 24 bits metric */ metric=tvb_get_ntoh24(tvb, offset+1); proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 3, @@ -2313,8 +2372,128 @@ return offset; } +static void +dissect_ospf_v2_flags (proto_tree *parent_tree, tvbuff_t *tvb, int offset) +{ + proto_item *item=NULL; + proto_tree *tree=NULL; + guint8 flags; + flags = tvb_get_guint8 (tvb, offset); + if(parent_tree){ + item=proto_tree_add_uint(parent_tree, hf_ospf_flags_v2, + tvb, offset, 1, flags); + tree=proto_item_add_subtree(item, ett_ospf_flags_v2); + } + + proto_tree_add_boolean(tree, hf_ospf_flags_v2_v, tvb, offset, 1, flags); + if (flags&OSPF_V2_ROUTER_LSA_FLAG_V){ + proto_item_append_text(item, " V"); + } + flags&=(~( OSPF_V2_ROUTER_LSA_FLAG_V )); + + proto_tree_add_boolean(tree, hf_ospf_flags_v2_e, tvb, offset, 1, flags); + if (flags&OSPF_V2_ROUTER_LSA_FLAG_E){ + proto_item_append_text(item, " E"); + } + flags&=(~( OSPF_V2_ROUTER_LSA_FLAG_E )); + + proto_tree_add_boolean(tree, hf_ospf_flags_v2_b, tvb, offset, 1, flags); + if (flags&OSPF_V2_ROUTER_LSA_FLAG_B){ + proto_item_append_text(item, " B"); + } + flags&=(~( OSPF_V2_ROUTER_LSA_FLAG_B )); +} + static void +dissect_ospf_v3_flags (proto_tree *parent_tree, tvbuff_t *tvb, int offset) +{ + proto_item *item=NULL; + proto_tree *tree=NULL; + guint8 flags; + + flags = tvb_get_guint8 (tvb, offset); + if(parent_tree){ + item=proto_tree_add_uint(parent_tree, hf_ospf_flags_v3, + tvb, offset, 1, flags); + tree=proto_item_add_subtree(item, ett_ospf_flags_v3); + } + + proto_tree_add_boolean(tree, hf_ospf_flags_v3_w, tvb, offset, 1, flags); + if (flags&OSPF_V3_ROUTER_LSA_FLAG_W){ + proto_item_append_text(item, " W"); + } + flags&=(~( OSPF_V3_ROUTER_LSA_FLAG_V )); + + proto_tree_add_boolean(tree, hf_ospf_flags_v3_v, tvb, offset, 1, flags); + if (flags&OSPF_V3_ROUTER_LSA_FLAG_V){ + proto_item_append_text(item, " V"); + } + flags&=(~( OSPF_V3_ROUTER_LSA_FLAG_V )); + + proto_tree_add_boolean(tree, hf_ospf_flags_v3_e, tvb, offset, 1, flags); + if (flags&OSPF_V3_ROUTER_LSA_FLAG_E){ + proto_item_append_text(item, " E"); + } + flags&=(~( OSPF_V3_ROUTER_LSA_FLAG_E )); + + proto_tree_add_boolean(tree, hf_ospf_flags_v3_b, tvb, offset, 1, flags); + if (flags&OSPF_V3_ROUTER_LSA_FLAG_B){ + proto_item_append_text(item, " B"); + } + flags&=(~( OSPF_V3_ROUTER_LSA_FLAG_B )); +} + +static void +dissect_ospf_flags(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version) +{ + switch ( version ) { + + case OSPF_VERSION_2: + dissect_ospf_v2_flags(tree, tvb, offset); + break; + + + case OSPF_VERSION_3: + dissect_ospf_v3_flags(tree, tvb, offset); + break; + } +} + +static void +dissect_ospf_v3_flags_asext (proto_tree *parent_tree, tvbuff_t *tvb, int offset) +{ + proto_item *item=NULL; + proto_tree *tree=NULL; + guint8 flags; + + flags = tvb_get_guint8 (tvb, offset); + if(parent_tree){ + item=proto_tree_add_uint(parent_tree, hf_ospf_flags_v3_asext, + tvb, offset, 1, flags); + tree=proto_item_add_subtree(item, ett_ospf_flags_v3_asext); + } + + proto_tree_add_boolean(tree, hf_ospf_flags_v3_asext_e, tvb, offset, 1, flags); + if (flags&OSPF_V3_AS_EXTERNAL_FLAG_E){ + proto_item_append_text(item, " E"); + } + flags&=(~( OSPF_V3_AS_EXTERNAL_FLAG_E )); + + proto_tree_add_boolean(tree, hf_ospf_flags_v3_asext_f, tvb, offset, 1, flags); + if (flags&OSPF_V3_AS_EXTERNAL_FLAG_F){ + proto_item_append_text(item, " F"); + } + flags&=(~( OSPF_V3_AS_EXTERNAL_FLAG_F )); + + proto_tree_add_boolean(tree, hf_ospf_flags_v3_asext_t, tvb, offset, 1, flags); + if (flags&OSPF_V3_AS_EXTERNAL_FLAG_T){ + proto_item_append_text(item, " T"); + } + flags&=(~( OSPF_V3_AS_EXTERNAL_FLAG_T )); +} + +static void dissect_ospf_v2_options (proto_tree *parent_tree, tvbuff_t *tvb, int offset) { proto_item *item=NULL; @@ -2328,13 +2507,18 @@ tree=proto_item_add_subtree(item, ett_ospf_options_v2); } + proto_tree_add_boolean(tree, hf_ospf_options_v2_dn, tvb, offset, 1, flags); + if (flags&OSPF_V2_OPTIONS_DN){ + proto_item_append_text(item, " DN"); + } + flags&=(~( OSPF_V2_OPTIONS_DN )); + proto_tree_add_boolean(tree, hf_ospf_options_v2_o, tvb, offset, 1, flags); if (flags&OSPF_V2_OPTIONS_O){ proto_item_append_text(item, " O"); } flags&=(~( OSPF_V2_OPTIONS_O )); - proto_tree_add_boolean(tree, hf_ospf_options_v2_dc, tvb, offset, 1, flags); if (flags&OSPF_V2_OPTIONS_DC){ proto_item_append_text(item, " DC"); @@ -2364,12 +2548,6 @@ proto_item_append_text(item, " E"); } flags&=(~( OSPF_V2_OPTIONS_E )); - - proto_tree_add_boolean(tree, hf_ospf_options_v2_dn, tvb, offset, 1, flags); - if (flags&OSPF_V2_OPTIONS_DN){ - proto_item_append_text(item, " DN"); - } - flags&=(~( OSPF_V2_OPTIONS_DN )); } static void @@ -2543,7 +2721,10 @@ &ett_ospf_lsa_oif_tna_stlv, &ett_ospf_options_v2, &ett_ospf_options_v3, - &ett_ospf_dbd + &ett_ospf_dbd, + &ett_ospf_flags_v2, + &ett_ospf_flags_v3, + &ett_ospf_flags_v3_asext }; proto_ospf = proto_register_protocol("Open Shortest Path First",
- Prev by Date: Re: [Ethereal-dev] SSL decryption patch for ethereal 0.10.13
- Next by Date: [Ethereal-dev] Buildbot crash output
- Previous by thread: [Ethereal-dev] Re: [Ethereal-cvs] rev 16708: /trunk/epan/: oid_resolv.c
- Next by thread: [Ethereal-dev] MSVC Problems :)
- Index(es):