blob: 6f1faf0b75bd4defd894c0da550a37669058ea23 [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
hassofee6e4e2005-02-02 16:29:31 +000021/* Master Community-list. */
22#define COMMUNITY_LIST_MASTER 0
23#define EXTCOMMUNITY_LIST_MASTER 1
24
paul718e3742002-12-13 20:15:29 +000025/* 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. */
hassofee6e4e2005-02-02 16:29:31 +000036#define EXTCOMMUNITY_LIST_STANDARD 2 /* Standard extcommunity-list. */
37#define EXTCOMMUNITY_LIST_EXPANDED 3 /* Expanded extcommunity-list. */
paul718e3742002-12-13 20:15:29 +000038
39/* Community-list. */
40struct 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. */
61struct 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. */
90struct 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. */
97struct 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. */
105struct 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. */
121extern struct community_list_handler *bgp_clist;
122
123/* Prototypes. */
124struct community_list_handler *community_list_init ();
125
paulfd79ac92004-10-13 05:06:08 +0000126int community_list_set (struct community_list_handler *ch, const char *name,
127 const char *str, int direct, int style);
128int community_list_unset (struct community_list_handler *ch, const char *name,
129 const char *str, int direct, int style);
130int extcommunity_list_set (struct community_list_handler *ch, const char *name,
131 const char *str, int direct, int style);
132int extcommunity_list_unset (struct community_list_handler *ch,
133 const char *name, const char *str,
134 int direct, int style);
paul718e3742002-12-13 20:15:29 +0000135
136struct community_list_master *
137community_list_master_lookup (struct community_list_handler *, int);
138
139struct community_list *
paulfd79ac92004-10-13 05:06:08 +0000140community_list_lookup (struct community_list_handler *, const char *, int);
paul718e3742002-12-13 20:15:29 +0000141
142int community_list_match (struct community *, struct community_list *);
paulfd79ac92004-10-13 05:06:08 +0000143int ecommunity_list_match (struct ecommunity *, struct community_list *);
paul718e3742002-12-13 20:15:29 +0000144int community_list_exact_match (struct community *, struct community_list *);
145struct community *
146community_list_match_delete (struct community *,
147 struct community_list *);