]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospfd: reduce ospf_verify_header()
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 28 Feb 2012 11:15:29 +0000 (15:15 +0400)
committerDavid Lamparter <equinox@diac24.net>
Mon, 12 Mar 2012 10:05:45 +0000 (11:05 +0100)
Protocol version checks fits ospf_packet_examin() better (like it is
implemented in ospf6d), and packet type check is already there.

ospfd/ospf_packet.c

index 4842c4e2eae1a4a08b1f620882a1181f620ff93b..351fb210b1379315dbe2cdfd67663c61f6a9ea8c 100644 (file)
@@ -2587,6 +2587,12 @@ ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire)
   /* Now it is safe to access header fields. Performing length check, allow
    * for possible extra bytes of crypto auth/padding, which are not counted
    * in the OSPF header "length" field. */
+  if (oh->version != OSPF_VERSION)
+  {
+    if (IS_DEBUG_OSPF_PACKET (0, RECV))
+      zlog_debug ("%s: invalid (%u) protocol version", __func__, oh->version);
+    return MSG_NG;
+  }
   bytesdeclared = ntohs (oh->length);
   if (ntohs (oh->auth_type) != OSPF_AUTH_CRYPTOGRAPHIC)
     bytesauth = 0;
@@ -2682,21 +2688,6 @@ static int
 ospf_verify_header (struct stream *ibuf, struct ospf_interface *oi,
                    struct ip *iph, struct ospf_header *ospfh)
 {
-  /* check version. */
-  if (ospfh->version != OSPF_VERSION)
-    {
-      zlog_warn ("interface %s: ospf_read version number mismatch.",
-                IF_NAME (oi));
-      return -1;
-    }
-
-  /* Valid OSPFv2 packet types are 1 through 5 inclusive. */
-  if (ospfh->type < 1 || ospfh->type > 5)
-  {
-    zlog_warn ("interface %s: invalid packet type %u", IF_NAME (oi), ospfh->type);
-    return -1;
-  }
-
   /* Check Area ID. */
   if (!ospf_check_area_id (oi, ospfh))
     {