blob: 11db2d712d579e419f3b0c89a405e4aea56fabda [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP Community list.
2 Copyright (C) 1999 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21/* Community-list deny and permit. */
22#define COMMUNITY_DENY 0
23#define COMMUNITY_PERMIT 1
24
25/* Number and string based community-list name. */
26#define COMMUNITY_LIST_STRING 0
27#define COMMUNITY_LIST_NUMBER 1
28
29/* Community-list entry types. */
30#define COMMUNITY_LIST_STANDARD 0 /* Standard community-list. */
31#define COMMUNITY_LIST_EXPANDED 1 /* Expanded community-list. */
32#define COMMUNITY_LIST_AUTO 2 /* Automatically detected. */
33#define EXTCOMMUNITY_LIST_STANDARD 3 /* Standard extcommunity-list. */
34#define EXTCOMMUNITY_LIST_EXPANDED 4 /* Expanded extcommunity-list. */
35#define EXTCOMMUNITY_LIST_AUTO 5 /* Automatically detected. */
36
37/* Community-list. */
38struct community_list
39{
40 /* Name of the community-list. */
41 char *name;
42
43 /* String or number. */
44 int sort;
45
46 /* Link to upper list. */
47 struct community_list_list *parent;
48
49 /* Linked list for other community-list. */
50 struct community_list *next;
51 struct community_list *prev;
52
53 /* Community-list entry in this community-list. */
54 struct community_entry *head;
55 struct community_entry *tail;
56};
57
58/* Each entry in community-list. */
59struct community_entry
60{
61 struct community_entry *next;
62 struct community_entry *prev;
63
64 /* Permit or deny. */
65 u_char direct;
66
67 /* Standard or expanded. */
68 u_char style;
69
70 /* Any match. */
71 u_char any;
72
73 /* Community structure. */
74 union
75 {
76 struct community *com;
77 struct ecommunity *ecom;
78 } u;
79
80 /* Configuration string. */
81 char *config;
82
83 /* Expanded community-list regular expression. */
84 regex_t *reg;
85};
86
87/* Linked list of community-list. */
88struct community_list_list
89{
90 struct community_list *head;
91 struct community_list *tail;
92};
93
94/* Master structure of community-list and extcommunity-list. */
95struct community_list_master
96{
97 struct community_list_list num;
98 struct community_list_list str;
99};
100
101/* Community-list handler. community_list_init() returns this
102 structure as handler. */
103struct community_list_handler
104{
105 /* Community-list. */
106 struct community_list_master community_list;
107
108 /* Exteded community-list. */
109 struct community_list_master extcommunity_list;
110};
111
112/* Error code of community-list. */
113#define COMMUNITY_LIST_ERR_CANT_FIND_LIST -1
114#define COMMUNITY_LIST_ERR_MALFORMED_VAL -2
115#define COMMUNITY_LIST_ERR_STANDARD_CONFLICT -3
116#define COMMUNITY_LIST_ERR_EXPANDED_CONFLICT -4
117
118/* Handler. */
119extern struct community_list_handler *bgp_clist;
120
121/* Prototypes. */
122struct community_list_handler *community_list_init ();
123
paulfd79ac92004-10-13 05:06:08 +0000124int community_list_set (struct community_list_handler *ch, const char *name,
125 const char *str, int direct, int style);
126int community_list_unset (struct community_list_handler *ch, const char *name,
127 const char *str, int direct, int style);
128int extcommunity_list_set (struct community_list_handler *ch, const char *name,
129 const char *str, int direct, int style);
130int extcommunity_list_unset (struct community_list_handler *ch,
131 const char *name, const char *str,
132 int direct, int style);
paul718e3742002-12-13 20:15:29 +0000133
134struct community_list_master *
135community_list_master_lookup (struct community_list_handler *, int);
136
137struct community_list *
paulfd79ac92004-10-13 05:06:08 +0000138community_list_lookup (struct community_list_handler *, const char *, int);
paul718e3742002-12-13 20:15:29 +0000139
140int community_list_match (struct community *, struct community_list *);
paulfd79ac92004-10-13 05:06:08 +0000141int ecommunity_list_match (struct ecommunity *, struct community_list *);
paul718e3742002-12-13 20:15:29 +0000142int community_list_exact_match (struct community *, struct community_list *);
143struct community *
144community_list_match_delete (struct community *,
145 struct community_list *);