summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_notification.h
blob: 1622785d00e0184a16eebdf2466d6b8a4501b39b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/* BGP Notification state handling -- header
 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
 *
 * Recast for pthreaded bgpd: Copyright (C) Chris Hall (GMCH), Highwayman
 *
 * This file is part of GNU Zebra.
 *
 * GNU Zebra is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * GNU Zebra is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Zebra; see the file COPYING.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef _QUAGGA_BGP_NOTIFY_H
#define _QUAGGA_BGP_NOTIFY_H

#include "lib/misc.h"
#include "bgpd/bgp_common.h"

/*==============================================================================
 * BGP NOTIFICATION message codes.
 */
typedef unsigned char bgp_nom_code_t ;
typedef unsigned char bgp_nom_subcode_t ;

/*==============================================================================
 * Structure for notification.
 *
 * Note that vast majority of notification handling concerns notifications that
 * are *sent* to the far end.  Occasionally a notification will be received.
 */
typedef struct bgp_notify* bgp_notify ;

struct bgp_notify
{
  bgp_nom_code_t    code ;
  bgp_nom_subcode_t subcode ;

  bool              received ;

  bgp_size_t        length ;
  bgp_size_t        size ;
  ptr_t             data ;
} ;

/*==============================================================================
 * "Legacy" definitions
 */
/* BGP notify message codes.                                    */
#define BGP_NOTIFY_HEADER_ERR                    1
#define BGP_NOTIFY_OPEN_ERR                      2
#define BGP_NOTIFY_UPDATE_ERR                    3
#define BGP_NOTIFY_HOLD_ERR                      4
#define BGP_NOTIFY_FSM_ERR                       5
#define BGP_NOTIFY_CEASE                         6
#define BGP_NOTIFY_CAPABILITY_ERR                7
#define BGP_NOTIFY_MAX                           8

#define BGP_NOTIFY_SUBCODE_UNSPECIFIC            0

/* BGP_NOTIFY_HEADER_ERR sub codes.                             */
#define BGP_NOTIFY_HEADER_NOT_SYNC               1
#define BGP_NOTIFY_HEADER_BAD_MESLEN             2
#define BGP_NOTIFY_HEADER_BAD_MESTYPE            3
#define BGP_NOTIFY_HEADER_MAX                    4

/* BGP_NOTIFY_OPEN_ERR sub codes.                               */
#define BGP_NOTIFY_OPEN_UNSUP_VERSION            1
#define BGP_NOTIFY_OPEN_BAD_PEER_AS              2
#define BGP_NOTIFY_OPEN_BAD_BGP_IDENT            3
#define BGP_NOTIFY_OPEN_UNSUP_PARAM              4
#define BGP_NOTIFY_OPEN_AUTH_FAILURE             5
#define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME          6
#define BGP_NOTIFY_OPEN_UNSUP_CAPBL              7
#define BGP_NOTIFY_OPEN_MAX                      8

/* BGP_NOTIFY_UPDATE_ERR sub codes.                             */
#define BGP_NOTIFY_UPDATE_MAL_ATTR               1
#define BGP_NOTIFY_UPDATE_UNREC_ATTR             2
#define BGP_NOTIFY_UPDATE_MISS_ATTR              3
#define BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR          4
#define BGP_NOTIFY_UPDATE_ATTR_LENG_ERR          5
#define BGP_NOTIFY_UPDATE_INVAL_ORIGIN           6
#define BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP          7
#define BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP         8
#define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR           9
#define BGP_NOTIFY_UPDATE_INVAL_NETWORK         10
#define BGP_NOTIFY_UPDATE_MAL_AS_PATH           11
#define BGP_NOTIFY_UPDATE_MAX                   12

/* BGP_NOTIFY_CEASE sub codes (RFC 4486).                       */
#define BGP_NOTIFY_CEASE_MAX_PREFIX              1
#define BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN          2
#define BGP_NOTIFY_CEASE_PEER_UNCONFIG           3
#define BGP_NOTIFY_CEASE_ADMIN_RESET             4
#define BGP_NOTIFY_CEASE_CONNECT_REJECT          5
#define BGP_NOTIFY_CEASE_CONFIG_CHANGE           6
#define BGP_NOTIFY_CEASE_COLLISION_RESOLUTION    7
#define BGP_NOTIFY_CEASE_OUT_OF_RESOURCE         8
#define BGP_NOTIFY_CEASE_MAX                     9

/* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */
#define BGP_NOTIFY_CAPABILITY_INVALID_ACTION     1
#define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH     2
#define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE     3
#define BGP_NOTIFY_CAPABILITY_MAX                4

/*==============================================================================
 * Functions
 */

extern bgp_notify
bgp_notify_new(bgp_nom_code_t code, bgp_nom_subcode_t subcode) ;

extern bgp_notify
bgp_notify_new_expect(bgp_nom_code_t code, bgp_nom_subcode_t subcode,
                                                            bgp_size_t expect) ;
extern bgp_notify
bgp_notify_new_with_data(bgp_nom_code_t code, bgp_nom_subcode_t subcode,
                                             const void* data, bgp_size_t len) ;
extern void
bgp_notify_free(bgp_notify notification) ;

extern bgp_notify
bgp_notify_dup(bgp_notify notification) ;

extern void
bgp_notify_unset(bgp_notify* p_notification) ;

extern bgp_notify
bgp_notify_take(bgp_notify* p_notification) ;

extern void
bgp_notify_set(bgp_notify* p_dst, bgp_notify src) ;

extern void
bgp_notify_set_dup(bgp_notify* p_dst, bgp_notify src) ;

extern void
bgp_notify_set_mov(bgp_notify* p_dst, bgp_notify* p_src) ;

/*==============================================================================
 * Access Functions -- mostly inline
 *
 * Note that the various get functions return undefined/unspecific/empty if
 * given a NULL bgp_notify.
 */

Inline void
bgp_notify_set_code(bgp_notify notification, bgp_nom_code_t code)
{
  notification->code = code ;
} ;

Inline void
bgp_notify_set_subcode(bgp_notify notification, bgp_nom_subcode_t subcode)
{
  notification->subcode = subcode ;
} ;

Inline void
bgp_notify_set_received(bgp_notify notification)
{
  notification->received = true ;
} ;

extern bgp_notify
bgp_notify_reset(bgp_notify notification, bgp_nom_code_t code,
                                                     bgp_nom_subcode_t subcode) ;
extern void
bgp_notify_append_data(bgp_notify notification, const void* data,
                                                               bgp_size_t len) ;
extern void
bgp_notify_append_b(bgp_notify notification, uint8_t b) ;

extern void
bgp_notify_append_w(bgp_notify notification, uint16_t w) ;

extern void
bgp_notify_append_l(bgp_notify notification, uint32_t l) ;

Inline bgp_nom_code_t
bgp_notify_get_code(bgp_notify notification)
{
  return (notification != NULL) ? notification->code :    BGP_NOMC_UNDEF ;
} ;

Inline bgp_nom_subcode_t
bgp_notify_get_subcode(bgp_notify notification)
{
  return (notification != NULL) ? notification->subcode : BGP_NOMS_UNSPECIFIC ;
} ;

Inline bool
bgp_notify_get_received(bgp_notify notification)
{
  return (notification != NULL) ? notification->received : false ;
} ;

Inline bgp_size_t
bgp_notify_get_length(bgp_notify notification)
{
  return (notification != NULL) ? notification->length  : 0 ;
} ;

Inline void*
bgp_notify_get_data(bgp_notify notification)
{
  return (notification != NULL) ? notification->data    : NULL ;
} ;

#endif /* _QUAGGA_BGP_NOTIFY_H */