Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/dsslib/ip_t/bgp.h
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2000-2012 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* Phong Vo <[email protected]> *
19
* *
20
***********************************************************************/
21
#pragma prototyped
22
/*
23
* bgp data interface
24
*
25
* Glenn Fowler
26
* AT&T Research
27
*/
28
29
#ifndef _BGP_H
30
#define _BGP_H
31
32
#include <ast_common.h>
33
#include <ip6.h>
34
35
#define BGP_VERSION 20120515L /* interface version */
36
37
#define BGP_SET16 0xffff /* as16 path set marker */
38
#define BGP_SET32 0xffffffff /* as32 path set marker */
39
40
/*
41
* attributes (even, 1 bit set)
42
*/
43
44
#define BGP_MESSAGE (1<<1)
45
#define BGP_atomic (1<<2)
46
#define BGP_best (1<<3)
47
#define BGP_damped (1<<4)
48
#define BGP_history (1<<5)
49
#define BGP_internal (1<<6)
50
#define BGP_ipv6 (1<<7)
51
#define BGP_rib_failure (1<<8)
52
#define BGP_slot (1<<9)
53
#define BGP_stale (1<<10)
54
#define BGP_suppressed (1<<11)
55
#define BGP_valid (1<<12)
56
#define BGP_PART (1<<15)
57
58
/*
59
* indices (odd, 2 bits set)
60
*/
61
62
#define BGP_afi ((1<<1)|1)
63
#define BGP_agg_addr ((2<<1)|1)
64
#define BGP_agg_addr32 ((3<<1)|1)
65
#define BGP_agg_addr32v4 ((4<<1)|1)
66
#define BGP_agg_addr32v6 ((5<<1)|1)
67
#define BGP_agg_addrv4 ((6<<1)|1)
68
#define BGP_agg_addrv6 ((7<<1)|1)
69
#define BGP_agg_as ((8<<1)|1)
70
#define BGP_agg_as16 ((9<<1)|1)
71
#define BGP_agg_as32 ((10<<1)|1)
72
#define BGP_bits ((11<<1)|1)
73
#define BGP_bitsv4 ((12<<1)|1)
74
#define BGP_bitsv6 ((13<<1)|1)
75
#define BGP_cluster ((14<<1)|1)
76
#define BGP_community ((15<<1)|1)
77
#define BGP_dpa_addr ((16<<1)|1)
78
#define BGP_dpa_addrv4 ((17<<1)|1)
79
#define BGP_dpa_addrv6 ((18<<1)|1)
80
#define BGP_dpa_as ((19<<1)|1)
81
#define BGP_dpa_as16 ((20<<1)|1)
82
#define BGP_dpa_as32 ((21<<1)|1)
83
#define BGP_dst_addr ((22<<1)|1)
84
#define BGP_dst_addrv4 ((23<<1)|1)
85
#define BGP_dst_addrv6 ((24<<1)|1)
86
#define BGP_dst_as ((25<<1)|1)
87
#define BGP_dst_as16 ((26<<1)|1)
88
#define BGP_dst_as32 ((27<<1)|1)
89
#define BGP_extended ((28<<1)|1)
90
#define BGP_flags ((29<<1)|1)
91
#define BGP_hop ((30<<1)|1)
92
#define BGP_hopv4 ((31<<1)|1)
93
#define BGP_hopv6 ((32<<1)|1)
94
#define BGP_id ((33<<1)|1)
95
#define BGP_key ((34<<1)|1)
96
#define BGP_label ((35<<1)|1)
97
#define BGP_labels ((36<<1)|1)
98
#define BGP_local ((37<<1)|1)
99
#define BGP_med ((38<<1)|1)
100
#define BGP_message ((39<<1)|1)
101
#define BGP_mvpn ((40<<1)|1)
102
#define BGP_new_state ((41<<1)|1)
103
#define BGP_old_state ((42<<1)|1)
104
#define BGP_origin ((43<<1)|1)
105
#define BGP_originator ((44<<1)|1)
106
#define BGP_path ((45<<1)|1)
107
#define BGP_path16 ((46<<1)|1)
108
#define BGP_path32 ((47<<1)|1)
109
#define BGP_prefix ((48<<1)|1)
110
#define BGP_prefixv4 ((49<<1)|1)
111
#define BGP_prefixv6 ((50<<1)|1)
112
#define BGP_rd_addr ((51<<1)|1)
113
#define BGP_rd_as ((52<<1)|1)
114
#define BGP_rd_number ((53<<1)|1)
115
#define BGP_rd_type ((54<<1)|1)
116
#define BGP_safi ((55<<1)|1)
117
#define BGP_src_addr ((56<<1)|1)
118
#define BGP_src_addrv4 ((57<<1)|1)
119
#define BGP_src_addrv6 ((58<<1)|1)
120
#define BGP_src_as ((59<<1)|1)
121
#define BGP_src_as16 ((60<<1)|1)
122
#define BGP_src_as32 ((61<<1)|1)
123
#define BGP_stamp ((62<<1)|1)
124
#define BGP_time ((63<<1)|1)
125
#define BGP_type ((64<<1)|1)
126
#define BGP_unknown ((65<<1)|1)
127
#define BGP_usec ((66<<1)|1)
128
#define BGP_weight ((67<<1)|1)
129
130
#define BGP_LAST 67
131
132
#define BGP_INDEX(x) (((x)>>1)-1)
133
134
/*
135
* field set bits
136
*/
137
138
#define BGP_SET_agg_addr32v4 (1<<0)
139
#define BGP_SET_agg_addr32v6 (1<<1)
140
#define BGP_SET_agg_addrv4 (1<<2)
141
#define BGP_SET_agg_addrv6 (1<<3)
142
#define BGP_SET_cluster (1<<4)
143
#define BGP_SET_community (1<<5)
144
#define BGP_SET_dpa_addrv4 (1<<6)
145
#define BGP_SET_dpa_addrv6 (1<<7)
146
#define BGP_SET_dst_addrv4 (1<<8)
147
#define BGP_SET_dst_addrv6 (1<<9)
148
#define BGP_SET_extended (1<<10)
149
#define BGP_SET_hopv4 (1<<11)
150
#define BGP_SET_hopv6 (1<<12)
151
#define BGP_SET_mvpn (1<<13)
152
#define BGP_SET_originatorv6 (1<<14)
153
#define BGP_SET_path16 (1L<<15)
154
#define BGP_SET_path32 (1L<<16)
155
#define BGP_SET_prefixv4 (1L<<17)
156
#define BGP_SET_prefixv6 (1L<<18)
157
#define BGP_SET_src_addrv4 (1L<<19)
158
#define BGP_SET_src_addrv6 (1L<<20)
159
#define BGP_SET_unknown (1L<<21)
160
161
/*
162
* BGP_type
163
*/
164
165
#define BGP_TYPE_announce 'A'
166
#define BGP_TYPE_keepalive 'K'
167
#define BGP_TYPE_notification 'N'
168
#define BGP_TYPE_open 'O'
169
#define BGP_TYPE_state_change 'S'
170
#define BGP_TYPE_table_dump 'T'
171
#define BGP_TYPE_withdraw 'W'
172
173
/*
174
* BGP_origin
175
*/
176
177
#define BGP_ORIGIN_incomplete '?'
178
#define BGP_ORIGIN_egp 'e'
179
#define BGP_ORIGIN_igp 'i'
180
181
#define BGPCLUSTER(r) ((Bgpnum_t*)((r)->data+(r)->cluster.offset))
182
#define BGPCOMMUNITY(r) ((Bgpasn_t*)((r)->data+(r)->community.offset))
183
#define BGPEXTENDED(r) ((Bgpasn_t*)((r)->data+(r)->extended.offset))
184
#define BGPLABELS(r) ((Bgpasn_t*)((r)->data+(r)->labels.offset))
185
#define BGPPATH(r) ((Bgpasn_t*)((r)->data+(r)->path.offset))
186
#define BGPPATH32(r) ((Bgpnum_t*)((r)->data+(r)->path32.offset))
187
188
union Bgpaddr_u; typedef union Bgpaddr_u Bgpaddr_t;
189
struct Bgproute_s; typedef struct Bgproute_s Bgproute_t;
190
struct Bgpvec_s; typedef struct Bgpvec_s Bgpvec_t;
191
192
typedef uint16_t Bgpasn_t;
193
typedef uint32_t Bgpnum_t;
194
195
struct Bgpvec_s /* vector data */
196
{
197
Bgpasn_t offset; /* Bgproute_t.data[] offset */
198
Bgpasn_t size; /* # elements */
199
Bgpasn_t maxsize; /* max allocated size */
200
Bgpasn_t elements; /* sizeof() elements */
201
Bgpasn_t flags; /* data-specific flags */
202
Bgpasn_t attr; /* data-specific attribute */
203
};
204
205
union Bgpaddr_u /* ipv4/ipv6 address */
206
{
207
Bgpnum_t v4; /* ipv4 addr */
208
unsigned char v6[16]; /* ipv6 addr */
209
};
210
211
/* BGP_TYPE_state_change */
212
213
#define old_state agg_as
214
#define new_state dpa_as
215
216
/* BGP_TYPE_open */
217
218
#define open_version med
219
#define open_as agg_as
220
#define open_hold dpa_as
221
#define open_id originator.v4
222
#define open_size local
223
224
/* BGP_TYPE_notification */
225
226
#define note_code agg_as
227
#define note_subcode dpa_as
228
#define note_size local
229
230
struct Bgproute_s
231
{
232
/* 128/32 bit members */
233
234
Bgpaddr_t addr; /* prefix address */
235
Bgpaddr_t agg_addr32; /* aggregator as32 addr */
236
Bgpaddr_t agg_addr; /* aggregator addr */
237
Bgpaddr_t dpa_addr; /* dpa addr */
238
Bgpaddr_t dst_addr; /* destination addr */
239
Bgpaddr_t hop; /* next hop addr */
240
Bgpaddr_t originator; /* originator addr */
241
Bgpaddr_t rd_addr; /* nlri rd addr */
242
Bgpaddr_t src_addr; /* source addr */
243
244
/* 32 bit members */
245
246
Bgpnum_t size; /* actual record size */
247
Bgpnum_t local; /* local preference */
248
Bgpnum_t med; /* med */
249
Bgpnum_t weight; /* router proprietary weight */
250
Bgpnum_t time; /* packet event time stamp */
251
Bgpnum_t usec; /* packet event time stamp usec */
252
Bgpnum_t stamp; /* data time stamp */
253
Bgpnum_t message; /* message group index */
254
Bgpnum_t agg_as32; /* aggregator as32 */
255
Bgpnum_t dpa_as32; /* dpa as32 */
256
Bgpnum_t dst_as32; /* destination as32 */
257
Bgpnum_t src_as32; /* source as32 */
258
Bgpnum_t set; /* BGP_SET_* bitmask */
259
Bgpnum_t label; /* nlri label */
260
Bgpnum_t rd_as; /* nlri rd as number */
261
Bgpnum_t rd_number; /* nlri rd assigned number */
262
Bgpnum_t flags; /* aux flags */
263
Bgpnum_t id; /* aux id */
264
265
/* 16 bit members */
266
267
Bgpvec_t path; /* as path */
268
Bgpvec_t cluster; /* clusters */
269
Bgpvec_t community; /* communities */
270
Bgpvec_t extended; /* extended communities */
271
Bgpvec_t labels; /* NLRI labels */
272
Bgpvec_t path32; /* as32 path */
273
Bgpvec_t unknown; /* unknown attributes */
274
Bgpvec_t ped; /* pe discriminator addr.label */
275
276
Bgpasn_t attr; /* BGP_[a-z]* route attributes */
277
Bgpasn_t agg_as; /* aggregator as */
278
Bgpasn_t dpa_as; /* dpa as */
279
Bgpasn_t dst_as; /* destination as */
280
Bgpasn_t src_as; /* source as */
281
282
/* 8 bit members */
283
284
unsigned char bits; /* prefix bits */
285
unsigned char type; /* BGP_TYPE_* */
286
unsigned char origin; /* BGP_ORIGIN_* */
287
unsigned char blocks; /* # blocks for this record */
288
unsigned char afi; /* announce afi */
289
unsigned char safi; /* announce subsequent afi */
290
unsigned char p1; /* parameter 1 */
291
unsigned char rd_type; /* nlri rd type */
292
293
/* unaligned fixed buffer members */
294
295
unsigned char prefixv6[17]; /* prefix */
296
297
char pad[5]; /* pad to 8 byte boundary */
298
299
char data[1704]; /* vector data (round to 2K) */
300
};
301
302
#endif
303
304