Zero-length arrays are a GCC extension, and some compilers don't support
[metze/wireshark/wip.git] / packet-bgp.h
1 /* packet-bgp.c
2  * Definitions for BGP packet disassembly structures and routine
3  *
4  * $Id: packet-bgp.h,v 1.4 1999/11/11 21:08:52 itojun Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@unicom.net>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  * 
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifndef __PACKET_BGP_H__
26 #define __PACKET_BGP_H__
27
28 /* some handy things to know */
29 #define BGP_MAX_PACKET_SIZE             4096
30 #define BGP_MARKER_SIZE                 16
31 #define BGP_HEADER_SIZE                 19
32 #define BGP_MIN_OPEN_MSG_SIZE           29
33 #define BGP_MIN_UPDATE_MSG_SIZE         23
34 #define BGP_MIN_NOTIFICATION_MSG_SIZE   21
35 #define BGP_MIN_KEEPALVE_MSG_SIZE       BGP_HEADER_SIZE
36 #define BGP_MAX_AS_PATH_LENGTH          32      /* guint16s */
37
38 #define BGP_OPEN                1
39 #define BGP_UPDATE              2
40 #define BGP_NOTIFICATION        3
41 #define BGP_KEEPALIVE           4
42
43 struct bgp {
44     guint8 bgp_marker[BGP_MARKER_SIZE];
45     guint16 bgp_len;
46     guint8 bgp_type;
47 };
48
49 struct bgp_open {
50     guint8 bgpo_marker[BGP_MARKER_SIZE];
51     guint16 bgpo_len;
52     guint8 bgpo_type;
53     guint8 bgpo_version;
54     guint16 bgpo_myas;
55     guint16 bgpo_holdtime;
56     guint32 bgpo_id;
57     guint8 bgpo_optlen;
58     /* options should follow */
59 };
60
61 struct bgp_notification {
62     guint8 bgpn_marker[BGP_MARKER_SIZE];
63     guint16 bgpn_len;
64     guint8 bgpn_type;
65     guint8 bgpn_major;
66     guint8 bgpn_minor;
67     /* data should follow */
68 };
69
70 struct bgp_attr {
71     guint8 bgpa_flags;
72     guint8 bgpa_type;
73 };
74
75 /* attribute flags, from RFC 1771 */
76 #define BGP_ATTR_FLAG_OPTIONAL        0x80
77 #define BGP_ATTR_FLAG_TRANSITIVE      0x40
78 #define BGP_ATTR_FLAG_PARTIAL         0x20
79 #define BGP_ATTR_FLAG_EXTENDED_LENGTH 0x10
80
81 /* AS_PATH segment types, from RFC 1771 */
82 #define AS_SET      1
83 #define AS_SEQUENCE 2
84
85 #define BGPTYPE_ORIGIN            1   /* RFC1771          */
86 #define BGPTYPE_AS_PATH           2   /* RFC1771          */
87 #define BGPTYPE_NEXT_HOP          3   /* RFC1771          */
88 #define BGPTYPE_MULTI_EXIT_DISC   4   /* RFC1771          */
89 #define BGPTYPE_LOCAL_PREF        5   /* RFC1771          */
90 #define BGPTYPE_ATOMIC_AGGREGATE  6   /* RFC1771          */
91 #define BGPTYPE_AGGREGATOR        7   /* RFC1771          */
92 #define BGPTYPE_COMMUNITIES       8   /* RFC1997          */
93 #define BGPTYPE_ORIGINATOR_ID     9   /* RFC1998          */
94 #define BGPTYPE_CLUSTER_LIST     10   /* RFC1998          */
95 #define BGPTYPE_DPA              11   /* work in progress */
96 #define BGPTYPE_ADVERTISERS      12   /* RFC1863          */
97 #define BGPTYPE_RCID_PATH        13   /* RFC1863          */
98 #define BGPTYPE_MP_REACH_NLRI    14   /* RFC2283          */
99 #define BGPTYPE_MP_UNREACH_NLRI  15   /* RFC2283          */
100
101 /* RFC1700 address family numbers */
102 #define AFNUM_INET      1
103 #define AFNUM_INET6     2
104 #define AFNUM_NSAP      3
105 #define AFNUM_HDLC      4
106 #define AFNUM_BBN1822   5
107 #define AFNUM_802       6
108 #define AFNUM_E163      7
109 #define AFNUM_E164      8
110 #define AFNUM_F69       9
111 #define AFNUM_X121      10
112 #define AFNUM_IPX       11
113 #define AFNUM_ATALK     12
114 #define AFNUM_DECNET    13
115 #define AFNUM_BANYAN    14
116 #define AFNUM_E164NSAP  15
117
118 #define CHECK_SIZE(x, s, l) \
119 do {                            \
120     if ((x) + (s) > (l))        \
121         return;                 \
122 } while (0)
123
124 #ifndef offsetof
125 #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
126 #endif
127
128 /*
129  * Convert prefix length into number of guint8s needed for prefix.
130  */
131 #define convert_prefix(p) (((p) + 7) / (8))
132
133 #endif