Text   |  XML   |  ReML   |   Visible Warnings:

Ignored Return Value  at packet-clnp.c:271

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

dissect_clnp

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-clnp.c)expand/collapse
Show more  
 191  static void dissect_clnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 192  {
 193    proto_tree *clnp_tree = NULL;
 194    proto_item *ti;
 195    guint8      cnf_proto_id;
 196    guint8      cnf_hdr_len;
 197    guint8      cnf_vers;
 198    guint8      cnf_ttl;
 199    guint8      cnf_type;
 200    char        flag_string[6+1];
 201    const char *pdu_type_string;
 202    proto_tree *type_tree;
 203    guint16     segment_length;
 204    guint16     du_id = 0;
 205    guint16     segment_offset = 0;
 206    guint16     cnf_cksum;
 207    cksum_status_t cksum_status;
 208    int         offset;
 209    guchar      src_len, dst_len, nsel, opt_len = 0;
 210    const guint8     *dst_addr, *src_addr;
 211    gint        len;
 212    guint       next_length;
 213    proto_tree *discpdu_tree;
 214    gboolean    save_in_error_pkt;
 215    fragment_data *fd_head;
 216    tvbuff_t   *next_tvb;
 217    gboolean    update_col_info = TRUE;
 218    gboolean    save_fragmented;
 219   
 220    if (check_col(pinfo->cinfo, COL_PROTOCOL))
 221      col_set_str(pinfo->cinfo, COL_PROTOCOL, "CLNP");
 222    if (check_col(pinfo->cinfo, COL_INFO))
 223      col_clear(pinfo->cinfo, COL_INFO);
 224   
 225    cnf_proto_id = tvb_get_guint8(tvb, P_CLNP_PROTO_ID);
 226    if (cnf_proto_id == NLPID_NULL) {
 227      if (check_col(pinfo->cinfo, COL_INFO))
 228        col_set_str(pinfo->cinfo, COL_INFO, "Inactive subset");
 229      if (tree) {
 230        ti = proto_tree_add_item(tree, proto_clnp, tvb, P_CLNP_PROTO_ID, 1, FALSE);
 231        clnp_tree = proto_item_add_subtree(ti, ett_clnp);
 232        proto_tree_add_uint_format(clnp_tree, hf_clnp_id, tvb, P_CLNP_PROTO_ID, 1,
 233                                   cnf_proto_id,
 234                                   "Inactive subset");
 235      }
 236      next_tvb = tvb_new_subset(tvb, 1, -1, -1);
 237      if (call_dissector(ositp_inactive_handle, next_tvb, pinfo, tree) == 0)
 238        call_dissector(data_handle,tvb, pinfo, tree);
 239      return;
 240    }
 241   
 242    /* return if version not known */
 243    cnf_vers = tvb_get_guint8(tvb, P_CLNP_VERS);
 244    if (cnf_vers != ISO8473_V1) {
 245      call_dissector(data_handle,tvb, pinfo, tree);
 246      return;
 247    }
 248   
 249    /* fixed part decoding */
 250    cnf_hdr_len = tvb_get_guint8(tvb, P_CLNP_HDR_LEN);
 251    opt_len = cnf_hdr_len;
 252   
 253    if (tree) {
 254      ti = proto_tree_add_item(tree, proto_clnp, tvb, 0, cnf_hdr_len, FALSE);
 255      clnp_tree = proto_item_add_subtree(ti, ett_clnp);
 256      proto_tree_add_uint(clnp_tree, hf_clnp_id, tvb, P_CLNP_PROTO_ID, 1,
 257                                 cnf_proto_id);
 258      proto_tree_add_uint(clnp_tree, hf_clnp_length, tvb, P_CLNP_HDR_LEN, 1,
 259                          cnf_hdr_len);
 260      proto_tree_add_uint(clnp_tree, hf_clnp_version, tvb, P_CLNP_VERS, 1,
 261                          cnf_vers);
 262      cnf_ttl = tvb_get_guint8(tvb, P_CLNP_TTL);
 263      proto_tree_add_uint_format(clnp_tree, hf_clnp_ttl, tvb, P_CLNP_TTL, 1,
 264                                 cnf_ttl,
 265                                 "Holding Time : %u (%u.%u secs)",
 266                                 cnf_ttl, cnf_ttl / 2, (cnf_ttl % 2) * 5);
 267    }
 268   
 269    cnf_type = tvb_get_guint8(tvb, P_CLNP_TYPE);
 270    pdu_type_string = val_to_str(cnf_type & CNF_TYPE, npdu_type_abbrev_vals,
 271                                  "Unknown (0x%02x)");
 272    flag_string[0] = '\0';
 273    if (cnf_type & CNF_SEG_OK)
 274      g_strlcat(flag_string, "S ", 7);
 275    if (cnf_type & CNF_MORE_SEGS)
 276      g_strlcat(flag_string, "M ", 7);
 277    if (cnf_type & CNF_ERR_OK)
 278      g_strlcat(flag_string, "E ", 7);
 279    if (tree) {
 280      ti = proto_tree_add_uint_format(clnp_tree, hf_clnp_type, tvb, P_CLNP_TYPE, 1,
 281                                 cnf_type,
 282                                 "PDU Type     : 0x%02x (%s%s)",
 283                                 cnf_type,
 284                                 flag_string,
 285                                 pdu_type_string);
 286      type_tree = proto_item_add_subtree(ti, ett_clnp_type);
 287      proto_tree_add_text(type_tree, tvb, P_CLNP_TYPE, 1, "%s",
 288                          decode_boolean_bitfield(cnf_type, CNF_SEG_OK, 8,
 289                                        "Segmentation permitted",
 290                                        "Segmentation not permitted"));
 291      proto_tree_add_text(type_tree, tvb, P_CLNP_TYPE, 1, "%s",
 292                          decode_boolean_bitfield(cnf_type, CNF_MORE_SEGS, 8,
 293                                        "More segments",
 294                                        "Last segment"));
 295      proto_tree_add_text(type_tree, tvb, P_CLNP_TYPE, 1, "%s",
 296                          decode_boolean_bitfield(cnf_type, CNF_ERR_OK, 8,
 297                                        "Report error if PDU discarded",
 298                                        "Don't report error if PDU discarded"));
 299      proto_tree_add_text(type_tree, tvb, P_CLNP_TYPE, 1, "%s",
 300                          decode_enumerated_bitfield(cnf_type, CNF_TYPE, 8,
 301                                        npdu_type_vals, "%s"));
 302    }
 303   
 304    /* If we don't have the full header - i.e., not enough to see the 
 305       segmentation part and determine whether this datagram is segmented
 306       or not - set the Info column now; we'll get an exception before
 307       we set it otherwise. */
 308   
 309    if (tvb_length(tvb) < cnf_hdr_len) {
 310      if (check_col(pinfo->cinfo, COL_INFO))
 311        col_add_fstr(pinfo->cinfo, COL_INFO, "%s NPDU %s", pdu_type_string, flag_string);
 312    }
 313   
 314    segment_length = tvb_get_ntohs(tvb, P_CLNP_SEGLEN);
 315    cnf_cksum = tvb_get_ntohs(tvb, P_CLNP_CKSUM);
 316    cksum_status = calc_checksum(tvb, 0, cnf_hdr_len, cnf_cksum);
 317    if (tree) {
 318      proto_tree_add_uint(clnp_tree, hf_clnp_pdu_length, tvb, P_CLNP_SEGLEN, 2,
 319                          segment_length);
 320      switch (cksum_status) {
 321   
 322      default:
 323          /*
 324           * No checksum present, or not enough of the header present to
 325           * checksum it.
 326           */
 327          proto_tree_add_uint_format(clnp_tree, hf_clnp_checksum, tvb,
 328                                 P_CLNP_CKSUM, 2,
 329                                 cnf_cksum,
 330                                 "Checksum     : 0x%04x",
 331                                 cnf_cksum);
 332          break;
 333   
 334      case CKSUM_OK:
 335          /*
 336           * Checksum is correct.
 337           */
 338          proto_tree_add_uint_format(clnp_tree, hf_clnp_checksum, tvb,
 339                                 P_CLNP_CKSUM, 2,
 340                                 cnf_cksum,
 341                                 "Checksum     : 0x%04x (correct)",
 342                                 cnf_cksum);
 343          break;
 344   
 345      case CKSUM_NOT_OK:
 346          /*
 347           * Checksum is not correct.
 348           */
 349          proto_tree_add_uint_format(clnp_tree, hf_clnp_checksum, tvb,
 350                                 P_CLNP_CKSUM, 2,
 351                                 cnf_cksum,
 352                                 "Checksum     : 0x%04x (incorrect)",
 353                                 cnf_cksum);
 354          break;
 355      }
 356      opt_len -= 9; /* Fixed part of Hesder */
 357    } /* tree */
 358   
 359    /* address part */
 360   
 361    offset = P_CLNP_ADDRESS_PART;
 362    dst_len  = tvb_get_guint8(tvb, offset);
 363    dst_addr = tvb_get_ptr(tvb, offset + 1, dst_len);
 364    nsel     = tvb_get_guint8(tvb, offset + dst_len);
 365    src_len  = tvb_get_guint8(tvb, offset + dst_len + 1);
 366    src_addr = tvb_get_ptr(tvb, offset + dst_len + 2, src_len);
 367   
 368    if (tree) {
 369      proto_tree_add_uint(clnp_tree, hf_clnp_dest_length, tvb, offset, 1,
 370                          dst_len);
 371      proto_tree_add_bytes_format(clnp_tree, hf_clnp_dest, tvb, offset + 1 , dst_len,
 372                                 dst_addr,
 373                                 " DA : %s",
 374                                 print_nsap_net(dst_addr, dst_len));
 375      proto_tree_add_uint(clnp_tree, hf_clnp_src_length, tvb,
 376                          offset + 1 + dst_len, 1, src_len);
 377      proto_tree_add_bytes_format(clnp_tree, hf_clnp_src, tvb,
 378                                 offset + dst_len + 2, src_len,
 379                                 src_addr,
 380                                 " SA : %s",
 381                                 print_nsap_net(src_addr, src_len));
 382   
 383      opt_len -= dst_len + src_len +2;
 384    }
 385   
 386    SET_ADDRESS(&pinfo->net_src, AT_OSI, src_len, src_addr);
 387    SET_ADDRESS(&pinfo->src, AT_OSI, src_len, src_addr);
 388    SET_ADDRESS(&pinfo->net_dst, AT_OSI, dst_len, dst_addr);
 389    SET_ADDRESS(&pinfo->dst, AT_OSI, dst_len, dst_addr);
 390   
 391    /* Segmentation Part */
 392   
 393    offset += dst_len + src_len + 2;
 394   
 395    if (cnf_type & CNF_SEG_OK) {
 396      struct clnp_segment seg;                    /* XXX - not used */
 397      tvb_memcpy(tvb, (guint8 *)&seg, offset, sizeof(seg));       /* XXX - not used */
 398   
 399      segment_offset = tvb_get_ntohs(tvb, offset + 2);
 400      du_id = tvb_get_ntohs(tvb, offset);
 401      if (tree) {
 402        proto_tree_add_text(clnp_tree, tvb, offset, 2,
 403                          "Data unit identifier: %06u",
 404                          du_id);
 405        proto_tree_add_text(clnp_tree, tvb, offset + 2 , 2,
 406                          "Segment offset      : %6u",
 407                          segment_offset);
 408        proto_tree_add_text(clnp_tree, tvb, offset + 4 , 2,
 409                          "Total length        : %6u",
 410                          tvb_get_ntohs(tvb, offset + 4));
 411      }
 412   
 413      offset  += 6;
 414      opt_len -= 6;
 415    }
 416   
 417    if (tree) {
 418      /* To do : decode options  */
 419  /*
 420      proto_tree_add_text(clnp_tree, tvb, offset,
 421                          cnf_hdr_len - offset,
 422                          "Options/Data: <not shown>");
 423  */
 424  /* QUICK HACK Option Len:= PDU_Hd_length-( FixedPart+AddresPart+SegmentPart )*/
 425   
 426      dissect_osi_options( opt_len,
 427                           tvb, offset, clnp_tree );
 428    }
 429   
 430    /* Length of CLNP datagram plus headers above it. */
 431    len = segment_length;
 432   
 433    offset = cnf_hdr_len;
 434   
 435    /* If clnp_reassemble is on, this is a segment, we have all the
 436     * data in the segment, and the checksum is valid, then just add the
 437     * segment to the hashtable.
 438     */
 439    save_fragmented = pinfo->fragmented;
 440    if (clnp_reassemble && (cnf_type & CNF_SEG_OK) &&
 441          ((cnf_type & CNF_MORE_SEGS) || segment_offset != 0) &&
 442          tvb_bytes_exist(tvb, offset, segment_length - cnf_hdr_len) &&
 443          segment_length > cnf_hdr_len &&
 444          cksum_status != CKSUM_NOT_OK) {
 445      fd_head = fragment_add_check(tvb, offset, pinfo, du_id, clnp_segment_table,
 446                             clnp_reassembled_table, segment_offset,
 447                             segment_length - cnf_hdr_len,
 448                             cnf_type & CNF_MORE_SEGS);
 449   
 450      next_tvb = process_reassembled_data(tvb, offset, pinfo, "Reassembled CLNP",
 451          fd_head, &clnp_frag_items, &update_col_info, clnp_tree);
 452    } else {
 453      /* If this is the first segment, dissect its contents, otherwise 
 454         just show it as a segment.
 455   
 456         XXX - if we eventually don't save the reassembled contents of all
 457         segmented datagrams, we may want to always reassemble. */
 458      if ((cnf_type & CNF_SEG_OK) && segment_offset != 0) {
 459        /* Not the first segment - don't dissect it. */
 460        next_tvb = NULL;
 461      } else {
 462        /* First segment, or not segmented.  Dissect what we have here. */
 463   
 464        /* Get a tvbuff for the payload. */
 465        next_tvb = tvb_new_subset(tvb, offset, -1, -1);
 466   
 467        /*
 468         * If this is the first segment, but not the only segment,
 469         * tell the next protocol that.
 470         */
 471        if ((cnf_type & (CNF_SEG_OK|CNF_MORE_SEGS)) == (CNF_SEG_OK|CNF_MORE_SEGS))
 472          pinfo->fragmented = TRUE;
 473        else 
 474          pinfo->fragmented = FALSE;
 475      }
 476    }
 477   
 478    if (next_tvb == NULL) {
 479      /* Just show this as a segment. */
 480      if (check_col(pinfo->cinfo, COL_INFO))
 481        col_add_fstr(pinfo->cinfo, COL_INFO, "Fragmented %s NPDU %s(off=%u)",
 482                  pdu_type_string, flag_string, segment_offset);
 483   
 484      /* As we haven't reassembled anything, we haven't changed "pi", so 
 485         we don't have to restore it. */
 486      call_dissector(data_handle, tvb_new_subset(tvb, offset, -1, -1), pinfo,
 487                     tree);
 488      pinfo->fragmented = save_fragmented;
 489      return;
 490    }
 491   
 492    if (tvb_offset_exists(tvb, offset)) {
 493      switch (cnf_type & CNF_TYPE) {
 494   
 495      case DT_NPDU:
 496      case MD_NPDU:
 497        /* Continue with COTP if any data.
 498           XXX - if this isn't the first Derived PDU of a segmented Initial
 499           PDU, skip that? */
 500   
 501        if (nsel == (char)tp_nsap_selector || always_decode_transport) {
 502          if (call_dissector(ositp_handle, next_tvb, pinfo, tree) != 0) {
 503            pinfo->fragmented = save_fragmented;
 504            return;       /* yes, it appears to be COTP or CLTP */
 505          }
 506        }
 507        if (dissector_try_heuristic(clnp_heur_subdissector_list, next_tvb,
 508                                    pinfo, tree)) {
 509            pinfo->fragmented = save_fragmented;
 510            return;       /* yes, it appears to be one of the protocols in the heuristic list */
 511        }
 512   
 513        break;
 514   
 515      case ER_NPDU:
 516        /* The payload is the header and "none, some, or all of the data 
 517           part of the discarded PDU", i.e. it's like an ICMP error;
 518           dissect it as a CLNP PDU. */
 519        if (check_col(pinfo->cinfo, COL_INFO))
 520          col_add_fstr(pinfo->cinfo, COL_INFO, "%s NPDU %s", pdu_type_string, flag_string);
 521        if (tree) {
 522          next_length = tvb_length_remaining(tvb, offset);
 523          if (next_length != 0) {
 524            /* We have payload; dissect it. */
 525            ti = proto_tree_add_text(clnp_tree, tvb, offset, next_length,
 526              "Discarded PDU");
 527            discpdu_tree = proto_item_add_subtree(ti, ett_clnp_disc_pdu);
 528   
 529            /* Save the current value of the "we're inside an error packet"
 530               flag, and set that flag; subdissectors may treat packets
 531               that are the payload of error packets differently from
 532               "real" packets. */
 533            save_in_error_pkt = pinfo->in_error_pkt;
 534            pinfo->in_error_pkt = TRUE;
 535   
 536            call_dissector(clnp_handle, next_tvb, pinfo, discpdu_tree);
 537   
 538            /* Restore the "we're inside an error packet" flag. */
 539            pinfo->in_error_pkt = save_in_error_pkt;
 540          }
 541        }
 542        pinfo->fragmented = save_fragmented;
 543        return;   /* we're done with this PDU */
 544   
 545      case ERQ_NPDU:
 546      case ERP_NPDU:
 547        /* XXX - dissect this */
 548        break;
 549      }
 550    }
 551    if (check_col(pinfo->cinfo, COL_INFO))
 552      col_add_fstr(pinfo->cinfo, COL_INFO, "%s NPDU %s", pdu_type_string, flag_string);
 553    call_dissector(data_handle,next_tvb, pinfo, tree);
 554    pinfo->fragmented = save_fragmented;
 555  } /* dissect_clnp */
Show more  




Change Warning 12548.35733 : Ignored Return Value

Priority:
State:
Finding:
Owner:
Note: