components/quagga/patches/07-cve-2012-0249.patch
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Wed, 29 Aug 2012 11:05:56 -0700
changeset 957 255465c5756f
parent 897 f239fb8865f3
permissions -rw-r--r--
Close of build 04.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
897
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
     1
The following patches are pulled directly from the GIT repository 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
     2
for the quagga community. They fix the following CVEs:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
     3
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
     4
CVE-2012-0249
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
     5
CVE-2012-0250
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
     6
CVE-2012-0255
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
     7
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
     8
All of the patched CVEs are included in Quagga 0.99.20.1. This patch
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
     9
file can be removed if Quagga is upgraded to that version.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    10
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    11
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    12
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    13
From 5861739f8c38bc36ea9955e5cb2be2bf2f482d70 Mon Sep 17 00:00:00 2001
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    14
From: Paul Jakma <[email protected]>
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    15
Date: Mon, 09 Jan 2012 20:59:26 +0000
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    16
Subject: bgpd: Open option parse errors don't NOTIFY, resulting in abort & DoS
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    17
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    18
* bgp_packet.c: (bgp_open_receive) Errors from bgp_open_option_parse are
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    19
  detected, and the code will stop processing the OPEN and return.  However
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    20
  it does so without calling bgp_notify_send to send a NOTIFY - which means
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    21
  the peer FSM doesn't get stopped, and bgp_read will be called again later.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    22
  Because it returns, it doesn't go through the code near the end of the
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    23
  function that removes the current message from the peer input streaam.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    24
  Thus the next call to bgp_read will try to parse a half-parsed stream as
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    25
  if it were a new BGP message, leading to an assert later in the code when
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    26
  it tries to read stuff that isn't there. Add the required call to
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    27
  bgp_notify_send before returning.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    28
* bgp_open.c: (bgp_capability_as4) Be a bit stricter, check the length field
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    29
  corresponds to the only value it can be, which is the amount we're going to
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    30
  read off the stream. And make sure the capability flag gets set, so
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    31
  callers can know this capability was read, regardless.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    32
  (peek_for_as4_capability) Let bgp_capability_as4 do the length check.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    33
---
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    34
diff --git bgpd/bgp_open.c bgpd/bgp_open.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    35
index 82deb3d..b5b50bb 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    36
--- bgpd/bgp_open.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    37
+++ bgpd/bgp_open.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    38
@@ -421,13 +421,20 @@ bgp_capability_restart (struct peer *peer, struct capability_header *caphdr)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    39
 static as_t
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    40
 bgp_capability_as4 (struct peer *peer, struct capability_header *hdr)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    41
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    42
+  SET_FLAG (peer->cap, PEER_CAP_AS4_RCV);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    43
+  
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    44
+  if (hdr->length != CAPABILITY_CODE_AS4_LEN)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    45
+    {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    46
+      zlog_err ("%s AS4 capability has incorrect data length %d",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    47
+                peer->host, hdr->length);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    48
+      return 0;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    49
+    }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    50
+  
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    51
   as_t as4 = stream_getl (BGP_INPUT(peer));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    52
   
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    53
   if (BGP_DEBUG (as4, AS4))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    54
     zlog_debug ("%s [AS4] about to set cap PEER_CAP_AS4_RCV, got as4 %u",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    55
                 peer->host, as4);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    56
-  SET_FLAG (peer->cap, PEER_CAP_AS4_RCV);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    57
-  
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    58
   return as4;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    59
 }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    60
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    61
@@ -689,9 +696,6 @@ peek_for_as4_capability (struct peer *peer, u_char length)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    62
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    63
 	      if (hdr.code == CAPABILITY_CODE_AS4)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    64
 	        {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    65
-	          if (hdr.length != CAPABILITY_CODE_AS4_LEN)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    66
-	            goto end;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    67
-                  
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    68
 	          if (BGP_DEBUG (as4, AS4))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    69
 	            zlog_info ("[AS4] found AS4 capability, about to parse");
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    70
 	          as4 = bgp_capability_as4 (peer, &hdr);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    71
diff --git bgpd/bgp_packet.c bgpd/bgp_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    72
index f5a74d1..5d8087a 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    73
--- bgpd/bgp_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    74
+++ bgpd/bgp_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    75
@@ -1459,9 +1459,13 @@ bgp_open_receive (struct peer *peer, bgp_size_t size)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    76
   /* Open option part parse. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    77
   if (optlen != 0) 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    78
     {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    79
-      ret = bgp_open_option_parse (peer, optlen, &capability);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    80
-      if (ret < 0)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    81
-	return ret;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    82
+      if ((ret = bgp_open_option_parse (peer, optlen, &capability)) < 0)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    83
+        {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    84
+          bgp_notify_send (peer,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    85
+                 BGP_NOTIFY_OPEN_ERR,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    86
+                 BGP_NOTIFY_OPEN_UNACEP_HOLDTIME);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    87
+	  return ret;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    88
+        }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    89
     }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    90
   else
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    91
     {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    92
--
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    93
cgit v0.9.0.2
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    94
From 393b2d64dc0625ba8e01e9e1516efac06d13072e Mon Sep 17 00:00:00 2001
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    95
From: Denis Ovsienko <[email protected]ex.ru>
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    96
Date: Sun, 15 Jan 2012 15:12:19 +0000
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    97
Subject: ospfd: use LOOKUP() for ospf_packet_type_str
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    98
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
    99
* ospf_packet.h: add proper str/max extern declarations
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   100
* ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   101
  * ospf_packet_type_str: rewrite in "struct message", add max value
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   102
  * ospf_packet_add(): use LOOKUP()
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   103
  * ospf_write(): ditto
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   104
  * ospf_hello(): ditto
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   105
  * ospf_read(): ditto
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   106
* ospf_dump.h: the declaration does not belong here
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   107
* ospf_dump.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   108
  * ospf_header_dump(): use LOOKUP()
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   109
  * show_debugging_ospf(): ditto
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   110
---
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   111
diff --git ospfd/ospf_dump.c ospfd/ospf_dump.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   112
index e65b2e3..8ace095 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   113
--- ospfd/ospf_dump.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   114
+++ ospfd/ospf_dump.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   115
@@ -661,7 +661,7 @@ ospf_header_dump (struct ospf_header *ospfh)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   116
   zlog_debug ("Header");
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   117
   zlog_debug ("  Version %d", ospfh->version);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   118
   zlog_debug ("  Type %d (%s)", ospfh->type,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   119
-	     ospf_packet_type_str[ospfh->type]);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   120
+	     LOOKUP (ospf_packet_type_str, ospfh->type));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   121
   zlog_debug ("  Packet Len %d", ntohs (ospfh->length));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   122
   zlog_debug ("  Router ID %s", inet_ntoa (ospfh->router_id));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   123
   zlog_debug ("  Area ID %s", inet_ntoa (ospfh->area_id));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   124
@@ -1457,7 +1457,7 @@ DEFUN (show_debugging_ospf,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   125
     if (IS_DEBUG_OSPF_PACKET (i, SEND) && IS_DEBUG_OSPF_PACKET (i, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   126
       {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   127
 	vty_out (vty, "  OSPF packet %s%s debugging is on%s",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   128
-		 ospf_packet_type_str[i + 1],
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   129
+		 LOOKUP (ospf_packet_type_str, i + 1),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   130
 		 IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   131
 		 VTY_NEWLINE);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   132
       }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   133
@@ -1465,12 +1465,12 @@ DEFUN (show_debugging_ospf,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   134
       {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   135
 	if (IS_DEBUG_OSPF_PACKET (i, SEND))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   136
 	  vty_out (vty, "  OSPF packet %s send%s debugging is on%s",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   137
-		   ospf_packet_type_str[i + 1],
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   138
+		   LOOKUP (ospf_packet_type_str, i + 1),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   139
 		   IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   140
 		   VTY_NEWLINE);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   141
 	if (IS_DEBUG_OSPF_PACKET (i, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   142
 	  vty_out (vty, "  OSPF packet %s receive%s debugging is on%s",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   143
-		   ospf_packet_type_str[i + 1],
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   144
+		   LOOKUP (ospf_packet_type_str, i + 1),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   145
 		   IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   146
 		   VTY_NEWLINE);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   147
       }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   148
diff --git ospfd/ospf_dump.h ospfd/ospf_dump.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   149
index fb81371..455214f 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   150
--- ospfd/ospf_dump.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   151
+++ ospfd/ospf_dump.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   152
@@ -121,7 +121,6 @@ extern unsigned long term_debug_ospf_zebra;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   153
 extern unsigned long term_debug_ospf_nssa;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   154
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   155
 /* Message Strings. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   156
-extern const char *ospf_packet_type_str[];
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   157
 extern char *ospf_lsa_type_str[];
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   158
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   159
 /* Prototypes. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   160
diff --git ospfd/ospf_packet.c ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   161
index 0f338d3..03e6d2a 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   162
--- ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   163
+++ ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   164
@@ -50,15 +50,16 @@
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   165
 #include "ospfd/ospf_dump.h"
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   166
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   167
 /* Packet Type String. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   168
-const char *ospf_packet_type_str[] =
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   169
-{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   170
-  "unknown",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   171
-  "Hello",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   172
-  "Database Description",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   173
-  "Link State Request",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   174
-  "Link State Update",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   175
-  "Link State Acknowledgment",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   176
+const struct message ospf_packet_type_str[] =
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   177
+{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   178
+  { OSPF_MSG_HELLO,   "Hello"                     },
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   179
+  { OSPF_MSG_DB_DESC, "Database Description"      },
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   180
+  { OSPF_MSG_LS_REQ,  "Link State Request"        },
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   181
+  { OSPF_MSG_LS_UPD,  "Link State Update"         },
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   182
+  { OSPF_MSG_LS_ACK,  "Link State Acknowledgment" },
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   183
 };
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   184
+const size_t ospf_packet_type_str_max = sizeof (ospf_packet_type_str) /
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   185
+  sizeof (ospf_packet_type_str[0]);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   186
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   187
 /* OSPF authentication checking function */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   188
 static int
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   189
@@ -201,7 +202,7 @@ ospf_packet_add (struct ospf_interface *oi, struct ospf_packet *op)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   190
 	       "destination %s) called with NULL obuf, ignoring "
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   191
 	       "(please report this bug)!\n",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   192
 	       IF_NAME(oi), oi->state, LOOKUP (ospf_ism_state_msg, oi->state),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   193
-	       ospf_packet_type_str[stream_getc_from(op->s, 1)],
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   194
+	       LOOKUP (ospf_packet_type_str, stream_getc_from(op->s, 1)),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   195
 	       inet_ntoa (op->dst));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   196
       return;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   197
     }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   198
@@ -755,7 +756,7 @@ ospf_write (struct thread *thread)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   199
 	}
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   200
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   201
       zlog_debug ("%s sent to [%s] via [%s].",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   202
-		 ospf_packet_type_str[type], inet_ntoa (op->dst),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   203
+		 LOOKUP (ospf_packet_type_str, type), inet_ntoa (op->dst),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   204
 		 IF_NAME (oi));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   205
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   206
       if (IS_DEBUG_OSPF_PACKET (type - 1, DETAIL))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   207
@@ -801,7 +802,7 @@ ospf_hello (struct ip *iph, struct ospf_header *ospfh,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   208
         {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   209
           zlog_debug ("ospf_header[%s/%s]: selforiginated, "
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   210
                      "dropping.",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   211
-                     ospf_packet_type_str[ospfh->type],
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   212
+                     LOOKUP (ospf_packet_type_str, ospfh->type),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   213
                      inet_ntoa (iph->ip_src));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   214
         }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   215
       return;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   216
@@ -2571,7 +2572,7 @@ ospf_read (struct thread *thread)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   217
         }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   218
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   219
       zlog_debug ("%s received from [%s] via [%s]",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   220
-                 ospf_packet_type_str[ospfh->type],
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   221
+                 LOOKUP (ospf_packet_type_str, ospfh->type),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   222
                  inet_ntoa (ospfh->router_id), IF_NAME (oi));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   223
       zlog_debug (" src [%s],", inet_ntoa (iph->ip_src));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   224
       zlog_debug (" dst [%s]", inet_ntoa (iph->ip_dst));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   225
diff --git ospfd/ospf_packet.h ospfd/ospf_packet.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   226
index 9a47208..2115f11 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   227
--- ospfd/ospf_packet.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   228
+++ ospfd/ospf_packet.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   229
@@ -163,4 +163,7 @@ extern int ospf_ls_ack_timer (struct thread *);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   230
 extern int ospf_poll_timer (struct thread *);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   231
 extern int ospf_hello_reply_timer (struct thread *);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   232
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   233
+extern const struct message ospf_packet_type_str[];
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   234
+extern const size_t ospf_packet_type_str_max;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   235
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   236
 #endif /* _ZEBRA_OSPF_PACKET_H */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   237
--
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   238
cgit v0.9.0.2
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   239
From 099ed6744881e71957f2bfeebc4c0727714d2394 Mon Sep 17 00:00:00 2001
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   240
From: Denis Ovsienko <[email protected]>
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   241
Date: Fri, 20 Jan 2012 18:32:10 +0000
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   242
Subject: ospfd: fix ospf_packet_add_top() to use LOOKUP()
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   243
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   244
---
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   245
diff --git ospfd/ospf_packet.c ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   246
index 03e6d2a..500f245 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   247
--- ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   248
+++ ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   249
@@ -223,7 +223,7 @@ ospf_packet_add_top (struct ospf_interface *oi, struct ospf_packet *op)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   250
 	       "destination %s) called with NULL obuf, ignoring "
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   251
 	       "(please report this bug)!\n",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   252
 	       IF_NAME(oi), oi->state, LOOKUP (ospf_ism_state_msg, oi->state),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   253
-	       ospf_packet_type_str[stream_getc_from(op->s, 1)],
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   254
+	       LOOKUP (ospf_packet_type_str, stream_getc_from(op->s, 1)),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   255
 	       inet_ntoa (op->dst));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   256
       return;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   257
     }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   258
--
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   259
cgit v0.9.0.2
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   260
From 3092cd57fb44c8293995d013bd86937d1a91745f Mon Sep 17 00:00:00 2001
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   261
From: Denis Ovsienko <[email protected]>
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   262
Date: Mon, 30 Jan 2012 11:41:39 +0000
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   263
Subject: ospfd: introduce ospf_packet_minlen[] (BZ#705)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   264
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   265
This commit ports some of the OSPFv3 packet reception checks
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   266
to OSPFv2.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   267
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   268
* ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   269
  * ospf_packet_minlen[]: a direct equivalent of ospf6_packet_minlen[]
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   270
  * ospf_packet_examin(): new function designed after the first part
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   271
    of ospf6_packet_examin()
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   272
  * ospf_read(): verify received packet with ospf_packet_examin()
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   273
* ospf_packet.h: add convenience macros
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   274
---
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   275
diff --git ospfd/ospf_packet.c ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   276
index 500f245..f425da8 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   277
--- ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   278
+++ ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   279
@@ -61,6 +61,18 @@ const struct message ospf_packet_type_str[] =
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   280
 const size_t ospf_packet_type_str_max = sizeof (ospf_packet_type_str) /
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   281
   sizeof (ospf_packet_type_str[0]);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   282
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   283
+/* Minimum (besides OSPF_HEADER_SIZE) lengths for OSPF packets of
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   284
+   particular types, offset is the "type" field of a packet. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   285
+static const u_int16_t ospf_packet_minlen[] =
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   286
+{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   287
+  0,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   288
+  OSPF_HELLO_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   289
+  OSPF_DB_DESC_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   290
+  OSPF_LS_REQ_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   291
+  OSPF_LS_UPD_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   292
+  OSPF_LS_ACK_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   293
+};
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   294
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   295
 /* OSPF authentication checking function */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   296
 static int
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   297
 ospf_auth_type (struct ospf_interface *oi)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   298
@@ -2309,6 +2321,47 @@ ospf_check_sum (struct ospf_header *ospfh)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   299
   return 1;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   300
 }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   301
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   302
+/* Verify a complete OSPF packet for proper sizing/alignment. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   303
+static unsigned
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   304
+ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   305
+{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   306
+  u_int16_t bytesdeclared;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   307
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   308
+  /* Length, 1st approximation. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   309
+  if (bytesonwire < OSPF_HEADER_SIZE)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   310
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   311
+    if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   312
+      zlog_debug ("%s: undersized (%u B) packet", __func__, bytesonwire);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   313
+    return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   314
+  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   315
+  /* Now it is safe to access header fields. Performing length check, allow
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   316
+   * for possible extra bytes of crypto auth/padding, which are not counted
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   317
+   * in the OSPF header "length" field. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   318
+  bytesdeclared = ntohs (oh->length);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   319
+  if (bytesdeclared > bytesonwire)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   320
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   321
+    if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   322
+      zlog_debug ("%s: packet length error (%u real, %u declared)",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   323
+                  __func__, bytesonwire, bytesdeclared);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   324
+    return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   325
+  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   326
+  /* Length, 2nd approximation. The type-specific constraint is checked
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   327
+     against declared length, not amount of bytes on wire. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   328
+  if
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   329
+  (
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   330
+    oh->type >= OSPF_MSG_HELLO &&
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   331
+    oh->type <= OSPF_MSG_LS_ACK &&
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   332
+    bytesdeclared < OSPF_HEADER_SIZE + ospf_packet_minlen[oh->type]
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   333
+  )
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   334
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   335
+    if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   336
+      zlog_debug ("%s: undersized (%u B) %s packet", __func__,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   337
+                  bytesdeclared, LOOKUP (ospf_packet_type_str, oh->type));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   338
+    return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   339
+  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   340
+  return MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   341
+}
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   342
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   343
 /* OSPF Header verification. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   344
 static int
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   345
 ospf_verify_header (struct stream *ibuf, struct ospf_interface *oi,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   346
@@ -2404,10 +2457,10 @@ ospf_read (struct thread *thread)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   347
   /* prepare for next packet. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   348
   ospf->t_read = thread_add_read (master, ospf_read, ospf, ospf->fd);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   349
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   350
-  /* read OSPF packet. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   351
   stream_reset(ospf->ibuf);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   352
   if (!(ibuf = ospf_recv_packet (ospf->fd, &ifp, ospf->ibuf)))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   353
     return -1;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   354
+  /* This raw packet is known to be at least as big as its IP header. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   355
   
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   356
   /* Note that there should not be alignment problems with this assignment
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   357
      because this is at the beginning of the stream data buffer. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   358
@@ -2442,16 +2495,10 @@ ospf_read (struct thread *thread)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   359
      by ospf_recv_packet() to be correct). */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   360
   stream_forward_getp (ibuf, iph->ip_hl * 4);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   361
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   362
-  /* Make sure the OSPF header is really there. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   363
-  if (stream_get_endp (ibuf) - stream_get_getp (ibuf) < OSPF_HEADER_SIZE)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   364
-  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   365
-    zlog_debug ("ospf_read: ignored OSPF packet with undersized (%u bytes) header",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   366
-                stream_get_endp (ibuf) - stream_get_getp (ibuf));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   367
+  ospfh = (struct ospf_header *) STREAM_PNT (ibuf);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   368
+  if (MSG_OK != ospf_packet_examin (ospfh, stream_get_endp (ibuf) - stream_get_getp (ibuf)))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   369
     return -1;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   370
-  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   371
-
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   372
   /* Now it is safe to access all fields of OSPF packet header. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   373
-  ospfh = (struct ospf_header *) STREAM_PNT (ibuf);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   374
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   375
   /* associate packet with ospf interface */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   376
   oi = ospf_if_lookup_recv_if (ospf, iph->ip_src, ifp);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   377
diff --git ospfd/ospf_packet.h ospfd/ospf_packet.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   378
index 2115f11..3cbe889 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   379
--- ospfd/ospf_packet.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   380
+++ ospfd/ospf_packet.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   381
@@ -46,6 +46,10 @@
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   382
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   383
 #define OSPF_HELLO_REPLY_DELAY          1
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   384
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   385
+/* Return values of functions involved in packet verification, see ospf6d. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   386
+#define MSG_OK    0
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   387
+#define MSG_NG    1
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   388
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   389
 struct ospf_packet
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   390
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   391
   struct ospf_packet *next;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   392
--
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   393
cgit v0.9.0.2
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   394
From 3779a3bf9d27b3cccda7e45223884257af362c28 Mon Sep 17 00:00:00 2001
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   395
From: Denis Ovsienko <[email protected]>
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   396
Date: Mon, 30 Jan 2012 12:07:18 +0000
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   397
Subject: ospfd: review ospf_check_auth()
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   398
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   399
1. The only purpose of "ibuf" argument was to get stream size, which
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   400
was always equal to OSPF_MAX_PACKET_SIZE + 1, exactly as initialized
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   401
in ospf_new().
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   402
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   403
2. Fix the packet size check condition, which was incorrect for very
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   404
large packets, at least in theory.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   405
---
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   406
diff --git ospfd/ospf_packet.c ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   407
index f425da8..a71cc99 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   408
--- ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   409
+++ ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   410
@@ -2255,8 +2255,7 @@ ospf_check_network_mask (struct ospf_interface *oi, struct in_addr ip_src)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   411
 }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   412
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   413
 static int
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   414
-ospf_check_auth (struct ospf_interface *oi, struct stream *ibuf,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   415
-		 struct ospf_header *ospfh)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   416
+ospf_check_auth (struct ospf_interface *oi, struct ospf_header *ospfh)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   417
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   418
   int ret = 0;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   419
   struct crypt_key *ck;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   420
@@ -2282,7 +2281,7 @@ ospf_check_auth (struct ospf_interface *oi, struct stream *ibuf,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   421
       /* This is very basic, the digest processing is elsewhere */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   422
       if (ospfh->u.crypt.auth_data_len == OSPF_AUTH_MD5_SIZE && 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   423
           ospfh->u.crypt.key_id == ck->key_id &&
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   424
-          ntohs (ospfh->length) + OSPF_AUTH_SIMPLE_SIZE <= stream_get_size (ibuf))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   425
+          ntohs (ospfh->length) + OSPF_AUTH_MD5_SIZE <= OSPF_MAX_PACKET_SIZE)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   426
         ret = 1;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   427
       else
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   428
         ret = 0;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   429
@@ -2406,7 +2405,7 @@ ospf_verify_header (struct stream *ibuf, struct ospf_interface *oi,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   430
       return -1;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   431
     }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   432
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   433
-  if (! ospf_check_auth (oi, ibuf, ospfh))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   434
+  if (! ospf_check_auth (oi, ospfh))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   435
     {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   436
       zlog_warn ("interface %s: ospf_read authentication failed.",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   437
 		 IF_NAME (oi));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   438
--
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   439
cgit v0.9.0.2
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   440
From 7edfc01207f3eee8f26d5c22cfef7c7f030c52ce Mon Sep 17 00:00:00 2001
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   441
From: Denis Ovsienko <[email protected]>
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   442
Date: Mon, 30 Jan 2012 16:32:39 +0000
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   443
Subject: ospfd: review ospf_check_md5_digest()
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   444
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   445
Rewrite some pointer arithmetics without the additional variables and
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   446
move byte order conversion inside the function.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   447
---
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   448
diff --git ospfd/ospf_packet.c ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   449
index a71cc99..5704f9d 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   450
--- ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   451
+++ ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   452
@@ -304,24 +304,14 @@ ospf_packet_max (struct ospf_interface *oi)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   453
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   454
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   455
 static int
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   456
-ospf_check_md5_digest (struct ospf_interface *oi, struct stream *s,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   457
-                       u_int16_t length)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   458
+ospf_check_md5_digest (struct ospf_interface *oi, struct ospf_header *ospfh)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   459
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   460
-  unsigned char *ibuf;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   461
   MD5_CTX ctx;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   462
   unsigned char digest[OSPF_AUTH_MD5_SIZE];
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   463
-  unsigned char *pdigest;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   464
   struct crypt_key *ck;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   465
-  struct ospf_header *ospfh;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   466
   struct ospf_neighbor *nbr;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   467
+  u_int16_t length = ntohs (ospfh->length);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   468
   
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   469
-
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   470
-  ibuf = STREAM_PNT (s);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   471
-  ospfh = (struct ospf_header *) ibuf;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   472
-
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   473
-  /* Get pointer to the end of the packet. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   474
-  pdigest = ibuf + length;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   475
-
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   476
   /* Get secret key. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   477
   ck = ospf_crypt_key_lookup (OSPF_IF_PARAM (oi, auth_crypt),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   478
 			      ospfh->u.crypt.key_id);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   479
@@ -347,12 +337,12 @@ ospf_check_md5_digest (struct ospf_interface *oi, struct stream *s,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   480
   /* Generate a digest for the ospf packet - their digest + our digest. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   481
   memset(&ctx, 0, sizeof(ctx));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   482
   MD5Init(&ctx);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   483
-  MD5Update(&ctx, ibuf, length);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   484
+  MD5Update(&ctx, ospfh, length);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   485
   MD5Update(&ctx, ck->auth_key, OSPF_AUTH_MD5_SIZE);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   486
   MD5Final(digest, &ctx);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   487
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   488
   /* compare the two */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   489
-  if (memcmp (pdigest, digest, OSPF_AUTH_MD5_SIZE))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   490
+  if (memcmp ((caddr_t)ospfh + length, digest, OSPF_AUTH_MD5_SIZE))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   491
     {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   492
       zlog_warn ("interface %s: ospf_check_md5 checksum mismatch",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   493
 		 IF_NAME (oi));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   494
@@ -2426,7 +2416,7 @@ ospf_verify_header (struct stream *ibuf, struct ospf_interface *oi,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   495
     {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   496
       if (ospfh->checksum != 0)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   497
 	return -1;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   498
-      if (ospf_check_md5_digest (oi, ibuf, ntohs (ospfh->length)) == 0)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   499
+      if (ospf_check_md5_digest (oi, ospfh) == 0)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   500
 	{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   501
 	  zlog_warn ("interface %s: ospf_read md5 authentication failed.",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   502
 		     IF_NAME (oi));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   503
--
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   504
cgit v0.9.0.2
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   505
From fba10fc38f482c617fdfbb81b8d855df56eeda51 Mon Sep 17 00:00:00 2001
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   506
From: Denis Ovsienko <[email protected]>
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   507
Date: Fri, 17 Feb 2012 12:20:50 +0000
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   508
Subject: ospfd: introduce ospf_lsa_minlen[] (BZ#705)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   509
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   510
This commit ports more packet checks to OSPFv2, in particular, LSA size
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   511
verification and Router-LSA link blocks verification.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   512
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   513
* ospf_lsa.h: add LSA size macros
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   514
* ospf_packet.h: add struct ospf_ls_update
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   515
* ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   516
  * ospf_lsa_minlen[]: a direct equivalent of ospf6_lsa_minlen[]
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   517
  * ospf_router_lsa_links_examin(): new function, verifies trailing
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   518
    part of a Router-LSA
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   519
  * ospf_lsa_examin(): new function like ospf6_lsa_examin()
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   520
  * ospf_lsaseq_examin(): new function like ospf6_lsaseq_examin()
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   521
  * ospf_packet_examin(): add type-specific deeper level checks
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   522
---
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   523
diff --git ospfd/ospf_lsa.h ospfd/ospf_lsa.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   524
index bf3b083..ca0653c 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   525
--- ospfd/ospf_lsa.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   526
+++ ospfd/ospf_lsa.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   527
@@ -153,6 +153,7 @@ struct router_lsa_link
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   528
 };
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   529
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   530
 /* OSPF Router-LSAs structure. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   531
+#define OSPF_ROUTER_LSA_MIN_SIZE                  16U /* w/1 link descriptor */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   532
 struct router_lsa
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   533
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   534
   struct lsa_header header;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   535
@@ -170,6 +171,7 @@ struct router_lsa
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   536
 };
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   537
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   538
 /* OSPF Network-LSAs structure. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   539
+#define OSPF_NETWORK_LSA_MIN_SIZE                  8U /* w/1 router-ID */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   540
 struct network_lsa
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   541
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   542
   struct lsa_header header;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   543
@@ -178,6 +180,7 @@ struct network_lsa
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   544
 };
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   545
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   546
 /* OSPF Summary-LSAs structure. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   547
+#define OSPF_SUMMARY_LSA_MIN_SIZE                  8U /* w/1 TOS metric block */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   548
 struct summary_lsa
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   549
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   550
   struct lsa_header header;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   551
@@ -187,6 +190,7 @@ struct summary_lsa
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   552
 };
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   553
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   554
 /* OSPF AS-external-LSAs structure. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   555
+#define OSPF_AS_EXTERNAL_LSA_MIN_SIZE             16U /* w/1 TOS forwarding block */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   556
 struct as_external_lsa
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   557
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   558
   struct lsa_header header;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   559
diff --git ospfd/ospf_packet.c ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   560
index 5704f9d..3b82820 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   561
--- ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   562
+++ ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   563
@@ -73,6 +73,24 @@ static const u_int16_t ospf_packet_minlen[] =
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   564
   OSPF_LS_ACK_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   565
 };
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   566
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   567
+/* Minimum (besides OSPF_LSA_HEADER_SIZE) lengths for LSAs of particular
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   568
+   types, offset is the "LSA type" field. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   569
+static const u_int16_t ospf_lsa_minlen[] =
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   570
+{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   571
+  0,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   572
+  OSPF_ROUTER_LSA_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   573
+  OSPF_NETWORK_LSA_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   574
+  OSPF_SUMMARY_LSA_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   575
+  OSPF_SUMMARY_LSA_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   576
+  OSPF_AS_EXTERNAL_LSA_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   577
+  0,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   578
+  OSPF_AS_EXTERNAL_LSA_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   579
+  0,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   580
+  0,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   581
+  0,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   582
+  0,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   583
+};
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   584
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   585
 /* OSPF authentication checking function */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   586
 static int
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   587
 ospf_auth_type (struct ospf_interface *oi)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   588
@@ -2310,11 +2328,199 @@ ospf_check_sum (struct ospf_header *ospfh)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   589
   return 1;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   590
 }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   591
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   592
+/* Verify, that given link/TOS records are properly sized/aligned and match
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   593
+   Router-LSA "# links" and "# TOS" fields as specified in RFC2328 A.4.2. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   594
+static unsigned
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   595
+ospf_router_lsa_links_examin
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   596
+(
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   597
+  struct router_lsa_link * link,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   598
+  u_int16_t linkbytes,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   599
+  const u_int16_t num_links
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   600
+)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   601
+{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   602
+  unsigned counted_links = 0, thislinklen;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   603
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   604
+  while (linkbytes)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   605
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   606
+    thislinklen = OSPF_ROUTER_LSA_LINK_SIZE + 4 * link->m[0].tos_count;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   607
+    if (thislinklen > linkbytes)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   608
+    {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   609
+      if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   610
+        zlog_debug ("%s: length error in link block #%u", __func__, counted_links);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   611
+      return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   612
+    }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   613
+    link = (struct router_lsa_link *)((caddr_t) link + thislinklen);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   614
+    linkbytes -= thislinklen;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   615
+    counted_links++;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   616
+  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   617
+  if (counted_links != num_links)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   618
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   619
+    if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   620
+      zlog_debug ("%s: %u link blocks declared, %u present",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   621
+                  __func__, num_links, counted_links);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   622
+    return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   623
+  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   624
+  return MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   625
+}
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   626
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   627
+/* Verify, that the given LSA is properly sized/aligned (including type-specific
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   628
+   minimum length constraint). */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   629
+static unsigned
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   630
+ospf_lsa_examin (struct lsa_header * lsah, const u_int16_t lsalen, const u_char headeronly)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   631
+{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   632
+  unsigned ret;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   633
+  struct router_lsa * rlsa;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   634
+  if
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   635
+  (
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   636
+    lsah->type < OSPF_MAX_LSA &&
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   637
+    ospf_lsa_minlen[lsah->type] &&
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   638
+    lsalen < OSPF_LSA_HEADER_SIZE + ospf_lsa_minlen[lsah->type]
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   639
+  )
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   640
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   641
+    if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   642
+      zlog_debug ("%s: undersized (%u B) %s",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   643
+                  __func__, lsalen, LOOKUP (ospf_lsa_type_msg, lsah->type));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   644
+    return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   645
+  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   646
+  switch (lsah->type)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   647
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   648
+  case OSPF_ROUTER_LSA:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   649
+    /* RFC2328 A.4.2, LSA header + 4 bytes followed by N>=1 (12+)-byte link blocks */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   650
+    if (headeronly)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   651
+    {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   652
+      ret = (lsalen - OSPF_LSA_HEADER_SIZE - OSPF_ROUTER_LSA_MIN_SIZE) % 4 ? MSG_NG : MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   653
+      break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   654
+    }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   655
+    rlsa = (struct router_lsa *) lsah;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   656
+    ret = ospf_router_lsa_links_examin
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   657
+    (
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   658
+      (struct router_lsa_link *) rlsa->link,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   659
+      lsalen - OSPF_LSA_HEADER_SIZE - 4, /* skip: basic header, "flags", 0, "# links" */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   660
+      ntohs (rlsa->links) /* 16 bits */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   661
+    );
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   662
+    break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   663
+  case OSPF_AS_EXTERNAL_LSA:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   664
+    /* RFC2328 A.4.5, LSA header + 4 bytes followed by N>=1 12-bytes long blocks */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   665
+  case OSPF_AS_NSSA_LSA:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   666
+    /* RFC3101 C, idem */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   667
+    ret = (lsalen - OSPF_LSA_HEADER_SIZE - OSPF_AS_EXTERNAL_LSA_MIN_SIZE) % 12 ? MSG_NG : MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   668
+    break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   669
+  /* Following LSA types are considered OK length-wise as soon as their minimum
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   670
+   * length constraint is met and length of the whole LSA is a multiple of 4
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   671
+   * (basic LSA header size is already a multiple of 4). */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   672
+  case OSPF_NETWORK_LSA:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   673
+    /* RFC2328 A.4.3, LSA header + 4 bytes followed by N>=1 router-IDs */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   674
+  case OSPF_SUMMARY_LSA:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   675
+  case OSPF_ASBR_SUMMARY_LSA:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   676
+    /* RFC2328 A.4.4, LSA header + 4 bytes followed by N>=1 4-bytes TOS blocks */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   677
+#ifdef HAVE_OPAQUE_LSA
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   678
+  case OSPF_OPAQUE_LINK_LSA:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   679
+  case OSPF_OPAQUE_AREA_LSA:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   680
+  case OSPF_OPAQUE_AS_LSA:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   681
+    /* RFC5250 A.2, "some number of octets (of application-specific
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   682
+     * data) padded to 32-bit alignment." This is considered equivalent
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   683
+     * to 4-byte alignment of all other LSA types, see OSPF-ALIGNMENT.txt
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   684
+     * file for the detailed analysis of this passage. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   685
+#endif
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   686
+    ret = lsalen % 4 ? MSG_NG : MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   687
+    break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   688
+  default:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   689
+    if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   690
+      zlog_debug ("%s: unsupported LSA type 0x%02x", __func__, lsah->type);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   691
+    return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   692
+  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   693
+  if (ret != MSG_OK && IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   694
+    zlog_debug ("%s: alignment error in %s",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   695
+                __func__, LOOKUP (ospf_lsa_type_msg, lsah->type));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   696
+  return ret;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   697
+}
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   698
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   699
+/* Verify if the provided input buffer is a valid sequence of LSAs. This
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   700
+   includes verification of LSA blocks length/alignment and dispatching
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   701
+   of deeper-level checks. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   702
+static unsigned
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   703
+ospf_lsaseq_examin
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   704
+(
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   705
+  struct lsa_header *lsah, /* start of buffered data */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   706
+  size_t length,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   707
+  const u_char headeronly,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   708
+  /* When declared_num_lsas is not 0, compare it to the real number of LSAs
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   709
+     and treat the difference as an error. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   710
+  const u_int32_t declared_num_lsas
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   711
+)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   712
+{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   713
+  u_int32_t counted_lsas = 0;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   714
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   715
+  while (length)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   716
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   717
+    u_int16_t lsalen;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   718
+    if (length < OSPF_LSA_HEADER_SIZE)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   719
+    {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   720
+      if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   721
+        zlog_debug ("%s: undersized (%zu B) trailing (#%u) LSA header",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   722
+                    __func__, length, counted_lsas);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   723
+      return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   724
+    }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   725
+    /* save on ntohs() calls here and in the LSA validator */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   726
+    lsalen = ntohs (lsah->length);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   727
+    if (lsalen < OSPF_LSA_HEADER_SIZE)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   728
+    {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   729
+      if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   730
+        zlog_debug ("%s: malformed LSA header #%u, declared length is %u B",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   731
+                    __func__, counted_lsas, lsalen);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   732
+      return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   733
+    }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   734
+    if (headeronly)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   735
+    {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   736
+      /* less checks here and in ospf_lsa_examin() */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   737
+      if (MSG_OK != ospf_lsa_examin (lsah, lsalen, 1))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   738
+      {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   739
+        if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   740
+          zlog_debug ("%s: malformed header-only LSA #%u", __func__, counted_lsas);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   741
+        return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   742
+      }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   743
+      lsah = (struct lsa_header *) ((caddr_t) lsah + OSPF_LSA_HEADER_SIZE);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   744
+      length -= OSPF_LSA_HEADER_SIZE;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   745
+    }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   746
+    else
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   747
+    {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   748
+      /* make sure the input buffer is deep enough before further checks */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   749
+      if (lsalen > length)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   750
+      {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   751
+        if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   752
+          zlog_debug ("%s: anomaly in LSA #%u: declared length is %u B, buffered length is %zu B",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   753
+                      __func__, counted_lsas, lsalen, length);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   754
+        return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   755
+      }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   756
+      if (MSG_OK != ospf_lsa_examin (lsah, lsalen, 0))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   757
+      {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   758
+        if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   759
+          zlog_debug ("%s: malformed LSA #%u", __func__, counted_lsas);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   760
+        return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   761
+      }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   762
+      lsah = (struct lsa_header *) ((caddr_t) lsah + lsalen);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   763
+      length -= lsalen;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   764
+    }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   765
+    counted_lsas++;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   766
+  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   767
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   768
+  if (declared_num_lsas && counted_lsas != declared_num_lsas)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   769
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   770
+    if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   771
+      zlog_debug ("%s: #LSAs declared (%u) does not match actual (%u)",
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   772
+                  __func__, declared_num_lsas, counted_lsas);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   773
+    return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   774
+  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   775
+  return MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   776
+}
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   777
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   778
 /* Verify a complete OSPF packet for proper sizing/alignment. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   779
 static unsigned
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   780
 ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   781
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   782
   u_int16_t bytesdeclared;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   783
+  unsigned ret;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   784
+  struct ospf_ls_update * lsupd;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   785
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   786
   /* Length, 1st approximation. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   787
   if (bytesonwire < OSPF_HEADER_SIZE)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   788
@@ -2348,7 +2554,59 @@ ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   789
                   bytesdeclared, LOOKUP (ospf_packet_type_str, oh->type));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   790
     return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   791
   }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   792
-  return MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   793
+  switch (oh->type)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   794
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   795
+  case OSPF_MSG_HELLO:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   796
+    /* RFC2328 A.3.2, packet header + OSPF_HELLO_MIN_SIZE bytes followed
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   797
+       by N>=0 router-IDs. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   798
+    ret = (bytesonwire - OSPF_HEADER_SIZE - OSPF_HELLO_MIN_SIZE) % 4 ? MSG_NG : MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   799
+    break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   800
+  case OSPF_MSG_DB_DESC:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   801
+    /* RFC2328 A.3.3, packet header + OSPF_DB_DESC_MIN_SIZE bytes followed
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   802
+       by N>=0 header-only LSAs. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   803
+    ret = ospf_lsaseq_examin
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   804
+    (
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   805
+      (struct lsa_header *) ((caddr_t) oh + OSPF_HEADER_SIZE + OSPF_DB_DESC_MIN_SIZE),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   806
+      bytesonwire - OSPF_HEADER_SIZE - OSPF_DB_DESC_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   807
+      1, /* header-only LSAs */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   808
+      0
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   809
+    );
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   810
+    break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   811
+  case OSPF_MSG_LS_REQ:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   812
+    /* RFC2328 A.3.4, packet header followed by N>=0 12-bytes request blocks. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   813
+    ret = (bytesonwire - OSPF_HEADER_SIZE - OSPF_LS_REQ_MIN_SIZE) %
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   814
+      OSPF_LSA_KEY_SIZE ? MSG_NG : MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   815
+    break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   816
+  case OSPF_MSG_LS_UPD:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   817
+    /* RFC2328 A.3.5, packet header + OSPF_LS_UPD_MIN_SIZE bytes followed
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   818
+       by N>=0 full LSAs (with N declared beforehand). */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   819
+    lsupd = (struct ospf_ls_update *) ((caddr_t) oh + OSPF_HEADER_SIZE);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   820
+    ret = ospf_lsaseq_examin
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   821
+    (
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   822
+      (struct lsa_header *) ((caddr_t) lsupd + OSPF_LS_UPD_MIN_SIZE),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   823
+      bytesonwire - OSPF_HEADER_SIZE - OSPF_LS_UPD_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   824
+      0, /* full LSAs */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   825
+      ntohl (lsupd->num_lsas) /* 32 bits */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   826
+    );
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   827
+    break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   828
+  case OSPF_MSG_LS_ACK:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   829
+    /* RFC2328 A.3.6, packet header followed by N>=0 header-only LSAs. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   830
+    ret = ospf_lsaseq_examin
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   831
+    (
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   832
+      (struct lsa_header *) ((caddr_t) oh + OSPF_HEADER_SIZE + OSPF_LS_ACK_MIN_SIZE),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   833
+      bytesonwire - OSPF_HEADER_SIZE - OSPF_LS_ACK_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   834
+      1, /* header-only LSAs */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   835
+      0
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   836
+    );
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   837
+    break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   838
+  default:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   839
+    if (IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   840
+      zlog_debug ("%s: invalid packet type 0x%02x", __func__, oh->type);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   841
+    return MSG_NG;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   842
+  }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   843
+  if (ret != MSG_OK && IS_DEBUG_OSPF_PACKET (0, RECV))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   844
+    zlog_debug ("%s: malformed %s packet", __func__, LOOKUP (ospf_packet_type_str, oh->type));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   845
+  return ret;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   846
 }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   847
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   848
 /* OSPF Header verification. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   849
diff --git ospfd/ospf_packet.h ospfd/ospf_packet.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   850
index 3cbe889..337686a 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   851
--- ospfd/ospf_packet.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   852
+++ ospfd/ospf_packet.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   853
@@ -121,6 +121,10 @@ struct ospf_db_desc
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   854
   u_int32_t dd_seqnum;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   855
 };
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   856
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   857
+struct ospf_ls_update
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   858
+{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   859
+  u_int32_t num_lsas;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   860
+};
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   861
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   862
 /* Macros. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   863
 /* XXX Perhaps obsolete; function in ospf_packet.c */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   864
--
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   865
cgit v0.9.0.2
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   866
From b03ae9f2d22acd8e3f97714a9c0df744676e344d Mon Sep 17 00:00:00 2001
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   867
From: Denis Ovsienko <[email protected]>
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   868
Date: Mon, 20 Feb 2012 19:08:10 +0000
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   869
Subject: ospfd: fix packet length check for auth/LLS cases
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   870
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   871
An OSPFv2 packet with trailing data blocks (authentication and/or
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   872
link-local signaling) failed the recently implemented packet length
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   873
check, because trailing data length isn't counted in the packet header
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   874
"length" field. This commit fixes respective check conditions.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   875
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   876
* ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   877
  * ospf_packet_examin(): use "bytesdeclared" instead of "bytesonwire"
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   878
---
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   879
diff --git ospfd/ospf_packet.c ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   880
index 3b82820..7b661a3 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   881
--- ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   882
+++ ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   883
@@ -2559,7 +2559,7 @@ ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   884
   case OSPF_MSG_HELLO:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   885
     /* RFC2328 A.3.2, packet header + OSPF_HELLO_MIN_SIZE bytes followed
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   886
        by N>=0 router-IDs. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   887
-    ret = (bytesonwire - OSPF_HEADER_SIZE - OSPF_HELLO_MIN_SIZE) % 4 ? MSG_NG : MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   888
+    ret = (bytesdeclared - OSPF_HEADER_SIZE - OSPF_HELLO_MIN_SIZE) % 4 ? MSG_NG : MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   889
     break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   890
   case OSPF_MSG_DB_DESC:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   891
     /* RFC2328 A.3.3, packet header + OSPF_DB_DESC_MIN_SIZE bytes followed
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   892
@@ -2567,14 +2567,14 @@ ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   893
     ret = ospf_lsaseq_examin
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   894
     (
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   895
       (struct lsa_header *) ((caddr_t) oh + OSPF_HEADER_SIZE + OSPF_DB_DESC_MIN_SIZE),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   896
-      bytesonwire - OSPF_HEADER_SIZE - OSPF_DB_DESC_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   897
+      bytesdeclared - OSPF_HEADER_SIZE - OSPF_DB_DESC_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   898
       1, /* header-only LSAs */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   899
       0
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   900
     );
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   901
     break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   902
   case OSPF_MSG_LS_REQ:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   903
     /* RFC2328 A.3.4, packet header followed by N>=0 12-bytes request blocks. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   904
-    ret = (bytesonwire - OSPF_HEADER_SIZE - OSPF_LS_REQ_MIN_SIZE) %
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   905
+    ret = (bytesdeclared - OSPF_HEADER_SIZE - OSPF_LS_REQ_MIN_SIZE) %
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   906
       OSPF_LSA_KEY_SIZE ? MSG_NG : MSG_OK;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   907
     break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   908
   case OSPF_MSG_LS_UPD:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   909
@@ -2584,7 +2584,7 @@ ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   910
     ret = ospf_lsaseq_examin
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   911
     (
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   912
       (struct lsa_header *) ((caddr_t) lsupd + OSPF_LS_UPD_MIN_SIZE),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   913
-      bytesonwire - OSPF_HEADER_SIZE - OSPF_LS_UPD_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   914
+      bytesdeclared - OSPF_HEADER_SIZE - OSPF_LS_UPD_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   915
       0, /* full LSAs */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   916
       ntohl (lsupd->num_lsas) /* 32 bits */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   917
     );
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   918
@@ -2594,7 +2594,7 @@ ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   919
     ret = ospf_lsaseq_examin
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   920
     (
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   921
       (struct lsa_header *) ((caddr_t) oh + OSPF_HEADER_SIZE + OSPF_LS_ACK_MIN_SIZE),
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   922
-      bytesonwire - OSPF_HEADER_SIZE - OSPF_LS_ACK_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   923
+      bytesdeclared - OSPF_HEADER_SIZE - OSPF_LS_ACK_MIN_SIZE,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   924
       1, /* header-only LSAs */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   925
       0
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   926
     );
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   927
--
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   928
cgit v0.9.0.2
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   929
From 1bdd96caefaa76883bece4d358a60dc890f1e375 Mon Sep 17 00:00:00 2001
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   930
From: Denis Ovsienko <[email protected]>
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   931
Date: Sun, 26 Feb 2012 13:00:57 +0000
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   932
Subject: ospfd: introduce ospf_auth_type_str[]
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   933
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   934
---
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   935
diff --git ospfd/ospf_dump.c ospfd/ospf_dump.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   936
index 8ace095..7e11e25 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   937
--- ospfd/ospf_dump.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   938
+++ ospfd/ospf_dump.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   939
@@ -115,6 +115,16 @@ const struct message ospf_network_type_msg[] =
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   940
 };
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   941
 const int ospf_network_type_msg_max = OSPF_IFTYPE_MAX;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   942
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   943
+/* AuType */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   944
+const struct message ospf_auth_type_str[] =
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   945
+{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   946
+  { OSPF_AUTH_NULL,          "Null"          },
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   947
+  { OSPF_AUTH_SIMPLE,        "Simple"        },
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   948
+  { OSPF_AUTH_CRYPTOGRAPHIC, "Cryptographic" },
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   949
+};
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   950
+const size_t ospf_auth_type_str_max = sizeof (ospf_auth_type_str) /
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   951
+  sizeof (ospf_auth_type_str[0]);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   952
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   953
 /* Configuration debug option variables. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   954
 unsigned long conf_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   955
 unsigned long conf_debug_ospf_event = 0;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   956
@@ -657,6 +667,7 @@ static void
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   957
 ospf_header_dump (struct ospf_header *ospfh)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   958
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   959
   char buf[9];
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   960
+  u_int16_t auth_type = ntohs (ospfh->auth_type);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   961
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   962
   zlog_debug ("Header");
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   963
   zlog_debug ("  Version %d", ospfh->version);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   964
@@ -666,9 +677,9 @@ ospf_header_dump (struct ospf_header *ospfh)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   965
   zlog_debug ("  Router ID %s", inet_ntoa (ospfh->router_id));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   966
   zlog_debug ("  Area ID %s", inet_ntoa (ospfh->area_id));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   967
   zlog_debug ("  Checksum 0x%x", ntohs (ospfh->checksum));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   968
-  zlog_debug ("  AuType %d", ntohs (ospfh->auth_type));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   969
+  zlog_debug ("  AuType %s", LOOKUP (ospf_auth_type_str, auth_type));
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   970
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   971
-  switch (ntohs (ospfh->auth_type))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   972
+  switch (auth_type)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   973
     {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   974
     case OSPF_AUTH_NULL:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   975
       break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   976
diff --git ospfd/ospf_dump.h ospfd/ospf_dump.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   977
index 455214f..a2d5e8b 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   978
--- ospfd/ospf_dump.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   979
+++ ospfd/ospf_dump.h
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   980
@@ -122,6 +122,8 @@ extern unsigned long term_debug_ospf_nssa;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   981
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   982
 /* Message Strings. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   983
 extern char *ospf_lsa_type_str[];
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   984
+extern const struct message ospf_auth_type_str[];
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   985
+extern const size_t ospf_auth_type_str_max;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   986
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   987
 /* Prototypes. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   988
 extern const char *ospf_area_name_string (struct ospf_area *);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   989
--
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   990
cgit v0.9.0.2
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   991
From e5fa148725fb2a3d1a8df12683f023ff9d65273f Mon Sep 17 00:00:00 2001
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   992
From: Denis Ovsienko <[email protected]>
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   993
Date: Sun, 26 Feb 2012 13:59:43 +0000
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   994
Subject: ospfd: bring ospf_check_auth() into focus
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   995
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   996
The old ospf_check_auth() function did two different jobs depending on
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   997
AuType. For Null and Simple cases it actually authenticated the packet,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   998
but for Cryptographic case it only checked declared packet size (not
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
   999
taking the actual number of bytes on wire into account). The calling
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1000
function, ospf_verify_header(), had its own set of MD5/checksum checks
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1001
dispatched depending on AuType.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1002
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1003
This commit makes the packet size check work against the real number of
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1004
bytes and moves it to ospf_packet_examine(). All MD5/checksum
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1005
verification is now performed in ospf_check_auth() function.
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1006
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1007
* ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1008
  * ospf_packet_examin(): check length with MD5 bytes in mind
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1009
  * ospf_verify_header(): remove all AuType-specific code
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1010
  * ospf_check_auth(): completely rewrite
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1011
---
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1012
diff --git ospfd/ospf_packet.c ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1013
index 7b661a3..05651d3 100644
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1014
--- ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1015
+++ ospfd/ospf_packet.c
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1016
@@ -91,6 +91,9 @@ static const u_int16_t ospf_lsa_minlen[] =
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1017
   0,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1018
 };
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1019
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1020
+/* for ospf_check_auth() */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1021
+static int ospf_check_sum (struct ospf_header *);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1022
+
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1023
 /* OSPF authentication checking function */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1024
 static int
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1025
 ospf_auth_type (struct ospf_interface *oi)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1026
@@ -2262,44 +2265,91 @@ ospf_check_network_mask (struct ospf_interface *oi, struct in_addr ip_src)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1027
  return 0;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1028
 }
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1029
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1030
+/* Return 1, if the packet is properly authenticated and checksummed,
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1031
+   0 otherwise. In particular, check that AuType header field is valid and
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1032
+   matches the locally configured AuType, and that D.5 requirements are met. */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1033
 static int
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1034
 ospf_check_auth (struct ospf_interface *oi, struct ospf_header *ospfh)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1035
 {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1036
-  int ret = 0;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1037
   struct crypt_key *ck;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1038
+  u_int16_t iface_auth_type;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1039
+  u_int16_t pkt_auth_type = ntohs (ospfh->auth_type);
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1040
 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1041
-  switch (ntohs (ospfh->auth_type))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1042
+  switch (pkt_auth_type)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1043
+  {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1044
+  case OSPF_AUTH_NULL: /* RFC2328 D.5.1 */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1045
+    if (OSPF_AUTH_NULL != (iface_auth_type = ospf_auth_type (oi)))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1046
     {
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1047
-    case OSPF_AUTH_NULL:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1048
-      ret = 1;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1049
-      break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1050
-    case OSPF_AUTH_SIMPLE:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1051
-      if (!memcmp (OSPF_IF_PARAM (oi, auth_simple), ospfh->u.auth_data, OSPF_AUTH_SIMPLE_SIZE))
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1052
-	ret = 1;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1053
-      else
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1054
-	ret = 0;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1055
-      break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1056
-    case OSPF_AUTH_CRYPTOGRAPHIC:
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1057
-      if ((ck = listgetdata (listtail(OSPF_IF_PARAM (oi,auth_crypt)))) == NULL)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1058
-	{
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1059
-	  ret = 0;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1060
-	  break;
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1061
-	}
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1062
-      
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1063
-      /* This is very basic, the digest processing is elsewhere */
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1064
-      if (ospfh->u.crypt.auth_data_len == OSPF_AUTH_MD5_SIZE && 
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1065
-          ospfh->u.crypt.key_id == ck->key_id &&
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff changeset
  1066
-          ntohs (ospfh->length) + OSPF_AUTH_MD5_SIZE <= OSPF_MAX_PACKET_SIZE)
f239fb8865f3 7153585 Problem with network/quagga
Brian Utterba&