Annotation of embedaddon/quagga/bgpd/bgp_attr.h, revision 1.1.1.3

1.1       misho       1: /* BGP attributes. 
                      2:    Copyright (C) 1996, 97, 98 Kunihiro Ishiguro
                      3: 
                      4: This file is part of GNU Zebra.
                      5: 
                      6: GNU Zebra is free software; you can redistribute it and/or modify it
                      7: under the terms of the GNU General Public License as published by the
                      8: Free Software Foundation; either version 2, or (at your option) any
                      9: later version.
                     10: 
                     11: GNU Zebra is distributed in the hope that it will be useful, but
                     12: WITHOUT ANY WARRANTY; without even the implied warranty of
                     13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     14: General Public License for more details.
                     15: 
                     16: You should have received a copy of the GNU General Public License
                     17: along with GNU Zebra; see the file COPYING.  If not, write to the Free
                     18: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
                     19: 02111-1307, USA.  */
                     20: 
                     21: #ifndef _QUAGGA_BGP_ATTR_H
                     22: #define _QUAGGA_BGP_ATTR_H
                     23: 
                     24: /* Simple bit mapping. */
                     25: #define BITMAP_NBBY 8
                     26: 
                     27: #define SET_BITMAP(MAP, NUM) \
                     28:         SET_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
                     29: 
                     30: #define CHECK_BITMAP(MAP, NUM) \
                     31:         CHECK_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
                     32: 
                     33: #define BGP_MED_MAX UINT32_MAX
                     34: 
                     35: 
                     36: /* BGP Attribute type range. */
                     37: #define BGP_ATTR_TYPE_RANGE     256
                     38: #define BGP_ATTR_BITMAP_SIZE    (BGP_ATTR_TYPE_RANGE / BITMAP_NBBY)
                     39: 
                     40: /* BGP Attribute flags. */
                     41: #define BGP_ATTR_FLAG_OPTIONAL  0x80   /* Attribute is optional. */
                     42: #define BGP_ATTR_FLAG_TRANS     0x40   /* Attribute is transitive. */
                     43: #define BGP_ATTR_FLAG_PARTIAL   0x20   /* Attribute is partial. */
                     44: #define BGP_ATTR_FLAG_EXTLEN    0x10   /* Extended length flag. */
                     45: 
                     46: /* BGP attribute header must bigger than 2. */
                     47: #define BGP_ATTR_MIN_LEN        3       /* Attribute flag, type length. */
                     48: #define BGP_ATTR_DEFAULT_WEIGHT 32768
                     49: 
1.1.1.3 ! misho      50: struct bgp_attr_encap_subtlv {
        !            51:     struct bgp_attr_encap_subtlv       *next;          /* for chaining */
        !            52:     uint16_t                           type;
        !            53:     uint16_t                           length;
        !            54:     uint8_t                            value[1];       /* will be extended */
        !            55: };
        !            56: 
1.1       misho      57: /* Additional/uncommon BGP attributes.
                     58:  * lazily allocated as and when a struct attr
                     59:  * requires it.
                     60:  */
                     61: struct attr_extra
                     62: {
                     63:   /* Multi-Protocol Nexthop, AFI IPv6 */
                     64:   struct in6_addr mp_nexthop_global;
                     65:   struct in6_addr mp_nexthop_local;
                     66: 
                     67:   /* Extended Communities attribute. */
                     68:   struct ecommunity *ecommunity;
                     69:   
                     70:   /* Route-Reflector Cluster attribute */
                     71:   struct cluster_list *cluster;
                     72:   
                     73:   /* Unknown transitive attribute. */
                     74:   struct transit *transit;
                     75: 
                     76:   struct in_addr mp_nexthop_global_in;
                     77:   struct in_addr mp_nexthop_local_in;
                     78:   
                     79:   /* Aggregator Router ID attribute */
                     80:   struct in_addr aggregator_addr;
                     81:   
                     82:   /* Route Reflector Originator attribute */
                     83:   struct in_addr originator_id;
                     84:   
                     85:   /* Local weight, not actually an attribute */
                     86:   u_int32_t weight;
                     87:   
                     88:   /* Aggregator ASN */
                     89:   as_t aggregator_as;
                     90:   
                     91:   /* MP Nexthop length */
                     92:   u_char mp_nexthop_len;
1.1.1.3 ! misho      93: 
        !            94:   uint16_t                     encap_tunneltype;       /* grr */
        !            95:   struct bgp_attr_encap_subtlv *encap_subtlvs;         /* rfc5512 */
1.1       misho      96: };
                     97: 
                     98: /* BGP core attribute structure. */
                     99: struct attr
                    100: {
                    101:   /* AS Path structure */
                    102:   struct aspath *aspath;
                    103: 
                    104:   /* Community structure */
                    105:   struct community *community; 
                    106:   
                    107:   /* Lazily allocated pointer to extra attributes */
                    108:   struct attr_extra *extra;
                    109:   
                    110:   /* Reference count of this attribute. */
                    111:   unsigned long refcnt;
                    112: 
                    113:   /* Flag of attribute is set or not. */
                    114:   u_int32_t flag;
                    115:   
                    116:   /* Apart from in6_addr, the remaining static attributes */
                    117:   struct in_addr nexthop;
                    118:   u_int32_t med;
                    119:   u_int32_t local_pref;
                    120:   
                    121:   /* Path origin attribute */
                    122:   u_char origin;
                    123: };
                    124: 
                    125: /* Router Reflector related structure. */
                    126: struct cluster_list
                    127: {
                    128:   unsigned long refcnt;
                    129:   int length;
                    130:   struct in_addr *list;
                    131: };
                    132: 
                    133: /* Unknown transit attribute. */
                    134: struct transit
                    135: {
                    136:   unsigned long refcnt;
                    137:   int length;
                    138:   u_char *val;
                    139: };
                    140: 
                    141: #define ATTR_FLAG_BIT(X)  (1 << ((X) - 1))
                    142: 
                    143: typedef enum {
                    144:  BGP_ATTR_PARSE_PROCEED = 0,
                    145:  BGP_ATTR_PARSE_ERROR = -1,
                    146:  BGP_ATTR_PARSE_WITHDRAW = -2,
1.1.1.3 ! misho     147: 
        !           148:  /* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR */
        !           149:  BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3,
1.1       misho     150: } bgp_attr_parse_ret_t;
                    151: 
                    152: /* Prototypes. */
                    153: extern void bgp_attr_init (void);
                    154: extern void bgp_attr_finish (void);
                    155: extern bgp_attr_parse_ret_t bgp_attr_parse (struct peer *, struct attr *,
                    156:                                            bgp_size_t, struct bgp_nlri *,
                    157:                                            struct bgp_nlri *);
                    158: extern struct attr_extra *bgp_attr_extra_get (struct attr *);
                    159: extern void bgp_attr_extra_free (struct attr *);
                    160: extern void bgp_attr_dup (struct attr *, struct attr *);
                    161: extern struct attr *bgp_attr_intern (struct attr *attr);
                    162: extern void bgp_attr_unintern_sub (struct attr *);
                    163: extern void bgp_attr_unintern (struct attr **);
                    164: extern void bgp_attr_flush (struct attr *);
                    165: extern struct attr *bgp_attr_default_set (struct attr *attr, u_char);
                    166: extern struct attr *bgp_attr_default_intern (u_char);
                    167: extern struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char,
                    168:                                         struct aspath *, 
                    169:                                         struct community *, int as_set);
1.1.1.3 ! misho     170: extern bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *,
        !           171:                                        struct stream *, struct attr *,
        !           172:                                        struct prefix *, afi_t, safi_t,
        !           173:                                        struct peer *, struct prefix_rd *,
        !           174:                                        u_char *);
1.1       misho     175: extern void bgp_dump_routes_attr (struct stream *, struct attr *,
                    176:                                  struct prefix *);
                    177: extern int attrhash_cmp (const void *, const void *);
                    178: extern unsigned int attrhash_key_make (void *);
                    179: extern void attr_show_all (struct vty *);
                    180: extern unsigned long int attr_count (void);
                    181: extern unsigned long int attr_unknown_count (void);
                    182: 
                    183: /* Cluster list prototypes. */
                    184: extern int cluster_loop_check (struct cluster_list *, struct in_addr);
                    185: extern void cluster_unintern (struct cluster_list *);
                    186: 
                    187: /* Transit attribute prototypes. */
                    188: void transit_unintern (struct transit *);
                    189: 
1.1.1.2   misho     190: /* Below exported for unit-test purposes only */
                    191: struct bgp_attr_parser_args {
                    192:   struct peer *peer;
                    193:   bgp_size_t length; /* attribute data length; */
                    194:   bgp_size_t total; /* total length, inc header */
                    195:   struct attr *attr;
                    196:   u_int8_t type;
                    197:   u_int8_t flags;
                    198:   u_char *startp;   
                    199: };
                    200: extern int bgp_mp_reach_parse (struct bgp_attr_parser_args *args, 
1.1       misho     201:                               struct bgp_nlri *);
1.1.1.2   misho     202: extern int bgp_mp_unreach_parse (struct bgp_attr_parser_args *args,
                    203:                                  struct bgp_nlri *);
1.1.1.3 ! misho     204: 
        !           205: extern struct bgp_attr_encap_subtlv *
        !           206: encap_tlv_dup(struct bgp_attr_encap_subtlv *orig);
        !           207: 
        !           208: extern void
        !           209: bgp_attr_flush_encap(struct attr *attr);
        !           210: 
        !           211: /**
        !           212:  * Set of functions to encode MP_REACH_NLRI and MP_UNREACH_NLRI attributes.
        !           213:  * Typical call sequence is to call _start(), followed by multiple _prefix(),
        !           214:  * one for each NLRI that needs to be encoded into the UPDATE message, and
        !           215:  * finally the _end() function.
        !           216:  */
        !           217: extern size_t bgp_packet_mpattr_start(struct stream *s, afi_t afi, safi_t safi,
        !           218:                                      struct attr *attr);
        !           219: extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi,
        !           220:                                     struct prefix *p, struct prefix_rd *prd,
        !           221:                                     u_char *tag);
        !           222: extern size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi,
        !           223:                                             struct prefix *p);
        !           224: extern void bgp_packet_mpattr_end(struct stream *s, size_t sizep);
        !           225: 
        !           226: extern size_t bgp_packet_mpunreach_start (struct stream *s, afi_t afi,
        !           227:                                          safi_t safi);
        !           228: extern void bgp_packet_mpunreach_prefix (struct stream *s, struct prefix *p,
        !           229:                             afi_t afi, safi_t safi, struct prefix_rd *prd,
        !           230:                             u_char *tag);
        !           231: extern void bgp_packet_mpunreach_end (struct stream *s, size_t attrlen_pnt);
1.1       misho     232: 
                    233: #endif /* _QUAGGA_BGP_ATTR_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>