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

📄 _ospf6.c

📁 This directory contains source code for tcpdump, a tool for network monitoring and data acquisition
💻 C
📖 第 1 页 / 共 2 页
字号:
             goto trunc;
           lsapp = (struct lsa_prefix *) (((u_char *) lsapp) + k);
         }
         break;

#if 0
    case LS_TYPE_SUM_ABR:
         TCHECK (lsap->lsa_un.un_sla.sla_tosmetric);
         lp = lsap->lsa_un.un_sla.sla_tosmetric;
         while ((u_char *) lp < ls_end)
         {
           u_int32_t ul;

           TCHECK (*lp);
           ul = ntohl (*lp);
           PRINTF (" tos %d metric %d",
                   (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS,
                   ul & SLA_MASK_METRIC);
           ++lp;
         }
         break;

    case LS_TYPE_ASE:
         TCHECK (lsap->lsa_un.un_nla.nla_mask);
         PRINTF (" mask %s", ipaddr_string (&lsap->lsa_un.un_asla.asla_mask));

         TCHECK (lsap->lsa_un.un_sla.sla_tosmetric);
         almp = lsap->lsa_un.un_asla.asla_metric;
         while ((u_char *) almp < ls_end)
         {
           u_int32_t ul;

           TCHECK (almp->asla_tosmetric);
           ul = ntohl (almp->asla_tosmetric);
           PRINTF (" type %d tos %d metric %d",
                   (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1,
                   (ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS,
                   (ul & ASLA_MASK_METRIC));
           TCHECK (almp->asla_forward);
           if (almp->asla_forward.s_addr)
              PRINTF (" forward %s", ipaddr_string (&almp->asla_forward));

           TCHECK (almp->asla_tag);
           if (almp->asla_tag.s_addr)
              PRINTF (" tag %s", ipaddr_string (&almp->asla_tag));
           ++almp;
         }
         break;

    case LS_TYPE_GROUP:
         /* Multicast extensions as of 23 July 1991 */
         mcp = lsap->lsa_un.un_mcla;
         while ((u_char *) mcp < ls_end)
         {
           TCHECK (mcp->mcla_vid);
           switch (ntohl (mcp->mcla_vtype))
           {
             case MCLA_VERTEX_ROUTER:
                  PRINTF (" rtr rtrid %s", ipaddr_string (&mcp->mcla_vid));
                  break;

             case MCLA_VERTEX_NETWORK:
                  PRINTF (" net dr %s", ipaddr_string (&mcp->mcla_vid));
                  break;

             default:
                  PRINTF (" ??VertexType %lu??", ntohl (mcp->mcla_vtype));
                  break;
           }
           ++mcp;
         }
#endif

    case LS_TYPE_LINK:
         /* Link LSA */
         llsap = &lsap->lsa_un.un_llsa;
         TCHECK (llsap->llsa_options);
         ospf6_print_bits (ospf6_option_bits, ntohl (llsap->llsa_options));
         TCHECK (llsap->llsa_nprefix);
         PRINTF (" pri %d lladdr %s npref %lu",
                 llsap->llsa_priority,
                 ip6addr_string (&llsap->llsa_lladdr),
                 ntohl (llsap->llsa_nprefix));
         lsapp = llsap->llsa_prefix;
         for (j = 0; j < ntohl (llsap->llsa_nprefix); j++)
         {
           k = ospf6_print_lsaprefix (lsapp);
           if (k < 0)
             goto trunc;
           lsapp = (struct lsa_prefix *) (((u_char *) lsapp) + k);
         }
         break;

    case LS_TYPE_INTRA_AP | LS_SCOPE_AREA:
         /* Intra-Area-Prefix LSA */
         TCHECK (lsap->lsa_un.un_intra_ap.intra_ap_rtid);
         ospf6_print_ls_type (ntohs (lsap->lsa_un.un_intra_ap.intra_ap_lstype),
                              &lsap->lsa_un.un_intra_ap.intra_ap_lsid,
                              &lsap->lsa_un.un_intra_ap.intra_ap_rtid,
                              "LinkStateType %d");
         TCHECK (lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
         PRINTF (" npref %d", ntohs (lsap->lsa_un.un_intra_ap.intra_ap_nprefix));

         lsapp = lsap->lsa_un.un_intra_ap.intra_ap_prefix;
         for (j = 0; j < ntohs (lsap->lsa_un.un_intra_ap.intra_ap_nprefix); j++)
         {
           k = ospf6_print_lsaprefix (lsapp);
           if (k < 0)
             goto trunc;
           lsapp = (struct lsa_prefix *) (((u_char *) lsapp) + k);
         }
         break;

    default:
         PRINTF (" ??LinkStateType 0x%04x??", ntohs (lsap->ls_hdr.ls_type));
  }

  PUTS (" }");
  return (0);
trunc:
  PUTS (" }");
  return (1);
}

static int ospf6_decode_v3 (const struct ospf6hdr *op, const u_char * dataend)
{
  const rtrid_t        *ap;
  const struct lsr     *lsrp;
  const struct lsa_hdr *lshp;
  const struct lsa     *lsap;
  char  sep;
  int   i;

  switch (op->ospf6_type)
  {
    case OSPF_TYPE_UMD:
         /*
          * Rob Coltun's special monitoring packets;
          * do nothing
          */
         break;

    case OSPF_TYPE_HELLO:
         if (vflag)
         {
           TCHECK (op->ospf6_hello.hello_deadint);
           ospf6_print_bits (ospf6_option_bits,
                             ntohl (op->ospf6_hello.hello_options));
           PRINTF (" ifid %s pri %d int %d dead %u",
                   ipaddr_string (&op->ospf6_hello.hello_ifid),
                   op->ospf6_hello.hello_priority,
                   ntohs (op->ospf6_hello.hello_helloint),
                   ntohs (op->ospf6_hello.hello_deadint));
         }
         TCHECK (op->ospf6_hello.hello_dr);
         if (op->ospf6_hello.hello_dr != 0)
            PRINTF (" dr %s", ipaddr_string (&op->ospf6_hello.hello_dr));

         TCHECK (op->ospf6_hello.hello_bdr);
         if (op->ospf6_hello.hello_bdr != 0)
            PRINTF (" bdr %s", ipaddr_string (&op->ospf6_hello.hello_bdr));
         if (vflag)
         {
           PUTS (" nbrs");
           ap = op->ospf6_hello.hello_neighbor;
           while ((u_char *) ap < dataend)
           {
             TCHECK (*ap);
             PRINTF (" %s", ipaddr_string (ap));
             ++ap;
           }
         }
         break;                  /* HELLO */

    case OSPF_TYPE_DB:
         TCHECK (op->ospf6_db.db_options);
         ospf6_print_bits (ospf6_option_bits, ntohl (op->ospf6_db.db_options));
         sep = ' ';
         TCHECK (op->ospf6_db.db_flags);
         if (op->ospf6_db.db_flags & OSPF6_DB_INIT)
         {
           PRINTF ("%cI", sep);
           sep = '/';
         }
         if (op->ospf6_db.db_flags & OSPF6_DB_MORE)
         {
           PRINTF ("%cM", sep);
           sep = '/';
         }
         if (op->ospf6_db.db_flags & OSPF6_DB_MASTER)
         {
           PRINTF ("%cMS", sep);
           sep = '/';
         }
         TCHECK (op->ospf6_db.db_seq);
         PRINTF (" mtu %u S %lX",
                 ntohs (op->ospf6_db.db_mtu),
                 ntohl (op->ospf6_db.db_seq));

         if (vflag)
         {
           /* Print all the LS adv's */
           lshp = op->ospf6_db.db_lshdr;

           while (!ospf6_print_lshdr (lshp))
           {
             PUTS (" }");
             ++lshp;
           }
         }
         break;

    case OSPF_TYPE_LSR:
         if (vflag)
         {
           lsrp = op->ospf6_lsr;
           while ((u_char *) lsrp < dataend)
           {
             TCHECK (*lsrp);
             PUTS (" {");
             ospf6_print_ls_type (ntohs (lsrp->ls_type),
                                  &lsrp->ls_stateid, &lsrp->ls_router,
                                  "LinkStateType %d");
             PUTS (" }");
             ++lsrp;
           }
         }
         break;

    case OSPF_TYPE_LSU:
         if (vflag)
         {
           lsap = op->ospf6_lsu.lsu_lsa;
           TCHECK (op->ospf6_lsu.lsu_count);
           i = ntohl (op->ospf6_lsu.lsu_count);
           while (i--)
           {
             if (ospf6_print_lsa (lsap))
               goto trunc;
             lsap = (struct lsa *) ((u_char *) lsap + ntohs (lsap->ls_hdr.ls_length));
           }
         }
         break;

    case OSPF_TYPE_LSA:
         if (vflag)
         {
           lshp = op->ospf6_lsa.lsa_lshdr;
           while (!ospf6_print_lshdr (lshp))
           {
             PUTS (" }");
             ++lshp;
           }
         }
         break;

    default:
         PRINTF ("v3 type %d", op->ospf6_type);
         break;
  }
  return (0);
trunc:
  return (1);
}

void ospf6_print (const u_char * bp, u_int length)
{
  const struct ospf6hdr *op = (struct ospf6hdr*) bp;
  const u_char *dataend;
  const char   *cp;

  /* If the type is valid translate it, or just print the type
   * value.  If it's not valid, say so and return
   */
  TCHECK (op->ospf6_type);
  cp = tok2str (type2str, "type%d", op->ospf6_type);

  PRINTF (" OSPFv%d-%s %d:", op->ospf6_version, cp, length);
  if (*cp == 't')
     return;

  TCHECK (op->ospf6_len);
  if (length != ntohs (op->ospf6_len))
  {
    PRINTF (" [len %d]", ntohs (op->ospf6_len));
    return;
  }
  dataend = bp + length;

  /* Print the routerid if it is not the same as the source
   */
  TCHECK (op->ospf6_routerid);
  PRINTF (" rtrid %s", ipaddr_string (&op->ospf6_routerid));

  TCHECK (op->ospf6_areaid);
  if (op->ospf6_areaid != 0)
       PRINTF (" area %s", ipaddr_string (&op->ospf6_areaid));
  else PUTS (" backbone");

  TCHECK (op->ospf6_instanceid);
  if (op->ospf6_instanceid)
     PRINTF (" instance %u", op->ospf6_instanceid);

  /* Do rest according to version.
   */
  switch (op->ospf6_version)
  {
    case 3:
         /* ospf version 3 */
         if (ospf6_decode_v3 (op, dataend))
           goto trunc;
         break;

    default:
         PRINTF (" ospf [version %d]", op->ospf6_version);
         break;
  } 
  return;

trunc:
  PUTS (tstr);
}

#endif /* USE_INET6 */

⌨️ 快捷键说明

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