Author: adrian.chadd
Date: Mon Feb 23 22:51:38 2009
New Revision: 13857
Modified:
playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c
playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c
playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.h
Log:
Migrate the bgp UPDATE -handling- into bgp_core.c rather than bgp_packet.c.
This includes the RIB fiddling.
This means the bgp_packet.c routines don't need references to
bgp_instance_t.
Of course, there's still no -real- FSM implemented yet.
Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c Mon Feb 23 22:51:38 2009
@@ -87,6 +87,9 @@
u_int8_t type;
u_int16_t pkt_len;
+ bgp_update_state_t us;
+ int i;
+
/* XXX should check the marker is 16 bytes */
/* XXX should make sure there's enough bytes in the msg! */
@@ -98,7 +101,18 @@
r = bgp_handle_open(bi, fd, buf + 19, pkt_len -
19);
break;
case 2: /* UPDATE */
- r = bgp_handle_update(bi, fd, buf + 19, pkt_len -
19);
+ r = bgp_handle_update(buf + 19, pkt_len - 19, &us);
+ /* Handle route add/withdraw */
+ if (r) {
+ /* Now, we need to poke the RIB with our saved
info */
+ for (i = 0; i < us.withdraw_cnt; i++) {
+ bgp_rib_del_net(&bi->rn,
us.withdraw[i],
us.withdraw_mask[i]);
+ }
+ for (i = 0; i < us.nlri_cnt; i++) {
+ bgp_rib_add_net(&bi->rn, us.nlri[i],
us.nlri_mask[i],
us.aspaths[us.aspath_len - 1]);
+ }
+ }
+ bgp_free_update(&us);
break;
case 3: /* NOTIFICATION */
r = bgp_handle_notification(bi, fd, buf + 19,
pkt_len - 19);
Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c Mon Feb 23 22:51:38 2009
@@ -21,21 +21,6 @@
#include "bgp_rib.h"
#include "bgp_core.h"
-struct _bgp_update_state {
- u_int8_t aspath_type;
- u_int8_t aspath_len;
- u_short *aspaths;
- int origin;
- int nlri_cnt;
- struct in_addr *nlri;
- u_int8_t *nlri_mask;
- int withdraw_cnt;
- struct in_addr *withdraw;
- u_int8_t *withdraw_mask;
- struct in_addr nexthop;
-};
-typedef struct _bgp_update_state bgp_update_state_t;
-
int
bgp_msg_len(const char *buf, int len)
{
@@ -212,7 +197,7 @@
}
int
-bgp_handle_update_withdraw(bgp_instance_t *bi, bgp_update_state_t *us,
const char *buf, int len)
+bgp_handle_update_withdraw(bgp_update_state_t *us, const char *buf, int
len)
{
u_int8_t pl, netmask;
int i = 0, j = 0;
@@ -248,7 +233,7 @@
}
int
-bgp_handle_update_pathattrib_origin(bgp_instance_t *bi, bgp_update_state_t
*us, const char *buf, int len)
+bgp_handle_update_pathattrib_origin(bgp_update_state_t *us, const char
*buf, int len)
{
if (len < 1)
return 0;
@@ -258,7 +243,7 @@
}
int
-bgp_handle_update_pathattrib_aspath(bgp_instance_t *bi, bgp_update_state_t
*us, const char *buf, int len)
+bgp_handle_update_pathattrib_aspath(bgp_update_state_t *us, const char
*buf, int len)
{
int i, j = 0;
@@ -282,7 +267,7 @@
}
int
-bgp_handle_update_pathattrib_nexthop(bgp_instance_t *bi,
bgp_update_state_t *us, const char *buf, int len)
+bgp_handle_update_pathattrib_nexthop(bgp_update_state_t *us, const char
*buf, int len)
{
if (len < 4)
return 0;
@@ -293,7 +278,7 @@
}
int
-bgp_handle_update_pathattrib(bgp_instance_t *bi, bgp_update_state_t *us,
const char *buf, int len)
+bgp_handle_update_pathattrib(bgp_update_state_t *us, const char *buf, int
len)
{
int i = 0;
u_int8_t a_flags, a_type;
@@ -318,15 +303,15 @@
switch (a_type) {
case 1: /* origin */
- if (bgp_handle_update_pathattrib_origin(bi, us,
buf + i, a_len) < 0)
+ if (bgp_handle_update_pathattrib_origin(us, buf
+ i, a_len) < 0)
return 0;
break;
case 2: /* as path */
- if (bgp_handle_update_pathattrib_aspath(bi, us,
buf + i, a_len) < 0)
+ if (bgp_handle_update_pathattrib_aspath(us, buf
+ i, a_len) < 0)
return 0;
break;
case 3: /* next hop*/
- if (bgp_handle_update_pathattrib_nexthop(bi,
us, buf + i, a_len) < 0)
+ if (bgp_handle_update_pathattrib_nexthop(us,
buf + i, a_len) < 0)
return 0;
break;
default:
@@ -341,7 +326,7 @@
}
int
-bgp_handle_update_nlri(bgp_instance_t *bi, bgp_update_state_t *us, const
char *buf, int len)
+bgp_handle_update_nlri(bgp_update_state_t *us, const char *buf, int len)
{
u_int8_t pl, netmask;
int i = 0, j = 0;
@@ -377,7 +362,7 @@
}
void
-bgp_free_update(bgp_instance_t *bi, bgp_update_state_t *us)
+bgp_free_update(bgp_update_state_t *us)
{
safe_free(us->withdraw);
safe_free(us->withdraw_mask);
@@ -387,15 +372,12 @@
}
int
-bgp_handle_update(bgp_instance_t *bi, int fd, const char *buf, int len)
+bgp_handle_update(const char *buf, int len, bgp_update_state_t *us)
{
- int rc = 0;
u_int16_t withdraw_route_len;
u_int16_t path_attrib_len;
- bgp_update_state_t us;
- int i;
- bzero(&us, sizeof(us));
+ bzero(us, sizeof(*us));
withdraw_route_len = ntohs(* (u_int16_t *) buf);
path_attrib_len = ntohs(* (u_int16_t *) (buf + withdraw_route_len + 2));
@@ -403,30 +385,17 @@
debug(85, 2) ("bgp_handle_update: UPDATE pktlen %d:
withdraw_route_len %d; path attrib len %d\n",
len, withdraw_route_len, path_attrib_len);
- if (! bgp_handle_update_withdraw(bi, &us, buf + 2, withdraw_route_len))
{
- rc = 0; goto finish;
- }
- if (! bgp_handle_update_pathattrib(bi, &us, buf + 2 +
withdraw_route_len
+ 2, path_attrib_len)) {
- rc = 0; goto finish;
- }
- if (! bgp_handle_update_nlri(bi, &us, buf + 2 + withdraw_route_len + 2
+
path_attrib_len, len - (2 + withdraw_route_len + 2 + path_attrib_len))) {
- rc = 0; goto finish;
+ if (! bgp_handle_update_withdraw(us, buf + 2, withdraw_route_len)) {
+ return 0;
}
-
- /* Now, we need to poke the RIB with our saved info */
- for (i = 0; i < us.withdraw_cnt; i++) {
- bgp_rib_del_net(&bi->rn, us.withdraw[i], us.withdraw_mask[i]);
+ if (! bgp_handle_update_pathattrib(us, buf + 2 + withdraw_route_len +
2,
path_attrib_len)) {
+ return 0;
}
- for (i = 0; i < us.nlri_cnt; i++) {
- bgp_rib_add_net(&bi->rn, us.nlri[i], us.nlri_mask[i],
us.aspaths[us.aspath_len - 1]);
+ if (! bgp_handle_update_nlri(us, buf + 2 + withdraw_route_len + 2 +
path_attrib_len, len - (2 + withdraw_route_len + 2 + path_attrib_len))) {
+ return 0;
}
- rc = 1;
-finish:
- /* free said saved info */
- bgp_free_update(bi, &us);
-
- return rc;
+ return 1;
}
int
Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.h
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.h (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.h Mon Feb 23 22:51:38 2009
@@ -9,6 +9,21 @@
/* XXX eww? */
struct _bgp_instance;
+struct _bgp_update_state {
+ u_int8_t aspath_type;
+ u_int8_t aspath_len;
+ u_short *aspaths;
+ int origin;
+ int nlri_cnt;
+ struct in_addr *nlri;
+ u_int8_t *nlri_mask;
+ int withdraw_cnt;
+ struct in_addr *withdraw;
+ u_int8_t *withdraw_mask;
+ struct in_addr nexthop;
+};
+typedef struct _bgp_update_state bgp_update_state_t;
+
/*
* XXX can we get away with -not- passing in the bgp_instance here?
* XXX now that the RIB related stuff can be done elsewhere?
@@ -17,8 +32,11 @@
extern int bgp_send_hello(struct _bgp_instance *bi, int fd, unsigned short
asnum, short hold_time, struct in_addr bgp_id);
extern int bgp_handle_open(struct _bgp_instance *bi, int fd, const char
*buf, int len);
-extern int bgp_handle_update(struct _bgp_instance *bi, int fd, const char
*buf, int len);
+extern int bgp_handle_update(const char *buf, int len, bgp_update_state_t
*us);
extern int bgp_handle_notification(struct _bgp_instance *bi, int fd, const
char *buf, int len);
extern int bgp_handle_keepalive(int fd, const char *buf, int len);
+
+extern void bgp_free_update(bgp_update_state_t *us);
+
#endif
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---