paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* BGP Community list. |
| 2 | Copyright (C) 1999 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 | |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 21 | /* Master Community-list. */ |
| 22 | #define COMMUNITY_LIST_MASTER 0 |
| 23 | #define EXTCOMMUNITY_LIST_MASTER 1 |
| 24 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 25 | /* Community-list deny and permit. */ |
| 26 | #define COMMUNITY_DENY 0 |
| 27 | #define COMMUNITY_PERMIT 1 |
| 28 | |
| 29 | /* Number and string based community-list name. */ |
| 30 | #define COMMUNITY_LIST_STRING 0 |
| 31 | #define COMMUNITY_LIST_NUMBER 1 |
| 32 | |
| 33 | /* Community-list entry types. */ |
| 34 | #define COMMUNITY_LIST_STANDARD 0 /* Standard community-list. */ |
| 35 | #define COMMUNITY_LIST_EXPANDED 1 /* Expanded community-list. */ |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 36 | #define EXTCOMMUNITY_LIST_STANDARD 2 /* Standard extcommunity-list. */ |
| 37 | #define EXTCOMMUNITY_LIST_EXPANDED 3 /* Expanded extcommunity-list. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 38 | |
| 39 | /* Community-list. */ |
| 40 | struct community_list |
| 41 | { |
| 42 | /* Name of the community-list. */ |
| 43 | char *name; |
| 44 | |
| 45 | /* String or number. */ |
| 46 | int sort; |
| 47 | |
| 48 | /* Link to upper list. */ |
| 49 | struct community_list_list *parent; |
| 50 | |
| 51 | /* Linked list for other community-list. */ |
| 52 | struct community_list *next; |
| 53 | struct community_list *prev; |
| 54 | |
| 55 | /* Community-list entry in this community-list. */ |
| 56 | struct community_entry *head; |
| 57 | struct community_entry *tail; |
| 58 | }; |
| 59 | |
| 60 | /* Each entry in community-list. */ |
| 61 | struct community_entry |
| 62 | { |
| 63 | struct community_entry *next; |
| 64 | struct community_entry *prev; |
| 65 | |
| 66 | /* Permit or deny. */ |
| 67 | u_char direct; |
| 68 | |
| 69 | /* Standard or expanded. */ |
| 70 | u_char style; |
| 71 | |
| 72 | /* Any match. */ |
| 73 | u_char any; |
| 74 | |
| 75 | /* Community structure. */ |
| 76 | union |
| 77 | { |
| 78 | struct community *com; |
| 79 | struct ecommunity *ecom; |
| 80 | } u; |
| 81 | |
| 82 | /* Configuration string. */ |
| 83 | char *config; |
| 84 | |
| 85 | /* Expanded community-list regular expression. */ |
| 86 | regex_t *reg; |
| 87 | }; |
| 88 | |
| 89 | /* Linked list of community-list. */ |
| 90 | struct community_list_list |
| 91 | { |
| 92 | struct community_list *head; |
| 93 | struct community_list *tail; |
| 94 | }; |
| 95 | |
| 96 | /* Master structure of community-list and extcommunity-list. */ |
| 97 | struct community_list_master |
| 98 | { |
| 99 | struct community_list_list num; |
| 100 | struct community_list_list str; |
| 101 | }; |
| 102 | |
| 103 | /* Community-list handler. community_list_init() returns this |
| 104 | structure as handler. */ |
| 105 | struct community_list_handler |
| 106 | { |
| 107 | /* Community-list. */ |
| 108 | struct community_list_master community_list; |
| 109 | |
| 110 | /* Exteded community-list. */ |
| 111 | struct community_list_master extcommunity_list; |
| 112 | }; |
| 113 | |
| 114 | /* Error code of community-list. */ |
| 115 | #define COMMUNITY_LIST_ERR_CANT_FIND_LIST -1 |
| 116 | #define COMMUNITY_LIST_ERR_MALFORMED_VAL -2 |
| 117 | #define COMMUNITY_LIST_ERR_STANDARD_CONFLICT -3 |
| 118 | #define COMMUNITY_LIST_ERR_EXPANDED_CONFLICT -4 |
| 119 | |
| 120 | /* Handler. */ |
| 121 | extern struct community_list_handler *bgp_clist; |
| 122 | |
| 123 | /* Prototypes. */ |
| 124 | struct community_list_handler *community_list_init (); |
| 125 | |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 126 | int community_list_set (struct community_list_handler *ch, const char *name, |
| 127 | const char *str, int direct, int style); |
| 128 | int community_list_unset (struct community_list_handler *ch, const char *name, |
| 129 | const char *str, int direct, int style); |
| 130 | int extcommunity_list_set (struct community_list_handler *ch, const char *name, |
| 131 | const char *str, int direct, int style); |
| 132 | int extcommunity_list_unset (struct community_list_handler *ch, |
| 133 | const char *name, const char *str, |
| 134 | int direct, int style); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 135 | |
| 136 | struct community_list_master * |
| 137 | community_list_master_lookup (struct community_list_handler *, int); |
| 138 | |
| 139 | struct community_list * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 140 | community_list_lookup (struct community_list_handler *, const char *, int); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 141 | |
| 142 | int community_list_match (struct community *, struct community_list *); |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 143 | int ecommunity_list_match (struct ecommunity *, struct community_list *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 144 | int community_list_exact_match (struct community *, struct community_list *); |
| 145 | struct community * |
| 146 | community_list_match_delete (struct community *, |
| 147 | struct community_list *); |