bgp_aspath.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* AS path related definitions.
  2. Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #ifndef _QUAGGA_BGP_ASPATH_H
  17. #define _QUAGGA_BGP_ASPATH_H
  18. /* AS path segment type. */
  19. #define AS_SET 1
  20. #define AS_SEQUENCE 2
  21. #define AS_CONFED_SEQUENCE 3
  22. #define AS_CONFED_SET 4
  23. /* Private AS range defined in RFC2270. */
  24. #define BGP_PRIVATE_AS_MIN 64512U
  25. #define BGP_PRIVATE_AS_MAX 65535U
  26. /* Private 4 byte AS range defined in RFC6996. */
  27. #define BGP_PRIVATE_AS4_MIN 4200000000U
  28. #define BGP_PRIVATE_AS4_MAX 4294967294U
  29. /* we leave BGP_AS_MAX as the 16bit AS MAX number. */
  30. #define BGP_AS_MAX 65535U
  31. #define BGP_AS4_MAX 4294967295U
  32. /* Transition 16Bit AS as defined by IANA */
  33. #define BGP_AS_TRANS 23456U
  34. #define BGP_AS_IS_PRIVATE(ASN) \
  35. (((ASN) >= BGP_PRIVATE_AS_MIN && (ASN) <= BGP_PRIVATE_AS_MAX) || \
  36. ((ASN) >= BGP_PRIVATE_AS4_MIN && (ASN) <= BGP_PRIVATE_AS4_MAX))
  37. /* AS_PATH segment data in abstracted form, no limit is placed on length */
  38. struct assegment
  39. {
  40. struct assegment *next;
  41. as_t *as;
  42. u_short length;
  43. u_char type;
  44. };
  45. /* AS path may be include some AsSegments. */
  46. struct aspath
  47. {
  48. /* Reference count to this aspath. */
  49. unsigned long refcnt;
  50. /* segment data */
  51. struct assegment *segments;
  52. /* String expression of AS path. This string is used by vty output
  53. and AS path regular expression match. */
  54. char *str;
  55. unsigned short str_len;
  56. };
  57. #define ASPATH_STR_DEFAULT_LEN 32
  58. /* Prototypes. */
  59. extern void aspath_init (void);
  60. extern void aspath_finish (void);
  61. extern struct aspath *aspath_parse (struct stream *, size_t, int);
  62. extern struct aspath *aspath_dup (struct aspath *);
  63. extern struct aspath *aspath_aggregate (struct aspath *, struct aspath *);
  64. extern struct aspath *aspath_aggregate_mpath (struct aspath *, struct aspath *);
  65. extern struct aspath *aspath_prepend (struct aspath *, struct aspath *);
  66. extern struct aspath *aspath_filter_exclude (struct aspath *, struct aspath *);
  67. extern struct aspath *aspath_add_seq_n (struct aspath *, as_t, unsigned);
  68. extern struct aspath *aspath_add_seq (struct aspath *, as_t);
  69. extern struct aspath *aspath_add_confed_seq (struct aspath *, as_t);
  70. extern int aspath_cmp (const void *, const void *);
  71. extern int aspath_cmp_left (const struct aspath *, const struct aspath *);
  72. extern int aspath_cmp_left_confed (const struct aspath *, const struct aspath *);
  73. extern struct aspath *aspath_delete_confed_seq (struct aspath *);
  74. extern struct aspath *aspath_empty (void);
  75. extern struct aspath *aspath_empty_get (void);
  76. extern struct aspath *aspath_str2aspath (const char *);
  77. extern void aspath_free (struct aspath *);
  78. extern struct aspath *aspath_intern (struct aspath *);
  79. extern void aspath_unintern (struct aspath **);
  80. extern const char *aspath_print (struct aspath *);
  81. extern void aspath_print_vty (struct vty *, const char *, struct aspath *, const char *);
  82. extern void aspath_print_all_vty (struct vty *);
  83. extern unsigned int aspath_key_make (void *);
  84. extern int aspath_loop_check (struct aspath *, as_t);
  85. extern int aspath_private_as_check (struct aspath *);
  86. extern int aspath_firstas_check (struct aspath *, as_t);
  87. extern int aspath_confed_check (struct aspath *);
  88. extern int aspath_left_confed_check (struct aspath *);
  89. extern unsigned long aspath_count (void);
  90. extern unsigned int aspath_count_hops (const struct aspath *);
  91. extern unsigned int aspath_count_confeds (struct aspath *);
  92. extern unsigned int aspath_size (struct aspath *);
  93. extern as_t aspath_highest (struct aspath *);
  94. extern as_t aspath_leftmost (struct aspath *);
  95. extern size_t aspath_put (struct stream *, struct aspath *, int);
  96. extern struct aspath *aspath_reconcile_as4 (struct aspath *, struct aspath *);
  97. extern unsigned int aspath_has_as4 (struct aspath *);
  98. /* For SNMP BGP4PATHATTRASPATHSEGMENT, might be useful for debug */
  99. extern u_char *aspath_snmp_pathseg (struct aspath *, size_t *);
  100. #endif /* _QUAGGA_BGP_ASPATH_H */