]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: check LOCAL_PREF attribute flags (BZ#674)
authorDenis Ovsienko <infrastation@yandex.ru>
Mon, 19 Sep 2011 12:30:47 +0000 (16:30 +0400)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 27 Sep 2011 17:15:56 +0000 (21:15 +0400)
* bgp_attr.c
  * bgp_attr_local_pref(): accept extra argument, add checks for
    "optional" and "transitive" bits, log each error condition
    independently
  * bgp_attr_parse(): provide extra argument

bgpd/bgp_attr.c

index 0af240e23a1dd49773b051dfa515e90fc8f035a8..337ddb7c54eb6ea6d86b6fc1d3da830d6dd5c42a 100644 (file)
@@ -1025,8 +1025,33 @@ bgp_attr_med (struct peer *peer, bgp_size_t length,
 /* Local preference attribute. */
 static bgp_attr_parse_ret_t
 bgp_attr_local_pref (struct peer *peer, bgp_size_t length, 
-                    struct attr *attr, u_char flag)
+                    struct attr *attr, u_char flag, u_char *startp)
 {
+  bgp_size_t total;
+
+  total = length + (CHECK_FLAG (flag, BGP_ATTR_FLAG_EXTLEN) ? 4 : 3);
+  /* Flag checks. */
+  if (CHECK_FLAG (flag, BGP_ATTR_FLAG_OPTIONAL))
+    {
+      zlog (peer->log, LOG_ERR,
+           "LOCAL_PREF attribute must be flagged as \"well-known\" (%u)", flag);
+      bgp_notify_send_with_data (peer,
+                                BGP_NOTIFY_UPDATE_ERR,
+                                BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR,
+                                startp, total);
+      return -1;
+    }
+  if (! CHECK_FLAG (flag, BGP_ATTR_FLAG_TRANS))
+    {
+      zlog (peer->log, LOG_ERR,
+           "LOCAL_PREF attribute must be flagged as \"transitive\" (%u)", flag);
+      bgp_notify_send_with_data (peer,
+                                BGP_NOTIFY_UPDATE_ERR,
+                                BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR,
+                                startp, total);
+      return -1;
+    }
+
   /* If it is contained in an UPDATE message that is received from an
      external peer, then this attribute MUST be ignored by the
      receiving speaker. */
@@ -1704,7 +1729,7 @@ bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size,
          ret = bgp_attr_med (peer, length, attr, flag, startp);
          break;
        case BGP_ATTR_LOCAL_PREF:
-         ret = bgp_attr_local_pref (peer, length, attr, flag);
+         ret = bgp_attr_local_pref (peer, length, attr, flag, startp);
          break;
        case BGP_ATTR_ATOMIC_AGGREGATE:
          ret = bgp_attr_atomic (peer, length, attr, flag);