Revision 54e55169

View differences:

proto/bgp/Doc
1
S bgp.c
2
S packets.c
3
S attrs.c
proto/bgp/attrs.c
170 170
  return bgp_set_attr(a->attrs, pool, attr, val);
171 171
}
172 172

  
173
/**
174
 * bgp_encode_attrs - encode BGP attributes
175
 * @w: buffer
176
 * @attrs: a list of extended attributes
177
 * @remains: remaining space in the buffer
178
 *
179
 * The bgp_encode_attrs() function takes a list of extended attributes
180
 * and converts it to its BGP representation (a part of an Update message).
181
 *
182
 * Result: Length of the attribute block generated.
183
 */
173 184
unsigned int
174 185
bgp_encode_attrs(byte *w, ea_list *attrs, int remains)
175 186
{
......
715 726
  return 0;
716 727
}
717 728

  
729
/**
730
 * bgp_decode_attrs - check and decode BGP attributes
731
 * @conn: connection
732
 * @attr: start of attribute block
733
 * @len: length of attribute block
734
 * @pool: linear pool to make all the allocations in
735
 * @mandatory: 1 iff presence of mandatory attributes has to be checked
736
 *
737
 * This function takes a BGP attribute block (a part of an Update message), checks
738
 * its consistency and converts it to a list of BIRD route attributes represented
739
 * by a &rta.
740
 */
718 741
struct rta *
719 742
bgp_decode_attrs(struct bgp_conn *conn, byte *attr, unsigned int len, struct linpool *pool, int mandatory)
720 743
{
proto/bgp/bgp.c
6 6
 *	Can be freely distributed and used under the terms of the GNU GPL.
7 7
 */
8 8

  
9
/**
10
 * DOC: Border Gateway Protocol
11
 *
12
 * The BGP protocol is implemented in three parts: |bgp.c| which takes care of the
13
 * connection and most of the interface with BIRD core, |packets.c| handling
14
 * both incoming and outgoing BGP packets and |attrs.c| containing functions for
15
 * manipulation with BGP attribute lists.
16
 *
17
 * As opposed to the other existing routing daemons, BIRD has a sophisticated core
18
 * architecture which is able to keep all the information needed by BGP in the
19
 * primary routing table, therefore no complex data structures like a central
20
 * BGP table are needed. This increases memory footprint of a BGP router with
21
 * many connections, but not too much and, which is more important, it makes
22
 * BGP much easier to implement.
23
 *
24
 * Each instance of BGP (corresponding to one BGP peer) is described by a &bgp_proto
25
 * structure to which are attached individual connections represented by &bgp_connection
26
 * (usually, there exists only one connection, but during BGP session setup, there
27
 * can be more of them). The connections are handled according to the BGP state machine
28
 * defined in the RFC with all the timers and all the parameters configurable.
29
 *
30
 * In incoming direction, we listen on the connection's socket and each time we receive
31
 * some input, we pass it to bgp_rx(). It decodes packet headers and the markers and
32
 * passes complete packets to bgp_rx_packet() which distributes the packet according
33
 * to its type.
34
 *
35
 * In outgoing direction, we gather all the routing updates and sort them to buckets
36
 * (&bgp_bucket) according to their attributes (we keep a hash table for fast comparison
37
 * of &rta's and a &fib which helps us to find if we already have another route for
38
 * the same destination queued for sending, so that we can replace it with the new one
39
 * immediately instead of sending both updates). There also exists a special bucket holding
40
 * all the route withdrawals which cannot be queued anywhere else as they don't have any
41
 * attributes. If we have any packet to send (due to either new routes or the connection
42
 * tracking code wanting to send a Open, KeepAlive or Notification message), we call
43
 * bgp_schedule_packet() which sets the corresponding bit in a @packet_to_send
44
 * bit field in &bgp_conn and as soon as the transmit socket buffer becomes empty,
45
 * we call bgp_fire_tx(). It inspects state of all the packet type bits and calls
46
 * the corresponding bgp_create_xx() functions, eventually rescheduling the same packet
47
 * type if we have more data of the same type to send.
48
 *
49
 * The processing of attributes consists of two functions: bgp_decode_attrs() for checking
50
 * of the attribute blocks and translating them to the language of BIRD's extended attributes
51
 * and bgp_encode_attrs() which does the converse. Both functions are built around a
52
 * @bgp_attr_table array describing all important characteristics of all known attributes.
53
 * Unknown transitive attributes are attached to the route as %EAF_TYPE_OPAQUE byte streams.
54
 */
55

  
9 56
#undef LOCAL_DEBUG
10 57

  
11 58
#include "nest/bird.h"
......
42 89
    }
43 90
}
44 91

  
92
/**
93
 * bgp_start_timer - start a BGP timer
94
 * @t: timer
95
 * @value: time to fire (0 to disable the timer)
96
 *
97
 * This functions calls tm_start() on @t with time @value and the
98
 * amount of randomization suggested by the BGP standard. Please use
99
 * it for all BGP timers.
100
 */
45 101
void
46 102
bgp_start_timer(timer *t, int value)
47 103
{
......
55 111
    tm_stop(t);
56 112
}
57 113

  
114
/**
115
 * bgp_close_conn - close a BGP connection
116
 * @conn: connection to close
117
 *
118
 * This function takes a connection described by the &bgp_conn structure,
119
 * closes its socket and frees all resources associated with it.
120
 *
121
 * If the connection is being closed due to a protocol error, adjust
122
 * the connection restart timer as well according to the error recovery
123
 * policy set in the configuration.
124
 *
125
 * If the connection was marked as primary, it shuts down the protocol as well.
126
 */
58 127
void
59 128
bgp_close_conn(struct bgp_conn *conn)
60 129
{
......
231 300
  conn->sk = s;
232 301
}
233 302

  
303
/**
304
 * bgp_connect - initiate an outgoing connection
305
 * @p: BGP instance
306
 *
307
 * The bgp_connect() function creates a new &bgp_conn and initiates
308
 * a TCP connection to the peer. The rest of connection setup is governed
309
 * by the BGP state machine as described in the standard.
310
 */
234 311
static void
235 312
bgp_connect(struct bgp_proto *p)	/* Enter Connect state and start establishing connection */
236 313
{
......
279 356
    bgp_connect(p);
280 357
}
281 358

  
359
/**
360
 * bgp_incoming_connection - handle an incoming connection
361
 * @sk: TCP socket
362
 * @dummy: unused
363
 *
364
 * This function serves as a socket hook for accepting of new BGP
365
 * connections. It searches a BGP instance corresponding to the peer
366
 * which has connected and if such an instance exists, it creates a
367
 * &bgp_conn structure, attaches it to the instance and either sends
368
 * an Open message or (if there already is an active connection) it
369
 * closes the new connection by sending a Notification message.
370
 */
282 371
static int
283 372
bgp_incoming_connection(sock *sk, int dummy)
284 373
{
......
473 562
  return P;
474 563
}
475 564

  
565
/**
566
 * bgp_error - report a protocol error
567
 * @c: connection
568
 * @code: error code (according to the RFC)
569
 * @subcode: error subcode
570
 * @data: data to be passed in the Notification message
571
 * @len: length of the data
572
 *
573
 * bgp_error() sends a notification packet to tell the other side that a protocol
574
 * error has occured (including the data considered erroneous if possible) and
575
 * closes the connection.
576
 */
476 577
void
477 578
bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, byte *data, int len)
478 579
{
proto/bgp/packets.c
236 236
  buf[18] = type;
237 237
}
238 238

  
239
/**
240
 * bgp_fire_tx - transmit packets
241
 * @conn: connection
242
 *
243
 * Whenever the transmit buffers of the underlying TCP connection
244
 * are free and we have any packets queued for sending, the socket functions
245
 * call bgp_fire_tx() which takes care of selecting the highest priority packet
246
 * queued (Notification > Keepalive > Open > Update), assembling its header
247
 * and body and sending it to the connection.
248
 */
239 249
static int
240 250
bgp_fire_tx(struct bgp_conn *conn)
241 251
{
......
295 305
  return sk_send(sk, end - buf);
296 306
}
297 307

  
308
/**
309
 * bgp_schedule_packet - schedule a packet for transmission
310
 * @conn: connection
311
 * @type: packet type
312
 *
313
 * Schedule a packet of type @type to be sent as soon as possible.
314
 */
298 315
void
299 316
bgp_schedule_packet(struct bgp_conn *conn, int type)
300 317
{
......
770 787
    }
771 788
}
772 789

  
790
/**
791
 * bgp_rx_packet - handle a received packet
792
 * @conn: BGP connection
793
 * @pkt: start of the packet
794
 * @len: packet size
795
 *
796
 * bgp_rx_packet() takes a newly received packet and calls the corresponding
797
 * packet handler according to the packet type.
798
 */
773 799
static void
774 800
bgp_rx_packet(struct bgp_conn *conn, byte *pkt, unsigned len)
775 801
{
......
784 810
    }
785 811
}
786 812

  
813
/**
814
 * bgp_rx - handle received data
815
 * @sk: socket
816
 * @size: amount of data received
817
 *
818
 * bgp_rx() is called by the socket layer whenever new data arrive from
819
 * the underlying TCP connection. It assembles the data fragments to packets,
820
 * checks their headers and framing and passes complete packets to
821
 * bgp_rx_packet().
822
 */
787 823
int
788 824
bgp_rx(sock *sk, int size)
789 825
{

Also available in: Unified diff