diff options
author | Denis Ovsienko <infrastation@yandex.ru> | 2011-09-19 16:30:47 +0400 |
---|---|---|
committer | Denis Ovsienko <infrastation@yandex.ru> | 2011-09-25 18:16:51 +0400 |
commit | d0511bd9b09a6952f18bf3a926de759638a5cda7 (patch) | |
tree | 6c6cd56ce610dad94c17e71b89780c5c914385b0 | |
parent | dda8187956966b2cc977855603a5beeeada3cc76 (diff) |
bgpd: check LOCAL_PREF attribute flags (BZ#674)
* 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
-rw-r--r-- | bgpd/bgp_attr.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index f34a7565..fe2d20e8 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -965,8 +965,33 @@ bgp_attr_med (struct peer *peer, bgp_size_t length, /* Local preference attribute. */ static int 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. */ @@ -1644,7 +1669,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); |