1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 2002-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 <gsf@research.att.com>                  *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 /*
22  * bgp library implementation header
23  *
24  * Glenn Fowler
25  * AT&T Research
26  */
27 
28 #ifndef _BGPLIB_H
29 #define _BGPLIB_H	1
30 
31 #include <dsslib.h>
32 #include <tm.h>
33 
34 #include "bgp.h"
35 
36 #define BGPFILE(f)		((Bgp_t*)(f)->dss->data)
37 #define BGPDATA(p)		BGPFILE(DSSRECORD(p)->file)
38 
39 #define BGP_FIXED		offsetof(Bgproute_t,data)
40 
41 typedef struct Prefix_s			/*  ip prefix			*/
42 {
43 	uint32_t	addr;
44 	unsigned char	bits;
45 } Prefix_t;
46 
47 typedef struct Bgp_s			/* method handle		*/
48 {
49 	Sfio_t*		tmp;
50 	Cxtype_t*	type_as16path;
51 	Cxtype_t*	type_as32path;
52 	Cxtype_t*	type_cluster;
53 	Cxtype_t*	type_community;
54 	Cxtype_t*	type_extended;
55 	Cxtype_t*	type_ipv4addr;
56 	Cxtype_t*	type_ipv4prefix;
57 	Cxtype_t*	type_ipv6addr;
58 	Cxtype_t*	type_ipv6prefix;
59 	Cxtype_t*	type_label;
60 	Bgproute_t	sub[2];
61 } Bgp_t;
62 
63 #define BGP_METHOD_ANONYMIZE		0x0001
64 
65 #define BGPALLOC(r,o,t,p,m,v,e,d) \
66 	do { \
67 		if (m > (v)->maxsize) \
68 		{ \
69 			int	n; \
70 			o = roundof(o, sizeof(t)); \
71 			n = (o >= elementsof((r)->data)) ? \
72 				0 : \
73 				(elementsof((r)->data) - o) / sizeof(t); \
74 			if (m > n) \
75 			{ \
76 				if ((d)->errorf) \
77 					(*(d)->errorf)(NiL, d, 1, "%s length %d truncated to %d", e, m, n); \
78 				m = n; \
79 			} \
80 			(v)->offset = o; \
81 			(v)->maxsize = m; \
82 			o += m * sizeof(t); \
83 		} \
84 		(v)->size = m; \
85 		p = (t*)((r)->data+(v)->offset); \
86 	} while (0)
87 
88 #define bgp_first_format	(&bgp_fixed_format)
89 #define bgp_cisco_next		(&bgp_ciscov6_format)
90 #define bgp_ciscov6_next	(&bgp_mrt_anonymize_format)
91 #define bgp_fixed_next		(&bgp_cisco_format)
92 #define bgp_mrt_anonymize_next	(&bgp_mrt_format)
93 #define bgp_mrt_next		(&bgp_ipma_format)
94 #define bgp_ipma_next		(&bgp_table_format)
95 #define bgp_table_next		0
96 
97 #define bgp_method		_dss_bgp_method
98 #define bgp_formats		_dss_bgp_formats
99 #define bgp_cisco_format	_dss_bgp_cisco_format
100 #define bgp_ciscov6_format	_dss_bgp_ciscov6_format
101 #define bgp_fixed_format	_dss_bgp_fixed_format
102 #define bgp_mrt_anonymize_format _dss_bgp_mrt_anonymize_format
103 #define bgp_mrt_format		_dss_bgp_mrt_format
104 #define bgp_ipma_format		_dss_bgp_ipma_format
105 #define bgp_table_format	_dss_bgp_table_format
106 
107 extern Dssformat_t*		bgp_formats;
108 extern Dssformat_t		bgp_cisco_format;
109 extern Dssformat_t		bgp_ciscov6_format;
110 extern Dssformat_t		bgp_fixed_format;
111 extern Dssformat_t		bgp_mrt_format;
112 extern Dssformat_t		bgp_mrt_anonymize_format;
113 extern Dssformat_t		bgp_ipma_format;
114 extern Dssformat_t		bgp_table_format;
115 
116 #endif
117